Reputation:
I have written a simple C++ program like this:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello.";
return 0;
}
Now I want to debug it. So what will be the command for it so my control goes to every line?
Upvotes: 24
Views: 57666
Reputation: 992955
You can use gdb
for this:
$ gdb hello
This will start gdb
and prompt you for what to do next. The next
command executes one line of source and stops at the next line.
I found a basic GDB tutorial that may be helpful.
Upvotes: 35
Reputation: 23978
In the C++ Programming course I did in Sweden there was a part of the laboratory about the GNU Debugger. I never used it after, but here there is a paper explaining the basic usage, as far as I remember is in chapter 2.
Upvotes: 3
Reputation: 8418
I always thought emacs provided a pretty user-friendly front-end to gdb...
E.g.
(That should suffice to get you started. Emacs being emacs, there are always more features...)
Upvotes: 6
Reputation: 1356
If you want some user-friendly debugger, you can use Kdbg, which is basically a gdb frontend for KDE. Perhaps not so powerful as ddd, but easier to start with.
Upvotes: 3
Reputation: 729
Don't forget to compile your source code using -g option.
Like this: g++ -g helloWorld.cc
This is going to create an a.out executable file.
You'll be able to debug your a.out exe using gdb ./a.out
command.
Another tool you may use it's ddd basically a GUI for gdb.
Good luck
Upvotes: 19