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.
Please add a doxygen comment to the function.
Should we rename this to startsWithDeref?