Skip to content
Snippets Groups Projects
Commit 5b7da9d7 authored by David Bühler's avatar David Bühler
Browse files

[Eva] Removes Value_types.Callstack.

parent 4d147ab5
No related branches found
No related tags found
No related merge requests found
......@@ -139,8 +139,6 @@ struct
in
(cs.entry_point, Cil_types.Kglobal) :: l
let to_legacy cs = List.rev (to_call_list cs)
(* Stable hash and pretty-printing *)
let stmt_hash s =
......
......@@ -53,7 +53,6 @@ sig
val top_call : t -> Cil_types.kernel_function * Cil_types.kinstr
val last_caller : t -> Cil_types.kernel_function option
val to_legacy : t -> Value_types.callstack
val to_kf_list : t -> Cil_types.kernel_function list
val to_stmt_list : t -> Cil_types.stmt list
val to_call_list : t -> (Cil_types.kernel_function * Cil_types.kinstr) list
......
......@@ -20,95 +20,6 @@
(* *)
(**************************************************************************)
module OCamlHashtbl = Hashtbl
open Cil_types
type call_site = kernel_function * kinstr
module Callsite = struct
include Datatype.Pair_with_collections(Kernel_function)(Cil_datatype.Kinstr)
(struct let module_name = "Value_callbacks.Callpoint" end)
let pretty fmt (kf, ki) =
Format.fprintf fmt "%a@@%t" Kernel_function.pretty kf
(fun fmt ->
match ki with
| Kglobal -> Format.pp_print_string fmt "<main>"
| Kstmt stmt -> Format.pp_print_int fmt stmt.sid
)
end
let dkey_callstack = Kernel.register_category "callstack"
type callstack = call_site list
module Callstack = struct
include Datatype.With_collections
(Datatype.List(Callsite))
(struct let module_name = "Value_types.Callstack" end)
(* Use default Datatype printer for debug only *)
let pretty_debug = pretty
let stmt_hash s =
let pos = fst (Cil_datatype.Stmt.loc s) in
OCamlHashtbl.seeded_hash 0
(pos.Filepath.pos_path, pos.Filepath.pos_lnum)
let kf_hash kf =
let name = Kernel_function.get_name kf in
OCamlHashtbl.seeded_hash 0 name
let ki_hash = function
| Kglobal -> 1
| Kstmt s -> 5 * stmt_hash s
let rec hash = function
| [] -> 0
| (kf, ki) :: r ->
let p = OCamlHashtbl.seeded_hash 0 (kf_hash kf, ki_hash ki, hash r) in
p mod 11_316_496 (* 58 ** 4 *)
let base58_map = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
(* Converts [i] into a fixed-length, 4-wide string in base-58 *)
let base58_of_int n =
let buf = Bytes.create 4 in
Bytes.set buf 0 (String.get base58_map (n mod 58));
let n = n / 58 in
Bytes.set buf 1 (String.get base58_map (n mod 58));
let n = n / 58 in
Bytes.set buf 2 (String.get base58_map (n mod 58));
let n = n / 58 in
Bytes.set buf 3 (String.get base58_map (n mod 58));
Bytes.to_string buf
let pretty_hash fmt callstack =
if Kernel.is_debug_key_enabled dkey_callstack then
Format.fprintf fmt "<%s> " (base58_of_int (hash callstack))
else Format.ifprintf fmt ""
let pretty_short fmt callstack =
Format.fprintf fmt "%a" pretty_hash callstack;
Pretty_utils.pp_flowlist ~left:"" ~sep:" <- " ~right:""
(fun fmt (kf,_) -> Kernel_function.pretty fmt kf)
fmt
callstack
let pretty fmt callstack =
Format.fprintf fmt "@[<hv>%a" pretty_hash callstack;
List.iter (fun (kf,ki) ->
Kernel_function.pretty fmt kf;
match ki with
| Kglobal -> ()
| Kstmt stmt -> Format.fprintf fmt " :: %a <-@ "
Cil_datatype.Location.pretty
(Cil_datatype.Stmt.loc stmt)
) callstack;
Format.fprintf fmt "@]"
end
type 'a callback_result =
| Normal of 'a
| NormalStore of 'a * int
......
......@@ -23,41 +23,6 @@
(** Declarations that are useful for plugins written on top of the results
of Value. *)
open Cil_types
(* TODO: These types are already defined in Value_util. *)
type call_site = kernel_function * kinstr
(** Value call-site.
A callsite [(f,p)] represents a call at function [f] invoked
{i from} program point [p].
*)
type callstack = call_site list
(** Value callstacks, as used e.g. in Db.Value hooks.
The head call site [(f,p)] is the most recent one,
where current function [f] has been called from program point [p].
Therefore, the tail call site is expected to be [(main,Kglobal)]
where [main] is the global entry point.
Moreover, given two consecutive call-sites […(_,p);(g,_)…] in a callstack,
program point [p] is then expected to live in function [g].
*)
module Callsite: Datatype.S_with_collections with type t = call_site
module Callstack: sig
include Datatype.S_with_collections with type t = callstack
val pretty_debug : Format.formatter -> t -> unit
(** Print a hash of the callstack when '-kernel-msg-key callstack'
is enabled (prints nothing otherwise). *)
val pretty_hash : Format.formatter -> t -> unit
(** Print a call stack without displaying call sites. *)
val pretty_short : Format.formatter -> t -> unit
end
type 'a callback_result =
| Normal of 'a
| NormalStore of 'a * int
......
......@@ -170,9 +170,6 @@ module Callstack: sig
(** {2 Conversion} *)
(** This function is likely to be removed in future versions*)
val to_legacy : t -> Value_types.callstack
(** Gives the list of kf in the callstack from the entry point to the top of the
callstack (i.e. reverse order of the call stack). *)
val to_kf_list : t -> Cil_types.kernel_function list
......
......@@ -75,9 +75,6 @@ val last_caller : t -> Cil_types.kernel_function option
(** {2 Conversion} *)
(** This function is likely to be removed in future versions*)
val to_legacy : t -> Value_types.callstack
(** Gives the list of kf in the callstack from the entry point to the top of the
callstack (i.e. reverse order of the call stack). *)
val to_kf_list : t -> Cil_types.kernel_function list
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment