Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Leutwein Tobias (BEG-PT/ESB1)" <Tobias.Leutwein@de.bosch.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: AW: [RFC, patch] ptype bitfields show bitpos and bitsize
Date: Mon, 20 Feb 2012 12:26:00 -0000	[thread overview]
Message-ID: <1606F039DD6642449BF6D1519D43AF621619BB4553@SI-MBX09.de.bosch.com> (raw)
In-Reply-To: <20120125112233.GA18042@host2.jankratochvil.net>

[-- Attachment #1: Type: text/plain, Size: 4476 bytes --]

I have reworked the patch for showing the bitpos and bitsize of bitfields through the
ptype command.
Now I didn't see any test cases, which passed before, failing.
Also there are some test cases regarding the new behavior of the ptype command added.
I haven't run the test suit on a big endian target, so probably the test cases will
fail on big endian targets.

I have tried to change the parameter "type" to "value" at the ..._print_type
functions, but I haven't got it to work. So the ..._print_type_through_value
functions are still needed.

Tobias


* ada-lang.c: Extension of ptype command for showing the bitpos
and bitsize of bitfield variables. ada_print_type_through_value
added.

* ada-lang.h: Extension of ptype command for showing the bitpos
and bitsize of bitfield variables. ada_print_type_through_value
added.

* ada-typeprint.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
ada_print_type_through_valuem added.

* c-lang.c: Extension of ptype command for showing the bitpos
and bitsize of bitfield variables. c_print_type_through_value
added.

* c-lang.h: Extension of ptype command for showing the bitpos
and bitsize of bitfield variables. c_print_type_through_value
added.

* c-typeprint.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables. c_print_type_common(),
c_type_print_base_common(), c_print_type_through_value() and
c_type_print_base_through_value() added.

* d-lang.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
c_print_type_through_value() added.

* f-lang.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
f_print_type_through_value() added.

* f-typeprint.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
f_print_type_through_value() added.

* jv-lang.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
java_print_type_through_value () added.

* jv-lang.h: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
java_print_type_through_value() added.

* jv-typeprint.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
java_print_type_through_value() added.

* language.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
unk_lang_print_type_through_value() added.

* language.h: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
LA_PRINT_TYPE_THROUGH_VALUE, la_print_type_through_value added.

* m2-lang.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
m2_print_type_through_value() added.

* m2-lang.h: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
m2_print_type_through_value() added.

* m2-typeprint.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
m2_print_type_through_value() added.

* objc-lang.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables. At
objc_language_defn c_print_type_through_value added.

* opencl-lang.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables. At
opencl_language_defn c_print_type_through_value added.

* p-lang.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
pascal_print_type_through_value() added.

* p-lang.h: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
pascal_print_type_through_value() added.

* p-typeprint.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
pascal_print_type_through_value() added.

* testsuite/gdb.base/bitfields2.exp: Extension of ptype command
for showing the bitpos and bitsize of bitfield variables. Test
cases for bitfield position und size added.

* testsuite/gdb.base/bitfields.exp: Extension of ptype command
for showing the bitpos and bitsize of bitfield variables. Test
cases for bitfield position und size added.

* typeprint.c: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
type_print_through_value() added.

* value.h: Extension of ptype command for showing the
bitpos and bitsize of bitfield variables.
type_print_through_value() added.


[-- Attachment #2: gdbPtype.diff --]
[-- Type: application/octet-stream, Size: 28758 bytes --]

diff -ur 7.4_orig/gdb/ada-lang.c 7.4_ptypeMixed/gdb/ada-lang.c
--- 7.4_orig/gdb/ada-lang.c	2012-01-06 04:34:45.000000000 +0100
+++ 7.4_ptypeMixed/gdb/ada-lang.c	2012-01-25 22:16:53.000000000 +0100
@@ -12337,6 +12337,7 @@
   ada_printstr,                 /* Function to print string constant */
   emit_char,                    /* Function to print single char (not used) */
   ada_print_type,               /* Print a type using appropriate syntax */
+  ada_print_type_through_value, /* Print a type using appropriate syntax */
   ada_print_typedef,            /* Print a typedef using appropriate syntax */
   ada_val_print,                /* Print a value using appropriate syntax */
   ada_value_print,              /* Print a top-level value */
diff -ur 7.4_orig/gdb/ada-lang.h 7.4_ptypeMixed/gdb/ada-lang.h
--- 7.4_orig/gdb/ada-lang.h	2012-01-04 09:16:55.000000000 +0100
+++ 7.4_ptypeMixed/gdb/ada-lang.h	2012-01-25 22:16:53.000000000 +0100
@@ -160,6 +160,8 @@
                         /* Defined in ada-typeprint.c */
 extern void ada_print_type (struct type *, const char *, struct ui_file *, int,
                             int);
+extern void ada_print_type_through_value (struct value *, const char *, struct ui_file *, int,
+                            int);
 
 extern void ada_print_typedef (struct type *type, struct symbol *new_symbol,
 			       struct ui_file *stream);
diff -ur 7.4_orig/gdb/ada-typeprint.c 7.4_ptypeMixed/gdb/ada-typeprint.c
--- 7.4_orig/gdb/ada-typeprint.c	2012-01-04 09:16:55.000000000 +0100
+++ 7.4_ptypeMixed/gdb/ada-typeprint.c	2012-01-25 22:16:53.000000000 +0100
@@ -871,3 +871,25 @@
   ada_print_type (type, "", stream, 0, 0);
   fprintf_filtered (stream, "\n");
 }
+
+
+/* Print a description of a value value_p.
+   Output goes to STREAM (via stdio).
+   If VARSTRING is a non-empty string, print as an Ada variable/field
+       declaration.
+   SHOW+1 is the maximum number of levels of internal type structure
+      to show (this applies to record types, enumerated types, and
+      array types).
+   SHOW is the number of levels of internal type structure to show
+      when there is a type name for the SHOWth deepest level (0th is
+      outer level).
+   When SHOW<0, no inner structure is shown.
+   LEVEL indicates level of recursion (for nested definitions).  */
+
+void
+ada_print_type_through_value (struct value *value_p, const char *varstring, struct ui_file *stream,
+		int show, int level)
+{
+	struct type *type_p = value_type(value_p);
+	ada_print_type(type_p, varstring, stream, show, level);
+}
diff -ur 7.4_orig/gdb/c-lang.c 7.4_ptypeMixed/gdb/c-lang.c
--- 7.4_orig/gdb/c-lang.c	2012-01-04 09:16:59.000000000 +0100
+++ 7.4_ptypeMixed/gdb/c-lang.c	2012-01-25 22:16:53.000000000 +0100
@@ -844,6 +844,7 @@
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
   c_print_type,			/* Print a type using appropriate syntax */
+  c_print_type_through_value,			/* Print a type using appropriate syntax */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
@@ -967,6 +968,7 @@
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
   c_print_type,			/* Print a type using appropriate syntax */
+  c_print_type_through_value,			/* Print a type using appropriate syntax */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
@@ -1008,6 +1010,7 @@
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
   c_print_type,			/* Print a type using appropriate syntax */
+  c_print_type_through_value,			/* Print a type using appropriate syntax */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
@@ -1054,6 +1057,7 @@
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
   c_print_type,			/* Print a type using appropriate syntax */
+  c_print_type_through_value,			/* Print a type using appropriate syntax */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
diff -ur 7.4_orig/gdb/c-lang.h 7.4_ptypeMixed/gdb/c-lang.h
--- 7.4_orig/gdb/c-lang.h	2012-01-04 09:17:00.000000000 +0100
+++ 7.4_ptypeMixed/gdb/c-lang.h	2012-01-25 22:16:53.000000000 +0100
@@ -66,6 +66,8 @@
 /* Defined in c-typeprint.c */
 extern void c_print_type (struct type *, const char *,
 			  struct ui_file *, int, int);
+extern void c_print_type_through_value (struct value *, 
+              const char *, struct ui_file *, int, int);
 
 extern void c_print_typedef (struct type *,
 			     struct symbol *,
@@ -111,6 +113,8 @@
 
 extern void c_type_print_base (struct type *, struct ui_file *,
 			       int, int);
+extern void c_type_print_base_through_value (struct value *, 
+			struct ui_file *, int, int);
 
 /* These are in cp-valprint.c */
 
diff -ur 7.4_orig/gdb/c-typeprint.c 7.4_ptypeMixed/gdb/c-typeprint.c
--- 7.4_orig/gdb/c-typeprint.c	2012-01-04 09:17:00.000000000 +0100
+++ 7.4_ptypeMixed/gdb/c-typeprint.c	2012-02-13 20:08:01.000000000 +0100
@@ -35,23 +35,52 @@
 #include "gdb_string.h"
 #include <errno.h>
 
+static void c_print_type_common( struct value *value, 
+					struct type *type, 
+					const char *varstring, 
+					struct ui_file *stream,	
+					int show, int level );
+					
 static void c_type_print_varspec_prefix (struct type *,
 					 struct ui_file *,
 					 int, int, int);
 
+/* Print the name of the type */
+static void c_type_print_base_common (struct value *value, struct type *type, struct ui_file *stream, int show,
+		   int level);
+
 /* Print "const", "volatile", or address space modifiers.  */
 static void c_type_print_modifier (struct type *,
 				   struct ui_file *,
 				   int, int);
-\f
-/* LEVEL is the depth to indent lines by.  */
 
+				   
+
+/*   \param[in]	level	 The depth to indent lines by. */
 void
 c_print_type (struct type *type,
 	      const char *varstring,
 	      struct ui_file *stream,
 	      int show, int level)
 {
+	c_print_type_common(0, type, varstring, stream, show, level);
+}
+
+
+/*    
+   \param[in]	value	Pointer to the value object. \b 0, if the value object is unknown.
+   
+   \param[in]	type	Pointer to the type object. If value object is know it can be determined through: value_type (value)
+
+   \param[in]	level	 The depth to indent lines by.  
+*/
+static void
+c_print_type_common( struct value *value, 
+				struct type *type, 
+				const char *varstring, 
+				struct ui_file *stream,
+				int show, int level )
+{
   enum type_code code;
   int demangled_args;
   int need_post_space;
@@ -59,7 +88,7 @@
   if (show > 0)
     CHECK_TYPEDEF (type);
 
-  c_type_print_base (type, stream, show, level);
+  c_type_print_base_common (value, type, stream, show, level);
   code = TYPE_CODE (type);
   if ((varstring != NULL && *varstring != '\0')
   /* Need a space if going to print stars or brackets;
@@ -88,6 +117,17 @@
     }
 }
 
+
+/*    \param[in]	level	 The depth to indent lines by.  
+*/
+void
+c_print_type_through_value (struct value *value, const char *varstring, struct ui_file *stream,
+	      int show, int level)
+{
+	c_print_type_common(value, value_type(value), varstring, stream, show, level);
+}
+
+
 /* Print a typedef using C syntax.  TYPE is the underlying type.
    NEW_SYMBOL is the symbol naming the type.  STREAM is the stream on
    which to print.  */
@@ -715,6 +755,42 @@
 c_type_print_base (struct type *type, struct ui_file *stream,
 		   int show, int level)
 {
+	c_type_print_base_common(0, type, stream, show, level);
+}
+
+
+/* Print the name of the type (or the ultimate pointer target,
+   function value or array element), or the description of a structure
+   or union.
+
+   SHOW positive means print details about the type (e.g. enum
+   values), and print structure elements passing SHOW - 1 for show.
+
+   SHOW negative means just print the type name or struct tag if there
+   is one.  If there is no name, print something sensible but concise
+   like "struct {...}".
+
+   SHOW zero means just print the type name or struct tag if there is
+   one.  If there is no name, print something sensible but not as
+   concise like "struct {int x; int y;}".
+
+   LEVEL is the number of spaces to indent by.
+   We increase it for some recursive calls.  
+   
+   \param[in]	value	Pointer to the value object. \b 0, if the value object is unknown.
+   
+   \param[in]	type	Pointer to the type object. If value object is know it can be determined through: value_type (value)
+
+   \remarks Like c_type_print_base but if it is a bitfield variable, the 
+   position and size will be shown if is not equal to 0.
+*/
+static void
+c_type_print_base_common (struct value *value, 
+				struct type *type, 
+				struct ui_file *stream, 
+				int show,
+				int level )
+{
   int i;
   int len, real_len;
   int lastval;
@@ -1247,6 +1323,24 @@
 	{
 	  c_type_print_modifier (type, stream, 0, 1);
 	  fputs_filtered (TYPE_NAME (type), stream);
+	  
+	  if ( value != 0 )
+	  {	/* Function is called with value pointer. */
+		  {	/* show the bit position of this value, if it is not equal to 0 */
+		    int bitpos_i = value_bitpos(value);
+		    if (bitpos_i != 0)
+		    {
+		      fprintf_filtered (stream, ", bitpos = %d", bitpos_i);
+		    }
+		  }
+		  {	/* show the bit size of this value, if it is not equal to 0 */
+		    int bitsize_i = value_bitsize(value);
+		    if (bitsize_i != 0)
+		    {
+		      fprintf_filtered (stream, ", bitsize = %d", bitsize_i);
+		    }
+		  }
+	  }
 	}
       else
 	{
@@ -1258,3 +1352,31 @@
       break;
     }
 }
+
+
+/* Print the name of the type (or the ultimate pointer target,
+   function value or array element), or the description of a
+   structure or union.
+
+   SHOW positive means print details about the type (e.g. enum values),
+   and print structure elements passing SHOW - 1 for show.
+   SHOW negative means just print the type name or struct tag if there is one.
+   If there is no name, print something sensible but concise like
+   "struct {...}".
+   SHOW zero means just print the type name or struct tag if there is one.
+   If there is no name, print something sensible but not as concise like
+   "struct {int x; int y;}".
+
+   LEVEL is the number of spaces to indent by.
+   We increase it for some recursive calls.  
+
+   \remarks Like c_type_print_base but if it is a bitfield variable, the 
+   position and size will be shown if is not equal to 0.
+*/
+void
+c_type_print_base_through_value (struct value *value, struct ui_file *stream, int show,
+		   int level)
+{
+	c_type_print_base_common(value, value_type(value), stream, show, level);
+}
+
diff -ur 7.4_orig/gdb/d-lang.c 7.4_ptypeMixed/gdb/d-lang.c
--- 7.4_orig/gdb/d-lang.c	2012-01-04 09:17:00.000000000 +0100
+++ 7.4_ptypeMixed/gdb/d-lang.c	2012-02-10 21:34:32.000000000 +0100
@@ -252,6 +252,8 @@
   c_printstr,			/* Function to print string constant.  */
   c_emit_char,			/* Print a single char.  */
   c_print_type,			/* Print a type using appropriate syntax.  */
+  c_print_type_through_value,	/* Print a type using appropriate 
+                   syntax */
   c_print_typedef,		/* Print a typedef using appropriate
 				   syntax.  */
   d_val_print,			/* Print a value using appropriate syntax.  */
diff -ur 7.4_orig/gdb/eval.c 7.4_ptypeMixed/gdb/eval.c
--- 7.4_orig/gdb/eval.c	2012-01-09 21:27:48.000000000 +0100
+++ 7.4_ptypeMixed/gdb/eval.c	2012-02-07 19:24:13.000000000 +0100
@@ -1945,12 +1945,6 @@
       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
       if (noside == EVAL_SKIP)
 	goto nosideret;
-      if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	return value_zero (lookup_struct_elt_type (value_type (arg1),
-						   &exp->elts[pc + 2].string,
-						   0),
-			   lval_memory);
-      else
 	{
 	  struct value *temp = arg1;
 
diff -ur 7.4_orig/gdb/f-lang.c 7.4_ptypeMixed/gdb/f-lang.c
--- 7.4_orig/gdb/f-lang.c	2012-01-04 09:17:02.000000000 +0100
+++ 7.4_ptypeMixed/gdb/f-lang.c	2012-01-25 22:16:53.000000000 +0100
@@ -290,6 +290,7 @@
   f_printstr,			/* function to print string constant */
   f_emit_char,			/* Function to print a single character */
   f_print_type,			/* Print a type using appropriate syntax */
+  f_print_type_through_value,	/* Print a type using appropriate syntax */
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   f_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* FIXME */
diff -ur 7.4_orig/gdb/f-lang.h 7.4_ptypeMixed/gdb/f-lang.h
--- 7.4_orig/gdb/f-lang.h	2012-01-04 09:17:02.000000000 +0100
+++ 7.4_ptypeMixed/gdb/f-lang.h	2012-01-25 22:16:53.000000000 +0100
@@ -27,6 +27,8 @@
 
 extern void f_print_type (struct type *, const char *, struct ui_file *, int,
 			  int);
+extern void f_print_type_through_value (struct value *, const char *, struct ui_file *, int,
+			  int);
 
 extern int f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR,
 			struct ui_file *, int,
diff -ur 7.4_orig/gdb/f-typeprint.c 7.4_ptypeMixed/gdb/f-typeprint.c
--- 7.4_orig/gdb/f-typeprint.c	2012-01-04 09:17:02.000000000 +0100
+++ 7.4_ptypeMixed/gdb/f-typeprint.c	2012-01-25 22:16:53.000000000 +0100
@@ -82,6 +82,18 @@
    }
 }
 
+
+/* LEVEL is the depth to indent lines by.  */
+
+void
+f_print_type_through_value (struct value *value_p, const char *varstring, struct ui_file *stream,
+	      int show, int level)
+{
+  struct type *type_p = value_type(value_p);
+  f_print_type (type_p, varstring, stream, show, level);
+}
+
+
 /* Print any asterisks or open-parentheses needed before the
    variable name (to describe its type).
 
diff -ur 7.4_orig/gdb/jv-lang.c 7.4_ptypeMixed/gdb/jv-lang.c
--- 7.4_orig/gdb/jv-lang.c	2012-01-08 22:02:45.000000000 +0100
+++ 7.4_ptypeMixed/gdb/jv-lang.c	2012-01-25 22:16:53.000000000 +0100
@@ -1178,6 +1178,7 @@
   java_printstr,		/* Function to print string constant */
   java_emit_char,		/* Function to print a single character */
   java_print_type,		/* Print a type using appropriate syntax */
+  java_print_type_through_value,	/* Print a type using appropriate syntax */
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   java_val_print,		/* Print a value using appropriate syntax */
   java_value_print,		/* Print a top-level value */
diff -ur 7.4_orig/gdb/jv-lang.h 7.4_ptypeMixed/gdb/jv-lang.h
--- 7.4_orig/gdb/jv-lang.h	2012-01-04 09:17:05.000000000 +0100
+++ 7.4_ptypeMixed/gdb/jv-lang.h	2012-01-25 22:16:53.000000000 +0100
@@ -71,6 +71,8 @@
 /* Defined in jv-typeprint.c */
 extern void java_print_type (struct type *, const char *,
 			     struct ui_file *, int, int);
+extern void java_print_type_through_value (struct value *, const char *,
+				 struct ui_file *, int, int);
 
 extern char *java_demangle_type_signature (char *);
 
diff -ur 7.4_orig/gdb/jv-typeprint.c 7.4_ptypeMixed/gdb/jv-typeprint.c
--- 7.4_orig/gdb/jv-typeprint.c	2012-01-04 09:17:05.000000000 +0100
+++ 7.4_ptypeMixed/gdb/jv-typeprint.c	2012-01-25 22:16:53.000000000 +0100
@@ -352,3 +352,12 @@
   demangled_args = varstring != NULL && strchr (varstring, '(') != NULL;
   c_type_print_varspec_suffix (type, stream, show, 0, demangled_args);
 }
+
+
+void
+java_print_type_through_value (struct value *value_p, const char *varstring, struct ui_file *stream,
+		 int show, int level)
+{
+	struct type *type_p = value_type(value_p);
+	java_print_type (type_p, varstring, stream, show, level);
+}
diff -ur 7.4_orig/gdb/language.c 7.4_ptypeMixed/gdb/language.c
--- 7.4_orig/gdb/language.c	2012-01-04 19:57:01.000000000 +0100
+++ 7.4_ptypeMixed/gdb/language.c	2012-01-25 22:16:53.000000000 +0100
@@ -847,6 +847,13 @@
 	   "function unk_lang_print_type called."));
 }
 
