Re: backtrace not working in ocamldebug ?
"Gabriel Scherer [email protected] [ocaml_beginners]" <[email protected]> Fri, 12 Aug 2016 09:32:34 +0200
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <CAPFanBGvGoZQNGRV5=h7yoxoz5Eb6Q+L6xGxzoYdNxMNtUmj-w@mail.gmail.com> |
There is confusion created by an unfortunate choice of words. The ocamldebug "backtrace" command actually prints the *stack trace*, which is the series of non-tail function calls from the start of the application to the current program point: http://caml.inria.fr/pub/docs/manual-ocaml/debugger.html#sec374 In your code, you run "bt" after the program has finished, so the stack trace is empty -- raising the exception returned the control to the very top of the program context. As ocamldebug supports reverse execution, you can always step back to the point the exception was raised and get the stack trace there, to get what usually corresponds to an exception backtrace: (ocd) r Time: 16 Program end. Uncaught exception: Debug_me.Excepted (ocd) prev Time: 15 - pc: 9740 - module Debug_me 3 let f1 x=raise(Excepted)<|a|>;; (ocd) backtrace Backtrace: #0 Debug_me debug_me.ml:3:25 #1 Debug_me debug_me.ml:7:5 (The backtrace is small because the auxiliary functions f2,f3 are tail-calls that do not appear in the trace. Change them to, for example, (f1 x)+1, (f2 x)+7 to see a longer trace with those calls.) On Fri, Aug 12, 2016 at 8:52 AM, [email protected] [ocaml_beginners] <[email protected]> wrote: > > > I have a file containing just the following code : > > exception Excepted;; > let f1 x=raise(Excepted);; > let f2 x=f1 (x+1);; > let f3 x=f2 (x+7);; > > f3 4;; > > > The file is called debug_me.ml and I compile it wth the following > command : > > ocamlc -g -o debug_me.out debug_me.ml > > Next, I launch the debugger with ocamldebug debug_me.out. In the debugger, > I do > « run » and « backtrace » but this last command produces no result : > > OCaml Debugger version 4.02.1 > > (ocd) r > Loading program... done. > Time: 16 > Program end. > Uncaught exception: Debug_me.Excepted > (ocd) bt > (ocd) backtrace > > > > > > > >