This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
I have a simple C++ program with some instance variables: int main (void) { A alpha, *aap, *abp; B beta, *bbp; ... return 0; } The command line is: gcc -S -gdwarf-2 The "return 0" line is on line 65. With gcc HEAD 2004-02-01 15:37:18 UTC, the generated code for "return 0" looks like this: .LBB10: .loc 1 65 0 leal -56(%ebp), %eax movl %eax, (%esp) call B::~B [in-charge]() leal -24(%ebp), %eax movl %eax, (%esp) call A::~A [in-charge]() .LBE10: movl $0, %eax Simple and good. I can set a breakpoint on line 65, the "return 0" line, and look at the values of A and B before they are destroyed. With gcc tree-ssa-20020619-branch 2004-02-05 12:45:13 UTC, the generated code looks like this: movl $0, %ebx .loc 1 56 0 leal -56(%ebp), %eax movl %eax, (%esp) call B::~B [in-charge]() .loc 1 55 0 leal -24(%ebp), %eax movl %eax, (%esp) call A::~A [in-charge]() movl %ebx, %eax .LBE2: .loc 1 66 0 movl -4(%ebp), %ebx leave ret The "return 0" line has had its code split up into two pieces, "movl 0, %ebx" and "movl %ebx, %eax", which are separated. There is no more .loc 1 65 at all. Instead, there are some .loc lines for the destructor calls which reference the lines that *declared* A and B. When I try to break on line 65 and print "A" and "B", gdb selects the .loc for line 66, which comes after the destructors, so the local instance variables have been destroyed. This happens with both dwarf-2 and stabs+. There needs to be a ".loc 1 65" for the "return 0;" line, and it needs to occur before the destructors.
Created an attachment (id=5691) [edit] C++ source file
Created an attachment (id=5692) [edit] Generated code with gcc HEAD, good
Created an attachment (id=5693) [edit] Generated code with gcc tree-ssa, bad
I can fix this for some, but not all, instances. For A a; if (p) return 0; if (q) return 1; there are two return statements. At -O0, there will only be one instance of the destructor for "a". What line should it be indicated for? It can't have line numbers for both return statements. Seems to me that the declaration line for "a" is as good as any... At -O2 we will ususally copy the destructor calls. However, if the destructor gets inlined, and is large enough, then we won't duplicate it there either.
Fixed with recent return statement changes.
Subject: Re: [3.5 regression] bad debug line numbers near "return" statement, c++ It works for me. Thanks!