Debugging C++ program in GDB on linux

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yinglcs@gmail.com

    Debugging C++ program in GDB on linux

    I am trying to debug a C++ program in GDB on linux.
    I want to dump out the content of the "this" object,
    Here is what I get:
    (gdb) print *this
    $2 = {path = <incomplete type>}

    My question is why I don't see the content of 'path'? It said
    '<incomplete type>'.

    In the code, path is:
    ostringstream path;

    When I try to do this: at GDB prompt 'print this->path.str()' , I get
    this error:

    (gdb) print this->path.str()
    Couldn't find method ostringstream:: str

  • Victor Bazarov

    #2
    Re: Debugging C++ program in GDB on linux

    yinglcs@gmail.c om wrote:[color=blue]
    > I am trying to debug a C++ program in GDB on linux.
    > I want to dump out the content of the "this" object,
    > Here is what I get:
    > (gdb) print *this
    > $2 = {path = <incomplete type>}
    >
    > My question is why I don't see the content of 'path'? It said
    > '<incomplete type>'.
    > [..][/color]

    This is OT here. Please consider asking in 'gnu.gdb' or in
    'gnu.utils.help ' or as a last resort in the newsgroup for your
    operating system (comp.os.linux. develpment.* hierarchy).

    V


    Comment

    • Shark

      #3
      Re: Debugging C++ program in GDB on linux

      yinglcs@gmail.c om wrote:[color=blue]
      > I am trying to debug a C++ program in GDB on linux.
      > I want to dump out the content of the "this" object,
      > Here is what I get:
      > (gdb) print *this[/color]

      I think its not the right way. There are multiple *this in a given
      program. Its like using a compiler. If you randomly say:

      int main()
      {
      *this->print();
      }

      then it doesn't mean anything. C++ compilers do name mangling (ok I
      don't know what I am talking about) which gives everything a unique
      name, and same goes for debuggers. You have to give the name of the
      object you are trying to call a method of.
      [color=blue]
      > $2 = {path = <incomplete type>}
      >
      > My question is why I don't see the content of 'path'? It said
      > '<incomplete type>'.[/color]

      Of course it is incomplete. *this doesn't exist on its own.
      [color=blue]
      >
      > In the code, path is:
      > ostringstream path;
      >
      > When I try to do this: at GDB prompt 'print this->path.str()' , I get
      > this error:
      >
      > (gdb) print this->path.str()
      > Couldn't find method ostringstream:: str[/color]

      Same...and once you have the names ready just follow Victor's advice
      and look in the newsgroups he suggests.

      Comment

      • Bernd Strieder

        #4
        Debugging and C++ standard libraries (was: Debugging C++ program in GDB on linux)

        Hello,

        yinglcs@gmail.c om wrote:
        [color=blue]
        > I am trying to debug a C++ program in GDB on linux.
        > I want to dump out the content of the "this" object,
        > Here is what I get:
        > (gdb) print *this
        > $2 = {path = <incomplete type>}
        >
        > My question is why I don't see the content of 'path'? It said
        > '<incomplete type>'.
        >
        > In the code, path is:
        > ostringstream path;
        >
        > When I try to do this: at GDB prompt 'print this->path.str()' , I get
        > this error:
        >
        > (gdb) print this->path.str()
        > Couldn't find method ostringstream:: str[/color]

        While others found this off-topic, I think there are at least three
        problems here connected to debugging which can be faced on all usual
        C++ implementations . The subject line was clearly off-topic.

        Could it be that your standard library is missing debugging information?
        Then showing information about its internals will surely fail with all
        C++ implementations . The incomplete type is a clear indication that
        debugging information is missing.

        I'm not sure, whether non-open-source implementors of a standard C++
        library have the freedom to make their internals visible enough to make
        some debugging sensible at all, i.e. handing out information the full
        source code could be derived from easily. I would not expect
        source-level debugging to be possible with all C++ implementations .
        Even g++ has not enabled this by default. The runtime libraries might
        have to be recompiled to make this possible.

        Calling methods from a debugger might not be possible when methods are
        inlined due to optimization. Maybe you can force the compiler to emit a
        non-inlined version of the functions by taking their addresses. The
        small missing method which is used in the code is a clear indication of
        inlining.

        Bernd Strieder

        Comment

        • Martin Eisenberg

          #5
          Re: Debugging and C++ standard libraries (was: Debugging C++ program in GDB on linux)

          Bernd Strieder wrote:
          [color=blue]
          > Calling methods from a debugger might not be possible when
          > methods are inlined due to optimization. Maybe you can force the
          > compiler to emit a non-inlined version of the functions by
          > taking their addresses.[/color]

          With GCC, using -fkeep-inline-functions might be preferable to
          putting contrived lines in the code to do that.


          Martin

          --
          Quidquid latine scriptum sit, altum viditur.

          Comment

          Working...