Add basic test
This commit is contained in:
parent
737a2b51a8
commit
24383471fd
3 changed files with 58 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -20,3 +20,4 @@ _build/
|
|||
setup.data
|
||||
setup.log
|
||||
|
||||
.merlin
|
||||
|
|
2
dune-project
Normal file
2
dune-project
Normal file
|
@ -0,0 +1,2 @@
|
|||
(lang dune 1.9)
|
||||
(using menhir 2.0)
|
55
src/elf_arrows.ml
Normal file
55
src/elf_arrows.ml
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue