Did you know Cybrary has FREE video training? Join more than 2,500,000 IT and cyber security professionals, students, career changers, and more, growing their careers on Cybrary.
The GNU Debugger (GDB) is one of the most commonly-used debugging tools in the world. We demonstrate its functionality, cover its basic commands, and apply it to a live program in order to perform non-trivial debugging.
Teaching Assistants George Mcpherson Vikramajeet Khatri
(Disclaimer: Breaking Stuff with Joe is a Cybrary series that will be running indefinitely. You will not earn CEU/CPE hours by watching any individual 'Breaking Stuff with Joe' episode. However, you can still earn a certificate of completion for each episode completed.)
Using the GNU Debugger
The GNU debugger, also called GDB, is the most popular debugging tool for UNIX systems. It works to debug several languages including C and C++. When the GDB program is executed, it runs other programs, allowing users to have control over these programs. You are able to see what is going on inside a program as it executes, or what a program was doing at the time it crashed.
Using the GDB allows you to determine the following information:
- When a core dump happens, which expression or statement did it crash on?
- What are the program variable values at a specific point during the execution of the program?
- When an error happens as a function is executed, which line of the program has the call to that function, and what are the parameters?
What is the outcome of a specific expression in a program? While GDP may assist you in identifying memory leakage related bugs, it’s not a tool that is designed to detect these leakages. Also, GDB can’t be used on programs that compile with errors and it doesn’t help to fix those issues.
Why Use the GNU Debugger?
The GNU debugger is a powerful debugging tool that comes with many benefits. The biggest asset of GDB is its functionality. With this debugger, you are able to do the following:
- Start the program you are debugging, specifying any variables that may affect its behavior.
- Instruct the program to discontinue on conditions you specify.
- Inspect what has occurred when the program being debugged has stopped.
- Modify things in the program allowing you to experiment with resolving the effects of one bug and continue on to learn about others.
Additional reasons to use the GDB tool include:
- Availability – GDB is easily downloaded online. Currently, the latest version (GDP 8.3) is available at the GNU website.
- Usability – The GDB debugging tool is simple to manage once the basics are learned.
- Interface requirements – GDB uses a simple command line interface.
- Integrations – In addition to the C and C++ languages, GDB supports Ada, Assembly, D, Fortran, Go, Objective-C, OpenCL, Modula-2, Pascal, and Rust.
For more information about the GNU debugger tool, and to learn to use it, check out our how to Use GDB tutorial. The class is free, and it provides you with foundation information and the steps you need to take to apply it to a live program.
Complete this course and earn a How to Use GDB (BSWJ) Certificate of Completion