public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 06/14] Factor out enum printing code from generic_val_print
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
@ 2015-07-15 16:47 ` Simon Marchi
  2015-07-15 16:47 ` [PATCH 01/14] Factor out print_unpacked_pointer " Simon Marchi
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out enum
	printing code to ...
	(generic_val_print_enum): ... this new function.
---
 gdb/valprint.c | 128 ++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 71 insertions(+), 57 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index 36fd3e1..f83faa8 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -509,6 +509,75 @@ generic_val_print_ref (struct type *type, const gdb_byte *valaddr,
     }
 }
 
+/* generic_val_print helper for TYPE_CODE_ENUM.  */
+
+static void
+generic_val_print_enum (struct type *type, const gdb_byte *valaddr,
+			int embedded_offset, struct ui_file *stream,
+			const struct value *original_value,
+			const struct value_print_options *options)
+{
+  unsigned int i;
+  unsigned int len;
+  LONGEST val;
+
+  if (options->format)
+    {
+      val_print_scalar_formatted (type, valaddr, embedded_offset,
+				  original_value, options, 0, stream);
+      return;
+    }
+  len = TYPE_NFIELDS (type);
+  val = unpack_long (type, valaddr + embedded_offset);
+  for (i = 0; i < len; i++)
+    {
+      QUIT;
+      if (val == TYPE_FIELD_ENUMVAL (type, i))
+	{
+	  break;
+	}
+    }
+  if (i < len)
+    {
+      fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
+    }
+  else if (TYPE_FLAG_ENUM (type))
+    {
+      int first = 1;
+
+      /* We have a "flag" enum, so we try to decompose it into
+	 pieces as appropriate.  A flag enum has disjoint
+	 constants by definition.  */
+      fputs_filtered ("(", stream);
+      for (i = 0; i < len; ++i)
+	{
+	  QUIT;
+
+	  if ((val & TYPE_FIELD_ENUMVAL (type, i)) != 0)
+	    {
+	      if (!first)
+		fputs_filtered (" | ", stream);
+	      first = 0;
+
+	      val &= ~TYPE_FIELD_ENUMVAL (type, i);
+	      fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
+	    }
+	}
+
+      if (first || val != 0)
+	{
+	  if (!first)
+	    fputs_filtered (" | ", stream);
+	  fputs_filtered ("unknown: ", stream);
+	  print_longest (stream, 'd', 0, val);
+	}
+
+      fputs_filtered (")", stream);
+    }
+  else
+    print_longest (stream, 'd', 0, val);
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -529,8 +598,6 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
 		   const struct generic_val_print_decorations *decorations)
 {
   struct gdbarch *gdbarch = get_type_arch (type);
-  unsigned int i = 0;	/* Number of characters printed.  */
-  unsigned len;
   struct type *unresolved_type = type;
   LONGEST val;
 
@@ -558,61 +625,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       break;
 
     case TYPE_CODE_ENUM:
-      if (options->format)
-	{
-	  val_print_scalar_formatted (type, valaddr, embedded_offset,
-				      original_value, options, 0, stream);
-	  break;
-	}
-      len = TYPE_NFIELDS (type);
-      val = unpack_long (type, valaddr + embedded_offset);
-      for (i = 0; i < len; i++)
-	{
-	  QUIT;
-	  if (val == TYPE_FIELD_ENUMVAL (type, i))
-	    {
-	      break;
-	    }
-	}
-      if (i < len)
-	{
-	  fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
-	}
-      else if (TYPE_FLAG_ENUM (type))
-	{
-	  int first = 1;
-
-	  /* We have a "flag" enum, so we try to decompose it into
-	     pieces as appropriate.  A flag enum has disjoint
-	     constants by definition.  */
-	  fputs_filtered ("(", stream);
-	  for (i = 0; i < len; ++i)
-	    {
-	      QUIT;
-
-	      if ((val & TYPE_FIELD_ENUMVAL (type, i)) != 0)
-		{
-		  if (!first)
-		    fputs_filtered (" | ", stream);
-		  first = 0;
-
-		  val &= ~TYPE_FIELD_ENUMVAL (type, i);
-		  fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
-		}
-	    }
-
-	  if (first || val != 0)
-	    {
-	      if (!first)
-		fputs_filtered (" | ", stream);
-	      fputs_filtered ("unknown: ", stream);
-	      print_longest (stream, 'd', 0, val);
-	    }
-
-	  fputs_filtered (")", stream);
-	}
-      else
-	print_longest (stream, 'd', 0, val);
+      generic_val_print_enum (type, valaddr, embedded_offset, stream,
+			      original_value, options);
       break;
 
     case TYPE_CODE_FLAGS:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 01/14] Factor out print_unpacked_pointer from generic_val_print
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
  2015-07-15 16:47 ` [PATCH 06/14] Factor out enum printing code from generic_val_print Simon Marchi
@ 2015-07-15 16:47 ` Simon Marchi
  2015-07-23 21:45   ` Pedro Alves
  2015-07-15 16:47 ` [PATCH 04/14] Factor out memberptr printing code " Simon Marchi
                   ` (12 subsequent siblings)
  14 siblings, 1 reply; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out
	print_unpacked_pointer code to ...
	(print_unpacked_pointer): ... this new function.
---
 gdb/valprint.c | 48 +++++++++++++++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 17 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index 52a386a..eee52c5 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -359,6 +359,33 @@ val_print_invalid_address (struct ui_file *stream)
   fprintf_filtered (stream, _("<invalid address>"));
 }
 
+/* Print a pointer based on the type of its target.
+
+   Arguments to this functions are roughly the same as those in
+   generic_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,
+			CORE_ADDR address, struct ui_file *stream,
+			const struct value_print_options *options)
+{
+  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)
+    print_address_demangle (options, gdbarch, address, stream, demangle);
+  else if (options->addressprint)
+    fputs_filtered (paddress (gdbarch, address), stream);
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -414,7 +441,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       /* Array of unspecified length: treat like pointer to first
 	 elt.  */
       addr = address + embedded_offset;
-      goto print_unpacked_pointer;
+      print_unpacked_pointer (type, elttype, addr, stream, options);
+      break;
 
     case TYPE_CODE_MEMBERPTR:
       val_print_scalar_formatted (type, valaddr, embedded_offset,
@@ -430,22 +458,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
 	}
       unresolved_elttype = TYPE_TARGET_TYPE (type);
       elttype = check_typedef (unresolved_elttype);
-	{
-	  addr = unpack_pointer (type, valaddr + embedded_offset);
-	print_unpacked_pointer:
-
-	  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)
-	    print_address_demangle (options, gdbarch, addr, stream, demangle);
-	  else if (options->addressprint)
-	    fputs_filtered (paddress (gdbarch, addr), stream);
-	}
+      addr = unpack_pointer (type, valaddr + embedded_offset);
+      print_unpacked_pointer (type, elttype, addr, stream, options);
       break;
 
     case TYPE_CODE_REF:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 04/14] Factor out memberptr printing code from generic_val_print
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
  2015-07-15 16:47 ` [PATCH 06/14] Factor out enum printing code from generic_val_print Simon Marchi
  2015-07-15 16:47 ` [PATCH 01/14] Factor out print_unpacked_pointer " Simon Marchi
@ 2015-07-15 16:47 ` Simon Marchi
  2015-07-15 16:48 ` [PATCH 11/14] Factor out char " Simon Marchi
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out memberptr
	printing code to ...
	(generic_val_print_memberptr): ... this new function.
---
 gdb/valprint.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index d84c3af..30fe348 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -448,6 +448,19 @@ generic_val_print_ptr (struct type *type, const gdb_byte *valaddr,
     }
 }
 
+
+/* generic_val_print helper for TYPE_CODE_MEMBERPTR.  */
+
+static void
+generic_val_print_memberptr (struct type *type, const gdb_byte *valaddr,
+			     int embedded_offset, struct ui_file *stream,
+			     const struct value *original_value,
+			     const struct value_print_options *options)
+{
+  val_print_scalar_formatted (type, valaddr, embedded_offset,
+			      original_value, options, 0, stream);
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -483,8 +496,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       break;
 
     case TYPE_CODE_MEMBERPTR:
-      val_print_scalar_formatted (type, valaddr, embedded_offset,
-				  original_value, options, 0, stream);
+      generic_val_print_memberptr (type, valaddr, embedded_offset, stream,
+				   original_value, options);
       break;
 
     case TYPE_CODE_PTR:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 00/14] Split generic_val_print in smaller parts
@ 2015-07-15 16:47 Simon Marchi
  2015-07-15 16:47 ` [PATCH 06/14] Factor out enum printing code from generic_val_print Simon Marchi
                   ` (14 more replies)
  0 siblings, 15 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

I gave the same treatment to generic_val_print as I gave c_val_print
previously.

Regression-tested on x86-64 Ubuntu 14.04, no visible regressions.

Simon Marchi (14):
  Factor out print_unpacked_pointer from generic_val_print
  Factor out array printing code from generic_val_print
  Factor out pointer printing code from generic_val_print
  Factor out memberptr printing code from generic_val_print
  Factor out reference printing code from generic_val_print
  Factor out enum printing code from generic_val_print
  Factor out flags printing code from generic_val_print
  Factor out function/method printing code from generic_val_print
  Factor out bool printing code from generic_val_print
  Factor out int printing code from generic_val_print
  Factor out char printing code from generic_val_print
  Factor out float printing code from generic_val_print
  Factor out decfloat printing code from generic_val_print
  Factor out complex printing code from generic_val_print

 gdb/valprint.c | 670 ++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 428 insertions(+), 242 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 09/14] Factor out bool printing code from generic_val_print
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
                   ` (5 preceding siblings ...)
  2015-07-15 16:48 ` [PATCH 05/14] Factor out reference " Simon Marchi
@ 2015-07-15 16:48 ` Simon Marchi
  2015-07-15 16:48 ` [PATCH 07/14] Factor out flags " Simon Marchi
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out bool
	printing code to ...
	(generic_val_print_bool): ... this new function.
---
 gdb/valprint.c | 51 +++++++++++++++++++++++++++++++++------------------
 1 file changed, 33 insertions(+), 18 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index d2ca244..7b90971 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -623,6 +623,37 @@ generic_val_print_func (struct type *type, const gdb_byte *valaddr,
     }
 }
 
+/* generic_val_print helper for TYPE_CODE_BOOL.  */
+
+static void
+generic_val_print_bool (struct type *type, const gdb_byte *valaddr,
+			int embedded_offset, struct ui_file *stream,
+			const struct value *original_value,
+			const struct value_print_options *options,
+			const struct generic_val_print_decorations *decorations)
+{
+  LONGEST val;
+
+  if (options->format || options->output_format)
+    {
+      struct value_print_options opts = *options;
+      opts.format = (options->format ? options->format
+		     : options->output_format);
+      val_print_scalar_formatted (type, valaddr, embedded_offset,
+				  original_value, &opts, 0, stream);
+    }
+  else
+    {
+      val = unpack_long (type, valaddr + embedded_offset);
+      if (val == 0)
+	fputs_filtered (decorations->false_name, stream);
+      else if (val == 1)
+	fputs_filtered (decorations->true_name, stream);
+      else
+	print_longest (stream, 'd', 0, val);
+    }
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -685,24 +716,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       break;
 
     case TYPE_CODE_BOOL:
-      if (options->format || options->output_format)
-	{
-	  struct value_print_options opts = *options;
-	  opts.format = (options->format ? options->format
-			 : options->output_format);
-	  val_print_scalar_formatted (type, valaddr, embedded_offset,
-				      original_value, &opts, 0, stream);
-	}
-      else
-	{
-	  val = unpack_long (type, valaddr + embedded_offset);
-	  if (val == 0)
-	    fputs_filtered (decorations->false_name, stream);
-	  else if (val == 1)
-	    fputs_filtered (decorations->true_name, stream);
-	  else
-	    print_longest (stream, 'd', 0, val);
-	}
+      generic_val_print_bool (type, valaddr, embedded_offset, stream,
+			      original_value, options, decorations);
       break;
 
     case TYPE_CODE_RANGE:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 13/14] Factor out decfloat printing code from generic_val_print
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
                   ` (8 preceding siblings ...)
  2015-07-15 16:48 ` [PATCH 14/14] Factor out complex " Simon Marchi
@ 2015-07-15 16:48 ` Simon Marchi
  2015-07-15 16:48 ` [PATCH 03/14] Factor out pointer " Simon Marchi
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out decfloat
	printing code to ...
	(generic_val_print_decfloat): ... this new function.
---
 gdb/valprint.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index c63402d..7712bf2 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -726,6 +726,21 @@ generic_val_print_float (struct type *type, const gdb_byte *valaddr,
 	}
 }
 
+/* generic_val_print helper for TYPE_CODE_DECFLOAT.  */
+
+static void
+generic_val_print_decfloat (struct type *type, const gdb_byte *valaddr,
+			    int embedded_offset, struct ui_file *stream,
+			    const struct value *original_value,
+			    const struct value_print_options *options)
+{
+  if (options->format)
+    val_print_scalar_formatted (type, valaddr, embedded_offset, original_value,
+				options, 0, stream);
+  else
+    print_decimal_floating (valaddr + embedded_offset, type, stream);
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -818,12 +833,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       break;
 
     case TYPE_CODE_DECFLOAT:
-      if (options->format)
-	val_print_scalar_formatted (type, valaddr, embedded_offset,
-				    original_value, options, 0, stream);
-      else
-	print_decimal_floating (valaddr + embedded_offset,
-				type, stream);
+      generic_val_print_decfloat (type, valaddr, embedded_offset, stream,
+				  original_value, options);
       break;
 
     case TYPE_CODE_VOID:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 03/14] Factor out pointer printing code from generic_val_print
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
                   ` (9 preceding siblings ...)
  2015-07-15 16:48 ` [PATCH 13/14] Factor out decfloat " Simon Marchi
@ 2015-07-15 16:48 ` Simon Marchi
  2015-07-15 16:48 ` [PATCH 08/14] Factor out function/method " Simon Marchi
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out pointer
	printing code to ...
	(generic_val_print_ptr): ... this new function.
---
 gdb/valprint.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index cf4567b..d84c3af 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -425,6 +425,29 @@ generic_val_print_array (struct type *type, const gdb_byte *valaddr,
 
 }
 
+/* generic_val_print helper for TYPE_CODE_PTR.  */
+
+static void
+generic_val_print_ptr (struct type *type, const gdb_byte *valaddr,
+		       int embedded_offset, struct ui_file *stream,
+		       const struct value *original_value,
+		       const struct value_print_options *options)
+{
+  if (options->format && options->format != 's')
+    {
+      val_print_scalar_formatted (type, valaddr, embedded_offset,
+				  original_value, options, 0, stream);
+    }
+  else
+    {
+      struct type *unresolved_elttype = TYPE_TARGET_TYPE(type);
+      struct type *elttype = check_typedef (unresolved_elttype);
+      CORE_ADDR addr = unpack_pointer (type, valaddr + embedded_offset);
+
+      print_unpacked_pointer (type, elttype, addr, stream, options);
+    }
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -447,10 +470,9 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
   struct gdbarch *gdbarch = get_type_arch (type);
   unsigned int i = 0;	/* Number of characters printed.  */
   unsigned len;
-  struct type *elttype, *unresolved_elttype;
+  struct type *elttype;
   struct type *unresolved_type = type;
   LONGEST val;
-  CORE_ADDR addr;
 
   type = check_typedef (type);
   switch (TYPE_CODE (type))
@@ -466,16 +488,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       break;
 
     case TYPE_CODE_PTR:
-      if (options->format && options->format != 's')
-	{
-	  val_print_scalar_formatted (type, valaddr, embedded_offset,
-				      original_value, options, 0, stream);
-	  break;
-	}
-      unresolved_elttype = TYPE_TARGET_TYPE (type);
-      elttype = check_typedef (unresolved_elttype);
-      addr = unpack_pointer (type, valaddr + embedded_offset);
-      print_unpacked_pointer (type, elttype, addr, stream, options);
+      generic_val_print_ptr (type, valaddr, embedded_offset, stream,
+			     original_value, options);
       break;
 
     case TYPE_CODE_REF:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 14/14] Factor out complex printing code from generic_val_print
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
                   ` (7 preceding siblings ...)
  2015-07-15 16:48 ` [PATCH 07/14] Factor out flags " Simon Marchi
@ 2015-07-15 16:48 ` Simon Marchi
  2015-07-15 16:48 ` [PATCH 13/14] Factor out decfloat " Simon Marchi
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out complex
	printing code to ...
	(generic_val_print_complex): ... this new function.
---
 gdb/valprint.c | 56 +++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 33 insertions(+), 23 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index 7712bf2..8b05c65 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -741,6 +741,37 @@ generic_val_print_decfloat (struct type *type, const gdb_byte *valaddr,
     print_decimal_floating (valaddr + embedded_offset, type, stream);
 }
 
+/* generic_val_print helper for TYPE_CODE_COMPLEX.  */
+
+static void
+generic_val_print_complex (struct type *type, const gdb_byte *valaddr,
+			   int embedded_offset, struct ui_file *stream,
+			   const struct value *original_value,
+			   const struct value_print_options *options,
+			   const struct generic_val_print_decorations
+			     *decorations)
+{
+  fprintf_filtered (stream, "%s", decorations->complex_prefix);
+  if (options->format)
+    val_print_scalar_formatted (TYPE_TARGET_TYPE (type), valaddr,
+				embedded_offset, original_value, options, 0,
+				stream);
+  else
+    print_floating (valaddr + embedded_offset, TYPE_TARGET_TYPE (type),
+		    stream);
+  fprintf_filtered (stream, "%s", decorations->complex_infix);
+  if (options->format)
+    val_print_scalar_formatted (TYPE_TARGET_TYPE (type), valaddr,
+				embedded_offset
+				+ TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
+				original_value, options, 0, stream);
+  else
+    print_floating (valaddr + embedded_offset
+		    + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
+		    TYPE_TARGET_TYPE (type), stream);
+  fprintf_filtered (stream, "%s", decorations->complex_suffix);
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -854,29 +885,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       break;
 
     case TYPE_CODE_COMPLEX:
-      fprintf_filtered (stream, "%s", decorations->complex_prefix);
-      if (options->format)
-	val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
-				    valaddr, embedded_offset,
-				    original_value, options, 0, stream);
-      else
-	print_floating (valaddr + embedded_offset,
-			TYPE_TARGET_TYPE (type),
-			stream);
-      fprintf_filtered (stream, "%s", decorations->complex_infix);
-      if (options->format)
-	val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
-				    valaddr,
-				    embedded_offset
-				    + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
-				    original_value,
-				    options, 0, stream);
-      else
-	print_floating (valaddr + embedded_offset
-			+ TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
-			TYPE_TARGET_TYPE (type),
-			stream);
-      fprintf_filtered (stream, "%s", decorations->complex_suffix);
+      generic_val_print_complex (type, valaddr, embedded_offset, stream,
+				 original_value, options, decorations);
       break;
 
     case TYPE_CODE_UNION:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 12/14] Factor out float printing code from generic_val_print
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
                   ` (3 preceding siblings ...)
  2015-07-15 16:48 ` [PATCH 11/14] Factor out char " Simon Marchi
@ 2015-07-15 16:48 ` Simon Marchi
  2015-07-23 21:46   ` Pedro Alves
  2015-07-15 16:48 ` [PATCH 05/14] Factor out reference " Simon Marchi
                   ` (9 subsequent siblings)
  14 siblings, 1 reply; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out float
	printing code to ...
	(generic_val_print_float): ... this new function.
---
 gdb/valprint.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index eff97c8..c63402d 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -707,6 +707,25 @@ generic_val_print_char (struct type *type, struct type *unresolved_type,
     }
 }
 
+/* generic_val_print helper for TYPE_CODE_FLT.  */
+
+static void
+generic_val_print_float (struct type *type, const gdb_byte *valaddr,
+			 int embedded_offset, struct ui_file *stream,
+			 const struct value *original_value,
+			 const struct value_print_options *options)
+{
+      if (options->format)
+	{
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
+	}
+      else
+	{
+	  print_floating (valaddr + embedded_offset, type, stream);
+	}
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -794,15 +813,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       break;
 
     case TYPE_CODE_FLT:
-      if (options->format)
-	{
-	  val_print_scalar_formatted (type, valaddr, embedded_offset,
-				      original_value, options, 0, stream);
-	}
-      else
-	{
-	  print_floating (valaddr + embedded_offset, type, stream);
-	}
+      generic_val_print_float (type, valaddr, embedded_offset, stream,
+			       original_value, options);
       break;
 
     case TYPE_CODE_DECFLOAT:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 05/14] Factor out reference printing code from generic_val_print
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
                   ` (4 preceding siblings ...)
  2015-07-15 16:48 ` [PATCH 12/14] Factor out float " Simon Marchi
@ 2015-07-15 16:48 ` Simon Marchi
  2015-07-15 16:48 ` [PATCH 09/14] Factor out bool " Simon Marchi
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out reference
	printing code to ...
	(generic_val_print_ref): ... this new function.
---
 gdb/valprint.c | 87 +++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 50 insertions(+), 37 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index 30fe348..36fd3e1 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -461,6 +461,54 @@ generic_val_print_memberptr (struct type *type, const gdb_byte *valaddr,
 			      original_value, options, 0, stream);
 }
 
+/* generic_val_print helper for TYPE_CODE_REF.  */
+
+static void
+generic_val_print_ref (struct type *type, const gdb_byte *valaddr,
+		       int embedded_offset, struct ui_file *stream, int recurse,
+		       const struct value *original_value,
+		       const struct value_print_options *options)
+{
+  struct gdbarch *gdbarch = get_type_arch (type);
+  struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
+
+  if (options->addressprint)
+    {
+      CORE_ADDR addr
+	= extract_typed_address (valaddr + embedded_offset, type);
+
+      fprintf_filtered (stream, "@");
+      fputs_filtered (paddress (gdbarch, addr), stream);
+      if (options->deref_ref)
+	fputs_filtered (": ", stream);
+    }
+  /* De-reference the reference.  */
+  if (options->deref_ref)
+    {
+      if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
+	{
+	  struct value *deref_val;
+
+	  deref_val = coerce_ref_if_computed (original_value);
+	  if (deref_val != NULL)
+	    {
+	      /* More complicated computed references are not supported.  */
+	      gdb_assert (embedded_offset == 0);
+	    }
+	  else
+	    deref_val = value_at (TYPE_TARGET_TYPE (type),
+				  unpack_pointer (type,
+						  (valaddr
+						   + embedded_offset)));
+
+	  common_val_print (deref_val, stream, recurse, options,
+			    current_language);
+	}
+      else
+	fputs_filtered ("???", stream);
+    }
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -483,7 +531,6 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
   struct gdbarch *gdbarch = get_type_arch (type);
   unsigned int i = 0;	/* Number of characters printed.  */
   unsigned len;
-  struct type *elttype;
   struct type *unresolved_type = type;
   LONGEST val;
 
@@ -506,42 +553,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       break;
 
     case TYPE_CODE_REF:
-      elttype = check_typedef (TYPE_TARGET_TYPE (type));
-      if (options->addressprint)
-	{
-	  CORE_ADDR addr
-	    = extract_typed_address (valaddr + embedded_offset, type);
-
-	  fprintf_filtered (stream, "@");
-	  fputs_filtered (paddress (gdbarch, addr), stream);
-	  if (options->deref_ref)
-	    fputs_filtered (": ", stream);
-	}
-      /* De-reference the reference.  */
-      if (options->deref_ref)
-	{
-	  if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
-	    {
-	      struct value *deref_val;
-
-	      deref_val = coerce_ref_if_computed (original_value);
-	      if (deref_val != NULL)
-		{
-		  /* More complicated computed references are not supported.  */
-		  gdb_assert (embedded_offset == 0);
-		}
-	      else
-		deref_val = value_at (TYPE_TARGET_TYPE (type),
-				      unpack_pointer (type,
-						      (valaddr
-						       + embedded_offset)));
-
-	      common_val_print (deref_val, stream, recurse, options,
-				current_language);
-	    }
-	  else
-	    fputs_filtered ("???", stream);
-	}
+      generic_val_print_ref (type, valaddr, embedded_offset, stream, recurse,
+			     original_value, options);
       break;
 
     case TYPE_CODE_ENUM:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 02/14] Factor out array printing code from generic_val_print
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
                   ` (11 preceding siblings ...)
  2015-07-15 16:48 ` [PATCH 08/14] Factor out function/method " Simon Marchi
@ 2015-07-15 16:48 ` Simon Marchi
  2015-07-15 16:48 ` [PATCH 10/14] Factor out int " Simon Marchi
  2015-07-23 21:54 ` [PATCH 00/14] Split generic_val_print in smaller parts Pedro Alves
  14 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out array
	printing code to ...
	(generic_val_print_array): ... this new function.
---
 gdb/valprint.c | 66 ++++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 41 insertions(+), 25 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index eee52c5..cf4567b 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -386,6 +386,45 @@ print_unpacked_pointer (struct type *type, struct type *elttype,
     fputs_filtered (paddress (gdbarch, address), stream);
 }
 
+/* generic_val_print helper for TYPE_CODE_ARRAY.  */
+
+static void
+generic_val_print_array (struct type *type, const gdb_byte *valaddr,
+		   int embedded_offset, CORE_ADDR address,
+		   struct ui_file *stream, int recurse,
+		   const struct value *original_value,
+		   const struct value_print_options *options)
+{
+  struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
+  struct type *elttype = check_typedef (unresolved_elttype);
+
+  if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
+    {
+      LONGEST low_bound, high_bound;
+
+      if (!get_array_bounds (type, &low_bound, &high_bound))
+	error (_("Could not determine the array high bound"));
+
+      if (options->prettyformat_arrays)
+	{
+	  print_spaces_filtered (2 + 2 * recurse, stream);
+	}
+
+      fprintf_filtered (stream, "{");
+      val_print_array_elements (type, valaddr, embedded_offset,
+				address, stream,
+				recurse, original_value, options, 0);
+      fprintf_filtered (stream, "}");
+    }
+  else
+    {
+      /* Array of unspecified length: treat like pointer to first elt.  */
+      print_unpacked_pointer (type, elttype, address + embedded_offset, stream,
+			      options);
+    }
+
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -417,31 +456,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
   switch (TYPE_CODE (type))
     {
     case TYPE_CODE_ARRAY:
-      unresolved_elttype = TYPE_TARGET_TYPE (type);
-      elttype = check_typedef (unresolved_elttype);
-      if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
-	{
-          LONGEST low_bound, high_bound;
-
-          if (!get_array_bounds (type, &low_bound, &high_bound))
-            error (_("Could not determine the array high bound"));
-
-	  if (options->prettyformat_arrays)
-	    {
-	      print_spaces_filtered (2 + 2 * recurse, stream);
-	    }
-
-	  fprintf_filtered (stream, "{");
-	  val_print_array_elements (type, valaddr, embedded_offset,
-				    address, stream,
-				    recurse, original_value, options, 0);
-	  fprintf_filtered (stream, "}");
-	  break;
-	}
-      /* Array of unspecified length: treat like pointer to first
-	 elt.  */
-      addr = address + embedded_offset;
-      print_unpacked_pointer (type, elttype, addr, stream, options);
+      generic_val_print_array (type, valaddr, embedded_offset, address, stream,
+			       recurse, original_value, options);
       break;
 
     case TYPE_CODE_MEMBERPTR:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 07/14] Factor out flags printing code from generic_val_print
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
                   ` (6 preceding siblings ...)
  2015-07-15 16:48 ` [PATCH 09/14] Factor out bool " Simon Marchi
@ 2015-07-15 16:48 ` Simon Marchi
  2015-07-15 16:48 ` [PATCH 14/14] Factor out complex " Simon Marchi
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out flags
	printing code to ...
	(generic_val_print_flags): ... this new function.
---
 gdb/valprint.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index f83faa8..3dcc54c 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -578,6 +578,22 @@ generic_val_print_enum (struct type *type, const gdb_byte *valaddr,
     print_longest (stream, 'd', 0, val);
 }
 
+/* generic_val_print helper for TYPE_CODE_FLAGS.  */
+
+static void
+generic_val_print_flags (struct type *type, const gdb_byte *valaddr,
+			 int embedded_offset, struct ui_file *stream,
+			 const struct value *original_value,
+			 const struct value_print_options *options)
+
+{
+  if (options->format)
+    val_print_scalar_formatted (type, valaddr, embedded_offset, original_value,
+				options, 0, stream);
+  else
+    val_print_type_code_flags (type, valaddr + embedded_offset, stream);
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -630,12 +646,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       break;
 
     case TYPE_CODE_FLAGS:
-      if (options->format)
-	val_print_scalar_formatted (type, valaddr, embedded_offset,
-				    original_value, options, 0, stream);
-      else
-	val_print_type_code_flags (type, valaddr + embedded_offset,
-				   stream);
+      generic_val_print_flags (type, valaddr, embedded_offset, stream,
+			       original_value, options);
       break;
 
     case TYPE_CODE_FUNC:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 11/14] Factor out char printing code from generic_val_print
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
                   ` (2 preceding siblings ...)
  2015-07-15 16:47 ` [PATCH 04/14] Factor out memberptr printing code " Simon Marchi
@ 2015-07-15 16:48 ` Simon Marchi
  2015-07-23 21:46   ` Pedro Alves
  2015-07-15 16:48 ` [PATCH 12/14] Factor out float " Simon Marchi
                   ` (10 subsequent siblings)
  14 siblings, 1 reply; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out char
	printing code to ...
	(generic_val_print_char): ... this new function.
---
 gdb/valprint.c | 54 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 20 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index 3d1480c2..eff97c8 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -675,6 +675,38 @@ generic_val_print_int (struct type *type, const gdb_byte *valaddr,
     val_print_type_code_int (type, valaddr + embedded_offset, stream);
 }
 
+/* generic_val_print helper for TYPE_CODE_INT.  */
+
+static void
+generic_val_print_char (struct type *type, struct type *unresolved_type,
+			const gdb_byte *valaddr, int embedded_offset,
+			struct ui_file *stream,
+			const struct value *original_value,
+			const struct value_print_options *options)
+{
+  LONGEST val;
+
+  if (options->format || options->output_format)
+    {
+      struct value_print_options opts = *options;
+
+      opts.format = (options->format ? options->format
+		     : options->output_format);
+      val_print_scalar_formatted (type, valaddr, embedded_offset,
+				  original_value, &opts, 0, stream);
+    }
+  else
+    {
+      val = unpack_long (type, valaddr + embedded_offset);
+      if (TYPE_UNSIGNED (type))
+	fprintf_filtered (stream, "%u", (unsigned int) val);
+      else
+	fprintf_filtered (stream, "%d", (int) val);
+      fputs_filtered (" ", stream);
+      LA_PRINT_CHAR (val, unresolved_type, stream);
+    }
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -695,7 +727,6 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
 		   const struct generic_val_print_decorations *decorations)
 {
   struct type *unresolved_type = type;
-  LONGEST val;
 
   type = check_typedef (type);
   switch (TYPE_CODE (type))
@@ -758,25 +789,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       break;
 
     case TYPE_CODE_CHAR:
-      if (options->format || options->output_format)
-	{
-	  struct value_print_options opts = *options;
-
-	  opts.format = (options->format ? options->format
-			 : options->output_format);
-	  val_print_scalar_formatted (type, valaddr, embedded_offset,
-				      original_value, &opts, 0, stream);
-	}
-      else
-	{
-	  val = unpack_long (type, valaddr + embedded_offset);
-	  if (TYPE_UNSIGNED (type))
-	    fprintf_filtered (stream, "%u", (unsigned int) val);
-	  else
-	    fprintf_filtered (stream, "%d", (int) val);
-	  fputs_filtered (" ", stream);
-	  LA_PRINT_CHAR (val, unresolved_type, stream);
-	}
+      generic_val_print_char (type, unresolved_type, valaddr, embedded_offset,
+			      stream, original_value, options);
       break;
 
     case TYPE_CODE_FLT:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 10/14] Factor out int printing code from generic_val_print
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
                   ` (12 preceding siblings ...)
  2015-07-15 16:48 ` [PATCH 02/14] Factor out array " Simon Marchi
@ 2015-07-15 16:48 ` Simon Marchi
  2015-07-23 21:54 ` [PATCH 00/14] Split generic_val_print in smaller parts Pedro Alves
  14 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out integer
	printing code to ...
	(generic_val_print_int): ... this new function.
---
 gdb/valprint.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index 7b90971..3d1480c2 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -654,6 +654,27 @@ generic_val_print_bool (struct type *type, const gdb_byte *valaddr,
     }
 }
 
