[Midnightbsd-cvs] src [7824] trunk/contrib/gdb/gdb: make gdb more friendly with optimized code.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Tue Sep 6 19:59:42 EDT 2016


Revision: 7824
          http://svnweb.midnightbsd.org/src/?rev=7824
Author:   laffer1
Date:     2016-09-06 19:59:42 -0400 (Tue, 06 Sep 2016)
Log Message:
-----------
make gdb more friendly with optimized code.

Modified Paths:
--------------
    trunk/contrib/gdb/gdb/c-valprint.c
    trunk/contrib/gdb/gdb/cp-valprint.c
    trunk/contrib/gdb/gdb/dwarf2loc.c
    trunk/contrib/gdb/gdb/f-valprint.c
    trunk/contrib/gdb/gdb/frame.c
    trunk/contrib/gdb/gdb/jv-valprint.c
    trunk/contrib/gdb/gdb/p-valprint.c
    trunk/contrib/gdb/gdb/scm-valprint.c
    trunk/contrib/gdb/gdb/stack.c
    trunk/contrib/gdb/gdb/valprint.c
    trunk/contrib/gdb/gdb/value.h
    trunk/contrib/gdb/gdb/varobj.c

Modified: trunk/contrib/gdb/gdb/c-valprint.c
===================================================================
--- trunk/contrib/gdb/gdb/c-valprint.c	2016-09-06 23:56:15 UTC (rev 7823)
+++ trunk/contrib/gdb/gdb/c-valprint.c	2016-09-06 23:59:42 UTC (rev 7824)
@@ -232,9 +232,8 @@
 		      wtype = TYPE_TARGET_TYPE (type);
 		    }
 		  vt_val = value_at (wtype, vt_address, NULL);
-		  val_print (VALUE_TYPE (vt_val), VALUE_CONTENTS (vt_val), 0,
-			     VALUE_ADDRESS (vt_val), stream, format,
-			     deref_ref, recurse + 1, pretty);
+		  common_val_print (vt_val, stream, format,
+				    deref_ref, recurse + 1, pretty);
 		  if (pretty)
 		    {
 		      fprintf_filtered (stream, "\n");
@@ -283,15 +282,8 @@
 	       unpack_pointer (lookup_pointer_type (builtin_type_void),
 			       valaddr + embedded_offset),
 	       NULL);
-	      val_print (VALUE_TYPE (deref_val),
-			 VALUE_CONTENTS (deref_val),
-			 0,
-			 VALUE_ADDRESS (deref_val),
-			 stream,
-			 format,
-			 deref_ref,
-			 recurse,
-			 pretty);
+	      common_val_print (deref_val, stream, format, deref_ref,
+				recurse, pretty);
 	    }
 	  else
 	    fputs_filtered ("???", stream);

Modified: trunk/contrib/gdb/gdb/cp-valprint.c
===================================================================
--- trunk/contrib/gdb/gdb/cp-valprint.c	2016-09-06 23:56:15 UTC (rev 7823)
+++ trunk/contrib/gdb/gdb/cp-valprint.c	2016-09-06 23:59:42 UTC (rev 7824)
@@ -361,8 +361,7 @@
 		    (TYPE_FIELD_TYPE (type, i), 
 		     unpack_field_as_long (type, valaddr + offset, i));
 
-		  val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v),
-			     0, 0, stream, format, 0, recurse + 1, pretty);
+		  common_val_print (v, stream, format, 0, recurse + 1, pretty);
 		}
 	    }
 	  else
@@ -426,8 +425,7 @@
       v = value_from_pointer (lookup_pointer_type (builtin_type_unsigned_long),
 			      *(unsigned long *) (valaddr + offset));
 
-      val_print (VALUE_TYPE (v), VALUE_CONTENTS (v), 0, 0,
-		 stream, format, 0, recurse + 1, pretty);
+      common_val_print (v, stream, format, 0, recurse + 1, pretty);
       fields_seen = 1;
 
       if (vtblprint)
