[clang/lldb] Could not evaluate DW_OP_entry_value for argv and argc
$ cat small.c
#include <stdlib.h>
#include <string.h>
int b = 9;
int main(int argc, char **argv) {
char *x = (char*)malloc(10);
memset(x, 0, 10);
int res = x[b];
free(x);
return res;
}
$ clang -Ofast -g small.c; lldb a.out
(lldb) target create "a.out"
Current executable set to '/root/DeVIL/a.out' (x86_64).
(lldb) b 10
Breakpoint 1: where = a.out`main + 35 at small.c:10:3, address = 0x00000000000006f3
(lldb) r
Process 23848 launched: '/root/DeVIL/a.out' (x86_64)
Process 23848 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x00005555555546f3 a.out`main(argc=<unavailable>, argv=<unavailable>) at small.c:10:3
7 memset(x, 0, 10);
8 int res = x[b];
9 free(x);
-> 10 return res;
11 }
(lldb) fr var
(int) argc = <Could not evaluate DW_OP_entry_value.>
(char **) argv = <Could not evaluate DW_OP_entry_value.>
(char *) x = <variable not available>
(int) res = 0
(lldb)
As can be seen, argc and argv are <Could not evaluate DW_OP_entry_value.>.
When Line 10 is changed to return 0;, the result is correct.
$ clang --version
Ubuntu clang version 15.0.0-++20220525063926+1f06398e96d4-1~exp1~20220525183937.510
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
@llvm/issue-subscribers-lldb
This sounds correct to me - any reason you believe it's not correct/where do you think this behavior should be changed?
The compiler optimized away the values, but said "hey, if you happen to be able to find the value of these parameters in the caller (if they had to be caller-saved, for instance) then you could still recover their values with that" - but presumably libc debug info doesn't have the location over the call (probably didn't save the value?) so there's no way to recover the value.
Thanks. In the stable version of clang/lldb, the behavior is different. Thus, I was wondering this might be a potential bug.
As you said, debug info doesn't have the location over the call. May it be a clang issue?
yibiao
Thanks. In the stable version of clang/lldb, the behavior is different. Thus, I was wondering this might be a potential bug.
Could you run llvm-dwarfdump on the binary with the stable version of clang? It /could/ be a bug, but might also be that the code got optimized further and there was no remaining copy of the location. (though this code seems simple enough that I'd be surprised if things got optimized significantly differently)
As you said, debug info doesn't have the location over the call. May it be a clang issue?
Possibly - hard to tell as I don't happen to have the right compiler versions on-hand to reproduce/investigate.
Following the dwarfdump for the binary built with the stable version of clang.
$ clang-6.0 -Ofast -g small.c; llvm-dwarfdump a.out
a.out: file format elf64-x86-64
.debug_info contents:
0x00000000: Compile Unit: length = 0x0000005a, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x0000005e)
0x0000000b: DW_TAG_compile_unit
DW_AT_producer ("GNU C11 7.5.0 -mlong-double-80 -mtune=generic -march=x86-64 -g -g -g -O2 -O2 -O2 -fbuilding-libgcc -fno-stack-protector -fpic")
DW_AT_language (DW_LANG_C99)
DW_AT_name ("../../../src/libgcc/config/i386/crtfastmath.c")
DW_AT_comp_dir ("/build/gcc-7-EmPD0P/gcc-7-7.5.0/build/x86_64-linux-gnu/libgcc")
DW_AT_ranges (0x00000000
[0x0000000000400430, 0x0000000000400443))
DW_AT_low_pc (0x0000000000000000)
DW_AT_stmt_list (0x00000000)
0x00000029: DW_TAG_subprogram
DW_AT_name ("set_fast_math")
DW_AT_decl_file ("/build/gcc-7-EmPD0P/gcc-7-7.5.0/build/x86_64-linux-gnu/libgcc/../../../src/libgcc/config/i386/crtfastmath.c")
DW_AT_decl_line (83)
DW_AT_prototyped (true)
DW_AT_low_pc (0x0000000000400430)
DW_AT_high_pc (0x0000000000400443)
DW_AT_frame_base (DW_OP_call_frame_cfa)
DW_AT_GNU_all_call_sites (true)
DW_AT_sibling (0x00000056)
0x00000046: DW_TAG_variable
DW_AT_name ("mxcsr")
DW_AT_decl_file ("/build/gcc-7-EmPD0P/gcc-7-7.5.0/build/x86_64-linux-gnu/libgcc/../../../src/libgcc/config/i386/crtfastmath.c")
DW_AT_decl_line (94)
DW_AT_type (0x00000056 "unsigned int")
DW_AT_location (0x00000000:
[0x0000000000400435, 0x000000000040043d): DW_OP_fbreg -12, DW_OP_deref_size 0x4, DW_OP_const2u 0x8040, DW_OP_or, DW_OP_stack_value
[0x000000000040043d, 0x0000000000400443): DW_OP_fbreg -12)
0x00000055: NULL
0x00000056: DW_TAG_base_type
DW_AT_byte_size (0x04)
DW_AT_encoding (DW_ATE_unsigned)
DW_AT_name ("unsigned int")
0x0000005d: NULL
0x0000005e: Compile Unit: length = 0x000000aa, format = DWARF32, version = 0x0004, abbr_offset = 0x0046, addr_size = 0x08 (next unit at 0x0000010c)
0x00000069: DW_TAG_compile_unit
DW_AT_producer ("clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)")
DW_AT_language (DW_LANG_C99)
DW_AT_name ("small.c")
DW_AT_stmt_list (0x00000067)
DW_AT_comp_dir ("/root/DeVIL")
DW_AT_GNU_pubnames (true)
DW_AT_low_pc (0x0000000000400540)
DW_AT_high_pc (0x000000000040056f)
0x00000088: DW_TAG_variable
DW_AT_name ("b")
DW_AT_type (0x0000009d "int")
DW_AT_external (true)
DW_AT_decl_file ("/root/DeVIL/small.c")
DW_AT_decl_line (4)
DW_AT_location (DW_OP_addr 0x601038)
0x0000009d: DW_TAG_base_type
DW_AT_name ("int")
DW_AT_encoding (DW_ATE_signed)
DW_AT_byte_size (0x04)
0x000000a4: DW_TAG_pointer_type
DW_AT_type (0x000000a9 "char")
0x000000a9: DW_TAG_base_type
DW_AT_name ("char")
DW_AT_encoding (DW_ATE_signed_char)
DW_AT_byte_size (0x01)
0x000000b0: DW_TAG_subprogram
DW_AT_low_pc (0x0000000000400540)
DW_AT_high_pc (0x000000000040056f)
DW_AT_frame_base (DW_OP_reg7 RSP)
DW_AT_name ("main")
DW_AT_decl_file ("/root/DeVIL/small.c")
DW_AT_decl_line (5)
DW_AT_prototyped (true)
DW_AT_type (0x0000009d "int")
DW_AT_external (true)
0x000000c9: DW_TAG_formal_parameter
DW_AT_location (0x0000003f:
[0x0000000000400540, 0x0000000000400546): DW_OP_reg5 RDI)
DW_AT_name ("argc")
DW_AT_decl_file ("/root/DeVIL/small.c")
DW_AT_decl_line (5)
DW_AT_type (0x0000009d "int")
0x000000d8: DW_TAG_formal_parameter
DW_AT_location (0x00000062:
[0x0000000000400540, 0x000000000040054b): DW_OP_reg4 RSI)
DW_AT_name ("argv")
DW_AT_decl_file ("/root/DeVIL/small.c")
DW_AT_decl_line (5)
DW_AT_type (0x00000106 "char **")
0x000000e7: DW_TAG_variable
DW_AT_location (0x00000085:
[0x000000000040054b, 0x000000000040056b): DW_OP_reg0 RAX)
DW_AT_name ("x")
DW_AT_decl_file ("/root/DeVIL/small.c")
DW_AT_decl_line (6)
DW_AT_type (0x000000a4 "char *")
0x000000f6: DW_TAG_variable
DW_AT_location (0x000000a8:
[0x0000000000400563, 0x000000000040056e): DW_OP_reg3 RBX)
DW_AT_name ("res")
DW_AT_decl_file ("/root/DeVIL/small.c")
DW_AT_decl_line (8)
DW_AT_type (0x0000009d "int")
0x00000105: NULL
0x00000106: DW_TAG_pointer_type
DW_AT_type (0x000000a4 "char *")
0x0000010b: NULL
Following is the dwarfdump for the binary built with the trunk version of clang $ clang -Ofast -g small.c; llvm-dwarfdump a.out
a.out: file format elf64-x86-64
.debug_info contents:
0x00000000: Compile Unit: length = 0x0000005a, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x0000005e)
0x0000000b: DW_TAG_compile_unit
DW_AT_producer ("GNU C11 7.5.0 -mlong-double-80 -mtune=generic -march=x86-64 -g -g -g -O2 -O2 -O2 -fbuilding-libgcc -fno-stack-protector -fpic")
DW_AT_language (DW_LANG_C99)
DW_AT_name ("../../../src/libgcc/config/i386/crtfastmath.c")
DW_AT_comp_dir ("/build/gcc-7-EmPD0P/gcc-7-7.5.0/build/x86_64-linux-gnu/libgcc")
DW_AT_ranges (0x00000000
[0x00000000000005a0, 0x00000000000005b3))
DW_AT_low_pc (0x0000000000000000)
DW_AT_stmt_list (0x00000000)
0x00000029: DW_TAG_subprogram
DW_AT_name ("set_fast_math")
DW_AT_decl_file ("/build/gcc-7-EmPD0P/gcc-7-7.5.0/build/x86_64-linux-gnu/libgcc/../../../src/libgcc/config/i386/crtfastmath.c")
DW_AT_decl_line (83)
DW_AT_prototyped (true)
DW_AT_low_pc (0x00000000000005a0)
DW_AT_high_pc (0x00000000000005b3)
DW_AT_frame_base (DW_OP_call_frame_cfa)
DW_AT_GNU_all_call_sites (true)
DW_AT_sibling (0x00000056)
0x00000046: DW_TAG_variable
DW_AT_name ("mxcsr")
DW_AT_decl_file ("/build/gcc-7-EmPD0P/gcc-7-7.5.0/build/x86_64-linux-gnu/libgcc/../../../src/libgcc/config/i386/crtfastmath.c")
DW_AT_decl_line (94)
DW_AT_type (0x00000056 "unsigned int")
DW_AT_location (0x00000000:
[0x00000000000005a5, 0x00000000000005ad): DW_OP_fbreg -12, DW_OP_deref_size 0x4, DW_OP_const2u 0x8040, DW_OP_or, DW_OP_stack_value
[0x00000000000005ad, 0x00000000000005b3): DW_OP_fbreg -12)
0x00000055: NULL
0x00000056: DW_TAG_base_type
DW_AT_byte_size (0x04)
DW_AT_encoding (DW_ATE_unsigned)
DW_AT_name ("unsigned int")
0x0000005d: NULL
0x0000005e: Compile Unit: length = 0x00000075, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0046, addr_size = 0x08 (next unit at 0x000000d7)
0x0000006a: DW_TAG_compile_unit
DW_AT_producer ("Ubuntu clang version 15.0.0-++20220530091621+14cc4674bf5a-1~exp1~20220530091715.519")
DW_AT_language (DW_LANG_C99)
DW_AT_name ("small.c")
DW_AT_str_offsets_base (0x00000008)
DW_AT_stmt_list (0x00000067)
DW_AT_comp_dir ("/root/DeVIL")
DW_AT_low_pc (0x00000000000006d0)
DW_AT_high_pc (0x00000000000006f7)
DW_AT_addr_base (0x00000008)
DW_AT_loclists_base (0x0000000c)
0x00000085: DW_TAG_variable
DW_AT_name ("b")
DW_AT_type (0x00000090 "int")
DW_AT_external (true)
DW_AT_decl_file ("/root/DeVIL/small.c")
DW_AT_decl_line (4)
DW_AT_location (DW_OP_addrx 0x0)
0x00000090: DW_TAG_base_type
DW_AT_name ("int")
DW_AT_encoding (DW_ATE_signed)
DW_AT_byte_size (0x04)
0x00000094: DW_TAG_pointer_type
DW_AT_type (0x00000099 "char")
0x00000099: DW_TAG_base_type
DW_AT_name ("char")
DW_AT_encoding (DW_ATE_signed_char)
DW_AT_byte_size (0x01)
0x0000009d: DW_TAG_subprogram
DW_AT_low_pc (0x00000000000006d0)
DW_AT_high_pc (0x00000000000006f7)
DW_AT_frame_base (DW_OP_reg7 RSP)
DW_AT_call_all_calls (true)
DW_AT_name ("main")
DW_AT_decl_file ("/root/DeVIL/small.c")
DW_AT_decl_line (5)
DW_AT_prototyped (true)
DW_AT_type (0x00000090 "int")
DW_AT_external (true)
0x000000ac: DW_TAG_formal_parameter
DW_AT_location (indexed (0x0) loclist = 0x0000001c:
[0x00000000000006d0, 0x00000000000006d6): DW_OP_reg5 RDI
[0x00000000000006d6, 0x00000000000006f7): DW_OP_entry_value(DW_OP_reg5 RDI), DW_OP_stack_value)
DW_AT_name ("argc")
DW_AT_decl_file ("/root/DeVIL/small.c")
DW_AT_decl_line (5)
DW_AT_type (0x00000090 "int")
0x000000b5: DW_TAG_formal_parameter
DW_AT_location (indexed (0x1) loclist = 0x0000002a:
[0x00000000000006d0, 0x00000000000006db): DW_OP_reg4 RSI
[0x00000000000006db, 0x00000000000006f7): DW_OP_entry_value(DW_OP_reg4 RSI), DW_OP_stack_value)
DW_AT_name ("argv")
DW_AT_decl_file ("/root/DeVIL/small.c")
DW_AT_decl_line (5)
DW_AT_type (0x000000d1 "char **")
0x000000be: DW_TAG_variable
DW_AT_location (indexed (0x2) loclist = 0x00000038:
[0x00000000000006e0, 0x00000000000006f3): DW_OP_reg0 RAX)
DW_AT_name ("x")
DW_AT_decl_file ("/root/DeVIL/small.c")
DW_AT_decl_line (6)
DW_AT_type (0x00000094 "char *")
0x000000c7: DW_TAG_variable
DW_AT_location (indexed (0x3) loclist = 0x0000003e:
[0x00000000000006eb, 0x00000000000006f6): DW_OP_reg3 RBX
[0x00000000000006f6, 0x00000000000006f7): DW_OP_reg0 RAX)
DW_AT_name ("res")
DW_AT_decl_file ("/root/DeVIL/small.c")
DW_AT_decl_line (8)
DW_AT_type (0x00000090 "int")
0x000000d0: NULL
0x000000d1: DW_TAG_pointer_type
DW_AT_type (0x00000094 "char *")
0x000000d6: NULL
Hmm - the old/"good" DWARF looks likely wrong to me - wouldn't RSI and RDI be clobbered by the function calls (malloc/free/memset), let alone for using the return register to store the resulting return value?
Is the value of the argc/argv values correct when debugging the old/"good" dwarf? What's the assembly look like (how does it use RSI/RDI)?
$ clang-6.0 -Ofast -g small.c; lldb-6.0 a.out
(lldb) target create "a.out"
Current executable set to 'a.out' (x86_64).
(lldb) b 10
Breakpoint 1: where = a.out`main + 43 at small.c:10, address = 0x000000000040056b
(lldb) r
Process 2418 launched: '/root/DeVIL/a.out' (x86_64)
Process 2418 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x000000000040056b a.out`main(argc=<unavailable>, argv=<unavailable>) at small.c:10
7 memset(x, 0, 10);
8 int res = x[b];
9 free(x);
-> 10 return res;
11 }
(lldb) fr var
(int) argc = <variable not available>
(char **) argv = <variable not available>
(char *) x = <variable not available>
(int) res = 0
(lldb)
The value of argc equal to 1 and the value of *argv is also correct.
The following is the assembly code of this old/"good" binary:
$ objdump -d a.out
a.out: file format elf64-x86-64
Disassembly of section .init:
00000000004003e0 <_init>:
4003e0: 48 83 ec 08 sub $0x8,%rsp
4003e4: 48 8b 05 0d 0c 20 00 mov 0x200c0d(%rip),%rax # 600ff8 <__gmon_start__>
4003eb: 48 85 c0 test %rax,%rax
4003ee: 74 02 je 4003f2 <_init+0x12>
4003f0: ff d0 call *%rax
4003f2: 48 83 c4 08 add $0x8,%rsp
4003f6: c3 ret
Disassembly of section .plt:
0000000000400400 <.plt>:
400400: ff 35 02 0c 20 00 push 0x200c02(%rip) # 601008 <_GLOBAL_OFFSET_TABLE_+0x8>
400406: ff 25 04 0c 20 00 jmp *0x200c04(%rip) # 601010 <_GLOBAL_OFFSET_TABLE_+0x10>
40040c: 0f 1f 40 00 nopl 0x0(%rax)
0000000000400410 <free@plt>:
400410: ff 25 02 0c 20 00 jmp *0x200c02(%rip) # 601018 <free@GLIBC_2.2.5>
400416: 68 00 00 00 00 push $0x0
40041b: e9 e0 ff ff ff jmp 400400 <.plt>
0000000000400420 <malloc@plt>:
400420: ff 25 fa 0b 20 00 jmp *0x200bfa(%rip) # 601020 <malloc@GLIBC_2.2.5>
400426: 68 01 00 00 00 push $0x1
40042b: e9 d0 ff ff ff jmp 400400 <.plt>
Disassembly of section .text:
0000000000400430 <set_fast_math>:
400430: 0f ae 5c 24 fc stmxcsr -0x4(%rsp)
400435: 81 4c 24 fc 40 80 00 orl $0x8040,-0x4(%rsp)
40043c: 00
40043d: 0f ae 54 24 fc ldmxcsr -0x4(%rsp)
400442: c3 ret
400443: 66 2e 0f 1f 84 00 00 cs nopw 0x0(%rax,%rax,1)
40044a: 00 00 00
40044d: 0f 1f 00 nopl (%rax)
0000000000400450 <_start>:
400450: 31 ed xor %ebp,%ebp
400452: 49 89 d1 mov %rdx,%r9
400455: 5e pop %rsi
400456: 48 89 e2 mov %rsp,%rdx
400459: 48 83 e4 f0 and $0xfffffffffffffff0,%rsp
40045d: 50 push %rax
40045e: 54 push %rsp
40045f: 49 c7 c0 e0 05 40 00 mov $0x4005e0,%r8
400466: 48 c7 c1 70 05 40 00 mov $0x400570,%rcx
40046d: 48 c7 c7 40 05 40 00 mov $0x400540,%rdi
400474: ff 15 76 0b 20 00 call *0x200b76(%rip) # 600ff0 <__libc_start_main@GLIBC_2.2.5>
40047a: f4 hlt
40047b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
0000000000400480 <_dl_relocate_static_pie>:
400480: f3 c3 repz ret
400482: 66 2e 0f 1f 84 00 00 cs nopw 0x0(%rax,%rax,1)
400489: 00 00 00
40048c: 0f 1f 40 00 nopl 0x0(%rax)
0000000000400490 <deregister_tm_clones>:
400490: 55 push %rbp
400491: b8 40 10 60 00 mov $0x601040,%eax
400496: 48 3d 40 10 60 00 cmp $0x601040,%rax
40049c: 48 89 e5 mov %rsp,%rbp
40049f: 74 17 je 4004b8 <deregister_tm_clones+0x28>
4004a1: b8 00 00 00 00 mov $0x0,%eax
4004a6: 48 85 c0 test %rax,%rax
4004a9: 74 0d je 4004b8 <deregister_tm_clones+0x28>
4004ab: 5d pop %rbp
4004ac: bf 40 10 60 00 mov $0x601040,%edi
4004b1: ff e0 jmp *%rax
4004b3: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
4004b8: 5d pop %rbp
4004b9: c3 ret
4004ba: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
00000000004004c0 <register_tm_clones>:
4004c0: be 40 10 60 00 mov $0x601040,%esi
4004c5: 55 push %rbp
4004c6: 48 81 ee 40 10 60 00 sub $0x601040,%rsi
4004cd: 48 89 e5 mov %rsp,%rbp
4004d0: 48 c1 fe 03 sar $0x3,%rsi
4004d4: 48 89 f0 mov %rsi,%rax
4004d7: 48 c1 e8 3f shr $0x3f,%rax
4004db: 48 01 c6 add %rax,%rsi
4004de: 48 d1 fe sar %rsi
4004e1: 74 15 je 4004f8 <register_tm_clones+0x38>
4004e3: b8 00 00 00 00 mov $0x0,%eax
4004e8: 48 85 c0 test %rax,%rax
4004eb: 74 0b je 4004f8 <register_tm_clones+0x38>
4004ed: 5d pop %rbp
4004ee: bf 40 10 60 00 mov $0x601040,%edi
4004f3: ff e0 jmp *%rax
4004f5: 0f 1f 00 nopl (%rax)
4004f8: 5d pop %rbp
4004f9: c3 ret
4004fa: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
0000000000400500 <__do_global_dtors_aux>:
400500: 80 3d 35 0b 20 00 00 cmpb $0x0,0x200b35(%rip) # 60103c <completed.7698>
400507: 75 17 jne 400520 <__do_global_dtors_aux+0x20>
400509: 55 push %rbp
40050a: 48 89 e5 mov %rsp,%rbp
40050d: e8 7e ff ff ff call 400490 <deregister_tm_clones>
400512: c6 05 23 0b 20 00 01 movb $0x1,0x200b23(%rip) # 60103c <completed.7698>
400519: 5d pop %rbp
40051a: c3 ret
40051b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
400520: f3 c3 repz ret
400522: 0f 1f 40 00 nopl 0x0(%rax)
400526: 66 2e 0f 1f 84 00 00 cs nopw 0x0(%rax,%rax,1)
40052d: 00 00 00
0000000000400530 <frame_dummy>:
400530: 55 push %rbp
400531: 48 89 e5 mov %rsp,%rbp
400534: 5d pop %rbp
400535: eb 89 jmp 4004c0 <register_tm_clones>
400537: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
40053e: 00 00
0000000000400540 <main>:
400540: 53 push %rbx
400541: bf 0a 00 00 00 mov $0xa,%edi
400546: e8 d5 fe ff ff call 400420 <malloc@plt>
40054b: 66 c7 40 08 00 00 movw $0x0,0x8(%rax)
400551: 48 c7 00 00 00 00 00 movq $0x0,(%rax)
400558: 48 63 0d d9 0a 20 00 movslq 0x200ad9(%rip),%rcx # 601038 <b>
40055f: 0f be 1c 08 movsbl (%rax,%rcx,1),%ebx
400563: 48 89 c7 mov %rax,%rdi
400566: e8 a5 fe ff ff call 400410 <free@plt>
40056b: 89 d8 mov %ebx,%eax
40056d: 5b pop %rbx
40056e: c3 ret
40056f: 90 nop
0000000000400570 <__libc_csu_init>:
400570: 41 57 push %r15
400572: 41 56 push %r14
400574: 49 89 d7 mov %rdx,%r15
400577: 41 55 push %r13
400579: 41 54 push %r12
40057b: 4c 8d 25 86 08 20 00 lea 0x200886(%rip),%r12 # 600e08 <__frame_dummy_init_array_entry>
400582: 55 push %rbp
400583: 48 8d 2d 8e 08 20 00 lea 0x20088e(%rip),%rbp # 600e18 <__do_global_dtors_aux_fini_array_entry>
40058a: 53 push %rbx
40058b: 41 89 fd mov %edi,%r13d
40058e: 49 89 f6 mov %rsi,%r14
400591: 4c 29 e5 sub %r12,%rbp
400594: 48 83 ec 08 sub $0x8,%rsp
400598: 48 c1 fd 03 sar $0x3,%rbp
40059c: e8 3f fe ff ff call 4003e0 <_init>
4005a1: 48 85 ed test %rbp,%rbp
4005a4: 74 20 je 4005c6 <__libc_csu_init+0x56>
4005a6: 31 db xor %ebx,%ebx
4005a8: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1)
4005af: 00
4005b0: 4c 89 fa mov %r15,%rdx
4005b3: 4c 89 f6 mov %r14,%rsi
4005b6: 44 89 ef mov %r13d,%edi
4005b9: 41 ff 14 dc call *(%r12,%rbx,8)
4005bd: 48 83 c3 01 add $0x1,%rbx
4005c1: 48 39 dd cmp %rbx,%rbp
4005c4: 75 ea jne 4005b0 <__libc_csu_init+0x40>
4005c6: 48 83 c4 08 add $0x8,%rsp
4005ca: 5b pop %rbx
4005cb: 5d pop %rbp
4005cc: 41 5c pop %r12
4005ce: 41 5d pop %r13
4005d0: 41 5e pop %r14
4005d2: 41 5f pop %r15
4005d4: c3 ret
4005d5: 90 nop
4005d6: 66 2e 0f 1f 84 00 00 cs nopw 0x0(%rax,%rax,1)
4005dd: 00 00 00
00000000004005e0 <__libc_csu_fini>:
4005e0: f3 c3 repz ret
Disassembly of section .fini:
00000000004005e4 <_fini>:
4005e4: 48 83 ec 08 sub $0x8,%rsp
4005e8: 48 83 c4 08 add $0x8,%rsp
4005ec: c3 ret
Ah, @jmorse looks like this might be an instrref issue? The code is optimized away entirely in both cases - so argc/argv don't actually get clobbered - but maybe they did/were being clobbered party-way through optimizations? Not sure if this is especially recoverable, but would be nice if we could.
Important point for reproduction, I think in the first post you meant to have return res; rather than return 0;? I can't reproduce without return res;. The DWARF for the subprogram in that case:
0x0000003f: DW_TAG_subprogram
DW_AT_low_pc (0x0000000000000000)
DW_AT_high_pc (0x0000000000000027)
DW_AT_frame_base (DW_OP_reg7 RSP)
DW_AT_call_all_calls (true)
DW_AT_name ("main")
DW_AT_decl_file ("/tmp/bees.c")
DW_AT_decl_line (5)
DW_AT_prototyped (true)
DW_AT_type (0x00000032 "int")
DW_AT_external (true)
0x0000004e: DW_TAG_formal_parameter
DW_AT_location (indexed (0x0) loclist = 0x0000001c:
[0x0000000000000000, 0x0000000000000006): DW_OP_reg5 RDI
[0x0000000000000006, 0x0000000000000027): DW_OP_entry_value(DW_OP_reg5 RDI), DW_OP_stack_value)
DW_AT_name ("argc")
DW_AT_decl_file ("/tmp/bees.c")
DW_AT_decl_line (5)
DW_AT_type (0x00000032 "int")
0x00000057: DW_TAG_formal_parameter
DW_AT_location (indexed (0x1) loclist = 0x0000002a:
[0x0000000000000000, 0x000000000000000b): DW_OP_reg4 RSI
[0x000000000000000b, 0x0000000000000027): DW_OP_entry_value(DW_OP_reg4 RSI), DW_OP_stack_value)
DW_AT_name ("argv")
DW_AT_decl_file ("/tmp/bees.c")
DW_AT_decl_line (5)
DW_AT_type (0x00000073 "char**")
0x00000060: DW_TAG_variable
DW_AT_location (indexed (0x2) loclist = 0x00000038:
[0x0000000000000010, 0x0000000000000023): DW_OP_reg0 RAX)
DW_AT_name ("x")
DW_AT_decl_file ("/tmp/bees.c")
DW_AT_decl_line (6)
DW_AT_type (0x00000036 "char*")
0x00000069: DW_TAG_variable
DW_AT_location (indexed (0x3) loclist = 0x0000003e:
[0x000000000000001b, 0x0000000000000026): DW_OP_reg3 RBX
[0x0000000000000026, 0x0000000000000027): DW_OP_reg0 RAX)
DW_AT_name ("res")
DW_AT_decl_file ("/tmp/bees.c")
DW_AT_decl_line (8)
DW_AT_type (0x00000032 "int")
0x00000072: NULL
And assembly:
0000000000000000 <main>:
0: 53 push %rbx
1: bf 01 00 00 00 mov $0x1,%edi
6: be 0a 00 00 00 mov $0xa,%esi
b: e8 00 00 00 00 callq 10 <main+0x10>
c: R_X86_64_PLT32 calloc-0x4
10: 48 63 0d 00 00 00 00 movslq 0x0(%rip),%rcx # 17 <main+0x17>
13: R_X86_64_PC32 b-0x4
17: 0f be 1c 08 movsbl (%rax,%rcx,1),%ebx
1b: 48 89 c7 mov %rax,%rdi
1e: e8 00 00 00 00 callq 23 <main+0x23>
13: R_X86_64_PC32 b-0x4
23: 89 d8 mov %ebx,%eax
25: 5b pop %rbx
26: c3 retq
With that in mind: the location lists look correct to me, argc and argv are in the argument registers until they're clobbered when calling calloc. For the rest of the function they're described as being available as an entry value in the relevant registers, which is AFAIUI correct.
I would imagine that the reason why lldb can't evaluate DW_OP_entry_value is because there isn't any DWARF call-site-information at the call site that would explain where the arguments can be found -- it would have to come from somewhere in the platforms crt0.o / startup object files.
IMHO this is all expected, although unfortunate.
@jmorse I am sorry. I post the wrong code. The reported problem only occurs when it comes to return res;. When the code changed to return 0;, lldb behaves corretly.
@dwblaikie I really apologize to let you know that I used the wrong code to post those dwarfdump info and the assembly code in above posts. Have update those information with the issue triggering code. Thanks for @jmorse pointing out this problem.
it's all good - I figured out and had reproduced your original failure - I forgot to call it out when referring this to @jmorse / or pointing it out to be corrected. But I did understand/had looked at the behavior you'd described and did observe the issue - hopefully @jmorse has more ideas on how to address it now that the explanation has been clarified.
Circling back to this -- my current understanding of the issue is that the output of the compiler is correct (location lists in main describe the entry value of $rdi and $rsi), however the next stack frame is below main and doesn't have any debug-info, meaning lldb can't find any call-site information.
From this comment ( https://github.com/llvm/llvm-project/issues/55760#issuecomment-1142933164 ) , am I right in thinking that you're expecting "
In that sense, it's a change in the compiler that's causing this to happen, because between LLVM 6.0 and now, we've started to emit entry values to describe variable locations. However, I believe the "could not evaluate..." output is the expected behaviour of lldb when asked to print a variable where the location is an unavailable entry value.
CC @JDevlieghere to confirm the displayed error is correct.
Yeah, with the updated/edits to the previous comments that sounds right to me - looks like (@yangyibiao could you confirm this?) the behavior's equivalent, but we went from "
@dwblaikie After reading @jmorse 's detail explanation. I agree that thest two bbehavior are equivalent and the latest one would be more precise.
Closing this as it looks like it works as intended.