[PATCH] Static field fix

Daniel Berlin dan@cgsoftware.com
Sun May 6 23:22:00 GMT 2001


This is a 4+ year old bug with an obvious fix.

We currently assume static fields always have an address.
This is not true.
You can have constant static fields with C++, and in fact, quite often
do (for instance, libstdc++-v3's std::string class has one).

Without this fix, it'll try to treat the constant value like an
address, and usually, fail miserably trying to print it out, and skip
printing the rest of the structure, because it gets an "Cannot access
memory at <whatever address is really the value>", causing it to jump
back to the prompt.

The fix, of course, is to actually look at the symbol location class,
and see if it's constant. If it is, the value of the field is the
value of the constant. Otherwise, we assume it's at an address (Unless you
change the definition of static, these are the only two possibilities).

I would have noticed this bug years ago, except value_static_field
sees fit to set the physaddr on the type field the first time through to
save a single symbol lookup (it checks if the type field has a
physaddr set first, and just uses that if it does, rather than try to
lookup the symbol again), so whenever I went to look at the cause, it
looked like a persistent gcc debug info generation bug, rather than a
gdb bug.  Cute, no?
It wasn't until I rewrote most of the dwarf2 reader, and knew the
value was being set correctly, that i realized it must be gdb's fault,
regardless of appearance.

I also added two comments to the code as part of the fix.

I have a test case for this fix, and will submit seperately (because I
don't think this change isn't obvious enough to just commit after i
wait a few days, while i'd rather have someone actually look at the
testsuite part).


2001-05-07  Daniel Berlin  <dan@cgsoftware.com>
 
        * values.c (value_static_field): Handle static fields that have a constant value.
 
Index: values.c
===================================================================
RCS file: /cvs/src/src/gdb/values.c,v
retrieving revision 1.15
diff -c -3 -p -d -r1.15 values.c
*** values.c	2001/04/27 00:19:09	1.15
--- values.c	2001/05/07 06:00:24
*************** value_static_field (struct type *type, i
*** 764,767 ****
  	{
! 	  addr = SYMBOL_VALUE_ADDRESS (sym);
! 	  sect = SYMBOL_BFD_SECTION (sym);
  	}
--- 764,776 ----
  	{
! 	  /* Anything static that isn't a constant, has an address */
! 	  if (SYMBOL_CLASS (sym) != LOC_CONST)
! 	    {
! 	      addr = SYMBOL_VALUE_ADDRESS (sym);
! 	      sect = SYMBOL_BFD_SECTION (sym);
! 	    }	 
! 	  /* However, static const's do not, the value is already known.  */
! 	  else
! 	    {
! 	      return value_from_longest (TYPE_FIELD_TYPE (type, fieldno), SYMBOL_VALUE (sym));
! 	    }
  	}



-- 
"I'm kinda tired.  I was up all night trying to round off
infinity.  Then I got bored and went out and painted passing
lines on curved roads.
"-Steven Wright



More information about the Gdb-patches mailing list