Skip to content

Commit 0a3320a

Browse files
committed
CHB: add error handling
1 parent 24c678f commit 0a3320a

File tree

2 files changed

+54
-34
lines changed

2 files changed

+54
-34
lines changed

CodeHawk/CHB/bchlib/bCHFunctionInfo.ml

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,9 @@ object (self)
11131113
(BCH_failure
11141114
(LBLOCK [STR "No virtual target found for "; v#toPretty]))
11151115

1116-
method get_frozen_variable (v: variable_t) =
1116+
method get_frozen_variable
1117+
(v: variable_t):
1118+
(variable_t * ctxt_iaddress_t * ctxt_iaddress_t) traceresult =
11171119
varmgr#get_frozen_variable v
11181120

11191121
method private get_register_variables =
@@ -1160,10 +1162,13 @@ object (self)
11601162

11611163
method get_stack_parameter_index (v: variable_t): int option =
11621164
if self#is_initial_memory_value v then
1163-
log_tfold
1164-
(log_error "get_stack_parameter_index" "invalid initial value")
1165+
TR.tfold
11651166
~ok:(fun iv -> varmgr#get_stack_parameter_index iv)
1166-
~error:(fun _ -> None)
1167+
~error:(fun e ->
1168+
begin
1169+
log_error_result __FILE__ __LINE__ e;
1170+
None
1171+
end)
11671172
(varmgr#get_initial_memory_value_variable v)
11681173
else
11691174
varmgr#get_stack_parameter_index v
@@ -1190,34 +1195,41 @@ object (self)
11901195
else if self#is_memory_variable v then
11911196
self#get_memvar_offset v
11921197
else
1193-
Error ["get_constant_offsets: " ^ v#getName#getBaseName] in
1194-
log_tfold
1195-
(log_error "get_constant_offsets" "invalid offset or variable")
1198+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1199+
^ "Not a memory variable or initial memory value: "
1200+
^ v#getName#getBaseName] in
1201+
TR.tfold
11961202
~ok:(fun offset ->
11971203
if is_constant_offset offset then
11981204
Some (get_constant_offsets offset)
11991205
else
12001206
None)
1201-
~error:(fun _ -> None)
1207+
~error:(fun e ->
1208+
begin log_error_result __FILE__ __LINE__ e; None end)
12021209
offset_r
12031210

12041211
method get_total_constant_offset (v:variable_t) =
12051212
match self#get_constant_offsets v with
12061213
| Some l -> Some (List.fold_left (fun acc n -> acc#add n) numerical_zero l)
12071214
| _ -> None
12081215

1209-
method get_calltarget_value = varmgr#get_calltarget_value
1216+
method get_calltarget_value (v: variable_t): call_target_t traceresult =
1217+
varmgr#get_calltarget_value v
12101218

1211-
method get_register = varmgr#get_register
1219+
method get_register (v: variable_t): register_t traceresult =
1220+
varmgr#get_register v
12121221

1213-
method get_pointed_to_function_name = varmgr#get_pointed_to_function_name
1222+
method get_pointed_to_function_name (v: variable_t): string traceresult =
1223+
varmgr#get_pointed_to_function_name v
12141224

1215-
method get_call_site = varmgr#get_call_site
1225+
method get_call_site (v: variable_t): ctxt_iaddress_t traceresult =
1226+
varmgr#get_call_site v
12161227

1217-
method get_se_argument_descriptor = varmgr#get_se_argument_descriptor
1228+
method get_se_argument_descriptor (v: variable_t): string traceresult =
1229+
varmgr#get_se_argument_descriptor v
12181230

1219-
method get_global_sideeffect_target_address =
1220-
varmgr#get_global_sideeffect_target_address
1231+
method get_global_sideeffect_target_address (v: variable_t): doubleword_result =
1232+
varmgr#get_global_sideeffect_target_address v
12211233

12221234
method is_global_sideeffect = varmgr#is_global_sideeffect
12231235

@@ -1248,24 +1260,24 @@ object (self)
12481260
if varmgr#has_global_variable_address v then
12491261
varmgr#get_global_variable_address v
12501262
else
1251-
Error [
1252-
"env#get_global_variable_address: "
1253-
^ "no constant numerical offset: "
1254-
^ v#getName#getBaseName]
1263+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1264+
^ "No constant numerical offset: "
1265+
^ v#getName#getBaseName]
12551266
else if varmgr#is_initial_memory_value v then
12561267
tbind
1257-
~msg:("env#get_global_variable_address: invalid initial_memory_value")
1268+
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
12581269
(fun ivar ->
12591270
if varmgr#has_global_variable_address ivar then
12601271
self#get_global_variable_address ivar
12611272
else
1262-
Error ["env#get_global_variable_address: not a constant offset"])
1273+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1274+
^ "Not a constant offset: "
1275+
^ v#getName#getBaseName])
12631276
(varmgr#get_initial_memory_value_variable v)
12641277
else
1265-
Error [
1266-
"env#get_global_variable_address: "
1267-
^ "not a global variable or initial-value global variable: "
1268-
^ v#getName#getBaseName]
1278+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1279+
^ "Not a global variable or initial-value global variable: "
1280+
^ v#getName#getBaseName]
12691281

12701282
method is_volatile_variable (v: variable_t) =
12711283
if varmgr#has_global_variable_address v then
@@ -1463,7 +1475,7 @@ object (self)
14631475
varmgr#get_initial_memory_value_variable v
14641476
else if self#is_initial_register_value v then
14651477
tbind
1466-
~msg:("finfo:get_init_value_variable: " ^ v#getName#getBaseName)
1478+
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": " ^ v#getName#getBaseName)
14671479
(fun iv ->
14681480
match iv with
14691481
| CPURegister r -> Ok (self#mk_cpu_register_variable r)
@@ -1475,14 +1487,14 @@ object (self)
14751487
| PowerGPRegister i -> Ok (self#mk_pwr_gp_register_variable i)
14761488
| PowerSPRegister r -> Ok (self#mk_pwr_sp_register_variable r)
14771489
| _ ->
1478-
Error [
1479-
"finfo:get_init_value_variable: not a cpu/mips/arm/pwr register: "
1480-
^ v#getName#getBaseName])
1490+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1491+
^ "Not a cpu/mips/arm/pwr initial register value: "
1492+
^ v#getName#getBaseName])
14811493
(self#get_initial_register_value_register v)
14821494
else
1483-
Error [
1484-
"finfo:get_init_value_variable: variable is not an initial value: "
1485-
^ v#getName#getBaseName]
1495+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1496+
^ "Variable is not an initial value: "
1497+
^ v#getName#getBaseName]
14861498

14871499
method get_initial_register_value_register
14881500
(v:variable_t): register_t traceresult =
@@ -1498,7 +1510,8 @@ object (self)
14981510
if self#is_symbolic_value v then
14991511
varmgr#get_symbolic_value_expr v
15001512
else
1501-
Error ["finfo:get_symbolic_value_expr: " ^ v#getName#getBaseName]
1513+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1514+
^ "Not a symbolic value expr: " ^ v#getName#getBaseName]
15021515

15031516
method is_in_test_jump_range (v: variable_t) (a: ctxt_iaddress_t) =
15041517
(varmgr#is_in_test_jump_range a v)

CodeHawk/CHB/bchlib/bCHLibTypes.mli

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4037,7 +4037,8 @@ object
40374037
method is_stack_parameter_variable: variable_t -> bool
40384038

40394039
(** Returns the index of the stack parameter variable [var] assuming
4040-
4-byte parameters starting at offset 4 (x86 only).
4040+
4-byte parameters starting at offset 4 (x86 only). The variable may
4041+
either be a stack memory variable or a stack initial memory value.
40414042
40424043
Returns None if the variable is not a stack parameter variable or if
40434044
the variable cannot be found. *)
@@ -4908,6 +4909,12 @@ class type function_environment_int =
49084909

49094910
method is_initial_value: variable_t -> bool
49104911

4912+
(** [get_init_value_variable var] returns the original variable for which
4913+
[var] is the initial value.
4914+
4915+
If [var] is not an initial memory or initial register value an Error is
4916+
returned.
4917+
*)
49114918
method get_init_value_variable: variable_t -> variable_t traceresult
49124919

49134920
(** {1 Variable collections} *)

0 commit comments

Comments
 (0)