From 1e467161932b6385b51d0bd365a91cf205b399b9 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 14 Sep 2017 15:57:01 +0200 Subject: 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) : Remove. : 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. : Remove. : 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. --- gdb/dwarf2expr.h | 101 +++++++++++++++++++++++++++---------------------------- 1 file changed, 49 insertions(+), 52 deletions(-) (limited to 'gdb/dwarf2expr.h') diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2expr.h index 7df697d..39bcea3 100644 --- a/gdb/dwarf2expr.h +++ b/gdb/dwarf2expr.h @@ -49,6 +49,53 @@ enum dwarf_value_location DWARF_VALUE_IMPLICIT_POINTER }; +/* A piece of an object, as recorded by DW_OP_piece or DW_OP_bit_piece. */ +struct dwarf_expr_piece +{ + enum dwarf_value_location location; + + union + { + struct + { + /* This piece's address, for DWARF_VALUE_MEMORY pieces. */ + CORE_ADDR addr; + /* Non-zero if the piece is known to be in memory and on + the program's stack. */ + int in_stack_memory; + } mem; + + /* The piece's register number, for DWARF_VALUE_REGISTER pieces. */ + int regno; + + /* The piece's literal value, for DWARF_VALUE_STACK pieces. */ + struct value *value; + + struct + { + /* A pointer to the data making up this piece, + for DWARF_VALUE_LITERAL pieces. */ + const gdb_byte *data; + /* The length of the available data. */ + ULONGEST length; + } literal; + + /* Used for DWARF_VALUE_IMPLICIT_POINTER. */ + struct + { + /* The referent DIE from DW_OP_implicit_pointer. */ + sect_offset die_sect_off; + /* The byte offset into the resulting data. */ + LONGEST offset; + } ptr; + } v; + + /* The length of the piece, in bits. */ + ULONGEST size; + /* The piece offset, in bits. */ + ULONGEST offset; +}; + /* The dwarf expression stack. */ struct dwarf_stack_value @@ -114,8 +161,7 @@ struct dwarf_expr_context initialized; zero otherwise. */ int initialized; - /* An array of pieces. PIECES points to its first element; - NUM_PIECES is its length. + /* A vector of pieces. Each time DW_OP_piece is executed, we add a new element to the end of this array, recording the current top of the stack, the @@ -137,8 +183,7 @@ struct dwarf_expr_context no DW_OP_piece operations have no value to place in a piece's 'size' field; the size comes from the surrounding data. So the two cases need to be handled separately.) */ - int num_pieces; - struct dwarf_expr_piece *pieces; + std::vector pieces; /* Return the value of register number REGNUM (a DWARF register number), read as an address. */ @@ -213,54 +258,6 @@ private: void pop (); }; - -/* A piece of an object, as recorded by DW_OP_piece or DW_OP_bit_piece. */ -struct dwarf_expr_piece -{ - enum dwarf_value_location location; - - union - { - struct - { - /* This piece's address, for DWARF_VALUE_MEMORY pieces. */ - CORE_ADDR addr; - /* Non-zero if the piece is known to be in memory and on - the program's stack. */ - int in_stack_memory; - } mem; - - /* The piece's register number, for DWARF_VALUE_REGISTER pieces. */ - int regno; - - /* The piece's literal value, for DWARF_VALUE_STACK pieces. */ - struct value *value; - - struct - { - /* A pointer to the data making up this piece, - for DWARF_VALUE_LITERAL pieces. */ - const gdb_byte *data; - /* The length of the available data. */ - ULONGEST length; - } literal; - - /* Used for DWARF_VALUE_IMPLICIT_POINTER. */ - struct - { - /* The referent DIE from DW_OP_implicit_pointer. */ - sect_offset die_sect_off; - /* The byte offset into the resulting data. */ - LONGEST offset; - } ptr; - } v; - - /* The length of the piece, in bits. */ - ULONGEST size; - /* The piece offset, in bits. */ - ULONGEST offset; -}; - void dwarf_expr_require_composition (const gdb_byte *, const gdb_byte *, const char *); -- cgit v1.1