+static void
+unk_lang_print_type_through_value (struct value *value, const char *varstring, struct ui_file *stream,
+		     int show, int level)
+{
+  error (_("internal error - unimplemented function unk_lang_print_type_through_value called."));
+}
+
 static int
 unk_lang_val_print (struct type *type, const gdb_byte *valaddr,
 		    int embedded_offset, CORE_ADDR address,
@@ -914,6 +921,7 @@
   unk_lang_printstr,
   unk_lang_emit_char,
   unk_lang_print_type,		/* Print a type using appropriate syntax */
+  unk_lang_print_type_through_value,		/* Print a type using appropriate syntax */
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   unk_lang_val_print,		/* Print a value using appropriate syntax */
   unk_lang_value_print,		/* Print a top-level value */
@@ -957,6 +965,7 @@
   unk_lang_printstr,
   unk_lang_emit_char,
   unk_lang_print_type,		/* Print a type using appropriate syntax */
+  unk_lang_print_type_through_value,		/* Print a type using appropriate syntax */
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   unk_lang_val_print,		/* Print a value using appropriate syntax */
   unk_lang_value_print,		/* Print a top-level value */
@@ -998,6 +1007,7 @@
   unk_lang_printstr,
   unk_lang_emit_char,
   unk_lang_print_type,		/* Print a type using appropriate syntax */
+  unk_lang_print_type_through_value,		/* Print a type using appropriate syntax */
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   unk_lang_val_print,		/* Print a value using appropriate syntax */
   unk_lang_value_print,		/* Print a top-level value */
diff -ur 7.4_orig/gdb/language.h 7.4_ptypeMixed/gdb/language.h
--- 7.4_orig/gdb/language.h	2012-01-04 19:57:01.000000000 +0100
+++ 7.4_ptypeMixed/gdb/language.h	2012-01-25 22:16:53.000000000 +0100
@@ -202,6 +202,12 @@
     void (*la_print_type) (struct type *, const char *, struct ui_file *, int,
 			   int);
 
+    /* Print a type (through value structure) using syntax appropriate for 
+       this language. */
+
+    void (*la_print_type_through_value) (struct value *, const char *, struct ui_file *, int,
+			   int);
+
     /* Print a typedef using syntax appropriate for this language.
        TYPE is the underlying type.  NEW_SYMBOL is the symbol naming
        the type.  STREAM is the output stream on which to print.  */
@@ -433,6 +439,8 @@
 
 #define LA_PRINT_TYPE(type,varstring,stream,show,level) \
   (current_language->la_print_type(type,varstring,stream,show,level))
+#define LA_PRINT_TYPE_THROUGH_VALUE(value,varstring,stream,show,level) \
+  (current_language->la_print_type_through_value(value,varstring,stream,show,level))
 
 #define LA_PRINT_TYPEDEF(type,new_symbol,stream) \
   (current_language->la_print_typedef(type,new_symbol,stream))
diff -ur 7.4_orig/gdb/m2-lang.c 7.4_ptypeMixed/gdb/m2-lang.c
--- 7.4_orig/gdb/m2-lang.c	2012-01-04 09:17:05.000000000 +0100
+++ 7.4_ptypeMixed/gdb/m2-lang.c	2012-01-25 22:16:53.000000000 +0100
@@ -382,6 +382,7 @@
   m2_printstr,			/* function to print string constant */
   m2_emit_char,			/* Function to print a single character */
   m2_print_type,		/* Print a type using appropriate syntax */
+  m2_print_type_through_value,	/* Print a type using appropriate syntax */
   m2_print_typedef,		/* Print a typedef using appropriate syntax */
   m2_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
diff -ur 7.4_orig/gdb/m2-lang.h 7.4_ptypeMixed/gdb/m2-lang.h
--- 7.4_orig/gdb/m2-lang.h	2012-01-04 09:17:05.000000000 +0100
+++ 7.4_ptypeMixed/gdb/m2-lang.h	2012-01-25 22:16:53.000000000 +0100
@@ -25,6 +25,8 @@
 /* Defined in m2-typeprint.c */
 extern void m2_print_type (struct type *, const char *, struct ui_file *, int,
 			   int);
+extern void m2_print_type_through_value (struct value *, const char *, struct ui_file *, int,
+			   int);
 
 extern void m2_print_typedef (struct type *, struct symbol *,
 			      struct ui_file *);
diff -ur 7.4_orig/gdb/m2-typeprint.c 7.4_ptypeMixed/gdb/m2-typeprint.c
--- 7.4_orig/gdb/m2-typeprint.c	2012-01-04 09:17:05.000000000 +0100
+++ 7.4_ptypeMixed/gdb/m2-typeprint.c	2012-01-25 22:16:53.000000000 +0100
@@ -151,6 +151,16 @@
     }
 }
 
