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

Runtime: record backtraces should be explicit #1637

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
## Features/Changes
* Misc: update testsuite to OCmaml 5.2
* Misc: CI uses opam.2.2 and no longer use sunset repo
* Runtime: change Sys.os_type on windows (Cygwin -> Win32)
* Compiler: speedup global_flow/global_deadcode pass on large bytecode
* Runtime: change Sys.os_type on windows (Cygwin -> Win32)
* Runtime: backtraces are really expensive, they need to be be explicitly
requested at compile time (--enable with-js-error) or at startup (OCAMLRUNPARAM=b=1)

## Bug fixes
* Runtime: fix parsing of unsigned integers (0u2147483648)
Expand Down
20 changes: 12 additions & 8 deletions runtime/backtrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,40 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


//Provides: caml_record_backtrace_flag
//Provides: caml_record_backtrace_env_flag
//Requires: jsoo_sys_getenv
var caml_record_backtrace_flag = FLAG("with-js-error");
var caml_record_backtrace_env_flag = FLAG("with-js-error");

(function () {
var r = jsoo_sys_getenv("OCAMLRUNPARAM")
if(r !== undefined){
var l = r.split(",");
for(var i = 0; i < l.length; i++){
if(l[i] == "b") { caml_record_backtrace_flag = 1; break }
if(l[i] == "b") { caml_record_backtrace_env_flag = 1; break }
else if (l[i].startsWith("b=")) {
caml_record_backtrace_flag = +(l[i].slice(2))}
caml_record_backtrace_env_flag = +(l[i].slice(2)) }
else continue;
}
}
}) ()

//Provides: caml_record_backtrace_runtime_flag
//Requires: caml_record_backtrace_env_flag
var caml_record_backtrace_runtime_flag = caml_record_backtrace_env_flag;


//Provides: caml_ml_debug_info_status const
function caml_ml_debug_info_status () { return 0; }
//Provides: caml_backtrace_status
//Requires: caml_record_backtrace_flag
function caml_backtrace_status (_unit) { return caml_record_backtrace_flag ? 1 : 0; }
//Requires: caml_record_backtrace_runtime_flag
function caml_backtrace_status (_unit) { return caml_record_backtrace_runtime_flag ? 1 : 0; }
//Provides: caml_get_exception_backtrace const
function caml_get_exception_backtrace () { return 0; }
//Provides: caml_get_exception_raw_backtrace const
function caml_get_exception_raw_backtrace () { return [0]; }
//Provides: caml_record_backtrace
//Requires: caml_record_backtrace_flag
function caml_record_backtrace (b) { caml_record_backtrace_flag = b; return 0; }
//Requires: caml_record_backtrace_runtime_flag
function caml_record_backtrace (b) { caml_record_backtrace_runtime_flag = b; return 0; }
//Provides: caml_convert_raw_backtrace const
function caml_convert_raw_backtrace () { return [0]; }
//Provides: caml_raw_backtrace_length
Expand Down
9 changes: 7 additions & 2 deletions runtime/jslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,14 @@ function caml_wrap_exception(e) {

//Provides: caml_maybe_attach_backtrace
//Requires: caml_exn_with_js_backtrace
//Requires: caml_record_backtrace_flag
//Requires: caml_record_backtrace_env_flag
//Requires: caml_record_backtrace_runtime_flag
function caml_maybe_attach_backtrace(exn, force) {
if(caml_record_backtrace_flag)
// Backtraces are very expensive, we only enable them when explicitly requested
// at compile-time (--enable with-js-error) or at startup with OCAMLRUNPARAM=b=1.
// Libraries such as Base unconditionally enable backtraces (programmatically) but
// it's way to slow. Here, we force the end-user to opt-in to backtraces.
if(caml_record_backtrace_env_flag && caml_record_backtrace_runtime_flag)
return caml_exn_with_js_backtrace(exn, force);
else return exn
}
Expand Down
Loading