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]

[RFA] Avoid problems with ptype command


  I got really strange result when trying to use
ptype command on Free Pascal classes,
if I typecast a valid pointer to a class
child of the declared type of that variable.

  H is a class, of type THTMLINDEXHELPFILE
which is a descendant of the declared type for H which is
THELPFILE

(top-gdb) p H^
$2 = {<TOBJECT> = {_vptr$ = {0x9a2848, 0x1}}, ID = 1, TOPICS = 0x45a26e8,
  INDEXENTRIES = 0x45a25c8}
(top-gdb) ptyp  H^
type = THELPFILE = class : public TOBJECT
  public
    ID : WORD;
    TOPICS : PTOPICCOLLECTION;
    INDEXENTRIES : PUNSORTEDINDEXENTRYCOLLECTION;

    constructor INIT (THELPFILE, POINTER, WORD) : LONGBOOL;
    function  LOADTOPIC (THELPFILE, LONGINT) : PTOPIC; virtual;
    procedure ADDTOPIC (THELPFILE, LONGINT, LONGINT, SHORTSTRING, OINTER7, );
    procedure ADDINDEXENTRY (THELPFILE, SHORTSTRING, ONGINT);
    destructor  ~DONE (THELPFILE, POINTER); virtual;
    function  LOADINDEX (THELPFILE) : BOOLEAN; virtual;
    function  SEARCHTOPIC (THELPFILE, LONGINT) : PTOPIC; virtual;
    function  READTOPIC (THELPFILE, PTOPIC) : BOOLEAN; virtual;
    function  GETTOPICINFO (THELPFILE, PTOPIC, SHORTSTRING) :
    SHORTSTRING; virtual;
    procedure MAINTAINTOPICCACHE (THELPFILE);
end

// If I try to typecast to its real type
// I get an error
(top-gdb) ptyp  THTMLINDEXHELPFILE(H^)
Cannot access memory at address 0x0

  Which is related to a call of value_at,
at a place where a value_at_lazy would be sufficient.

  With my patch, I get this:

(top-gdb) ptyp THTMLINDEXHELPFILE (H^)
type = THTMLINDEXHELPFILE = class : public TCUSTOMHTMLHELPFILE
  private
    INDEXFILENAME : SHORTSTRING;

  public
    constructor INIT (THTMLINDEXHELPFILE, OINTER1, H, ) : LONGBOOL;
    function  LOADINDEX (THTMLINDEXHELPFILE) : BOOLEAN; virtual;
end

  Patch tested on a x86_64-unknown-linux-gnu machine
from the Compile Farm, no regression found.


Pierre Muller
Pascal language support maintainer for GDB


 
2010-10-15  Pierre Muller  <muller@ics.u-strasbg.fr>

	* valops.c (value_cast_structs): Use value_at_lazy instead of value_at
	to avoid troubles for ptype command.

Index: src/gdb/valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.252
diff -u -p -r1.252 valops.c
--- src/gdb/valops.c	8 Oct 2010 16:50:53 -0000	1.252
+++ src/gdb/valops.c	15 Oct 2010 10:37:47 -0000
@@ -289,7 +289,7 @@ value_cast_structs (struct type *type, s
 	  CORE_ADDR addr2 = value_address (v2);
 
 	  addr2 -= value_address (v) + value_embedded_offset (v);
-	  return value_at (type, addr2);
+	  return value_at_lazy (type, addr2);
 	}
     }
 


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