@@ -791,8 +789,7 @@
 	  VALUE_TYPE (vf) = VALUE_TYPE (v);	/* make it a pointer */
 
 	  /* print out the entry */
-	  val_print (VALUE_TYPE (vf), VALUE_CONTENTS (vf), 0, 0,
-		     stream, format, 0, recurse + 1, pretty);
+	  common_val_print (vf, stream, format, 0, recurse + 1, pretty);
 	  field_physname
 	    = TYPE_FN_FIELD_PHYSNAME (TYPE_FN_FIELDLIST1 (type, fn), oi);
 	  /* pai: (temp) FIXME Maybe this should be DMGL_ANSI */

Modified: trunk/contrib/gdb/gdb/dwarf2loc.c
===================================================================
--- trunk/contrib/gdb/gdb/dwarf2loc.c	2016-09-06 23:56:15 UTC (rev 7823)
+++ trunk/contrib/gdb/gdb/dwarf2loc.c	2016-09-06 23:59:42 UTC (rev 7824)
@@ -492,10 +492,15 @@
   data = find_location_expression (dlbaton, &size,
 				   frame ? get_frame_pc (frame) : 0);
   if (data == NULL)
-    error ("Variable \"%s\" is not available.", SYMBOL_NATURAL_NAME (symbol));
+    {
+      val = allocate_value (SYMBOL_TYPE (symbol));
+      VALUE_LVAL (val) = not_lval;
+      VALUE_OPTIMIZED_OUT (val) = 1;
+    }
+  else
+    val = dwarf2_evaluate_loc_desc (symbol, frame, data, size,
+				    dlbaton->objfile);
 
-  val = dwarf2_evaluate_loc_desc (symbol, frame, data, size, dlbaton->objfile);
-
   return val;
 }
 

Modified: trunk/contrib/gdb/gdb/f-valprint.c
===================================================================
--- trunk/contrib/gdb/gdb/f-valprint.c	2016-09-06 23:56:15 UTC (rev 7823)
+++ trunk/contrib/gdb/gdb/f-valprint.c	2016-09-06 23:59:42 UTC (rev 7824)
@@ -444,15 +444,8 @@
 	       unpack_pointer (lookup_pointer_type (builtin_type_void),
 			       valaddr + embedded_offset),
 	       NULL);
-	      val_print (VALUE_TYPE (deref_val),
-			 VALUE_CONTENTS (deref_val),
-			 0,
-			 VALUE_ADDRESS (deref_val),
-			 stream,
-			 format,
-			 deref_ref,
-			 recurse,
-			 pretty);
+	      common_val_print (deref_val, stream, format, deref_ref, recurse,
+				pretty);
 	    }
 	  else
 	    fputs_filtered ("???", stream);

Modified: trunk/contrib/gdb/gdb/frame.c
===================================================================
--- trunk/contrib/gdb/gdb/frame.c	2016-09-06 23:56:15 UTC (rev 7823)
+++ trunk/contrib/gdb/gdb/frame.c	2016-09-06 23:59:42 UTC (rev 7824)
@@ -1846,6 +1846,23 @@
       return NULL;
     }
 
+  /* Assume that the only way to get a zero PC is through something
+     like a SIGSEGV or a dummy frame, and hence that NORMAL frames
+     will never unwind a zero PC.  */
+  if (this_frame->level > 0
+      && get_frame_type (this_frame) == NORMAL_FRAME
+      && get_frame_type (get_next_frame (this_frame)) == NORMAL_FRAME
+      && get_frame_pc (this_frame) == 0)
+    {
+      if (frame_debug)
+	{
+	  fprintf_unfiltered (gdb_stdlog, "-> ");
+	  fprint_frame (gdb_stdlog, this_frame->prev);
+	  fprintf_unfiltered (gdb_stdlog, " // zero PC \n");
+	}
+      return NULL;
+    }
+
   /* Only try to do the unwind once.  */
   if (this_frame->prev_p)
     {

Modified: trunk/contrib/gdb/gdb/jv-valprint.c
===================================================================
--- trunk/contrib/gdb/gdb/jv-valprint.c	2016-09-06 23:56:15 UTC (rev 7823)
+++ trunk/contrib/gdb/gdb/jv-valprint.c	2016-09-06 23:59:42 UTC (rev 7824)
@@ -189,8 +189,7 @@
 	      else
 		fprintf_filtered (stream, "%d..%d: ", i, i + reps - 1);
 
-	      val_print (VALUE_TYPE (v), VALUE_CONTENTS (v), 0, 0,
-			 stream, format, 2, 1, pretty);
+	      common_val_print (v, stream, format, 2, 1, pretty);
 
 	      things_printed++;
 	      i += reps;
@@ -242,8 +241,7 @@
       return 0;
     }
 
