aryoda / R_CppDebugHelper

Diagnostics functions to be called in debuggers like 'gdb' to debug C and C++ based code called from R
GNU General Public License v3.0
0 stars 0 forks source link

debugging gcc compiled code with lldb does not work for every dbg_* function #5

Open aryoda opened 4 years ago

aryoda commented 4 years ago

Running lldb with

R -d lldb

and setting a breakpoint (same commands as in gdb so far) prints strange results:

(lldb) p dbg_print(x)
error: warning: '__cplusplus' macro redefined
previous definition is here
warning: '__GNUC__' macro redefined
previous definition is here
...
warning: '__LDBL_EPSILON__' macro redefined
previous definition is here
warning: '__LDBL_DENORM_MIN__' macro redefined
previous definition is here
error: Couldn't lookup symbols:
  Rcpp::PreserveStorage<Rcpp::Vector<4> >::~PreserveStorage()
  Rcpp::Vector<4>::Vector(Rcpp::Vector<4> const&)

but SEXP printing does work:

(lldb) p dbg_print(x.data)
[1] "foo"   "bar"   NA      "hello"

Investigate this (low prio)...

See also: Is it possible to debug a gcc-compiled program using lldb, or debug a clang-compiled program using gdb?

aryoda commented 4 years ago

Perhaps switching to clang++ solves the problem, see:

http://r-pkgs.had.co.nz/src.html

Use clang instead of gcc to compile your C++ code: it gives much better error messages. You can make clang the default by creating a .R/Makevars (linux and mac) or .R/Makevars.win (windows) file in your home directory that contains: CXX=clang++

But a first try with a clean & rebuild of CppDebugHelper only (not Rcpp) didn't help (debugging/stepping works, but printing not):

(lldb) p dbg_print(x)
error: CppDebugHelper.so DWARF DIE at 0x00099d2f (class String) has a member variable 0x00099d44 (buffer) whose type is a forward declaration, not a complete definition.
Try compiling the source file with -fstandalone-debug
error: Couldn't lookup symbols:
  Rcpp::Vector<16>::Vector(Rcpp::Vector<16> const&)
  Rcpp::traits::proxy_cache<16>::~proxy_cache()
  Rcpp::PreserveStorage<Rcpp::Vector<16> >::~PreserveStorage()

Some interesting links:

It seems that R and Rcpp must be recompiled completely with clang++ (but clang++ seems to be supported by R only on OSX/Mac) to avoid mixing compilers...

in general you CANNOT mix C++ code from different compilers

aryoda commented 4 years ago

This Debugging compiled code in R with lldb video by Jim Hester show the lldb does work within RStudio (on OSX/Mac)

It also gives good "how to debug" instructions via a live debugging session in RStudio

Direct link to the video: https://www.youtube.com/watch?v=R3-IMGyNJY4