+
+void
+m2_print_type_through_value (struct value *value_p, const char *varstring, struct ui_file *stream,
+	       int show, int level)
+{
+	struct type *type_p = value_type(value_p);
+	m2_print_type (type_p, varstring, stream, show, level);
+}
+
+
 /* Print a typedef using M2 syntax.  TYPE is the underlying type.
    NEW_SYMBOL is the symbol naming the type.  STREAM is the stream on
    which to print.  */
diff -ur 7.4_orig/gdb/objc-lang.c 7.4_ptypeMixed/gdb/objc-lang.c
--- 7.4_orig/gdb/objc-lang.c	2012-01-04 09:17:08.000000000 +0100
+++ 7.4_ptypeMixed/gdb/objc-lang.c	2012-01-25 22:16:53.000000000 +0100
@@ -521,6 +521,7 @@
   objc_printstr,		/* Function to print string constant */
   objc_emit_char,
   c_print_type,			/* Print a type using appropriate syntax */
+  c_print_type_through_value,	/* Print a type using appropriate syntax */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
diff -ur 7.4_orig/gdb/opencl-lang.c 7.4_ptypeMixed/gdb/opencl-lang.c
--- 7.4_orig/gdb/opencl-lang.c	2012-01-04 09:17:09.000000000 +0100
+++ 7.4_ptypeMixed/gdb/opencl-lang.c	2012-01-25 22:16:53.000000000 +0100
@@ -1005,6 +1005,7 @@
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
   c_print_type,			/* Print a type using appropriate syntax */