-  return (val_print (type, VALUE_CONTENTS (val), 0, address,
-		     stream, format, 1, 0, pretty));
+  return common_val_print (val, stream, format, 1, 0, pretty);
 }
 
 /* TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and PRETTY have the
@@ -391,8 +389,7 @@
 		  v = value_from_longest (TYPE_FIELD_TYPE (type, i),
 				   unpack_field_as_long (type, valaddr, i));
 
-		  val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0,
-			     0, stream, format, 0, recurse + 1, pretty);
+		  common_val_print (v, stream, format, 0, recurse + 1, pretty);
 		}
 	    }
 	  else
@@ -411,9 +408,8 @@
 		      struct type *t = check_typedef (VALUE_TYPE (v));
 		      if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
 			v = value_addr (v);
-		      val_print (VALUE_TYPE (v),
-				 VALUE_CONTENTS (v), 0, VALUE_ADDRESS (v),
-				 stream, format, 0, recurse + 1, pretty);
+		      common_val_print (v, stream, format, 0, recurse + 1,
+					pretty);
 		    }
 		}
 	      else if (TYPE_FIELD_TYPE (type, i) == NULL)

Modified: trunk/contrib/gdb/gdb/p-valprint.c
===================================================================
--- trunk/contrib/gdb/gdb/p-valprint.c	2016-09-06 23:56:15 UTC (rev 7823)
+++ trunk/contrib/gdb/gdb/p-valprint.c	2016-09-06 23:59:42 UTC (rev 7824)
@@ -238,9 +238,8 @@
 		      wtype = TYPE_TARGET_TYPE (type);
 		    }
 		  vt_val = value_at (wtype, vt_address, NULL);
-		  val_print (VALUE_TYPE (vt_val), VALUE_CONTENTS (vt_val), 0,
-			     VALUE_ADDRESS (vt_val), stream, format,
-			     deref_ref, recurse + 1, pretty);
+		  common_val_print (vt_val, stream, format, deref_ref,
+				    recurse + 1, pretty);
 		  if (pretty)
 		    {
 		      fprintf_filtered (stream, "\n");
@@ -291,10 +290,8 @@
 	       unpack_pointer (lookup_pointer_type (builtin_type_void),
 			       valaddr + embedded_offset),
 	       NULL);
-	      val_print (VALUE_TYPE (deref_val),
-			 VALUE_CONTENTS (deref_val), 0,
-			 VALUE_ADDRESS (deref_val), stream, format,
-			 deref_ref, recurse + 1, pretty);
+	      common_val_print (deref_val, stream, format, deref_ref,
+				recurse + 1, pretty);
 	    }
 	  else
 	    fputs_filtered ("???", stream);
@@ -565,9 +562,7 @@
 	  fprintf_filtered (stream, ") ");
 	}
     }
-  return val_print (type, VALUE_CONTENTS (val), VALUE_EMBEDDED_OFFSET (val),
-		    VALUE_ADDRESS (val) + VALUE_OFFSET (val),
-		    stream, format, 1, 0, pretty);
+  return common_val_print (val, stream, format, 1, 0, pretty);
 }
 
 
@@ -583,7 +578,7 @@
 static struct obstack dont_print_vb_obstack;
 static struct obstack dont_print_statmem_obstack;
 
-static void pascal_object_print_static_field (struct type *, struct value *,
+static void pascal_object_print_static_field (struct value *,
 					      struct ui_file *, int, int,
 					      enum val_prettyprint);
 
@@ -844,8 +839,7 @@
 		  v = value_from_longest (TYPE_FIELD_TYPE (type, i),
 				   unpack_field_as_long (type, valaddr, i));
 
-		  val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0, 0,
-			     stream, format, 0, recurse + 1, pretty);
+		  common_val_print (v, stream, format, 0, recurse + 1, pretty);
 		}
 	    }
 	  else
@@ -864,9 +858,8 @@
 		  if (v == NULL)
 		    fputs_filtered ("<optimized out>", stream);
 		  else
-		    pascal_object_print_static_field (TYPE_FIELD_TYPE (type, i), v,
-						stream, format, recurse + 1,
-						      pretty);
+		    pascal_object_print_static_field (v, stream, format,
+						      recurse + 1, pretty);
 		}
 	      else
 		{
@@ -1005,14 +998,16 @@
    static member classes in an obstack and refuse to print them more
    than once.
 
-   VAL contains the value to print, TYPE, STREAM, RECURSE, and PRETTY
+   VAL contains the value to print, STREAM, RECURSE, and PRETTY
    have the same meanings as in c_val_print.  */
 
 static void
