From patchwork Tue Sep 27 04:08:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 16060 Received: (qmail 102914 invoked by alias); 27 Sep 2016 04:50:10 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 102884 invoked by uid 89); 27 Sep 2016 04:50:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=shine, 20026, lazy X-HELO: gproxy9-pub.mail.unifiedlayer.com Received: from gproxy9-pub.mail.unifiedlayer.com (HELO gproxy9-pub.mail.unifiedlayer.com) (69.89.20.122) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Tue, 27 Sep 2016 04:49:58 +0000 Received: (qmail 17710 invoked by uid 0); 27 Sep 2016 04:49:57 -0000 Received: from unknown (HELO cmgw2) (10.0.90.83) by gproxy9.mail.unifiedlayer.com with SMTP; 27 Sep 2016 04:49:57 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id oUps1t00N2f2jeq01UpvhK; Mon, 26 Sep 2016 22:49:55 -0600 X-Authority-Analysis: v=2.1 cv=F4vEKMRN c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=GW1xBdLrtEIA:10 a=zstS-IiYAAAA:8 a=lL5FHgDp-7AU5VG-lxgA:9 a=OMirIjo2KcDsTy22:21 a=NwPC5jY2PmIgKozH:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 71-218-192-86.hlrn.qwest.net ([71.218.192.86]:56110 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1bojhX-0006Nj-Gx; Mon, 26 Sep 2016 22:09:03 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 18/22] Some cleanup removal in dwarf2loc.c Date: Mon, 26 Sep 2016 22:08:46 -0600 Message-Id: <1474949330-4307-19-git-send-email-tom@tromey.com> In-Reply-To: <1474949330-4307-1-git-send-email-tom@tromey.com> References: <1474949330-4307-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1bojhX-0006Nj-Gx X-Source-Sender: 71-218-192-86.hlrn.qwest.net (bapiya.Home) [71.218.192.86]:56110 X-Source-Auth: tom+tromey.com X-Email-Count: 23 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This removes some cleanups and manual allocation handling in dwarf2loc.c with std::vector. 2016-09-26 Tom Tromey * dwarf2loc.c: Include . (read_pieced_value, write_pieced_value) (dwarf2_compile_expr_to_ax): Use std::vector. --- gdb/ChangeLog | 6 ++++++ gdb/dwarf2loc.c | 66 ++++++++++++++++++++++----------------------------------- 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 89ce46f..1e2fc29 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2016-09-26 Tom Tromey + * dwarf2loc.c: Include . + (read_pieced_value, write_pieced_value) + (dwarf2_compile_expr_to_ax): Use std::vector. + +2016-09-26 Tom Tromey + * ui-out.c (make_cleanup_restore_current_uiout) (restore_current_uiout_cleanup): Remove. * infrun.c (print_stop_event): Use scoped_restore_uiout. diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index f9f3216..7b3a2b2 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -39,6 +39,7 @@ #include "dwarf2-frame.h" #include "compile/compile.h" #include +#include extern int dwarf_always_disassemble; @@ -1697,8 +1698,7 @@ read_pieced_value (struct value *v) struct frame_info *frame = frame_find_by_id (VALUE_FRAME_ID (v)); size_t type_len; size_t buffer_size = 0; - gdb_byte *buffer = NULL; - struct cleanup *cleanup; + std::vector buffer; int bits_big_endian = gdbarch_bits_big_endian (get_type_arch (value_type (v))); @@ -1707,8 +1707,6 @@ read_pieced_value (struct value *v) _("Should not be able to create a lazy value with " "an enclosing type")); - cleanup = make_cleanup (free_current_contents, &buffer); - contents = value_contents_raw (v); bits_to_skip = 8 * value_offset (v); if (value_bitsize (v)) @@ -1754,9 +1752,9 @@ read_pieced_value (struct value *v) if (buffer_size < this_size) { buffer_size = this_size; - buffer = (gdb_byte *) xrealloc (buffer, buffer_size); + buffer.reserve (buffer_size); } - intermediate_buffer = buffer; + intermediate_buffer = buffer.data (); /* Copy from the source to DEST_BUFFER. */ switch (p->location) @@ -1779,11 +1777,11 @@ read_pieced_value (struct value *v) } if (!get_frame_register_bytes (frame, gdb_regnum, reg_offset, - this_size, buffer, + this_size, buffer.data (), &optim, &unavail)) { /* Just so garbage doesn't ever shine through. */ - memset (buffer, 0, this_size); + memset (buffer.data (), 0, this_size); if (optim) mark_value_bits_optimized_out (v, offset, this_size_bits); @@ -1797,7 +1795,7 @@ read_pieced_value (struct value *v) read_value_memory (v, offset, p->v.mem.in_stack_memory, p->v.mem.addr + source_offset, - buffer, this_size); + buffer.data (), this_size); break; case DWARF_VALUE_STACK: @@ -1855,8 +1853,6 @@ read_pieced_value (struct value *v) offset += this_size_bits; } - - do_cleanups (cleanup); } static void @@ -1871,8 +1867,7 @@ write_pieced_value (struct value *to, struct value *from) struct frame_info *frame = frame_find_by_id (VALUE_FRAME_ID (to)); size_t type_len; size_t buffer_size = 0; - gdb_byte *buffer = NULL; - struct cleanup *cleanup; + std::vector buffer; int bits_big_endian = gdbarch_bits_big_endian (get_type_arch (value_type (to))); @@ -1882,8 +1877,6 @@ write_pieced_value (struct value *to, struct value *from) return; } - cleanup = make_cleanup (free_current_contents, &buffer); - contents = value_contents (from); bits_to_skip = 8 * value_offset (to); if (value_bitsize (to)) @@ -1936,9 +1929,9 @@ write_pieced_value (struct value *to, struct value *from) if (buffer_size < this_size) { buffer_size = this_size; - buffer = (gdb_byte *) xrealloc (buffer, buffer_size); + buffer.reserve (buffer_size); } - source_buffer = buffer; + source_buffer = buffer.data (); need_bitwise = 1; } @@ -1962,7 +1955,7 @@ write_pieced_value (struct value *to, struct value *from) int optim, unavail; if (!get_frame_register_bytes (frame, gdb_regnum, reg_offset, - this_size, buffer, + this_size, buffer.data (), &optim, &unavail)) { if (optim) @@ -1976,7 +1969,7 @@ write_pieced_value (struct value *to, struct value *from) "bitfield; containing word " "is unavailable")); } - copy_bitwise (buffer, dest_offset_bits, + copy_bitwise (buffer.data (), dest_offset_bits, contents, source_offset_bits, this_size_bits, bits_big_endian); @@ -1991,10 +1984,10 @@ write_pieced_value (struct value *to, struct value *from) { /* Only the first and last bytes can possibly have any bits reused. */ - read_memory (p->v.mem.addr + dest_offset, buffer, 1); + read_memory (p->v.mem.addr + dest_offset, buffer.data (), 1); read_memory (p->v.mem.addr + dest_offset + this_size - 1, - buffer + this_size - 1, 1); - copy_bitwise (buffer, dest_offset_bits, + &buffer[this_size - 1], 1); + copy_bitwise (buffer.data (), dest_offset_bits, contents, source_offset_bits, this_size_bits, bits_big_endian); @@ -2009,8 +2002,6 @@ write_pieced_value (struct value *to, struct value *from) } offset += this_size_bits; } - - do_cleanups (cleanup); } /* An implementation of an lval_funcs method to see whether a value is @@ -3054,9 +3045,8 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc, const gdb_byte *op_ptr, const gdb_byte *op_end, struct dwarf2_per_cu_data *per_cu) { - struct cleanup *cleanups; - int i, *offsets; - VEC(int) *dw_labels = NULL, *patches = NULL; + int i; + std::vector dw_labels, patches; const gdb_byte * const base = op_ptr; const gdb_byte *previous_piece = op_ptr; enum bfd_endian byte_order = gdbarch_byte_order (arch); @@ -3064,15 +3054,11 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc, unsigned int addr_size_bits = 8 * addr_size; int bits_big_endian = gdbarch_bits_big_endian (arch); - offsets = XNEWVEC (int, op_end - op_ptr); - cleanups = make_cleanup (xfree, offsets); + std::vector offsets (op_end - op_ptr); for (i = 0; i < op_end - op_ptr; ++i) offsets[i] = -1; - make_cleanup (VEC_cleanup (int), &dw_labels); - make_cleanup (VEC_cleanup (int), &patches); - /* By default we are making an address. */ loc->kind = axs_lvalue_memory; @@ -3584,8 +3570,8 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc, offset = extract_signed_integer (op_ptr, 2, byte_order); op_ptr += 2; i = ax_goto (expr, aop_goto); - VEC_safe_push (int, dw_labels, op_ptr + offset - base); - VEC_safe_push (int, patches, i); + dw_labels.push_back (op_ptr + offset - base); + patches.push_back (i); break; case DW_OP_bra: @@ -3594,8 +3580,8 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc, /* Zero extend the operand. */ ax_zero_ext (expr, addr_size_bits); i = ax_goto (expr, aop_if_goto); - VEC_safe_push (int, dw_labels, op_ptr + offset - base); - VEC_safe_push (int, patches, i); + dw_labels.push_back (op_ptr + offset - base); + patches.push_back (i); break; case DW_OP_nop: @@ -3704,15 +3690,13 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc, } /* Patch all the branches we emitted. */ - for (i = 0; i < VEC_length (int, patches); ++i) + for (i = 0; i < patches.size (); ++i) { - int targ = offsets[VEC_index (int, dw_labels, i)]; + int targ = offsets[dw_labels[i]]; if (targ == -1) internal_error (__FILE__, __LINE__, _("invalid label")); - ax_label (expr, VEC_index (int, patches, i), targ); + ax_label (expr, patches[i], targ); } - - do_cleanups (cleanups); }