(* Registration function used by the tools. *)
let register ?(external_cmd = true) ?(extra_args = [])
- ?argcheck ?beforeksyms ?run
+ ?argcheck ?beforeksyms ?beforeutsname ?run
name summary description =
tools :=
(name, (name, summary, description, external_cmd, extra_args,
- argcheck, beforeksyms, run))
+ argcheck, beforeksyms, beforeutsname, run))
:: !tools
(* Main program, called from mem/virt_mem_main.ml when all the
match tool with
| None -> (* Generic usage message. *)
let tools = List.map (
- fun (name, (_, summary, _, external_cmd, _, _, _, _)) ->
+ fun (name, (_, summary, _, external_cmd, _, _, _, _, _)) ->
if external_cmd then "virt-"^name, summary
else "virt-mem "^name, summary
) tools in
Options:") tools
(* Tool-specific usage message. *)
- | Some (name, summary, description, external_cmd, _, _, _, _) ->
+ | Some (name, summary, description, external_cmd, _, _, _, _, _) ->
let cmd =
if external_cmd then "virt-" ^ name else "virt-mem " ^ name in
let argspec =
let extra_args = match tool with
| None -> []
- | Some (_, _, _, _, extra_args, _, _, _) -> extra_args in
+ | Some (_, _, _, _, extra_args, _, _, _, _) -> extra_args in
let argspec = [
"-A", Arg.String set_architecture,
"arch " ^ s_"Set kernel architecture, endianness and word size";
* or the user didn't give us a valid tool (eg. "virt-mem foobar").
* Detect that final case now and give an error.
*)
- let name, _, _, _, _, argcheck, beforeksyms, run =
+ let name, _, _, _, _, argcheck, beforeksyms, beforeutsname, run =
match tool with
| Some t -> t
| None ->
List.map (
fun (dom, _) ->
- let id = D.get_id dom in
- let name = D.get_name dom in
+ let domname = D.get_name dom in
let wordsize =
match !def_wordsize with
| None ->
failwith
(sprintf (f_"%s: use -W to define word size for this image")
- name);
+ domname);
| Some ws -> ws in
let endian =
match !def_endian with
| None ->
failwith
(sprintf (f_"%s: use -E to define endianness for this image")
- name);
+ domname);
| Some e -> e in
let arch =
| Some I386 -> I386 | Some X86_64 -> X86_64
| _ ->
failwith
- (sprintf (f_"%s: use -A to define architecture (i386/x86-64 only) for this image") name) in
+ (sprintf (f_"%s: use -A to define architecture (i386/x86-64 only) for this image") domname) in
if !def_text_addr = 0L then
failwith
- (sprintf (f_"%s: use -T to define kernel load address for this image") name);
+ (sprintf (f_"%s: use -T to define kernel load address for this image") domname);
let start_t = gettimeofday () in
let mem = Virt_mem_mmap.set_wordsize mem wordsize in
let mem = Virt_mem_mmap.set_endian mem endian in
- ((Some id, name, arch, mem) : image0)
+ { dom = Some dom; domname = domname; mem = mem; arch = arch }
) xmls
) else (
(* One or more -t options passed. *)
let mem = Virt_mem_mmap.set_wordsize mem wordsize in
let mem = Virt_mem_mmap.set_endian mem endian in
- ((None, filename, arch, mem) : image0)
+ { dom = None; domname = filename; mem = mem; arch = arch }
) testimages
) in
| Some beforeksyms -> beforeksyms debug images
);
- (* If there is no run function, then there is no point continuing
- * with the rest of the program (kernel symbol analysis) ...
+ (* If there are no more callback functions, then there is no point
+ * continuing with the rest of the program (kernel symbol analysis) ...
*)
- if run = None then exit 0;
+ if beforeutsname = None && run = None then exit 0;
(* Do the kernel symbol analysis. *)
let images =
List.map (
fun image ->
-
(* Look for ordinary kernel symbols: *)
let image = Virt_mem_ksyms.find_kernel_symbols debug image in
(* Look for kallsyms: *)
let image = Virt_mem_kallsyms.find_kallsyms debug image in
+(*
(* Finally, just wrap the lookup_ksym call in something
* which prints the query when debug is set.
*)
(domid, name, arch, mem, lookup_ksym)
else
image in
+*)
image
) images in
+ (* Before utsname analysis. *)
+ (match beforeutsname with
+ | None -> ()
+ | Some beforeutsname -> List.iter (beforeutsname debug) images
+ );
+
+ (* If there are no more callback functions, then there is no point
+ * continuing with the rest of the program (kernel version analysis) ...
+ *)
+ if run = None then exit 0;
+
+ (* Get the kernel version (utsname analysis). *)
+ let images = List.map (Virt_mem_utsname.find_utsname debug) images in
+
(* Run the tool's main function. *)
(match run with
| None -> ()
- | Some run ->
- run debug images
+ | Some run -> List.iter (run debug) images
)