public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@ericsson.com>
Subject: [PATCH 2/7] Factor out print_unpacked_pointer from c_val_print
Date: Wed, 08 Jul 2015 21:08:00 -0000	[thread overview]
Message-ID: <1436389629-18754-3-git-send-email-simon.marchi@ericsson.com> (raw)
In-Reply-To: <1436389629-18754-1-git-send-email-simon.marchi@ericsson.com>

Turn this code into a function, instead of a goto.

gdb/ChangeLog:

	* c-valprint.c (c_val_print): Factor out pointer printing code
	to ...
	(print_unpacked_pointer): ... this new function.
---
 gdb/c-valprint.c | 205 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 106 insertions(+), 99 deletions(-)

diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index e8a2fc7..41950ee 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -127,6 +127,104 @@ static const struct generic_val_print_decorations c_decorations =
   "void"
 };
 
+/* Print a pointer based on the type of its target.
+ *
+ * Arguments to this functions are roughly the same as those in c_val_print.
+ * A difference is that ADDRESS is the address to print, with embedded_offset
+ * already added.  UNRESOLVED_ELTTYPE and ELTTYPE represent the pointed type,
+ * respectively before and after check_typedef.  */
+
+static void
+print_unpacked_pointer (struct type *type, struct type *elttype,
+			struct type *unresolved_elttype,
+			const gdb_byte *valaddr, int embedded_offset,
+			CORE_ADDR address, struct ui_file *stream, int recurse,
+			const struct value_print_options *options)
+{
+  int want_space = 0;
+  struct gdbarch *gdbarch = get_type_arch (type);
+
+  if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
+    {
+      /* Try to print what function it points to.  */
+      print_function_pointer_address (options, gdbarch, address, stream);
+      return;
+    }
+
+  if (options->symbol_print)
+    want_space = print_address_demangle (options, gdbarch, address, stream,
+					 demangle);
+  else if (options->addressprint)
+    {
+      fputs_filtered (paddress (gdbarch, address), stream);
+      want_space = 1;
+    }
+
+  /* For a pointer to a textual type, also print the string
+     pointed to, unless pointer is null.  */
+
+  if (c_textual_element_type (unresolved_elttype, options->format)
+      && address != 0)
+    {
+      if (want_space)
+	fputs_filtered (" ", stream);
+      val_print_string (unresolved_elttype, NULL, address, -1, stream, options);
+    }
+  else if (cp_is_vtbl_member (type))
+    {
+      /* Print vtbl's nicely.  */
+      CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);
+      struct bound_minimal_symbol msymbol =
+	lookup_minimal_symbol_by_pc (vt_address);
+
+      /* If 'symbol_print' is set, we did the work above.  */
+      if (!options->symbol_print
+	  && (msymbol.minsym != NULL)
+	  && (vt_address == BMSYMBOL_VALUE_ADDRESS (msymbol)))
+	{
+	  if (want_space)
+	    fputs_filtered (" ", stream);
+	  fputs_filtered (" <", stream);
+	  fputs_filtered (MSYMBOL_PRINT_NAME (msymbol.minsym), stream);
+	  fputs_filtered (">", stream);
+	  want_space = 1;
+	}
+
+      if (vt_address && options->vtblprint)
+	{
+	  struct value *vt_val;
+	  struct symbol *wsym = (struct symbol *) NULL;
+	  struct type *wtype;
+	  struct block *block = (struct block *) NULL;
+	  struct field_of_this_result is_this_fld;
+
+	  if (want_space)
+	    fputs_filtered (" ", stream);
+
+	  if (msymbol.minsym != NULL)
+	    wsym = lookup_symbol (MSYMBOL_LINKAGE_NAME(msymbol.minsym), block,
+				  VAR_DOMAIN, &is_this_fld);
+
+	  if (wsym)
+	    {
+	      wtype = SYMBOL_TYPE (wsym);
+	    }
+	  else
+	    {
+	      wtype = unresolved_elttype;
+	    }
+	  vt_val = value_at (wtype, vt_address);
+	  common_val_print (vt_val, stream, recurse + 1, options,
+			    current_language);
+	  if (options->prettyformat)
+	    {
+	      fprintf_filtered (stream, "\n");
+	      print_spaces_filtered (2 + 2 * recurse, stream);
+	    }
+	}
+    }
+}
+
 /* See val_print for a description of the various parameters of this
    function; they are identical.  */
 
@@ -237,10 +335,11 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
 	    }
 	  break;
 	}
-      /* Array of unspecified length: treat like pointer to first
-	 elt.  */
-      addr = address + embedded_offset;
-      goto print_unpacked_pointer;
+      /* Array of unspecified length: treat like pointer to first elt.  */
+      print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr,
+			      embedded_offset, address + embedded_offset,
+			      stream, recurse, options);
+      break;
 
     case TYPE_CODE_METHODPTR:
       cplus_print_method_ptr (valaddr + embedded_offset, type, stream);
