Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DebugInfo@O2] Poor coverage for frame index variable locations #49629

Open
OCHyams opened this issue May 10, 2021 · 4 comments
Open

[DebugInfo@O2] Poor coverage for frame index variable locations #49629

OCHyams opened this issue May 10, 2021 · 4 comments
Labels
bugzilla Issues migrated from bugzilla debuginfo llvm:codegen

Comments

@OCHyams
Copy link
Contributor

OCHyams commented May 10, 2021

Bugzilla Link 50285
Version trunk
OS Linux
Blocks #38116
CC @dwblaikie,@jmorse,@jdm

Extended Description

In the reproducer below, the variable 'local' has no location around the call to 'ext' when built with "-O2 -g -c" (targeting x86_64-unknown-linux-gnu):

clang built at 71597d4.

$ cat test.cpp
void ext(int, int, int, int, int, int, int, int, int, int);
void escape(int*);
int example() {
int local = 0;
escape(&local);
ext(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
local += 2;
return local;
}

$ clang -O2 -g -c test.cpp -o test.o

$ llvm-objdump -d test.o
test.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <_Z7examplev>:
0: 50 pushq %rax
1: c7 44 24 04 00 00 00 00 movl $0, 4(%rsp)
9: 48 8d 7c 24 04 leaq 4(%rsp), %rdi
e: e8 00 00 00 00 callq 0x13 <_Z7examplev+0x13>
13: 31 ff xorl %edi, %edi
15: be 01 00 00 00 movl $1, %esi
1a: ba 02 00 00 00 movl $2, %edx
1f: b9 03 00 00 00 movl $3, %ecx
24: 41 b8 04 00 00 00 movl $4, %r8d
2a: 41 b9 05 00 00 00 movl $5, %r9d
30: 6a 09 pushq $9
32: 6a 08 pushq $8
34: 6a 07 pushq $7
36: 6a 06 pushq $6
38: e8 00 00 00 00 callq 0x3d <_Z7examplev+0x3d>
3d: 48 83 c4 20 addq $32, %rsp
41: 8b 44 24 04 movl 4(%rsp), %eax
45: 83 c0 02 addl $2, %eax
48: 59 popq %rcx
49: c3 retq

$ llvm-dwarfdump test.o --name local
test.o: file format elf64-x86-64
0x00000047: DW_TAG_variable
DW_AT_location (0x00000000:
[0x0000000000000001, 0x0000000000000009): DW_OP_consts +0, DW_OP_stack_value
[0x0000000000000009, 0x0000000000000032): DW_OP_breg7 RSP+4
[0x0000000000000045, 0x000000000000004a): DW_OP_reg0 RAX)
DW_AT_name ("local")
DW_AT_decl_file ("test.cpp")
DW_AT_decl_line (4)

The variable 'local' is not given a location over the interval [32, 45) even though its stack home is still valid here (RSP+8, RSP+12, ...).

@OCHyams
Copy link
Contributor Author

OCHyams commented May 10, 2021

It looks like the DBG_VALUE describing the stack home uses a frame index location which is rewritten in terms of RSP by Prologue/Epilogue Insertion (prologepilog). DbgEntityHistoryCalculator then terminates the location range at the first stack adjustment because RSP is clobbered.

This has been discussed on llvm-dev with the subject line "[llvm-dev] [debug-info] Stack pointer based variable locations". The preferred solution currently appears to be to set DW_AT_frame_base to DW_OP_call_frame_cfa in the parent subroutine DIE and use DW_OP_fbreg to describe the stack location.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 27, 2022

@llvm/issue-subscribers-debuginfo

@OCHyams
Copy link
Contributor Author

OCHyams commented May 17, 2023

Note: the first part of the solution

Set DW_AT_frame_base to DW_OP_call_frame_cfa in the parent subroutine DIE

appears to be implemented in D143463 .

@khuey
Copy link
Contributor

khuey commented May 23, 2023

Unfortunately LLDB issues (#62840 and #62841) prevented me from using DW_OP_call_frame_cfa across the board in D143463.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla debuginfo llvm:codegen
Projects
None yet
Development

No branches or pull requests

4 participants