[debug] new command

Summary:
New `debug` command takes over from `explore` the `--procedures`, `--source-files` functionality and adds `--global-tenv` for printing the global type environment.

Also, uncrustify printing of type environments.

Reviewed By: jvillard

Differential Revision: D22284807

fbshipit-source-id: 9c6fb0c7a
master
Nikos Gorogiannis 4 years ago committed by Facebook GitHub Bot
parent 727cc8ce6d
commit ba2bad25aa

@ -54,6 +54,7 @@ INFER_COMMANDS = \
infer-analyze \ infer-analyze \
infer-capture \ infer-capture \
infer-compile \ infer-compile \
infer-debug \
infer-explore \ infer-explore \
infer-help \ infer-help \
infer-report \ infer-report \

@ -0,0 +1,122 @@
NAME
infer-debug - print internal infer data structures
SYNOPSIS
infer debug --global-tenv
infer debug --procedures [options]
infer debug --source-files [options]
DESCRIPTION
If --procedures is passed, print information about each procedures
captured by infer.
If --source-files is passed, print information about captured source
files.
If --global-tenv is passed, print the global type environment (if
any).
At least one of the above options must be passed.
OPTIONS
--help
Show this manual
--help-format { auto | groff | pager | plain }
Show this help in the specified format. auto sets the format to
plain if the environment variable TERM is "dumb" or undefined, and
to pager otherwise.
--help-full
Show this manual with all internal options in the INTERNAL OPTIONS
section
DEBUG GLOBAL TYPE ENVIRONMENT
--global-tenv
Activates: Print the global type environment. (Conversely:
--no-global-tenv)
DEBUG PROCEDURES
--procedures
Activates: Print functions and methods discovered by infer
(Conversely: --no-procedures)
--procedures-attributes
Activates: Print the attributes of each procedure in the output of
--procedures (Conversely: --no-procedures-attributes)
--no-procedures-definedness
Deactivates: Include procedures definedness in the output of
--procedures, i.e. whether the procedure definition was found, or
only the procedure declaration, or the procedure is an
auto-generated Objective-C accessor (Conversely:
--procedures-definedness)
--procedures-filter filter
With --procedures, only print functions and methods (procedures)
matching the specified filter. A procedure filter is of the form
path_pattern:procedure_name. Patterns are interpreted as OCaml Str
regular expressions. For instance, to keep only methods named
"foo", one can use the filter ".*:foo", or "foo" for short.
--procedures-name
Activates: Include procedures names in the output of --procedures
(Conversely: --no-procedures-name)
--no-procedures-source-file
Deactivates: Include the source file in which the procedure
definition or declaration was found in the output of --procedures
(Conversely: --procedures-source-file)
--procedures-summary
Activates: Print the summaries of each procedure in the output of
--procedures (Conversely: --no-procedures-summary)
DEBUG SOURCE FILES
--source-files
Activates: Print source files discovered by infer (Conversely:
--no-source-files)
--source-files-cfg
Activates: Output a dotty file in infer-out/captured for each
source file in the output of --source-files (Conversely:
--no-source-files-cfg)
--source-files-filter filter
With --source-files, only print source files matching the
specified filter. The filter is a pattern that should match the
file path. Patterns are interpreted as OCaml Str regular
expressions.
--source-files-freshly-captured
Activates: Print whether the source file has been captured in the
most recent capture phase in the output of --source-files.
(Conversely: --no-source-files-freshly-captured)
--source-files-procedure-names
Activates: Print the names of procedure of each source file in the
output of --source-files (Conversely:
--no-source-files-procedure-names)
--source-files-type-environment
Activates: Print the type environment of each source file in the
output of --source-files (Conversely:
--no-source-files-type-environment)
ENVIRONMENT
INFER_ARGS, INFERCONFIG, INFER_STRICT_MODE
See the ENVIRONMENT section in the manual of infer(1).
FILES
.inferconfig
See the FILES section in the manual of infer(1).
SEE ALSO
infer-explore(1), infer-report(1)

@ -3,20 +3,12 @@ NAME
SYNOPSIS SYNOPSIS
infer explore [options] infer explore [options]
infer explore --procedures [options]
infer explore --source-files [options]
DESCRIPTION DESCRIPTION
If --procedures is passed, print information about each procedure Show the list of bugs on the console and explore symbolic program
captured by infer. traces emitted by infer to explain a report. Can also generate an HTML
report from a JSON report.
If --source-files is passed, print information about captured source
files.
Otherwise, show the list of bugs on the console and explore symbolic
program traces emitted by infer to explain a report. Can also generate
an HTML report from a JSON report.
@ -50,71 +42,6 @@ EXPLORE BUGS
--no-source-preview --no-source-preview
Deactivates: print code excerpts around trace elements Deactivates: print code excerpts around trace elements
(Conversely: --source-preview) (Conversely: --source-preview)
EXPLORE PROCEDURES
--procedures
Activates: Print functions and methods discovered by infer
(Conversely: --no-procedures)
--procedures-attributes
Activates: Print the attributes of each procedure in the output of
--procedures (Conversely: --no-procedures-attributes)
--no-procedures-definedness
Deactivates: Include procedures definedness in the output of
--procedures, i.e. whether the procedure definition was found, or
only the procedure declaration, or the procedure is an
auto-generated Objective-C accessor (Conversely:
--procedures-definedness)
--procedures-filter filter
With --procedures, only print functions and methods (procedures)
matching the specified filter. A procedure filter is of the form
path_pattern:procedure_name. Patterns are interpreted as OCaml Str
regular expressions. For instance, to keep only methods named
"foo", one can use the filter ".*:foo", or "foo" for short.
--procedures-name
Activates: Include procedures names in the output of --procedures
(Conversely: --no-procedures-name)
--no-procedures-source-file
Deactivates: Include the source file in which the procedure
definition or declaration was found in the output of --procedures
(Conversely: --procedures-source-file)
--procedures-summary
Activates: Print the summaries of each procedure in the output of
--procedures (Conversely: --no-procedures-summary)
EXPLORE SOURCE FILES
--source-files
Activates: Print source files discovered by infer (Conversely:
--no-source-files)
--source-files-cfg
Activates: Output a dotty file in infer-out/captured for each
source file in the output of --source-files (Conversely:
--no-source-files-cfg)
--source-files-filter filter
With --source-files, only print source files matching the
specified filter. The filter is a pattern that should match the
file path. Patterns are interpreted as OCaml Str regular
expressions.
--source-files-freshly-captured
Activates: Print whether the source file has been captured in the
most recent capture phase in the output of --source-files.
(Conversely: --no-source-files-freshly-captured)
--source-files-procedure-names
Activates: Print the names of procedure of each source file in the
output of --source-files (Conversely:
--no-source-files-procedure-names)
--source-files-type-environment
Activates: Print the type environment of each source file in the
output of --source-files (Conversely:
--no-source-files-type-environment)
ENVIRONMENT ENVIRONMENT

