From e90e51fc2a4686ff6b1989d116efeb3899602354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Fri, 22 Nov 2019 12:46:47 +0100 Subject: [PATCH] Match with file names instead of file ids It seems possible that two runs of eg. gcc at different levels of optimisation on the same files assigns different IDs to the same files. To circumvent this, we use the file paths instead of file IDs. --- src/asm_matcher.ml | 22 ++++++++++++++++++++-- src/elf_arrows.ml | 12 +++++++++--- src/html_renderer.ml | 2 +- src/renderer.ml | 4 ++-- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/asm_matcher.ml b/src/asm_matcher.ml index ed01523..e029f71 100644 --- a/src/asm_matcher.ml +++ b/src/asm_matcher.ml @@ -8,6 +8,8 @@ module BlockidMap = Map.Make(struct end) type asm_block_info = { + asm_bi_dwarfhead : Dwarf.line_number_header ; (* FIXME overkill to carry + around? *) asm_bi_dwarfline : Dwarf.line_number_registers ; asm_bi_blockid : blockid_t ; } @@ -20,9 +22,24 @@ let fresh_blockid = incr next_id ; out +(** Gets the file path for a given file id and header data *) +let extract_file_name file_id files_list = + let file_data = List.nth files_list (file_id - 1) in + file_data.Dwarf.lnfe_path + |> List.to_seq + |> String.of_seq + + +(** Gets the file path for the given blk, instead of its id *) +let get_file_name blk = Dwarf.( + let file_id = blk.asm_bi_dwarfline.lnr_file + |> Z.to_int in + extract_file_name file_id blk.asm_bi_dwarfhead.lnh_file_names + ) + (** Compares two block infos wrt. class equivalence *) let asm_bi_compare blk1 blk2 = - let select_file blk = Dwarf.(blk.asm_bi_dwarfline.lnr_file) in + let select_file blk = get_file_name blk in let select_line blk = Dwarf.(blk.asm_bi_dwarfline.lnr_line) in let select_col blk = Dwarf.(blk.asm_bi_dwarfline.lnr_column) in @@ -81,8 +98,9 @@ let add_block_bi state blockinfo = argument and generates a fresh id by itself. WARNING! Do not mix automatically and manually generated ids. *) -let add_block state lnr = +let add_block state lnh lnr = add_block_bi state { + asm_bi_dwarfhead = lnh ; asm_bi_dwarfline = lnr ; asm_bi_blockid = fresh_blockid () } diff --git a/src/elf_arrows.ml b/src/elf_arrows.ml index 585a0bc..b28dbaa 100644 --- a/src/elf_arrows.ml +++ b/src/elf_arrows.ml @@ -45,7 +45,8 @@ let add_line_boxes render_data matcher_data dwarf_lines = do_fold base lst in - List.fold_left (fun (cur_render_data, cur_matcher_data) (_, reg_list) -> + List.fold_left (fun (cur_render_data, cur_matcher_data) + (reg_header, reg_list) -> fold_ahead (fun (cur_render_data, cur_matcher_data) cur_reg reg_ahead -> let box_start = Z.to_int @@ cur_reg.Dwarf.lnr_address in let box_end = Z.to_int @@ reg_ahead.Dwarf.lnr_address in @@ -54,11 +55,16 @@ let add_line_boxes render_data matcher_data dwarf_lines = | false -> Format.eprintf "Add box %x -- %x@." box_start box_end ; let n_matcher_data, block_class_id = - Asm_matcher.add_block cur_matcher_data cur_reg in + Asm_matcher.add_block cur_matcher_data reg_header cur_reg in + let file_name = ( + let file_id = cur_reg.lnr_file + |> Z.to_int in + Asm_matcher.extract_file_name file_id reg_header.lnh_file_names + ) in let n_render_data, _ = Renderer.add_box_excl cur_render_data (box_start, box_end) Renderer.(Some { - box_file = Z.to_int cur_reg.lnr_file; + box_file = file_name ; box_line = Z.to_int cur_reg.lnr_line; box_col = Z.to_int cur_reg.lnr_column; box_class_id = block_class_id; diff --git a/src/html_renderer.ml b/src/html_renderer.ml index 29e10ee..dfdc4d7 100644 --- a/src/html_renderer.ml +++ b/src/html_renderer.ml @@ -46,7 +46,7 @@ let render_prog_box annotated_prog = Jingoo.Jg_types.(Renderer.AnnotAsm.( ("typ", box_string typ); ("id", box_int id); ("bound", box_string @@ render_addr bound); - ("data", box_string @@ Format.sprintf "[%d] File %d, %d:%d" + ("data", box_string @@ Format.sprintf "[%d] File %s, %d:%d" data.box_class_id data.box_file data.box_line data.box_col); ("box_eq", box_int data.box_class_id); diff --git a/src/renderer.ml b/src/renderer.ml index c9ecebd..758eb3b 100644 --- a/src/renderer.ml +++ b/src/renderer.ml @@ -8,7 +8,7 @@ module RawAsm = Asm_info.NoAnnot type addr_range_t = RawAsm.addr_t * RawAsm.addr_t type box_data_t = { - box_file : int; + box_file : string; box_line : int; box_col : int; box_class_id : int; @@ -82,7 +82,7 @@ let add_box render_data range opt_data : render_data_t * int = let data = (match opt_data with | Some data -> data | None -> { - box_file = 0; + box_file = ""; box_line = 0; box_col = 0; box_class_id = 0;