Incorrect location range for local variable in the register clobbered by callee for GDB tune
| Bugzilla Link | 49641 |
| Resolution | DUPLICATE |
| Resolved on | Mar 22, 2021 02:36 |
| Version | trunk |
| OS | Linux |
| CC | @adrian-prantl,@dstenb,@JDevlieghere,@walkerkd,@pogo59 |
Extended Description
Please consider these two files:
$ cat test2.c void f1(int); int f2(); void f3();
void f() { f1(0); int local = f2(); f1(local); f3(); }
$ cat main-for-core.c #include <stdio.h>
void f1(int param) { if (param % 2 == 0) return; printf("HELLO\n"); abort(); }
int f2() { int x; scanf("%d", &x); return x; }
void f3() { int y; scanf("%d", &y); printf("%d\n", y); }
int main() { f(); return 0; }
Compilation of the files:
$ clang -g -O2 test2.c -c -o object-file-test2.o $ clang -g -O2 main-for-core.c object-file-test2.o -o main-for-core
By examining debug_loc from object-file-test2.o for the local var we see:
00000000 000000000000000f 0000000000000016 (DW_OP_reg0 (rax))
And the code for the f() is:
0000000000000000
While debugging it, by loading the core file generated due to abort() (as an input I typed 5):
$ gdb main-for-core
...
(gdb) bt
#0 0x00007fb2d7aeb377 in raise () from /lib64/libc.so.6
#1 0x00007fb2d7aeca68 in abort () from /lib64/libc.so.6
#2 0x0000000000401197 in f1 (param=
But it should be reported as <optimized_out>, because the %eax was clobbered by the call.
GCC produces different high pc address to keep GDB working properly: 00000000 000000000000000f 0000000000000015 (DW_OP_reg0 (rax))
LLDB works OK for this case.
I've tried to change the DwarfDebug, to generate the debug loc entry ending address as addr(endLabel) - 1, as GCC, for GDB tune, and it works -- GDB prints optimized_out for the local var.
*** This bug has been marked as a duplicate of bug llvm/llvm-project#39099 ***
@David Thanks for the reply!
I see... it is the same issue. I've reproduced this on X86_64 target.
I prepared a patch to trim the ranges for GDB [1]. I've made a very similar one as well...
This looks like [0]. I prepared a patch to trim the ranges for GDB [1]. However, people thought it was better for GDB to handle this, so after discussions I abandoned that and wrote a GDB ticket instead [2]. We have implemented this for our downstream target in GDB. I don't think this has happened for any upstream targets as far as I know, but it was a while seen I checked that.
[0] llvm/llvm-project#39099 [1] https://reviews.llvm.org/D68465 [2] https://sourceware.org/bugzilla/show_bug.cgi?id=25143