+/* generic_val_print helper for TYPE_CODE_INT.  */
+
+static void
+generic_val_print_int (struct type *type, const gdb_byte *valaddr,
+		       int embedded_offset, struct ui_file *stream,
+		       const struct value *original_value,
+		       const struct value_print_options *options)
+{
+  if (options->format || options->output_format)
+    {
+      struct value_print_options opts = *options;
+
+      opts.format = (options->format ? options->format
+		     : options->output_format);
+      val_print_scalar_formatted (type, valaddr, embedded_offset,
+				  original_value, &opts, 0, stream);
+    }
+  else
+    val_print_type_code_int (type, valaddr + embedded_offset, stream);
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -732,17 +753,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       /* FALLTHROUGH */
 
     case TYPE_CODE_INT:
-      if (options->format || options->output_format)
-	{
-	  struct value_print_options opts = *options;
-
-	  opts.format = (options->format ? options->format
-			 : options->output_format);
-	  val_print_scalar_formatted (type, valaddr, embedded_offset,
-				      original_value, &opts, 0, stream);
-	}
-      else
-	val_print_type_code_int (type, valaddr + embedded_offset, stream);
+      generic_val_print_int (type, valaddr, embedded_offset, stream,
+			     original_value, options);
       break;
 
     case TYPE_CODE_CHAR:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 08/14] Factor out function/method printing code from generic_val_print
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
                   ` (10 preceding siblings ...)
  2015-07-15 16:48 ` [PATCH 03/14] Factor out pointer " Simon Marchi
