Skip to content

Commit e42febd

Browse files
committed
Merge branch 'dwarf' of /local/schommer/trunk/build/compcert.ppc/compcert into dwarf
2 parents 03ad26a + b597ce8 commit e42febd

24 files changed

+1615
-42
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
include Makefile.config
1717

18-
DIRS=lib common $(ARCH) backend cfrontend driver \
18+
DIRS=lib common $(ARCH) backend cfrontend driver debug\
1919
flocq/Core flocq/Prop flocq/Calc flocq/Appli exportclight \
2020
cparser cparser/validator
2121

@@ -203,6 +203,7 @@ compcert.ini: Makefile.config VERSION
203203
echo "system=$(SYSTEM)"; \
204204
echo "has_runtime_lib=$(HAS_RUNTIME_LIB)"; \
205205
echo "asm_supports_cfi=$(ASM_SUPPORTS_CFI)"; \
206+
echo "advanced_debug=$(ADVANCED_DEBUG)"; \
206207
echo "struct_passing_style=$(STRUCT_PASSING)"; \
207208
echo "struct_return_style=$(STRUCT_RETURN)"; \
208209
version=`cat VERSION`; \

Makefile.extr

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ include Makefile.config
2121

2222
DIRS=extraction \
2323
lib common $(ARCH) backend cfrontend cparser driver \
24-
exportclight
24+
exportclight debug
2525

2626
# Directories containing Caml code that must be preprocessed by Camlp4
2727

arm/TargetPrinter.ml

+12
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,18 @@ module Target (Opt: PRINTER_OPTIONS) : TARGET =
11271127
let print_epilogue oc = ()
11281128

11291129
let default_falignment = 4
1130+
1131+
let get_start_addr () = -1 (* Dummy constant *)
1132+
1133+
let get_end_addr () = -1 (* Dummy constant *)
1134+
1135+
let get_stmt_list_addr () = -1 (* Dummy constant *)
1136+
1137+
module DwarfAbbrevs = DwarfUtil.DefaultAbbrevs (* Dummy Abbrev types *)
1138+
1139+
let label = print_label
1140+
1141+
let new_label = new_label
11301142
end
11311143

11321144
let sel_target () =

backend/PrintAnnot.ml

+11-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ open AST
2121
open Memdata
2222
open Asm
2323

24+
(** All files used in the debug entries *)
25+
module StringSet = Set.Make(String)
26+
let all_files : StringSet.t ref = ref StringSet.empty
27+
let add_file file =
28+
all_files := StringSet.add file !all_files
29+
30+
2431
(** Line number annotations *)
2532

2633
let filename_info : (string, int * Printlines.filebuf option) Hashtbl.t
@@ -66,21 +73,21 @@ let print_file_line oc pref file line =
6673
| Some fb -> Printlines.copy oc pref fb line line
6774
end
6875

