Line data Source code
1 : /* Debug hooks for GCC.
2 : Copyright (C) 2001-2026 Free Software Foundation, Inc.
3 :
4 : This program is free software; you can redistribute it and/or modify it
5 : under the terms of the GNU General Public License as published by the
6 : Free Software Foundation; either version 3, or (at your option) any
7 : later version.
8 :
9 : This program is distributed in the hope that it will be useful,
10 : but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : GNU General Public License for more details.
13 :
14 : You should have received a copy of the GNU General Public License
15 : along with this program; see the file COPYING3. If not see
16 : <http://www.gnu.org/licenses/>. */
17 :
18 : #ifndef GCC_DEBUG_H
19 : #define GCC_DEBUG_H
20 :
21 : /* This structure contains hooks for the debug information output
22 : functions, accessed through the global instance debug_hooks set in
23 : toplev.cc according to command line options. */
24 : /* WARNING: Do not add new debug hook targets - DWARF will be the only
25 : way to speak debug to the middle-end once we are able to get rid of
26 : the remaining targets. If you need alternate output formats instead
27 : generate them off the DWARF representation. */
28 :
29 : /* Kinds of references to early DWARF DIEs. */
30 : enum debug_external_ref_kind
31 : {
32 : DEBUG_DIE_REF,
33 : DEBUG_ABSTRACT_ORIGIN_REF
34 : };
35 :
36 : struct gcc_debug_hooks
37 : {
38 : /* Initialize debug output. MAIN_FILENAME is the name of the main
39 : input file. */
40 : void (* init) (const char *main_filename);
41 :
42 : /* Output debug symbols. */
43 : void (* finish) (const char *main_filename);
44 :
45 : /* Run cleanups necessary after early debug generation. */
46 : void (* early_finish) (const char *main_filename);
47 :
48 : /* Called from cgraph_optimize before starting to assemble
49 : functions/variables/toplevel asms. */
50 : void (* assembly_start) (void);
51 :
52 : /* Macro defined on line LINE with name and expansion TEXT. */
53 : void (* define) (unsigned int line, const char *text);
54 :
55 : /* MACRO undefined on line LINE. */
56 : void (* undef) (unsigned int line, const char *macro);
57 :
58 : /* Record the beginning of a new source file FILE from LINE number
59 : in the previous one. */
60 : void (* start_source_file) (unsigned int line, const char *file);
61 :
62 : /* Record the resumption of a source file. LINE is the line number
63 : in the source file we are returning to. */
64 : void (* end_source_file) (unsigned int line);
65 :
66 : /* Record the beginning of block N, counting from 1 and not
67 : including the function-scope block, at LINE. */
68 : void (* begin_block) (unsigned int line, unsigned int n, tree block);
69 :
70 : /* Record the end of a block. Arguments as for begin_block. */
71 : void (* end_block) (unsigned int line, unsigned int n);
72 :
73 : /* Returns nonzero if it is appropriate not to emit any debugging
74 : information for BLOCK, because it doesn't contain any
75 : instructions. This may not be the case for blocks containing
76 : nested functions, since we may actually call such a function even
77 : though the BLOCK information is messed up. Defaults to true. */
78 : bool (* ignore_block) (const_tree);
79 :
80 : /* Record a source file location at (FILE, LINE, COLUMN, DISCRIMINATOR). */
81 : void (* source_line) (unsigned int line, unsigned int column,
82 : const char *file, int discriminator, bool is_stmt);
83 :
84 : /* Record a source file location for a DECL_IGNORED_P function. */
85 : void (* set_ignored_loc) (unsigned int line, unsigned int column,
86 : const char *file);
87 :
88 : /* Called at start of prologue code. LINE is the first line in the
89 : function. */
90 : void (* begin_prologue) (unsigned int line, unsigned int column,
91 : const char *file);
92 :
93 : /* Called at end of prologue code. LINE is the first line in the
94 : function. */
95 : void (* end_prologue) (unsigned int line, const char *file);
96 :
97 : /* Called at beginning of epilogue code. */
98 : void (* begin_epilogue) (unsigned int line, const char *file);
99 :
100 : /* Record end of epilogue code. */
101 : void (* end_epilogue) (unsigned int line, const char *file);
102 :
103 : /* Called at start of function DECL, before it is declared. */
104 : void (* begin_function) (tree decl);
105 :
106 : /* Record end of function. LINE is highest line number in function. */
107 : void (* end_function) (unsigned int line);
108 :
109 : /* Register UNIT as the main translation unit. Called from front-ends when
110 : they create their main translation unit. */
111 : void (* register_main_translation_unit) (tree);
112 :
113 : /* Debug information for a function DECL. This might include the
114 : function name (a symbol), its parameters, and the block that
115 : makes up the function's body, and the local variables of the
116 : function.
117 :
118 : This is only called for FUNCTION_DECLs. It is part of the late
119 : debug pass and is called from rest_of_handle_final.
120 :
121 : Location information is available at this point.
122 :
123 : See the documentation for early_global_decl and late_global_decl
124 : for other entry points into the debugging back-ends for DECLs. */
125 : void (* function_decl) (tree decl);
126 :
127 : /* Debug information for a global DECL. Called from the parser
128 : after the parsing process has finished.
129 :
130 : This gets called for both variables and functions.
131 :
132 : Location information is not available at this point, but it is a
133 : good probe point to get access to symbols before they get
134 : optimized away.
135 :
136 : This hook may be called on VAR_DECLs or FUNCTION_DECLs. It is up
137 : to the hook to use what it needs. */
138 : void (* early_global_decl) (tree decl);
139 :
140 : /* Augment debug information generated by early_global_decl with
141 : more complete debug info (if applicable). Called from toplev.cc
142 : after the compilation proper has finished and cgraph information
143 : is available.
144 :
145 : This gets called for both variables and functions.
146 :
147 : Location information is usually available at this point, unless
148 : the hook is being called for a decl that has been optimized away.
149 :
150 : This hook may be called on VAR_DECLs or FUNCTION_DECLs. It is up
151 : to the hook to use what it needs. */
152 : void (* late_global_decl) (tree decl);
153 :
154 : /* Debug information for a type DECL. Called from toplev.cc after
155 : compilation proper, also from various language front ends to
156 : record built-in types. The second argument is properly a
157 : boolean, which indicates whether or not the type is a "local"
158 : type as determined by the language. (It's not a boolean for
159 : legacy reasons.) */
160 : void (* type_decl) (tree decl, int local);
161 :
162 : /* Debug information for imported modules and declarations. */
163 : void (* imported_module_or_decl) (tree decl, tree name,
164 : tree context, bool child,
165 : bool implicit);
166 :
167 : /* Return true if a DIE reference of KIND is available for the tree,
168 : and return its symbol and offset for external use. */
169 : bool (* die_ref_for_decl) (tree, debug_external_ref_kind, const char **,
170 : unsigned HOST_WIDE_INT *);
171 :
172 : /* Record an external early-DWARF reference of KIND for the tree.
173 : A null symbol clears a saved abstract-origin reference. */
174 : void (* register_external_die) (tree, debug_external_ref_kind, const char *,
175 : unsigned HOST_WIDE_INT);
176 :
177 : /* DECL is an inline function, whose body is present, but which is
178 : not being output at this point. */
179 : void (* deferred_inline_function) (tree decl);
180 :
181 : /* DECL is an inline function which is about to be emitted out of
182 : line. The hook is useful to, e.g., emit abstract debug info for
183 : the inline before it gets mangled by optimization. */
184 : void (* outlining_inline_function) (tree decl);
185 :
186 : /* Called from final_scan_insn for any CODE_LABEL insn whose
187 : LABEL_NAME is non-null. */
188 : void (* label) (rtx_code_label *);
189 :
190 : /* Called after the start and before the end of writing a PCH file.
191 : The parameter is 0 if after the start, 1 if before the end. */
192 : void (* handle_pch) (unsigned int);
193 :
194 : /* Called from final_scan_insn for any NOTE_INSN_VAR_LOCATION note. */
195 : void (* var_location) (rtx_insn *);
196 :
197 : /* Called from final_scan_insn for any NOTE_INSN_INLINE_ENTRY note. */
198 : void (* inline_entry) (tree block);
199 :
200 : /* Called from finalize_size_functions for size functions so that their body
201 : can be encoded in the debug info to describe the layout of variable-length
202 : structures. */
203 : void (* size_function) (tree decl);
204 :
205 : /* Called from final_scan_insn if there is a switch between hot and cold
206 : text sections. */
207 : void (* switch_text_section) (void);
208 :
209 : /* Called from grokdeclarator. Replaces the anonymous name with the
210 : type name. */
211 : void (* set_name) (tree, tree);
212 :
213 : /* This is 1 if the debug writer wants to see start and end commands for the
214 : main source files, and 0 otherwise. */
215 : int start_end_main_source_file;
216 :
217 : /* The type of symtab field used by these debug hooks. This is one
218 : of the TYPE_SYMTAB_IS_xxx values defined in tree.h. */
219 : int tree_type_symtab_field;
220 : };
221 :
222 : extern const struct gcc_debug_hooks *debug_hooks;
223 :
224 : /* The do-nothing hooks. */
225 : extern void debug_nothing_void (void);
226 : extern void debug_nothing_charstar (const char *);
227 : extern void debug_nothing_int_int_charstar (unsigned int, unsigned int,
228 : const char *);
229 : extern void debug_nothing_int_charstar (unsigned int, const char *);
230 : extern void debug_nothing_int_int_charstar_int_bool (unsigned int,
231 : unsigned int,
232 : const char *,
233 : int, bool);
234 : extern void debug_nothing_int (unsigned int);
235 : extern void debug_nothing_int_int (unsigned int, unsigned int);
236 : extern void debug_nothing_int_int_tree (unsigned int, unsigned int, tree);
237 : extern void debug_nothing_tree (tree);
238 : extern void debug_nothing_tree_tree (tree, tree);
239 : extern void debug_nothing_tree_int (tree, int);
240 : extern void debug_nothing_tree_tree_tree_bool_bool (tree, tree, tree,
241 : bool, bool);
242 : extern bool debug_true_const_tree (const_tree);
243 : extern void debug_nothing_rtx_insn (rtx_insn *);
244 : extern void debug_nothing_rtx_code_label (rtx_code_label *);
245 : extern bool debug_false_tree_charstarstar_uhwistar
246 : (tree, debug_external_ref_kind, const char **, unsigned HOST_WIDE_INT *);
247 : extern void debug_nothing_tree_charstar_uhwi
248 : (tree, debug_external_ref_kind, const char *, unsigned HOST_WIDE_INT);
249 :
250 : extern void copy_debug_abstract_origin (tree, tree);
251 :
252 : /* Hooks for various debug formats. */
253 : extern const struct gcc_debug_hooks do_nothing_debug_hooks;
254 : extern const struct gcc_debug_hooks xcoff_debug_hooks;
255 : extern const struct gcc_debug_hooks dwarf2_debug_hooks;
256 : extern const struct gcc_debug_hooks dwarf2_lineno_debug_hooks;
257 : extern const struct gcc_debug_hooks vmsdbg_debug_hooks;
258 :
259 : /* Dwarf2 frame information. */
260 :
261 : extern void dwarf2out_begin_prologue (unsigned int, unsigned int,
262 : const char *);
263 : extern void dwarf2out_vms_end_prologue (unsigned int, const char *);
264 : extern void dwarf2out_vms_begin_epilogue (unsigned int, const char *);
265 : extern void dwarf2out_end_epilogue (unsigned int, const char *);
266 : extern void dwarf2out_frame_finish (void);
267 : extern bool dwarf2out_do_eh_frame (void);
268 : extern bool dwarf2out_do_frame (void);
269 : extern bool dwarf2out_do_cfi_asm (void);
270 : extern void dwarf2out_switch_text_section (void);
271 : extern bool dwarf2out_default_as_loc_support (void);
272 : extern bool dwarf2out_default_as_locview_support (void);
273 :
274 : /* For -fdump-go-spec. */
275 :
276 : extern const struct gcc_debug_hooks *
277 : dump_go_spec_init (const char *, const struct gcc_debug_hooks *);
278 :
279 : /* Instance discriminator mapping table. See final.cc. */
280 : typedef hash_map<const_tree, int> decl_to_instance_map_t;
281 : extern decl_to_instance_map_t *decl_to_instance_map;
282 :
283 : /* Allocate decl_to_instance_map with COUNT slots to begin with, if it
284 : * hasn't been allocated yet. */
285 :
286 : inline decl_to_instance_map_t *
287 0 : maybe_create_decl_to_instance_map (int count = 13)
288 : {
289 0 : if (!decl_to_instance_map)
290 0 : decl_to_instance_map = new decl_to_instance_map_t (count);
291 0 : return decl_to_instance_map;
292 : }
293 :
294 : #endif /* !GCC_DEBUG_H */
|