1 # Copyright (C) 2001-2022 Free Software Foundation, Inc.
3 # This file is part of GCC.
5 # GCC is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3, or (at your option)
10 # GCC is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with GCC; see the file COPYING3. If not see
17 # <http://www.gnu.org/licenses/>.
23 document help-gcc-hooks
24 GCC gdbinit file introduces several debugging shorthands:
26 pr [rtx], prl [rtx], prc [rtx], pi [rtx_insn],
27 pt [tree], pct [tree], ptc [tree], trt [tree],
28 pgs [tree], pge [tree], pdn [tree], ptn [tree],
29 pgg [gimple], pgq [gimple_seq],
36 They are generally implemented by calling a function that prints to stderr,
37 and therefore will not work when the compiler is not executing.
39 Most shorthands accept an optional argument. When it is not supplied,
40 they use value in GDB register $, i.e. the last printed value.
44 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
45 call debug ($debug_arg)
49 GCC hook: debug (<multiple overloads>)
50 Print a representation of any GCC data structure for which an instance of
51 overloaded function 'debug' is available.
52 See also 'help-gcc-hooks'.
56 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
57 call debug_rtx ($debug_arg)
61 GCC hook: debug_rtx (rtx)
62 Print the full structure of given rtx.
63 See also 'help-gcc-hooks'.
67 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
68 call debug_rtx_list ($debug_arg, debug_rtx_count)
72 GCC hook: debug_rtx_list (rtx)
73 Print the full structure of all rtx insns beginning at given rtx.
74 Uses variable debug_rtx_count to control number of insns printed:
75 debug_rtx_count > 0: print from given rtx on.
76 debug_rtx_count < 0: print a window around given rtx.
78 There is also debug_rtx_find (rtx, uid) that will scan a list for UID and print
79 it using debug_rtx_list. Usage example: set $foo=debug_rtx_find(first, 42)
83 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
84 call debug_tree ($debug_arg)
88 GCC hook: debug_tree (tree)
89 Print the full structure of given tree.
90 See also 'help-gcc-hooks'.
94 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
95 call debug_c_tree ($debug_arg)
99 GCC hook: debug_c_tree (tree)
100 Print given tree in C syntax.
101 See also 'help-gcc-hooks'.
105 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
106 call debug_gimple_stmt ($debug_arg)
110 GCC hook: debug_gimple_stmt (gimple)
111 Print given GIMPLE statement in C syntax.
112 See also 'help-gcc-hooks'.
116 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
117 call debug_gimple_seq ($debug_arg)
121 GCC hook: debug_gimple_seq (gimple_seq)
122 Print given GIMPLE sequence in C syntax.
123 See also 'help-gcc-hooks'.
127 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
128 call debug_generic_stmt ($debug_arg)
132 GCC hook: debug_generic_stmt (tree)
133 Print given GENERIC statement in C syntax.
134 See also 'help-gcc-hooks'.
138 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
139 call debug_generic_expr ($debug_arg)
143 GCC hook: debug_generic_expr (tree)
144 Print given GENERIC expression in C syntax.
145 See also 'help-gcc-hooks'.
149 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
150 call mpz_out_str(stderr, 10, $debug_arg)
154 GCC hook: mpz_out_str (mpz_t)
155 Print given mpz value.
156 See also 'help-gcc-hooks'.
160 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
161 output (enum tree_code) $debug_arg.base.code
166 GCC hook: TREE_CODE (tree)
167 Print the tree-code of given tree node.
168 See also 'help-gcc-hooks'.
172 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
173 output $debug_arg.decl_minimal.name->identifier.id.str
178 GCC hook: IDENTIFIER_POINTER (DECL_NAME (tree))
179 Print the name of given decl-node.
180 See also 'help-gcc-hooks'.
184 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
185 output $debug_arg.type.name->decl_minimal.name->identifier.id.str
190 GCC hook: IDENTIFIER_POINTER (DECL_NAME (TREE_TYPE (tree)))
191 Print the name of given type-node.
192 See also 'help-gcc-hooks'.
196 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
197 call debug_dwarf_die ($debug_arg)
201 GCC hook: debug_dwarf_die (dw_die_ref)
202 Print given dw_die_ref.
203 See also 'help-gcc-hooks'.
207 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
208 output (enum rtx_code) $debug_arg.code
210 output $debug_arg.mode
215 GCC hook: GET_CODE (rtx)
216 Print the rtx-code and machine mode of given rtx.
217 See also 'help-gcc-hooks'.
221 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
222 print $debug_arg.u.fld[0].rt_rtx@7
226 GCC hook: X0EXP (rtx_insn)
227 Print the fields of given RTL instruction.
228 See also 'help-gcc-hooks'.
232 call print_binding_stack ()
236 In cc1plus, print the current binding stack, frame by frame, up to and
237 including the global binding level.
241 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
242 call bitmap_print (stderr, $debug_arg, "", "\n")
246 GCC hook: bitmap_print (bitmap)
247 Dump given bitmap as a comma-separated list of numbers.
248 See also 'help-gcc-hooks'.
252 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
253 output expand_location ($debug_arg)
258 GCC hook: expand_location (location_t)
259 Print given location.
260 See also 'help-gcc-hooks'.
264 output debug_function (cfun ? cfun->decl : current_function_decl, 0)
269 Print current function.
273 eval "set $debug_arg = $%s", $argc ? "arg0" : ""
274 print ($debug_arg.typed.type)
278 GCC hook: TREE_TYPE (tree)
279 Print TREE_TYPE of given tree node.
280 See also 'help-gcc-hooks'.
283 define break-on-diagnostic
284 break diagnostic_show_locus
287 document break-on-diagnostic
288 Put a breakpoint on diagnostic_show_locus, called whenever a diagnostic
289 is emitted (as opposed to those warnings that are suppressed by
290 command-line options).
293 define break-on-saved-diagnostic
294 break ana::diagnostic_manager::add_diagnostic
297 document break-on-saved-diagnostic
298 Put a breakpoint on ana::diagnostic_manager::add_diagnostic, called within
299 the analyzer whenever a diagnostic is saved for later de-duplication and
303 define reload-gdbhooks
304 python import imp; imp.reload(gdbhooks)
307 document reload-gdbhooks
308 Load the gdbhooks.py module again in order to pick up any changes made to it.
311 alias rh = reload-gdbhooks
313 # Define some macros helpful to gdb when it is expanding macros.
314 macro define __FILE__ "gdb"
315 macro define __LINE__ 1
316 macro define __FUNCTION__ "gdb"
317 macro define __null 0
318 macro define input_line expand_location(input_location).line
319 macro define input_filename expand_location(input_location).file
321 # Remember previous pagination status and turn it off, so that
322 # the messages for skip commands don't require pagination.
323 python __gcc_prev_pagination=gdb.parameter("pagination")
326 # Gracefully handle aborts in functions used from gdb.
327 set unwindonsignal on
329 # Put breakpoints at exit and fancy_abort in case abort is mapped
330 # to either fprintf/exit or fancy_abort.
333 # Put a breakpoint on internal_error to help with debugging ICEs.
337 # Don't let abort actually run, as it will make
338 # stdio stop working and therefore the `pr' command above as well.
339 # Put this last because gcc does not reference it any more unless
340 # USE_SYSTEM_ABORT is defined, so gdb may complain and bail out.
344 # Disable strict type checking. This allows developers to (for example)
345 # make inferior calls without casting absolute address to a suitable
349 # Skip all inline functions in tree.h.
350 # These are used in accessor macros.
351 # Note that this is added at the end because older gdb versions
352 # do not understand the 'skip' command.
353 # See https://sourceware.org/gdb/current/onlinedocs/gdb/Skipping-Over-Functions-and-Files.html
356 # Also skip inline functions in is-a.h.
365 # Likewise, skip various inline functions in rtl.h.
366 skip rtx_expr_list::next
367 skip rtx_expr_list::element
368 skip rtx_insn_list::next
369 skip rtx_insn_list::insn
370 skip rtx_sequence::len
371 skip rtx_sequence::element
372 skip rtx_sequence::insn
381 skip INSN_HAS_LOCATION
382 skip JUMP_LABEL_AS_INSN
384 # Restore pagination to the previous state.
385 python if __gcc_prev_pagination: gdb.execute("set pagination on")