aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2expr.h
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2017-09-14 22:36:57 +0200
committerSimon Marchi <simon.marchi@ericsson.com>2017-09-14 22:36:57 +0200
commitd185219da329805075ba5e0e72ec4c89c925cff2 (patch)
treee0c67acb37781d15ef668c142141cfc3603363c8 /gdb/dwarf2expr.h
parent79254a5260cf49887b4017700bd75b27f483b322 (diff)
downloadgdb-d185219da329805075ba5e0e72ec4c89c925cff2.zip
gdb-d185219da329805075ba5e0e72ec4c89c925cff2.tar.gz
gdb-d185219da329805075ba5e0e72ec4c89c925cff2.tar.bz2
Make dwarf_expr_context::stack an std::vector
Replace the manually managed array with a vector. It is mostly straightforward, except maybe one thing in execute_stack_op, in the handling of DW_OP_fbreg. When the code stumbles on that opcode while evaluating an expression, it needs to evaluate a subexpression to find where the fb reg has been saved. Rather than creating a new context, it reuses the current context. It saves the size of the stack before and restores the stack to that size after. I think we can do a little bit better by saving the current stack locally and installing a new empty stack. This way, if the subexpression is malformed and underflows, we'll get an exception. Before, it would have overwritten the top elements of the top-level expression. The evaluation of the top-level expression would have then resumed with the same stack size, but possibly some corrupted elements. gdb/ChangeLog: * dwarf2expr.h (dwarf_stack_value): Add constructor. (dwarf_expr_context) <~dwarf_expr_context>: Define as default. <stack>: Change type to std::vector. <stack_len, stack_allocated>: Remove. <grow_stack>: Remove. * dwarf2expr.c (dwarf_expr_context::dwarf_expr_context): Adjust. (dwarf_expr_context::~dwarf_expr_context): Remove. (dwarf_expr_context::grow_stack): Remove. (dwarf_expr_context::push): Adjust. (dwarf_expr_context::pop): Adjust. (dwarf_expr_context::fetch): Adjust. (dwarf_expr_context::fetch_in_stack_memory): Adjust. (dwarf_expr_context::stack_empty_p): Adjust. (dwarf_expr_context::execute_stack_op): Adjust.
Diffstat (limited to 'gdb/dwarf2expr.h')
-rw-r--r--gdb/dwarf2expr.h15
1 files changed, 7 insertions, 8 deletions
diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2expr.h
index 0a57bee..a8d6ae1 100644
--- a/gdb/dwarf2expr.h
+++ b/gdb/dwarf2expr.h
@@ -100,6 +100,10 @@ struct dwarf_expr_piece
struct dwarf_stack_value
{
+ dwarf_stack_value (struct value *value_, int in_stack_memory_)
+ : value (value_), in_stack_memory (in_stack_memory_)
+ {}
+
struct value *value;
/* True if the piece is in memory and is known to be on the program's stack.
@@ -114,7 +118,7 @@ struct dwarf_stack_value
struct dwarf_expr_context
{
dwarf_expr_context ();
- virtual ~dwarf_expr_context ();
+ virtual ~dwarf_expr_context () = default;
void push_address (CORE_ADDR value, bool in_stack_memory);
void eval (const gdb_byte *addr, size_t len);
@@ -122,12 +126,8 @@ struct dwarf_expr_context
CORE_ADDR fetch_address (int n);
bool fetch_in_stack_memory (int n);
- /* The stack of values, allocated with xmalloc. */
- struct dwarf_stack_value *stack;
-
- /* The number of values currently pushed on the stack, and the
- number of elements allocated to the stack. */
- int stack_len, stack_allocated;
+ /* The stack of values. */
+ std::vector<dwarf_stack_value> stack;
/* Target architecture to use for address operations. */
struct gdbarch *gdbarch;
@@ -249,7 +249,6 @@ struct dwarf_expr_context
private:
struct type *address_type () const;
- void grow_stack (size_t need);
void push (struct value *value, bool in_stack_memory);
bool stack_empty_p () const;
void add_piece (ULONGEST size, ULONGEST offset);