[PATCH] D23283: Debugging of optimized code: When locals have their address taken as part of a call use their stack slots as location expressions for debug info.

Wolfgang Pieb via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 8 15:24:14 PDT 2016


wolfgangp created this revision.
wolfgangp added reviewers: dblaikie, aprantl, echristo.
wolfgangp added a subscriber: llvm-commits.
Herald added a subscriber: mehdi_amini.

This patch proposes a small improvement to debug information for local variables whose address is taken and passed to a function. It is only relevant with optimization.

Example:

/******************************/
int data = 17;
int zero = 0;
int *ptr;

extern void foo(int i, int *p);

int main()
{
  int val;
  val = data;
  foo(1, &val); // <== generates indirect+0 entry
  foo(2, &data);
  return zero;
}
/*******************************/

Compiled with -O2 -g -fno-omit-frame-pointer, the dwarfdump output for 'val' shows (Linux-X86):

DW_TAG_variable
                        DW_AT_location              <loclist with 2 entries follows>
                        [ 0]<lowpc=0x0000000e><highpc=0x00000015>DW_OP_reg0 DW_OP_piece 4
                        [ 1]<lowpc=0x00000015><highpc=0x0000001f>DW_OP_breg4+0
                        DW_AT_name                  "val"

The second location list entry for 'val' is an indirection of the register that gets the address of 'val', taken by the first call to 'foo()'. 
That location list entry is only valid until the register is killed, which causes the range for the entry to be shorter than what would be feasible.

The patch proposes to detect FrameIndexSDNodes in SelectionDAG and generate FrameIndexDbgValues for them when we see a DW_op_deref expression attached to the incoming node. This will ultimately generate DBG_VALUE instructions with stack location operands, which will be valid longer than the current indirections. With the patch, dwarfdump shows:

DW_TAG_variable
                        DW_AT_location              <loclist with 2 entries follows>
                        [ 0]<lowpc=0x0000000e><highpc=0x00000015>DW_OP_reg0 DW_OP_piece 4
                        [ 1]<lowpc=0x00000015><highpc=0x0000003a>DW_OP_breg6-4
                        DW_AT_name                  "val"

Which makes 'val' visible in the debugger longer. 

Note that when the frame pointer is eliminated, we don't get a longer range for the second entry in this example. This is due to the fact that subsequent call instructions are currently deemed to imp-def the stack pointer, ending the range for val's location prematurely. This is an orthogonal issue and is best addressed separately.






https://reviews.llvm.org/D23283

Files:
  include/llvm/IR/DebugInfoMetadata.h
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  test/DebugInfo/AArch64/coalescing.ll
  test/DebugInfo/X86/bbjoin.ll
  test/DebugInfo/X86/dbg-value-const-byref.ll
  test/DebugInfo/X86/debug-loc-frame.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23283.67231.patch
Type: text/x-patch
Size: 8388 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160808/8c155890/attachment.bin>


More information about the llvm-commits mailing list