This is the mail archive of the
gdb-prs@sourceware.org
mailing list for the GDB project.
[Bug c++/9170] Unable to locate constructors with forward-declared classes
- From: "thor at math dot tu-berlin dot de" <sourceware-bugzilla at sourceware dot org>
- To: gdb-prs at sourceware dot org
- Date: 17 Feb 2010 18:20:01 -0000
- Subject: [Bug c++/9170] Unable to locate constructors with forward-declared classes
- References: <20060107214801.9170.thor@math.tu-berlin.de>
- Reply-to: sourceware-bugzilla at sourceware dot org
------- Additional Comments From thor at math dot tu-berlin dot de 2010-02-17 18:20 -------
Played again with it. The trouble becomes at least more obvious if the class in
question has multiple constructors. Here's how to reproduce - and while gdb
certainly doesn't crash anymore, it still tries to set the breakpoint at address
0x0:
Enter the following as class.cpp:
/* snip */
class A {
int x;
bool b;
A *p;
public:
A(int i)
: x(i), b(false), p(0)
{ };
A(int i,bool a)
: x(i), b(a), p(0)
{ };
A(int i,A *next)
: x(i), p(next)
{ }
~A()
{
if (p)
p->inc();
}
void inc()
{
x++;
}
};
A *getA(int x)
{
A a(1);
return new A(x,&a);
}
void dispose(A *a)
{
delete a;
}
/* snip */
Enter the following as main.cpp:
/* snip */
extern class A *getA(int x);
extern void dispose(class A *);
int main(int argc,char **argv)
{
class A *ap = getA(1);
dispose(ap);
}
/* snip */
Compile with:
g++ -c -ggdb3 -O0 -o class.o class.cpp
g++ -c -ggdb3 -O0 -o main.o main.cpp
Link with:
g++ -o a.out class.o main.o
Run the debugger with:
gdb a.out
Then try:
break A::A
The result of which is:
[0] cancel
[1] all
?HERE
?HERE
?HERE
Then enter 1. The result is:
Note: breakpoint -1 (disabled) also set at pc 0x0.
Breakpoint 1 at 0x0
Note: breakpoints -1 (disabled) and 1 also set at pc 0x0.
Breakpoint 2 at 0x0
Note: breakpoints -1 (disabled), 1 and 2 also set at pc 0x0.
Breakpoint 3 at 0x0
warning: Multiple breakpoints were set.
Use the "delete" command to delete unwanted breakpoints.
Also known as "nonsense". With the patch in question, the situation does in so
far get better as errors are no longer printed, but the breakpoint nevertheless
doesn't work - or is set at the wrong place.
Part of the problem might be that g++ generates multiple routines for the same
constructor (i.e. one constructor is expanded into several assembly routines
depending on whether the object is allocated on the heap or the stack), and
apparently, gdb sets the breakpoint at the wrong place.
Unfortunately, this is indeed a long standing bug, I've never been able to debug
constructors successfully with any gdb version I have seen so far. The onyl
workaround I know is to add a dummy function to constructors and set a
breakpoint in this dummy....
So long,
Thomas
--
http://sourceware.org/bugzilla/show_bug.cgi?id=9170
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.