+  c_print_type_through_value,	/* Print a type using appropriate syntax */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_val_print,			/* Print a value using appropriate syntax */
   c_value_print,		/* Print a top-level value */
diff -ur 7.4_orig/gdb/p-lang.c 7.4_ptypeMixed/gdb/p-lang.c
--- 7.4_orig/gdb/p-lang.c	2012-01-04 09:17:09.000000000 +0100
+++ 7.4_ptypeMixed/gdb/p-lang.c	2012-01-25 22:16:53.000000000 +0100
@@ -441,6 +441,7 @@
   pascal_printstr,		/* Function to print string constant */
   pascal_emit_char,		/* Print a single char */
   pascal_print_type,		/* Print a type using appropriate syntax */
+  pascal_print_type_through_value,	/* Print a type using appropriate syntax */
   pascal_print_typedef,		/* Print a typedef using appropriate syntax */
   pascal_val_print,		/* Print a value using appropriate syntax */
   pascal_value_print,		/* Print a top-level value */
diff -ur 7.4_orig/gdb/p-lang.h 7.4_ptypeMixed/gdb/p-lang.h
--- 7.4_orig/gdb/p-lang.h	2012-01-04 09:17:09.000000000 +0100
+++ 7.4_ptypeMixed/gdb/p-lang.h	2012-01-25 22:16:53.000000000 +0100
@@ -32,6 +32,9 @@
 extern void pascal_print_type (struct type *, const char *, struct ui_file *,
 			       int, int);
 
