You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 3885 Reporter:@mmottl Assigned to:@xavierleroy Status: closed (set by @xavierleroy on 2008-12-12T08:56:56Z) Resolution: fixed Priority: normal Severity: feature Version: 3.09.0 Category: ~DO NOT USE (was: OCaml general) Monitored by: lyongu ibormuth adam jehenrik kral letaris sds erikd "Richard Jones" romildo tema n8gray @avsm@dbuenzli jjhellst @Chris00 spiralvoice smimram cfloyd pzimmer @alainfrisch@mmottl
Bug 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.
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).
Original bug ID: 3885
Reporter: @mmottl
Assigned to: @xavierleroy
Status: closed (set by @xavierleroy on 2008-12-12T08:56:56Z)
Resolution: fixed
Priority: normal
Severity: feature
Version: 3.09.0
Category: ~DO NOT USE (was: OCaml general)
Monitored by: lyongu ibormuth adam jehenrik kral letaris sds erikd "Richard Jones" romildo tema n8gray @avsm @dbuenzli jjhellst @Chris00 spiralvoice smimram cfloyd pzimmer @alainfrisch @mmottl
Bug 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
File attachments
The text was updated successfully, but these errors were encountered: