Frontend: print as readelf -wF
This commit is contained in:
parent
7ffc33d7a8
commit
ee6ac40294
4 changed files with 47 additions and 1 deletions
|
@ -4,3 +4,4 @@ PreDwarf
|
|||
Regs
|
||||
OnlyUnwind
|
||||
Simplest
|
||||
Frontend
|
||||
|
|
44
DwarfSynth/Frontend.ml
Normal file
44
DwarfSynth/Frontend.ml
Normal file
|
@ -0,0 +1,44 @@
|
|||
(** Frontend
|
||||
Clean printers, etc.
|
||||
*)
|
||||
|
||||
let pp_int64_hex ppx number =
|
||||
let mask_short = Int64.(pred (shift_left one 16)) in
|
||||
let pp_short number =
|
||||
Format.fprintf ppx "%04x" Int64.(to_int (logand number mask_short))
|
||||
in
|
||||
List.iter pp_short @@ List.map (fun x ->
|
||||
Int64.(shift_right number (16*x))) [3;2;1;0]
|
||||
|
||||
let pp_cfa_change ppx (Simplest.CfaChange (addr, pos)) = Simplest.(
|
||||
let num_len num =
|
||||
let str_rep = Format.sprintf "%+d" num in
|
||||
String.length str_rep
|
||||
in
|
||||
let print_row cfa_reg int64_offset =
|
||||
let offset = Int64.to_int int64_offset in
|
||||
let post_offset_spaces = String.make (6 - num_len offset) ' ' in
|
||||
Format.fprintf ppx "%a %s%+d%sc-8@."
|
||||
pp_int64_hex addr cfa_reg offset post_offset_spaces
|
||||
in
|
||||
|
||||
match pos with
|
||||
| RspOffset offset ->
|
||||
print_row "rsp" offset
|
||||
| RbpOffset offset ->
|
||||
print_row "rbp" offset
|
||||
| CfaLostTrack ->
|
||||
Format.fprintf ppx "%a u u@." pp_int64_hex addr
|
||||
)
|
||||
|
||||
let pp_pre_dwarf_readelf ppx pre_dwarf =
|
||||
Simplest.StrMap.iter (fun fde_name entry ->
|
||||
Format.fprintf ppx "FDE %s@." fde_name ;
|
||||
(match entry with
|
||||
| [] -> ()
|
||||
| _ ->
|
||||
Format.fprintf ppx " LOC CFA ra@." ;
|
||||
List.iter (pp_cfa_change ppx) entry ;
|
||||
Format.fprintf ppx "@.")
|
||||
)
|
||||
pre_dwarf
|
|
@ -2,4 +2,4 @@ open Std
|
|||
|
||||
let main outfile proj =
|
||||
let pre_dwarf = Simplest.of_proj proj in
|
||||
Format.printf "%a" Simplest.pp_cfa_changes pre_dwarf
|
||||
Format.printf "%a" Frontend.pp_pre_dwarf_readelf pre_dwarf
|
||||
|
|
1
_tags
1
_tags
|
@ -6,3 +6,4 @@ true: bin_annot
|
|||
<DwarfSynth/Regs.cmx>: for-pack(DwarfSynth)
|
||||
<DwarfSynth/OnlyUnwind.cmx>: for-pack(DwarfSynth)
|
||||
<DwarfSynth/Simplest.cmx>: for-pack(DwarfSynth)
|
||||
<DwarfSynth/Frontend.cmx>: for-pack(DwarfSynth)
|
||||
|
|
Loading…
Add table
Reference in a new issue