a R_PV problem

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

a R_PV problem

pseudo-2
Dear all,

When using gdb to debug my C code, I use R_PV to show the content of
SEXP variables:

  SEXP sexp; // it is a data.frame
  SEXP colNames = getAttrib(sexp, R_NameSymbol);

A strange thing is that after halting the program:

  (gdb) p R_PV(colNames)

does not show the content of colNames. I am positive my code is right
because if I insert "PrintValue(colNames);" in the c code, it will
print the right value. My debug result shows that the variable
"colNames" failed the "isObject" call. I am not sure whether this is a
new feature or bug. Anyone can help?

Thanks,

Gang Liang

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: a R_PV problem

Duncan Murdoch
On 06/05/2008 3:02 AM, pseudo wrote:

> Dear all,
>
> When using gdb to debug my C code, I use R_PV to show the content of
> SEXP variables:
>
>   SEXP sexp; // it is a data.frame
>   SEXP colNames = getAttrib(sexp, R_NameSymbol);
>
> A strange thing is that after halting the program:
>
>   (gdb) p R_PV(colNames)
>
> does not show the content of colNames. I am positive my code is right
> because if I insert "PrintValue(colNames);" in the c code, it will
> print the right value. My debug result shows that the variable
> "colNames" failed the "isObject" call. I am not sure whether this is a
> new feature or bug. Anyone can help?

Are you sure that getAttrib has been called?  Depending on the
optimization level under which your code was compiled, instructions may
be re-ordered.  gdb may show the instruction pointer after that line,
even though that line hasn't been run yet.

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: a R_PV problem

Antonio, Fabio Di Narzo
In reply to this post by pseudo-2
2008/5/6 pseudo <[hidden email]>:
[...]
> A strange thing is that after halting the program:
>
>  (gdb) p R_PV(colNames)
>
> does not show the content of colNames. I am positive my code is right
> because if I insert "PrintValue(colNames);" in the c code, it will
> print the right value.
Have you tried:
p Rf_PrintValue(colNames)
from the gdb prompt?

A.
--
Antonio, Fabio Di Narzo
Ph.D. student at
Department of Statistical Sciences
University of Bologna, Italy

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: a R_PV problem

Prof Brian Ripley
In reply to this post by Duncan Murdoch
>From the C code:

/* Ditto, but only for objects, for use in debugging */

so R_PV only prints for 'objects' (that is those with an S3 class, and if
properly formed, those with an S4 class).  I doubt a set of names has a
class: to print those, use Rf_PrintValue.

I am not sure why one would want to confine attention to 'objects', but
the code has been that way 'for ever' (8 years).

On Tue, 6 May 2008, Duncan Murdoch wrote:

> On 06/05/2008 3:02 AM, pseudo wrote:
>> Dear all,
>>
>> When using gdb to debug my C code, I use R_PV to show the content of
>> SEXP variables:
>>
>>   SEXP sexp; // it is a data.frame
>>   SEXP colNames = getAttrib(sexp, R_NameSymbol);
>>
>> A strange thing is that after halting the program:
>>
>>   (gdb) p R_PV(colNames)
>>
>> does not show the content of colNames. I am positive my code is right
>> because if I insert "PrintValue(colNames);" in the c code, it will
>> print the right value. My debug result shows that the variable
>> "colNames" failed the "isObject" call. I am not sure whether this is a
>> new feature or bug. Anyone can help?
>
> Are you sure that getAttrib has been called?  Depending on the optimization
> level under which your code was compiled, instructions may be re-ordered.
> gdb may show the instruction pointer after that line, even though that line
> hasn't been run yet.
>
> Duncan Murdoch
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: a R_PV problem

pseudo-2
In reply to this post by Duncan Murdoch
On Tue, May 6, 2008 at 1:46 AM, Duncan Murdoch <[hidden email]> wrote:

>
> On 06/05/2008 3:02 AM, pseudo wrote:
>
> > Dear all,
> >
> > When using gdb to debug my C code, I use R_PV to show the content of
> > SEXP variables:
> >
> >  SEXP sexp; // it is a data.frame
> >  SEXP colNames = getAttrib(sexp, R_NameSymbol);
> >
> > A strange thing is that after halting the program:
> >
> >  (gdb) p R_PV(colNames)
> >
> > does not show the content of colNames. I am positive my code is right
> > because if I insert "PrintValue(colNames);" in the c code, it will
> > print the right value. My debug result shows that the variable
> > "colNames" failed the "isObject" call. I am not sure whether this is a
> > new feature or bug. Anyone can help?
> >
>
>  Are you sure that getAttrib has been called?  Depending on the optimization
> level under which your code was compiled, instructions may be re-ordered.
> gdb may show the instruction pointer after that line, even though that line
> hasn't been run yet.
>

Yes, the getAttrib is called because the optimization is turned off.

Gang

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: a R_PV problem

Bill Dunlap
In reply to this post by Duncan Murdoch
On Tue, 6 May 2008, Duncan Murdoch wrote:

> On 06/05/2008 3:02 AM, pseudo wrote:
> > Dear all,
> >
> > When using gdb to debug my C code, I use R_PV to show the content of
> > SEXP variables:
> >
> >   SEXP sexp; // it is a data.frame
> >   SEXP colNames = getAttrib(sexp, R_NameSymbol);
> >
> > A strange thing is that after halting the program:
> >
> >   (gdb) p R_PV(colNames)
> >
> > does not show the content of colNames. I am positive my code is right
> > because if I insert "PrintValue(colNames);" in the c code, it will
> > print the right value. My debug result shows that the variable
> > "colNames" failed the "isObject" call. I am not sure whether this is a
> > new feature or bug. Anyone can help?
>
> Are you sure that getAttrib has been called?  Depending on the
> optimization level under which your code was compiled, instructions may
> be re-ordered.  gdb may show the instruction pointer after that line,
> even though that line hasn't been run yet.

R_PV(sexp) only prints if isObject(sexp) is true, i.e., if it
is "internally classed".  Try using Rf_PrintValue(colNames) from
the debugger.

src/main/print.c contains:
   /* Print an S-expression using global options */
   void PrintValue(SEXP s)
   {
       PrintValueEnv(s, R_GlobalEnv);
   }
   /* Ditto, but only for objects, for use in debugging */
   void R_PV(SEXP s)
   {
       if(isObject(s)) PrintValueEnv(s, R_GlobalEnv);
   }
and include/Internals.h has the usual add-Rf_ #define:
   #define PrintValue              Rf_PrintValue

----------------------------------------------------------------------------
Bill Dunlap
Insightful Corporation
bill at insightful dot com
360-428-8146

 "All statements in this message represent the opinions of the author and do
 not necessarily reflect Insightful Corporation policy or position."

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: a R_PV problem

pseudo-2
In reply to this post by Antonio, Fabio Di Narzo
On Tue, May 6, 2008 at 5:23 AM, Antonio, Fabio Di Narzo
<[hidden email]> wrote:

> 2008/5/6 pseudo <[hidden email]>:
>  [...]
>
> > A strange thing is that after halting the program:
>  >
>  >  (gdb) p R_PV(colNames)
>  >
>  > does not show the content of colNames. I am positive my code is right
>  > because if I insert "PrintValue(colNames);" in the c code, it will
>  > print the right value.
>  Have you tried:
>  p Rf_PrintValue(colNames)
>  from the gdb prompt?
>

Yes, I also tried "p Rf_PrintValue(colNames)", the outcome is the
same. I can step in the r-base-core and what I found is that the
"isObject" returns false.

>  A.
>  --
>  Antonio, Fabio Di Narzo
>  Ph.D. student at
>  Department of Statistical Sciences
>  University of Bologna, Italy
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: a R_PV problem

pseudo-2
In reply to this post by Bill Dunlap
Thanks for the pointer, and the problem solved.

I double checked that Rf_PrintValue works when the option
"unwindonsignal" is turned on in gdb. I also found that without "set
unwindonsignal on", both "p Rf_PrintValue(colNames)" and "p
R_PV(colNames)" could result in SIGTRAP or SIGSEGV sometimes. But not
sure what caused the signal and why... because if I stepped into these
functions, nothing would happen.

Thanks, Gang

On Tue, May 6, 2008 at 8:30 AM, Bill Dunlap <[hidden email]> wrote:

> On Tue, 6 May 2008, Duncan Murdoch wrote:
>
>
>
> > On 06/05/2008 3:02 AM, pseudo wrote:
>  > > Dear all,
>  > >
>  > > When using gdb to debug my C code, I use R_PV to show the content of
>  > > SEXP variables:
>  > >
>  > >   SEXP sexp; // it is a data.frame
>  > >   SEXP colNames = getAttrib(sexp, R_NameSymbol);
>  > >
>  > > A strange thing is that after halting the program:
>  > >
>  > >   (gdb) p R_PV(colNames)
>  > >
>  > > does not show the content of colNames. I am positive my code is right
>  > > because if I insert "PrintValue(colNames);" in the c code, it will
>  > > print the right value. My debug result shows that the variable
>  > > "colNames" failed the "isObject" call. I am not sure whether this is a
>  > > new feature or bug. Anyone can help?
>  >
>  > Are you sure that getAttrib has been called?  Depending on the
>  > optimization level under which your code was compiled, instructions may
>  > be re-ordered.  gdb may show the instruction pointer after that line,
>  > even though that line hasn't been run yet.
>
>  R_PV(sexp) only prints if isObject(sexp) is true, i.e., if it
>  is "internally classed".  Try using Rf_PrintValue(colNames) from
>  the debugger.
>
>  src/main/print.c contains:
>    /* Print an S-expression using global options */
>    void PrintValue(SEXP s)
>    {
>        PrintValueEnv(s, R_GlobalEnv);
>
>    }
>    /* Ditto, but only for objects, for use in debugging */
>    void R_PV(SEXP s)
>    {
>        if(isObject(s)) PrintValueEnv(s, R_GlobalEnv);
>    }
>  and include/Internals.h has the usual add-Rf_ #define:
>    #define PrintValue              Rf_PrintValue
>
>  ----------------------------------------------------------------------------
>  Bill Dunlap
>  Insightful Corporation
>  bill at insightful dot com
>  360-428-8146
>
>   "All statements in this message represent the opinions of the author and do
>   not necessarily reflect Insightful Corporation policy or position."
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel