From luke at stat.uiowa.edu  Wed Jun 29 20:44:42 2005
From: luke at stat.uiowa.edu (Luke Tierney)
Date: Wed, 29 Jun 2005 13:44:42 -0500 (CDT)
Subject: [Rd] Viewing R objects in gdb
In-Reply-To: <42C2E8B4.4010007@stats.uwo.ca>
References: <42C2DF42.8090200@stats.uwo.ca>
	<Pine.LNX.4.63.0506291302130.4273@nokomis.stat.uiowa.edu>
	<42C2E8B4.4010007@stats.uwo.ca>
Message-ID: <Pine.LNX.4.63.0506291338500.4273@nokomis.stat.uiowa.edu>

On Wed, 29 Jun 2005, Duncan Murdoch wrote:

> On 6/29/2005 2:06 PM, Luke Tierney wrote:
>> On Wed, 29 Jun 2005, Duncan Murdoch wrote:
>> 
>>> I'm trying to track down a bug in some experimental code, where an
>>> object's attribute is getting messed up.  This means I'd like to examine
>>> R objects while within gdb.
>>> 
>>> One of the things I'd like to do is to examine the names of all the
>>> attributes.  This is exactly what an example in the R Extensions manual
>>> section 4.11.2 "Inspecting R objects when debugging" does, but the code
>>> there doesn't work, presumably because the R internals have changed
>>> since it was written.
>>> 
>>> Specifically, I get
>>> 
>>> (gdb) p $a->u.listsxp.tagval->u.symsxp.pname->u.vecsxp.type.c
>>> Error: There is no member named vecsxp.
>>> 
>> 
>> Something like this I think (untested):
>>
>>          p ((VECSEXP)$a->u.listsxp.tagval->u.symsxp.pname)->vecsxp.type.c
>
> That gets the typecast right, but now I have the problem that currently 
> vecsxp doesn't have a type member:
>
> (gdb) p ((VECSEXP)$a->u.listsxp.tagval->u.symsxp.pname)->vecsxp.type.c
> Error: There is no member named type.
>
> (gdb) p ((VECSEXP)$a->u.listsxp.tagval->u.symsxp.pname)->vecsxp
> $1 = {length = 5, truelength = 6957219}
>
> I guess I need to write a function that uses the macros to extract the data 
> (since gdb doesn't see the macros).  Or do we already have one?

The type fiels it in the sxpinfo part of the header; I think either

   ((VECSEXP)$a->u.listsxp.tagval->u.symsxp.pname)->sxpinfo.type

or

   $a->u.listsxp.tagval->u.symsxp.pname->sxpinfo.type

will give you that.

It is probably possible to do something like write a file of gdb
macros, run the C pre-processor over it to get the expnansions, and
load that into gdb. Not that I've tried...

luke

-- 
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:      luke at stat.uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



[Rd] Viewing R objects in gdb
Luke Tierney