Debugging with GDB

Of the available tools for developing C applications, GDB (Gnu Debugger) is one of the more common. GDB is a command-line tool for C and C++, intended to help you find bugs in an application. It takes a while to learn how to make the most out of GDB, but if you do much C programming, doing so will pay off.

Programming for Easy Debugging

There are steps you can take to minimize the amount of debugging you have to do or to assist in the process when it does occur. The best practices include

  • Use lots of comments to explain the purpose of variables and specific code.

  • Avoid overly complex macros, functions, and statements.

  • Make explicit use of parentheses or otherwise be careful with operator precedence.

  • Make sure you're using =

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.