@ -582,13 +582,17 @@ OPTIONS
--generated-classes path --generated-classes path
Specify where to load the generated class files See also infer-capture(1). Specify where to load the generated class files See also infer-capture(1).
--global-tenv
Activates: Print the global type environment. (Conversely:
--no-global-tenv) See also infer-debug(1).
--headers --headers
Activates: Analyze code in header files (Conversely: --no-headers) Activates: Analyze code in header files (Conversely: --no-headers)
See also infer-capture(1). See also infer-capture(1).
--help --help
Show this manual See also infer-analyze(1), infer-capture(1), infer-compile(1), Show this manual See also infer-analyze(1), infer-capture(1), infer-compile(1),
infer-explore(1), infer-help(1), infer-report(1), infer-debug(1), infer-explore(1), infer-help(1), infer-report(1),
infer-reportdiff(1), and infer-run(1). infer-reportdiff(1), and infer-run(1).
--help-checker +checker-id --help-checker +checker-id
@ -599,13 +603,13 @@ OPTIONS
Show this help in the specified format. auto sets the format to Show this help in the specified format. auto sets the format to
plain if the environment variable TERM is "dumb" or undefined, and plain if the environment variable TERM is "dumb" or undefined, and
to pager otherwise. See also infer-analyze(1), infer-capture(1), infer-compile(1), to pager otherwise. See also infer-analyze(1), infer-capture(1), infer-compile(1),
infer-explore(1), infer-help(1), infer-report(1), infer-debug(1), infer-explore(1), infer-help(1), infer-report(1),
infer-reportdiff(1), and infer-run(1). infer-reportdiff(1), and infer-run(1).
--help-full --help-full
Show this manual with all internal options in the INTERNAL OPTIONS Show this manual with all internal options in the INTERNAL OPTIONS
section See also infer-analyze(1), infer-capture(1), infer-compile(1), section See also infer-analyze(1), infer-capture(1), infer-compile(1),
infer-explore(1), infer-help(1), infer-report(1), infer-debug(1), infer-explore(1), infer-help(1), infer-report(1),
infer-reportdiff(1), and infer-run(1). infer-reportdiff(1), and infer-run(1).
--help-issue-type +UNIQUE_ID --help-issue-type +UNIQUE_ID
@ -813,19 +817,19 @@ OPTIONS
--procedures --procedures
Activates: Print functions and methods discovered by infer Activates: Print functions and methods discovered by infer
(Conversely: --no-procedures) See also infer-explore(1). (Conversely: --no-procedures) See also infer-debug(1).
--procedures-attributes --procedures-attributes
Activates: Print the attributes of each procedure in the output of Activates: Print the attributes of each procedure in the output of
--procedures (Conversely: --no-procedures-attributes) --procedures (Conversely: --no-procedures-attributes)
See also infer-explore(1). See also infer-debug(1).
--no-procedures-definedness --no-procedures-definedness
Deactivates: Include procedures definedness in the output of Deactivates: Include procedures definedness in the output of
--procedures, i.e. whether the procedure definition was found, or --procedures, i.e. whether the procedure definition was found, or
only the procedure declaration, or the procedure is an only the procedure declaration, or the procedure is an
auto-generated Objective-C accessor (Conversely: auto-generated Objective-C accessor (Conversely:
--procedures-definedness) See also infer-explore(1). --procedures-definedness) See also infer-debug(1).
--procedures-filter filter --procedures-filter filter
With --procedures, only print functions and methods (procedures) With --procedures, only print functions and methods (procedures)
@ -833,20 +837,20 @@ OPTIONS
path_pattern:procedure_name. Patterns are interpreted as OCaml Str path_pattern:procedure_name. Patterns are interpreted as OCaml Str
regular expressions. For instance, to keep only methods named regular expressions. For instance, to keep only methods named
"foo", one can use the filter ".*:foo", or "foo" for short. "foo", one can use the filter ".*:foo", or "foo" for short.
See also infer-explore(1). See also infer-debug(1).
--procedures-name --procedures-name
Activates: Include procedures names in the output of --procedures Activates: Include procedures names in the output of --procedures
(Conversely: --no-procedures-name) See also infer-explore(1). (Conversely: --no-procedures-name) See also infer-debug(1).
--no-procedures-source-file --no-procedures-source-file
Deactivates: Include the source file in which the procedure Deactivates: Include the source file in which the procedure
definition or declaration was found in the output of --procedures definition or declaration was found in the output of --procedures
(Conversely: --procedures-source-file) See also infer-explore(1). (Conversely: --procedures-source-file) See also infer-debug(1).
--procedures-summary --procedures-summary
Activates: Print the summaries of each procedure in the output of Activates: Print the summaries of each procedure in the output of
--procedures (Conversely: --no-procedures-summary) See also infer-explore(1). --procedures (Conversely: --no-procedures-summary) See also infer-debug(1).
--no-progress-bar,-P --no-progress-bar,-P
Deactivates: Show a progress bar (Conversely: --progress-bar | -p) Deactivates: Show a progress bar (Conversely: --progress-bar | -p)
@ -1043,33 +1047,33 @@ OPTIONS
--source-files --source-files
Activates: Print source files discovered by infer (Conversely: Activates: Print source files discovered by infer (Conversely:
--no-source-files) See also infer-explore(1). --no-source-files) See also infer-debug(1).
--source-files-cfg --source-files-cfg
Activates: Output a dotty file in infer-out/captured for each Activates: Output a dotty file in infer-out/captured for each
source file in the output of --source-files (Conversely: source file in the output of --source-files (Conversely:
--no-source-files-cfg) See also infer-explore(1). --no-source-files-cfg) See also infer-debug(1).
--source-files-filter filter --source-files-filter filter
With --source-files, only print source files matching the With --source-files, only print source files matching the
specified filter. The filter is a pattern that should match the specified filter. The filter is a pattern that should match the
file path. Patterns are interpreted as OCaml Str regular file path. Patterns are interpreted as OCaml Str regular
expressions. See also infer-explore(1). expressions. See also infer-debug(1).
--source-files-freshly-captured --source-files-freshly-captured
Activates: Print whether the source file has been captured in the Activates: Print whether the source file has been captured in the
most recent capture phase in the output of --source-files. most recent capture phase in the output of --source-files.
(Conversely: --no-source-files-freshly-captured) See also infer-explore(1). (Conversely: --no-source-files-freshly-captured) See also infer-debug(1).
--source-files-procedure-names --source-files-procedure-names
Activates: Print the names of procedure of each source file in the Activates: Print the names of procedure of each source file in the
output of --source-files (Conversely: output of --source-files (Conversely:
--no-source-files-procedure-names) See also infer-explore(1). --no-source-files-procedure-names) See also infer-debug(1).
--source-files-type-environment --source-files-type-environment
Activates: Print the type environment of each source file in the Activates: Print the type environment of each source file in the
output of --source-files (Conversely: output of --source-files (Conversely:
--no-source-files-type-environment) See also infer-explore(1). --no-source-files-type-environment) See also infer-debug(1).
--no-source-preview --no-source-preview
Deactivates: print code excerpts around trace elements Deactivates: print code excerpts around trace elements
@ -1960,7 +1964,7 @@ FILES
SEE ALSO SEE ALSO
infer-analyze(1), infer-capture(1), infer-compile(1), infer-analyze(1), infer-capture(1), infer-compile(1), infer-debug(1),
infer-explore(1), infer-help(1), infer-report(1), infer-reportdiff(1), infer-explore(1), infer-help(1), infer-report(1), infer-reportdiff(1),
infer-run(1) infer-run(1)

@ -582,13 +582,17 @@ OPTIONS
--generated-classes path --generated-classes path
Specify where to load the generated class files See also infer-capture(1). Specify where to load the generated class files See also infer-capture(1).
--global-tenv
Activates: Print the global type environment. (Conversely:
--no-global-tenv) See also infer-debug(1).
--headers --headers
Activates: Analyze code in header files (Conversely: --no-headers) Activates: Analyze code in header files (Conversely: --no-headers)
See also infer-capture(1). See also infer-capture(1).
--help --help
Show this manual See also infer-analyze(1), infer-capture(1), infer-compile(1), Show this manual See also infer-analyze(1), infer-capture(1), infer-compile(1),
infer-explore(1), infer-help(1), infer-report(1), infer-debug(1), infer-explore(1), infer-help(1), infer-report(1),
infer-reportdiff(1), and infer-run(1). infer-reportdiff(1), and infer-run(1).
--help-checker +checker-id --help-checker +checker-id
@ -599,13 +603,13 @@ OPTIONS
Show this help in the specified format. auto sets the format to Show this help in the specified format. auto sets the format to
plain if the environment variable TERM is "dumb" or undefined, and plain if the environment variable TERM is "dumb" or undefined, and
to pager otherwise. See also infer-analyze(1), infer-capture(1), infer-compile(1), to pager otherwise. See also infer-analyze(1), infer-capture(1), infer-compile(1),
infer-explore(1), infer-help(1), infer-report(1), infer-debug(1), infer-explore(1), infer-help(1), infer-report(1),
infer-reportdiff(1), and infer-run(1). infer-reportdiff(1), and infer-run(1).
--help-full --help-full
Show this manual with all internal options in the INTERNAL OPTIONS Show this manual with all internal options in the INTERNAL OPTIONS
section See also infer-analyze(1), infer-capture(1), infer-compile(1), section See also infer-analyze(1), infer-capture(1), infer-compile(1),
infer-explore(1), infer-help(1), infer-report(1), infer-debug(1), infer-explore(1), infer-help(1), infer-report(1),
infer-reportdiff(1), and infer-run(1). infer-reportdiff(1), and infer-run(1).
--help-issue-type +UNIQUE_ID --help-issue-type +UNIQUE_ID
@ -813,19 +817,19 @@ OPTIONS
--procedures --procedures
Activates: Print functions and methods discovered by infer Activates: Print functions and methods discovered by infer
(Conversely: --no-procedures) See also infer-explore(1). (Conversely: --no-procedures) See also infer-debug(1).
--procedures-attributes --procedures-attributes
Activates: Print the attributes of each procedure in the output of Activates: Print the attributes of each procedure in the output of
--procedures (Conversely: --no-procedures-attributes) --procedures (Conversely: --no-procedures-attributes)
See also infer-explore(1). See also infer-debug(1).
--no-procedures-definedness --no-procedures-definedness
Deactivates: Include procedures definedness in the output of Deactivates: Include procedures definedness in the output of
--procedures, i.e. whether the procedure definition was found, or --procedures, i.e. whether the procedure definition was found, or
only the procedure declaration, or the procedure is an only the procedure declaration, or the procedure is an
auto-generated Objective-C accessor (Conversely: auto-generated Objective-C accessor (Conversely:
--procedures-definedness) See also infer-explore(1). --procedures-definedness) See also infer-debug(1).
--procedures-filter filter --procedures-filter filter
With --procedures, only print functions and methods (procedures) With --procedures, only print functions and methods (procedures)
@ -833,20 +837,20 @@ OPTIONS
path_pattern:procedure_name. Patterns are interpreted as OCaml Str path_pattern:procedure_name. Patterns are interpreted as OCaml Str
regular expressions. For instance, to keep only methods named regular expressions. For instance, to keep only methods named
"foo", one can use the filter ".*:foo", or "foo" for short. "foo", one can use the filter ".*:foo", or "foo" for short.
See also infer-explore(1). See also infer-debug(1).
--procedures-name --procedures-name
Activates: Include procedures names in the output of --procedures Activates: Include procedures names in the output of --procedures
(Conversely: --no-procedures-name) See also infer-explore(1). (Conversely: --no-procedures-name) See also infer-debug(1).
--no-procedures-source-file --no-procedures-source-file
Deactivates: Include the source file in which the procedure Deactivates: Include the source file in which the procedure
definition or declaration was found in the output of --procedures definition or declaration was found in the output of --procedures
(Conversely: --procedures-source-file) See also infer-explore(1). (Conversely: --procedures-source-file) See also infer-debug(1).
--procedures-summary --procedures-summary
Activates: Print the summaries of each procedure in the output of Activates: Print the summaries of each procedure in the output of
--procedures (Conversely: --no-procedures-summary) See also infer-explore(1). --procedures (Conversely: --no-procedures-summary) See also infer-debug(1).
--no-progress-bar,-P --no-progress-bar,-P
Deactivates: Show a progress bar (Conversely: --progress-bar | -p) Deactivates: Show a progress bar (Conversely: --progress-bar | -p)
@ -1043,33 +1047,33 @@ OPTIONS
--source-files --source-files
Activates: Print source files discovered by infer (Conversely: Activates: Print source files discovered by infer (Conversely:
--no-source-files) See also infer-explore(1). --no-source-files) See also infer-debug(1).
--source-files-cfg --source-files-cfg
Activates: Output a dotty file in infer-out/captured for each Activates: Output a dotty file in infer-out/captured for each
source file in the output of --source-files (Conversely: source file in the output of --source-files (Conversely:
--no-source-files-cfg) See also infer-explore(1). --no-source-files-cfg) See also infer-debug(1).
--source-files-filter filter --source-files-filter filter
With --source-files, only print source files matching the With --source-files, only print source files matching the
specified filter. The filter is a pattern that should match the specified filter. The filter is a pattern that should match the
file path. Patterns are interpreted as OCaml Str regular file path. Patterns are interpreted as OCaml Str regular
expressions. See also infer-explore(1). expressions. See also infer-debug(1).
--source-files-freshly-captured --source-files-freshly-captured
Activates: Print whether the source file has been captured in the Activates: Print whether the source file has been captured in the
most recent capture phase in the output of --source-files. most recent capture phase in the output of --source-files.
(Conversely: --no-source-files-freshly-captured) See also infer-explore(1). (Conversely: --no-source-files-freshly-captured) See also infer-debug(1).
--source-files-procedure-names --source-files-procedure-names
Activates: Print the names of procedure of each source file in the Activates: Print the names of procedure of each source file in the
output of --source-files (Conversely: output of --source-files (Conversely:
--no-source-files-procedure-names) See also infer-explore(1). --no-source-files-procedure-names) See also infer-debug(1).
--source-files-type-environment --source-files-type-environment
Activates: Print the type environment of each source file in the Activates: Print the type environment of each source file in the
output of --source-files (Conversely: output of --source-files (Conversely:
--no-source-files-type-environment) See also infer-explore(1). --no-source-files-type-environment) See also infer-debug(1).
--no-source-preview --no-source-preview
Deactivates: print code excerpts around trace elements Deactivates: print code excerpts around trace elements
@ -1204,7 +1208,7 @@ FILES
SEE ALSO SEE ALSO
infer-analyze(1), infer-capture(1), infer-compile(1), infer-analyze(1), infer-capture(1), infer-compile(1), infer-debug(1),
infer-explore(1), infer-help(1), infer-report(1), infer-reportdiff(1), infer-explore(1), infer-help(1), infer-report(1), infer-reportdiff(1),
infer-run(1) infer-run(1)