+extern void pascal_print_type_through_value (struct value *, const char *, 
+	               struct ui_file *, int, int);
+
 extern void pascal_print_typedef (struct type *, struct symbol *,
 				  struct ui_file *);
 
diff -ur 7.4_orig/gdb/p-typeprint.c 7.4_ptypeMixed/gdb/p-typeprint.c
--- 7.4_orig/gdb/p-typeprint.c	2012-01-04 09:17:09.000000000 +0100
+++ 7.4_ptypeMixed/gdb/p-typeprint.c	2012-01-25 22:16:53.000000000 +0100
@@ -89,6 +89,18 @@
 
 }
 
+
+/* LEVEL is the depth to indent lines by.  */
+
+void
+pascal_print_type_through_value (struct value *value_p, const char *varstring, struct ui_file *stream,
+		   int show, int level)
+{
+	struct type *type_p = value_type(value_p);
+	pascal_print_type (type_p, varstring, stream, show, level);
+}
+
+
 /* Print a typedef using Pascal syntax.  TYPE is the underlying type.
    NEW_SYMBOL is the symbol naming the type.  STREAM is the stream on
    which to print.  */
diff -ur 7.4_orig/gdb/testsuite/gdb.base/bitfields2.exp 7.4_ptypeMixed/gdb/testsuite/gdb.base/bitfields2.exp
--- 7.4_orig/gdb/testsuite/gdb.base/bitfields2.exp	2012-01-16 17:21:44.000000000 +0100
+++ 7.4_ptypeMixed/gdb/testsuite/gdb.base/bitfields2.exp	2012-02-10 21:42:17.000000000 +0100
@@ -62,7 +62,39 @@
     }
     continue_test $function "#0"
 }
