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

[PATCH] Print references as /x correctly


Hi Folks,

gdb 6.4 does not print references correctly with the type specifier /x. To reproduce, create
a reference "a" to an int variable, then try to print its value by

p /x a

gdb will now incorrectly print the address of the variable a references, not its contents.
To fix this problem, edit print_formatted() in printcmd.c, the "default:" case of the
big switch in lines 323 of printcmd.c as follows:

  default:
      if (format == 0 /* FIX THOR: Print references also by this */
	  || TYPE_CODE (type) == TYPE_CODE_ARRAY
	  || TYPE_CODE (type) == TYPE_CODE_STRING
	  || TYPE_CODE (type) == TYPE_CODE_STRUCT
	  || TYPE_CODE (type) == TYPE_CODE_UNION
	  || TYPE_CODE (type) == TYPE_CODE_REF
	  || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
	/* If format is 0, use the 'natural' format for
	 * that type of value.  If the type is non-scalar,
	 * we have to use language rules to print it as
	 * a series of scalars.
	 */
	value_print (val, stream, format, Val_pretty_default);

Thus, include the type code TYPE_CODE_REF in the default printing style.

So long,
	Thomas


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