@ 2015-07-15 16:48 ` Simon Marchi
  2015-07-23 21:45   ` Pedro Alves
  2015-07-15 16:48 ` [PATCH 02/14] Factor out array " Simon Marchi
                   ` (2 subsequent siblings)
  14 siblings, 1 reply; 26+ messages in thread
From: Simon Marchi @ 2015-07-15 16:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out function/method
	printing code to ...
	(generic_val_print_func): ... this new function.
---
 gdb/valprint.c | 46 +++++++++++++++++++++++++++++++---------------
 1 file changed, 31 insertions(+), 15 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index 3dcc54c..d2ca244 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -594,6 +594,35 @@ generic_val_print_flags (struct type *type, const gdb_byte *valaddr,
     val_print_type_code_flags (type, valaddr + embedded_offset, stream);
 }
 
+/* generic_val_print helper for TYPE_CODE_FUNC and _METHOD.  */
+
+static void
+generic_val_print_func (struct type *type, const gdb_byte *valaddr,
+			int embedded_offset, CORE_ADDR address,
+			struct ui_file *stream,
+			const struct value *original_value,
+			const struct value_print_options *options)
+{
+  struct gdbarch *gdbarch = get_type_arch (type);
+
+  if (options->format)
+    {
+      val_print_scalar_formatted (type, valaddr, embedded_offset,
+				  original_value, options, 0, stream);
+    }
+  else
+    {
+      /* FIXME, we should consider, at least for ANSI C language,
+         eliminating the distinction made between FUNCs and POINTERs
+         to FUNCs.  */
+      fprintf_filtered (stream, "{");
+      type_print (type, "", stream, -1);
+      fprintf_filtered (stream, "} ");
+      /* Try to print what function it points to, and its address.  */
+      print_address_demangle (options, gdbarch, address, stream, demangle);
+    }
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -613,7 +642,6 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
 		   const struct value_print_options *options,
 		   const struct generic_val_print_decorations *decorations)
 {
-  struct gdbarch *gdbarch = get_type_arch (type);
   struct type *unresolved_type = type;
   LONGEST val;
 
@@ -652,20 +680,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
 
     case TYPE_CODE_FUNC:
     case TYPE_CODE_METHOD:
-      if (options->format)
-	{
-	  val_print_scalar_formatted (type, valaddr, embedded_offset,
-				      original_value, options, 0, stream);
-	  break;
-	}
-      /* FIXME, we should consider, at least for ANSI C language,
-         eliminating the distinction made between FUNCs and POINTERs
-         to FUNCs.  */
-      fprintf_filtered (stream, "{");
-      type_print (type, "", stream, -1);
-      fprintf_filtered (stream, "} ");
-      /* Try to print what function it points to, and its address.  */
-      print_address_demangle (options, gdbarch, address, stream, demangle);
+      generic_val_print_func (type, valaddr, embedded_offset, address, stream,
+			      original_value, options);
       break;
 
     case TYPE_CODE_BOOL:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 01/14] Factor out print_unpacked_pointer from generic_val_print
  2015-07-15 16:47 ` [PATCH 01/14] Factor out print_unpacked_pointer " Simon Marchi
@ 2015-07-23 21:45   ` Pedro Alves
  2015-07-24  2:29     ` Simon Marchi
  2015-07-27 18:16     ` Simon Marchi
  0 siblings, 2 replies; 26+ messages in thread
