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 03/13] Use std::vector in compile-loc2c.c
Date: Thu, 02 Nov 2017 22:36:00 -0000	[thread overview]
Message-ID: <20171102223612.3642-4-tom@tromey.com> (raw)
In-Reply-To: <20171102223612.3642-1-tom@tromey.com>

This changes compile-loc2c.c to use std::vector, removing some
cleanups.

gdb/ChangeLog
2017-11-02  Tom Tromey  <tom@tromey.com>

	* compile/compile-loc2c.c (compute_stack_depth_worker): Change
	type of "info".
	(compute_stack_depth): Likewise.
	(do_compile_dwarf_expr_to_c): Use std::vector.
---
 gdb/ChangeLog               |  7 +++++++
 gdb/compile/compile-loc2c.c | 42 +++++++++++++++++-------------------------
 2 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
index 7ec6f67cdf..ca26f13eda 100644
--- a/gdb/compile/compile-loc2c.c
+++ b/gdb/compile/compile-loc2c.c
@@ -62,7 +62,7 @@ struct insn_info
    NEED_TEMPVAR is an out parameter which is set if this expression
    needs a special temporary variable to be emitted (see the code
    generator).
-   INFO is an array of insn_info objects, indexed by offset from the
+   INFO is a vector of insn_info objects, indexed by offset from the
    start of the DWARF expression.
    TO_DO is a list of bytecodes which must be examined; it may be
    added to by this function.
@@ -71,7 +71,7 @@ struct insn_info
 
 static void
 compute_stack_depth_worker (int start, int *need_tempvar,
-			    struct insn_info *info,
+			    std::vector<struct insn_info> *info,
 			    std::vector<int> *to_do,
 			    enum bfd_endian byte_order, unsigned int addr_size,
 			    const gdb_byte *op_ptr, const gdb_byte *op_end)
