]>
Commit | Line | Data |
---|---|---|
aeee4812 | 1 | # Copyright (C) 2001-2023 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], | |
abbdb623 | 34 | phrs [HARD_REG_SET] |
2c2e9f7a AM |
35 | pp, pbs, pcfun |
36 | ||
37 | They are generally implemented by calling a function that prints to stderr, | |
38 | and therefore will not work when the compiler is not executing. | |
39 | ||
40 | Most shorthands accept an optional argument. When it is not supplied, | |
41 | they use value in GDB register $, i.e. the last printed value. | |
42 | end | |
43 | ||
b3147e59 | 44 | define pp |
2c2e9f7a AM |
45 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
46 | call debug ($debug_arg) | |
b3147e59 JM |
47 | end |
48 | ||
49 | document pp | |
ee42f826 | 50 | GCC hook: debug (<multiple overloads>) |
2c2e9f7a AM |
51 | Print a representation of any GCC data structure for which an instance of |
52 | overloaded function 'debug' is available. | |
53 | See also 'help-gcc-hooks'. | |
b3147e59 JM |
54 | end |
55 | ||
861bb6c1 | 56 | define pr |
2c2e9f7a AM |
57 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
58 | call debug_rtx ($debug_arg) | |
861bb6c1 JL |
59 | end |
60 | ||
61 | document pr | |
ee42f826 | 62 | GCC hook: debug_rtx (rtx) |
2c2e9f7a AM |
63 | Print the full structure of given rtx. |
64 | See also 'help-gcc-hooks'. | |
861bb6c1 JL |
65 | end |
66 | ||
67 | define prl | |
2c2e9f7a AM |
68 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
69 | call debug_rtx_list ($debug_arg, debug_rtx_count) | |
861bb6c1 JL |
70 | end |
71 | ||
72 | document prl | |
ee42f826 | 73 | GCC hook: debug_rtx_list (rtx) |
2c2e9f7a | 74 | Print the full structure of all rtx insns beginning at given rtx. |
861bb6c1 | 75 | Uses variable debug_rtx_count to control number of insns printed: |
2c2e9f7a AM |
76 | debug_rtx_count > 0: print from given rtx on. |
77 | debug_rtx_count < 0: print a window around given rtx. | |
861bb6c1 JL |
78 | |
79 | There is also debug_rtx_find (rtx, uid) that will scan a list for UID and print | |
80 | it using debug_rtx_list. Usage example: set $foo=debug_rtx_find(first, 42) | |
81 | end | |
82 | ||
83 | define pt | |
2c2e9f7a AM |
84 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
85 | call debug_tree ($debug_arg) | |
861bb6c1 JL |
86 | end |
87 | ||
88 | document pt | |
ee42f826 | 89 | GCC hook: debug_tree (tree) |
2c2e9f7a AM |
90 | Print the full structure of given tree. |
91 | See also 'help-gcc-hooks'. | |
861bb6c1 JL |
92 | end |
93 | ||
b9d8832d | 94 | define pct |
2c2e9f7a AM |
95 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
96 | call debug_c_tree ($debug_arg) | |
b9d8832d JM |
97 | end |
98 | ||
99 | document pct | |
ee42f826 | 100 | GCC hook: debug_c_tree (tree) |
2c2e9f7a AM |
101 | Print given tree in C syntax. |
102 | See also 'help-gcc-hooks'. | |
b9d8832d JM |
103 | end |
104 | ||
f8bf9252 | 105 | define pgg |
2c2e9f7a AM |
106 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
107 | call debug_gimple_stmt ($debug_arg) | |
f8bf9252 SP |
108 | end |
109 | ||
110 | document pgg | |
ee42f826 | 111 | GCC hook: debug_gimple_stmt (gimple) |
2c2e9f7a AM |
112 | Print given GIMPLE statement in C syntax. |
113 | See also 'help-gcc-hooks'. | |
f8bf9252 SP |
114 | end |
115 | ||
6e7e763e | 116 | define pgq |
2c2e9f7a AM |
117 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
118 | call debug_gimple_seq ($debug_arg) | |
6e7e763e JM |
119 | end |
120 | ||
121 | document pgq | |
ee42f826 | 122 | GCC hook: debug_gimple_seq (gimple_seq) |
2c2e9f7a AM |
123 | Print given GIMPLE sequence in C syntax. |
124 | See also 'help-gcc-hooks'. | |
6e7e763e JM |
125 | end |
126 | ||
6de9cd9a | 127 | define pgs |
2c2e9f7a AM |
128 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
129 | call debug_generic_stmt ($debug_arg) | |
6de9cd9a DN |
130 | end |
131 | ||
132 | document pgs | |
ee42f826 | 133 | GCC hook: debug_generic_stmt (tree) |
2c2e9f7a AM |
134 | Print given GENERIC statement in C syntax. |
135 | See also 'help-gcc-hooks'. | |
6de9cd9a DN |
136 | end |
137 | ||
138 | define pge | |
2c2e9f7a AM |
139 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
140 | call debug_generic_expr ($debug_arg) | |
6de9cd9a DN |
141 | end |
142 | ||
143 | document pge | |
ee42f826 | 144 | GCC hook: debug_generic_expr (tree) |
2c2e9f7a AM |
145 | Print given GENERIC expression in C syntax. |
146 | See also 'help-gcc-hooks'. | |
6de9cd9a DN |
147 | end |
148 | ||
abbdb623 HPN |
149 | define phrs |
150 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" | |
151 | call debug_hard_reg_set ($debug_arg) | |
152 | end | |
153 | ||
154 | document phrs | |
155 | GCC hook: debug_hard_reg_set (HARD_REG_SET) | |
156 | Print given HARD_REG_SET. | |
157 | See also 'help-gcc-hooks'. | |
158 | end | |
159 | ||
605be31e | 160 | define pmz |
2c2e9f7a AM |
161 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
162 | call mpz_out_str(stderr, 10, $debug_arg) | |
605be31e MS |
163 | end |
164 | ||
165 | document pmz | |
ee42f826 | 166 | GCC hook: mpz_out_str (mpz_t) |
2c2e9f7a AM |
167 | Print given mpz value. |
168 | See also 'help-gcc-hooks'. | |
605be31e MS |
169 | end |
170 | ||
861bb6c1 | 171 | define ptc |
2c2e9f7a AM |
172 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
173 | output (enum tree_code) $debug_arg.base.code | |
861bb6c1 JL |
174 | echo \n |
175 | end | |
176 | ||
177 | document ptc | |
ee42f826 | 178 | GCC hook: TREE_CODE (tree) |
2c2e9f7a AM |
179 | Print the tree-code of given tree node. |
180 | See also 'help-gcc-hooks'. | |
861bb6c1 JL |
181 | end |
182 | ||
183 | define pdn | |
2c2e9f7a AM |
184 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
185 | output $debug_arg.decl_minimal.name->identifier.id.str | |
861bb6c1 JL |
186 | echo \n |
187 | end | |
188 | ||
189 | document pdn | |
ee42f826 | 190 | GCC hook: IDENTIFIER_POINTER (DECL_NAME (tree)) |
2c2e9f7a AM |
191 | Print the name of given decl-node. |
192 | See also 'help-gcc-hooks'. | |
861bb6c1 JL |
193 | end |
194 | ||
195 | define ptn | |
2c2e9f7a AM |
196 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
197 | output $debug_arg.type.name->decl_minimal.name->identifier.id.str | |
861bb6c1 JL |
198 | echo \n |
199 | end | |
200 | ||
201 | document ptn | |
ee42f826 | 202 | GCC hook: IDENTIFIER_POINTER (DECL_NAME (TREE_TYPE (tree))) |
2c2e9f7a AM |
203 | Print the name of given type-node. |
204 | See also 'help-gcc-hooks'. | |
861bb6c1 JL |
205 | end |
206 | ||
b042534c | 207 | define pdd |
2c2e9f7a AM |
208 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
209 | call debug_dwarf_die ($debug_arg) | |
b042534c JM |
210 | end |
211 | ||
212 | document pdd | |
ee42f826 | 213 | GCC hook: debug_dwarf_die (dw_die_ref) |
2c2e9f7a AM |
214 | Print given dw_die_ref. |
215 | See also 'help-gcc-hooks'. | |
b042534c JM |
216 | end |
217 | ||
861bb6c1 | 218 | define prc |
2c2e9f7a AM |
219 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
220 | output (enum rtx_code) $debug_arg.code | |
861bb6c1 | 221 | echo \ ( |
2c2e9f7a | 222 | output $debug_arg.mode |
861bb6c1 JL |
223 | echo )\n |
224 | end | |
225 | ||
226 | document prc | |
ee42f826 | 227 | GCC hook: GET_CODE (rtx) |
2c2e9f7a AM |
228 | Print the rtx-code and machine mode of given rtx. |
229 | See also 'help-gcc-hooks'. | |
861bb6c1 JL |
230 | end |
231 | ||
232 | define pi | |
2c2e9f7a AM |
233 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
234 | print $debug_arg.u.fld[0].rt_rtx@7 | |
861bb6c1 JL |
235 | end |
236 | ||
237 | document pi | |
ee42f826 | 238 | GCC hook: X0EXP (rtx_insn) |
2c2e9f7a AM |
239 | Print the fields of given RTL instruction. |
240 | See also 'help-gcc-hooks'. | |
861bb6c1 JL |
241 | end |
242 | ||
243 | define pbs | |
582097cb | 244 | call print_binding_stack () |
861bb6c1 JL |
245 | end |
246 | ||
247 | document pbs | |
248 | In cc1plus, print the current binding stack, frame by frame, up to and | |
249 | including the global binding level. | |
250 | end | |
251 | ||
55a9c4b2 | 252 | define pbm |
2c2e9f7a AM |
253 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
254 | call bitmap_print (stderr, $debug_arg, "", "\n") | |
55a9c4b2 HPN |
255 | end |
256 | ||
257 | document pbm | |
ee42f826 | 258 | GCC hook: bitmap_print (bitmap) |
2c2e9f7a AM |
259 | Dump given bitmap as a comma-separated list of numbers. |
260 | See also 'help-gcc-hooks'. | |
55a9c4b2 HPN |
261 | end |
262 | ||
71e55f04 | 263 | define pel |
2c2e9f7a AM |
264 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
265 | output expand_location ($debug_arg) | |
71e55f04 MP |
266 | echo \n |
267 | end | |
268 | ||
269 | document pel | |
ee42f826 | 270 | GCC hook: expand_location (location_t) |
2c2e9f7a AM |
271 | Print given location. |
272 | See also 'help-gcc-hooks'. | |
71e55f04 MP |
273 | end |
274 | ||
2e1a9cdb MP |
275 | define pcfun |
276 | output debug_function (cfun ? cfun->decl : current_function_decl, 0) | |
277 | echo \n | |
278 | end | |
279 | ||
280 | document pcfun | |
281 | Print current function. | |
282 | end | |
283 | ||
7c83619c | 284 | define trt |
2c2e9f7a AM |
285 | eval "set $debug_arg = $%s", $argc ? "arg0" : "" |
286 | print ($debug_arg.typed.type) | |
7c83619c ML |
287 | end |
288 | ||
289 | document trt | |
ee42f826 | 290 | GCC hook: TREE_TYPE (tree) |
2c2e9f7a AM |
291 | Print TREE_TYPE of given tree node. |
292 | See also 'help-gcc-hooks'. | |
7c83619c ML |
293 | end |
294 | ||
6e72eb34 DM |
295 | define break-on-diagnostic |
296 | break diagnostic_show_locus | |
297 | end | |
298 | ||
299 | document break-on-diagnostic | |
300 | Put a breakpoint on diagnostic_show_locus, called whenever a diagnostic | |
301 | is emitted (as opposed to those warnings that are suppressed by | |
302 | command-line options). | |
303 | end | |
304 | ||
757bf1df | 305 | define break-on-saved-diagnostic |
75038aa6 | 306 | break ana::diagnostic_manager::add_diagnostic |
757bf1df DM |
307 | end |
308 | ||
309 | document break-on-saved-diagnostic | |
75038aa6 | 310 | Put a breakpoint on ana::diagnostic_manager::add_diagnostic, called within |
757bf1df DM |
311 | the analyzer whenever a diagnostic is saved for later de-duplication and |
312 | possible emission. | |
313 | end | |
314 | ||
d894bafc VI |
315 | define reload-gdbhooks |
316 | python import imp; imp.reload(gdbhooks) | |
317 | end | |
318 | ||
319 | document reload-gdbhooks | |
320 | Load the gdbhooks.py module again in order to pick up any changes made to it. | |
321 | end | |
322 | ||
323 | alias rh = reload-gdbhooks | |
324 | ||
0823efed DN |
325 | # Define some macros helpful to gdb when it is expanding macros. |
326 | macro define __FILE__ "gdb" | |
327 | macro define __LINE__ 1 | |
b57ca59b | 328 | macro define __FUNCTION__ "gdb" |
0bfdb81e | 329 | macro define __null 0 |
2a0da5ad JM |
330 | macro define input_line expand_location(input_location).line |
331 | macro define input_filename expand_location(input_location).file | |
0823efed | 332 | |
35a5722c JJ |
333 | # Remember previous pagination status and turn it off, so that |
334 | # the messages for skip commands don't require pagination. | |
335 | python __gcc_prev_pagination=gdb.parameter("pagination") | |
336 | set pagination off | |
337 | ||
0823efed DN |
338 | # Gracefully handle aborts in functions used from gdb. |
339 | set unwindonsignal on | |
340 | ||
22c4957e MM |
341 | # Put breakpoints at exit and fancy_abort in case abort is mapped |
342 | # to either fprintf/exit or fancy_abort. | |
22c4957e MM |
343 | b fancy_abort |
344 | ||
c9092111 BE |
345 | # Put a breakpoint on internal_error to help with debugging ICEs. |
346 | b internal_error | |
347 | ||
3a7f50dc | 348 | set complaints 0 |
b14a4f5a AS |
349 | # Don't let abort actually run, as it will make |
350 | # stdio stop working and therefore the `pr' command above as well. | |
351 | # Put this last because gcc does not reference it any more unless | |
352 | # USE_SYSTEM_ABORT is defined, so gdb may complain and bail out. | |
3aed1981 | 353 | b exit |
b14a4f5a | 354 | b abort |
0823efed | 355 | |
2a936959 JL |
356 | # Disable strict type checking. This allows developers to (for example) |
357 | # make inferior calls without casting absolute address to a suitable | |
358 | # pointer type. | |
359 | set check type off | |
360 | ||
0823efed DN |
361 | # Skip all inline functions in tree.h. |
362 | # These are used in accessor macros. | |
363 | # Note that this is added at the end because older gdb versions | |
364 | # do not understand the 'skip' command. | |
08216dfb | 365 | # See https://sourceware.org/gdb/current/onlinedocs/gdb/Skipping-Over-Functions-and-Files.html |
865ea646 | 366 | skip file tree.h |
08216dfb | 367 | |
e6e860a2 JM |
368 | # Also skip inline functions in is-a.h. |
369 | skip file is-a.h | |
370 | ||
0d1892d2 JM |
371 | # And line-map.h. |
372 | skip file line-map.h | |
373 | ||
e1d74c91 JM |
374 | # And timevar.h. |
375 | skip file timevar.h | |
376 | ||
08216dfb DM |
377 | # Likewise, skip various inline functions in rtl.h. |
378 | skip rtx_expr_list::next | |
379 | skip rtx_expr_list::element | |
380 | skip rtx_insn_list::next | |
381 | skip rtx_insn_list::insn | |
382 | skip rtx_sequence::len | |
383 | skip rtx_sequence::element | |
384 | skip rtx_sequence::insn | |
385 | skip INSN_UID | |
386 | skip PREV_INSN | |
387 | skip SET_PREV_INSN | |
388 | skip NEXT_INSN | |
389 | skip SET_NEXT_INSN | |
390 | skip BLOCK_FOR_INSN | |
391 | skip PATTERN | |
392 | skip INSN_LOCATION | |
393 | skip INSN_HAS_LOCATION | |
394 | skip JUMP_LABEL_AS_INSN | |
35a5722c JJ |
395 | |
396 | # Restore pagination to the previous state. | |
397 | python if __gcc_prev_pagination: gdb.execute("set pagination on") |