From: Pedro Alves @ 2015-07-23 21:45 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches; +Cc: Simon Marchi

On 07/15/2015 05:47 PM, Simon Marchi wrote:

> 
> diff --git a/gdb/valprint.c b/gdb/valprint.c
> index 52a386a..eee52c5 100644
> --- a/gdb/valprint.c
> +++ b/gdb/valprint.c
> @@ -359,6 +359,33 @@ val_print_invalid_address (struct ui_file *stream)
>    fprintf_filtered (stream, _("<invalid address>"));
>  }
>  
> +/* Print a pointer based on the type of its target.
> +
> +   Arguments to this functions are roughly the same as those in
> +   generic_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.  */

Line too long.  Comment seems stale -- there's no UNRESOLVED_ELTTYPE
parameter.

Otherwise looks good.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 08/14] Factor out function/method printing code from generic_val_print
  2015-07-15 16:48 ` [PATCH 08/14] Factor out function/method " Simon Marchi
@ 2015-07-23 21:45   ` Pedro Alves
  2015-07-27 18:17     ` Simon Marchi
  0 siblings, 1 reply; 26+ messages in thread
From: Pedro Alves @ 2015-07-23 21:45 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 07/15/2015 05:47 PM, Simon Marchi wrote:

> +/* generic_val_print helper for TYPE_CODE_FUNC and _METHOD.  */

Please spell out TYPE_CODE_METHOD to be grep friendlier.

Otherwise OK.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 12/14] Factor out float printing code from generic_val_print
  2015-07-15 16:48 ` [PATCH 12/14] Factor out float " Simon Marchi
