diff --git a/.gitignore b/.gitignore index 193bdce..2c374a2 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ _build/ setup.data setup.log +.merlin diff --git a/dune-project b/dune-project new file mode 100644 index 0000000..a34fdb8 --- /dev/null +++ b/dune-project @@ -0,0 +1,2 @@ +(lang dune 1.9) +(using menhir 2.0) diff --git a/src/elf_arrows.ml b/src/elf_arrows.ml new file mode 100644 index 0000000..7076d1f --- /dev/null +++ b/src/elf_arrows.ml @@ -0,0 +1,55 @@ +(** Entry point file for elf_arrows *) + +exception NotElf;; +exception NoDwarf;; +exception NoDwarfStatic;; + +let (>>=) = Error.bind + +let make_pp linksem_pp = + (fun fmt arg -> + linksem_pp arg + |> Format.fprintf fmt "%s") + +type elf_path = string +type elf_handle = ElfHandle of elf_path * Elf_file.elf_file * Dwarf.dwarf_static + +(** Open an ELF file and loads its dwarf_static infos. *) +let open_elf elf_path = + + (Byte_sequence.acquire elf_path >>= fun elf_bs -> ( + match Elf_file.read_elf64_file elf_bs with + | Error.Success elf64 -> Error.Success (Elf_file.ELF_File_64 elf64) + | Error.Fail _ -> (match Elf_file.read_elf32_file elf_bs with + | Error.Success elf32 -> Error.Success (Elf_file.ELF_File_32 elf32) + | Error.Fail _ -> raise NotElf) + )) + >>= fun elf_file -> ( + let static_info = (match Dwarf.extract_dwarf_static elf_file with + | Some static_info -> static_info + | None -> raise NoDwarfStatic) in + Error.Success (ElfHandle (elf_path, elf_file, static_info))) + + +let elf_files = ref [] +let speclist = [] +let parse_anon_arg arg = + elf_files := arg :: (!elf_files) + +let _ = + Arg.parse speclist parse_anon_arg "./test ELF_FILE" ; + let elf_handles = List.rev @@ + List.map (fun path -> match open_elf path with + | Error.Success handle -> handle + | Error.Fail msg -> + raise (Failure ("Could not open " ^ path ^ ": " ^ msg))) + !elf_files + in + + List.iter (fun (ElfHandle(path, _, static_info)) -> + let line_info = static_info.ds_evaluated_line_info in + Format.eprintf "Line infos <%s>:@. %a@." + path + (make_pp Dwarf.pp_evaluated_line_info) + line_info ; + ) elf_handles