@ -39,30 +39,32 @@ let pp_field pe f (field_name, typ, ann) =
let pp pe name f {fields; supers; methods; exported_objc_methods; annots} = let pp pe name f {fields; supers; methods; exported_objc_methods; annots} =
if Config.debug_mode then let pp_field pe f (field_name, typ, ann) =
(* change false to true to print the details of struct *) F.fprintf f "@;<0 2>%a %a %a" (Typ.pp_full pe) typ Fieldname.pp field_name Annot.Item.pp ann
F.fprintf f in
"%a @\n\ let seq pp fmt = function
\tfields: {%a@\n\ | [] ->
\t}@\n\ ()
\tsupers: {%a@\n\ | lst ->
\t}@\n\ Pp.seq pp fmt lst ;
\tmethods: {%a@\n\ F.pp_print_break fmt 0 0
\t}@\n\ in
\texported_obj_methods: {%a@\n\ F.fprintf f
\t}@\n\ "%a@,\
\tannots: {%a@\n\ @[<v>fields: {@[<v>%a@]}@,\
\t}" supers: {@[<v>%a@]}@,\
Typ.Name.pp name methods: {@[<v>%a@]}@,\
(Pp.seq (pp_field pe)) exported_obj_methods: {@[<v>%a@]}@,\
fields annots: {%a}@]@,"
(Pp.seq (fun f n -> F.fprintf f "@\n\t\t%a" Typ.Name.pp n)) Typ.Name.pp name
supers (seq (pp_field pe))
(Pp.seq (fun f m -> F.fprintf f "@\n\t\t%a" Procname.pp m)) fields
methods (seq (fun f n -> F.fprintf f "@;<0 2>%a" Typ.Name.pp n))
(Pp.seq (fun f m -> F.fprintf f "@\n\t\t%a" Procname.pp m)) supers
exported_objc_methods Annot.Item.pp annots (seq (fun f m -> F.fprintf f "@;<0 2>%a" Procname.pp m))
else Typ.Name.pp f name methods
(seq (fun f m -> F.fprintf f "@;<0 2>%a" Procname.pp m))
exported_objc_methods Annot.Item.pp annots
let internal_mk_struct ?default ?fields ?statics ?methods ?exported_objc_methods ?supers ?annots let internal_mk_struct ?default ?fields ?statics ?methods ?exported_objc_methods ?supers ?annots

