Skip to content

Commit

Permalink
[html][multicore] safe debug html state control
Browse files Browse the repository at this point in the history
Summary: Fix race on flag controlling html debug output generation.

Reviewed By: jvillard

Differential Revision:
D68017869

Privacy Context Container: L1208441

fbshipit-source-id: af20a305c571a44c8b570348de726ec5673f0cb9
  • Loading branch information
ngorogiannis authored and facebook-github-bot committed Jan 13, 2025
1 parent e9bfd6c commit 9dfabdb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
9 changes: 7 additions & 2 deletions infer/src/backend/NodePrinter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,20 @@ let kind_to_string = function
let with_kind pp_name kind f = Format.fprintf f "[%s] %t" (kind_to_string kind) pp_name

(* turned off in preanalysis *)
let print_html = ref true
let print_html = DLS.new_key (fun () -> true)

let with_session ?kind ~pp_name node ~f =
AnalysisState.set_node node ;
if Config.write_html && !print_html then (
if Config.write_html && DLS.get print_html then (
L.reset_delayed_prints () ;
let session = new_session node in
AnalysisState.set_session session ;
let pp_name = Option.fold kind ~init:pp_name ~f:with_kind in
Printer.node_start_session ~pp_name node session ;
Exception.try_finally ~f ~finally:(fun () -> Printer.node_finish_session node) )
else f ()


let enable_html_printing () = DLS.set print_html true

let disable_html_printing () = DLS.set print_html false
6 changes: 3 additions & 3 deletions infer/src/backend/NodePrinter.mli
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ val with_session :
-> 'a
(** Wraps [f] in an html debug session *)

val print_html : bool ref
(** Controls whether the HTML printing is enabled for all analyses except pre-analysis. Set to false
in preanalysis to prevent printing and turned back again. *)
val enable_html_printing : unit -> unit

val disable_html_printing : unit -> unit
4 changes: 2 additions & 2 deletions infer/src/backend/preanal.ml
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ module RemoveDeadNodes = struct
end

let do_preanalysis tenv pdesc =
if not Config.preanalysis_html then NodePrinter.print_html := false ;
if not Config.preanalysis_html then NodePrinter.disable_html_printing () ;
let proc_name = Procdesc.get_proc_name pdesc in
if Procname.is_java proc_name || Procname.is_csharp proc_name then
InlineJavaSyntheticMethods.process pdesc ;
Expand All @@ -570,5 +570,5 @@ let do_preanalysis tenv pdesc =
if Procname.is_java proc_name then Devirtualizer.process pdesc tenv ;
NoReturn.process tenv pdesc ;
RemoveDeadNodes.process pdesc ;
NodePrinter.print_html := true ;
NodePrinter.enable_html_printing () ;
()
2 changes: 1 addition & 1 deletion infer/src/clang/cFrontend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let do_objc_preanalyses cfg tenv =
CReplaceDynamicDispatch.process cfg ;
CViewControllerLifecycle.process cfg tenv ;
if Config.compute_captured_context then (
if not Config.preanalysis_html then NodePrinter.print_html := false ;
if not Config.preanalysis_html then NodePrinter.disable_html_printing () ;
Timer.time Preanalysis
~f:(fun () -> ComputeCapturedInfo.process cfg)
~on_timeout:(fun span ->
Expand Down

0 comments on commit 9dfabdb

Please sign in to comment.