Skip to content

Commit d8e20c7

Browse files
committed
CMD: add cmdline option to fail on function analysis failure
1 parent b6f43e4 commit d8e20c7

File tree

6 files changed

+67
-13
lines changed

6 files changed

+67
-13
lines changed

CodeHawk/CHB/bchanalyze/bCHAnalyzeApp.ml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
Copyright (c) 2005-2020 Kestrel Technology LLC
88
Copyright (c) 2020 Henny Sipma
9-
Copyright (c) 2021-2024 Aarno Labs LLC
9+
Copyright (c) 2021-2025 Aarno Labs LLC
1010
1111
Permission is hereby granted, free of charge, to any person obtaining a copy
1212
of this software and associated documentation files (the "Software"), to deal
@@ -184,7 +184,12 @@ let analyze starttime =
184184
faddr#toPretty;
185185
STR ": ";
186186
p]);
187-
failedfunctions := faddr :: !failedfunctions
187+
if system_settings#fail_on_function_failure then
188+
raise
189+
(BCH_failure
190+
(LBLOCK [STR "Function failure of "; faddr#toPretty; STR ": "; p]))
191+
else
192+
failedfunctions := faddr :: !failedfunctions
188193
end in
189194

190195
begin
@@ -414,7 +419,12 @@ let analyze_mips starttime =
414419
faddr#toPretty;
415420
STR ": ";
416421
p]);
417-
failedfunctions := faddr :: !failedfunctions
422+
if system_settings#fail_on_function_failure then
423+
raise
424+
(BCH_failure
425+
(LBLOCK [STR "Function failure of "; faddr#toPretty; STR "; "; p]))
426+
else
427+
failedfunctions := faddr :: !failedfunctions
418428
end in
419429
begin
420430
(if (List.length fns_included) > 0 then
@@ -566,7 +576,12 @@ let analyze_arm starttime =
566576
faddr#toPretty;
567577
STR ": ";
568578
p]);
569-
failedfunctions := faddr :: !failedfunctions
579+
if system_settings#fail_on_function_failure then
580+
raise
581+
(BCH_failure
582+
(LBLOCK [STR "Function failure of "; faddr#toPretty; STR ": "; p]))
583+
else
584+
failedfunctions := faddr :: !failedfunctions
570585
end in
571586
begin
572587
(if (List.length fns_included) > 0 then
@@ -606,9 +621,11 @@ let analyze_arm starttime =
606621
pr_interval_timing [STR "functions analyzed: "; INT !count] 60.0
607622
with
608623
| Failure s -> functionfailure "Failure" faddr (STR s)
609-
| Invalid_argument s -> functionfailure "Invalid argument" faddr (STR s)
624+
| Invalid_argument s ->
625+
functionfailure "Invalid argument" faddr (STR s)
610626
| Internal_error s -> functionfailure "Internal error" faddr (STR s)
611-
| Invocation_error s -> functionfailure "Invocation error" faddr (STR s)
627+
| Invocation_error s ->
628+
functionfailure "Invocation error" faddr (STR s)
612629
| CHFailure p -> functionfailure "CHFailure" faddr p
613630
| BCH_failure p -> functionfailure "BCHFailure" faddr p));
614631
file_metrics#record_runtime ((Unix.gettimeofday ()) -. starttime)

CodeHawk/CHB/bchcmdline/bCHXBinaryAnalyzer.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,14 @@ let show_chif = ref None
119119
let set_chif s = show_chif := Some s
120120

121121
let speclist =
122-
[ ("-version", Arg.Unit (fun () -> ()), "show version information and exit") ;
122+
[ ("-version", Arg.Unit (fun () -> ()), "show version information and exit");
123123
("-gc", Arg.Unit (fun () -> cmd := "gc"),
124-
"show ocaml garbage collector settings and exit") ;
124+
"show ocaml garbage collector settings and exit");
125+
("-fail_on_function_failure",
126+
Arg.Unit (fun () -> system_settings#set_fail_on_function_failure),
127+
"fail immediately if analysis of one of the functions fails");
125128
("-set_vftables",Arg.Unit (fun () -> system_settings#set_vftables),
126-
"declare jumptable targets as funcion entry points") ;
129+
"declare jumptable targets as funcion entry points");
127130
("-extracthex", Arg.Unit (fun () -> cmd := "extracthex"),
128131
"extract executable content from lisphex encoded executable");
129132
("-ssa", Arg.Unit (fun () -> system_settings#set_ssa),
@@ -878,6 +881,7 @@ let main () =
878881
(* function annotations in userdata should be loaded after the header
879882
files are parsed, so types in the function annotations can be resolved.*)
880883
let _ = system_info#initialize_function_annotations in
884+
let _ = pr_timing [STR "function annotations initialized"] in
881885

882886
let index = file_metrics#get_index in
883887
let logcmd = "analyze_" ^ (string_of_int index) in

CodeHawk/CHB/bchlib/bCHFunctionStackframe.ml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,20 @@ object (self)
471471
if (H.find stackslots offset)#is_spill then
472472
()
473473
else
474-
raise (BCH_failure (LBLOCK [STR "Stackslot already taken"]))
474+
let sslot = H.find stackslots offset in
475+
raise
476+
(BCH_failure
477+
(LBLOCK [
478+
STR "Add register spill at address ";
479+
STR iaddr;
480+
STR " for register ";
481+
STR (register_to_string reg);
482+
STR " at offset ";
483+
INT offset;
484+
STR " cannot be completed, because another stackslot ";
485+
STR "at this offset, with name: ";
486+
STR sslot#name;
487+
STR " already exists"]))
475488
else
476489
let ssrec = {
477490
sslot_name = (register_to_string reg) ^ "_spill";
@@ -494,7 +507,20 @@ object (self)
494507
if (H.find stackslots offset)#is_spill then
495508
()
496509
else
497-
raise (BCH_failure (LBLOCK [STR "Stackslot already taken"]))
510+
let sslot = H.find stackslots offset in
511+
raise
512+
(BCH_failure
513+
(LBLOCK [
514+
STR "Add register restore at address ";
515+
STR iaddr;
516+
STR " for register ";
517+
STR (register_to_string reg);
518+
STR " at offset ";
519+
INT offset;
520+
STR " cannot be completed, because another stackslot ";
521+
STR "at this offset, with name: ";
522+
STR sslot#name;
523+
STR " already exists"]))
498524
else
499525
let ssrec = {
500526
sslot_name = (register_to_string reg) ^ "_spill";

CodeHawk/CHB/bchlib/bCHLibTypes.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,7 @@ object
14171417
method enable_sideeffects_on_globals : string list -> unit
14181418
method disable_sideeffects_on_globals: string list -> unit
14191419
method set_no_varinvs: unit
1420+
method set_fail_on_function_failure: unit
14201421
method set_abstract_stackvars_disabled: unit
14211422
method set_apps_dir: string -> unit
14221423
method set_app_summary_jars: string -> unit (* application name *)
@@ -1451,6 +1452,7 @@ object
14511452
method has_thumb: bool
14521453
method use_ssa: bool
14531454
method collect_data: bool
1455+
method fail_on_function_failure: bool
14541456
method generate_varinvs: bool
14551457
method include_arm_extension_registers: bool
14561458
method show_function_timing: bool

CodeHawk/CHB/bchlib/bCHSystemSettings.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,14 @@ object (self)
181181
val mutable ssa = false
182182
val mutable collectdata = false
183183
val mutable generate_varinvs = true
184+
val mutable fail_on_function_failure = false
184185

185186
method set_collect_data = collectdata <- true
186187

188+
method set_fail_on_function_failure = fail_on_function_failure <- true
189+
190+
method fail_on_function_failure = fail_on_function_failure
191+
187192
method set_no_varinvs = generate_varinvs <- false
188193

189194
method collect_data = collectdata

CodeHawk/CHB/bchlib/bCHVersion.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ end
9595

9696

9797
let version = new version_info_t
98-
~version:"0.6.0_20250811"
99-
~date:"2025-08-11"
98+
~version:"0.6.0_20250812"
99+
~date:"2025-08-12"
100100
~licensee: None
101101
~maxfilesize: None
102102
()

0 commit comments

Comments
 (0)