Skip to content

Commit d0c3d1d

Browse files
committed
add diagnostics
1 parent 94a7c6e commit d0c3d1d

File tree

5 files changed

+60
-7
lines changed

5 files changed

+60
-7
lines changed

CodeHawk/CHB/bchlib/bCHFloc.ml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,12 @@ object (self)
15631563
) coffset_r)
15641564
cbasevar_r
15651565
else
1566+
let _ =
1567+
log_diagnostics_result
1568+
~msg:(p2s self#l#toPretty)
1569+
~tag:"convert-variable-offsets:default"
1570+
__FILE__ __LINE__
1571+
[(p2s v#toPretty)] in
15661572
Ok v
15671573

15681574
method convert_value_offsets
@@ -1573,7 +1579,7 @@ object (self)
15731579
let cbasevar_r =
15741580
TR.tbind
15751581
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
1576-
self#convert_value_offsets
1582+
(self#convert_value_offsets ~size)
15771583
basevar_r in
15781584
let basetype_r = TR.tbind self#get_variable_type cbasevar_r in
15791585
let tgttype_r =
@@ -1597,6 +1603,12 @@ object (self)
15971603
(fun offset ->
15981604
match offset with
15991605
| NoOffset ->
1606+
let _ =
1607+
log_diagnostics_result
1608+
~msg:(p2s self#l#toPretty)
1609+
~tag:"convert-value-offsets:NoOffset"
1610+
__FILE__ __LINE__
1611+
["v: " ^ (p2s v#toPretty)] in
16001612
TR.tbind
16011613
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
16021614
(fun tgttype ->
@@ -1618,10 +1630,20 @@ object (self)
16181630
(fun coffset ->
16191631
let memvar_r =
16201632
self#env#mk_basevar_memory_variable cbasevar coffset in
1621-
TR.tbind self#env#mk_initial_memory_value memvar_r
1633+
TR.tbind
1634+
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1635+
^ "cbasevar: " ^ (p2s cbasevar#toPretty)
1636+
^ "; coffset: " ^ (memory_offset_to_string coffset))
1637+
self#env#mk_initial_memory_value memvar_r
16221638
) coffset_r)
16231639
cbasevar_r
16241640
else
1641+
let _ =
1642+
log_diagnostics_result
1643+
~msg:(p2s self#l#toPretty)
1644+
~tag:"convert-value-offsets:default"
1645+
__FILE__ __LINE__
1646+
["v: " ^ (p2s v#toPretty)] in
16251647
Ok v
16261648

16271649
method convert_xpr_offsets ?(size=None) (x: xpr_t): xpr_t traceresult =
@@ -1650,7 +1672,14 @@ object (self)
16501672
| XOp (op, [xx]) -> TR.tmap (fun x -> XOp (op, [x])) (aux xx)
16511673
| XOp (op, [x1; x2]) ->
16521674
TR.tmap2 (fun x1 x2 -> XOp (op, [x1; x2])) (aux x1) (aux x2)
1653-
| _ -> Ok exp in
1675+
| _ ->
1676+
let _ =
1677+
log_diagnostics_result
1678+
~msg:(p2s self#l#toPretty)
1679+
~tag:"convert-xpr-offsets:default"
1680+
__FILE__ __LINE__
1681+
["x: " ^ (x2s x) ^ "; exp: " ^ (x2s exp)] in
1682+
Ok exp in
16541683
aux x
16551684

16561685
method get_xpr_type (x: xpr_t): btype_t traceresult =

CodeHawk/CHB/bchlib/bCHMemoryReference.ml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ let rec address_memory_offset
192192
let rbasetype = TR.tvalue (resolve_type basetype) ~default:t_unknown in
193193
match xoffset with
194194
| XConst (IntConst n) when is_unknown_type rbasetype ->
195+
let _ =
196+
log_diagnostics_result
197+
~msg:"address-memory-offset:unknown basetype"
198+
__FILE__ __LINE__
199+
["xoffset: " ^ n#toString] in
195200
Ok (ConstantOffset (n, NoOffset))
196201
| XConst (IntConst n) ->
197202
let tgtbtype =
@@ -201,7 +206,14 @@ let rec address_memory_offset
201206
else if is_array_type rbasetype then
202207
arrayvar_memory_offset ~tgtsize ~tgtbtype rbasetype xoffset
203208
else
204-
Ok (ConstantOffset (n, NoOffset))
209+
let _ =
210+
log_diagnostics_result
211+
~msg:"address-memory-offset:scalar basetype"
212+
__FILE__ __LINE__
213+
["base type: " ^ (btype_to_string rbasetype)
214+
^ "; xoffset: " ^ n#toString] in
215+
(* Ok (ConstantOffset (n, NoOffset)) *)
216+
Ok (BasePtrArrayIndexOffset (num_constant_expr n, NoOffset))
205217
| _ ->
206218
let tgtbtype =
207219
if is_unknown_type tgtbtype then None else Some tgtbtype in
@@ -436,6 +448,12 @@ let rec is_field_offset (offset: memory_offset_t): bool =
436448
| _ -> false
437449

438450

451+
let is_base_ptr_array_index_offset (offset: memory_offset_t): bool =
452+
match offset with
453+
| BasePtrArrayIndexOffset (_, suboffset) -> is_constant_offset suboffset
454+
| _ -> false
455+
456+
439457
let rec is_index_offset (offset: memory_offset_t): bool =
440458
match offset with
441459
| IndexOffset (_, _, NoOffset) -> true

CodeHawk/CHB/bchlib/bCHMemoryReference.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ val is_field_offset: memory_offset_t -> bool
101101
val is_index_offset: memory_offset_t -> bool
102102

103103

104+
val is_base_ptr_array_index_offset: memory_offset_t -> bool
105+
106+
104107
(** Returns [true] if [memoff] itself or one of its suboffsets is an unknown
105108
offset. *)
106109
val is_unknown_offset: memory_offset_t -> bool

CodeHawk/CHB/bchlib/bCHVariable.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,10 @@ object (self)
10061006
method has_constant_offset (v: variable_t) =
10071007
(self#is_memory_variable v)
10081008
&& (tfold_default
1009-
(fun off -> is_constant_offset off || is_field_offset off)
1009+
(fun off ->
1010+
(is_constant_offset off)
1011+
|| (is_field_offset off)
1012+
|| (is_base_ptr_array_index_offset off))
10101013
false
10111014
(self#get_memvar_offset v))
10121015

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_20250325"
99-
~date:"2025-03-25"
98+
~version:"0.6.0_20250401"
99+
~date:"2025-04-01"
100100
~licensee: None
101101
~maxfilesize: None
102102
()

0 commit comments

Comments
 (0)