







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








GDB is a debugger that helps you debug your program.
The time you spend now learning gdb will save you days of debugging time.
A debugger will make a good programmer a better programmer.
(^) To run a program with gdb type gdb progname (gdb) (^) Then set a breakpoint in the main function. (gdb) break main (^) A breakpoint is a marker in your program that will make the program stop and return control back to gdb. (^) Now run your program. (gdb) run (^) If your program has arguments, you can pass them after run.
gdb>
(gdb) step It will run the next line of code and stop. If it is a function call, it will enter into it (gdb) next It will run the next line of code and stop. If it is a function call, it will not enter the function and it will go through it. Example: (gdb) step (gdb) next
When you type
If the program is running without stopping, you can regain control again typing ctrl-c.
The command
(gdb) where #0 main () at test_mystring.c: (gdb)
The command “quit” exits gdb. (gdb) quit The program is running. Exit anyway? (y or n) y
This is also called “postmortem debugging”
It has nothing to do with CSI
When a program crashes, it writes a core file.
The core is a file that contains a snapshot of the program at the time of the crash. That includes what function the program was running.
Now Try gdb in Your Own Program
Make sure that your program is compiled with the –g option.
Remember: One hour you spend learning gdb will save you days of debugging. Less stress, better grades.