From cc332679fe7c5926e84a5d7fd9eb979d8393ac91 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Tue, 30 Apr 2024 11:23:16 +0200 Subject: [PATCH] Make sure backtraces are propagated --- spectec/src/backend-interpreter/runner.ml | 3 ++- spectec/src/il/valid.ml | 3 ++- spectec/src/util/debug_log.ml | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/spectec/src/backend-interpreter/runner.ml b/spectec/src/backend-interpreter/runner.ml index c07547bdec..35b03bfc96 100644 --- a/spectec/src/backend-interpreter/runner.ml +++ b/spectec/src/backend-interpreter/runner.ml @@ -265,10 +265,11 @@ let parse_file name parser_ file = try parser_ file with e -> + let bt = Printexc.get_raw_backtrace () in print_endline ("- Failed to parse " ^ name ^ "\n"); log ("- Failed to parse %s\n") name; num_parse_fail := !num_parse_fail + 1; - raise e + Printexc.raise_with_backtrace e bt (** Runner **) diff --git a/spectec/src/il/valid.ml b/spectec/src/il/valid.ml index 8ace2a0068..45ba90c446 100644 --- a/spectec/src/il/valid.ml +++ b/spectec/src/il/valid.ml @@ -449,8 +449,9 @@ try equiv_typ env t2 t e.at; sub_typ env t1 t2 e.at with exn -> + let bt = Printexc.get_raw_backtrace () in Printf.eprintf "[valid_exp] %s\n%!" (Debug.il_exp e); - raise exn + Printexc.raise_with_backtrace exn bt and valid_expmix env mixop e (mixop', t) at = diff --git a/spectec/src/util/debug_log.ml b/spectec/src/util/debug_log.ml index a842ec0705..6e85dfa2e6 100644 --- a/spectec/src/util/debug_log.ml +++ b/spectec/src/util/debug_log.ml @@ -14,8 +14,9 @@ let log_at (type a) label at (arg_f : unit -> string) (res_f : a -> string) (f : Printf.eprintf "[%s%s] %s\n%!" label ats arg; match f () with | exception exn -> + let bt = Printexc.get_raw_backtrace () in Printf.eprintf "[%s%s] %s => raise %s\n%!" label ats arg (Printexc.to_string exn); - raise exn + Printexc.raise_with_backtrace exn bt | x -> let res = res_f x in if res <> "" then Printf.eprintf "[%s%s] %s => %s\n%!" label ats arg res;