/* DWARF 2 Expression Evaluator.
- Copyright (C) 2001, 2002, 2003, 2005, 2007, 2008, 2009, 2010, 2011
- Free Software Foundation, Inc.
+ Copyright (C) 2001-2003, 2005, 2007-2012 Free Software Foundation,
+ Inc.
Contributed by Daniel Berlin (dan@dberlin.org)
return dwarf_reg;
}
+/* If <BUF..BUF_END] contains DW_FORM_block* with just DW_OP_breg*(0) and
+ DW_OP_deref* return the DWARF register number. Otherwise return -1.
+ DEREF_SIZE_RETURN contains -1 for DW_OP_deref; otherwise it contains the
+ size from DW_OP_deref_size. */
+
+int
+dwarf_block_to_dwarf_reg_deref (const gdb_byte *buf, const gdb_byte *buf_end,
+ CORE_ADDR *deref_size_return)
+{
+ ULONGEST dwarf_reg;
+ LONGEST offset;
+
+ if (buf_end <= buf)
+ return -1;
+ if (*buf >= DW_OP_breg0 && *buf <= DW_OP_breg31)
+ {
+ dwarf_reg = *buf - DW_OP_breg0;
+ buf++;
+ }
+ else if (*buf == DW_OP_bregx)
+ {
+ buf++;
+ buf = read_uleb128 (buf, buf_end, &dwarf_reg);
+ if ((int) dwarf_reg != dwarf_reg)
+ return -1;
+ }
+ else
+ return -1;
+
+ buf = read_sleb128 (buf, buf_end, &offset);
+ if (offset != 0)
+ return -1;
+
+ if (buf >= buf_end)
+ return -1;
+
+ if (*buf == DW_OP_deref)
+ {
+ buf++;
+ *deref_size_return = -1;
+ }
+ else if (*buf == DW_OP_deref_size)
+ {
+ buf++;
+ if (buf >= buf_end)
+ return -1;
+ *deref_size_return = *buf++;
+ }
+ else
+ return -1;
+
+ if (buf != buf_end)
+ return -1;
+
+ return dwarf_reg;
+}
+
+/* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_fbreg(X) fill
+ in FB_OFFSET_RETURN with the X offset and return 1. Otherwise return 0. */
+
+int
+dwarf_block_to_fb_offset (const gdb_byte *buf, const gdb_byte *buf_end,
+ CORE_ADDR *fb_offset_return)
+{
+ LONGEST fb_offset;
+
+ if (buf_end <= buf)
+ return 0;
+
+ if (*buf != DW_OP_fbreg)
+ return 0;
+ buf++;
+
+ buf = read_sleb128 (buf, buf_end, &fb_offset);
+ *fb_offset_return = fb_offset;
+ if (buf != buf_end || fb_offset != (LONGEST) *fb_offset_return)
+ return 0;
+
+ return 1;
+}
+
+/* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_bregSP(X) fill
+ in SP_OFFSET_RETURN with the X offset and return 1. Otherwise return 0.
+ The matched SP register number depends on GDBARCH. */
+
+int
+dwarf_block_to_sp_offset (struct gdbarch *gdbarch, const gdb_byte *buf,
+ const gdb_byte *buf_end, CORE_ADDR *sp_offset_return)
+{
+ ULONGEST dwarf_reg;
+ LONGEST sp_offset;
+
+ if (buf_end <= buf)
+ return 0;
+ if (*buf >= DW_OP_breg0 && *buf <= DW_OP_breg31)
+ {
+ dwarf_reg = *buf - DW_OP_breg0;
+ buf++;
+ }
+ else
+ {
+ if (*buf != DW_OP_bregx)
+ return 0;
+ buf++;
+ buf = read_uleb128 (buf, buf_end, &dwarf_reg);
+ }
+
+ if (gdbarch_dwarf2_reg_to_regnum (gdbarch, dwarf_reg)
+ != gdbarch_sp_regnum (gdbarch))
+ return 0;
+
+ buf = read_sleb128 (buf, buf_end, &sp_offset);
+ *sp_offset_return = sp_offset;
+ if (buf != buf_end || sp_offset != (LONGEST) *sp_offset_return)
+ return 0;
+
+ return 1;
+}
+
/* The engine for the expression evaluator. Using the context in CTX,
evaluate the expression between OP_PTR and OP_END. */
{
op_ptr += len;
ctx->funcs->push_dwarf_reg_entry_value (ctx, dwarf_reg,
- 0 /* unused */);
+ 0 /* unused */,
+ -1 /* deref_size */);
+ goto no_push;
+ }
+
+ dwarf_reg = dwarf_block_to_dwarf_reg_deref (op_ptr, op_ptr + len,
+ &deref_size);
+ if (dwarf_reg != -1)
+ {
+ if (deref_size == -1)
+ deref_size = ctx->addr_size;
+ op_ptr += len;
+ ctx->funcs->push_dwarf_reg_entry_value (ctx, dwarf_reg,
+ 0 /* unused */,
+ deref_size);
goto no_push;
}
error (_("DWARF-2 expression error: DW_OP_GNU_entry_value is "
- "supported only for single DW_OP_reg*"));
+ "supported only for single DW_OP_reg* "
+ "or for DW_OP_breg*(0)+DW_OP_deref*"));
}
case DW_OP_GNU_const_type:
gdb_assert (ctx->recursion_depth >= 0);
}
-/* Stub dwarf_expr_context_funcs.read_reg implementation. */
-
-CORE_ADDR
-ctx_no_read_reg (void *baton, int regnum)
-{
- error (_("Registers access is invalid in this context"));
-}
-
/* Stub dwarf_expr_context_funcs.get_frame_base implementation. */
void
void
ctx_no_push_dwarf_reg_entry_value (struct dwarf_expr_context *ctx,
- int dwarf_reg, CORE_ADDR fb_offset)
+ int dwarf_reg, CORE_ADDR fb_offset,
+ int deref_size)
{
internal_error (__FILE__, __LINE__,
_("Support for DW_OP_GNU_entry_value is unimplemented"));