diff --git a/CodeHawk/CHB/bchlib/bCHFloc.ml b/CodeHawk/CHB/bchlib/bCHFloc.ml index d38d5f57..da17fb26 100644 --- a/CodeHawk/CHB/bchlib/bCHFloc.ml +++ b/CodeHawk/CHB/bchlib/bCHFloc.ml @@ -1273,7 +1273,7 @@ object (self) __FILE__ __LINE__ ["addrvalue: " ^ (x2s addrvalue); "btype: " ^ (btype_to_string btype); - "size: " ^ (if Option.is_some size then (string_of_int (Option.get size)) else "?")] in + "size: " ^ (opti2s size)] in match self#normalize_addrvalue addrvalue with | XOp ((Xf "addressofvar"), [XVar v]) when self#env#is_global_variable v -> @@ -1341,7 +1341,8 @@ object (self) (TR.tmap ~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__)) (fun offset -> self#f#env#mk_gloc_variable gloc offset) - (gloc#address_memory_offset ~tgtsize:size ~tgtbtype:btype self#l addrvalue)) + (gloc#address_memory_offset + ~tgtsize:size ~tgtbtype:btype self#l addrvalue)) | _ -> let (memref_r, memoff_r) = self#decompose_memaddr addrvalue in TR.tmap2 @@ -2362,15 +2363,7 @@ object (self) | XConst (IntConst n) when n#gt CHNumerical.numerical_zero -> let dw = numerical_mod_to_doubleword n in if memmap#has_location dw then - TR.tfold - ~ok:(fun gv -> XOp ((Xf "addressofvar"), [XVar gv])) - ~error:(fun e -> - begin - log_result - ~tag:"assign global variable address" __FILE__ __LINE__ e; - rhs - end) - (self#f#env#mk_global_variable self#l n) + TR.tvalue (self#f#env#mk_global_variable_address dw) ~default:rhs else rhs | _ -> rhs in diff --git a/CodeHawk/CHB/bchlib/bCHFunctionInfo.ml b/CodeHawk/CHB/bchlib/bCHFunctionInfo.ml index 2ead7e3b..f248756b 100644 --- a/CodeHawk/CHB/bchlib/bCHFunctionInfo.ml +++ b/CodeHawk/CHB/bchlib/bCHFunctionInfo.ml @@ -840,6 +840,22 @@ object (self) end end + method mk_global_variable_address (dw: doubleword_int): xpr_t traceresult = + match memmap#containing_location dw with + | Some gloc when dw#equal gloc#address -> + let gvar = + self#mk_variable (self#varmgr#make_global_variable dw#to_numerical) in + let ivar = self#mk_variable (varmgr#make_initial_memory_value gvar) in + begin + self#set_variable_name gvar gloc#name; + self#set_variable_name ivar (gloc#name ^ "_in"); + Ok (XOp ((Xf "addressofvar"), [XVar gvar])) + end + | _ -> + Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": " + ^ dw#to_hex_string + ^ " is not the address of a known global variable"] + method mk_global_variable ?(size=4) ?(btype=t_unknown) @@ -848,10 +864,6 @@ object (self) let dw = numerical_mod_to_doubleword base in match memmap#containing_location dw with | Some gloc -> - let gvar = - self#mk_variable - (self#varmgr#make_global_variable gloc#address#to_numerical) in - let _ivar = self#mk_variable (varmgr#make_initial_memory_value gvar) in tmap ~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": memref:global") (fun offset -> diff --git a/CodeHawk/CHB/bchlib/bCHGlobalMemoryMap.ml b/CodeHawk/CHB/bchlib/bCHGlobalMemoryMap.ml index 8d846515..4c4a3f43 100644 --- a/CodeHawk/CHB/bchlib/bCHGlobalMemoryMap.ml +++ b/CodeHawk/CHB/bchlib/bCHGlobalMemoryMap.ml @@ -484,7 +484,8 @@ object (self) ~msg:(p2s loc#toPretty) ~tag:"mmap:address-offset-memory-offset" __FILE__ __LINE__ - ["xoffset: " ^ (x2s xoffset) + ["gloc: " ^ self#address#to_hex_string + ^ "; xoffset: " ^ (x2s xoffset) ^ "; tgtsize: " ^ (opti2s tgtsize) ^ "; tgtbtype: " ^ (ty2s tgtbtype)] in match xoffset with @@ -517,7 +518,9 @@ object (self) else Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ":" ^ (btype_to_string self#btype) - ^ " is not known to be a struct or array"] + ^ " is not known to be a struct or array"; + "gloc_address: " ^ self#address#to_hex_string; + "xoffset: " ^ (x2s xoffset)] method address_memory_offset ?(tgtsize=None) diff --git a/CodeHawk/CHB/bchlib/bCHLibTypes.mli b/CodeHawk/CHB/bchlib/bCHLibTypes.mli index a0e72d79..baba19a8 100644 --- a/CodeHawk/CHB/bchlib/bCHLibTypes.mli +++ b/CodeHawk/CHB/bchlib/bCHLibTypes.mli @@ -4778,6 +4778,8 @@ class type function_environment_int = (** {2 Memory variables} *) + method mk_global_variable_address: doubleword_int -> xpr_t traceresult + (** [mk_global_variable offset] attempts to find a containing global location for [offset]. If successful a memory offset will be computed for that offset relative to the address of the containing location