Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 18/22] Some cleanup removal in dwarf2loc.c
Date: Tue, 27 Sep 2016 04:51:00 -0000	[thread overview]
Message-ID: <1474949330-4307-19-git-send-email-tom@tromey.com> (raw)
In-Reply-To: <1474949330-4307-1-git-send-email-tom@tromey.com>

This removes some cleanups and manual allocation handling in
dwarf2loc.c with std::vector.

2016-09-26  Tom Tromey  <tom@tromey.com>

	* dwarf2loc.c: Include <vector>.
	(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  <tom@tromey.com>
 
+	* dwarf2loc.c: Include <vector>.
+	(read_pieced_value, write_pieced_value)
+	(dwarf2_compile_expr_to_ax): Use std::vector.
+
+2016-09-26  Tom Tromey  <tom@tromey.com>
+
 	* 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 <algorithm>
+#include <vector>
 
 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<gdb_byte> 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<gdb_byte> 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<int> 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<int> 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);
 }
 
 \f
-- 
2.7.4


  parent reply	other threads:[~2016-09-27  4:50 UTC|newest]

Thread overview: 121+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-27  4:49 [RFA 00/22] More C++-ification Tom Tromey
2016-09-27  4:41 ` [RFA 07/22] Change scoped_minimal_symbol_reader to store objfile Tom Tromey
2016-09-29  9:19   ` Trevor Saunders
2016-09-30 21:41     ` Tom Tromey
2016-09-27  4:41 ` [RFA 15/22] Use std::string in macho_symfile_read_all_oso Tom Tromey
2016-10-09 17:28   ` Pedro Alves
2016-10-10 22:40     ` Tom Tromey
2016-10-10 22:46       ` Pedro Alves
2016-09-27  4:42 ` [RFA 19/22] Convert tid_range_parser to class Tom Tromey
2016-09-30  1:41   ` Pedro Alves
2016-09-30 14:52     ` Tom Tromey
     [not found]       ` <926126cb-b3c5-340b-ac1c-5bc14ca41bf9@redhat.com>
2016-10-04 19:24         ` Pedro Alves
2016-10-04 23:09           ` Pedro Alves
2016-10-05  2:16             ` Trevor Saunders
2016-10-12  2:12             ` Tom Tromey
2016-10-13  1:06               ` Pedro Alves
2016-09-27  4:42 ` [RFA 16/22] Use std::vector in elf_read_minimal_symbols Tom Tromey
2016-10-09 17:30   ` Pedro Alves
2016-09-27  4:43 ` [RFA 20/22] Initial conversion of dwarf_expr_ctx Tom Tromey
2016-10-09 17:40   ` Pedro Alves
2016-09-27  4:45 ` [RFA 21/22] Convert DWARF expr functions to methods Tom Tromey
2016-10-09 19:18   ` Pedro Alves
2016-09-27  4:47 ` [RFA 05/22] Turn wchar iterator into a class Tom Tromey
2016-10-06  1:01   ` Pedro Alves
2016-09-27  4:47 ` [RFA 22/22] Convert dwarf_expr_context_funcs to methods Tom Tromey
2016-10-09 19:11   ` Pedro Alves
2016-10-10 18:31     ` Pedro Alves
2016-10-10 19:33       ` Pedro Alves
2016-09-27  4:47 ` [RFA 04/22] Use scoped_restore for current_ui Tom Tromey
2016-09-27  4:47 ` [RFA 02/22] Use RAII to save and restore scalars Tom Tromey
2016-09-27 10:24   ` Trevor Saunders
2016-09-30  1:40     ` Pedro Alves
2016-09-30  9:22       ` Pedro Alves
2016-09-30 15:00       ` Tom Tromey
2016-09-30 23:50         ` Pedro Alves
2016-09-30 15:44       ` Tom Tromey
2016-09-30 23:51         ` Pedro Alves
2016-10-01  3:55           ` Tom Tromey
2016-10-01  4:23             ` Tom Tromey
2016-10-01 10:33               ` Pedro Alves
2016-10-02 17:11                 ` Tom Tromey
2016-10-05  0:06                   ` Pedro Alves
2016-10-12 22:36                     ` Tom Tromey
2016-09-27  4:48 ` [RFA 09/22] Remove make_cleanup_restore_current_ui Tom Tromey
2016-09-29 11:55   ` Trevor Saunders
2016-10-01  3:47     ` Tom Tromey
2016-10-01  4:29   ` Simon Marchi
2016-10-06  2:53     ` Tom Tromey
2016-10-06  1:24   ` Pedro Alves
2016-10-06  2:52     ` Tom Tromey
2016-10-09  4:31   ` Simon Marchi
2016-10-09 15:10     ` Tom Tromey
2016-10-09 19:20       ` Pedro Alves
2016-10-12 22:43         ` Tom Tromey
2016-10-13  1:28           ` Pedro Alves
2016-10-13  6:11             ` Eli Zaretskii
2016-10-13 10:16               ` Pedro Alves
2016-10-13 13:53                 ` Eli Zaretskii
2016-10-13 14:26                   ` Pedro Alves
2016-10-13 14:46                     ` Eli Zaretskii
     [not found]                       ` <9d9dca17-56a6-6c0a-44bb-efc425f24d8d@redhat.com>
2016-10-13 15:19                         ` Eli Zaretskii
2016-10-13 15:43                           ` Pedro Alves
2016-10-13 15:48                             ` Pedro Alves
2016-10-17 23:43                             ` Go C++11? (was: Re: [RFA 09/22] Remove make_cleanup_restore_current_ui) Pedro Alves
2016-10-18  6:14                               ` Eli Zaretskii
2016-10-19 18:02                               ` Go C++11? Luis Machado
2016-10-19 22:34                                 ` Pedro Alves
2016-10-13 15:27                       ` [RFA 09/22] Remove make_cleanup_restore_current_ui Pedro Alves
2016-10-13 14:26                 ` Trevor Saunders
2016-09-27  4:48 ` [RFA 01/22] Change selttest.c to use use std::vector Tom Tromey
2016-09-27  8:50   ` Trevor Saunders
2016-09-27 16:44     ` Tom Tromey
2016-09-28 14:58       ` Trevor Saunders
2016-09-29  8:59         ` Tom Tromey
2016-10-06  0:18       ` Pedro Alves
2016-10-06  0:39       ` Pedro Alves
2016-09-30 14:43   ` Simon Marchi
2016-09-30 21:40     ` Tom Tromey
2016-10-06  0:45       ` Pedro Alves
2016-09-27  4:48 ` [RFA 03/22] Use scoped_restore for ui_file Tom Tromey
2016-10-01  4:28   ` Simon Marchi
2016-10-01  5:22     ` Tom Tromey
2016-10-01 11:47       ` Simon Marchi
2016-10-13 14:56         ` Tom Tromey
2016-09-27  4:48 ` [RFA 08/22] Record minimal symbols directly in reader Tom Tromey
2016-10-01  4:29   ` Simon Marchi
2016-10-06  1:12     ` Pedro Alves
2016-09-27  4:50 ` [RFA 17/22] Remove make_cleanup_restore_current_uiout Tom Tromey
2016-09-29 14:35   ` Trevor Saunders
2016-09-29 15:23     ` Tom Tromey
2016-09-29 17:55       ` Simon Marchi
2016-09-29 20:34         ` Tom Tromey
2016-09-30  2:45       ` Pedro Alves
2016-09-30 23:48         ` Tom Tromey
2016-09-30 23:52           ` Pedro Alves
2016-09-27  4:51 ` [RFA 12/22] Remove unnecessary null_cleanup Tom Tromey
2016-10-09 17:06   ` Pedro Alves
2016-09-27  4:51 ` [RFA 13/22] Remove unnecessary cleanup from stabsread.c Tom Tromey
2016-09-30 16:19   ` Tom Tromey
2016-10-09 17:07   ` Pedro Alves
2016-09-27  4:51 ` Tom Tromey [this message]
2016-10-09 17:37   ` [RFA 18/22] Some cleanup removal in dwarf2loc.c Pedro Alves
2016-09-27  4:51 ` [RFA 14/22] Replace two xmallocs with vector Tom Tromey
2016-10-09 17:20   ` Pedro Alves
2016-10-12 22:39     ` Tom Tromey
2016-10-13  1:17       ` Pedro Alves
2016-10-13  2:04         ` Tom Tromey
2016-10-13 15:15     ` Tom Tromey
2016-10-13 15:26       ` Trevor Saunders
2016-09-27  4:52 ` [RFA 10/22] Remove some cleanups in MI Tom Tromey
2016-10-06  1:42   ` Pedro Alves
2016-09-27  4:52 ` [RFA 06/22] Introduce scoped_minimal_symbol_reader Tom Tromey
2016-10-06  1:10   ` Pedro Alves
2016-10-06 15:37     ` Tom Tromey
2016-10-10 23:06     ` Tom Tromey
2016-10-10 23:26       ` Pedro Alves
2016-09-27  8:32 ` [RFA 11/22] Change command stats reporting to use class Tom Tromey
2016-10-09 17:01   ` Pedro Alves
2016-10-11 17:31     ` Tom Tromey
     [not found] ` <e06fbe1ea266e078eaff6bdc98e48efa@simark.ca>
2016-10-08 16:42   ` [RFA 00/22] More C++-ification Pedro Alves
2016-10-09  2:09   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1474949330-4307-19-git-send-email-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox