Skip to content

Commit c35f32d

Browse files
committed
CHB: allow named functions without listing in userdata
1 parent 0703fc3 commit c35f32d

File tree

4 files changed

+85
-25
lines changed

4 files changed

+85
-25
lines changed

CodeHawk/CHB/bchlib/bCHBCFiles.ml

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,40 @@ object (self)
316316
(BCH_failure
317317
(LBLOCK [STR "No enuminfo found with name "; STR name]))
318318

319-
method has_varinfo (name: string) =
320-
(H.mem gvars name) || (H.mem gvardecls name)
321-
322-
method get_varinfo (name: string) =
319+
method private get_prefixed_name (name: string): bvarinfo_t option =
320+
let declnames = H.fold (fun k _ a -> k :: a) gvardecls [] in
321+
let gvarnames = H.fold (fun k _ a -> k :: a) gvars [] in
322+
let namelen = String.length name in
323+
let result =
324+
List.fold_left (fun result n ->
325+
match result with
326+
| Some _ -> result
327+
| _ ->
328+
if String.length n > namelen && (String.sub n 0 namelen) = name then
329+
let (ix, _) = H.find gvardecls n in
330+
Some ix
331+
else
332+
None) None declnames in
333+
let result =
334+
List.fold_left (fun result n ->
335+
match result with
336+
| Some _ -> result
337+
| _ ->
338+
if String.length n > namelen && (String.sub n 0 namelen) = name then
339+
let (ix, _, _) = H.find gvars n in
340+
Some ix
341+
else
342+
None) result gvarnames in
343+
match result with
344+
| Some ix -> Some (bcd#get_varinfo ix)
345+
| _ -> None
346+
347+
method has_varinfo ?(prefix=false) (name: string) =
348+
(H.mem gvars name)
349+
|| (H.mem gvardecls name)
350+
|| (prefix && (Option.is_some (self#get_prefixed_name name)))
351+
352+
method get_varinfo ?(prefix=false) (name: string): bvarinfo_t =
323353
if self#has_varinfo name then
324354
let ix =
325355
if H.mem gvars name then
@@ -328,6 +358,13 @@ object (self)
328358
let (ix, _) = H.find gvardecls name in ix
329359
in
330360
bcd#get_varinfo ix
361+
else if prefix then
362+
match self#get_prefixed_name name with
363+
| Some vinfo -> vinfo
364+
| _ ->
365+
raise
366+
(BCH_failure
367+
(LBLOCK [STR "No varinfo found with prefixed name "; STR name]))
331368
else
332369
raise
333370
(BCH_failure

CodeHawk/CHB/bchlib/bCHBCTypes.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,12 +592,12 @@ class type bcfiles_int =
592592
(** [get_varinfo name] returns the varinfo with name [name].
593593
594594
@raise BCH_failure if no varinfo exists with name [name].*)
595-
method get_varinfo: string -> bvarinfo_t
595+
method get_varinfo: ?prefix:bool -> string -> bvarinfo_t
596596

597597
(** [has_varinfo name] returns true if there exists either a defined or
598598
declared variable with name [name]. Note that this includes function
599599
names.*)
600-
method has_varinfo: string -> bool
600+
method has_varinfo: ?prefix:bool -> string -> bool
601601

602602
method list_varinfos: string list
603603

CodeHawk/CHB/bchlib/bCHFunctionInfo.ml

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,27 +2651,50 @@ let load_finfo_userdata (finfo: function_info_int) (faddr: doubleword_int) =
26512651
| Some node ->
26522652
finfo#read_xml_user_summary node
26532653
| _ ->
2654-
let fname =
2655-
if functions_data#has_function_name faddr then
2656-
(functions_data#get_function faddr)#get_function_name
2654+
if functions_data#has_function_name faddr then
2655+
let fname = (functions_data#get_function faddr)#get_function_name in
2656+
if bcfiles#has_varinfo fname then
2657+
let vinfo = bcfiles#get_varinfo fname in
2658+
let bcsum = function_summary_of_bvarinfo vinfo in
2659+
begin
2660+
finfo#set_bc_summary bcsum;
2661+
chlog#add
2662+
"bc-function-summary"
2663+
(LBLOCK [
2664+
STR fname;
2665+
STR ": ";
2666+
function_interface_to_pretty bcsum#get_function_interface])
2667+
end
26572668
else
2669+
()
2670+
else
2671+
let fname =
26582672
let hexfaddr = faddr#to_hex_string in
26592673
let lenfaddr = String.length hexfaddr in
26602674
"sub_" ^ (String.sub (faddr#to_hex_string) 2 (lenfaddr - 2)) in
2661-
if bcfiles#has_varinfo fname then
2662-
let vinfo = bcfiles#get_varinfo fname in
2663-
let bcsum = function_summary_of_bvarinfo vinfo in
2664-
begin
2665-
finfo#set_bc_summary bcsum;
2666-
chlog#add
2667-
"bc-function-summary"
2668-
(LBLOCK [
2669-
STR fname;
2670-
STR ": ";
2671-
function_interface_to_pretty bcsum#get_function_interface])
2672-
end
2673-
else
2674-
()
2675+
if bcfiles#has_varinfo ~prefix:true fname then
2676+
let vinfo = bcfiles#get_varinfo ~prefix:true fname in
2677+
let bcsum = function_summary_of_bvarinfo vinfo in
2678+
begin
2679+
(if not (vinfo.bvname = fname) then
2680+
if functions_data#has_function faddr then
2681+
let fndata = functions_data#get_function faddr in
2682+
begin
2683+
fndata#add_name vinfo.bvname;
2684+
chlog#add
2685+
"bc-function-summary (update name)"
2686+
(LBLOCK [STR vinfo.bvname; STR " from "; STR fname])
2687+
end);
2688+
finfo#set_bc_summary bcsum;
2689+
chlog#add
2690+
"bc-function-summary"
2691+
(LBLOCK [
2692+
STR vinfo.bvname;
2693+
STR ": ";
2694+
function_interface_to_pretty bcsum#get_function_interface])
2695+
end
2696+
else
2697+
()
26752698

26762699

26772700
let load_function_info ?(reload=false) (faddr:doubleword_int) =

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_20241127"
99-
~date:"2024-11-27"
98+
~version:"0.6.0_20241128"
99+
~date:"2024-11-28"
100100
~licensee: None
101101
~maxfilesize: None
102102
()

0 commit comments

Comments
 (0)