Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004880OCaml~DO NOT USE (was: OCaml general)public2009-10-01 12:202012-09-25 20:07
Assigned Toxleroy 
PlatformWindowsOSWindows XP + VC8OS VersionCXP, SP3
Product Version3.11.1 
Target VersionFixed in Version3.13.0+dev 
Summary0004880: caml_print_exception_backtrace do not print backtrace when main program is C
DescriptionThis is a regression with 3.10.0.
When program is in CAML, call of "Printexc.record_backtrace true" triggers the printing of stack when exception are uncaught.
When main program is C or C++, backtrace are not printed anymore.
TagsNo tags attached.
Attached Fileszip file icon [^] (3,251 bytes) 2009-10-01 12:20
zip file icon [^] (4,089 bytes) 2009-10-01 16:56

- Relationships

-  Notes
daweil (reporter)
2009-10-01 16:56

After deeper analysis, it appears that :
1) for bytecode compiler, it is not a regression : printing backtrace from c never worked. (unzip attach file and type make byte_dll.exe)

2) for native compiler, I was able to print backtrace with the toy example. Within the whole application, I found a hack to print the back trace : just after caml_startup, I'v added the folowwing line "caml_backtrace_active = 1;", which replace the call to "//caml_init_backtrace();" in ocaml3.10

Is it the good hack?
xleroy (administrator)
2010-04-28 15:06

In OCaml 3.11, you can either
- call "Printexc.record_backtrace true" from your Caml code, e.g. in the initialization of one of your Caml modules,
- or call "caml_record_backtrace(Val_int(1));" from your C code.

In native code, this will produce backtraces even if your Caml code is embedded in C.

Seeting "caml_backtrace_active = 1;" is a little bit less safe than calling "caml_record_backtrace". The stakes are low (a re-raise of an exception can be confused for an initial raise), but better go through the function.

In bytecode, this is not supported: the C object file produced by ocamlc -output-obj does not contain the debugging information associated to the corresponding bytecode.

Finally, your example shows that the exception raising in an "assert" construct lacks debugging information when compiled with the native-code compiler, which results in a less precise backtrace than for a regular "raise". In other terms, your example works better if "assert false" is replaced by "raise (Failure "foo")". I'll investigate this further.
daweil (reporter)
2010-08-31 16:16

Sorry for the long long delay to answer. That works.
Is it possible to include these advice in the official doc ?
xleroy (administrator)
2011-12-20 11:46

Mentioned the backtrace trick in the manual (commit 11892).

Fixed the compiler so that "assert" constructs carry the debugging info needed for them to appear properly in stack backtraces (commit 11891 in SVN trunk).

- Issue History
Date Modified Username Field Change
2009-10-01 12:20 daweil New Issue
2009-10-01 12:20 daweil File Added:
2009-10-01 16:56 daweil Note Added: 0005126
2009-10-01 16:56 daweil File Added:
2010-04-18 15:05 xleroy Status new => assigned
2010-04-18 15:05 xleroy Assigned To => xleroy
2010-04-28 15:06 xleroy Note Added: 0005404
2010-08-31 16:16 daweil Note Added: 0005647
2011-12-20 11:46 xleroy Note Added: 0006406
2011-12-20 11:46 xleroy Status assigned => resolved
2011-12-20 11:46 xleroy Resolution open => fixed
2011-12-20 11:46 xleroy Fixed in Version => 3.13.0+dev
2012-09-25 20:07 xleroy Status resolved => closed
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker