[Rcpp-devel] experimental c++ stack trace
Romain Francois
romain at r-enthusiasts.com
Tue Mar 23 17:19:42 CET 2010
Hello,
I've commited some experimental mechanism based on this blog post
:http://tombarta.wordpress.com/2008/08/01/c-stack-traces-with-gcc/
This uses the backtrace_symbols function (see
http://www.gnu.org/s/libc/manual/html_node/Backtraces.html) to grab a
stack trace.
The main entry point is the Rcpp_error macro that is used similarly to
Rf_error, but it gathers more information. For example :
require( inline )
require( Rcpp)
inspect <- function(...) .Internal(inspect(...))
fx <- cfunction( signature( l = "list" ), '
Rcpp_error( "boom" ) ;
', Rcpp = TRUE, includes = "using namespace Rcpp;" )
tryCatch( fx( poisson() ), "error" = function(e) print(str(e)) )
prints out this :
List of 3
$ message : chr "unrecognized exception"
$ call : language fx(poisson())
$ cppstack:List of 3
..$ file : chr "file10d63af1.cpp"
..$ line : int 11
..$ stack: chr [1:47] "Rcpp::exception::exception(char const*, char
const*, int)" "file10d63af1" "do_dotcall" "Rf_eval" ...
..- attr(*, "class")= chr "Rcpp_stack_trace"
- attr(*, "class")= chr [1:4] "Rcpp::exception*" "C++Error" "error"
"condition"
The interesting bit is the cppstack which indicates :
- the file from which Rcpp_error was called
- the line of
- the stack of calls, demangled
I'd appreciate suggestions on the interface, should we have a nice print
function at the R level, etc ...
Romain
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/OIXN : raster images and RImageJ
|- http://tr.im/OcQe : Rcpp 0.7.7
`- http://tr.im/O1wO : highlight 0.1-5
More information about the Rcpp-devel
mailing list