Hello everybody, I have written a script with two inline cfunctions. The script crashes from time to time with: ? ?*** caught segfault *** ? address 0x10, cause 'memory not mapped' The crashs happen within R code after the cfunctions were executed. Nevertheless I think that the pointers in my cfunctions are not used correctly. I tried to find some examples for debugging tools. I found something like "R -d gdb". But I could not find an example how to use it with #!/usr/bin/Rscript. And I cannot source the script within a running R session because I must run it with some args. Can anybody tell me as a non nerd step by step what I can do to locate the problem? Can you recommend tools? If so how are they used with Rscript? Many many thanks in advance Donatella
On 30/11/2012 12:02 PM, Donatella Quagli wrote:> Hello everybody, > > I have written a script with two inline cfunctions. The script crashes from time to time with: > *** caught segfault *** > address 0x10, cause 'memory not mapped' > > The crashs happen within R code after the cfunctions were executed. Nevertheless I think > that the pointers in my cfunctions are not used correctly. > > I tried to find some examples for debugging tools. I found something like "R -d gdb". But I > could not find an example how to use it with #!/usr/bin/Rscript. And I cannot source the script > within a running R session because I must run it with some args. > > Can anybody tell me as a non nerd step by step what I can do to locate the problem? Can > you recommend tools? If so how are they used with Rscript?This isn't easy, but what I would do is add something to your script to get it to pause (or to wait for some file to be created, or some other signal), then figure out the process number, and tell gdb to connect to it after it has already started. The ps command will list all the running processes, for some definition of "all". Then gdb --pid=PID will connect to the process with id PID. I believe it will interrupt the process at that point, but you can restart it, send the signal to it to get out of its loop), and hopefully see the segfault in action. Duncan Murdoch
Thank you so far. Here is an excerpt from the gdb session after a crash: ? Program received signal SIGSEGV, Segmentation fault. ? 0xb7509a6b in Rf_allocVector () from /usr/lib/R/lib/libR.so ? (gdb) backtrace ? #0 ?0xb7509a6b in Rf_allocVector () from /usr/lib/R/lib/libR.so ? #1 ?0xb744b64c in ?? () from /usr/lib/R/lib/libR.so ? #2 ?0xb74c58bf in ?? () from /usr/lib/R/lib/libR.so ? #3 ?0xb74c9c62 in Rf_eval () from /usr/lib/R/lib/libR.so ? #4 ?0xb74ce60f in Rf_applyClosure () from /usr/lib/R/lib/libR.so ? #5 ?0xb74c9f29 in Rf_eval () from /usr/lib/R/lib/libR.so ? #6 ?0xb7503002 in Rf_ReplIteration () from /usr/lib/R/lib/libR.so ? #7 ?0xb7503298 in ?? () from /usr/lib/R/lib/libR.so ? #8 ?0xb7503812 in run_Rmainloop () from /usr/lib/R/lib/libR.so ? #9 ?0xb7503839 in Rf_mainloop () from /usr/lib/R/lib/libR.so ? #10 0x08048768 in main () ? #11 0xb728de46 in __libc_start_main (main=0x8048730 <main>, argc=8, ubp_av=0xbfdb7824, init=0x80488a0 <__libc_csu_init>,? ? ? ? fini=0x8048890 <__libc_csu_fini>, rtld_fini=0xb7784590, stack_end=0xbfdb781c) at libc-start.c:228 ? #12 0x08048791 in _start () It seems to me that the error is in frame #0. Does it mean that there is a bug in libR.so? ?What can I do next? Greetings Donatella
On Nov 30, 2012, at 10:02 AM, Donatella Quagli wrote:> Hello everybody, > > I have written a script with two inline cfunctions. The script > crashes from time to time with: > *** caught segfault *** > address 0x10, cause 'memory not mapped' > > The crashs happen within R code after the cfunctions were executed. > Nevertheless I think > that the pointers in my cfunctions are not used correctly. > > I tried to find some examples for debugging tools. I found something > like "R -d gdb". But I > could not find an example how to use it with #!/usr/bin/Rscript. And > I cannot source the script > within a running R session because I must run it with some args. > > Can anybody tell me as a non nerd step by step what I can do to > locate the problem? Can > you recommend tools? If so how are they used with Rscript?I think you may have difficulty defending your non-nerd claim if you are writing cfunctions in R. That said, you may want to look at a very recent SO answer by Hadley Wickham on StackOverflow: http://stackoverflow.com/questions/13661065/r-superimpose-histogram-fits-in-one-plot (I'm less nerdy than you, but it does appear that Hadley's code demonstrates efforts at checking for available memory and you may benefit from a worked example in Rcpp.) -- David Winsemius, MD Alameda, CA, USA