1

I am working in a write of fixest that uses vendoring (i.e., to use it in a server where a lot of people change things constantly)

So far, some of my functions work, but this creates a segfault

devtools::load_all()

gravity_pois = fepois(Euros ~ log(dist_km) | Origin + Destination + Product + Year, trade)
fixedEffects = fixef(gravity_pois)

To be able to replicate this error you can clone my project with

git clone --depth 1 --branch cpp11_wip https://github.com/pachadotdev/fixest2.git

Then open the project in RStudio and run the 1st chunk.

The function of the problem is https://github.com/pachadotdev/fixest2/blob/cpp11_wip/src/05_01_misc_helpers.cpp#LL540C26-L540C41.

I tried adding cout << "LINE XXX" to see where it stop printing the line number, and up to https://github.com/pachadotdev/fixest2/blob/cpp11_wip/src/05_01_misc_helpers.cpp#L607 it seems to be fine.

How can I debug this in a more efficient way? I tried R -d lldb-11 and all I get is

Thread 1 "R" received signal SIGSEGV, Segmentation fault.
0x00007ffff7cec0d5 in Rf_allocVector3 () from /usr/lib/R/lib/libR.so

I got sure that the values that I have to pass as integers are integers, etc. I did that verification here https://github.com/pachadotdev/fixest2/blob/cpp11_wip/R/Methods.R#L1087-L1098.

pachadotdev
  • 3,345
  • 6
  • 33
  • 60
  • 1
    After you break to `lldb`, run `up` several times (or `thread backtrace`) to see the calls that led to the segfault. Then add lots of `Rprintf()` (or whatever the Rcpp equivalent is) calls to see local variable just before the crash. – user2554330 May 24 '23 at 08:57
  • I used Rcout to print it, and it is a specific part of the function, but still a mystery – pachadotdev May 25 '23 at 02:01
  • 1
    It's typically a bad memory allocation somewhere. Using cout will not work since the program does not necessarily crash at the moment of the the problem (it can be after and sometimes it may not crash at all). Compiling with valgrind/Asan will spot the problem. See Ciro's answer: https://stackoverflow.com/questions/6261201/how-to-find-memory-leak-in-a-c-code-project. – Laurent Bergé May 30 '23 at 19:37
  • Thanks a lot. I ended creating a function to debug and I have some outputs now. I did this https://github.com/pachadotdev/fixest2/tree/cpp11_wip#debugging, which returns https://github.com/pachadotdev/fixest2/issues/52 – pachadotdev Jun 01 '23 at 05:21

0 Answers0