GDB is the standard debugger for Linux and Unix-like operating systems.
A good debugger is one of the most important tools in a programmer's toolkit. On a UNIX or Linux system, GDB (the GNU debugger) is a powerful and popular debugging tool; it lets you do whatever you like with your program running under GDB.
Should you read this?
You should... if you can relate to two or more of the following:
You have a general idea of programming with C or C++.
You put a lot of cout or printf statements in the code if something goes wrong.
You have used a debugger with an IDE, and are curious about how the command line works.
You've just moved to a Unix-like operating system and would like to know about the toolchain better.
A crash course on compiling with gcc (or g++)
Gcc is the de facto compiler in Linux or any other *nix system. It also has Windows ports but on Windows, you'll probably find the debugger in Visual Studio 'easier'.
Suppose you have a file called main.cpp containing your c++ code. You should compile it with the following command:
g++ main.cpp -o main
While this will work fine and produce an executable file called main, you also need to put a -g flag to tell the compiler that you may want to debug your program later.
So the final command turns into:
g++ main.cpp -g -Wall -Werror -o main
(If you're wondering what -Wall and -Werror are, you may find this page on GCC a useful read.)
Don't worry if it looks cumbersome, you'll get used to it! (If you've got multiple source files you should use a good build system like make or Scons.)
Posted By:-Cplusplusprogramming