]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | # Copyright (C) 2001-2022 Free Software Foundation, Inc. |
ad41bd84 JM |
2 | # |
3 | # This file is part of GCC. | |
4 | # | |
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) | |
8 | # any later version. | |
9 | # | |
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. | |
14 | # | |
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/>. | |
18 | ||
2c2e9f7a AM |
19 | define help-gcc-hooks |
20 | help help-gcc-hooks | |
21 | end | |
22 | ||
23 | document help-gcc-hooks | |
24 | GCC gdbinit file introduces several debugging shorthands: | |
25 | ||
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], | |
30 | pmz [mpz_t], | |
31 | pdd [dw_die_ref], | |
32 | pbm [bitmap], | |
33 | pel [location_t], | |
34 | pp, pbs, pcfun | |
35 | ||
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. | |
38 | ||
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. | |
41 | end | |
42 | ||
b3147e59 | 43 | define pp |
2c2e9f7a AM |
44 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
45 | call debug ($debug_arg) | |
b3147e59 JM |
46 | end |
47 | ||
48 | document pp | |
ee42f826 | 49 | GCC hook: debug (<multiple overloads>) |
2c2e9f7a AM |
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'. | |
b3147e59 JM |
53 | end |
54 | ||
861bb6c1 | 55 | define pr |
2c2e9f7a AM |
56 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
57 | call debug_rtx ($debug_arg) | |
861bb6c1 JL |
58 | end |
59 | ||
60 | document pr | |
ee42f826 | 61 | GCC hook: debug_rtx (rtx) |
2c2e9f7a AM |
62 | Print the full structure of given rtx. |
63 | See also 'help-gcc-hooks'. | |
861bb6c1 JL |
64 | end |
65 | ||
66 | define prl | |
2c2e9f7a AM |
67 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
68 | call debug_rtx_list ($debug_arg, debug_rtx_count) | |
861bb6c1 JL |
69 | end |
70 | ||
71 | document prl | |
ee42f826 | 72 | GCC hook: debug_rtx_list (rtx) |
2c2e9f7a | 73 | Print the full structure of all rtx insns beginning at given rtx. |
861bb6c1 | 74 | Uses variable debug_rtx_count to control number of insns printed: |
2c2e9f7a AM |
75 | debug_rtx_count > 0: print from given rtx on. |
76 | debug_rtx_count < 0: print a window around given rtx. | |
861bb6c1 JL |
77 | |
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) | |
80 | end | |
81 | ||
82 | define pt | |
2c2e9f7a AM |
83 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
84 | call debug_tree ($debug_arg) | |
861bb6c1 JL |
85 | end |
86 | ||
87 | document pt | |
ee42f826 | 88 | GCC hook: debug_tree (tree) |
2c2e9f7a AM |
89 | Print the full structure of given tree. |
90 | See also 'help-gcc-hooks'. | |
861bb6c1 JL |
91 | end |
92 | ||
b9d8832d | 93 | define pct |
2c2e9f7a AM |
94 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
95 | call debug_c_tree ($debug_arg) | |
b9d8832d JM |
96 | end |
97 | ||
98 | document pct | |
ee42f826 | 99 | GCC hook: debug_c_tree (tree) |
2c2e9f7a AM |
100 | Print given tree in C syntax. |
101 | See also 'help-gcc-hooks'. | |
b9d8832d JM |
102 | end |
103 | ||
f8bf9252 | 104 | define pgg |
2c2e9f7a AM |
105 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
106 | call debug_gimple_stmt ($debug_arg) | |
f8bf9252 SP |
107 | end |
108 | ||
109 | document pgg | |
ee42f826 | 110 | GCC hook: debug_gimple_stmt (gimple) |
2c2e9f7a AM |
111 | Print given GIMPLE statement in C syntax. |
112 | See also 'help-gcc-hooks'. | |
f8bf9252 SP |
113 | end |
114 | ||
6e7e763e | 115 | define pgq |
2c2e9f7a AM |
116 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
117 | call debug_gimple_seq ($debug_arg) | |
6e7e763e JM |
118 | end |
119 | ||
120 | document pgq | |
ee42f826 | 121 | GCC hook: debug_gimple_seq (gimple_seq) |
2c2e9f7a AM |
122 | Print given GIMPLE sequence in C syntax. |
123 | See also 'help-gcc-hooks'. | |
6e7e763e JM |
124 | end |
125 | ||
6de9cd9a | 126 | define pgs |
2c2e9f7a AM |
127 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
128 | call debug_generic_stmt ($debug_arg) | |
6de9cd9a DN |
129 | end |
130 | ||
131 | document pgs | |
ee42f826 | 132 | GCC hook: debug_generic_stmt (tree) |
2c2e9f7a AM |
133 | Print given GENERIC statement in C syntax. |
134 | See also 'help-gcc-hooks'. | |
6de9cd9a DN |
135 | end |
136 | ||
137 | define pge | |
2c2e9f7a AM |
138 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
139 | call debug_generic_expr ($debug_arg) | |
6de9cd9a DN |
140 | end |
141 | ||
142 | document pge | |
ee42f826 | 143 | GCC hook: debug_generic_expr (tree) |
2c2e9f7a AM |
144 | Print given GENERIC expression in C syntax. |
145 | See also 'help-gcc-hooks'. | |
6de9cd9a DN |
146 | end |
147 | ||
605be31e | 148 | define pmz |
2c2e9f7a AM |
149 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
150 | call mpz_out_str(stderr, 10, $debug_arg) | |
605be31e MS |
151 | end |
152 | ||
153 | document pmz | |
ee42f826 | 154 | GCC hook: mpz_out_str (mpz_t) |
2c2e9f7a AM |
155 | Print given mpz value. |
156 | See also 'help-gcc-hooks'. | |
605be31e MS |
157 | end |
158 | ||
861bb6c1 | 159 | define ptc |
2c2e9f7a AM |
160 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
161 | output (enum tree_code) $debug_arg.base.code | |
861bb6c1 JL |
162 | echo \n |
163 | end | |
164 | ||
165 | document ptc | |
ee42f826 | 166 | GCC hook: TREE_CODE (tree) |
2c2e9f7a AM |
167 | Print the tree-code of given tree node. |
168 | See also 'help-gcc-hooks'. | |
861bb6c1 JL |
169 | end |
170 | ||
171 | define pdn | |
2c2e9f7a AM |
172 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
173 | output $debug_arg.decl_minimal.name->identifier.id.str | |
861bb6c1 JL |
174 | echo \n |
175 | end | |
176 | ||
177 | document pdn | |
ee42f826 | 178 | GCC hook: IDENTIFIER_POINTER (DECL_NAME (tree)) |
2c2e9f7a AM |
179 | Print the name of given decl-node. |
180 | See also 'help-gcc-hooks'. | |
861bb6c1 JL |
181 | end |
182 | ||
183 | define ptn | |
2c2e9f7a AM |
184 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
185 | output $debug_arg.type.name->decl_minimal.name->identifier.id.str | |
861bb6c1 JL |
186 | echo \n |
187 | end | |
188 | ||
189 | document ptn | |
ee42f826 | 190 | GCC hook: IDENTIFIER_POINTER (DECL_NAME (TREE_TYPE (tree))) |
2c2e9f7a AM |
191 | Print the name of given type-node. |
192 | See also 'help-gcc-hooks'. | |
861bb6c1 JL |
193 | end |
194 | ||
b042534c | 195 | define pdd |
2c2e9f7a AM |
196 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
197 | call debug_dwarf_die ($debug_arg) | |
b042534c JM |
198 | end |
199 | ||
200 | document pdd | |
ee42f826 | 201 | GCC hook: debug_dwarf_die (dw_die_ref) |
2c2e9f7a AM |
202 | Print given dw_die_ref. |
203 | See also 'help-gcc-hooks'. | |
b042534c JM |
204 | end |
205 | ||
861bb6c1 | 206 | define prc |
2c2e9f7a AM |
207 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
208 | output (enum rtx_code) $debug_arg.code | |
861bb6c1 | 209 | echo \ ( |
2c2e9f7a | 210 | output $debug_arg.mode |
861bb6c1 JL |
211 | echo )\n |
212 | end | |
213 | ||
214 | document prc | |
ee42f826 | 215 | GCC hook: GET_CODE (rtx) |
2c2e9f7a AM |
216 | Print the rtx-code and machine mode of given rtx. |
217 | See also 'help-gcc-hooks'. | |
861bb6c1 JL |
218 | end |
219 | ||
220 | define pi | |
2c2e9f7a AM |
221 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
222 | print $debug_arg.u.fld[0].rt_rtx@7 | |
861bb6c1 JL |
223 | end |
224 | ||
225 | document pi | |
ee42f826 | 226 | GCC hook: X0EXP (rtx_insn) |
2c2e9f7a AM |
227 | Print the fields of given RTL instruction. |
228 | See also 'help-gcc-hooks'. | |
861bb6c1 JL |
229 | end |
230 | ||
231 | define pbs | |
582097cb | 232 | call print_binding_stack () |
861bb6c1 JL |
233 | end |
234 | ||
235 | document pbs | |
236 | In cc1plus, print the current binding stack, frame by frame, up to and | |
237 | including the global binding level. | |
238 | end | |
239 | ||
55a9c4b2 | 240 | define pbm |
2c2e9f7a AM |
241 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
242 | call bitmap_print (stderr, $debug_arg, "", "\n") | |
55a9c4b2 HPN |
243 | end |
244 | ||
245 | document pbm | |
ee42f826 | 246 | GCC hook: bitmap_print (bitmap) |
2c2e9f7a AM |
247 | Dump given bitmap as a comma-separated list of numbers. |
248 | See also 'help-gcc-hooks'. | |
55a9c4b2 HPN |
249 | end |
250 | ||
71e55f04 | 251 | define pel |
2c2e9f7a AM |
252 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
253 | output expand_location ($debug_arg) | |
71e55f04 MP |
254 | echo \n |
255 | end | |
256 | ||
257 | document pel | |
ee42f826 | 258 | GCC hook: expand_location (location_t) |
2c2e9f7a AM |
259 | Print given location. |
260 | See also 'help-gcc-hooks'. | |
71e55f04 MP |
261 | end |
262 | ||
2e1a9cdb MP |
263 | define pcfun |
264 | output debug_function (cfun ? cfun->decl : current_function_decl, 0) | |
265 | echo \n | |
266 | end | |
267 | ||
268 | document pcfun | |
269 | Print current function. | |
270 | end | |
271 | ||
7c83619c | 272 | define trt |
2c2e9f7a AM |
273 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
274 | print ($debug_arg.typed.type) | |
7c83619c ML |
275 | end |
276 | ||
277 | document trt | |
ee42f826 | 278 | GCC hook: TREE_TYPE (tree) |
2c2e9f7a AM |
279 | Print TREE_TYPE of given tree node. |
280 | See also 'help-gcc-hooks'. | |
7c83619c ML |
281 | end |
282 | ||
6e72eb34 DM |
283 | define break-on-diagnostic |
284 | break diagnostic_show_locus | |
285 | end | |
286 | ||
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). | |
291 | end | |
292 | ||
757bf1df | 293 | define break-on-saved-diagnostic |
75038aa6 | 294 | break ana::diagnostic_manager::add_diagnostic |
757bf1df DM |
295 | end |
296 | ||
297 | document break-on-saved-diagnostic | |
75038aa6 | 298 | Put a breakpoint on ana::diagnostic_manager::add_diagnostic, called within |
757bf1df DM |
299 | the analyzer whenever a diagnostic is saved for later de-duplication and |
300 | possible emission. | |
301 | end | |
302 | ||
d894bafc VI |
303 | define reload-gdbhooks |
304 | python import imp; imp.reload(gdbhooks) | |
305 | end | |
306 | ||
307 | document reload-gdbhooks | |
308 | Load the gdbhooks.py module again in order to pick up any changes made to it. | |
309 | end | |
310 | ||
311 | alias rh = reload-gdbhooks | |
312 | ||
0823efed DN |
313 | # Define some macros helpful to gdb when it is expanding macros. |
314 | macro define __FILE__ "gdb" | |
315 | macro define __LINE__ 1 | |
b57ca59b | 316 | macro define __FUNCTION__ "gdb" |
0bfdb81e | 317 | macro define __null 0 |
2a0da5ad JM |
318 | macro define input_line expand_location(input_location).line |
319 | macro define input_filename expand_location(input_location).file | |
0823efed | 320 | |
35a5722c JJ |
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") | |
324 | set pagination off | |
325 | ||
0823efed DN |
326 | # Gracefully handle aborts in functions used from gdb. |
327 | set unwindonsignal on | |
328 | ||
22c4957e MM |
329 | # Put breakpoints at exit and fancy_abort in case abort is mapped |
330 | # to either fprintf/exit or fancy_abort. | |
22c4957e MM |
331 | b fancy_abort |
332 | ||
c9092111 BE |
333 | # Put a breakpoint on internal_error to help with debugging ICEs. |
334 | b internal_error | |
335 | ||
3a7f50dc | 336 | set complaints 0 |
b14a4f5a AS |
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. | |
3aed1981 | 341 | b exit |
b14a4f5a | 342 | b abort |
0823efed | 343 | |
2a936959 JL |
344 | # Disable strict type checking. This allows developers to (for example) |
345 | # make inferior calls without casting absolute address to a suitable | |
346 | # pointer type. | |
347 | set check type off | |
348 | ||
0823efed DN |
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. | |
08216dfb | 353 | # See https://sourceware.org/gdb/current/onlinedocs/gdb/Skipping-Over-Functions-and-Files.html |
865ea646 | 354 | skip file tree.h |
08216dfb | 355 | |
e6e860a2 JM |
356 | # Also skip inline functions in is-a.h. |
357 | skip file is-a.h | |
358 | ||
0d1892d2 JM |
359 | # And line-map.h. |
360 | skip file line-map.h | |
361 | ||
e1d74c91 JM |
362 | # And timevar.h. |
363 | skip file timevar.h | |
364 | ||
08216dfb DM |
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 | |
373 | skip INSN_UID | |
374 | skip PREV_INSN | |
375 | skip SET_PREV_INSN | |
376 | skip NEXT_INSN | |
377 | skip SET_NEXT_INSN | |
378 | skip BLOCK_FOR_INSN | |
379 | skip PATTERN | |
380 | skip INSN_LOCATION | |
381 | skip INSN_HAS_LOCATION | |
382 | skip JUMP_LABEL_AS_INSN | |
35a5722c JJ |
383 | |
384 | # Restore pagination to the previous state. | |
385 | python if __gcc_prev_pagination: gdb.execute("set pagination on") |