1 # Copyright
1998-2023 Free Software Foundation
, Inc.
3 # This
program is free software
; you can redistribute it and
/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation
; either version
3 of the License
, or
6 #
(at your option
) any later version.
8 # This
program is distributed in the hope that it will be useful
,
9 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License
for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this
program.
If not
, see
<http
://www.gnu.org
/licenses
/>.
16 # This file was written by Elena Zannoni
(ezannoni@cygnus.com
)
18 # this file tests maintenance commands and help
on those.
20 # source file used is
break.c
23 #maintenance check
-psymtabs
-- Check consistency of psymtabs vs symtabs
24 #maintenance check
-symtabs
-- Check consistency of symtabs
25 #maintenance expand
-symtabs
-- Expand symtabs matching a file regexp
26 #maintenance
set -- Set GDB internal variables used by the GDB maintainer
27 #maintenance
show -- Show GDB internal variables used by the GDB maintainer
28 #maintenance dump
-me
-- Get fatal error
; make debugger dump its core
29 #maintenance print
-- Maintenance command
for printing GDB internal state
30 #maintenance
info -- Commands
for showing internal
info about the
program being debugged
31 #maintenance internal
-error
-- Give GDB an internal error.
33 #maintenance print dummy
-frames
-- Print the dummy frame stack
34 #maintenance print statistics
-- Print statistics about internal gdb state
35 #maintenance print objfiles
-- Print dump of current object file definitions
36 #maintenance print psymbols
-- Print dump of current partial symbol definitions
37 #maintenance print msymbols
-- Print dump of current minimal symbol definitions
38 #maintenance print symbols
-- Print dump of current symbol definitions
39 #maintenance print type
-- Print a type chain
for a given symbol
40 #maintenance print unwind
-- Print unwind table entry at given address
43 #maintenance
info breakpoints
-- Status of all breakpoints
48 standard_testfile
break.c break1.c
50 if {[prepare_for_testing
"failed to prepare" $testfile \
51 [list $srcfile $srcfile2
] {debug nowarnings
}]} {
55 set readnow_p
[readnow
]
57 # The commands we test here produce many lines of output
; disable
"press
58 #
<return> to
continue" prompts.
59 gdb_test_no_output
"set height 0"
61 # Tests that require that no
program is running
63 gdb_file_cmd $
{binfile
}
65 # Test
for a regression where this command would internal
-error
if the
66 #
program wasn
't running. If there's a lot of registers
then this
67 # might overflow expect
's buffers, so process the output line at a
71 set test "maint print registers"
72 gdb_test_multiple $test $test {
73 -re "\[^\r\n\]+Name\[^\r\n\]+Nr\[^\r\n\]+Rel\[^\r\n\]+Offset\[^\r\n\]+Size\[^\r\n\]+Type\[^\r\n\]+\r\n" {
77 -re "^\[^\r\n\]+\[0-9\]+\[^\r\n\]+\[0-9\]+\[^\r\n\]+\[0-9\]+\[^\r\n\]+\[0-9\]+\[^\r\n\]+\r\n" {
81 -re "^\\*\[0-9\]+\[^\r\n\]+\r\n" {
85 gdb_assert { $saw_registers && $saw_headers } $test
89 # Test "mt expand-symtabs" here as it's easier to verify before we
91 gdb_test_no_output
"mt set per on" "mt set per on for expand-symtabs"
92 gdb_test_multiple
"mt expand-symtabs $subdir/break\[.\]c$" \
94 -re
"#compunits: (1|2) \\(\[+\](0|1|2)\\),.*$gdb_prompt $" {
95 # This should expand at most two primary symtabs.
96 #
"Normally" it will not expand any, because the symtab
97 # holding
"main" will already have been expanded, but if the
98 # file is compiled with
-fdebug
-types
-section
then a second primary
99 # symtab
for break.c will be created
for any types.
100 pass
"$gdb_test_name"
102 -re
"#compunits: ($decimal) \\(\[+\]0\\),.*$gdb_prompt $" {
104 pass
"$gdb_test_name"
106 fail
"$gdb_test_name"
110 gdb_test
"mt set per off" ".*" "mt set per off for expand-symtabs"
112 # Tests that can or should be done with a running
program
120 #
If we
're using .gdb_index or .debug_names there will be no psymtabs.
121 set have_gdb_index [ exec_has_index_section ${binfile} ]
123 # There also won't be
any psymtabs
if we read the index from the index
cache.
124 # We can detect this by looking
if the index
-cache is enabled and
if the number
125 # of
cache misses is
0.
126 set index_cache_misses
-1
127 gdb_test_multiple
"show index-cache stats" "check index cache stats" {
128 -re
".*Cache misses \\(this session\\): (\\d+)\r\n.*$gdb_prompt $" {
129 set index_cache_misses $expect_out
(1,string
)
133 set using_index_cache
0
134 gdb_test_multiple
"show index-cache enabled" "check index cache status" {
135 -re
".*is off.\r\n$gdb_prompt $" {
136 set using_index_cache
0
138 -re
".*is on.\r\n$gdb_prompt $" {
139 set using_index_cache
1
143 if { $index_cache_misses
== 0 && $using_index_cache
} {
147 set have_psyms
[expr
! ( $have_gdb_index || $readnow_p
)]
150 # this command does not produce
any output
151 # unless there is some problem with the symtabs and psymtabs
152 # so that branch will really never be covered in this tests here
!!
154 # When there is a problem
, there may be loads of output
, which can
155 # overwhelm the expect buffer. Splitting it seems to fix those
158 set seen_command false
159 gdb_test_multiple
"maint check-psymtabs" "" {
160 -re
"^maint check-psymtabs\r\n" {
161 set seen_command true
165 -re
"^$gdb_prompt $" {
166 gdb_assert
{ $seen_command
} $gdb_test_name
169 -re
"^\[^\r\n\]+\r\n" {
174 # This command does not produce
any output unless there is some problem
175 # with the symtabs
, so that branch will really never be covered in the
177 gdb_test_no_output
"maint check-symtabs"
179 # Test per
-command stats.
180 gdb_test_no_output
"maint set per-command on"
181 set decimal
"\[0-9\]+"
182 set time_fmt
"${decimal}-${decimal}-${decimal} ${decimal}:${decimal}:${decimal}\\.${decimal}"
184 "${time_fmt} - command started\r\n.*\r\n${time_fmt} - command finished\r\nCommand execution time: \[0-9.\]+ \\(cpu\\), \[0-9.\]+ \\(wall\\)\[\r\n\]+Space used: $decimal \\(\\+$decimal for this command\\)\[\r\n\]+#symtabs: $decimal \\(\\+$decimal\\), #compunits: $decimal \\(\\+$decimal\\), #blocks: $decimal \\(\\+$decimal\\)"
185 gdb_test
"maint set per-command off" \
186 "${time_fmt} - command started"
188 # The timeout value is raised
, because printing all the symbols and
189 # statistical information about Cygwin and Windows libraries takes a lot
191 if [istarget
"*-*-cygwin*"] {
192 set oldtimeout $timeout
193 set timeout
[expr $timeout
+ 500]
198 "Statistics for\[^\n\r\]*maint\[^\n\r\]*:" \
199 " Number of \"minimal\" symbols read: $decimal" \
200 " Number of \"full\" symbols read: $decimal" \
201 " Number of \"types\" defined: $decimal" \
202 " Number of symbol tables: $decimal" \
203 " Number of symbol tables with line tables: $decimal" \
204 " Number of symbol tables with blockvectors: $decimal" \
205 "( Number of \"partial\" symbols read: $decimal" \
206 ")?( Number of psym tables \\(not yet expanded\\): $decimal" \
207 ")?( Total memory used for psymbol cache: $decimal" \
208 ")?( Number of read CUs: $decimal" \
209 " Number of unread CUs: $decimal" \
210 ")? Total memory used for objfile obstack: $decimal" \
211 " Total memory used for BFD obstack: $decimal" \
212 " Total memory used for string cache: $decimal" \
215 set re
[multi_line
{*}$re
]
216 gdb_test_lines
"maint print statistics" "" $re
218 # There aren
't any ...
219 gdb_test_no_output "maint print dummy-frames"
223 # To avoid timeouts, we avoid expects with many .* patterns that match
224 # many lines. Instead, we keep track of which milestones we've seen
225 # in the output
, and stop when we
've seen all of them.
231 set cmd "maint print objfiles"
233 gdb_test_multiple "$cmd $re" "$cmd" -lbl {
234 -re "\r\nObject file.*maint($EXEEXT)?: Objfile at ${hex}" {
238 -re "\r\nCooked index" {
242 -re "\r\nPsymtabs:\[\r\t \]+" {
246 -re "\r\nSymtabs:\[\r\t \]+\n" {
255 proc maint_pass_if {val name} {
256 if $val { pass $name } else { fail $name }
259 maint_pass_if $header "maint print objfiles: header"
264 maint_pass_if $psymtabs "maint print objfiles: psymtabs"
266 maint_pass_if $symtabs "maint print objfiles: symtabs"
269 set psymbols_output [standard_output_file psymbols_output]
270 set psymbols_output_re [string_to_regexp $psymbols_output]
271 set test_list [list \
272 "maint print psymbols -source" \
273 "maint print psymbols -source ${srcdir}/${subdir}/${srcfile} $psymbols_output" \
274 "maint print psymbols -pc" \
275 "maint print psymbols -pc main $psymbols_output"]
276 foreach { test_name command } $test_list {
277 gdb_test_no_output "$command" "collecting data for $test_name"
278 gdb_test_multiple "shell grep 'main.
*function
' $psymbols_output" "" {
279 -re -wrap ".main., function, $hex.*" {
280 pass "$test_name (pattern 1)"
282 -re -wrap ".*main. .., function, $hex.*" {
283 pass "$test_name (pattern 2)"
286 gdb_test "shell rm -f $psymbols_output" ".*" \
287 "${test_name}: shell rm -f psymbols_output"
292 set msymbols_output [standard_output_file msymbols_output]
293 set msymbols_output_re [string_to_regexp $msymbols_output]
294 gdb_test_no_output "maint print msymbols -objfile ${binfile} $msymbols_output" \
295 "print msymbols to file, with absolute path"
296 gdb_test "shell grep factorial $msymbols_output" \
297 "\\\[ *$decimal\\\] \[tT\]\[ \t\]+$hex \\.?factorial.*" \
298 "maint print msymbols, absolute pathname"
299 gdb_test "shell rm -f $msymbols_output" ".*" "remove absolute path msymbols"
301 # Check that maint print msymbols allows relative pathnames
303 gdb_test "cd [standard_output_file {}]" \
304 "Working directory .*\..*" \
307 gdb_test_no_output "maint print msymbols -objfile ${testfile} $msymbols_output"\
308 "print msymbols to file, with relative path"
309 gdb_test "shell grep factorial $msymbols_output" \
310 "\\\[ *$decimal\\\] \[tT\]\[ \t\]+$hex \\.?factorial.*" \
311 "maint print msymbols, relative pathname"
312 gdb_test "shell rm -f msymbols_output" ".*" "remove relative path msymbols"
314 gdb_test "cd ${mydir}" \
315 "Working directory [string_to_regexp ${mydir}]\..*" \
319 # Request symbols for one particular source file so that we don't try to
320 # dump the symbol information
for the entire C library
- over
500MB nowadays
323 set symbols_output
[standard_output_file symbols_output
]
324 set symbols_output_re
[string_to_regexp $symbols_output
]
325 set test_list
[list \
326 "maint print symbols -source" \
327 "maint print symbols -source ${srcdir}/${subdir}/${srcfile} $symbols_output" \
328 "maint print symbols -pc" \
329 "maint print symbols -pc main $symbols_output"]
330 foreach
{ test_name command
} $test_list
{
331 gdb_test_no_output
"$command" "$test_name generate"
332 gdb_test
"shell grep 'main(.*block' $symbols_output"\
333 "int main\\(int, char \\*\\*, char \\*\\*\\); block.*"\
335 gdb_test
"shell rm -f $symbols_output" ".*" \
336 "$test_name: shell rm -f symbols_output"
339 set msg
"maint print type"
340 gdb_test_multiple
"maint print type argc" $msg {
341 -re
"type node $hex\r\nname .int. \\($hex\\)\r\ncode $hex \\(TYPE_CODE_INT\\)\r\nlength \[24\]\r\nobjfile $hex\r\ntarget_type $hex\r\npointer_type $hex\r\nreference_type $hex\r\ntype_chain $hex\r\ninstance_flags $hex\r\nflags\r\nnfields 0 $hex\r\n$gdb_prompt $" {
346 if [istarget
"hppa*-*-11*"] {
347 setup_xfail hppa
*-*-*11* CLLbs14860
348 gdb_test_multiple
"maint print unwind &main" "maint print unwind" {
349 -re
".*unwind_table_entry \\($hex\\):\r\n\tregion_start = $hex <main>\r\n\tregion_end = $hex <main\\+\[0-9\]*>\r\n\tflags = Args_stored Save_RP\r\n\tRegion_description = $hex\r\n\tEntry_FR = $hex\r\n\tEntry_GR = $hex\r\n\tTotal_frame_size = $hex\r\n$gdb_prompt $" {
350 pass
"maint print unwind"
352 -re
".*unwind_table_entry \\($hex\\):\r\n\tregion_start = $hex <main>\r\n\tregion_end = $hex <main\\+\[0-9\]*>\r\n\tflags = Args_stored Save_RP\r\n\tFLD = $hex\r\n\tFLD = $hex\r\n\tFLD = $hex\r\n\tFLD = $hex\r\n$gdb_prompt $" {
353 xfail
"maint print unwind"
358 set oldtimeout $timeout
359 set timeout
[expr $timeout
+ 300]
361 set bp_location6
[gdb_get_line_number
"set breakpoint 6 here"]
363 gdb_test_multiple
"maint info breakpoints" "maint info breakpoints" {
364 -re
"Num\[ \t\]+Type\[ \t\]+Disp\[ \t\]+Enb\[ \t\]+Address\[ \t\]+What\r\n1\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+$hex\[ \t\]+in main at.*break.c:$bp_location6 inf 1\r\n\[ \t\]+breakpoint already hit 1 time\r\n.*$gdb_prompt $" {
365 pass
"maint info breakpoints"
367 -re
"Num\[ \t\]+Type\[ \t\]+Disp\[ \t\]+Enb\[ \t\]+Address\[ \t\]+What\r\n1\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+$hex in main at.*break.c:$bp_location6 sspace 1\r\n\[ \t\]+breakpoint already hit 1 time\r\n-1\[ \t\]+shlib events\[ \t\]+keep\[ \t\]+y\[ \t\]+$hex.*breakpoint already hit.*$gdb_prompt $" {
368 pass
"maint info breakpoints (with shlib events)"
372 gdb_test
"maint print" \
373 "List.*unambiguous\\..*" \
374 "maint print w/o args"
376 gdb_test
"maint info" \
377 "List.*unambiguous\\..*" \
378 "maint info w/o args"
381 "List.*unambiguous\\..*" \
384 # Test that
"main info line-table" w/o a file name shows the symtab for
387 gdb_test_multiple
"maint info line-table" \
388 "maint info line-table w/o a file name" {
389 -re
"symtab: \[^\n\r\]+${srcfile} \\(\\(struct symtab \\*\\) $hex\\)\r\nlinetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+REL-ADDRESS\[ \t\]+UNREL-ADDRESS\[^\r\n\]*\r\n" {
393 -re
"symtab: \[^\n\r\]+ \\(\\(struct symtab \\*\\) $hex\\)\r\nlinetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+REL-ADDRESS\[ \t\]+UNREL-ADDRESS\[^\r\n\]*\r\n" {
394 # Match each symtab to avoid overflowing expect
's buffer.
397 -re "symtab: \[^\n\r\]+ \\(\\(struct symtab \\*\\) $hex\\)\r\nlinetable: \\(\\(struct linetable \\*\\) 0x0\\):\r\nNo line table.\r\n" {
398 # For symtabs with no linetable.
401 -re "^$decimal\[ \t\]+$decimal\[ \t\]+$hex\[ \t\]+$hex\[^\r\n\]*\r\n" {
402 # Line table entries can be long too:
405 # 0 29 0x00000000004006f6
406 # 1 30 0x00000000004006fa
407 # 2 31 0x0000000000400704
408 # 3 42 0x0000000000400706
409 # 4 43 0x0000000000400719
410 # 5 44 0x0000000000400722
411 # 6 45 0x0000000000400740
413 # 454 129 0x00007ffff7df1d28
414 # 455 END 0x00007ffff7df1d3f
416 # Match each line to avoid overflowing expect's buffer.
419 -re
"^$decimal\[ \t\]+END\[ \t\]+$hex\[ \t\]+$hex\[^\r\n\]*\r\n" {
420 # Matches an end marker in the above.
424 # Empty line between tables.
427 -re
"^$gdb_prompt $" {
428 gdb_assert $saw_srcfile $gdb_test_name
432 gdb_test
"maint info line-table ${srcfile}" \
433 "symtab: \[^\n\r\]+${srcfile}.*INDEX.*LINE.*ADDRESS.*" \
434 "maint info line-table with filename of current symtab"
436 if { ! $readnow_p
} {
437 gdb_test_no_output
"maint info line-table ${srcfile2}" \
439 "maint info line-table with filename of symtab that is not" \
440 " currently expanded"]
443 gdb_test_no_output
"maint expand-symtabs"
445 gdb_test
"maint info line-table ${srcfile2}" \
446 "symtab: \[^\n\r\]+${srcfile2}.*INDEX.*LINE.*ADDRESS.*" \
447 "maint info line-table with filename of symtab that is not current"
449 gdb_test_no_output
"maint info line-table xxx.c" \
450 "maint info line-table with invalid filename"
452 set timeout $oldtimeout
454 # Just check that the DWARF unwinders control flag is visible.
455 gdb_test
"maint show dwarf unwinders" \
456 "The DWARF stack unwinders are currently (on|off)\\."
458 #
============test help
on maint commands
460 test_prefix_command_help
{"maint info" "maintenance info"} {
461 "Commands for showing internal info about the program being debugged\\.\[\r\n\]+"
464 test_prefix_command_help
{"maint print" "maintenance print"} {
465 "Maintenance command for printing GDB internal state\\.\[\r\n\]+"
468 test_prefix_command_help
{"maint" "maintenance"} {
469 "Commands for use by GDB maintainers\\.\[\r\n\]+"
470 "Includes commands to dump specific internal GDB structures in\[\r\n\]+"
471 "a human readable form, to cause GDB to deliberately dump core, etc\\.\[\r\n\]+"
474 #
set oldtimeout $timeout
475 #
set timeout
[expr $timeout
+ 300]
477 gdb_test_multiple
"maint dump-me" "maint dump-me" {
478 -re
"Should GDB dump core.*\\(y or n\\) $" {
479 gdb_test
"n" ".*" "maint dump-me"
481 -re
"Undefined maintenance command: .*$gdb_prompt $" {
482 # Command
'maint dump-me' is registered
on non
-win32 host.
483 unsupported
"maint dump-me"
487 send_gdb
"maint internal-error\n"
489 -re
"A problem internal to GDB has been detected" {
490 pass
"maint internal-error"
491 if [gdb_internal_error_resync
] {
492 pass
"internal-error resync"
494 fail
"internal-error resync"
497 -re
".*$gdb_prompt $" {
498 fail
"maint internal-error"
499 untested
"internal-error resync"
502 fail
"maint internal-error (timeout)"
503 untested
"internal-error resync"
507 #
set timeout $oldtimeout
509 # Test that the commands work without an
argument.
For this test
, we
510 # don
't need an inferior loaded/running. See PR gdb/21164.
513 gdb_test_no_output "maint print symbols"
514 gdb_test_no_output "maint print msymbols"
515 gdb_test_no_output "maint print psymbols"