69-
(* Add file and line debug location, using DWARF1 directives in the style
76+
(* Add file and line debug location, using DWARF2 directives in the style
7077
of Diab C 5 *)
7178

72-
let print_file_line_d1 oc pref file line =
79+
let print_file_line_d2 oc pref file line =
7380
if !Clflags.option_g && file <> "" then begin
7481
let (_, filebuf) =
7582
try
7683
Hashtbl.find filename_info file
7784
with Not_found ->
7885
enter_filename file in
7986
if file <> !last_file then begin
80-
fprintf oc " .d1file %S\n" file;
87+
fprintf oc " .d2file %S\n" file;
8188
last_file := file
8289
end;
83-
fprintf oc " .d1line %d\n" line;
90+
fprintf oc " .d2line %d\n" line;
8491
match filebuf with
8592
| None -> ()
8693
| Some fb -> Printlines.copy oc pref fb line line

backend/PrintAsm.ml

+49-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ open AST
1515
open Asm
1616
open Camlcoq
1717
open Datatypes
18+
open DwarfPrinter
1819
open PrintAsmaux
1920
open Printf
2021
open Sections
@@ -23,6 +24,22 @@ open TargetPrinter
2324
module Printer(Target:TARGET) =
2425
struct
2526

27+
let addr_mapping: (string, (int * int)) Hashtbl.t = Hashtbl.create 7
28+
29+
let get_fun_addr name =
30+
let name = extern_atom name in
31+
let start_addr = new_label ()
32+
and end_addr = new_label () in
33+
Hashtbl.add addr_mapping name (start_addr,end_addr);
34+
start_addr,end_addr
35+
36+
let print_debug_label oc l =
37+
if !Clflags.option_g && Configuration.advanced_debug then
38+
fprintf oc "%a:\n" Target.label l
39+
else
40+
()
41+
42+
2643
let print_location oc loc =
2744
if loc <> Cutil.no_loc then Target.print_file_line oc (fst loc) (snd loc)
2845

@@ -37,16 +54,21 @@ module Printer(Target:TARGET) =
3754
if not (C2C.atom_is_static name) then
3855
fprintf oc " .globl %a\n" Target.symbol name;
3956
Target.print_optional_fun_info oc;
57+
let s,e = if !Clflags.option_g && Configuration.advanced_debug then
58+
get_fun_addr name
59+
else
60+
-1,-1 in
61+
print_debug_label oc s;
4062
fprintf oc "%a:\n" Target.symbol name;
4163
print_location oc (C2C.atom_location name);
4264
Target.cfi_startproc oc;
4365
Target.print_instructions oc fn;
4466
Target.cfi_endproc oc;
67+
print_debug_label oc e;
4568
Target.print_fun_info oc name;
4669
Target.emit_constants oc lit;
4770
Target.print_jumptable oc jmptbl
48-
49-
71+
5072
let print_init_data oc name id =
5173
if Str.string_match PrintCsyntax.re_string_literal (extern_atom name) 0
5274
&& List.for_all (function Init_int8 _ -> true | _ -> false) id
@@ -87,15 +109,37 @@ module Printer(Target:TARGET) =
87109
| Gfun (Internal code) -> print_function oc name code
88110
| Gfun (External ef) -> ()
89111
| Gvar v -> print_var oc name v
90-
112+
113+
module DwarfTarget: DwarfTypes.DWARF_TARGET =
114+
struct
115+
let label = Target.label
116+
let name_of_section = Target.name_of_section
117+
let print_file_loc = Target.print_file_loc
118+
let get_start_addr = Target.get_start_addr
119+
let get_end_addr = Target.get_end_addr
120+
let get_stmt_list_addr = Target.get_stmt_list_addr
121+
let name_of_section = Target.name_of_section
122+
let get_fun_addr s = Hashtbl.find addr_mapping s
123+
end
124+
125+
module DebugPrinter = DwarfPrinter (DwarfTarget) (Target.DwarfAbbrevs)
126+
127+
91128
end
92129

93-
let print_program oc p =
130+
let print_program oc p db =
94131
let module Target = (val (sel_target ()):TARGET) in
95132
let module Printer = Printer(Target) in
96133
PrintAnnot.reset_filenames ();
97134
PrintAnnot.print_version_and_options oc Target.comment;
98135
Target.print_prologue oc;
99136
List.iter (Printer.print_globdef oc) p.prog_defs;
100137
Target.print_epilogue oc;
101-
PrintAnnot.close_filenames ()
138+
PrintAnnot.close_filenames ();
139+
if !Clflags.option_g && Configuration.advanced_debug then
140+
begin
141+
match db with
142+
| None -> ()
143+
| Some db ->
144+
Printer.DebugPrinter.print_debug oc db
145+
end

backend/PrintAsm.mli

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@
1111
(* *)
1212
(* *********************************************************************)
1313

14-
open PrintAsmaux
15-
16-
val print_program: out_channel -> Asm.program -> unit
14+
val print_program: out_channel -> Asm.program -> DwarfTypes.dw_entry option -> unit

backend/PrintAsmaux.ml

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
open AST
1515
open Asm
1616
open Camlcoq
17+
open DwarfTypes
1718
open Datatypes
1819
open Printf
1920
open Sections
@@ -43,6 +44,13 @@ module type TARGET =
4344
val comment: string
4445
val symbol: out_channel -> P.t -> unit
4546
val default_falignment: int
47+
val get_start_addr: unit -> int
48+
val get_end_addr: unit -> int
49+
val get_stmt_list_addr: unit -> int
50+
val new_label: unit -> int
51+
val label: out_channel -> int -> unit
52+
val print_file_loc: out_channel -> file_loc -> unit
53+
module DwarfAbbrevs: DWARF_ABBREVS
4654
end
4755

4856
(* On-the-fly label renaming *)

checklink/Check.ml

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ let name_of_section_Linux: section_name -> string = function
7575
| Section_literal -> ".rodata.cst8"
7676
| Section_jumptable -> ".text"
7777
| Section_user(s, wr, ex) -> s
78+
| Section_debug_info -> ".debug_info"
79+
| Section_debug_abbrev -> ".debug_abbrev"
7880

7981
(** Adapted from CompCert *)
8082
let name_of_section_Diab: section_name -> string = function
@@ -87,6 +89,8 @@ let name_of_section_Diab: section_name -> string = function
8789
| Section_literal -> ".text"
8890
| Section_jumptable -> ".text"
8991
| Section_user(s, wr, ex) -> s
92+
| Section_debug_info -> ".debug_info"
93+
| Section_debug_abbrev -> ".debug_abbrev"
9094

9195
(** Taken from CompCert *)
9296
let name_of_section: section_name -> string =

common/Sections.ml

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type section_name =
2727
| Section_literal
2828
| Section_jumptable
2929
| Section_user of string * bool (*writable*) * bool (*executable*)
30+
| Section_debug_info
31+
| Section_debug_abbrev
3032

3133
type access_mode =
3234
| Access_default

common/Sections.mli

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type section_name =
2626
| Section_literal
2727
| Section_jumptable
2828
| Section_user of string * bool (*writable*) * bool (*executable*)
29+
| Section_debug_info
30+
| Section_debug_abbrev
2931

3032
type access_mode =
3133
| Access_default

configure

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ toolprefix=''
1919
target=''
2020
has_runtime_lib=true
2121
build_checklink=true
22+
advanced_debug=false
2223

2324
usage='Usage: ./configure [options] target
2425
@@ -113,7 +114,8 @@ case "$target" in
113114
asm_supports_cfi=false
114115
clinker="${toolprefix}dcc"
115116
libmath="-lm"
116-
cchecklink=${build_checklink};;
117+
cchecklink=${build_checklink}
118+
advanced_debug=true;;
117119
arm*-*)
118120
arch="arm"
119121
case "$target" in
@@ -357,6 +359,7 @@ LIBMATH=$libmath
357359
HAS_RUNTIME_LIB=$has_runtime_lib
358360
CCHECKLINK=$cchecklink
359361
ASM_SUPPORTS_CFI=$asm_supports_cfi
362+
ADVANCED_DEBUG=$advanced_debug
360363
EOF
361364
else
362365
cat >> Makefile.config <<'EOF'

