1
(***********************************************************************)
5
(* Xavier Leroy, projet Gallium, INRIA Rocquencourt *)
7
(* Copyright 2009 Institut National de Recherche en Informatique et *)
8
(* en Automatique. All rights reserved. This file is distributed *)
9
(* under the terms of the GNU Library General Public License, with *)
10
(* the special exception on linking described in file ../../LICENSE. *)
12
(***********************************************************************)
16
(* Dumps a .cmxs file *)
25
Printf.eprintf "Usage: %s file.cmxs\n" Sys.argv.(0);
29
exception Abnormal_exit
32
let eprint = Printf.eprintf in
33
let print_exc s = function
35
eprint "%s: %s\n" s file
38
| e -> eprint "%s\n" (Printexc.to_string e)
44
let cmd = Printf.sprintf command file in
45
let ic = Unix.open_process_in cmd in
47
let line = input_line ic in
48
begin match (Unix.close_process_in ic) with
49
| Unix.WEXITED 0 -> Str.split (Str.regexp "[ ]+") line
50
| Unix.WEXITED _ | Unix.WSIGNALED _ | Unix.WSTOPPED _ ->
53
"Command \"%s\" exited abnormally"
58
with e -> error "File is empty" e
60
let get_offset adr_off adr_sec =
62
let adr = List.nth adr_off 4 in
63
let off = List.nth adr_off 5 in
64
let sec = List.hd adr_sec in
66
let (!) x = Int64.of_string ("0x" ^ x) in
67
let (+) = Int64.add in
68
let (-) = Int64.sub in
70
Int64.to_int (!off + !sec - !adr)
72
with Failure _ | Invalid_argument _ ->
74
"Command output doesn't have the expected format"
77
let print_infos name crc defines cmi cmx =
78
let print_name_crc (name, crc) =
79
printf "@ %s (%s)" name (Digest.to_hex crc)
81
let pr_imports ppf imps = List.iter print_name_crc imps in
82
printf "Name: %s@." name;
83
printf "CRC of implementation: %s@." (Digest.to_hex crc);
84
printf "@[<hov 2>Globals defined:";
85
List.iter (fun s -> printf "@ %s" s) defines;
87
printf "@[<v 2>Interfaces imported:%a@]@." pr_imports cmi;
88
printf "@[<v 2>Implementations imported:%a@]@." pr_imports cmx
91
let adr_off = read_in "objdump -h %s | grep ' .data '" in
92
let adr_sec = read_in "objdump -T %s | grep ' caml_plugin_header$'" in
94
let ic = open_in file in
95
let _ = seek_in ic (get_offset adr_off adr_sec) in
96
let header = (input_value ic : Natdynlink.dynheader) in
97
if header.magic <> Natdynlink.dyn_magic_number then
98
raise(Error(Natdynlink.Not_a_bytecode_file file))