<div dir="auto">Hello,<div dir="auto">If its really so, if i could, id vote for implementing full debuginfo as default and maybe left optimized path as optional. If that matters to anyone. It will help in tracking locals while debugging.</div><div dir="auto"><br></div><div dir="auto">Best regards,</div><div dir="auto">Pawel Kunio</div><div dir="auto"><br></div><div dir="auto"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">czw., 6.05.2021, 19:51 użytkownik via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> napisał:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-GB" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="m_-2062243056245460616WordSection1">
<p class="MsoNormal">Hello llvm-dev,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I've noticed some behaviour I found surprising with the way that we emit stack pointer relative<u></u><u></u></p>
<p class="MsoNormal">variable locations. It seems that locations defined by DBG_VALUEs that are written in terms of RSP<u></u><u></u></p>
<p class="MsoNormal">(for x86) are terminated by any stack manipulation operations, e.g. pushing arguments before a<u></u><u></u></p>
<p class="MsoNormal">call. Since we know the stack offset at each adjustment it seems like we could maintain the variable<u></u><u></u></p>
<p class="MsoNormal">location by generating location list entries with adjusted RSP offsets.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Here's a source reproducer with clang built at 71597d40e878 (recent), target<u></u><u></u></p>
<p class="MsoNormal">x86_64-unknown-linux-gnu).<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">$ cat test.cpp<u></u><u></u></p>
<p class="MsoNormal">void ext(int, int, int, int, int, int, int, int, int, int);<u></u><u></u></p>
<p class="MsoNormal">void escape(int*);<u></u><u></u></p>
<p class="MsoNormal">int example() {<u></u><u></u></p>
<p class="MsoNormal"> int local = 0;<u></u><u></u></p>
<p class="MsoNormal"> escape(&local);<u></u><u></u></p>
<p class="MsoNormal"> ext(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);<u></u><u></u></p>
<p class="MsoNormal"> local += 2;<u></u><u></u></p>
<p class="MsoNormal"> return local;<u></u><u></u></p>
<p class="MsoNormal">}<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">$ clang -O2 -g -c test.cpp -o test.o<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">$ llvm-objdump -d test.o<u></u><u></u></p>
<p class="MsoNormal">test.o: file format elf64-x86-64<u></u><u></u></p>
<p class="MsoNormal">Disassembly of section .text:<u></u><u></u></p>
<p class="MsoNormal">0000000000000000 <_Z7examplev>:<u></u><u></u></p>
<p class="MsoNormal"> 0: 50 pushq %rax<u></u><u></u></p>
<p class="MsoNormal"> 1: c7 44 24 04 00 00 00 00 movl $0, 4(%rsp)<u></u><u></u></p>
<p class="MsoNormal"> 9: 48 8d 7c 24 04 leaq 4(%rsp), %rdi<u></u><u></u></p>
<p class="MsoNormal"> e: e8 00 00 00 00 callq 0x13 <_Z7examplev+0x13><u></u><u></u></p>
<p class="MsoNormal"> 13: 31 ff xorl %edi, %edi<u></u><u></u></p>
<p class="MsoNormal"> 15: be 01 00 00 00 movl $1, %esi<u></u><u></u></p>
<p class="MsoNormal"> 1a: ba 02 00 00 00 movl $2, %edx<u></u><u></u></p>
<p class="MsoNormal"> 1f: b9 03 00 00 00 movl $3, %ecx<u></u><u></u></p>
<p class="MsoNormal"> 24: 41 b8 04 00 00 00 movl $4, %r8d<u></u><u></u></p>
<p class="MsoNormal"> 2a: 41 b9 05 00 00 00 movl $5, %r9d<u></u><u></u></p>
<p class="MsoNormal"> 30: 6a 09 pushq $9<u></u><u></u></p>
<p class="MsoNormal"> 32: 6a 08 pushq $8<u></u><u></u></p>
<p class="MsoNormal"> 34: 6a 07 pushq $7<u></u><u></u></p>
<p class="MsoNormal"> 36: 6a 06 pushq $6<u></u><u></u></p>
<p class="MsoNormal"> 38: e8 00 00 00 00 callq 0x3d <_Z7examplev+0x3d><u></u><u></u></p>
<p class="MsoNormal"> 3d: 48 83 c4 20 addq $32, %rsp<u></u><u></u></p>
<p class="MsoNormal"> 41: 8b 44 24 04 movl 4(%rsp), %eax<u></u><u></u></p>
<p class="MsoNormal"> 45: 83 c0 02 addl $2, %eax<u></u><u></u></p>
<p class="MsoNormal"> 48: 59 popq %rcx<u></u><u></u></p>
<p class="MsoNormal"> 49: c3 retq<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">$ llvm-dwarfdump test.o --name local<u></u><u></u></p>
<p class="MsoNormal">test.o: file format elf64-x86-64<u></u><u></u></p>
<p class="MsoNormal">0x00000047: DW_TAG_variable<u></u><u></u></p>
<p class="MsoNormal"> DW_AT_location (0x00000000: <u></u>
<u></u></p>
<p class="MsoNormal"> [0x0000000000000001, 0x0000000000000009): DW_OP_consts +0, DW_OP_stack_value<u></u><u></u></p>
<p class="MsoNormal"> [0x0000000000000009, 0x0000000000000032): DW_OP_breg7 RSP+4<u></u><u></u></p>
<p class="MsoNormal"> [0x0000000000000045, 0x000000000000004a): DW_OP_reg0 RAX)<u></u><u></u></p>
<p class="MsoNormal"> DW_AT_name ("local")<u></u><u></u></p>
<p class="MsoNormal"> DW_AT_decl_file ("/home/och/dev/bugs/scratch/test.cpp")<u></u><u></u></p>
<p class="MsoNormal"> DW_AT_decl_line (4)<u></u><u></u></p>
<p class="MsoNormal"> DW_AT_type (0x000000ad "int")<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">The variable 'local' is not given a location over the interval [32, 45) even though we<u></u><u></u></p>
<p class="MsoNormal">know where it is (RSP+8, RSP+12, ..., back to RSP+4 after the stack adjustment following the<u></u><u></u></p>
<p class="MsoNormal">call). It seems unfortunate to lose variable locations in this way, especially around call sites. Is<u></u><u></u></p>
<p class="MsoNormal">this a deliberate omission, perhaps made in order to save space? Jeremy mentioned that we do<u></u><u></u></p>
<p class="MsoNormal">something similar in prologues/epilogues to avoid generating large location lists.<br>
<br>
<u></u><u></u></p>
<p class="MsoNormal">Many thanks,<u></u><u></u></p>
<p class="MsoNormal">Orlando<u></u><u></u></p>
</div>
</div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" rel="noreferrer">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>