From b59b2b182a6832e1b6ebf3cf7ba4fd1943843b74 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Wed, 1 Jul 2015 17:25:44 +0200 Subject: Removed the version from the compcert.ini file and add it again in a separate file. --- debug/DwarfPrinter.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'debug') diff --git a/debug/DwarfPrinter.ml b/debug/DwarfPrinter.ml index 13d4049e..96332006 100644 --- a/debug/DwarfPrinter.ml +++ b/debug/DwarfPrinter.ml @@ -328,7 +328,7 @@ module DwarfPrinter(Target: DWARF_TARGET)(DwarfAbbrevs:DWARF_ABBREVS): print_string oc bt.base_type_name let print_compilation_unit oc tag = - let prod_name = sprintf "AbsInt Angewandte Informatik GmbH:CompCert Version %s:%s" Configuration.version Configuration.arch in + let prod_name = sprintf "AbsInt Angewandte Informatik GmbH:CompCert Version %s:%s" Version.version Configuration.arch in print_string oc (Sys.getcwd ()); print_addr oc (get_start_addr ()); print_addr oc (get_end_addr ()); -- cgit From f3ca5a662a3375c238c0b3f0aa2819bb05bd27f7 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Thu, 2 Jul 2015 10:23:45 +0200 Subject: Add bulitin typedes during C to dwarf translation. --- debug/CtoDwarf.ml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'debug') diff --git a/debug/CtoDwarf.ml b/debug/CtoDwarf.ml index a352e99f..70b9e208 100644 --- a/debug/CtoDwarf.ml +++ b/debug/CtoDwarf.ml @@ -10,6 +10,7 @@ (* *) (* *********************************************************************) +open Builtins open C open Cprint open Cutil @@ -270,12 +271,12 @@ and type_to_dwarf (typ: typ): int * dw_entry list = attr_type_to_dwarf typ typ_string (* Translate a typedef to its corresponding dwarf representation *) -let typedef_to_dwarf (n,t) gloc = +let typedef_to_dwarf gloc (name,t) = let i,t = type_to_dwarf t in - Hashtbl.add typedef_table n.name i; + Hashtbl.add typedef_table name i; let td = { - typedef_file_loc = Some (gloc); - typedef_name = n.name; + typedef_file_loc = gloc; + typedef_name = name; typedef_type = i; } in let td = new_entry (DW_TAG_typedef td) in @@ -461,7 +462,7 @@ let union_to_dwarf (n,at,m) env gloc = let globdecl_to_dwarf env (typs,decls) decl = PrintAsmaux.add_file (fst decl.gloc); match decl.gdesc with - | Gtypedef (n,t) -> let ret = typedef_to_dwarf (n,t) decl.gloc in + | Gtypedef (n,t) -> let ret = typedef_to_dwarf (Some decl.gloc) (n.name,t) in typs@ret,decls | Gdecl d -> let t,d = glob_var_to_dwarf d decl.gloc in typs@t,d::decls @@ -485,7 +486,9 @@ let program_to_dwarf prog prog1 name = let prog = cleanupGlobals (prog) in let env = translEnv Env.empty prog1 in reset_id (); - let typs,defs = List.fold_left (globdecl_to_dwarf env) ([],[]) prog in + let typs = List.map (typedef_to_dwarf None) C2C.builtins.typedefs in + let typs = List.concat typs in + let typs,defs = List.fold_left (globdecl_to_dwarf env) (typs,[]) prog in let defs = typs @ defs in let cp = { compile_unit_name = name; -- cgit From b946cdfc8e33468a813cd8b2e41aa3442b51f04f Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Thu, 2 Jul 2015 11:17:56 +0200 Subject: Allow Anonymous structs, unions and enums in debug info. --- debug/CtoDwarf.ml | 18 +++++++++--------- debug/DwarfPrinter.ml | 12 ++++++------ debug/DwarfTypes.mli | 6 +++--- 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'debug') diff --git a/debug/CtoDwarf.ml b/debug/CtoDwarf.ml index 70b9e208..e0bc014f 100644 --- a/debug/CtoDwarf.ml +++ b/debug/CtoDwarf.ml @@ -29,10 +29,10 @@ let type_table: (string, int) Hashtbl.t = Hashtbl.create 7 let typedef_table: (string, int) Hashtbl.t = Hashtbl.create 7 (* Hashtable from composite table to entry id *) -let composite_types_table: (string, int) Hashtbl.t = Hashtbl.create 7 +let composite_types_table: (int, int) Hashtbl.t = Hashtbl.create 7 (* Get the type id of a composite_type *) -let get_composite_type (name: string): int = +let get_composite_type (name: int): int = try Hashtbl.find composite_types_table name with Not_found -> @@ -232,7 +232,7 @@ and type_to_dwarf_entry typ typ_string= | TStruct (i,_) | TUnion (i,_) | TEnum (i,_) -> - let t = get_composite_type i.name in + let t = get_composite_type i.stamp in t,[] | TNamed (i,at) -> let t = Hashtbl.find typedef_table i.name in @@ -353,9 +353,9 @@ let enum_to_dwarf (n,at,e) gloc = enumeration_file_loc = Some gloc; enumeration_byte_size = bs; enumeration_declaration = Some false; - enumeration_name = n.name; + enumeration_name = if n.name <> "" then Some n.name else None; } in - let id = get_composite_type n.name in + let id = get_composite_type n.stamp in let child = List.map enumerator_to_dwarf e in let enum = { @@ -372,9 +372,9 @@ let struct_to_dwarf (n,at,m) env gloc = structure_file_loc = Some gloc; structure_byte_size = info.ci_sizeof; structure_declaration = Some false; - structure_name = n.name; + structure_name = if n.name <> "" then Some n.name else None; } in - let id = get_composite_type n.name in + let id = get_composite_type n.stamp in let rec pack acc bcc l m = match m with | [] -> acc,bcc,[] @@ -435,9 +435,9 @@ let union_to_dwarf (n,at,m) env gloc = union_file_loc = Some gloc; union_byte_size = info.ci_sizeof; union_declaration = Some false; - union_name = n.name; + union_name = if n.name <> "" then Some n.name else None; } in - let id = get_composite_type n.name in + let id = get_composite_type n.stamp in let children,e = mmap (fun acc f -> let t,e = type_to_dwarf f.fld_typ in diff --git a/debug/DwarfPrinter.ml b/debug/DwarfPrinter.ml index 96332006..53caa8f1 100644 --- a/debug/DwarfPrinter.ml +++ b/debug/DwarfPrinter.ml @@ -112,7 +112,7 @@ module DwarfPrinter(Target: DWARF_TARGET)(DwarfAbbrevs:DWARF_ABBREVS): add_attr_some e.enumeration_file_loc add_file_loc; add_byte_size buf; add_attr_some e.enumeration_declaration add_declaration; - add_name buf + add_attr_some e.enumeration_name add_name | DW_TAG_enumerator e -> prologue 0x28; add_attr_some e.enumerator_file_loc add_file_loc; @@ -156,7 +156,7 @@ module DwarfPrinter(Target: DWARF_TARGET)(DwarfAbbrevs:DWARF_ABBREVS): add_attr_some e.structure_file_loc add_file_loc; add_attr_some e.structure_byte_size add_byte_size; add_attr_some e.structure_declaration add_declaration; - add_name buf + add_attr_some e.structure_name add_name | DW_TAG_subprogram e -> prologue 0x2e; add_attr_some e.subprogram_file_loc add_file_loc; @@ -187,7 +187,7 @@ module DwarfPrinter(Target: DWARF_TARGET)(DwarfAbbrevs:DWARF_ABBREVS): add_attr_some e.union_file_loc add_file_loc; add_attr_some e.union_byte_size add_byte_size; add_attr_some e.union_declaration add_declaration; - add_name buf + add_attr_some e.union_name add_name | DW_TAG_unspecified_parameter e -> prologue 0x18; add_attr_some e.unspecified_parameter_file_loc add_file_loc; @@ -344,7 +344,7 @@ module DwarfPrinter(Target: DWARF_TARGET)(DwarfAbbrevs:DWARF_ABBREVS): print_file_loc oc et.enumeration_file_loc; print_uleb128 oc et.enumeration_byte_size; print_opt_value oc et.enumeration_declaration print_flag; - print_string oc et.enumeration_name + print_opt_value oc et.enumeration_name print_string let print_enumerator oc en = print_file_loc oc en.enumerator_file_loc; @@ -385,7 +385,7 @@ module DwarfPrinter(Target: DWARF_TARGET)(DwarfAbbrevs:DWARF_ABBREVS): print_file_loc oc st.structure_file_loc; print_opt_value oc st.structure_byte_size print_uleb128; print_opt_value oc st.structure_declaration print_flag; - print_string oc st.structure_name + print_opt_value oc st.structure_name print_string let print_subprogram oc sp = let s,e = get_fun_addr sp.subprogram_name in @@ -415,7 +415,7 @@ module DwarfPrinter(Target: DWARF_TARGET)(DwarfAbbrevs:DWARF_ABBREVS): print_file_loc oc ut.union_file_loc; print_opt_value oc ut.union_byte_size print_uleb128; print_opt_value oc ut.union_declaration print_flag; - print_string oc ut.union_name + print_opt_value oc ut.union_name print_string let print_unspecified_parameter oc up = print_file_loc oc up.unspecified_parameter_file_loc; diff --git a/debug/DwarfTypes.mli b/debug/DwarfTypes.mli index c02558b5..e32f6fab 100644 --- a/debug/DwarfTypes.mli +++ b/debug/DwarfTypes.mli @@ -80,7 +80,7 @@ type dw_tag_enumeration_type = enumeration_file_loc: file_loc option; enumeration_byte_size: constant; enumeration_declaration: flag option; - enumeration_name: string; + enumeration_name: string option; } type dw_tag_enumerator = @@ -135,7 +135,7 @@ type dw_tag_structure_type = structure_file_loc: file_loc option; structure_byte_size: constant option; structure_declaration: flag option; - structure_name: string; + structure_name: string option; } type dw_tag_subprogram = @@ -172,7 +172,7 @@ type dw_tag_union_type = union_file_loc: file_loc option; union_byte_size: constant option; union_declaration: flag option; - union_name: string; + union_name: string option; } type dw_tag_unspecified_parameter = -- cgit From c32e15e23759d354c1491a69767093e374f52754 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Thu, 2 Jul 2015 12:59:10 +0200 Subject: Do not search for high and low pc of inlined functions. --- debug/DwarfPrinter.ml | 14 +++++++++++--- debug/DwarfTypes.mli | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'debug') diff --git a/debug/DwarfPrinter.ml b/debug/DwarfPrinter.ml index 53caa8f1..cf3c7730 100644 --- a/debug/DwarfPrinter.ml +++ b/debug/DwarfPrinter.ml @@ -62,6 +62,11 @@ module DwarfPrinter(Target: DWARF_TARGET)(DwarfAbbrevs:DWARF_ABBREVS): let add_low_pc = add_abbr_entry (0x11,low_pc_type_abbr) + let add_fun_pc sp buf = + match get_fun_addr sp.subprogram_name with + | None ->() + | Some (a,b) -> add_high_pc buf; add_low_pc buf + let add_declaration = add_abbr_entry (0x3c,declaration_type_abbr) let add_location loc buf = @@ -387,13 +392,16 @@ module DwarfPrinter(Target: DWARF_TARGET)(DwarfAbbrevs:DWARF_ABBREVS): print_opt_value oc st.structure_declaration print_flag; print_opt_value oc st.structure_name print_string + let print_subprogram_addr oc (s,e) = + fprintf oc " .4byte %a\n" label s; + fprintf oc " .4byte %a\n" label e + let print_subprogram oc sp = - let s,e = get_fun_addr sp.subprogram_name in + let addr = get_fun_addr sp.subprogram_name in print_file_loc oc sp.subprogram_file_loc; print_opt_value oc sp.subprogram_external print_flag; print_opt_value oc sp.subprogram_frame_base print_loc; - fprintf oc " .4byte %a\n" label s; - fprintf oc " .4byte %a\n" label e; + print_opt_value oc addr print_subprogram_addr; print_string oc sp.subprogram_name; print_flag oc sp.subprogram_prototyped; print_opt_value oc sp.subprogram_type print_ref diff --git a/debug/DwarfTypes.mli b/debug/DwarfTypes.mli index e32f6fab..e3d08e57 100644 --- a/debug/DwarfTypes.mli +++ b/debug/DwarfTypes.mli @@ -268,5 +268,5 @@ module type DWARF_TARGET= val get_end_addr: unit -> int val get_stmt_list_addr: unit -> int val name_of_section: section_name -> string - val get_fun_addr: string -> int * int + val get_fun_addr: string -> (int * int) option end -- cgit From e2a117e9801a432ea2813b2a6cddf073733575d2 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Fri, 3 Jul 2015 16:42:12 +0200 Subject: Allow forward declarations of structure and union types in the debug information. --- debug/CtoDwarf.ml | 60 +++++++++++++++++++++++++++++++++++++++++---------- debug/DwarfPrinter.ml | 4 ++-- debug/DwarfTypes.mli | 2 +- 3 files changed, 52 insertions(+), 14 deletions(-) (limited to 'debug') diff --git a/debug/CtoDwarf.ml b/debug/CtoDwarf.ml index e0bc014f..cead6099 100644 --- a/debug/CtoDwarf.ml +++ b/debug/CtoDwarf.ml @@ -18,6 +18,7 @@ open C2C open DwarfTypes open DwarfUtil open Env +open Set (* Functions to translate a C Ast into Dwarf 2 debugging information *) @@ -31,6 +32,14 @@ let typedef_table: (string, int) Hashtbl.t = Hashtbl.create 7 (* Hashtable from composite table to entry id *) let composite_types_table: (int, int) Hashtbl.t = Hashtbl.create 7 +(* Hashtable from id of a defined composite types to minimal type info *) +let composite_declarations: (int, (struct_or_union * string * location)) Hashtbl.t = Hashtbl.create 7 + +module IntSet = Set.Make(struct type t = int let compare = compare end) + +(* Set of all declared composite_types *) +let composite_defined: IntSet.t ref = ref IntSet.empty + (* Get the type id of a composite_type *) let get_composite_type (name: int): int = try @@ -395,7 +404,7 @@ let struct_to_dwarf (n,at,m) env gloc = member_bit_size = Some n; member_data_member_location = None; member_declaration = None; - member_name = m.fld_name; + member_name = if m.fld_name <> "" then Some m.fld_name else None; member_type = t; } in pack ((new_entry (DW_TAG_member um))::acc) (e@bcc) (l + n) ms) @@ -413,7 +422,7 @@ let struct_to_dwarf (n,at,m) env gloc = member_bit_size = None; member_data_member_location = None; member_declaration = None; - member_name = m.fld_name; + member_name = if m.fld_name <> "" then Some m.fld_name else None; member_type = t; } in translate ((new_entry (DW_TAG_member um))::acc) (e@bcc) ms @@ -448,7 +457,7 @@ let union_to_dwarf (n,at,m) env gloc = member_bit_size = None; member_data_member_location = None; member_declaration = None; - member_name = f.fld_name; + member_name = if f.fld_name <> "" then Some f.fld_name else None; member_type = t; } in new_entry (DW_TAG_member um),e@acc)[] m in @@ -468,15 +477,42 @@ let globdecl_to_dwarf env (typs,decls) decl = typs@t,d::decls | Gfundef f -> let t,d = fundef_to_dwarf f decl.gloc in typs@t,d::decls - | Genumdef (n,at,e) ->let ret = enum_to_dwarf (n,at,e) decl.gloc in - typs@ret,decls - | Gcompositedef (Struct,n,at,m) -> let ret = struct_to_dwarf (n,at,m) env decl.gloc in - typs@ret,decls - | Gcompositedef (Union,n,at,m) -> let ret = union_to_dwarf (n,at,m) env decl.gloc in - typs@ret,decls - | Gcompositedecl _ + | Genumdef (n,at,e) -> + composite_defined:= IntSet.add n.stamp !composite_defined; + let ret = enum_to_dwarf (n,at,e) decl.gloc in + typs@ret,decls + | Gcompositedef (Struct,n,at,m) -> + composite_defined:= IntSet.add n.stamp !composite_defined; + let ret = struct_to_dwarf (n,at,m) env decl.gloc in + typs@ret,decls + | Gcompositedef (Union,n,at,m) -> + composite_defined:= IntSet.add n.stamp !composite_defined; + let ret = union_to_dwarf (n,at,m) env decl.gloc in + typs@ret,decls + | Gcompositedecl (sou,i,_) -> Hashtbl.add composite_declarations i.stamp (sou,i.name,decl.gloc); + typs,decls | Gpragma _ -> typs,decls +let forward_declaration_to_dwarf sou name loc stamp = + let id = get_composite_type stamp in + let tag = match sou with + | Struct -> + DW_TAG_structure_type{ + structure_file_loc = Some loc; + structure_byte_size = None; + structure_declaration = Some true; + structure_name = if name <> "" then Some name else None; + } + | Union -> + DW_TAG_union_type { + union_file_loc = Some loc; + union_byte_size = None; + union_declaration = Some true; + union_name = if name <> "" then Some name else None; + } in + {tag = tag; children = []; id = id} + + (* Compute the dwarf representations of global declarations. The second program argument is the program after the bitfield and packed struct transformation *) let program_to_dwarf prog prog1 name = @@ -489,7 +525,9 @@ let program_to_dwarf prog prog1 name = let typs = List.map (typedef_to_dwarf None) C2C.builtins.typedefs in let typs = List.concat typs in let typs,defs = List.fold_left (globdecl_to_dwarf env) (typs,[]) prog in - let defs = typs @ defs in + let typs = Hashtbl.fold (fun i (sou,name,loc) typs -> if not (IntSet.mem i !composite_defined) then + (forward_declaration_to_dwarf sou name loc i)::typs else typs) composite_declarations typs in + let defs = typs @ defs in let cp = { compile_unit_name = name; } in diff --git a/debug/DwarfPrinter.ml b/debug/DwarfPrinter.ml index cf3c7730..9e565ee4 100644 --- a/debug/DwarfPrinter.ml +++ b/debug/DwarfPrinter.ml @@ -151,7 +151,7 @@ module DwarfPrinter(Target: DWARF_TARGET)(DwarfAbbrevs:DWARF_ABBREVS): | Some (DataLocBlock __) -> add_abbr_entry (0x38,data_location_block_type_abbr) buf | Some (DataLocRef _) -> add_abbr_entry (0x38,data_location_ref_type_abbr) buf); add_attr_some e.member_declaration add_declaration; - add_name buf; + add_attr_some e.member_name add_name; add_type buf | DW_TAG_pointer_type _ -> prologue 0xf; @@ -380,7 +380,7 @@ module DwarfPrinter(Target: DWARF_TARGET)(DwarfAbbrevs:DWARF_ABBREVS): print_opt_value oc mb.member_bit_size print_byte; print_opt_value oc mb.member_data_member_location print_data_location; print_opt_value oc mb.member_declaration print_flag; - print_string oc mb.member_name; + print_opt_value oc mb.member_name print_string; print_ref oc mb.member_type let print_pointer oc pt = diff --git a/debug/DwarfTypes.mli b/debug/DwarfTypes.mli index e3d08e57..d6592bd9 100644 --- a/debug/DwarfTypes.mli +++ b/debug/DwarfTypes.mli @@ -121,7 +121,7 @@ type dw_tag_member = member_bit_size: constant option; member_data_member_location: data_location_value option; member_declaration: flag option; - member_name: string; + member_name: string option; member_type: reference; } -- cgit