Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler patch for native code function backtraces #3885

Closed
vicuna opened this issue Nov 22, 2005 · 1 comment
Closed

Compiler patch for native code function backtraces #3885

vicuna opened this issue Nov 22, 2005 · 1 comment
Assignees

Comments

@vicuna
Copy link

vicuna commented Nov 22, 2005

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

@vicuna
Copy link
Author

vicuna commented Jan 30, 2007

Comment author: @xavierleroy

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants