-1

I have a static library that I compiled with -g0 -O3 flags. Since this library provides a framework, I can use it in many different projects. I do not want to distribute all of the source code of this library (that's why I need -g0 flag). The users who have this library can create their own executables by including it. When one tries to debug his/her executable with gdb, he/she cannot see the contents of member variables which are inherited from the base classes defined in the library. What I mean is that:

// This class is defined in a static library and it is compiled with -g0 flag.
class Foo {
protected:
    std::string name;

    virtual void someAction() = 0;

//...
};

// This class is defined in a project that uses the static library and it is compiled with -g3 flag.
class Bar {
protected:
    std::string surname;

    void someAction(){
        std::string fullName = this->name + " " + this->surname;
    }
};

When the executable project is being debugged, the user cannot see the name attribute in gdb. If I compile the library with -g3 flag everything is OK, but it is not desired. When I use -g0 flag and tries to run p this.name in gdb when the debugger is at the someAction function, I am getting this error message:

No symbol "name" in current context.

Is there any advice or solution for this? I think it should be possible because the compiler can know the content of the Foo class even if the debugging flag is -g0. By the way, I need to access only contents of the members. Maybe, is there an option for gdb for this. I use gdb 9.2, g++ 10.1.0 under MSYS2 in Windows 10.

simon_tulia
  • 368
  • 1
  • 6
  • 22
  • 1
    debug information isn't source code. Also you can have it separately – Swift - Friday Pie May 11 '22 at 08:06
  • @Swift-FridayPie you're right, but I cannot figure out why gdb cannot handle member variables that are defined in header files. I can provide them to gdb. Moreover, auto code completion tools can recognize those members. So, I think they could be accesible to gdb somehow. – simon_tulia May 16 '22 at 07:17
  • 1
    generally speaking , machine code got nothing in relation to source code except effect. Member variable do not have a stati address also, their position is relative to the object, information about object and it's type and storage class is required contextually.. There are ways to set up external debug information, see https://stackoverflow.com/questions/866721/how-to-generate-gcc-debug-symbol-outside-the-build-target – Swift - Friday Pie May 16 '22 at 08:31

0 Answers0