@ 2015-07-23 21:46   ` Pedro Alves
  2015-07-27 18:18     ` Simon Marchi
  0 siblings, 1 reply; 26+ messages in thread
From: Pedro Alves @ 2015-07-23 21:46 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 07/15/2015 05:47 PM, Simon Marchi wrote:
> +/* generic_val_print helper for TYPE_CODE_FLT.  */
> +
> +static void
> +generic_val_print_float (struct type *type, const gdb_byte *valaddr,
> +			 int embedded_offset, struct ui_file *stream,
> +			 const struct value *original_value,
> +			 const struct value_print_options *options)
> +{
> +      if (options->format)
> +	{
> +	  val_print_scalar_formatted (type, valaddr, embedded_offset,
> +				      original_value, options, 0, stream);
> +	}
> +      else
> +	{
> +	  print_floating (valaddr + embedded_offset, type, stream);
> +	}

Wrong indentation, it seem.  Otherwise OK.

> +}


Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 11/14] Factor out char printing code from generic_val_print
  2015-07-15 16:48 ` [PATCH 11/14] Factor out char " Simon Marchi
@ 2015-07-23 21:46   ` Pedro Alves
  2015-07-27 18:17     ` Simon Marchi
  0 siblings, 1 reply; 26+ messages in thread
From: Pedro Alves @ 2015-07-23 21:46 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 07/15/2015 05:47 PM, Simon Marchi wrote:
> +/* generic_val_print helper for TYPE_CODE_INT.  */

TYPE_CODE_CHAR.  Otherwise looks good.

> +
> +static void
> +generic_val_print_char (struct type *type, struct type *unresolved_type,
> +			const gdb_byte *valaddr, int embedded_offset,
> +			struct ui_file *stream,
> +			const struct value *original_value,
> +			const struct value_print_options *options)


Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 00/14] Split generic_val_print in smaller parts
  2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
                   ` (13 preceding siblings ...)
  2015-07-15 16:48 ` [PATCH 10/14] Factor out int " Simon Marchi
@ 2015-07-23 21:54 ` Pedro Alves
  2015-07-27 18:14   ` Simon Marchi
  14 siblings, 1 reply; 26+ messages in thread
From: Pedro Alves @ 2015-07-23 21:54 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 07/15/2015 05:47 PM, Simon Marchi wrote:

> Simon Marchi (14):
>   Factor out print_unpacked_pointer from generic_val_print
>   Factor out array printing code from generic_val_print
>   Factor out pointer printing code from generic_val_print
>   Factor out memberptr printing code from generic_val_print
>   Factor out reference printing code from generic_val_print
>   Factor out enum printing code from generic_val_print
>   Factor out flags printing code from generic_val_print
>   Factor out function/method printing code from generic_val_print
>   Factor out bool printing code from generic_val_print
>   Factor out int printing code from generic_val_print
>   Factor out char printing code from generic_val_print
>   Factor out float printing code from generic_val_print
>   Factor out decfloat printing code from generic_val_print
>   Factor out complex printing code from generic_val_print

I read the whole series.  Patches that I didn't comment
on looked OK to me as is.  The one's I commented on,
just fix them and push right ahead.

Nice cleanup!  Keep 'em coming.  :-)

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 01/14] Factor out print_unpacked_pointer from generic_val_print
  2015-07-23 21:45   ` Pedro Alves
@ 2015-07-24  2:29     ` Simon Marchi
  2015-07-27 18:16     ` Simon Marchi
  1 sibling, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-24  2:29 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Simon Marchi, gdb-patches

On 23 July 2015 at 17:45, Pedro Alves <palves@redhat.com> wrote:
> Line too long.  Comment seems stale -- there's no UNRESOLVED_ELTTYPE
> parameter.
>
> Otherwise looks good.

Thanks, fixed.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 00/14] Split generic_val_print in smaller parts
  2015-07-23 21:54 ` [PATCH 00/14] Split generic_val_print in smaller parts Pedro Alves
@ 2015-07-27 18:14   ` Simon Marchi
  0 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-27 18:14 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On 15-07-23 05:54 PM, Pedro Alves wrote:
> On 07/15/2015 05:47 PM, Simon Marchi wrote:
> 
>> Simon Marchi (14):
>>   Factor out print_unpacked_pointer from generic_val_print
>>   Factor out array printing code from generic_val_print
>>   Factor out pointer printing code from generic_val_print
>>   Factor out memberptr printing code from generic_val_print
>>   Factor out reference printing code from generic_val_print
>>   Factor out enum printing code from generic_val_print
>>   Factor out flags printing code from generic_val_print
>>   Factor out function/method printing code from generic_val_print
>>   Factor out bool printing code from generic_val_print
>>   Factor out int printing code from generic_val_print
>>   Factor out char printing code from generic_val_print
>>   Factor out float printing code from generic_val_print
>>   Factor out decfloat printing code from generic_val_print
>>   Factor out complex printing code from generic_val_print
> 
> I read the whole series.  Patches that I didn't comment
> on looked OK to me as is.  The one's I commented on,
> just fix them and push right ahead.
> 
> Nice cleanup!  Keep 'em coming.  :-)
> 
> Thanks,
> Pedro Alves

I did the fixes and pushed.  I'll post the final versions of
the patches that were modified.

Thanks

Simon

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 01/14] Factor out print_unpacked_pointer from generic_val_print
  2015-07-23 21:45   ` Pedro Alves
  2015-07-24  2:29     ` Simon Marchi