@ -18,11 +18,7 @@ module TypenameHashNormalizer = MaximumSharing.ForHashtbl (TypenameHash)
type t = Struct.t TypenameHash.t type t = Struct.t TypenameHash.t
let pp fmt (tenv : t) = let pp fmt (tenv : t) =
TypenameHash.iter TypenameHash.iter (fun name typ -> Format.fprintf fmt "%a@," (Struct.pp Pp.text name) typ) tenv
(fun name typ ->
Format.fprintf fmt "@[<6>NAME: %s@]@," (Typ.Name.to_string name) ;
Format.fprintf fmt "@[<6>TYPE: %a@]@," (Struct.pp Pp.text name) typ )
tenv
(** Create a new type environment. *) (** Create a new type environment. *)

@ -50,13 +50,12 @@ val mk_struct :
val add_field : t -> Typ.Name.t -> Struct.field -> unit val add_field : t -> Typ.Name.t -> Struct.field -> unit
(** Add a field to a given struct in the global type environment. *) (** Add a field to a given struct in the global type environment. *)
val pp : Format.formatter -> t -> unit [@@warning "-32"] val pp : Format.formatter -> t -> unit
(** print a type environment *) (** print a type environment *)
type per_file = Global | FileLocal of t type per_file = Global | FileLocal of t
val pp_per_file : Format.formatter -> per_file -> unit val pp_per_file : Format.formatter -> per_file -> unit
[@@warning "-32"]
(** print per file type environment *) (** print per file type environment *)
val merge : src:t -> dst:t -> unit val merge : src:t -> dst:t -> unit

@ -7,7 +7,7 @@
open Core open Core
(* NOTE: All variants must be also added to [command_to_string] below *) (* NOTE: All variants must be also added to [command_to_string] below *)
type t = Analyze | Capture | Compile | Explore | Help | Report | ReportDiff | Run type t = Analyze | Capture | Compile | Debug | Explore | Help | Report | ReportDiff | Run
[@@deriving compare] [@@deriving compare]
let equal = [%compare.equal: t] let equal = [%compare.equal: t]
@ -16,6 +16,7 @@ let command_to_string =
[ (Analyze, "analyze") [ (Analyze, "analyze")
; (Capture, "capture") ; (Capture, "capture")
; (Compile, "compile") ; (Compile, "compile")
; (Debug, "debug")
; (Explore, "explore") ; (Explore, "explore")
; (Help, "help") ; (Help, "help")
; (Report, "report") ; (Report, "report")

@ -13,6 +13,7 @@ type t =
| Compile | Compile
(** set up the infer environment then run the compilation commands without capturing the (** set up the infer environment then run the compilation commands without capturing the
source files *) source files *)
| Debug (** print information about internal structures *)
| Explore (** explore infer reports *) | Explore (** explore infer reports *)
| Help (** documentation about various aspects of infer *) | Help (** documentation about various aspects of infer *)
| Report (** post-process infer results and reports *) | Report (** post-process infer results and reports *)

@ -116,22 +116,30 @@ let compile =
~see_also:InferCommand.[Capture] ~see_also:InferCommand.[Capture]
let explore = let debug =
mk_command_doc ~title:"Infer Explore" mk_command_doc ~title:"Infer Debug" ~short_description:"print internal infer data structures"
~short_description:"explore the error traces in infer reports"
~synopsis: ~synopsis:
{|$(b,infer) $(b,explore) $(i,[options]) {|$(b,infer) $(b,debug) $(b,--global-tenv)
$(b,infer) $(b,explore) $(b,--procedures) $(i,[options]) $(b,infer) $(b,debug) $(b,--procedures) $(i,[options])
$(b,infer) $(b,explore) $(b,--source-files) $(i,[options])|} $(b,infer) $(b,debug) $(b,--source-files) $(i,[options])|}
~description: ~description:
[ `P [ `P
"If $(b,--procedures) is passed, print information about each procedure captured by \ "If $(b,--procedures) is passed, print information about each procedures captured by \
infer." infer."
; `P "If $(b,--source-files) is passed, print information about captured source files." ; `P "If $(b,--source-files) is passed, print information about captured source files."
; `P ; `P "If $(b,--global-tenv) is passed, print the global type environment (if any)."
"Otherwise, show the list of bugs on the console and explore symbolic program traces \ ; `P "At least one of the above options must be passed." ]
emitted by infer to explain a report. Can also generate an HTML report from a JSON \ ~see_also:InferCommand.[Explore; Report]
report." ]
let explore =
mk_command_doc ~title:"Infer Explore"
~short_description:"explore the error traces in infer reports"
~synopsis:{|$(b,infer) $(b,explore) $(i,[options])|}
~description:
[ `P
"Show the list of bugs on the console and explore symbolic program traces emitted by \
infer to explain a report. Can also generate an HTML report from a JSON report." ]
~see_also:InferCommand.[Report; Run] ~see_also:InferCommand.[Report; Run]
@ -326,6 +334,7 @@ let command_to_data =
[ mk Analyze analyze [ mk Analyze analyze
; mk Capture capture ; mk Capture capture
; mk Compile compile ; mk Compile compile
; mk Debug debug
; mk Explore explore ; mk Explore explore
; mk Help help ; mk Help help
; mk Report report ; mk Report report

@ -139,9 +139,11 @@ let manual_clang_linters = "CLANG LINTERS OPTIONS"
let manual_explore_bugs = "EXPLORE BUGS" let manual_explore_bugs = "EXPLORE BUGS"
let manual_explore_procedures = "EXPLORE PROCEDURES" let manual_debug_procedures = "DEBUG PROCEDURES"
let manual_explore_source_files = "EXPLORE SOURCE FILES" let manual_debug_source_files = "DEBUG SOURCE FILES"
let manual_debug_global_tenv = "DEBUG GLOBAL TYPE ENVIRONMENT"
let manual_generic = Cmdliner.Manpage.s_options let manual_generic = Cmdliner.Manpage.s_options
@ -485,7 +487,7 @@ let () =
match cmd with match cmd with
| Report -> | Report ->
`Add `Add
| Analyze | Capture | Compile | Explore | Help | ReportDiff | Run -> | Analyze | Capture | Compile | Debug | Explore | Help | ReportDiff | Run ->
`Reject `Reject
in in
(* make sure we generate doc for all the commands we know about *) (* make sure we generate doc for all the commands we know about *)
@ -985,7 +987,7 @@ and ( bo_debug
let all_generic_manuals = let all_generic_manuals =
List.filter_map InferCommand.all_commands ~f:(fun (command : InferCommand.t) -> List.filter_map InferCommand.all_commands ~f:(fun (command : InferCommand.t) ->
match command with match command with
| Explore | Help -> | Debug | Explore | Help ->
None None
| (Analyze | Capture | Compile | Report | ReportDiff | Run) as command -> | (Analyze | Capture | Compile | Report | ReportDiff | Run) as command ->
Some (command, manual_generic) ) Some (command, manual_generic) )
@ -1700,6 +1702,11 @@ and _print_log_identifier =
"[DOES NOTHING] Print the unique identifier that is common to all logged events" "[DOES NOTHING] Print the unique identifier that is common to all logged events"
and global_tenv =
CLOpt.mk_bool ~long:"global-tenv" "Print the global type environment."
~in_help:InferCommand.[(Debug, manual_debug_global_tenv)]
and print_using_diff = and print_using_diff =
CLOpt.mk_bool ~deprecated_no:["noprintdiff"] ~long:"print-using-diff" ~default:true CLOpt.mk_bool ~deprecated_no:["noprintdiff"] ~long:"print-using-diff" ~default:true
"Highlight the difference w.r.t. the previous prop when printing symbolic execution debug info" "Highlight the difference w.r.t. the previous prop when printing symbolic execution debug info"
@ -1707,19 +1714,19 @@ and print_using_diff =
and procedures = and procedures =
CLOpt.mk_bool ~long:"procedures" CLOpt.mk_bool ~long:"procedures"
~in_help:InferCommand.[(Explore, manual_explore_procedures)] ~in_help:InferCommand.[(Debug, manual_debug_procedures)]
"Print functions and methods discovered by infer" "Print functions and methods discovered by infer"
and procedures_attributes = and procedures_attributes =
CLOpt.mk_bool ~long:"procedures-attributes" CLOpt.mk_bool ~long:"procedures-attributes"
~in_help:InferCommand.[(Explore, manual_explore_procedures)] ~in_help:InferCommand.[(Debug, manual_debug_procedures)]
"Print the attributes of each procedure in the output of $(b,--procedures)" "Print the attributes of each procedure in the output of $(b,--procedures)"
and procedures_definedness = and procedures_definedness =
CLOpt.mk_bool ~long:"procedures-definedness" ~default:true CLOpt.mk_bool ~long:"procedures-definedness" ~default:true
~in_help:InferCommand.[(Explore, manual_explore_procedures)] ~in_help:InferCommand.[(Debug, manual_debug_procedures)]
"Include procedures definedness in the output of $(b,--procedures), i.e. whether the procedure \ "Include procedures definedness in the output of $(b,--procedures), i.e. whether the procedure \
definition was found, or only the procedure declaration, or the procedure is an \ definition was found, or only the procedure declaration, or the procedure is an \
auto-generated Objective-C accessor" auto-generated Objective-C accessor"
@ -1727,7 +1734,7 @@ and procedures_definedness =
and procedures_filter = and procedures_filter =
CLOpt.mk_string_opt ~long:"procedures-filter" ~meta:"filter" CLOpt.mk_string_opt ~long:"procedures-filter" ~meta:"filter"
~in_help:InferCommand.[(Explore, manual_explore_procedures)] ~in_help:InferCommand.[(Debug, manual_debug_procedures)]
"With $(b,--procedures), only print functions and methods (procedures) matching the specified \ "With $(b,--procedures), only print functions and methods (procedures) matching the specified \
$(i,filter). A procedure filter is of the form $(i,path_pattern:procedure_name). Patterns are \ $(i,filter). A procedure filter is of the form $(i,path_pattern:procedure_name). Patterns are \
interpreted as OCaml Str regular expressions. For instance, to keep only methods named \ interpreted as OCaml Str regular expressions. For instance, to keep only methods named \
@ -1736,20 +1743,20 @@ and procedures_filter =
and procedures_name = and procedures_name =
CLOpt.mk_bool ~long:"procedures-name" CLOpt.mk_bool ~long:"procedures-name"
~in_help:InferCommand.[(Explore, manual_explore_procedures)] ~in_help:InferCommand.[(Debug, manual_debug_procedures)]
"Include procedures names in the output of $(b,--procedures)" "Include procedures names in the output of $(b,--procedures)"
and procedures_source_file = and procedures_source_file =
CLOpt.mk_bool ~long:"procedures-source-file" ~default:true CLOpt.mk_bool ~long:"procedures-source-file" ~default:true
~in_help:InferCommand.[(Explore, manual_explore_procedures)] ~in_help:InferCommand.[(Debug, manual_debug_procedures)]
"Include the source file in which the procedure definition or declaration was found in the \ "Include the source file in which the procedure definition or declaration was found in the \
output of $(b,--procedures)" output of $(b,--procedures)"
and procedures_summary = and procedures_summary =
CLOpt.mk_bool ~long:"procedures-summary" ~default:false CLOpt.mk_bool ~long:"procedures-summary" ~default:false
~in_help:InferCommand.[(Explore, manual_explore_procedures)] ~in_help:InferCommand.[(Debug, manual_debug_procedures)]
"Print the summaries of each procedure in the output of $(b,--procedures)" "Print the summaries of each procedure in the output of $(b,--procedures)"
@ -2077,13 +2084,13 @@ and source_preview =
and source_files = and source_files =
CLOpt.mk_bool ~long:"source-files" CLOpt.mk_bool ~long:"source-files"
~in_help:InferCommand.[(Explore, manual_explore_source_files)] ~in_help:InferCommand.[(Debug, manual_debug_source_files)]
"Print source files discovered by infer" "Print source files discovered by infer"
and source_files_cfg = and source_files_cfg =
CLOpt.mk_bool ~long:"source-files-cfg" CLOpt.mk_bool ~long:"source-files-cfg"
~in_help:InferCommand.[(Explore, manual_explore_source_files)] ~in_help:InferCommand.[(Debug, manual_debug_source_files)]
(Printf.sprintf (Printf.sprintf
"Output a dotty file in %s for each source file in the output of $(b,--source-files)" "Output a dotty file in %s for each source file in the output of $(b,--source-files)"
(ResultsDirEntryName.get_path ~results_dir:"infer-out" Debug)) (ResultsDirEntryName.get_path ~results_dir:"infer-out" Debug))
@ -2091,7 +2098,7 @@ and source_files_cfg =
and source_files_filter = and source_files_filter =
CLOpt.mk_string_opt ~long:"source-files-filter" ~meta:"filter" CLOpt.mk_string_opt ~long:"source-files-filter" ~meta:"filter"
~in_help:InferCommand.[(Explore, manual_explore_source_files)] ~in_help:InferCommand.[(Debug, manual_debug_source_files)]
"With $(b,--source-files), only print source files matching the specified $(i,filter). The \ "With $(b,--source-files), only print source files matching the specified $(i,filter). The \
filter is a pattern that should match the file path. Patterns are interpreted as OCaml Str \ filter is a pattern that should match the file path. Patterns are interpreted as OCaml Str \
regular expressions." regular expressions."
@ -2099,19 +2106,19 @@ and source_files_filter =
and source_files_type_environment = and source_files_type_environment =
CLOpt.mk_bool ~long:"source-files-type-environment" CLOpt.mk_bool ~long:"source-files-type-environment"
~in_help:InferCommand.[(Explore, manual_explore_source_files)] ~in_help:InferCommand.[(Debug, manual_debug_source_files)]
"Print the type environment of each source file in the output of $(b,--source-files)" "Print the type environment of each source file in the output of $(b,--source-files)"
and source_files_procedure_names = and source_files_procedure_names =
CLOpt.mk_bool ~long:"source-files-procedure-names" CLOpt.mk_bool ~long:"source-files-procedure-names"
~in_help:InferCommand.[(Explore, manual_explore_source_files)] ~in_help:InferCommand.[(Debug, manual_debug_source_files)]
"Print the names of procedure of each source file in the output of $(b,--source-files)" "Print the names of procedure of each source file in the output of $(b,--source-files)"
and source_files_freshly_captured = and source_files_freshly_captured =
CLOpt.mk_bool ~long:"source-files-freshly-captured" CLOpt.mk_bool ~long:"source-files-freshly-captured"
~in_help:InferCommand.[(Explore, manual_explore_source_files)] ~in_help:InferCommand.[(Debug, manual_debug_source_files)]
"Print whether the source file has been captured in the most recent capture phase in the \ "Print whether the source file has been captured in the most recent capture phase in the \
output of $(b,--source-files)." output of $(b,--source-files)."
@ -2787,6 +2794,8 @@ and html = !html
and hoisting_report_only_expensive = !hoisting_report_only_expensive and hoisting_report_only_expensive = !hoisting_report_only_expensive
and global_tenv = !global_tenv
and icfg_dotty_outfile = !icfg_dotty_outfile and icfg_dotty_outfile = !icfg_dotty_outfile
and inclusive_cost = !inclusive_cost and inclusive_cost = !inclusive_cost

@ -312,6 +312,8 @@ val hoisting_report_only_expensive : bool
val html : bool val html : bool
val global_tenv : bool
val icfg_dotty_outfile : string option val icfg_dotty_outfile : string option
val infer_is_clang : bool val infer_is_clang : bool

@ -61,11 +61,13 @@ let setup () =
SourceFiles.mark_all_stale () ) SourceFiles.mark_all_stale () )
| Explore -> | Explore ->
ResultsDir.assert_results_dir "please run an infer analysis first" ResultsDir.assert_results_dir "please run an infer analysis first"
| Debug ->
ResultsDir.assert_results_dir "please run an infer analysis or capture first"
| Help -> | Help ->
() ) ; () ) ;
let has_result_dir = let has_result_dir =
match Config.command with match Config.command with
| Analyze | Capture | Compile | Explore | Report | ReportDiff | Run -> | Analyze | Capture | Compile | Debug | Explore | Report | ReportDiff | Run ->
true true
| Help -> | Help ->
false false
@ -209,9 +211,17 @@ let () =
ReportDiff.reportdiff ~current_report:Config.report_current ReportDiff.reportdiff ~current_report:Config.report_current
~previous_report:Config.report_previous ~current_costs:Config.costs_current ~previous_report:Config.report_previous ~current_costs:Config.costs_current
~previous_costs:Config.costs_previous ~previous_costs:Config.costs_previous
| Explore -> ( | Debug when not Config.(global_tenv || procedures || source_files) ->
match (Config.procedures, Config.source_files) with L.die UserError
| true, false -> "Expected at least one of '--procedures', '--source_files', or '--global-tenv'"
| Debug ->
( if Config.global_tenv then
match Tenv.load_global () with
| None ->
L.result "No global type environment was found.@."
| Some tenv ->
L.result "Global type environment:@\n@[<v>%a@]" Tenv.pp tenv ) ;
( if Config.procedures then
let filter = Lazy.force Filtering.procedures_filter in let filter = Lazy.force Filtering.procedures_filter in
if Config.procedures_summary then if Config.procedures_summary then
let pp_summary fmt proc_name = let pp_summary fmt proc_name =
@ -228,8 +238,8 @@ let () =
Config.( Config.(
Procedures.pp_all ~filter ~proc_name:procedures_name ~attr_kind:procedures_definedness Procedures.pp_all ~filter ~proc_name:procedures_name ~attr_kind:procedures_definedness
~source_file:procedures_source_file ~proc_attributes:procedures_attributes) ~source_file:procedures_source_file ~proc_attributes:procedures_attributes)
() () ) ;
| false, true -> if Config.source_files then (
let filter = Lazy.force Filtering.source_files_filter in let filter = Lazy.force Filtering.source_files_filter in
L.result "%a" L.result "%a"
(SourceFiles.pp_all ~filter ~type_environment:Config.source_files_type_environment (SourceFiles.pp_all ~filter ~type_environment:Config.source_files_type_environment
@ -250,18 +260,16 @@ let () =
(* emit the dot file in captured/... *) (* emit the dot file in captured/... *)
DotCfg.emit_frontend_cfg source_file cfgs ) ; DotCfg.emit_frontend_cfg source_file cfgs ) ;
L.result "CFGs written in %s/*/%s@." (ResultsDir.get_path Debug) L.result "CFGs written in %s/*/%s@." (ResultsDir.get_path Debug)
Config.dotty_frontend_output ) Config.dotty_frontend_output ) )
| false, false -> | Explore ->
(* explore bug traces *) if (* explore bug traces *)
if Config.html then Config.html then
TraceBugs.gen_html_report ~report_json:(ResultsDir.get_path ReportJson) TraceBugs.gen_html_report ~report_json:(ResultsDir.get_path ReportJson)
~show_source_context:Config.source_preview ~max_nested_level:Config.max_nesting ~show_source_context:Config.source_preview ~max_nested_level:Config.max_nesting
~report_html_dir:(ResultsDir.get_path ReportHtml) ~report_html_dir:(ResultsDir.get_path ReportHtml)
else else
TraceBugs.explore ~selector_limit:None ~report_json:(ResultsDir.get_path ReportJson) TraceBugs.explore ~selector_limit:None ~report_json:(ResultsDir.get_path ReportJson)
~report_txt:(ResultsDir.get_path ReportText) ~selected:Config.select ~report_txt:(ResultsDir.get_path ReportText) ~selected:Config.select
~show_source_context:Config.source_preview ~max_nested_level:Config.max_nesting ~show_source_context:Config.source_preview ~max_nested_level:Config.max_nesting ) ;
| true, true ->
L.user_error "Options --procedures and --source-files cannot be used together.@\n" ) ) ;
(* to make sure the exitcode=0 case is logged, explicitly invoke exit *) (* to make sure the exitcode=0 case is logged, explicitly invoke exit *)
L.exit 0 L.exit 0

@ -242,7 +242,7 @@ let analyze_and_report ?suppress_console_report ~changed_files mode =
| _ when Config.infer_is_clang || Config.infer_is_javac -> | _ when Config.infer_is_clang || Config.infer_is_javac ->
(* Called from another integration to do capture only. *) (* Called from another integration to do capture only. *)
(false, false) (false, false)
| (Capture | Compile | Explore | Help | Report | ReportDiff), _ -> | (Capture | Compile | Debug | Explore | Help | Report | ReportDiff), _ ->
(false, false) (false, false)
| (Analyze | Run), _ -> | (Analyze | Run), _ ->
(true, true) (true, true)

Loading…
Cancel
Save