Make dwarf_expr_piece::pieces an std::vector

Change the manually managed array dwarf_expr_piece::piece with an
std::vector.  After passing the pieces array to allocate_piece_closure,
dwarf2_evaluate_loc_desc_full doesn't need that data anymore.  We can
therefore move the content of the vector to avoid copying it.

Reg-tested on the buildbot.

gdb/ChangeLog:

	* dwarf2expr.h (struct dwarf_expr_piece): Move up.
	(struct dwarf_expr_context) <n_pieces>: Remove.
	<pieces>: Change type to std::vector.
	* dwarf2expr.c (dwarf_expr_context::dwarf_expr_context): Adjust.
	(dwarf_expr_context::~dwarf_expr_context): Don't manually free
	pieces.
	(dwarf_expr_context::add_piece): Adjust.
	* dwarf2loc.c (struct piece_closure): Initialize fields.
	<n_pieces>: Remove.
	<pieces>: Change type to std::vector.
	(allocate_piece_closure): Adjust, change parameter to
	std::vector rvalue and std::move it to piece_closure.
	(rw_pieced_value): Adjust.
	(check_pieced_synthetic_pointer): Adjust.
	(indirect_synthetic_pointer): Adjust.
	(coerce_pieced_ref): Adjust.
	(free_pieced_value_closure):  Adjust.  Use delete to free
	piece_closure.
	(dwarf2_evaluate_loc_desc_full): Adjust.  std::move ctx.pieces
	to allocate_piece_closure.
	(dwarf2_loc_desc_get_symbol_read_needs): Adjust.
This commit is contained in:
Simon Marchi 2017-09-14 15:57:01 +02:00
parent 4d465c689a
commit 1e46716193
4 changed files with 124 additions and 124 deletions

View file

@ -100,9 +100,7 @@ dwarf_expr_context::dwarf_expr_context ()
location (DWARF_VALUE_MEMORY),
len (0),
data (NULL),
initialized (0),
num_pieces (0),
pieces (NULL)
initialized (0)
{
this->stack = XNEWVEC (struct dwarf_stack_value, this->stack_allocated);
}
@ -112,7 +110,6 @@ dwarf_expr_context::dwarf_expr_context ()
dwarf_expr_context::~dwarf_expr_context ()
{
xfree (this->stack);
xfree (this->pieces);
}
/* Expand the memory allocated stack to contain at least
@ -285,47 +282,42 @@ dwarf_expr_context::stack_empty_p () const
void
dwarf_expr_context::add_piece (ULONGEST size, ULONGEST offset)
{
struct dwarf_expr_piece *p;
this->pieces.emplace_back ();
dwarf_expr_piece &p = this->pieces.back ();
this->num_pieces++;
p.location = this->location;
p.size = size;
p.offset = offset;
this->pieces
= XRESIZEVEC (struct dwarf_expr_piece, this->pieces, this->num_pieces);
p = &this->pieces[this->num_pieces - 1];
p->location = this->location;
p->size = size;
p->offset = offset;
if (p->location == DWARF_VALUE_LITERAL)
if (p.location == DWARF_VALUE_LITERAL)
{
p->v.literal.data = this->data;
p->v.literal.length = this->len;
p.v.literal.data = this->data;
p.v.literal.length = this->len;
}
else if (stack_empty_p ())
{
p->location = DWARF_VALUE_OPTIMIZED_OUT;
p.location = DWARF_VALUE_OPTIMIZED_OUT;
/* Also reset the context's location, for our callers. This is
a somewhat strange approach, but this lets us avoid setting
the location to DWARF_VALUE_MEMORY in all the individual
cases in the evaluator. */
this->location = DWARF_VALUE_OPTIMIZED_OUT;
}
else if (p->location == DWARF_VALUE_MEMORY)
else if (p.location == DWARF_VALUE_MEMORY)
{
p->v.mem.addr = fetch_address (0);
p->v.mem.in_stack_memory = fetch_in_stack_memory (0);
p.v.mem.addr = fetch_address (0);
p.v.mem.in_stack_memory = fetch_in_stack_memory (0);
}
else if (p->location == DWARF_VALUE_IMPLICIT_POINTER)
else if (p.location == DWARF_VALUE_IMPLICIT_POINTER)
{
p->v.ptr.die_sect_off = (sect_offset) this->len;
p->v.ptr.offset = value_as_long (fetch (0));
p.v.ptr.die_sect_off = (sect_offset) this->len;
p.v.ptr.offset = value_as_long (fetch (0));
}
else if (p->location == DWARF_VALUE_REGISTER)
p->v.regno = value_as_long (fetch (0));
else if (p.location == DWARF_VALUE_REGISTER)
p.v.regno = value_as_long (fetch (0));
else
{
p->v.value = fetch (0);
p.v.value = fetch (0);
}
}