aboutsummaryrefslogtreecommitdiff
path: root/gdb/findvar.c
diff options
context:
space:
mode:
authorKevin Buettner <kevinb@redhat.com>2016-09-27 21:18:44 -0700
committerKevin Buettner <kevinb@redhat.com>2016-11-16 11:38:19 -0700
commit41b56feb5063aee4fefb4a991eb796d1e8a7475e (patch)
treeca88891a5d6ab514db31652af8d3093386b25f58 /gdb/findvar.c
parentdf433d316277ff5293832d3cd6cbc30b5c38dec0 (diff)
downloadgdb-41b56feb5063aee4fefb4a991eb796d1e8a7475e.zip
gdb-41b56feb5063aee4fefb4a991eb796d1e8a7475e.tar.gz
gdb-41b56feb5063aee4fefb4a991eb796d1e8a7475e.tar.bz2
Change meaning of VALUE_FRAME_ID; rename to VALUE_NEXT_FRAME_ID
The VALUE_FRAME_ID macro provides access to a member in struct value that's used to hold the frame id that's used when determining a register's value or when assigning to a register. The underlying member has a long and obscure name. I won't refer to it here, but will simply refer to VALUE_FRAME_ID as if it's the struct value member instead of being a convenient macro. At the moment, without this patch in place, VALUE_FRAME_ID is set in value_of_register_lazy() and several other locations to hold the frame id of the frame passed to those functions. VALUE_FRAME_ID is used in the lval_register case of value_fetch_lazy(). To fetch the register's value, it calls get_frame_register_value() which, in turn, calls frame_unwind_register_value() with frame->next. A python based unwinder may wish to determine the value of a register or evaluate an expression containing a register. When it does this, value_fetch_lazy() will be called under some circumstances. It will attempt to determine the frame id associated with the frame passed to it. In so doing, it will end up back in the frame sniffer of the very same python unwinder that's attempting to learn the value of a register as part of the sniffing operation. This recursion is not desirable. As noted above, when value_fetch_lazy() wants to fetch a register's value, it does so (indirectly) by unwinding from frame->next. With this in mind, a solution suggests itself: Change VALUE_FRAME_ID to hold the frame id associated with the next frame. Then, when it comes time to obtain the value associated with the register, we can simply unwind from the frame corresponding to the frame id stored in VALUE_FRAME_ID. This neatly avoids the python unwinder recursion problem by changing when the "next" operation occurs. Instead of the "next" operation occuring when the register value is fetched, it occurs earlier on when assigning a frame id to VALUE_FRAME_ID. (Thanks to Pedro for this suggestion.) This patch implements this idea. It builds on the patch "Distinguish sentinel frame from null frame". Without that work in place, it's necessary to check for null_id at several places and then obtain the sentinel frame. It also renames most occurences of VALUE_FRAME_ID to VALUE_NEXT_FRAME_ID to reflect the new meaning of this field. There are several uses of VALUE_FRAME_ID which were not changed. In each case, the original meaning of VALUE_FRAME_ID is required to get correct results. In all but one of these uses, either put_frame_register_bytes() or get_frame_register_bytes() is being called with the frame value obtained from VALUE_FRAME_ID. Both of these functions perform some unwinding by performing a "->next" operation on the frame passed to it. If we were to use the new VALUE_NEXT_FRAME_ID macro, this would effectively do two "->next" operations, which is not what we want. The VALUE_FRAME_ID macro has been redefined in terms of VALUE_NEXT_FRAME_ID. It simply fetches the previous frame's id, providing this id as the value of the macro. gdb/ChangeLog: * value.h (VALUE_FRAME_ID): Rename to VALUE_NEXT_FRAME_ID. Update comment. Create new VALUE_FRAME_ID which is defined in terms of VALUE_NEXT_FRAME_ID. (deprecated_value_frame_id_hack): Rename to deprecated_value_next_frame_id_hack. * dwarf2loc.c, findvar.c, frame-unwind.c, sentinel-frame.c, valarith.c, valops.c, value.c: Adjust nearly all occurences of VALUE_FRAME_ID to VALUE_NEXT_FRAME_ID. Add comments for those which did not change. * value.c (struct value): Rename frame_id field to next_frame_id. Update comment. (deprecated_value_frame_id_hack): Rename to deprecated_value_next_frame_id_hack. (value_fetch_lazy): Call frame_unwind_register_value() instead of get_frame_register_value(). * frame.c (get_prev_frame_id_by_id): New function. * frame.h (get_prev_frame_id_by_id): Declare. * dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Make VALUE_NEXT_FRAME_ID refer to the next frame. * findvar.c (value_of_register_lazy): Likewise. (default_value_from_register): Likewise. (value_from_register): Likewise. * frame_unwind.c (frame_unwind_got_optimized): Likewise. * sentinel-frame.c (sentinel_frame_prev_register): Likewise. * value.h (VALUE_FRAME_ID): Update comment describing this macro.
Diffstat (limited to 'gdb/findvar.c')
-rw-r--r--gdb/findvar.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 6e28a29..bab717a 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -283,17 +283,23 @@ value_of_register_lazy (struct frame_info *frame, int regnum)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
struct value *reg_val;
+ struct frame_info *next_frame;
gdb_assert (regnum < (gdbarch_num_regs (gdbarch)
+ gdbarch_num_pseudo_regs (gdbarch)));
- /* We should have a valid (i.e. non-sentinel) frame. */
- gdb_assert (frame_id_p (get_frame_id (frame)));
+ gdb_assert (frame != NULL);
+
+ next_frame = get_next_frame_sentinel_okay (frame);
+
+ /* We should have a valid next frame. */
+ gdb_assert (frame_id_p (get_frame_id (next_frame)));
reg_val = allocate_value_lazy (register_type (gdbarch, regnum));
VALUE_LVAL (reg_val) = lval_register;
VALUE_REGNUM (reg_val) = regnum;
- VALUE_FRAME_ID (reg_val) = get_frame_id (frame);
+ VALUE_NEXT_FRAME_ID (reg_val) = get_frame_id (next_frame);
+
return reg_val;
}
@@ -815,9 +821,17 @@ default_value_from_register (struct gdbarch *gdbarch, struct type *type,
{
int len = TYPE_LENGTH (type);
struct value *value = allocate_value (type);
+ struct frame_info *frame;
VALUE_LVAL (value) = lval_register;
- VALUE_FRAME_ID (value) = frame_id;
+ frame = frame_find_by_id (frame_id);
+
+ if (frame == NULL)
+ frame_id = null_frame_id;
+ else
+ frame_id = get_frame_id (get_next_frame_sentinel_okay (frame));
+
+ VALUE_NEXT_FRAME_ID (value) = frame_id;
VALUE_REGNUM (value) = regnum;
/* Any structure stored in more than one register will always be
@@ -902,7 +916,7 @@ value_from_register (struct type *type, int regnum, struct frame_info *frame)
including the location. */
v = allocate_value (type);
VALUE_LVAL (v) = lval_register;
- VALUE_FRAME_ID (v) = get_frame_id (frame);
+ VALUE_NEXT_FRAME_ID (v) = get_frame_id (get_next_frame_sentinel_okay (frame));
VALUE_REGNUM (v) = regnum;
ok = gdbarch_register_to_value (gdbarch, frame, regnum, type1,
value_contents_raw (v), &optim,
@@ -950,7 +964,7 @@ address_from_register (int regnum, struct frame_info *frame)
where the ID of FRAME is not yet known. Calling value_from_register
would therefore abort in get_frame_id. However, since we only need
a temporary value that is never used as lvalue, we actually do not
- really need to set its VALUE_FRAME_ID. Therefore, we re-implement
+ really need to set its VALUE_NEXT_FRAME_ID. Therefore, we re-implement
the core of value_from_register, but use the null_frame_id. */
/* Some targets require a special conversion routine even for plain