[Dwarf-Discuss] DW_OP_ encoding

David Earlam David.Earlam@csr.com
Mon Nov 1 11:41:37 GMT 2010

I now know to watch out when the producer naively encodes DW_OP_reg(x)
as a macro
 .byte DW_OP_REG0 + x 
and x can be more than 31. 

That can incorrectly become a DW_OP_breg(x-32) with no following SLEB128
offset operand. 

The usually excellent libdwarf for one does not detect the missing
operand in the location list. Our symptom was the debugger couldn't
display some variable values in optimized code.

This mistake is all too easily made when reading Dwarf3/Dwarf4 spec
'Figure 24 DWARF operation encodings' on page 144/167 which says just
'DW_OP_REG0 + regnum'.

Dwarf2 equally unhelpfully said 'DW_OP_REG0 | regnum' in 'Figure 23
Location operation encodings part2'

I think the spec should say something like
    'DW_OP_REG0 + (regnum & 0x1F), where 0 <= regnum <= 31'

Same applies for DW_OP_lit and DW_OP_breg.

kind regards, 

Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom

More information about the Dwarf-discuss mailing list