Skip to content

Commit a2615e4

Browse files
committed
Rigorous backtrace across compiler-libs
1 parent aef9296 commit a2615e4

File tree

6 files changed

+45
-4
lines changed

6 files changed

+45
-4
lines changed

jscomp/ext/ext_obj.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,23 @@ let pp_any fmt v =
108108
(dump v )
109109

110110

111+
let bt () =
112+
let raw_bt = Printexc.backtrace_slots (Printexc.get_raw_backtrace()) in
113+
match raw_bt with
114+
| None -> ()
115+
| Some raw_bt ->
116+
let acc = ref [] in
117+
(for i = Array.length raw_bt - 1 downto 0 do
118+
let slot = raw_bt.(i) in
119+
match Printexc.Slot.location slot with
120+
| None
121+
-> ()
122+
| Some bt ->
123+
(match !acc with
124+
| [] -> acc := [bt]
125+
| hd::tl -> if hd <> bt then acc := bt :: !acc )
126+
127+
done);
128+
Ext_list.iter !acc (fun bt ->
129+
Printf.eprintf "File \"%s\", line %d, characters %d-%d\n"
130+
bt.filename bt.line_number bt.start_char bt.end_char )

jscomp/ext/ext_obj.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424
val dump : 'a -> string
2525
val pp_any : Format.formatter -> 'a -> unit
26+
val bt : unit -> unit

jscomp/main/js_main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ let _ =
347347
with x ->
348348
begin
349349
#if undefined BS_RELEASE_BUILD then
350-
Printexc.print_backtrace stderr;
350+
Ext_obj.bt ();
351351
#end
352352
Location.report_exception ppf x;
353353
exit 2

jscomp/test/recursive_unbound_module_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function Make(X) {
1212

1313
var B = Caml_module.init_mod([
1414
"recursive_unbound_module_test.ml",
15-
15,
15+
18,
1616
0
1717
], [[[[0]]]]);
1818

lib/4.02.3/unstable/all_ounit_tests.ml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10579,7 +10579,7 @@ module Ext_obj : sig
1057910579
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
1058010580
val dump : 'a -> string
1058110581
val pp_any : Format.formatter -> 'a -> unit
10582-
10582+
val bt : unit -> unit
1058310583
end = struct
1058410584
#1 "ext_obj.ml"
1058510585
(* Copyright (C) 2019-Present Authors of BuckleScript
@@ -10692,6 +10692,26 @@ let pp_any fmt v =
1069210692
(dump v )
1069310693

1069410694

10695+
let bt () =
10696+
let raw_bt = Printexc.backtrace_slots (Printexc.get_raw_backtrace()) in
10697+
match raw_bt with
10698+
| None -> ()
10699+
| Some raw_bt ->
10700+
let acc = ref [] in
10701+
(for i = Array.length raw_bt - 1 downto 0 do
10702+
let slot = raw_bt.(i) in
10703+
match Printexc.Slot.location slot with
10704+
| None
10705+
-> ()
10706+
| Some bt ->
10707+
(match !acc with
10708+
| [] -> acc := [bt]
10709+
| hd::tl -> if hd <> bt then acc := bt :: !acc )
10710+
10711+
done);
10712+
Ext_list.iter !acc (fun bt ->
10713+
Printf.eprintf "File \"%s\", line %d, characters %d-%d\n"
10714+
bt.filename bt.line_number bt.start_char bt.end_char )
1069510715

1069610716
end
1069710717
module Ounit_hashtbl_tests

ocaml

Submodule ocaml updated from 263b645 to f195cac

0 commit comments

Comments
 (0)