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]

[RFA] c-valprint.c: Improve function pointer printing on AIX.


Now that CONVERT_FROM_FUNC_PTR_ADDR is multi-arched, I'd like to improve
the printing of function pointers on AIX.

Here is the relevant function pointer explanation from rs6000-tdep.c:

   Usually a function pointer's representation is simply the address
   of the function. On the RS/6000 however, a function pointer is
   represented by a pointer to a TOC entry. This TOC entry contains
   three words, the first word is the address of the function, the
   second word is the TOC pointer (r2), and the third word is the
   static chain value.  Throughout GDB it is currently assumed that a
   function pointer contains the address of the function, which is not
   easy to fix.  In addition, the conversion of a function address to
   a function pointer would require allocation of a TOC entry in the
   inferior's memory space, with all its drawbacks.

With the patch applied, function pointers are automatically dereferenced
before printing, so that e.g.

catch_errors (func=0x2001ff9c <__dbargs+15796>, ....

becomes

catch_errors (func=@0x2001ff9c: 0x100054e0 <get_prompt_1>, ....

	* c-valprint.c (print_function_pointer_address):  New function
	to automatically dereference a function pointer for printing
	if necessary.
	(c_val_print):  Use print_function_pointer_address when printing
	function pointer addresses.

*** gdb/c-valprint.c.orig	Sat Sep 30 13:36:06 2000
--- gdb/c-valprint.c	Wed Oct 25 17:42:57 2000
***************
*** 30,35 ****
--- 30,55 ----
  #include "c-lang.h"
  
  
+ /* Print function pointer with inferior address ADDRESS onto stdio
+    stream STREAM.  */
+ 
+ static void
+ print_function_pointer_address (CORE_ADDR address, struct ui_file *stream)
+ {
+   CORE_ADDR func_addr = CONVERT_FROM_FUNC_PTR_ADDR (address);
+ 
+   /* If the function pointer is represented by a description, print the
+      address of the description.  */
+   if (addressprint && func_addr != address)
+     {
+       fputs_filtered ("@", stream);
+       print_address_numeric (address, 1, stream);
+       fputs_filtered (": ", stream);
+     }
+   print_address_demangle (func_addr, stream, demangle);
+ }
+ 
+ 
  /* Print data of type TYPE located at VALADDR (within GDB), which came from
     the inferior at address ADDRESS, onto stdio stream STREAM according to
     FORMAT (a letter or 0 for natural format).  The data at VALADDR is in
***************
*** 129,135 ****
  	     -fvtable_thunks.  (Otherwise, look under TYPE_CODE_STRUCT.) */
  	  CORE_ADDR addr
  	    = extract_typed_address (valaddr + embedded_offset, type);
! 	  print_address_demangle (addr, stream, demangle);
  	  break;
  	}
        elttype = check_typedef (TYPE_TARGET_TYPE (type));
--- 149,155 ----
  	     -fvtable_thunks.  (Otherwise, look under TYPE_CODE_STRUCT.) */
  	  CORE_ADDR addr
  	    = extract_typed_address (valaddr + embedded_offset, type);
! 	  print_function_pointer_address (addr, stream);
  	  break;
  	}
        elttype = check_typedef (TYPE_TARGET_TYPE (type));
***************
*** 152,158 ****
  	  if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
  	    {
  	      /* Try to print what function it points to.  */
! 	      print_address_demangle (addr, stream, demangle);
  	      /* Return value is irrelevant except for string pointers.  */
  	      return (0);
  	    }
--- 172,178 ----
  	  if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
  	    {
  	      /* Try to print what function it points to.  */
! 	      print_function_pointer_address (addr, stream);
  	      /* Return value is irrelevant except for string pointers.  */
  	      return (0);
  	    }
***************
*** 294,300 ****
  	  CORE_ADDR addr
  	    = extract_typed_address (valaddr + offset, field_type);
  
! 	  print_address_demangle (addr, stream, demangle);
  	}
        else
  	cp_print_value_fields (type, type, valaddr, embedded_offset, address, stream, format,
--- 314,320 ----
  	  CORE_ADDR addr
  	    = extract_typed_address (valaddr + offset, field_type);
  
! 	  print_function_pointer_address (addr, stream);
  	}
        else
  	cp_print_value_fields (type, type, valaddr, embedded_offset, address, stream, format,

-- 
Peter Schauer			pes@regent.e-technik.tu-muenchen.de

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