[Bioc-devel] [External] Re: Strange "internal logical NA value has been modified" error

iuke-tier@ey m@iii@g oii uiow@@edu iuke-tier@ey m@iii@g oii uiow@@edu
Wed Oct 13 14:27:32 CEST 2021


The most likely culprit is C code that is modifying a logical vector
without checking whether this is legitimate for R semantics
(i.e. making sure MAYBE_REFERENCED or at least MAYBE_SHARED is FALSE).
If that is the case, then this is legitimate for C code to do in
principle, so UBSAN and valgrind won't help. You need to set a gdb
watchpoint on the location, catch where it is modified, and look up
the call stack from there.

The error signaled in the GC is a sanity check for catching that this
sort of misbehavior has happened in C code. But it is a check after
the fact; it can't tell you more that that the problem happened
sometime before it was detected.

Best,

luke

On Wed, 13 Oct 2021, Martin Morgan wrote:

> The problem with using gdb is you'd find yourself in the garbage collector, but perhaps quite removed from where the corruption occurred, e.g., gc() might / will likely be triggered after you've returned to the top-level evaluation loop, and the part of your code that did the corruption might be off the stack.
>
> The problem with devtools::check() (and R CMD check) is that running the unit tests occurs in a separate process, so things like setting a global option (and even system variable from within R) may not be visible in the process doing the check. Conversely, for the same reasons, it seems like the problem can be tickled by running the tests alone. So
>
>  R -f <your_source>/tests/testthat.R
>
> would seem to be a good enough starting point.
>
> Actually, I liked Henrik's UBSAN suggestion, which requires the least amount of work. I think I'd then try
>
>  R -d valgrind -f <your_source>/tests/testthat.R
>
> and then further into the weeds... actually from the section of R-exts you mention
>
>  R_C_BOUNDS_CHECK=yes R -f <your_source>/tests/testthat.R
>
> might also be promising.
>
> Martin
>
> On 10/12/21, 10:30 PM, "Bioc-devel on behalf of Pariksheet Nanda" <bioc-devel-bounces using r-project.org on behalf of pariksheet.nanda using uconn.edu> wrote:
>
>    Hi all,
>
>    On 10/12/21 6:43 PM, Pariksheet Nanda wrote:
>    >
>    > Error in `...`: internal logical NA value has been modified
>
>    In the R source code, this error is in src/main/memory.c so I was
>    thinking one way of investigating might be to run `R --debugger gdb`,
>    then running R to load the symbols and either:
>
>    1) set a breakpoint for when it reaches that particular line in
>    memory.c:R_gc_internal and then walk up the stack,
>
>    2) or set a watch point on memory.c:R_gc_internal:R_LogicalNAValue
>    (somehow; having trouble getting gdb to reach that context).
>
>    3) Then I thought, maybe this is getting far into the weeds and instead
>    I could check the most common C related error by enabling bounds
>    checking of my C arrays per section 4.4 of the R-exts manual:
>
>    $ R -q
>     > options(CBoundsCheck = TRUE)
>     > Sys.setenv(R_C_BOUNDS_CHECK = "yes") # Try both ways *shrug*
>     > devtools::test()
>    ... # All tests still pass.
>     > devtools::check()
>    ... # No change :(
>
>    Maybe I'm not sure I'm using that option correctly?  Or the option is
>    ignored in devtools::check().  Or indeed, the error is not from over
>    running C array boundaries.
>
>    It turns out that using the precompiled debug symbols[1] isn't all that
>    useful here because I don't get line numbers in gdb without the source
>    files and many symbols are optimized out, so it looks like I would need
>    to compile R from source with -ggdb first instead of using the Debian
>    packages.
>
>    Hopefully this is still the right approach?
>
>    Pariksheet
>
>
>    [1] After install r-base-core-dbg on Debian for the debug symbols.
>
>    _______________________________________________
>    Bioc-devel using r-project.org mailing list
>    https://stat.ethz.ch/mailman/listinfo/bioc-devel
> _______________________________________________
> Bioc-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel

-- 
Luke Tierney
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-tierney using uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu


More information about the Bioc-devel mailing list