-    
+
+
+#
+# Test bitfield member bit position and bit size
+#
+
+proc bitfield_ptype {} {
+    global decimal
+    global hex
+    global gdb_prompt
+    global srcfile
+
+	# \r\n for new line; " *" for white spaces
+    if [gdb_test "ptype flags" "type = struct fields {\r\n *long long unsigned int u1 : 15;\r\n *long long unsigned int u2 : 33;\r\n *long long unsigned int u3 : 16;\r\n *long long int s1 : 15;\r\n *long long int s2 : 33;\r\n *long long int s3 : 16;\r\n}"] {
+		gdb_suppress_tests;
+    }
+
+    if [gdb_test "ptype flags.u1" "type = long long unsigned int, bitsize = 15"] {
+		gdb_suppress_tests;
+	}
+	
+    if [gdb_test "ptype flags.u2" "type = long long unsigned int, bitpos = 15, bitsize = 33"] {
+		gdb_suppress_tests;
+    }
+	
+    if [gdb_test "ptype flags.s1" "type = long long int, bitsize = 15"] {
+		gdb_suppress_tests;
+    }
+	
+    if [gdb_test "ptype flags.s2" "type = long long int, bitpos = 15, bitsize = 33"] {
+		gdb_suppress_tests;
+    }
+}    
 
 #
 # Test bitfield locating and uniqueness.
