[R-pkg-devel] RFC: C backtraces for R CMD check via just-in-time debugging
Ivan Krylov
|kry|ov @end|ng |rom d|@root@org
Thu Mar 7 10:30:42 CET 2024
On Tue, 5 Mar 2024 18:26:28 -0500 (EST)
Vladimir Dergachev <volodya using mindspring.com> wrote:
> I use libunwind in my programs, works quite well, and simple to use.
>
> Happy to share the code if there is interest..
Do you mean that you use libunwind in signal handlers? An example on
how to produce a backtrace without calling any async-signal-unsafe
functions would indeed be greatly useful.
Speaking of shared objects injected using LD_PRELOAD, I've experimented
some more, and I think that none of them would work with R without
additional adjustments. They install their signal handler very soon
after the process starts up, and later, when R initialises, it
installs its own signal handler, overwriting the previous one. For this
scheme to work, either R would have to cooperate, remembering a pointer
to the previous signal handler and calling it at some point (which
sounds unsafe), or the injected shared object would have to override
sigaction() and call R's signal handler from its own (which sounds
extremely unsafe).
Without that, if we want C-level backtraces, we either need to patch R
to produce them (using backtrace() and limiting this to glibc systems
or using libunwind and paying the dependency cost) or to use a debugger.
--
Best regards,
Ivan
More information about the R-package-devel
mailing list