This is the mail archive of the gdb-patches@sources.redhat.com 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]

fix for gdb/635


Here's a patch that fixes values.c(value_static_field) to get rid of
some situations where it was doing bad memory accesses, as mentioned
in PR gdb/635.

I also checked to see whether or not value_static_field's callers
correctly handled a return value of NULL as meaning that the field in
question had been optimized out.  Some of them handled it correctly,
but a few didn't; in those cases, I fixed the error messages that they
printed to make them a bit more appropriate.

No new regressions.

David Carlton
carlton@math.stanford.edu

2002-08-15  David Carlton  <carlton@math.stanford.edu>

	* valops.c (search_struct_field): Change error message to treat
	return value of 0 from value_static_field as meaning that field is
	optimized out.
	(value_struct_elt_for_reference): Ditto.

	* values.c (value_static_field): Treat an unresolved location the
	same as a nonexistent symbol.

Index: values.c
===================================================================
RCS file: /cvs/src/src/gdb/values.c,v
retrieving revision 1.38
diff -u -p -r1.38 values.c
--- values.c	3 Jul 2002 21:27:55 -0000	1.38
+++ values.c	15 Aug 2002 21:45:37 -0000
@@ -793,7 +793,9 @@ unpack_pointer (struct type *type, char 
 }
 
 
-/* Get the value of the FIELDN'th field (which must be static) of TYPE. */
+/* Get the value of the FIELDN'th field (which must be static) of
+   TYPE.  Return NULL if the field doesn't exist or has been
+   optimized out. */
 
 struct value *
 value_static_field (struct type *type, int fieldno)
@@ -809,7 +811,14 @@ value_static_field (struct type *type, i
     {
       char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, fieldno);
       struct symbol *sym = lookup_symbol (phys_name, 0, VAR_NAMESPACE, 0, NULL);
-      if (sym == NULL)
+      /* In some cases (involving uninitalized, unreferenced static
+	 const integral members), g++ -gdwarf-2 can emit debugging
+	 information giving rise to symbols whose SYMBOL_CLASS is
+	 LOC_UNRESOLVED.  In that case, do a minimal symbol lookup.
+	 If it returns a useful value, then the symbol was defined
+	 elsewhere, so we use that information.  Otherwise, return
+	 NULL. */
+      if (sym == NULL || SYMBOL_CLASS (sym) == LOC_UNRESOLVED)
 	{
 	  /* With some compilers, e.g. HP aCC, static data members are reported
 	     as non-debuggable symbols */

Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.66
diff -u -p -r1.66 valops.c
--- valops.c	1 Aug 2002 17:18:33 -0000	1.66
+++ valops.c	15 Aug 2002 21:50:05 -0000
@@ -2054,11 +2054,18 @@ search_struct_field (char *name, struct 
 	  {
 	    struct value *v;
 	    if (TYPE_FIELD_STATIC (type, i))
-	      v = value_static_field (type, i);
+	      {
+		v = value_static_field (type, i);
+		if (v == 0)
+		  error ("field %s is nonexistent or has been optimised out",
+			 name);
+	      }
 	    else
-	      v = value_primitive_field (arg1, offset, i, type);
-	    if (v == 0)
-	      error ("there is no field named %s", name);
+	      {
+		v = value_primitive_field (arg1, offset, i, type);
+		if (v == 0)
+		  error ("there is no field named %s", name);
+	      }
 	    return v;
 	  }
 
@@ -3043,7 +3050,7 @@ value_struct_elt_for_reference (struct t
 	    {
 	      v = value_static_field (t, i);
 	      if (v == NULL)
-		error ("Internal error: could not find static variable %s",
+		error ("static field %s has been optimized out",
 		       name);
 	      return v;
 	    }


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