@@ -287,6 +319,7 @@
 gdb_test_no_output "set print sevenbit-strings"
 runto_main
 
+bitfield_ptype
 bitfield_uniqueness
 bitfield_containment
 bitfield_unsignedness
diff -ur 7.4_orig/gdb/testsuite/gdb.base/bitfields.exp 7.4_ptypeMixed/gdb/testsuite/gdb.base/bitfields.exp
--- 7.4_orig/gdb/testsuite/gdb.base/bitfields.exp	2012-01-16 17:21:44.000000000 +0100
+++ 7.4_ptypeMixed/gdb/testsuite/gdb.base/bitfields.exp	2012-02-10 21:25:06.000000000 +0100
@@ -26,6 +26,34 @@
 }
 
 #
+# Test bitfield member bit position and bit size
+#
+
+proc bitfield_ptype {} {
+    global decimal
+    global hex
+    global gdb_prompt
+    global srcfile
+
+	# \r\n for new line; " *" for white spaces
+    if [gdb_test "ptype flags" "type = struct fields {\r\n *unsigned char uc;\r\n *int s1 : 1;\r\n *unsigned int u1 : 1;\r\n *int s2 : 2;\r\n *unsigned int u2 : 2;\r\n *int s3 : 3;\r\n *unsigned int u3 : 3;\r\n *int s9 : 9;\r\n *unsigned int u9 : 9;\r\n *signed char sc;\r\n}"] {
+		gdb_suppress_tests;
+    }
+
+    if [gdb_test "ptype flags.s9" "type = int, bitpos = 20, bitsize = 9"] {
+		gdb_suppress_tests;
+	}
+	
+    if [gdb_test "ptype flags.u9" "type = unsigned int, bitsize = 9"] {
+		gdb_suppress_tests;
+	}
+	
+    if [gdb_test "ptype flags.sc" "type = signed char"] {
+		gdb_suppress_tests;
+	}
+}    
+
+#
 # Test bitfield locating and uniqueness.
 # For each member, set that member to 1 and verify that the member (and only
 # that member) is 1, then reset it back to 0.
