Skip to main content

Introduction to Computer Organization

  • Chapter
  • First Online:
Book cover Introductory Computer Forensics
  • 167k Accesses

Abstract

The objectives of this chapter are to:

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 89.00
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Hardcover Book
USD 119.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Author information

Authors and Affiliations

Authors

Appendix A: How to Use GDB to Debug C Programs

Appendix A: How to Use GDB to Debug C Programs

In order to use gdb to debug a C program, you should compile your C program with -g option. It allows the compiler to collect the debugging information. For example,

gcc –g –o test test.c

where gcc is the compiler, test.c is the C program and test is the executable file.

Suppose we need to debug the executable file, the followings are basic steps for debugging a c program using gdb debugger:

Step 1: start gdb

  • gdb ./test

Step 2: Set up a break point inside C program

Syntax: break <line_number>

Note that since now on, you execute the commands in the gdb command line, not in the bash command line.

Step 3: Execute the C program in gdb debugger

run [args]

where args is the command line arguments you pass to the program.

Afterwards, you can use various gdb commands to examine executing Code. Example options of examining executing Code include:

  • p or print: Print the content of variables or parameters.

  • x or examine: Examine memory contents in different forms, including binary and hexadecimal forms. It uses the following syntax:

    x/[NUM][SIZE][FORMAT] [Address]

    where NUM is the number of objects to display, SIZE is the size of each object (b = byte, h = half-word, w = word, g = giant word (eight bytes)), FORMAT indicates how to display each object (d = decimal, x = hex, o = octal, t = binary), and [Address] is the memory address. For example,

    the following x command will display a program’s variable a’s actual value in hex form when given the argument &a. 4 is the repeat count or the number of units whose size is specified by argument b, which stands for byte as the unit size. ‘x’ means that you want to display or output the value in hexadecimal form, which is the default display format for the x command.

    (gdb) x/4bx &a

    0xbffff56c: 0x10 0x00 0x00 0x00

Step 4: Continue, stepping over and in after a breakpoint

There are three kinds of gdp operations after a breakpoint:

  • c or continue: Execution will continue until the next breakpoint in your code.

  • n or next: Executing the next line of code after the current breakpoint.

  • s or step: The s command is very similar to the n command, except for that the s command steps into a function and executes it line by line, whereas the n command simply treats a function call as one line of code.

Step 5: Quit from the gdb debugger

Syntax: quit

Rights and permissions

Reprints and permissions

Copyright information

© 2018 Springer Nature Switzerland AG

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Lin, X. (2018). Introduction to Computer Organization. In: Introductory Computer Forensics. Springer, Cham. https://doi.org/10.1007/978-3-030-00581-8_2

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-00581-8_2

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-00580-1

  • Online ISBN: 978-3-030-00581-8

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics