Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
a472283
g2html/resources: xslt based approach
kalmera Mar 2, 2014
7b502d5
g2html/resources: offline fonts
kalmera Mar 2, 2014
d99f2a0
g2html/resources: more work on g2html
kalmera Mar 3, 2014
d4eda40
g2html/resources: some more work
kalmera Mar 3, 2014
db65b2c
g2html/resources: iframe resizing, warnings, and svg window size
kalmera Mar 4, 2014
6b35d75
g2html/resources: only iframes and objects
kalmera Mar 4, 2014
f788e60
g2html/resources: multiple levels of iframes
kalmera Mar 4, 2014
b5ca604
g2html/resources: Revert 760e44a..1d23536
kalmera Mar 5, 2014
33b8454
g2html/resources: reverted to use json files again
kalmera Mar 5, 2014
757fcfc
g2html/resources: more work on stuff
kalmera Mar 7, 2014
6b291e6
g2html/resources: Syntax highlighting added
stefanmarcik Mar 13, 2014
ba43f46
g2html/resources: re-ordered globals and made node style lighter
kalmera Mar 13, 2014
7c46c52
g2html/resources: added more syntax highlighting
kalmera Mar 14, 2014
80a7901
g2html/resources: forward the selected line to the file listing
kalmera Mar 14, 2014
a3debde
g2html/resources: monospaced font for code listings
kalmera Mar 14, 2014
490b7a2
g2html/resources: span nodes have no value in firefox
kalmera Mar 14, 2014
b722c66
g2html/resources: minor improvements
kalmera Mar 14, 2014
dbbf775
g2html/resources: use full path for id
kalmera Mar 19, 2014
b6004be
g2html/resources: filter listing files that have live program points
kalmera Mar 19, 2014
8c97fe4
g2html/resources: server code
kalmera Jul 2, 2014
c3af784
g2html/resources: warning iframes too high and animation too slow
vogler Jun 1, 2016
cf8af72
g2html/resources: Fix globals being mixed up between analyses
sim642 Oct 1, 2020
2ae9608
g2html/resources: Trim trailing whitespace in globals
sim642 Dec 1, 2021
b0cc2ba
g2html/resources: Fix globals analysis blocks showing empty values fo…
sim642 Dec 1, 2021
2c94f59
g2html/resources: Fix duplicate globals analysis blocks
sim642 Dec 1, 2021
fd1e3b8
g2html/resources: Add support for contexts embedded in global invariant
sim642 Jan 20, 2022
1556c52
g2html/resources: Fix globals uniqueness filtering
sim642 Sep 2, 2022
c73eef9
g2html/resources: Add end locations and synthetic flag to node locations
sim642 Feb 8, 2024
7f9c70a
Output most g2html results directly
sim642 May 22, 2025
4e134b8
Output g2html .dot files directly
sim642 May 23, 2025
1b6c6b5
Generate g2html graphviz files directly
sim642 May 23, 2025
d350cb9
Output minimal g2html <file> files directly
sim642 May 23, 2025
f1253e6
Fix file paths in direct g2html index
sim642 May 23, 2025
402543a
Copy g2html resources to direct g2html output
sim642 May 23, 2025
4e69fd9
Add warnings to code lines in direct g2html output
sim642 May 23, 2025
cb0cb1c
Add nodes to code lines in direct g2html output
sim642 May 23, 2025
244a4d8
Add liveness to code lines in direct g2html output
sim642 May 23, 2025
7b38ce4
Add pygmentize to direct g2html output
sim642 Jul 23, 2025
e9b4d94
Extract XsltResult from AnalysisResult
sim642 Jul 23, 2025
b1c4368
Split XsltResult modules more
sim642 Jul 23, 2025
beb7955
Extract write_index in direct g2html output
sim642 Jul 23, 2025
a96405b
Extract write_globals in direct g2html output
sim642 Jul 23, 2025
ac3bd04
Extract write_node in direct g2html output
sim642 Jul 23, 2025
aa72440
Extract write_warn in direct g2html output
sim642 Jul 23, 2025
4739751
Extract write_file in direct g2html output
sim642 Jul 23, 2025
754a0cb
Extract write_dot in direct g2html output
sim642 Jul 23, 2025
bedfa49
Extract cfg_task in direct g2html output
sim642 Jul 23, 2025
04cf00d
Extract copy_resources in direct g2html output
sim642 Jul 23, 2025
8bfcfeb
Remove unused <node>-s from direct g2html index
sim642 Jul 23, 2025
d6e2785
Use set for file2funs in direct g2html output
sim642 Jul 24, 2025
50200f9
Use set of fundecs for file2funs in direct g2html output
sim642 Jul 24, 2025
f0fc4fb
Extract write_nodes in direct g2html output
sim642 Jul 24, 2025
7f4f2d9
Extract write_warns in direct g2html output
sim642 Jul 24, 2025
b814daf
Extract write_files in direct g2html output
sim642 Jul 24, 2025
52634e4
Extract write_dots_cfgs in direct g2html output
sim642 Jul 24, 2025
e1ee2f2
Extract output_g2html in direct g2html output
sim642 Jul 24, 2025
ee8a726
Generalize path handling in direct g2html output
sim642 Jul 24, 2025
c8ebdb3
Extract CodeHighlighter module
sim642 Jul 24, 2025
9d9a786
Add fallback to CodeHighlighter
sim642 Jul 24, 2025
054d87c
Clean up format strings in direct g2html output
sim642 Jul 24, 2025
6e68cdf
Extract GobHashtbl with find_or_add_default_delayed
sim642 Jul 24, 2025
d442435
Simplify nested Hashtbl lookups in direct g2html output
sim642 Jul 24, 2025
4544dbe
Clean up printXml-s in direct g2html output
sim642 Jul 24, 2025
63fa7fa
Clean up CFG functions in direct g2html output
sim642 Jul 24, 2025
4c8ef99
Add 'xslt/' from commit 'c73eef953faf47ebe174854e276b801eaa6be932'
sim642 Jul 24, 2025
5906c11
Adapt xslt/file for direct g2html output with Pygments highlighting
sim642 Jul 24, 2025
c67f7e8
Vendor xslt for direct g2html output
sim642 Jul 24, 2025
069f311
Extract AnalysisResult0 module
sim642 Jul 24, 2025
8cff582
Separate analysis result from result output
sim642 Jul 24, 2025
64c3fd8
Rename analysis result output modules
sim642 Jul 24, 2025
dcac0a1
Rename analysis result module
sim642 Jul 24, 2025
4d35dc0
Update module documentation for result output
sim642 Jul 24, 2025
9610bcb
Merge branch 'master' into g2html-ocaml
sim642 Jul 24, 2025
4802f12
Fix new BatEnum semgrep warnings
sim642 Jul 24, 2025
63bda22
Rename direct g2html output to xslt
sim642 Jul 25, 2025
52137b5
Replace g2html option with g2html result
sim642 Jul 25, 2025
901dbcb
Move do_html_output with g2html to XsltResultOutput
sim642 Jul 25, 2025
478db9d
Move exp.g2html_path option handling
sim642 Jul 25, 2025
21c97e0
Make exp.cfgdot part of g2html output
sim642 Jul 25, 2025
393cc37
Don't use outfile option for g2html directory
sim642 Jul 25, 2025
e72289c
Remove assert false from xslt output
sim642 Jul 25, 2025
c5cbb4c
Make xslt output default for --html
sim642 Jul 25, 2025
947c30b
Merge branch 'master' into g2html-ocaml
sim642 Aug 11, 2025
e84a0ce
Add timing for code highlighter
sim642 Aug 11, 2025
e88b0e2
Remove remove old result dir in direct g2html output
sim642 Aug 11, 2025
31c74b2
Update TODOs in XsltResultOutput
sim642 Oct 3, 2025
3724cbd
Update HTML output documentatioon
sim642 Oct 3, 2025
8461c86
Update make setup for new HTML output
sim642 Oct 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions docs/user-guide/inspecting.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
# Inspecting results

## g2html
## HTML
1. Run Goblint with additional `--html` argument.
2. Run `python3 -m http.server --directory result 8080`
or `npx http-server -c-1 result`.
3. Inspect results at <http://localhost:8080/index.xml>.

Modern browsers' security settings forbid some file access which is necessary for the HTML output to work, hence the need for serving the results via Python's `http.server` (or similar).

## g2html (legacy)
If there are problems with the above HTML output, the legacy g2html output (using an external Java component) is still possible.
The frontend of the above HTML output is reused from g2html, so the two look the same (except for code highlighting).

1. First time run: `make jar`.
2. Run Goblint with additional `--html` argument.
2. Run Goblint with additional `--set result g2html` arguments.
3. Run `python3 -m http.server --directory result 8080`
or `npx http-server -c-1 result`.
or `npx http-server -c-1 result`.
4. Inspect results at <http://localhost:8080/index.xml>.

Modern browsers' security settings forbid some file access which is necessary for g2html to work, hence the need for serving the results via Python's `http.server` (or similar).
Expand Down
3 changes: 2 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ Goblint includes analyses for assertions, overflows, deadlocks, etc and can be e
)
(sites
(share lib)
(share conf))
(share conf)
(share xslt))
)

; (map_workspace_root false) ;uncomment to enable breakpoints
2 changes: 1 addition & 1 deletion make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ rule() {
}
;; setup)
echo "Make sure you have the following installed: opam >= 2.0.0, git, patch, m4, autoconf, libgmp-dev, libmpfr-dev, pkg-config"
echo "For the --html output you also need: javac, ant, dot (graphviz)"
echo "For the --html output you also need: graphviz and python3-pygments (optional)"
echo "For running the regression tests you also need: ruby, gem, curl, and the `os` gem"
echo "For reference see ./Dockerfile or ./scripts/travis-ci.sh"
opam_setup
Expand Down
4 changes: 2 additions & 2 deletions src/common/framework/cfgTools.ml
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,12 @@ let sprint_fundec_html_dot (module Cfg : CfgBidir) live fd =
fprint_fundec_html_dot (module Cfg) live fd Format.str_formatter;
Format.flush_str_formatter ()

let dead_code_cfg (module FileCfg: MyCFG.FileCfg) live =
let dead_code_cfg ~path (module FileCfg: MyCFG.FileCfg) live =
iterGlobals FileCfg.file (fun glob ->
match glob with
| GFun (fd,loc) ->
(* ignore (Printf.printf "fun: %s\n" fd.svar.vname); *)
let base_dir = GobSys.mkdir_or_exists_absolute (Fpath.v "cfgs") in
let base_dir = GobSys.mkdir_or_exists_absolute path in
let c_file_name = Str.global_substitute (Str.regexp Filename.dir_sep) (fun _ -> "%2F") loc.file in
let dot_file_name = fd.svar.vname^".dot" in
let file_dir = GobSys.mkdir_or_exists_absolute Fpath.(base_dir / c_file_name) in
Expand Down
8 changes: 1 addition & 7 deletions src/config/options.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"description":
"Result style: none, fast_xml, json, pretty, pretty-deterministic, json-messages, sarif.",
"type": "string",
"enum": ["none", "fast_xml", "json", "pretty", "pretty-deterministic", "json-messages", "sarif"],
"enum": ["none", "fast_xml", "g2html", "xslt", "json", "pretty", "pretty-deterministic", "json-messages", "sarif"],
"default": "none"
},
"solver": {
Expand Down Expand Up @@ -117,12 +117,6 @@
"enum": ["auto", "always", "never"],
"default": "auto"
},
"g2html": {
"title": "g2html",
"description": "Run g2html.jar on the generated xml.",
"type": "boolean",
"default": false
},
"save_run": {
"title": "save_run",
"description":
Expand Down
172 changes: 15 additions & 157 deletions src/framework/analysisResult.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(** Analysis result output. *)
(** Analysis results. *)

open GoblintCil
open Pretty
Expand Down Expand Up @@ -32,164 +32,22 @@ sig
val result_name: string
end

module Result (Range: Printable.S) (C: ResultConf) =
struct
include BatHashtbl.Make (ResultNode)
type nonrec t = Range.t t (* specialize polymorphic type for Range values *)

let pretty () mapping =
let f key st dok =
dok ++ dprintf "%a ->@? @[%a@]\n" ResultNode.pretty key Range.pretty st
in
let content () = fold f mapping nil in
let defline () = dprintf "OTHERS -> Not available\n" in
dprintf "@[Mapping {\n @[%t%t@]}@]" content defline

let pretty_deterministic () mapping =
let bindings =
to_list mapping
|> List.sort [%ord: ResultNode.t * Range.t]
in
let f dok (key, st) =
dok ++ dprintf "%a ->@? @[%a@]\n" ResultNode.pretty key Range.pretty st
in
let content () = List.fold_left f nil bindings in
let defline () = dprintf "OTHERS -> Not available\n" in
dprintf "@[Mapping {\n @[%t%t@]}@]" content defline
module type Result =
sig
include ResultConf
module Range: Printable.S
module H: BatHashtbl.S with type key := ResultNode.t
include BatHashtbl.S with type 'a t := 'a H.t and type key := ResultNode.t
type t = Range.t H.t
end

module Result (Range: Printable.S) (C: ResultConf): Result with module Range = Range =
struct
include C

let printXml f xs =
let print_one n v =
(* Not using Node.location here to have updated locations in incremental analysis.
See: https://github.com/goblint/analyzer/issues/290#issuecomment-881258091. *)
let loc = UpdateCil.getLoc n in
BatPrintf.fprintf f "<call id=\"%s\" file=\"%s\" line=\"%d\" order=\"%d\" column=\"%d\" endLine=\"%d\" endColumn=\"%d\" synthetic=\"%B\">\n" (Node.show_id n) loc.file loc.line loc.byte loc.column loc.endLine loc.endColumn loc.synthetic;
BatPrintf.fprintf f "%a</call>\n" Range.printXml v
in
iter print_one xs

let printJson f xs =
let print_one n v =
(* Not using Node.location here to have updated locations in incremental analysis.
See: https://github.com/goblint/analyzer/issues/290#issuecomment-881258091. *)
let loc = UpdateCil.getLoc n in
BatPrintf.fprintf f "{\n\"id\": \"%s\", \"file\": \"%s\", \"line\": \"%d\", \"byte\": \"%d\", \"column\": \"%d\", \"states\": %s\n},\n" (Node.show_id n) loc.file loc.line loc.byte loc.column (Yojson.Safe.to_string (Range.to_yojson v))
in
iter print_one xs

let printXmlWarning f () =
let one_text f Messages.Piece.{loc; text = m; _} =
match loc with
| Some loc ->
let l = Messages.Location.to_cil loc in
BatPrintf.fprintf f "\n<text file=\"%s\" line=\"%d\" column=\"%d\">%s</text>" l.file l.line l.column (XmlUtil.escape m)
| None ->
() (* TODO: not outputting warning without location *)
in
let one_w f (m: Messages.Message.t) = match m.multipiece with
| Single piece -> one_text f piece
| Group {group_text = n; pieces = e; group_loc} ->
let group_loc_text = match group_loc with
| None -> ""
| Some group_loc -> GobPretty.sprintf " (%a)" CilType.Location.pretty (Messages.Location.to_cil group_loc)
in
BatPrintf.fprintf f "<group name=\"%s%s\">%a</group>\n" n group_loc_text (BatList.print ~first:"" ~last:"" ~sep:"" one_text) e
in
let one_w f x = BatPrintf.fprintf f "\n<warning>%a</warning>" one_w x in
List.iter (one_w f) !Messages.Table.messages_list

let output table gtable gtfxml (file: file) =
let out = Messages.get_out result_name !Messages.out in
match get_string "result" with
| "pretty" -> ignore (fprintf out "%a\n" pretty (Lazy.force table))
| "pretty-deterministic" -> ignore (fprintf out "%a\n" pretty_deterministic (Lazy.force table))
| "fast_xml" ->
let module SH = BatHashtbl.Make (Basetype.RawStrings) in
let file2funs = SH.create 100 in
let funs2node = SH.create 100 in
iter (fun n _ -> SH.add funs2node (Node.find_fundec n).svar.vname n) (Lazy.force table);
iterGlobals file (function
| GFun (fd,loc) -> SH.add file2funs loc.file fd.svar.vname
| _ -> ()
);
let p_node f n = BatPrintf.fprintf f "%s" (Node.show_id n) in
let p_nodes f xs =
List.iter (BatPrintf.fprintf f "<node name=\"%a\"/>\n" p_node) xs
in
let p_funs f xs =
let one_fun n =
BatPrintf.fprintf f "<function name=\"%s\">\n%a</function>\n" n p_nodes (SH.find_all funs2node n)
in
List.iter one_fun xs
in
let write_file f fn =
Messages.xml_file_name := fn;
Logs.info "Writing xml to temp. file: %s" fn;
BatPrintf.fprintf f "<run>";
BatPrintf.fprintf f "<parameters>%s</parameters>" GobSys.command_line;
BatPrintf.fprintf f "<statistics>";
let timing_ppf = BatFormat.formatter_of_out_channel f in
Timing.Default.print timing_ppf;
Format.pp_print_flush timing_ppf ();
BatPrintf.fprintf f "</statistics>";
BatPrintf.fprintf f "<result>\n";
BatEnum.iter (fun b -> BatPrintf.fprintf f "<file name=\"%s\" path=\"%s\">\n%a</file>\n" (Filename.basename b) b p_funs (SH.find_all file2funs b)) (BatEnum.uniq @@ SH.keys file2funs); (* nosemgrep: batenum-module *)
BatPrintf.fprintf f "%a" printXml (Lazy.force table);
gtfxml f gtable;
printXmlWarning f ();
BatPrintf.fprintf f "</result></run>\n";
BatPrintf.fprintf f "%!"
in
if get_bool "g2html" then
BatFile.with_temporary_out ~mode:[`create;`text;`delete_on_exit] write_file
else
let f = BatIO.output_channel out in
write_file f (get_string "outfile")
| "json" ->
let open BatPrintf in
let module SH = BatHashtbl.Make (Basetype.RawStrings) in
let file2funs = SH.create 100 in
let funs2node = SH.create 100 in
iter (fun n _ -> SH.add funs2node (Node.find_fundec n).svar.vname n) (Lazy.force table);
iterGlobals file (function
| GFun (fd,loc) -> SH.add file2funs loc.file fd.svar.vname
| _ -> ()
);
let p_enum p f xs = BatEnum.print ~first:"[\n " ~last:"\n]" ~sep:",\n " p f xs in (* nosemgrep: batenum-module *)
let p_list p f xs = BatList.print ~first:"[\n " ~last:"\n]" ~sep:",\n " p f xs in
(*let p_kv f (k,p,v) = fprintf f "\"%s\": %a" k p v in*)
(*let p_obj f xs = BatList.print ~first:"{\n " ~last:"\n}" ~sep:",\n " p_kv xs in*)
let p_node f n = BatPrintf.fprintf f "\"%s\"" (Node.show_id n) in
let p_fun f x = fprintf f "{\n \"name\": \"%s\",\n \"nodes\": %a\n}" x (p_list p_node) (SH.find_all funs2node x) in
(*let p_fun f x = p_obj f [ "name", BatString.print, x; "nodes", p_list p_node, SH.find_all funs2node x ] in*)
let p_file f x = fprintf f "{\n \"name\": \"%s\",\n \"path\": \"%s\",\n \"functions\": %a\n}" (Filename.basename x) x (p_list p_fun) (SH.find_all file2funs x) in
let write_file f fn =
Logs.info "Writing json to temp. file: %s" fn;
fprintf f "{\n \"parameters\": \"%s\",\n " GobSys.command_line;
fprintf f "\"files\": %a,\n " (p_enum p_file) (SH.keys file2funs);
fprintf f "\"results\": [\n %a\n]\n" printJson (Lazy.force table);
(*gtfxml f gtable;*)
(*printXmlWarning f ();*)
fprintf f "}\n";
in
if get_bool "g2html" then
BatFile.with_temporary_out ~mode:[`create;`text;`delete_on_exit] write_file
else
let f = BatIO.output_channel out in
write_file f (get_string "outfile")
| "sarif" ->
Logs.result "Writing Sarif to file: %s" (get_string "outfile");
Yojson.Safe.to_channel ~std:true out (Sarif.to_yojson (List.rev !Messages.Table.messages_list));
| "json-messages" ->
let json = `Assoc [
("files", Preprocessor.dependencies_to_yojson ());
("messages", Messages.Table.to_yojson ());
]
in
Yojson.Safe.to_channel ~std:true out json
| "none" -> ()
| s -> failwith @@ "Unsupported value for option `result`: "^s
module Range = Range
module H = BatHashtbl.Make (ResultNode)
include H
type t = Range.t H.t
end

module ResultType2 (S: Analyses.Spec) =
Expand Down
97 changes: 97 additions & 0 deletions src/framework/analysisResultOutput.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
(** Analysis result output. *)

open GoblintCil
open Pretty
open GobConfig
open AnalysisResult

module Make (Result: Result) =
struct
open Result

let pretty () mapping =
let f key st dok =
dok ++ dprintf "%a ->@? @[%a@]\n" ResultNode.pretty key Range.pretty st
in
let content () = fold f mapping nil in
let defline () = dprintf "OTHERS -> Not available\n" in
dprintf "@[Mapping {\n @[%t%t@]}@]" content defline

let pretty_deterministic () mapping =
let bindings =
to_list mapping
|> List.sort [%ord: ResultNode.t * Range.t]
in
let f dok (key, st) =
dok ++ dprintf "%a ->@? @[%a@]\n" ResultNode.pretty key Range.pretty st
in
let content () = List.fold_left f nil bindings in
let defline () = dprintf "OTHERS -> Not available\n" in
dprintf "@[Mapping {\n @[%t%t@]}@]" content defline


let printJson f xs =
let print_one n v =
(* Not using Node.location here to have updated locations in incremental analysis.
See: https://github.com/goblint/analyzer/issues/290#issuecomment-881258091. *)
let loc = UpdateCil.getLoc n in
BatPrintf.fprintf f "{\n\"id\": \"%s\", \"file\": \"%s\", \"line\": \"%d\", \"byte\": \"%d\", \"column\": \"%d\", \"states\": %s\n},\n" (Node.show_id n) loc.file loc.line loc.byte loc.column (Yojson.Safe.to_string (Range.to_yojson v))
in
iter print_one xs


let output table live gtable gtfxml (module FileCfg: MyCFG.FileCfg) =
let file = FileCfg.file in
let out = Messages.get_out result_name !Messages.out in
match get_string "result" with
| "pretty" -> ignore (fprintf out "%a\n" pretty (Lazy.force table))
| "pretty-deterministic" -> ignore (fprintf out "%a\n" pretty_deterministic (Lazy.force table))
| "fast_xml"
| "g2html" ->
let module Output = XsltResultOutput.Make (Result) in
Output.output table live gtable gtfxml (module FileCfg)
| "xslt" ->
let module Output = XsltResultOutput.Make2 (Result) in
Output.output table live gtable gtfxml (module FileCfg)
| "json" ->
let open BatPrintf in
let module SH = BatHashtbl.Make (Basetype.RawStrings) in
let file2funs = SH.create 100 in
let funs2node = SH.create 100 in
iter (fun n _ -> SH.add funs2node (Node.find_fundec n).svar.vname n) (Lazy.force table);
iterGlobals file (function
| GFun (fd,loc) -> SH.add file2funs loc.file fd.svar.vname
| _ -> ()
);
let p_enum p f xs = BatEnum.print ~first:"[\n " ~last:"\n]" ~sep:",\n " p f xs in (* nosemgrep: batenum-module *)
let p_list p f xs = BatList.print ~first:"[\n " ~last:"\n]" ~sep:",\n " p f xs in
(*let p_kv f (k,p,v) = fprintf f "\"%s\": %a" k p v in*)
(*let p_obj f xs = BatList.print ~first:"{\n " ~last:"\n}" ~sep:",\n " p_kv xs in*)
let p_node f n = BatPrintf.fprintf f "\"%s\"" (Node.show_id n) in
let p_fun f x = fprintf f "{\n \"name\": \"%s\",\n \"nodes\": %a\n}" x (p_list p_node) (SH.find_all funs2node x) in
(*let p_fun f x = p_obj f [ "name", BatString.print, x; "nodes", p_list p_node, SH.find_all funs2node x ] in*)
let p_file f x = fprintf f "{\n \"name\": \"%s\",\n \"path\": \"%s\",\n \"functions\": %a\n}" (Filename.basename x) x (p_list p_fun) (SH.find_all file2funs x) in
let write_file f fn =
Logs.info "Writing json to temp. file: %s" fn;
fprintf f "{\n \"parameters\": \"%s\",\n " GobSys.command_line;
fprintf f "\"files\": %a,\n " (p_enum p_file) (SH.keys file2funs);
fprintf f "\"results\": [\n %a\n]\n" printJson (Lazy.force table);
(*gtfxml f gtable;*)
(*printXmlWarning f ();*)
fprintf f "}\n";
in
let f = BatIO.output_channel out in
write_file f (get_string "outfile")
| "sarif" ->
Logs.result "Writing Sarif to file: %s" (get_string "outfile");
Yojson.Safe.to_channel ~std:true out (Sarif.to_yojson (List.rev !Messages.Table.messages_list));
| "json-messages" ->
let json = `Assoc [
("files", Preprocessor.dependencies_to_yojson ());
("messages", Messages.Table.to_yojson ());
]
in
Yojson.Safe.to_channel ~std:true out json
| "none" -> ()
| s -> failwith @@ "Unsupported value for option `result`: "^s
end
5 changes: 3 additions & 2 deletions src/framework/control.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ struct
module LT = SetDomain.HeadlessSet (RT)
(* Analysis result structure---a hashtable from program points to [LT] *)
module Result = AnalysisResult.Result (LT) (struct let result_name = "analysis" end)
module ResultOutput = AnalysisResultOutput.Make (Result)

module Query = ResultQuery.Query (SpecSys)

Expand Down Expand Up @@ -753,7 +754,7 @@ struct
in

if get_bool "exp.cfgdot" then
CfgTools.dead_code_cfg (module FileCfg) liveness;
CfgTools.dead_code_cfg ~path:(Fpath.v "cfgs") (module FileCfg) liveness;

let warn_global g v =
(* Logs.debug "warn_global %a %a" EQSys.GVar.pretty_trace g EQSys.G.pretty v; *)
Expand Down Expand Up @@ -829,7 +830,7 @@ struct
if get_string "result" <> "none" then Logs.debug "Generating output: %s" (get_string "result");

Messages.finalize ();
Timing.wrap "result output" (Result.output (lazy local_xml) gh make_global_fast_xml) file
Timing.wrap "result output" (ResultOutput.output (lazy local_xml) liveness gh make_global_fast_xml) (module FileCfg)
end

(* This function was originally a part of the [AnalyzeCFG] module, but
Expand Down
Loading
Loading