This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Factor out struct and union printing code from c_val_print


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9e4f353ca9d4f4ae70ce76ae704e5686d47e2f63

commit 9e4f353ca9d4f4ae70ce76ae704e5686d47e2f63
Author: Simon Marchi <simon.marchi@ericsson.com>
Date:   Thu Jul 9 11:18:39 2015 -0400

    Factor out struct and union printing code from c_val_print
    
    gdb/ChangeLog:
    
    	* c-valprint.c (c_val_print): Factor out struct and union
    	printing code to ...
    	(c_val_print_struct): ... this new function ...
    	(c_val_print_union): ... and this new function.

Diff:
---
 gdb/ChangeLog    |  7 +++++
 gdb/c-valprint.c | 88 +++++++++++++++++++++++++++++++++++++-------------------
 2 files changed, 65 insertions(+), 30 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 54f7374..34adebe 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
 2015-07-09  Simon Marchi  <simon.marchi@ericsson.com>
 
+	* c-valprint.c (c_val_print): Factor out struct and union
+	printing code to ...
+	(c_val_print_struct): ... this new function ...
+	(c_val_print_union): ... and this new function.
+
+2015-07-09  Simon Marchi  <simon.marchi@ericsson.com>
+
 	* c-valprint.c (c_val_print): Factor out pointer printing code
 	to ...
 	(c_val_print_ptr): ... this new function.
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index 4853575..a22a9d3 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -370,6 +370,58 @@ c_val_print_ptr (struct type *type, const gdb_byte *valaddr,
     }
 }
 
+/* c_val_print helper for TYPE_CODE_STRUCT.  */
+
+static void
+c_val_print_struct (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)
+{
+  if (options->vtblprint && cp_is_vtbl_ptr_type (type))
+    {
+      /* Print the unmangled name if desired.  */
+      /* Print vtable entry - we only get here if NOT using
+	 -fvtable_thunks.  (Otherwise, look under
+	 TYPE_CODE_PTR.)  */
+      struct gdbarch *gdbarch = get_type_arch (type);
+      int offset = (embedded_offset
+		    + TYPE_FIELD_BITPOS (type,
+					 VTBL_FNADDR_OFFSET) / 8);
+      struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET);
+      CORE_ADDR addr = extract_typed_address (valaddr + offset, field_type);
+
+      print_function_pointer_address (options, gdbarch, addr, stream);
+    }
+  else
+    cp_print_value_fields_rtti (type, valaddr,
+				embedded_offset, address,
+				stream, recurse,
+				original_value, options,
+				NULL, 0);
+}
+
+/* c_val_print helper for TYPE_CODE_UNION.  */
+
+static void
+c_val_print_union (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)
+{
+  if (recurse && !options->unionprint)
+    {
+      fprintf_filtered (stream, "{...}");
+     }
+  else
+    {
+      c_val_print_struct (type, valaddr, embedded_offset, address, stream,
+			  recurse, original_value, options);
+    }
+}
+
 /* See val_print for a description of the various parameters of this
    function; they are identical.  */
 
@@ -380,7 +432,6 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
 	     const struct value *original_value,
 	     const struct value_print_options *options)
 {
-  struct gdbarch *gdbarch = get_type_arch (type);
   struct type *unresolved_type = type;
 
   CHECK_TYPEDEF (type);
@@ -401,36 +452,13 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
       break;
 
     case TYPE_CODE_UNION:
-      if (recurse && !options->unionprint)
-	{
-	  fprintf_filtered (stream, "{...}");
-	  break;
-	}
-      /* Fall through.  */
+      c_val_print_union (type, valaddr, embedded_offset, address, stream,
+			 recurse, original_value, options);
+      break;
+
     case TYPE_CODE_STRUCT:
-      /*FIXME: Abstract this away.  */
-      if (options->vtblprint && cp_is_vtbl_ptr_type (type))
-	{
-	  /* Print the unmangled name if desired.  */
-	  /* Print vtable entry - we only get here if NOT using
-	     -fvtable_thunks.  (Otherwise, look under
-	     TYPE_CODE_PTR.)  */
-	  int offset = (embedded_offset
-			+ TYPE_FIELD_BITPOS (type,
-					     VTBL_FNADDR_OFFSET) / 8);
-	  struct type *field_type = TYPE_FIELD_TYPE (type,
-						     VTBL_FNADDR_OFFSET);
-	  CORE_ADDR addr
-	    = extract_typed_address (valaddr + offset, field_type);
-
-	  print_function_pointer_address (options, gdbarch, addr, stream);
-	}
-      else
-	cp_print_value_fields_rtti (type, valaddr,
-				    embedded_offset, address,
-				    stream, recurse,
-				    original_value, options,
-				    NULL, 0);
+      c_val_print_struct (type, valaddr, embedded_offset, address, stream,
+			  recurse, original_value, options);
       break;
 
     case TYPE_CODE_INT:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]