diff options
author | Andrew Burgess <aburgess@redhat.com> | 2022-03-16 17:32:25 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2022-04-03 17:18:20 +0100 |
commit | 1fb43cf75982f17c27ee0c72328de41750213689 (patch) | |
tree | 9dbc96b03e4422beaa1f6b223e68e161d3ab9c2c | |
parent | 22480d7c3977df6a111a1c1ab56982372732f4e5 (diff) | |
download | gdb-1fb43cf75982f17c27ee0c72328de41750213689.zip gdb-1fb43cf75982f17c27ee0c72328de41750213689.tar.gz gdb-1fb43cf75982f17c27ee0c72328de41750213689.tar.bz2 |
gdb/dwarf: pass an array of values to the dwarf evaluator
When we need to evaluate a DWARF expression in order to resolve some
dynamic property of a type we call the dwarf2_evaluate_property
function, which is declared in gdb/dwarf/loc.h and defined in
gdb/dwarf/loc.c.
Currently, this function takes (amongst other things) an argument of
type property_addr_info called addr_stack and a boolean called
push_initial_value. When push_initial_value then the top value of
addr_stack is pushed onto the dwarf expression evaluation stack before
the expression is evaluated.
So far this has worked fine, as the only two cases we needed to handle
are the case the DWARF expression doesn't require the object
address (what the top of addr_stack represents), and the case where
the DWARF expression does require the address.
In the next commit this is going to change. As we add support for
Fortran assumed rank arrays, we need to start resolving the dynamic
properties of arrays. To do this, we need to push the array rank onto
the dwarf expression evaluation stack before the expression is
evaluated.
This commit is a refactoring commit aimed at making it easier to
support Fortran assumed rank arrays. Instead of passing a boolean,
and using this to decide if we should push the object address or not,
we instead pass an array (view) of values that should be pushed to the
dwarf expression evaluation stack.
In the couple of places where we previously passed push_initial_value
as true (mostly this was defaulting to false), we now have to pass the
address from the addr_stack as an item in the array view.
In the next commit, when we want to handle passing the array rank,
this will easily be supported too.
There should be no user visible changes after this commit.
-rw-r--r-- | gdb/dwarf2/loc.c | 21 | ||||
-rw-r--r-- | gdb/dwarf2/loc.h | 8 | ||||
-rw-r--r-- | gdb/gdbtypes.c | 2 | ||||
-rw-r--r-- | gdb/gnu-v3-abi.c | 2 |
4 files changed, 16 insertions, 17 deletions
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index 634b51e..bb9778d 100644 --- a/gdb/dwarf2/loc.c +++ b/gdb/dwarf2/loc.c @@ -1570,10 +1570,9 @@ dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame, evaluated. ADDR_STACK is a context (location of a variable) and might be needed to evaluate the location expression. - PUSH_INITIAL_VALUE is true if the first address from ADDR_STACK, should - be pushed on the DWARF expression evaluation stack before evaluating the - expression; this is required by certain forms of DWARF expression. When - PUSH_INITIAL_VALUE is true ADDR_STACK can't be nullptr. + PUSH_VALUES is an array of values to be pushed to the expression stack + before evaluation starts. PUSH_VALUES[0] is pushed first, then + PUSH_VALUES[1], and so on. Returns 1 on success, 0 otherwise. */ @@ -1582,7 +1581,7 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton, struct frame_info *frame, const struct property_addr_info *addr_stack, CORE_ADDR *valp, - bool push_initial_value, + gdb::array_view<CORE_ADDR> push_values, bool *is_reference) { if (dlbaton == NULL || dlbaton->size == 0) @@ -1595,11 +1594,9 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton, value *result; scoped_value_mark free_values; - if (push_initial_value) - { - gdb_assert (addr_stack != nullptr); - ctx.push_address (addr_stack->addr, false); - } + /* Place any initial values onto the expression stack. */ + for (const auto &val : push_values) + ctx.push_address (val, false); try { @@ -1645,7 +1642,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, struct frame_info *frame, const struct property_addr_info *addr_stack, CORE_ADDR *value, - bool push_initial_value) + gdb::array_view<CORE_ADDR> push_values) { if (prop == NULL) return false; @@ -1663,7 +1660,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, bool is_reference = baton->locexpr.is_reference; if (dwarf2_locexpr_baton_eval (&baton->locexpr, frame, addr_stack, - value, push_initial_value, &is_reference)) + value, push_values, &is_reference)) { if (is_reference) { diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h index cf02f60..a9834d3 100644 --- a/gdb/dwarf2/loc.h +++ b/gdb/dwarf2/loc.h @@ -114,14 +114,16 @@ struct property_addr_info Returns true if PROP could be converted and the static value is passed back into VALUE, otherwise returns false. - If PUSH_INITIAL_VALUE is true, then the top value of ADDR_STACK - will be pushed before evaluating a location expression. */ + Any values in PUSH_VALUES will be pushed before evaluating the location + expression, PUSH_VALUES[0] will be pushed first, then PUSH_VALUES[1], + etc. This means the during evaluation PUSH_VALUES[0] will be at the + bottom of the stack. */ bool dwarf2_evaluate_property (const struct dynamic_prop *prop, struct frame_info *frame, const struct property_addr_info *addr_stack, CORE_ADDR *value, - bool push_initial_value = false); + gdb::array_view<CORE_ADDR> push_values = {}); /* A helper for the compiler interface that compiles a single dynamic property to C code. diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 1769796..ae3b4cd 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -2601,7 +2601,7 @@ resolve_dynamic_struct (struct type *type, CORE_ADDR addr; if (dwarf2_evaluate_property (&prop, nullptr, addr_stack, &addr, - true)) + {addr_stack->addr})) resolved_type->field (i).set_loc_bitpos (TARGET_CHAR_BIT * (addr - addr_stack->addr)); } diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c index b8640d6..baf015b 100644 --- a/gdb/gnu-v3-abi.c +++ b/gdb/gnu-v3-abi.c @@ -483,7 +483,7 @@ gnuv3_baseclass_offset (struct type *type, int index, CORE_ADDR result; if (dwarf2_evaluate_property (&prop, nullptr, &addr_stack, &result, - true)) + {addr_stack.addr})) return (int) (result - addr_stack.addr); } |