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

caml_print_exception_backtrace do not print backtrace when main program is C #4880

Closed
vicuna opened this issue Oct 1, 2009 · 4 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link

commented Oct 1, 2009

Original bug ID: 4880
Reporter: daweil
Assigned to: @xavierleroy
Status: closed (set by @xavierleroy on 2012-09-25T18:07:21Z)
Resolution: fixed
Priority: normal
Severity: block
Platform: Windows
OS: Windows XP + VC8
OS Version: CXP, SP3
Version: 3.11.1
Fixed in version: 3.13.0+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @glondu @hcarty daweil

Bug description

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

File attachments

@vicuna

This comment has been minimized.

Copy link
Author

commented Oct 1, 2009

Comment author: daweil

After deeper analysis, it appears that :

  1. for bytecode compiler, it is not a regression : printing backtrace from c never worked. (unzip attach file caml_from_c2.zip 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?

@vicuna

This comment has been minimized.

Copy link
Author

commented Apr 28, 2010

Comment author: @xavierleroy

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.

@vicuna

This comment has been minimized.

Copy link
Author

commented Aug 31, 2010

Comment author: daweil

Sorry for the long long delay to answer. That works.
Is it possible to include these advice in the official doc ?

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 20, 2011

Comment author: @xavierleroy

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

@vicuna vicuna closed this Sep 25, 2012

@vicuna vicuna added the bug label Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.