A bugger of a debugger

through the years I’ve tried from time to time to use ocamldebug and always failed.
And I assumed it was just buggy.

but that cannot possibly be by now.
so - I cannot think of anything more obviously desirable than to be able to run a program
through to a thrown exception then see the backtrace for its origin.
and I cannot do it!!!
backtrace? no output
start? ‘not meaningful in outermost frame’
goto X (picking some arbitrary event number before the final one)? somewhere in the no man’s land of the standard library usually, then ‘backtrace’ shows something but it’s hit and miss.
next/prev? they don’t appear to jump over functions or be symmetrical - one next descends into a function innards while several 'prev’s are needed to get back. WTF?

how can something so simple be so difficult?
I know it’s probably me but after looking at it with a fresh head so many times then retreating, I can’t help but wonder…

90% of the times I use ocamldebug I use it the following way (my guess would be that you forgot step 6) :

  1. You notice that a certain function (let’s call it my_flawed_fun) raises some exception or has an otherwise unwanted behavior.
  2. Add a line or two to my_flawed_fun so that it raises an exception (if it does not already).
  3. Compile all the modules my_flawed_fun needs with the -g option, and link them in an executable.
  4. Launch ocamldebug on that executable.
  5. run (you should see your exception)
  6. backstep
  7. backtrace
  8. In the backtrace list, spot the item you need. Set a breakpoint on it and
  9. reverse
1 Like

I normally run until the uncaught exception, and then backstep to get to the point that raised the exception. Sometimes people have been catching and reraising the exception, which means using prev and backstep a bit more to get there.