Skip to content

Commit

Permalink
Only generate dwarf entries if the line & column looks legitimate (#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
poechsel authored and mshinwell committed May 20, 2022
1 parent 3871ae8 commit 5cb3b91
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
4 changes: 4 additions & 0 deletions backend/debug/dwarf/dwarf_high/dwarf_attribute_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ let create_external ~is_visible_externally =
let spec = AS.create External Flag in
AV.create spec (V.bool ~comment:"not visible externally" false)

let create_artificial () =
let spec = AS.create Artificial Flag_present in
AV.create spec (V.flag_true ~comment:"artificial" ())

let create_decl_file file =
let spec = AS.create Decl_file Udata in
let file = Uint64.of_nonnegative_int_exn file in
Expand Down
2 changes: 2 additions & 0 deletions backend/debug/dwarf/dwarf_high/dwarf_attribute_helpers.mli
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ val create_stmt_list :
val create_external :
is_visible_externally:bool -> Dwarf_attribute_values.Attribute_value.t

val create_artificial : unit -> Dwarf_attribute_values.Attribute_value.t

val create_decl_file : int -> Dwarf_attribute_values.Attribute_value.t

val create_decl_line : int -> Dwarf_attribute_values.Attribute_value.t
Expand Down
35 changes: 20 additions & 15 deletions backend/debug/dwarf/dwarf_ocaml/dwarf_concrete_instances.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,33 @@ let for_fundecl ~get_file_id state fundecl =
in
let start_sym = Asm_symbol.create fun_name in
let end_sym = Asm_symbol.create (end_symbol_name ~start_symbol:fun_name) in
let file_num, line, startchar =
let location_attributes =
let loc = Debuginfo.to_location fundecl.fun_dbg in
if Location.is_none loc
then 0, 0, 0
then [DAH.create_artificial ()]
else
let file, line, startchar = Location.get_pos_info loc.loc_start in
get_file_id file, line, startchar
let attributes = [DAH.create_decl_file (get_file_id file)] in
if line < 0 then attributes
else if startchar < 0 then (DAH.create_decl_line line) :: attributes
else (* Both line and startchar are >= 0*)
(DAH.create_decl_line line) :: (DAH.create_decl_column startchar)
:: attributes
in
let attribute_values =
location_attributes @
[ DAH.create_name fun_name;
DAH.create_linkage_name ~linkage_name;
DAH.create_low_pc_from_symbol start_sym;
DAH.create_high_pc_from_symbol ~low_pc:start_sym end_sym;
DAH.create_entry_pc_from_symbol start_sym;
DAH.create_stmt_list
~debug_line_label:
(Asm_label.for_dwarf_section Asm_section.Debug_line) ]
in
let concrete_instance_proto_die =
Proto_die.create ~parent:(Some parent) ~tag:Subprogram
~attribute_values:
[ DAH.create_name fun_name;
DAH.create_linkage_name ~linkage_name;
DAH.create_low_pc_from_symbol start_sym;
DAH.create_high_pc_from_symbol ~low_pc:start_sym end_sym;
DAH.create_entry_pc_from_symbol start_sym;
DAH.create_decl_file file_num;
DAH.create_decl_line line;
DAH.create_decl_column startchar;
DAH.create_stmt_list
~debug_line_label:
(Asm_label.for_dwarf_section Asm_section.Debug_line) ]
~attribute_values
()
in
let name = Printf.sprintf "__concrete_instance_%s" fun_name in
Expand Down

0 comments on commit 5cb3b91

Please sign in to comment.