@ 2015-07-27 18:16     ` Simon Marchi
  1 sibling, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-27 18:16 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches; +Cc: Simon Marchi

On 15-07-23 05:45 PM, Pedro Alves wrote:
> Line too long.  Comment seems stale -- there's no UNRESOLVED_ELTTYPE
> parameter.
> 
> Otherwise looks good.
> 
> Thanks,
> Pedro Alves

Fixed, here is what I pushed:


From 9f436164d55690a0b3d2e4308bfd8834996b97d1 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@ericsson.com>
Date: Mon, 27 Jul 2015 14:11:18 -0400
Subject: [PATCH] Factor out print_unpacked_pointer from generic_val_print

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out
	print_unpacked_pointer code to ...
	(print_unpacked_pointer): ... this new function.
---
 gdb/ChangeLog  |  6 ++++++
 gdb/valprint.c | 48 +++++++++++++++++++++++++++++++-----------------
 2 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a03ca35..c36f548 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2015-07-27  Simon Marchi  <simon.marchi@ericsson.com>
+
+	* valprint.c (generic_val_print): Factor out
+	print_unpacked_pointer code to ...
+	(print_unpacked_pointer): ... this new function.
+
 2015-07-27  Patrick Palka  <patrick@parcs.ath.cx>

 	* event-top.c (handle_sigterm): Don't inspect
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 52a386a..c643956 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -359,6 +359,33 @@ val_print_invalid_address (struct ui_file *stream)
   fprintf_filtered (stream, _("<invalid address>"));
 }

+/* Print a pointer based on the type of its target.
+
+   Arguments to this functions are roughly the same as those in
+   generic_val_print.  A difference is that ADDRESS is the address to print,
+   with embedded_offset already added.  ELTTYPE represents
+   the pointed type after check_typedef.  */
+
+static void
+print_unpacked_pointer (struct type *type, struct type *elttype,
+			CORE_ADDR address, struct ui_file *stream,
+			const struct value_print_options *options)
+{
+  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)
+    print_address_demangle (options, gdbarch, address, stream, demangle);
+  else if (options->addressprint)
+    fputs_filtered (paddress (gdbarch, address), stream);
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -414,7 +441,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       /* Array of unspecified length: treat like pointer to first
 	 elt.  */
       addr = address + embedded_offset;
-      goto print_unpacked_pointer;
+      print_unpacked_pointer (type, elttype, addr, stream, options);
+      break;

     case TYPE_CODE_MEMBERPTR:
       val_print_scalar_formatted (type, valaddr, embedded_offset,
@@ -430,22 +458,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
 	}
       unresolved_elttype = TYPE_TARGET_TYPE (type);
       elttype = check_typedef (unresolved_elttype);
-	{
-	  addr = unpack_pointer (type, valaddr + embedded_offset);
-	print_unpacked_pointer:
-
-	  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)
-	    print_address_demangle (options, gdbarch, addr, stream, demangle);
-	  else if (options->addressprint)
-	    fputs_filtered (paddress (gdbarch, addr), stream);
-	}
+      addr = unpack_pointer (type, valaddr + embedded_offset);
+      print_unpacked_pointer (type, elttype, addr, stream, options);
       break;

     case TYPE_CODE_REF:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 08/14] Factor out function/method printing code from generic_val_print
  2015-07-23 21:45   ` Pedro Alves
@ 2015-07-27 18:17     ` Simon Marchi
  0 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-27 18:17 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On 15-07-23 05:45 PM, Pedro Alves wrote:
> On 07/15/2015 05:47 PM, Simon Marchi wrote:
> 
>> +/* generic_val_print helper for TYPE_CODE_FUNC and _METHOD.  */
> 
> Please spell out TYPE_CODE_METHOD to be grep friendlier.
> 
> Otherwise OK.
> 
> Thanks,
> Pedro Alves

Here is what I pushed:


From 4a8c372f1f82d1be24d2575e5979690efd839e08 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@ericsson.com>
Date: Mon, 27 Jul 2015 14:11:22 -0400
Subject: [PATCH] Factor out function/method printing code from
 generic_val_print

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out function/method
	printing code to ...
	(generic_val_print_func): ... this new function.
---
 gdb/ChangeLog  |  6 ++++++
 gdb/valprint.c | 46 +++++++++++++++++++++++++++++++---------------
 2 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4c6e17c..c5e6fe2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 2015-07-27  Simon Marchi  <simon.marchi@ericsson.com>

+	* valprint.c (generic_val_print): Factor out function/method
+	printing code to ...
+	(generic_val_print_func): ... this new function.
+
+2015-07-27  Simon Marchi  <simon.marchi@ericsson.com>
+
 	* valprint.c (generic_val_print): Factor out flags
 	printing code to ...
 	(generic_val_print_flags): ... this new function.
diff --git a/gdb/valprint.c b/gdb/valprint.c
index d05b907..cb1a317 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -594,6 +594,35 @@ generic_val_print_flags (struct type *type, const gdb_byte *valaddr,
     val_print_type_code_flags (type, valaddr + embedded_offset, stream);
 }

+/* generic_val_print helper for TYPE_CODE_FUNC and TYPE_CODE_METHOD.  */
+
+static void
+generic_val_print_func (struct type *type, const gdb_byte *valaddr,
+			int embedded_offset, CORE_ADDR address,
+			struct ui_file *stream,
+			const struct value *original_value,
+			const struct value_print_options *options)
+{
+  struct gdbarch *gdbarch = get_type_arch (type);
+
+  if (options->format)
+    {
+      val_print_scalar_formatted (type, valaddr, embedded_offset,
+				  original_value, options, 0, stream);
+    }
+  else
+    {
+      /* FIXME, we should consider, at least for ANSI C language,
+         eliminating the distinction made between FUNCs and POINTERs
+         to FUNCs.  */
+      fprintf_filtered (stream, "{");
+      type_print (type, "", stream, -1);
+      fprintf_filtered (stream, "} ");
+      /* Try to print what function it points to, and its address.  */
+      print_address_demangle (options, gdbarch, address, stream, demangle);
+    }
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -613,7 +642,6 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
 		   const struct value_print_options *options,
 		   const struct generic_val_print_decorations *decorations)
 {
-  struct gdbarch *gdbarch = get_type_arch (type);
   struct type *unresolved_type = type;
   LONGEST val;

@@ -652,20 +680,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,

     case TYPE_CODE_FUNC:
     case TYPE_CODE_METHOD:
-      if (options->format)
-	{
-	  val_print_scalar_formatted (type, valaddr, embedded_offset,
-				      original_value, options, 0, stream);
-	  break;
-	}
-      /* FIXME, we should consider, at least for ANSI C language,
-         eliminating the distinction made between FUNCs and POINTERs
-         to FUNCs.  */
-      fprintf_filtered (stream, "{");
-      type_print (type, "", stream, -1);
-      fprintf_filtered (stream, "} ");
-      /* Try to print what function it points to, and its address.  */
-      print_address_demangle (options, gdbarch, address, stream, demangle);
+      generic_val_print_func (type, valaddr, embedded_offset, address, stream,
+			      original_value, options);
       break;

     case TYPE_CODE_BOOL:
-- 
2.1.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 11/14] Factor out char printing code from generic_val_print
  2015-07-23 21:46   ` Pedro Alves
