Re: backtrace not working in ocamldebug ?

"Gabriel Scherer [email protected] [ocaml_beginners]" <[email protected]> Fri, 12 Aug 2016 09:56:10 +0200
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <CAPFanBHEZSZzx=CosCfZOHKTfSE-sjzTWbFG2ge29DwnEEjXhw@mail.gmail.com>
A "tail call" (not a tail function) is a function call whose return value
is the return value of the whole expression it contains. For example the
calls to "f" in (f 1) or (f (g x)) or (if foo then f 1 else f 2) are tail
calls, but ((f 1) + 1) is not -- after f has returned, some computations (_
+ 1) is still to be done.

In most functional programming languages tail call have a different status
from non-tail calls. This generalizes the so-called "tail-recursion
optimization".

On Fri, Aug 12, 2016 at 9:32 AM, Gabriel Scherer <[email protected]>
wrote:

> 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
>>
>>
>>
>>
>>
>>
>> 
>>
>
>