Search code examples
c++visual-studiogccgdb

Is there any way to get more debug info from gdb?


I can get more debug info if built my program on Windows compared to Linux. Here is my code:

#include <iostream>
#include <vector>

using namespace std;

class Base
{
public:
    Base() = default;
    virtual ~Base() = default;
};

class Derived : public Base
{
public:
    Derived() = default;
    ~Derived() = default;
private:
    int i = 1;
};

int main()
{
    vector<Base*> a;
    a.push_back(new Derived());
    return 0;
}

Build On Linux:Build On Linux

Build On Windows:enter image description here

It's obvious I can get more information with Windows build version. Such as vector info, vector element real type, derived object info... But Linux version, I only get the pointer address. By the way, they are all debugging by visual studio. Is there some way to add more debug info to the program built by GNU compiler? Such as compiler flags?


Solution

  • I fixed this problem by add a init command to the ~/.gdbinit.

    Add the following command to the first line of file ~/.gdbinit.

    set print object on