-pascal_object_print_static_field (struct type *type, struct value *val,
+pascal_object_print_static_field (struct value *val,
 				  struct ui_file *stream, int format,
 				  int recurse, enum val_prettyprint pretty)
 {
+  struct type *type = VALUE_TYPE (val);
+
   if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
     {
       CORE_ADDR *first_dont_print;
@@ -1041,8 +1036,7 @@
 				  stream, format, recurse, pretty, NULL, 1);
       return;
     }
-  val_print (type, VALUE_CONTENTS (val), 0, VALUE_ADDRESS (val),
-	     stream, format, 0, recurse, pretty);
+  common_val_print (val, stream, format, 0, recurse, pretty);
 }
 
 void

Modified: trunk/contrib/gdb/gdb/scm-valprint.c
===================================================================
--- trunk/contrib/gdb/gdb/scm-valprint.c	2016-09-06 23:56:15 UTC (rev 7823)
+++ trunk/contrib/gdb/gdb/scm-valprint.c	2016-09-06 23:59:42 UTC (rev 7824)
@@ -390,6 +390,5 @@
 scm_value_print (struct value *val, struct ui_file *stream, int format,
 		 enum val_prettyprint pretty)
 {
-  return (val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
-		     VALUE_ADDRESS (val), stream, format, 1, 0, pretty));
+  return (common_val_print (val, stream, format, 1, 0, pretty));
 }

Modified: trunk/contrib/gdb/gdb/stack.c
===================================================================
--- trunk/contrib/gdb/gdb/stack.c	2016-09-06 23:56:15 UTC (rev 7823)
+++ trunk/contrib/gdb/gdb/stack.c	2016-09-06 23:59:42 UTC (rev 7824)
@@ -354,9 +354,7 @@
 
 	  if (val)
 	    {
-	      val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
-			 VALUE_ADDRESS (val),
-			 stb->stream, 0, 0, 2, Val_no_prettyprint);
+	      common_val_print (val, stb->stream, 0, 0, 2, Val_no_prettyprint);
 	      ui_out_field_stream (uiout, "value", stb);
 	    }
 	  else

Modified: trunk/contrib/gdb/gdb/valprint.c
===================================================================
--- trunk/contrib/gdb/gdb/valprint.c	2016-09-06 23:56:15 UTC (rev 7823)
+++ trunk/contrib/gdb/gdb/valprint.c	2016-09-06 23:59:42 UTC (rev 7824)
@@ -150,25 +150,66 @@
 			stream, format, deref_ref, recurse, pretty));
 }
 