cparser/Cutil.mli

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ val incomplete_type : Env.t -> typ -> bool
9494
declared but not defined struct or union, or array type without a size. *)
9595
val sizeof_ikind: ikind -> int
9696
(* Return the size of the given integer kind. *)
97+
val sizeof_fkind: fkind -> int
98+
(* Return the size of the given float kind. *)
9799
val is_signed_ikind: ikind -> bool
98100
(* Return true if the given integer kind is signed, false if unsigned. *)
99101

cparser/Parse.ml

+13-8
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@
1717

1818
module CharSet = Set.Make(struct type t = char let compare = compare end)
1919

20-
let transform_program t p =
20+
let transform_program t p name =
2121
let run_pass pass flag p = if CharSet.mem flag t then pass p else p in
22-
Rename.program
23-
(run_pass StructReturn.program 's'
22+
let p1 = (run_pass StructReturn.program 's'
2423
(run_pass PackedStructs.program 'p'
2524
(run_pass Bitfields.program 'f'
2625
(run_pass Unblock.program 'b'
27-
p))))
26+
p)))) in
27+
let debug =
28+
if !Clflags.option_g && Configuration.advanced_debug then
29+
Some (CtoDwarf.program_to_dwarf p p1 name)
30+
else
31+
None in
32+
(Rename.program p1),debug
2833

2934
let parse_transformations s =
3035
let t = ref CharSet.empty in
@@ -41,7 +46,7 @@ let parse_transformations s =
4146
let preprocessed_file transfs name sourcefile =
4247
Cerrors.reset();
4348
let ic = open_in sourcefile in
44-
let p =
49+
let p,d =
4550
try
4651
let t = parse_transformations transfs in
4752
let lb = Lexer.init name ic in
@@ -57,9 +62,9 @@ let preprocessed_file transfs name sourcefile =
5762
| Parser.Parser.Inter.Timeout_pr -> assert false
5863
| Parser.Parser.Inter.Parsed_pr (ast, _ ) -> ast) in
5964
let p1 = Timing.time "Elaboration" Elab.elab_file ast in
60-
Timing.time2 "Emulations" transform_program t p1
65+
Timing.time2 "Emulations" transform_program t p1 name
6166
with
6267
| Cerrors.Abort ->
63-
[] in
68+
[],None in
6469
close_in ic;
65-
if Cerrors.check_errors() then None else Some p
70+
if Cerrors.check_errors() then None,None else Some p,d

cparser/Parse.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
(* Entry point for the library: parse, elaborate, and transform *)
1717

18-
val preprocessed_file: string -> string -> string -> C.program option
18+
val preprocessed_file: string -> string -> string -> C.program option * DwarfTypes.dw_entry option
1919

2020
(* first arg: desired transformations
2121
second arg: source file name before preprocessing

0 commit comments

Comments
 (0)