https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91751
Bug ID: 91751
Summary: In backtrace, calls to c++ destructors are shown way
afar from the actual place
Product: gcc
Version: 9.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: debug
Assignee: unassigned at gcc dot gnu.org
Reporter: Hi-Angel at yandex dot ru
Target Milestone: ---
As the title says. I'm not aware of a way to get backtrace with gcc builtins,
so I'm using gdb in testcase, so it's possible that it's a bug in gdb. But to
me a wrong debugging information sounded more likely, so I'm reporting here.
# Steps to reproduce
$ cat test.cpp
#include <cstdio>
struct MyStruct {
void use_the_object() { puts("MyStruct is still in use"); }
~MyStruct() {
puts("MyStruct destructor called");
}
};
int main() {
MyStruct m;
printf("line %i crossed\n", __LINE__);
m.use_the_object();
}
$ g++ test.cpp -o a -g3 -O0
$ ./a
line 12 crossed
MyStruct is still in use
MyStruct destructor called
$ gdb ./a
Reading symbols from ./a...
gdb λ br MyStruct::~MyStruct()
Breakpoint 1 at 0x1214: file test.cpp, line 6.
gdb λ r
Starting program: /tmp/a
line 12 crossed
MyStruct is still in use
Breakpoint 1, MyStruct::~MyStruct (this=0x7fffffffde27,
__in_chrg=<optimized out>) at test.cpp:6
6 puts("MyStruct destructor called");
gdb λ bt
#0 MyStruct::~MyStruct (this=0x7fffffffde27, __in_chrg=<optimized out>) at
test.cpp:6
#1 0x00005555555551af in main () at test.cpp:11
## Expected
The last line in backtrace has either line test.cpp:13 or 14, because the
destructor could not possibly get called before the last use of the object.
## Actual
Backtrace says it's called at line 11, before the last use of the object.