-/* Print the value VAL in C-ish syntax on stream STREAM.
-   FORMAT is a format-letter, or 0 for print in natural format of data type.
-   If the object printed is a string pointer, returns
-   the number of string bytes printed.  */
+/* Check whether the value VAL is printable.  Return 1 if it is;
+   return 0 and print an appropriate error message to STREAM if it
+   is not.  */
 
-int
-value_print (struct value *val, struct ui_file *stream, int format,
-	     enum val_prettyprint pretty)
+static int
+value_check_printable (struct value *val, struct ui_file *stream)
 {
   if (val == 0)
     {
-      printf_filtered ("<address of value unknown>");
+      fprintf_filtered (stream, "<address of value unknown>");
       return 0;
     }
+
   if (VALUE_OPTIMIZED_OUT (val))
     {
-      printf_filtered ("<value optimized out>");
+      fprintf_filtered (stream, "<value optimized out>");
       return 0;
     }
+
+  return 1;
+}
+
+/* Print the value VAL onto stream STREAM according to FORMAT (a
+   letter, or 0 for natural format using TYPE).
+
+   If DEREF_REF is nonzero, then dereference references, otherwise just print
+   them like pointers.
+
+   The PRETTY parameter controls prettyprinting.
+
+   If the data are a string pointer, returns the number of string characters
+   printed.
+
+   This is a preferable interface to val_print, above, because it uses
+   GDB's value mechanism.  */
+
+int
+common_val_print (struct value *val, struct ui_file *stream, int format,
+		  int deref_ref, int recurse, enum val_prettyprint pretty)
+{
+  if (!value_check_printable (val, stream))
+    return 0;
+
+  return val_print (VALUE_TYPE(val), VALUE_CONTENTS_ALL (val),
+		    VALUE_EMBEDDED_OFFSET (val), VALUE_ADDRESS (val),
+		    stream, format, deref_ref, recurse, pretty);
+}
+
+/* Print the value VAL in C-ish syntax on stream STREAM.
+   FORMAT is a format-letter, or 0 for print in natural format of data type.
+   If the object printed is a string pointer, returns
+   the number of string bytes printed.  */
+
+int
+value_print (struct value *val, struct ui_file *stream, int format,
+	     enum val_prettyprint pretty)
+{
+  if (!value_check_printable (val, stream))
+    return 0;
+
   return LA_VALUE_PRINT (val, stream, format, pretty);
 }
 

Modified: trunk/contrib/gdb/gdb/value.h
===================================================================
--- trunk/contrib/gdb/gdb/value.h	2016-09-06 23:56:15 UTC (rev 7823)
+++ trunk/contrib/gdb/gdb/value.h	2016-09-06 23:59:42 UTC (rev 7824)
@@ -523,6 +523,11 @@
 		      int deref_ref, int recurse,
 		      enum val_prettyprint pretty);
 
+extern int common_val_print (struct value *val,
+			     struct ui_file *stream, int format,
+			     int deref_ref, int recurse,
+			     enum val_prettyprint pretty);
+
 extern int val_print_string (CORE_ADDR addr, int len, int width, struct ui_file *stream);
 
 extern void print_variable_value (struct symbol * var,

Modified: trunk/contrib/gdb/gdb/varobj.c
===================================================================
--- trunk/contrib/gdb/gdb/varobj.c	2016-09-06 23:56:15 UTC (rev 7823)
+++ trunk/contrib/gdb/gdb/varobj.c	2016-09-06 23:59:42 UTC (rev 7824)
@@ -2093,10 +2093,8 @@
 
 	    if (VALUE_LAZY (var->value))
 	      gdb_value_fetch_lazy (var->value);
-	    val_print (VALUE_TYPE (var->value),
-		       VALUE_CONTENTS_RAW (var->value), 0,
-		       VALUE_ADDRESS (var->value), stb,
-		       format_code[(int) var->format], 1, 0, 0);
+	    common_val_print (var->value, stb,
+			      format_code[(int) var->format], 1, 0, 0);
 	    thevalue = ui_file_xstrdup (stb, &dummy);
 	    do_cleanups (old_chain);
 	return thevalue;



More information about the Midnightbsd-cvs mailing list