@@ -267,101 +366,9 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
 	}
       unresolved_elttype = TYPE_TARGET_TYPE (type);
       elttype = check_typedef (unresolved_elttype);
-	{
-	  int want_space;
-
-	  addr = unpack_pointer (type, valaddr + embedded_offset);
-	print_unpacked_pointer:
-
-	  want_space = 0;
-
-	  if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
-	    {
-	      /* Try to print what function it points to.  */
-	      print_function_pointer_address (options, gdbarch, addr, stream);
-	      return;
-	    }
-
-	  if (options->symbol_print)
-	    want_space = print_address_demangle (options, gdbarch, addr,
-						 stream, demangle);
-	  else if (options->addressprint)
-	    {
-	      fputs_filtered (paddress (gdbarch, addr), stream);
-	      want_space = 1;
-	    }
-
-	  /* For a pointer to a textual type, also print the string
-	     pointed to, unless pointer is null.  */
-
-	  if (c_textual_element_type (unresolved_elttype,
-				      options->format)
-	      && addr != 0)
-	    {
-	      if (want_space)
-		fputs_filtered (" ", stream);
-	      val_print_string (unresolved_elttype, NULL,
-				addr, -1,
-				stream, options);
-	    }
-	  else if (cp_is_vtbl_member (type))
-	    {
-	      /* Print vtbl's nicely.  */
-	      CORE_ADDR vt_address = unpack_pointer (type,
-						     valaddr
-						     + embedded_offset);
-	      struct bound_minimal_symbol msymbol =
-		lookup_minimal_symbol_by_pc (vt_address);
-
-	      /* If 'symbol_print' is set, we did the work above.  */
-	      if (!options->symbol_print
-		  && (msymbol.minsym != NULL)
-		  && (vt_address == BMSYMBOL_VALUE_ADDRESS (msymbol)))
-		{
-		  if (want_space)
-		    fputs_filtered (" ", stream);
-		  fputs_filtered (" <", stream);
-		  fputs_filtered (MSYMBOL_PRINT_NAME (msymbol.minsym), stream);
-		  fputs_filtered (">", stream);
-		  want_space = 1;
-		}
-
-	      if (vt_address && options->vtblprint)
-		{
-		  struct value *vt_val;
-		  struct symbol *wsym = (struct symbol *) NULL;
-		  struct type *wtype;
-		  struct block *block = (struct block *) NULL;
-		  struct field_of_this_result is_this_fld;
-
-		  if (want_space)
-		    fputs_filtered (" ", stream);
-
-		  if (msymbol.minsym != NULL)
-		    wsym = lookup_symbol (MSYMBOL_LINKAGE_NAME (msymbol.minsym),
-					  block, VAR_DOMAIN,
-					  &is_this_fld);
-
-		  if (wsym)
-		    {
-		      wtype = SYMBOL_TYPE (wsym);
-		    }
-		  else
-		    {
-		      wtype = unresolved_elttype;
-		    }
-		  vt_val = value_at (wtype, vt_address);
-		  common_val_print (vt_val, stream, recurse + 1,
-				    options, current_language);
-		  if (options->prettyformat)
-		    {
-		      fprintf_filtered (stream, "\n");
-		      print_spaces_filtered (2 + 2 * recurse, stream);
-		    }
-		}
-	    }
-	  return;
-	}
+      addr = unpack_pointer (type, valaddr + embedded_offset);
+      print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr,
+			      embedded_offset, addr, stream, recurse, options);
       break;
 
     case TYPE_CODE_UNION:
-- 
2.1.4

  parent reply	other threads:[~2015-07-08 21:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08 21:08 [PATCH 0/7] Split c_val_print Simon Marchi
2015-07-08 21:08 ` [PATCH 7/7] Factor out memberptr printing code from c_val_print Simon Marchi
2015-07-08 21:08 ` [PATCH 6/7] Factor out int " Simon Marchi
2015-07-08 21:08 ` [PATCH 3/7] Factor out array " Simon Marchi
2015-07-08 21:08 ` Simon Marchi [this message]
2015-07-09 15:30   ` [PATCH 2/7] Factor out print_unpacked_pointer " Simon Marchi
2015-07-08 21:08 ` [PATCH 1/7] Remove unneeded variable assignment Simon Marchi
2015-07-08 21:08 ` [PATCH 4/7] Factor out pointer printing code from c_val_print Simon Marchi
2015-07-09 15:32   ` Simon Marchi
2015-07-08 21:08 ` [PATCH 5/7] Factor out struct and union " Simon Marchi
2015-07-09 10:53 ` [PATCH 0/7] Split c_val_print Pedro Alves
2015-07-09 15:28   ` Simon Marchi
2015-07-09 15:30     ` Pedro Alves
2015-07-09 23:42 ` Sergio Durigan Junior

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=1436389629-18754-3-git-send-email-simon.marchi@ericsson.com \
    --to=simon.marchi@ericsson.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).