@ 2015-07-27 18:17     ` Simon Marchi
  0 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-27 18:17 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On 15-07-23 05:45 PM, Pedro Alves wrote:
> On 07/15/2015 05:47 PM, Simon Marchi wrote:
>> +/* generic_val_print helper for TYPE_CODE_INT.  */
> 
> TYPE_CODE_CHAR.  Otherwise looks good.
> 
>> +
>> +static void
>> +generic_val_print_char (struct type *type, struct type *unresolved_type,
>> +			const gdb_byte *valaddr, int embedded_offset,
>> +			struct ui_file *stream,
>> +			const struct value *original_value,
>> +			const struct value_print_options *options)
> 
> 
> Thanks,
> Pedro Alves

Here is what I pushed:


From 385f5affc00e88ad6ff0f8287bb3c1c43d59351c Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@ericsson.com>
Date: Mon, 27 Jul 2015 14:11:24 -0400
Subject: [PATCH] Factor out char printing code from generic_val_print

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out char
	printing code to ...
	(generic_val_print_char): ... this new function.
---
 gdb/ChangeLog  |  6 ++++++
 gdb/valprint.c | 54 ++++++++++++++++++++++++++++++++++--------------------
 2 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index bf318c3..782a893 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 2015-07-27  Simon Marchi  <simon.marchi@ericsson.com>

+	* valprint.c (generic_val_print): Factor out char
+	printing code to ...
+	(generic_val_print_char): ... this new function.
+
+2015-07-27  Simon Marchi  <simon.marchi@ericsson.com>
+
 	* valprint.c (generic_val_print): Factor out integer
 	printing code to ...
 	(generic_val_print_int): ... this new function.
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 887701c..c8f1e0a 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -675,6 +675,38 @@ generic_val_print_int (struct type *type, const gdb_byte *valaddr,
     val_print_type_code_int (type, valaddr + embedded_offset, stream);
 }

+/* generic_val_print helper for TYPE_CODE_CHAR.  */
+
+static void
+generic_val_print_char (struct type *type, struct type *unresolved_type,
+			const gdb_byte *valaddr, int embedded_offset,
+			struct ui_file *stream,
+			const struct value *original_value,
+			const struct value_print_options *options)
+{
+  LONGEST val;
+
+  if (options->format || options->output_format)
+    {
+      struct value_print_options opts = *options;
+
+      opts.format = (options->format ? options->format
+		     : options->output_format);
+      val_print_scalar_formatted (type, valaddr, embedded_offset,
+				  original_value, &opts, 0, stream);
+    }
+  else
+    {
+      val = unpack_long (type, valaddr + embedded_offset);
+      if (TYPE_UNSIGNED (type))
+	fprintf_filtered (stream, "%u", (unsigned int) val);
+      else
+	fprintf_filtered (stream, "%d", (int) val);
+      fputs_filtered (" ", stream);
+      LA_PRINT_CHAR (val, unresolved_type, stream);
+    }
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -695,7 +727,6 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
 		   const struct generic_val_print_decorations *decorations)
 {
   struct type *unresolved_type = type;
-  LONGEST val;

   type = check_typedef (type);
   switch (TYPE_CODE (type))
@@ -758,25 +789,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       break;

     case TYPE_CODE_CHAR:
-      if (options->format || options->output_format)
-	{
-	  struct value_print_options opts = *options;
-
-	  opts.format = (options->format ? options->format
-			 : options->output_format);
-	  val_print_scalar_formatted (type, valaddr, embedded_offset,
-				      original_value, &opts, 0, stream);
-	}
-      else
-	{
-	  val = unpack_long (type, valaddr + embedded_offset);
-	  if (TYPE_UNSIGNED (type))
-	    fprintf_filtered (stream, "%u", (unsigned int) val);
-	  else
-	    fprintf_filtered (stream, "%d", (int) val);
-	  fputs_filtered (" ", stream);
-	  LA_PRINT_CHAR (val, unresolved_type, stream);
-	}
+      generic_val_print_char (type, unresolved_type, valaddr, embedded_offset,
+			      stream, original_value, options);
       break;

     case TYPE_CODE_FLT:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 12/14] Factor out float printing code from generic_val_print
  2015-07-23 21:46   ` Pedro Alves
@ 2015-07-27 18:18     ` Simon Marchi
  0 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2015-07-27 18:18 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On 15-07-23 05:46 PM, Pedro Alves wrote:
> On 07/15/2015 05:47 PM, Simon Marchi wrote:
>> +/* generic_val_print helper for TYPE_CODE_FLT.  */
>> +
>> +static void
>> +generic_val_print_float (struct type *type, const gdb_byte *valaddr,
>> +			 int embedded_offset, struct ui_file *stream,
>> +			 const struct value *original_value,
>> +			 const struct value_print_options *options)
>> +{
>> +      if (options->format)
>> +	{
>> +	  val_print_scalar_formatted (type, valaddr, embedded_offset,
>> +				      original_value, options, 0, stream);
>> +	}
>> +      else
>> +	{
>> +	  print_floating (valaddr + embedded_offset, type, stream);
>> +	}
> 
> Wrong indentation, it seem.  Otherwise OK.
> 
>> +}
> 
> 
> Thanks,
> Pedro Alves

Here is what I pushed:


From 7784724bb1b8a5732239e27935cd76813b9df35c Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@ericsson.com>
Date: Mon, 27 Jul 2015 14:11:24 -0400
Subject: [PATCH] Factor out float printing code from generic_val_print

gdb/ChangeLog:

	* valprint.c (generic_val_print): Factor out float
	printing code to ...
	(generic_val_print_float): ... this new function.
---
 gdb/ChangeLog  |  6 ++++++
 gdb/valprint.c | 30 +++++++++++++++++++++---------
 2 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 782a893..135e789 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 2015-07-27  Simon Marchi  <simon.marchi@ericsson.com>

+	* valprint.c (generic_val_print): Factor out float
+	printing code to ...
+	(generic_val_print_float): ... this new function.
+
+2015-07-27  Simon Marchi  <simon.marchi@ericsson.com>
+
 	* valprint.c (generic_val_print): Factor out char
 	printing code to ...
 	(generic_val_print_char): ... this new function.
diff --git a/gdb/valprint.c b/gdb/valprint.c
index c8f1e0a..0bce438 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -707,6 +707,25 @@ generic_val_print_char (struct type *type, struct type *unresolved_type,
     }
 }

+/* generic_val_print helper for TYPE_CODE_FLT.  */
+
+static void
+generic_val_print_float (struct type *type, const gdb_byte *valaddr,
+			 int embedded_offset, struct ui_file *stream,
+			 const struct value *original_value,
+			 const struct value_print_options *options)
+{
+  if (options->format)
+    {
+      val_print_scalar_formatted (type, valaddr, embedded_offset,
+				  original_value, options, 0, stream);
+    }
+  else
+    {
+      print_floating (valaddr + embedded_offset, type, stream);
+    }
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -794,15 +813,8 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
       break;

     case TYPE_CODE_FLT:
-      if (options->format)
-	{
-	  val_print_scalar_formatted (type, valaddr, embedded_offset,
-				      original_value, options, 0, stream);
-	}
-      else
-	{
-	  print_floating (valaddr + embedded_offset, type, stream);
-	}
+      generic_val_print_float (type, valaddr, embedded_offset, stream,
+			       original_value, options);
       break;

     case TYPE_CODE_DECFLOAT:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2015-07-27 18:18 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-15 16:47 [PATCH 00/14] Split generic_val_print in smaller parts Simon Marchi
2015-07-15 16:47 ` [PATCH 06/14] Factor out enum printing code from generic_val_print Simon Marchi
2015-07-15 16:47 ` [PATCH 01/14] Factor out print_unpacked_pointer " Simon Marchi
2015-07-23 21:45   ` Pedro Alves
2015-07-24  2:29     ` Simon Marchi
2015-07-27 18:16     ` Simon Marchi
2015-07-15 16:47 ` [PATCH 04/14] Factor out memberptr printing code " Simon Marchi
2015-07-15 16:48 ` [PATCH 11/14] Factor out char " Simon Marchi
2015-07-23 21:46   ` Pedro Alves
2015-07-27 18:17     ` Simon Marchi
2015-07-15 16:48 ` [PATCH 12/14] Factor out float " Simon Marchi
2015-07-23 21:46   ` Pedro Alves
2015-07-27 18:18     ` Simon Marchi
2015-07-15 16:48 ` [PATCH 05/14] Factor out reference " Simon Marchi
2015-07-15 16:48 ` [PATCH 09/14] Factor out bool " Simon Marchi
2015-07-15 16:48 ` [PATCH 07/14] Factor out flags " Simon Marchi
2015-07-15 16:48 ` [PATCH 14/14] Factor out complex " Simon Marchi
2015-07-15 16:48 ` [PATCH 13/14] Factor out decfloat " Simon Marchi
2015-07-15 16:48 ` [PATCH 03/14] Factor out pointer " Simon Marchi
2015-07-15 16:48 ` [PATCH 08/14] Factor out function/method " Simon Marchi
2015-07-23 21:45   ` Pedro Alves
2015-07-27 18:17     ` Simon Marchi
2015-07-15 16:48 ` [PATCH 02/14] Factor out array " Simon Marchi
2015-07-15 16:48 ` [PATCH 10/14] Factor out int " Simon Marchi
2015-07-23 21:54 ` [PATCH 00/14] Split generic_val_print in smaller parts Pedro Alves
2015-07-27 18:14   ` Simon Marchi

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).