@@ -252,6 +280,7 @@
 
 gdb_test_no_output "set print sevenbit-strings"
 
+bitfield_ptype
 bitfield_uniqueness
 if [istarget "mips-idt-*"] then {
     # Restart because IDT/SIM runs out of file descriptors.
diff -ur 7.4_orig/gdb/typeprint.c 7.4_ptypeMixed/gdb/typeprint.c
--- 7.4_orig/gdb/typeprint.c	2012-01-04 09:27:57.000000000 +0100
+++ 7.4_ptypeMixed/gdb/typeprint.c	2012-02-07 19:25:57.000000000 +0100
@@ -79,6 +79,20 @@
   LA_PRINT_TYPE (type, varstring, stream, show, 0);
 }
 
+/* Print a description of a type TYPE in the form of a declaration of a
+   variable named VARSTRING.  (VARSTRING is demangled if necessary.)
+   Output goes to STREAM (via stdio).
+   If SHOW is positive, we show the contents of the outermost level
+   of structure even if there is a type name that could be used instead.
+   If SHOW is negative, we never show the details of elements' types.  */
+
+void
+type_print_through_value (struct value *value, char *varstring, struct ui_file *stream,
+	    int show)
+{
+  LA_PRINT_TYPE_THROUGH_VALUE (value, varstring, stream, show, 0);
+}
+
 /* Print TYPE to a string, returning it.  The caller is responsible for
    freeing the string.  */
 
@@ -164,7 +178,10 @@
       printf_filtered (" */\n");    
     }
 
-  type_print (type, "", gdb_stdout, show);
+  /* To see the positon and size of bitfields changed from 
+     type_print (type, "", gdb_stdout, show); 
+     to: */
+  type_print_through_value (val, "", gdb_stdout, show);
   printf_filtered ("\n");
 
   if (exp)
diff -ur 7.4_orig/gdb/value.h 7.4_ptypeMixed/gdb/value.h
--- 7.4_orig/gdb/value.h	2012-01-04 09:27:58.000000000 +0100
+++ 7.4_ptypeMixed/gdb/value.h	2012-01-25 22:16:53.000000000 +0100
@@ -779,6 +779,8 @@
 
 extern void type_print (struct type *type, char *varstring,
 			struct ui_file *stream, int show);
+extern void type_print_through_value (struct value *value, char *varstring,
+			struct ui_file *stream, int show);
 
 extern char *type_to_string (struct type *type);
 

      parent reply	other threads:[~2012-02-20 10:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-25 11:22 Leutwein Tobias (BEG-PT/ESB1)
2012-01-25 14:16 ` Jan Kratochvil
2012-01-26 10:15   ` AW: " Leutwein Tobias (BEG-PT/ESB1)
2012-02-20 12:26   ` Leutwein Tobias (BEG-PT/ESB1) [this message]

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=1606F039DD6642449BF6D1519D43AF621619BB4553@SI-MBX09.de.bosch.com \
    --to=tobias.leutwein@de.bosch.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