0

I'm developing an R package for myself that interacts with both Java code using rJava and C++ code using Rcpp. While trying to debug Rsession crashes when working under Rstudio using lldb, I noticed that lddb outputs the following message when I try to load the package I'm developing:

(lldb) Process 19030 stopped
* thread #1, name = 'rsession', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
    frame #0: 0x00007fe6c7b872b4
->  0x7fe6c7b872b4: movl   (%rsi), %eax
    0x7fe6c7b872b6: leaq   0xf8(%rbp), %rsi
    0x7fe6c7b872bd: vmovdqu %ymm0, (%rsi)
    0x7fe6c7b872c1: vmovdqu %ymm7, 0x20(%rsi)

(where 19030 is the pid of rsession). At this point, Rstudio stops waiting for lldb to resume execution, but instead of getting the dreaded "R session aborted" popup, entering the 'c' command in lldb resumes the rsession process and Rstudio continues chugging along just fine and I can use the loaded package with no problems. i.e.:

c
Process 19030 resuming

What is going on here? Why is Rstudio's rsession not crashing if lldb says it has "stopped"? Is this due to R's (or Rstudio's?) SIGSEGV handling mechanism? Does that mean that the original SIGSEGV is spurious and should not be a cause of concern? And of course (but probably off topic in this question): how do I make sense of lldb's output in order to ascertain if this SIGSEGV on loading my package should be debugged further?

jtatria
  • 527
  • 3
  • 12

1 Answers1

0

The SIGSEGV does not occur in Rsession's process, but in the JVM process launched by rJava on package load. This behaviour is known and due to JVM's memory management, as stated here:

Java uses speculative loads. If a pointer points to addressable memory, the load succeeds. Rarely the pointer does not point to addressable memory, and the attempted load generates SIGSEGV ... which java runtime intercepts, makes the memory addressable again, and restarts the load instruction.

The proposed workaround for gdb works fine:

(gdb) handle SIGSEGV nostop noprint pass
jtatria
  • 527
  • 3
  • 12