From ripley at stats.ox.ac.uk  Wed Dec 13 00:01:14 2006
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Tue, 12 Dec 2006 23:01:14 +0000 (GMT)
Subject: [Rd] [R] Segfault in pure R code
In-Reply-To: <148ed8180612121433n1287d12al6fdc622722d0b3ef@mail.gmail.com>
References: <148ed8180612121218pea45e0agcdb39a8b9fe9ff43@mail.gmail.com>
	<457F18AB.4020109@biostat.ku.dk>
	<148ed8180612121414x5763a5f1k4c802976fe9c85fe@mail.gmail.com>
	<148ed8180612121433n1287d12al6fdc622722d0b3ef@mail.gmail.com>
Message-ID: <Pine.LNX.4.64.0612122249290.25343@gannet.stats.ox.ac.uk>

That's in the memory manager and indicates prior memory corruption.
Please re-run under valgrind, plus gctorture(TRUE) if needed.

However, I would start by seeing if this occurs in a single-byte domain if 
this was in a UTF-8 domain.  Experience suggests that we have some flakier 
code in the less-used MBCS pathways.


On Tue, 12 Dec 2006, G?ran Brostr?m wrote:

> I tried once more under the debugger, and
>
> ++++++++++++++++++++++++++++++++++++++++++
> gb at kasparov:~/R/BEMANNING/Doc$ R -d gdb
> GNU gdb 6.5-debian
> Copyright (C) 2006 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and you are
> welcome to change it and/or distribute copies of it under certain conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB.  Type "show warranty" for details.
> This GDB was configured as "i486-linux-gnu"...Using host libthread_db
> library "/lib/tls/i686/cmov/libthread_db.so.1".
>
> (gdb) run
> Starting program: /usr/local/lib/R/bin/exec/R
> Failed to read a valid object file image from memory.
>
> R version 2.4.0 Patched (2006-10-29 r39744)
> Copyright (C) 2006 The R Foundation for Statistical Computing
> ISBN 3-900051-07-0
>
> R is free software and comes with ABSOLUTELY NO WARRANTY.
> You are welcome to redistribute it under certain conditions.
> Type 'license()' or 'licence()' for distribution details.
>
>  Natural language support but running in an English locale
>
> R is a collaborative project with many contributors.
> Type 'contributors()' for more information and
> 'citation()' on how to cite R or R packages in publications.
>
> Type 'demo()' for some demos, 'help()' for on-line help, or
> 'help.start()' for an HTML browser interface to help.
> Type 'q()' to quit R.
>
> [Previously saved workspace restored]
>
>> library(xtable)
>> ?xtable)
> Error: syntax error in "?xtable)"
>> ?xtable
>> help.start()
> Making links in per-session dir ...
> If '/usr/bin/firefox' is already running, it is *not* restarted, and
>    you must switch to its window.
> Otherwise, be patient ...
>> library(bemanning)
>> load("bemanning07-32.rda")
>> courses("Ingrid")
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x080f5026 in R_gc_internal (size_needed=17588127) at memory.c:1313
> 1313        PROCESS_NODES();
> (gdb)
> ++++++++++++++++++++++++++++++++++++++++++++
>
> How do I continue?
>
> G?ran
>
> On 12/12/06, G?ran Brostr?m <goran.brostrom at gmail.com> wrote:
>> On 12/12/06, Peter Dalgaard <p.dalgaard at biostat.ku.dk> wrote:
>>> G?ran Brostr?m wrote:
>>>> I just caught a segfault:
>>>>
>>>>
>>>>> courses("Ingrid")
>>>>>
>>>>
>>>>  *** caught segfault ***
>>>> address 0x99b279c, cause 'memory not mapped'
>>>>
>>>> Traceback:
>>>>  1: structure(y, class = oldClass(x), row.names = attr(x, "row.names"))
>>>>  2: `[.data.frame`(gudata, -(1:5))
>>>>  3: gudata[-(1:5)]
>>>>  4: names(gudata[-(1:5)])
>>>>  5: inherits(x, "factor")
>>>>  6: is.factor(table)
>>>>  7: match(x, table, nomatch = 0)
>>>>  8: who %in% names(gudata[-(1:5)])
>>>>  9: courses("Ingrid")
>>>>
>>>> when running a function 'courses' in an R package without compiled
>>>> code. Is this "possible"? I have got many segfaults when testing my
>>>> own packages, but it has always been caused by stupidities in C or
>>>> Fortran code, never with pure R code.
>>>>
>>>> So, before I start debugging, I'd like to know if a segfault in pure R
>>>> code indicates  a bug in R itself, or if it can be in my function?
>>>>
>>>>
>>> By definition, reproducible segfaults in R code are bugs in R, unless
>>> caused by abuse of .C calls or similar. (Irreproducible ones are often
>>> hardware faults.)
>>>
>>> However, at least presently, you are the only one with a handle on the
>>> bug. So either you get to do the debugging or you have to provide
>>> something that others can reproduce.
>>>
>>> Astarting point could be to run R under the debugger (R -d gdb)  and
>>> generate a C backtrace, then look at the variables involved.
>>
>> Thanks, Peter,
>>
>> the error is reproducible. The full session is
>>
>> +++++++++++++++++++++++++++++++++++++++++
>> gb at kasparov:~/R/BEMANNING/Doc$ R
>>
>> R version 2.4.0 Patched (2006-10-29 r39744)
>> Copyright (C) 2006 The R Foundation for Statistical Computing
>> ISBN 3-900051-07-0
>>
>> R is free software and comes with ABSOLUTELY NO WARRANTY.
>> You are welcome to redistribute it under certain conditions.
>> Type 'license()' or 'licence()' for distribution details.
>>
>>   Natural language support but running in an English locale
>>
>> R is a collaborative project with many contributors.
>> Type 'contributors()' for more information and
>> 'citation()' on how to cite R or R packages in publications.
>>
>> Type 'demo()' for some demos, 'help()' for on-line help, or
>> 'help.start()' for an HTML browser interface to help.
>> Type 'q()' to quit R.
>>
>> [Previously saved workspace restored]
>>
>>> library(xtable)
>>> ?xtable)
>> Error: syntax error in "?xtable)"
>>> ?xtable
>>> help.start()
>> Making links in per-session dir ...
>> If '/usr/bin/firefox' is already running, it is *not* restarted, and
>>     you must switch to its window.
>> Otherwise, be patient ...
>>> library(bemanning)
>>> load("bemanning07-32.rda")
>>> courses("Ingrid")
>>
>>  *** caught segfault ***
>> address 0x99b279c, cause 'memory not mapped'
>>
>> Traceback:
>>  1: structure(y, class = oldClass(x), row.names = attr(x, "row.names"))
>>  2: `[.data.frame`(gudata, -(1:5))
>>  3: gudata[-(1:5)]
>>  4: names(gudata[-(1:5)])
>>  5: inherits(x, "factor")
>>  6: is.factor(table)
>>  7: match(x, table, nomatch = 0)
>>  8: who %in% names(gudata[-(1:5)])
>>  9: courses("Ingrid")
>>
>> Possible actions:
>> 1: abort (with core dump)
>> 2: normal R exit
>> 3: exit R without saving workspace
>> 4: exit R saving workspace
>> Selection:
>> +++++++++++++++++++++++++++++++++++++++++++++
>>
>> Notes:
>>
>> 1. Tried to remove one line at a time, but then no error.
>> 2. R -d gdb: No errors
>> 3. Starting with 'R --vanilla': No errors.
>>
>> i.e., it seems as if my previously saved workspace '.RData' is part of
>> the error.
>> Could it be corrupt and cause a segfault in a bug free R?
>>
>> I'll try to build a newer version of R and check (but not tonight).
>>
>> G?ran
>>
>>> (Further discussion should probably go on r-devel instead of r-help).
>>>
>>> -p
>>>
>>>> I have used 'courses' many times before without problems.
>>>>
>>>> Thanks,
>>>>
>>>> G?ran
>>>> ++++++++++++++++++++++++++++++++++++++
>>>>
>>>>> sessionInfo()
>>>>>
>>>> R version 2.4.0 Patched (2006-10-29 r39744)
>>>> i686-pc-linux-gnu
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>> --
>> G?ran Brostr?m
>>
>
>
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
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


[Rd] [R] Segfault in pure R code
Prof Brian Ripley