On Tue, Dec 04, 2012 at 12:59:11PM +0530, Senthil Kumar Selvaraj wrote: > As a follow-up to this discussion > (http://gcc.gnu.org/ml/gcc/2012-11/msg00307.html), I have a patch that > makes dwarf2out.c emit correct location information for a FP register spanning > multiple hard regs. > > Before the patch, the DW_AT_location for a local variable on the AVR > target (whose FP spans registers R29 and R28) looks like this > <4f> DW_AT_location : 2 byte block: 8c 1 (DW_OP_breg28 (r28): 1) > > After the patch, it looks like this > <4f> DW_AT_location : 11 byte block: 6c 93 1 6d 93 1 11 1 22 94 2 > (DW_OP_reg28 (r28); DW_OP_piece: 1; DW_OP_reg29 (r29); DW_OP_piece: 1; > DW_OP_consts: 1; DW_OP_plus; DW_OP_deref_size: 2) > > What do you guys think?
That is invalid DWARF. Most DW_OP_* opcodes are usable in DWARF expressions, but not all of them, and DW_OP_reg0..DW_OP_reg31/DW_OP_regx/DW_OP_piece/DW_OP_bit_piece /DW_OP_implicit_value/DW_OP_stack_value/DW_OP_GNU_implicit_pointer are the exceptions that can't be used in DWARF expressions. Then there are DWARF location descriptions, which can be: 1) memory location descriptions (a sequence of DWARF expression opcodes) 2) register location descriptions (one of DW_OP_reg0..DW_OP_reg31 or DW_OP_regx) 3) implicit location descriptions, either DW_OP_implicit_value alone, or DWARF expression opcodes followed by DW_OP_stack_value 4) implicit pointer, DW_OP_GNU_implicit_pointer 5) composite location description (a series of 1), 2), 3) or 4) followed by DW_OP_piece or DW_OP_bit_piece So, you can't put any DWARF expression opcodes after DW_OP_reg* or DW_OP_piece. If your registers are 8-bit, but pointers 16-bit, the question is what the consumers actually push into the DWARF stack on say DW_OP_bregx, if they push just one 8-bit register (and, is it zero or sign extending?), then perhaps you could emit for say based_loc_register register 4 with offset 16 if register 4 is 8-bit something like (assuming little endian): DW_OP_breg5 <0> DW_OP_lit8 DW_OP_shl DW_OP_breg4 <0> DW_OP_const1u <0xff> DW_OP_and DW_OP_plus DW_OP_plus_uconst <offset> (for positive offset, for negative offset you'd want int_loc_descriptor (offset) followed by DW_OP_plus. That will put there (reg5<<8)+(reg4&0xff)+offset. DW_OP_deref* shouldn't be used, DWARF expression is simply a memory location description ( 1) above) by default. Jakub