Support partial objects for DW_OP_piece
/DW_OP_bit_piece
#322
Labels
debuginfo
Support for debugging information formats
DW_OP_piece
/DW_OP_bit_piece
#322
Background
DWARF specifies the location of a variable (local or global) with a "location description". See section 2.6 in the DWARF 5 specification. A location description is essentially a series of instructions that, when executed, gives the address or value of the desired variable. drgn has code that evaluates a location description and translates it into a drgn object: see
drgn_object_from_dwarf_location()
anddrgn_eval_dwarf_expression()
.DWARF location descriptions have two operations,
DW_OP_piece
andDW_OP_bit_piece
(section 2.6.1.2 in the DWARF 5 spec), that describe a piece of an object instead of the whole object. These can even be used to describe an object whose value is partially known, partially unknown, and/or partially in memory.Example
Consider the following (contrived) source file compiled with
gcc -O2
:And the generated assembly code:
Note that
s
is not actually present in memory. However, its value can still be recovered, as the DWARF information shows:s.a
is always 1. Thelit1, stack_value, piece 4
sequence at the beginning of every location description means that the first 4 byte piece ofs
has the value 1.s.b
varies throughout the function, but the part relevant to this issue is the first address range, 0x401040-0x401048. This range is from the beginning of the function up to and thecall rand
instruction. The lonepiece 4
means that the second 4 byte piece ofs
has an unknown value. (In the other two address ranges, the value ofs.b
can be recovered, and the location description defines how to do that.)Problem Statement
drgn can handle cases of
DW_OP_piece
/DW_OP_bit_piece
where the entire object's value can be recovered. However, for more complicated cases, drgn loses precision and represents the "least common denominator":drgn/libdrgn/dwarf_info.c
Lines 5056 to 5071 in c69e5b1
(Note that case 4 is #173.) In other words, the second and third address ranges above could be represented exactly by drgn, but the first address range would be returned as entirely unknown even though
s.a
is known. This is mainly because drgn doesn't have a way to represent a value that is partially known, partially unknown, and/or partially in memory. To support this, we need to:DW_OP_piece
andDW_OP_bit_piece
using that.The text was updated successfully, but these errors were encountered: