Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0003885 [OCaml] OCaml general feature N/A 2005-11-22 17:11 2008-12-12 09:56
Reporter mottl View Status public  
Assigned To xleroy
Priority normal Resolution fixed  
Status closed   Product Version 3.09.0
Summary 0003885: Compiler patch for native code function backtraces
Description One missing feature of OCaml that makes it less useful in production code for long-running, mission-critical systems is that it is difficult to find out the reasons for crashes due to uncaught exceptions.

We have now created a patch for the most recent CVS-snapshot of the OCaml-compiler that allow users to get a backtrace at runtime about the last functions called. This is not the same as a stack backtrace. Sometimes it is more useful, sometimes less. But it is usually sufficient to find out what was going on shortly before an unexpected exception escaped a part of code or the whole program.

This feature is thread-safe: each thread maintains its own backtrace buffer. There is always a (though very small) performance overhead for calling functions that were compiled with backtracing. Inlined functions are not traced (and hence have no call-overhead).

If the program neither uses threads nor backtracing, there is never any kind of performance penalty. If threads are used, there is always a tiny penalty for thread creation/termination (due to (de)allocation of backtrace buffers), and for context switches (blitting of backtrace buffers). If backtracing is turned off, this penalty is reduced to only one instruction (for checking the backtracing flag). The large overhead that naturally comes with these thread operations renders the tiny additional overhead practically unmeasurable.

This patch does the following:

  * add a code generation module asmcomp/cmmgen_bt.ml which
    generates code for functions that should be traced. This module
    is thoroughly documented.

  * small patch to asmcomp/cmmgen.ml to call code generation
    for backtraces if demanded by the command line flags.

  * adds runtime argument "b" to "startup.c" to turn on backtracing.

  * adds functions to "printexc.{c,h,ml,mli}" to print backtraces to
    stderr, or to get an array of strings denoting the last functions
    called.

  * adds command-line argument "-gb" to "optmain.ml" and
    "clflags.{ml,mli}" to compile a module with code for backtracing.

  * larger patch to "otherlibs/systhreads/posix.c" such that each
    thread maintains its own backtrace ring buffer.

  * some small patches to Makefiles

We would be very grateful if this patch could be incorporated into the next OCaml-release, because it would make debugging long-running production code considerably easier.

Of course, feel free to make any changes to it that you see fit for making it even more useful.

Best regards,
Markus
Additional Information
Tags No tags attached.
Attached Files ? file icon ocaml_native_bt.patch [^] (25,188 bytes) 2005-11-22 17:11

- Relationships

-  Notes
(0003908)
xleroy (administrator)
2007-01-30 11:04

CVS trunk now contains a mechanism for stack backtrace on uncaught exception in native-code. It works by stack inspection (like the similar mechanism in bytecode) rather than function instrumentation (as the proposed patch).

- Issue History
Date Modified Username Field Change
2005-11-22 17:11 mottl New Issue
2005-11-22 17:11 mottl File Added: ocaml_native_bt.patch
2005-11-22 17:11 mottl Issue Monitored: mottl
2005-11-22 18:35 frisch Issue Monitored: frisch
2005-11-29 13:46 doligez Status new => acknowledged
2005-11-30 17:25 cfloyd Issue Monitored: cfloyd
2005-11-30 21:30 pzimmer Issue Monitored: pzimmer
2005-12-15 14:03 doligez Assigned To => xleroy
2006-03-06 15:49 jjhellst Issue Monitored: jjhellst
2006-03-06 16:04 dbuenzli Issue Monitored: dbuenzli
2006-03-06 22:31 avsm Issue Monitored: avsm
2006-03-07 22:30 n8gray Issue Monitored: n8gray
2006-03-31 16:56 db Issue Monitored: db
2006-05-23 12:04 tema Issue Monitored: tema
2006-05-31 22:37 romildo Issue Monitored: romildo
2006-07-19 18:08 Christoph Bauer Issue Monitored: Christoph Bauer
2006-08-10 06:24 erikd Issue Monitored: erikd
2006-08-23 13:03 smimram Issue Monitored: smimram
2006-08-23 13:03 Richard Jones Issue Monitored: Richard Jones
2006-08-23 18:37 sds Issue Monitored: sds
2006-08-24 01:07 letaris Issue Monitored: letaris
2006-08-24 09:45 kral Issue Monitored: kral
2006-09-13 06:21 jehenrik Issue Monitored: jehenrik
2006-12-12 00:44 adam Issue Monitored: adam
2006-12-13 14:05 ibormuth Issue Monitored: ibormuth
2007-01-16 14:55 Christophe Troestler Issue Monitored: Christophe Troestler
2007-01-16 21:22 spiralvoice Issue Monitored: spiralvoice
2007-01-22 04:43 lyongu Issue Monitored: lyongu
2007-01-30 11:04 xleroy Note Added: 0003908
2007-01-30 11:04 xleroy Status acknowledged => resolved
2007-01-30 11:04 xleroy Resolution open => fixed
2007-03-26 10:49 Christoph Bauer Issue End Monitor: Christoph Bauer
2008-01-21 02:56 db Issue End Monitor: db
2008-12-12 09:56 xleroy Status resolved => closed


Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker