Debugging C++ program in GDB on linux

Y

yinglcs

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
 
V

Victor Bazarov

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>'.
[..]

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
 
S

Shark

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

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.
$2 = {path = <incomplete type>}

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

Of course it is incomplete. *this doesn't exist on its own.
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

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

Bernd Strieder

Hello,

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

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
 
M

Martin Eisenberg

Bernd said:
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.

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


Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top