[RFA] Limited DW_OP_piece support

Kevin Buettner
2003-05-22T17:00:47Z

The patch below adds limited DW_OP_piece support to dwarf2expr.c. I
will post a patch to rs6000-tdep.c which illustrates what a
``dwarf2_compose_register_pieces'' method should look like.

Okay?

Index: dwarf2expr.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2expr.c,v
retrieving revision 1.7
diff -u -p -r1.7 dwarf2expr.c
--- dwarf2expr.c 14 May 2003 22:45:41 -0000 1.7
+++ dwarf2expr.c 22 May 2003 16:39:14 -0000
@@ -456,6 +456,98 @@ execute_stack_op (struct dwarf_expr_cont
ctx->in_reg = 0;
}
break;
+
+ case DW_OP_piece:
+
+ if (!gdbarch_dwarf2_compose_register_pieces_p (current_gdbarch))
+ error ("DWARF-2 expression error: DW_OP_piece not supported for "
+ "this architecture.");
+ else
+ {
+ /* If the pieces consist of 2 or more registers in the
+ proper order, then gdb "will do the right thing" by
+ simply using the first register -- assuming, of course
+ that the corresponding type information is correct.
+ Otherwise, complain.
+
+ For the case that we handle, there should already be
+ a register pushed on the stack. Our strategy will
+ be to push the DW_OP_piece size information and then
+ push the next register and it's size information, etc.
+ Once that is done, an architecture specific method will
+ be called to determine which register should be used
+ to access the entire object described by the pieces.
+
+ When we've finished the stack should look like this:
+
+ reg num 1 Bottom of stack (index == 0)
+ size num 1
+ .
+ .
+ reg num N
+ size num N Top of stack (index == 2*N-1) */
+
+ CORE_ADDR regnum;
+
+ /* First check to make sure there's only one thing on the
+ stack and that's it's a register. */
+ if (ctx->stack_len != 1 || !ctx->in_reg)
+ error ("DWARF-2 expression error: DW_OP_piece expression "
+ "is too complicated.");
+
+ while (1)
+ {
+ long nextregnum;
+
+ /* Fetch the number of bytes for this piece. */
+ op_ptr = read_uleb128 (op_ptr, op_end, &uoffset);
+ dwarf_expr_push (ctx, uoffset);
+
+ /* Break out if we're done. */
+ if (op_ptr >= op_end)
+ break;
+
+ /* We expect to see a register next. */
+ op = *op_ptr++;
+ if (DW_OP_reg0 <= op && op <= DW_OP_reg31)
+ {
+ reg = op - DW_OP_reg0;
+ dwarf_expr_push (ctx, reg);
+ }
+ else if (op == DW_OP_regx)
+ {
+ op_ptr = read_uleb128 (op_ptr, op_end, &reg);
+ dwarf_expr_push (ctx, reg);
+ }
+ else
+ error ("DWARF-2 expression error: DW_OP_piece expression "
+ "is too complicated.");
+
+ /* Make sure that we haven't read too far and that
+ a DW_OP_piece operator comes next. */
+
+ if (op_ptr >= op_end || (*op_ptr!= DW_OP_piece))
+ error ("DWARF-2 expression error: DW_OP_piece expression "
+ "is too complicated.");
+
+ /* Skip over DW_OP_piece operator. */
+ op_ptr++;
+ }
+
+ result = gdbarch_dwarf2_compose_register_pieces (
+ current_gdbarch, ctx->stack_len / 2, &ctx->stack[0]);
+
+ if (result < 0)
+ error ("DWARF-2 expression error: DW_OP_piece expression "
+ "is too complicated.");
+
+ /* Note: ctx->in_reg is already set. We want result to be the
+ only thing on the stack -- it will be pushed below.
+ Make the stack empty so that this will occur. */
+ ctx->stack_len = 0;
+ }
+ break;
+
case DW_OP_dup:
result = dwarf_expr_fetch (ctx, 0);
break;
Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.237
diff -u -p -r1.237 gdbarch.sh
--- gdbarch.sh 17 May 2003 05:59:58 -0000 1.237
+++ gdbarch.sh 22 May 2003 16:39:16 -0000
@@ -471,6 +471,7 @@ f:2:DWARF_REG_TO_REGNUM:int:dwarf_reg_to
# to map one to one onto the sdb register numbers.
f:2:SDB_REG_TO_REGNUM:int:sdb_reg_to_regnum:int sdb_regnr:sdb_regnr:::no_op_reg_to_regnum::0
f:2:DWARF2_REG_TO_REGNUM:int:dwarf2_reg_to_regnum:int dwarf2_regnr:dwarf2_regnr:::no_op_reg_to_regnum::0
+M:2:DWARF2_COMPOSE_REGISTER_PIECES:long:dwarf2_compose_register_pieces:int count, CORE_ADDR *piece_info:count, piece_info
f:2:REGISTER_NAME:const char *:register_name:int regnr:regnr:::legacy_register_name::0
v::DEPRECATED_REGISTER_SIZE:int:deprecated_register_size
v::DEPRECATED_REGISTER_BYTES:int:deprecated_register_bytes