简体   繁体   中英

How to break C source code in R?

I want to set aa break-point in the C implementation for model.matrix. I tried Selva's solution in How can I view the source code for a function? :

> debug(C_modelmatrix)
Error in debug(C_modelmatrix) : object 'C_modelmatrix' not found
> debug(modelmatrix)
Error in debug(modelmatrix) : object 'modelmatrix' not found

The function I'm interested can be found here .

SEXP modelmatrix(SEXP call, SEXP op, SEXP args, SEXP rho

I'm building and running from R source code. How do I set a break-point?

There is still-useful video tutorial by Seth Falcon on how to debug R packages with native code which shows this.

In essence, launch R with R -d gdb to invoke the gdb debugger which you then instruct to set breakpoints in the right places.

If you (or your operating system) prefers a different compiler, you obviously need to substitute it in the invocation: R -d lldb .

I think Dirk's answer is perfect. Note that gdb is not supported in OS-X, we'd have to use lldb.

> /bin/R -d lldb
> b modelmatrix
> r

Now, run any one-factor ANOVA experiment to trigger the breakpoint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM