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.
This commit is contained in:
Théophile Bastian 2019-11-22 12:46:47 +01:00
parent 89ac1b8368
commit e90e51fc2a
4 changed files with 32 additions and 8 deletions

View File

@ -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 ()
}

View File

@ -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;

View File

@ -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);

View File

@ -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;