GCC Middle and Back End API Reference
debug.h
Go to the documentation of this file.
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. */
35
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. */
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. */
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. */
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. */
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. */
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. */
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. */
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. */
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. */
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. */
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. */
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. */
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. */
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. */
220};
221
222extern const struct gcc_debug_hooks *debug_hooks;
223
224/* The do-nothing hooks. */
225extern void debug_nothing_void (void);
226extern void debug_nothing_charstar (const char *);
227extern void debug_nothing_int_int_charstar (unsigned int, unsigned int,
228 const char *);
229extern void debug_nothing_int_charstar (unsigned int, const char *);
230extern void debug_nothing_int_int_charstar_int_bool (unsigned int,
231 unsigned int,
232 const char *,
233 int, bool);
234extern void debug_nothing_int (unsigned int);
235extern void debug_nothing_int_int (unsigned int, unsigned int);
236extern void debug_nothing_int_int_tree (unsigned int, unsigned int, tree);
237extern void debug_nothing_tree (tree);
238extern void debug_nothing_tree_tree (tree, tree);
239extern void debug_nothing_tree_int (tree, int);
241 bool, bool);
243extern void debug_nothing_rtx_insn (rtx_insn *);
246 (tree, debug_external_ref_kind, const char **, unsigned HOST_WIDE_INT *);
248 (tree, debug_external_ref_kind, const char *, unsigned HOST_WIDE_INT);
249
251
252/* Hooks for various debug formats. */
253extern const struct gcc_debug_hooks do_nothing_debug_hooks;
254extern const struct gcc_debug_hooks xcoff_debug_hooks;
255extern const struct gcc_debug_hooks dwarf2_debug_hooks;
257extern const struct gcc_debug_hooks vmsdbg_debug_hooks;
258
259/* Dwarf2 frame information. */
260
261extern void dwarf2out_begin_prologue (unsigned int, unsigned int,
262 const char *);
263extern void dwarf2out_vms_end_prologue (unsigned int, const char *);
264extern void dwarf2out_vms_begin_epilogue (unsigned int, const char *);
265extern void dwarf2out_end_epilogue (unsigned int, const char *);
266extern void dwarf2out_frame_finish (void);
267extern bool dwarf2out_do_eh_frame (void);
268extern bool dwarf2out_do_frame (void);
269extern bool dwarf2out_do_cfi_asm (void);
270extern void dwarf2out_switch_text_section (void);
271extern bool dwarf2out_default_as_loc_support (void);
272extern bool dwarf2out_default_as_locview_support (void);
273
274/* For -fdump-go-spec. */
275
276extern const struct gcc_debug_hooks *
277dump_go_spec_init (const char *, const struct gcc_debug_hooks *);
278
279/* Instance discriminator mapping table. See final.cc. */
282
283/* Allocate decl_to_instance_map with COUNT slots to begin with, if it
284 * hasn't been allocated yet. */
285
293
294#endif /* !GCC_DEBUG_H */
Definition hash-map.h:40
const union tree_node * const_tree
Definition coretypes.h:98
union tree_node * tree
Definition coretypes.h:97
void debug_nothing_rtx_insn(rtx_insn *insn)
Definition debug.cc:102
void debug_nothing_void(void)
Definition debug.cc:71
void debug_nothing_tree_tree(tree t1, tree t2)
Definition debug.cc:81
void debug_nothing_tree_int(tree decl, int local)
Definition debug.cc:157
void debug_nothing_int_int(unsigned int line, unsigned int n)
Definition debug.cc:144
void debug_nothing_tree(tree decl)
Definition debug.cc:76
bool debug_true_const_tree(const_tree block)
Definition debug.cc:96
void debug_nothing_rtx_code_label(rtx_code_label *label)
Definition debug.cc:107
void debug_nothing_charstar(const char *main_filename)
Definition debug.cc:112
void debug_nothing_int_int_charstar(unsigned int line, unsigned int column, const char *text)
Definition debug.cc:123
void debug_nothing_int_charstar(unsigned int line, const char *text)
Definition debug.cc:117
void debug_nothing_int_int_charstar_int_bool(unsigned int line, unsigned int column, const char *text, int discriminator, bool is_stmt)
Definition debug.cc:130
void copy_debug_abstract_origin(tree dest, tree source)
Definition debug.cc:180
void debug_nothing_tree_charstar_uhwi(tree, debug_external_ref_kind, const char *, unsigned HOST_WIDE_INT)
Definition debug.cc:171
const struct gcc_debug_hooks do_nothing_debug_hooks
Definition debug.cc:25
void debug_nothing_int(unsigned int line)
Definition debug.cc:139
void debug_nothing_int_int_tree(unsigned int line, unsigned int n, tree block)
Definition debug.cc:150
bool debug_false_tree_charstarstar_uhwistar(tree, debug_external_ref_kind, const char **, unsigned HOST_WIDE_INT *)
Definition debug.cc:163
void debug_nothing_tree_tree_tree_bool_bool(tree t1, tree t2, tree t3, bool b1, bool b2)
Definition debug.cc:87
void dwarf2out_vms_end_prologue(unsigned int, const char *)
Definition dwarf2out.cc:1157
bool dwarf2out_default_as_locview_support(void)
Definition dwarf2out.cc:3363
void dwarf2out_vms_begin_epilogue(unsigned int, const char *)
Definition dwarf2out.cc:1176
const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
Definition dwarf2out.cc:2946
hash_map< const_tree, int > decl_to_instance_map_t
Definition debug.h:280
void dwarf2out_begin_prologue(unsigned int, unsigned int, const char *)
Definition dwarf2out.cc:1074
const struct gcc_debug_hooks xcoff_debug_hooks
void dwarf2out_switch_text_section(void)
Definition dwarf2out.cc:1298
const struct gcc_debug_hooks * dump_go_spec_init(const char *, const struct gcc_debug_hooks *)
Definition godump.cc:1441
debug_external_ref_kind
Definition debug.h:31
@ DEBUG_DIE_REF
Definition debug.h:32
@ DEBUG_ABSTRACT_ORIGIN_REF
Definition debug.h:33
bool dwarf2out_do_cfi_asm(void)
Definition dwarf2cfi.cc:3738
bool dwarf2out_do_frame(void)
Definition dwarf2cfi.cc:3715
decl_to_instance_map_t * decl_to_instance_map
Definition final.cc:2925
const struct gcc_debug_hooks dwarf2_debug_hooks
Definition dwarf2out.cc:2896
const struct gcc_debug_hooks * debug_hooks
Definition toplev.cc:125
const struct gcc_debug_hooks vmsdbg_debug_hooks
void dwarf2out_frame_finish(void)
Definition dwarf2out.cc:1283
void dwarf2out_end_epilogue(unsigned int, const char *)
Definition dwarf2out.cc:1252
bool dwarf2out_default_as_loc_support(void)
Definition dwarf2out.cc:3350
decl_to_instance_map_t * maybe_create_decl_to_instance_map(int count=13)
Definition debug.h:287
bool dwarf2out_do_eh_frame(void)
Definition dwarf2cfi.cc:3704
Definition genautomata.cc:499
Definition debug.h:37
void(*) begin_epilogue(unsigned int line, const char *file)
Definition debug.h:98
void(*) begin_prologue(unsigned int line, unsigned int column, const char *file)
Definition debug.h:90
int tree_type_symtab_field
Definition debug.h:219
void(*) source_line(unsigned int line, unsigned int column, const char *file, int discriminator, bool is_stmt)
Definition debug.h:81
void(*) label(rtx_code_label *)
Definition debug.h:188
void(*) end_source_file(unsigned int line)
Definition debug.h:64
void(*) outlining_inline_function(tree decl)
Definition debug.h:184
void(*) register_main_translation_unit(tree)
Definition debug.h:111
void(*) begin_function(tree decl)
Definition debug.h:104
void(*) end_prologue(unsigned int line, const char *file)
Definition debug.h:95
void(*) deferred_inline_function(tree decl)
Definition debug.h:179
void(*) register_external_die(tree, debug_external_ref_kind, const char *, unsigned HOST_WIDE_INT)
Definition debug.h:174
void(*) define(unsigned int line, const char *text)
Definition debug.h:53
void(*) set_ignored_loc(unsigned int line, unsigned int column, const char *file)
Definition debug.h:85
void(*) finish(const char *main_filename)
Definition debug.h:43
void(*) set_name(tree, tree)
Definition debug.h:211
void(*) early_finish(const char *main_filename)
Definition debug.h:46
void(*) inline_entry(tree block)
Definition debug.h:198
void(*) type_decl(tree decl, int local)
Definition debug.h:160
void(*) var_location(rtx_insn *)
Definition debug.h:195
bool(*) die_ref_for_decl(tree, debug_external_ref_kind, const char **, unsigned HOST_WIDE_INT *)
Definition debug.h:169
void(*) early_global_decl(tree decl)
Definition debug.h:138
void(*) size_function(tree decl)
Definition debug.h:203
void(*) assembly_start(void)
Definition debug.h:50
void(*) end_function(unsigned int line)
Definition debug.h:107
int start_end_main_source_file
Definition debug.h:215
void(*) handle_pch(unsigned int)
Definition debug.h:192
void(*) end_block(unsigned int line, unsigned int n)
Definition debug.h:71
void(*) late_global_decl(tree decl)
Definition debug.h:152
void(*) begin_block(unsigned int line, unsigned int n, tree block)
Definition debug.h:68
void(*) init(const char *main_filename)
Definition debug.h:40
void(*) imported_module_or_decl(tree decl, tree name, tree context, bool child, bool implicit)
Definition debug.h:163
void(*) start_source_file(unsigned int line, const char *file)
Definition debug.h:60
void(*) function_decl(tree decl)
Definition debug.h:125
bool(*) ignore_block(const_tree)
Definition debug.h:78
void(*) undef(unsigned int line, const char *macro)
Definition debug.h:56
void(*) end_epilogue(unsigned int line, const char *file)
Definition debug.h:101
void(*) switch_text_section(void)
Definition debug.h:207
Definition rtl.h:691
Definition rtl.h:551
#define bool
Definition system.h:830