Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When -g should be used to print stack traces in OCaml ?

I'm trying to get a stacktrace with Printexc.get_backtrace, but I'm getting an error:

(Program not linked with -g, cannot print stack backtrace)

I'm compiling like this:

ocamlfind ocamlc -g -o foo ... $(FOO_OBJS)

FOO_OBJS are compiled with just: ocamlc -c $OBJ

What's wrong? Should every .cmo be compiled with -g?

If exception occurs in an object compiled without -g will I get a partial stacktrace, or no stacktrace at all?

like image 457
pbp Avatar asked Feb 23 '12 17:02

pbp


1 Answers

What's wrong? Should every .cmo be compiled with -g?

Yes, you must add the -g option to compilation and linking. You can also use ocamldebug to step through the program with this option on. Also the enviroment variable, OCAMLRUNPARAM must be set to b.

If exception occurs in an object compiled without -g will I get a partial stacktrace, or no stacktrace at all?

You bet! I recall a few times that I'd forgotten the -g option and the back-trace was just of the standard library.

like image 197
nlucaroni Avatar answered Sep 19 '22 13:09

nlucaroni