@@ -15,6 +15,7 @@ open AST
15
15
open Asm
16
16
open Camlcoq
17
17
open Datatypes
18
+ open DwarfPrinter
18
19
open PrintAsmaux
19
20
open Printf
20
21
open Sections
@@ -23,6 +24,22 @@ open TargetPrinter
23
24
module Printer (Target :TARGET ) =
24
25
struct
25
26
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
+
26
43
let print_location oc loc =
27
44
if loc <> Cutil. no_loc then Target. print_file_line oc (fst loc) (snd loc)
28
45
@@ -37,16 +54,21 @@ module Printer(Target:TARGET) =
37
54
if not (C2C. atom_is_static name) then
38
55
fprintf oc " .globl %a\n " Target. symbol name;
39
56
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;
40
62
fprintf oc " %a:\n " Target. symbol name;
41
63
print_location oc (C2C. atom_location name);
42
64
Target. cfi_startproc oc;
43
65
Target. print_instructions oc fn;
44
66
Target. cfi_endproc oc;
67
+ print_debug_label oc e;
45
68
Target. print_fun_info oc name;
46
69
Target. emit_constants oc lit;
47
70
Target. print_jumptable oc jmptbl
48
-
49
-
71
+
50
72
let print_init_data oc name id =
51
73
if Str. string_match PrintCsyntax. re_string_literal (extern_atom name) 0
52
74
&& List. for_all (function Init_int8 _ -> true | _ -> false ) id
@@ -87,15 +109,37 @@ module Printer(Target:TARGET) =
87
109
| Gfun (Internal code ) -> print_function oc name code
88
110
| Gfun (External ef ) -> ()
89
111
| 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
+
91
128
end
92
129
93
- let print_program oc p =
130
+ let print_program oc p db =
94
131
let module Target = (val (sel_target () ):TARGET ) in
95
132
let module Printer = Printer (Target ) in
96
133
PrintAnnot. reset_filenames () ;
97
134
PrintAnnot. print_version_and_options oc Target. comment;
98
135
Target. print_prologue oc;
99
136
List. iter (Printer. print_globdef oc) p.prog_defs;
100
137
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
0 commit comments