C++ – Debug C++ program in Linux


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?

Best Solution

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.