Skip to content

Commit

Permalink
Merge pull request #1619 from goblint/issue-1616
Browse files Browse the repository at this point in the history
Print innermost backtrace mark for uncaught exception even with backtrace printing off
  • Loading branch information
sim642 authored Dec 16, 2024
2 parents d2f6584 + f7184c0 commit b7747c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/util/backtrace/goblint_backtrace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,19 @@ let print_marktrace oc e =
Printf.fprintf oc "Marked with %s\n" (mark_to_string m)
) ms

let print_innermost_mark oc e =
match find_marks e with
| m :: _ -> Printf.fprintf oc "Marked with %s\n" (mark_to_string m)
| [] -> ()

let () =
Printexc.set_uncaught_exception_handler (fun e bt ->
(* Copied & modified from Printexc.default_uncaught_exception_handler. *)
Printf.eprintf "Fatal error: exception %s\n" (Printexc.to_string e); (* nosemgrep: print-not-logging *)
if Printexc.backtrace_status () then
print_marktrace stderr e;
print_marktrace stderr e
else
print_innermost_mark stderr e;
Printexc.print_raw_backtrace stderr bt;
flush stderr
)
5 changes: 5 additions & 0 deletions src/util/backtrace/goblint_backtrace.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@ val print_marktrace: out_channel -> exn -> unit
Used by default for uncaught exceptions. *)

val print_innermost_mark: out_channel -> exn -> unit
(** Print innermost mark of an exception.
Used by default for uncaught exceptions. *)

val find_marks: exn -> mark list
(** Find all marks of an exception. *)

0 comments on commit b7747c9

Please sign in to comment.