Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing current call stack in OCaml

Tags:

ocaml

Is there a way in OCaml to get the current call stack programatically? By this, I do not mean inside a debugger but as a function call inside the program that will print the current call stack. I imagine this should not be beyond the capabilities of the byte-code interpreter, especially if debug symbols are available.

like image 587
Jon Smark Avatar asked Aug 12 '12 11:08

Jon Smark


2 Answers

I came to this question looking for the same thing, here's my solution

Printexc.get_callstack 5 |> Printexc.raw_backtrace_to_string

(Its actually a pretty good way to familiarize yourself with a new code base)

like image 82
EdgarArout Avatar answered Nov 08 '22 16:11

EdgarArout


You can also use ocamldebug, with which you can start your code, compiled in bytecode. In this environment, Printexc.get_backtrace () are far more completes.

like image 41
Ontologiae Avatar answered Nov 08 '22 16:11

Ontologiae