Skip to content

Commit

Permalink
Add Goblint_backtrace.wrap_val
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Aug 12, 2024
1 parent 476f20b commit 4eb58d6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/autoTune.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let functionArgs fd = (ResettableLazy.force functionCallMaps).argLists |> Functi

let findMallocWrappers () =
let isMalloc f =
Goblint_backtrace.protect ~mark:(fun () -> Cilfacade.FunVarinfo f) ~finally:Fun.id @@ fun () ->
Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo f) @@ fun () ->
if LibraryFunctions.is_special f then (
let desc = LibraryFunctions.find f in
match functionArgs f with
Expand Down Expand Up @@ -154,15 +154,15 @@ let disableIntervalContextsInRecursiveFunctions () =

let hasFunction pred =
let relevant_static var =
Goblint_backtrace.protect ~mark:(fun () -> Cilfacade.FunVarinfo var) ~finally:Fun.id @@ fun () ->
Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo var) @@ fun () ->
if LibraryFunctions.is_special var then
let desc = LibraryFunctions.find var in
GobOption.exists (fun args -> pred (desc.special args)) (functionArgs var)
else
false
in
let relevant_dynamic var =
Goblint_backtrace.protect ~mark:(fun () -> Cilfacade.FunVarinfo var) ~finally:Fun.id @@ fun () ->
Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo var) @@ fun () ->
if LibraryFunctions.is_special var then
let desc = LibraryFunctions.find var in
(* We don't really have arguments at hand, so we cheat and just feed it a list of MyCFG.unknown_exp of appropriate length *)
Expand Down
2 changes: 1 addition & 1 deletion src/cdomain/value/util/wideningThresholds.ml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class extractInvariantsVisitor (exps) = object
method! vinst (i: instr) =
match i with
| Call (_, Lval (Var f, NoOffset), args, _, _) when LibraryFunctions.is_special f ->
Goblint_backtrace.protect ~mark:(fun () -> Cilfacade.FunVarinfo f) ~finally:Fun.id @@ fun () ->
Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo f) @@ fun () ->
let desc = LibraryFunctions.find f in
begin match desc.special args with
| Assert { exp; _ } ->
Expand Down
2 changes: 1 addition & 1 deletion src/transform/evalAssert.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct
let is_lock exp args =
match exp with
| Lval(Var v,_) when LibraryFunctions.is_special v ->
Goblint_backtrace.protect ~mark:(fun () -> Cilfacade.FunVarinfo v) ~finally:Fun.id @@ fun () ->
Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo v) @@ fun () ->
let desc = LibraryFunctions.find v in
(match desc.special args with
| Lock _ -> true
Expand Down
9 changes: 9 additions & 0 deletions src/util/backtrace/goblint_backtrace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ let protect ~(mark: unit -> mark) ~(finally: unit -> unit) work =
add_mark work_exn (mark ());
Printexc.raise_with_backtrace work_exn work_bt

(* Copied & modified from protect. *)
let wrap_val ~(mark:mark) work =
try
work ()
with work_exn ->
let work_bt = Printexc.get_raw_backtrace () in
add_mark work_exn mark;
Printexc.raise_with_backtrace work_exn work_bt


let mark_printers: (mark -> string option) list ref = ref []

Expand Down
3 changes: 3 additions & 0 deletions src/util/backtrace/goblint_backtrace.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ val add_mark: exn -> mark -> unit
val protect: mark:(unit -> mark) -> finally:(unit -> unit) -> (unit -> 'a) -> 'a
(** {!Fun.protect} with additional [~mark] addition to all exceptions. *)

val wrap_val: mark:mark -> (unit -> 'a) -> 'a
(** {!protect} with [~mark] value and without [~finally]. *)

val print_marktrace: out_channel -> exn -> unit
(** Print trace of marks of an exception.
Expand Down
2 changes: 1 addition & 1 deletion src/util/loopUnrolling.ml
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class loopUnrollingCallVisitor = object

method! vinst = function
| Call (_,Lval ((Var info), NoOffset),args,_,_) when LibraryFunctions.is_special info -> (
Goblint_backtrace.protect ~mark:(fun () -> Cilfacade.FunVarinfo info) ~finally:Fun.id @@ fun () ->
Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo info) @@ fun () ->
let desc = LibraryFunctions.find info in
match desc.special args with
| Malloc _
Expand Down
2 changes: 1 addition & 1 deletion src/witness/witnessUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct
List.exists (fun (_, edge) ->
match edge with
| Proc (_, Lval (Var fv, NoOffset), args) when LibraryFunctions.is_special fv ->
Goblint_backtrace.protect ~mark:(fun () -> Cilfacade.FunVarinfo fv) ~finally:Fun.id @@ fun () ->
Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo fv) @@ fun () ->
let desc = LibraryFunctions.find fv in
begin match desc.special args with
| Lock _ -> true
Expand Down

0 comments on commit 4eb58d6

Please sign in to comment.