@@ -80,8 +80,8 @@ compute_stack_depth_worker (int start, int *need_tempvar,
   int stack_depth;
 
   op_ptr += start;
-  gdb_assert (info[start].visited);
-  stack_depth = info[start].depth;
+  gdb_assert ((*info)[start].visited);
+  stack_depth = (*info)[start].depth;
 
   while (op_ptr < op_end)
     {
@@ -91,16 +91,16 @@ compute_stack_depth_worker (int start, int *need_tempvar,
       int ndx = op_ptr - base;
 
 #define SET_CHECK_DEPTH(WHERE)				\
-      if (info[WHERE].visited)				\
+      if ((*info)[WHERE].visited)				\
 	{						\
-	  if (info[WHERE].depth != stack_depth)		\
+	  if ((*info)[WHERE].depth != stack_depth)		\
 	    error (_("inconsistent stack depths"));	\
 	}						\
       else						\
 	{						\
 	  /* Stack depth not set, so set it.  */	\
-	  info[WHERE].visited = 1;			\
-	  info[WHERE].depth = stack_depth;		\
+	  (*info)[WHERE].visited = 1;			\
+	  (*info)[WHERE].depth = stack_depth;		\
 	}
 
       SET_CHECK_DEPTH (ndx);
@@ -324,7 +324,7 @@ compute_stack_depth_worker (int start, int *need_tempvar,
 
 	case DW_OP_GNU_push_tls_address:
 	case DW_OP_form_tls_address:
-	  info[ndx].is_tls = 1;
+	  (*info)[ndx].is_tls = 1;
 	  break;
 
 	case DW_OP_skip:
@@ -333,10 +333,10 @@ compute_stack_depth_worker (int start, int *need_tempvar,
 	  offset = op_ptr + offset - base;
 	  /* If the destination has not been seen yet, add it to the
 	     to-do list.  */
-	  if (!info[offset].visited)
+	  if (!(*info)[offset].visited)
 	    to_do->push_back (offset);
 	  SET_CHECK_DEPTH (offset);
-	  info[offset].label = 1;
+	  (*info)[offset].label = 1;
 	  /* We're done with this line of code.  */
 	  return;
 
@@ -347,10 +347,10 @@ compute_stack_depth_worker (int start, int *need_tempvar,
 	  --stack_depth;
 	  /* If the destination has not been seen yet, add it to the
 	     to-do list.  */
-	  if (!info[offset].visited)
+	  if (!(*info)[offset].visited)
 	    to_do->push_back (offset);
 	  SET_CHECK_DEPTH (offset);
-	  info[offset].label = 1;
+	  (*info)[offset].label = 1;
 	  break;
 
 	case DW_OP_nop:
@@ -387,15 +387,13 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size,
 		     int *need_tempvar, int *is_tls,
 		     const gdb_byte *op_ptr, const gdb_byte *op_end,
 		     int initial_depth,
-		     struct insn_info **info)
+		     std::vector<struct insn_info> *info)
 {
   unsigned char *set;
-  struct cleanup *outer_cleanup;
   std::vector<int> to_do;
   int stack_depth, i;
 
-  *info = XCNEWVEC (struct insn_info, op_end - op_ptr);
-  outer_cleanup = make_cleanup (xfree, *info);
+  info->resize (op_end - op_ptr);
 
   to_do.push_back (0);
   (*info)[0].depth = initial_depth;
@@ -406,7 +404,7 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size,
       int ndx = to_do.back ();
       to_do.pop_back ();
 
-      compute_stack_depth_worker (ndx, need_tempvar, *info, &to_do,
+      compute_stack_depth_worker (ndx, need_tempvar, info, &to_do,
 				  byte_order, addr_size,
 				  op_ptr, op_end);
     }
@@ -421,7 +419,6 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size,
 	*is_tls = 1;
     }
 
-  discard_cleanups (outer_cleanup);
   return stack_depth + 1;
 }
 
@@ -594,8 +591,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
   const gdb_byte * const base = op_ptr;
   int need_tempvar = 0;
   int is_tls = 0;
-  struct cleanup *cleanup;
-  struct insn_info *info;
+  std::vector<struct insn_info> info;
   int stack_depth;
 
   ++scope;
@@ -609,7 +605,6 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
 				     &need_tempvar, &is_tls,
 				     op_ptr, op_end, initial != NULL,
 				     &info);
-  cleanup = make_cleanup (xfree, info);
 
   /* This is a hack until we can add a feature to glibc to let us
      properly generate code for TLS.  You might think we could emit
@@ -643,7 +638,6 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
 			 result_name,
 			 core_addr_to_string (value_address (val)));
       fprintfi_filtered (indent - 2, &stream, "}\n");
-      do_cleanups (cleanup);
       return;
     }
 
@@ -1117,8 +1111,6 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
   fprintfi_filtered (indent, &stream, "%s = __gdb_stack[__gdb_tos];\n",
 		     result_name);
   fprintfi_filtered (indent - 2, &stream, "}\n");
-
-  do_cleanups (cleanup);
 }
 
 /* See compile.h.  */
-- 
2.13.6


  parent reply	other threads:[~2017-11-02 22:36 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-02 22:36 [RFA 00/13] more cleanup removal Tom Tromey
2017-11-02 22:36 ` [RFA 07/13] Use gdb::def_vector in sparc64-tdep.c Tom Tromey
2017-11-03  1:25   ` Simon Marchi
2017-11-03 17:05     ` Tom Tromey
2017-11-02 22:36 ` [RFA 05/13] Remove directive-searched cleanups Tom Tromey
2017-11-03  1:09   ` Simon Marchi
2017-11-03 16:42     ` Tom Tromey
2017-11-03 16:46       ` Simon Marchi
2017-11-02 22:36 ` [RFA 12/13] Introduce gdb_breakpoint_up Tom Tromey
2017-11-03  1:56   ` Simon Marchi
2017-11-03 17:28     ` Tom Tromey
2017-11-02 22:36 ` [RFA 06/13] Replace start_rbreak_breakpoints and end_rbreak_breakpoints Tom Tromey
2017-11-03  1:21   ` Simon Marchi
2017-11-03 16:58     ` Tom Tromey
2017-11-03 17:20       ` Simon Marchi
2017-11-04 16:25         ` Tom Tromey
2017-11-02 22:36 ` [RFA 01/13] Replace really_free_pendings with a scoped_ class Tom Tromey
2017-11-02 22:36 ` [RFA 13/13] Use std::vector in h8300-tdep.c Tom Tromey
2017-11-03  1:59   ` Simon Marchi
2017-11-04 16:25     ` Tom Tromey
2017-11-02 22:36 ` [RFA 09/13] Use gdb::def_vector in ppc-linux-tdep.c Tom Tromey
2017-11-03  1:31   ` Simon Marchi
2017-11-03 17:07     ` Tom Tromey
2017-11-02 22:36 ` Tom Tromey [this message]
2017-11-02 22:36 ` [RFA 08/13] Remove make_cleanup_free_objfile Tom Tromey
2017-11-02 22:36 ` [RFA 10/13] Remove cleanups from linux-tdep.c Tom Tromey
2017-11-03  1:43   ` Simon Marchi
2017-11-04 16:25     ` Tom Tromey
2017-11-02 22:36 ` [RFA 02/13] Remove cleanups from link_callbacks_einfo Tom Tromey
2017-11-02 22:36 ` [RFA 11/13] Use unique_xmalloc_ptr in c_type_print_base Tom Tromey
2017-11-02 22:38 ` [RFA 04/13] Use unique_xmalloc_ptr in find_separate_debug_file_by_debuglink Tom Tromey
2017-11-03  1:02   ` Simon Marchi
2017-11-03 16:39     ` Tom Tromey
2017-11-03  1:59 ` [RFA 00/13] more cleanup removal Simon Marchi
2017-11-04 16:28   ` 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=20171102223612.3642-4-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