1 # Copyright 1998-2016 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 sections -- List the BFD sections of the exec and core files
44 #maintenance info breakpoints -- Status of all breakpoints
49 standard_testfile break.c break1.c
51 if {[prepare_for_testing $testfile.exp $testfile \
52 [list $srcfile $srcfile2] {debug nowarnings}]} {
53 untested $testfile.exp
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.
67 gdb_test "maint print registers" "Name.*Nr.*Rel.*Offset.*Size.*Type.*"
69 # Test "mt expand-symtabs" here as it's easier to verify before we
71 gdb_test_no_output "mt set per on" "mt set per on for expand-symtabs"
72 gdb_test_multiple "mt expand-symtabs $subdir/break\[.\]c$" \
74 -re "#compunits: (1|2) \\(\[+\](0|1|2)\\),.*$gdb_prompt $" {
75 # This should expand at most two primary symtabs.
76 # "Normally" it will not expand any, because the symtab
77 # holding "main" will already have been expanded, but if the
78 # file is compiled with -fdebug-types-section then a second primary
79 # symtab for break.c will be created for any types.
80 pass "mt expand-symtabs"
83 gdb_test "mt set per off" ".*" "mt set per off for expand-symtabs"
85 # Tests that can or should be done with a running program
89 if ![runto_main] then {
90 perror "tests suppressed"
93 # If we're using .gdb_index there will be no psymtabs.
95 gdb_test_multiple "maint info sections .gdb_index" "check for .gdb_index" {
96 -re ": .gdb_index.*$gdb_prompt $" {
99 -re ".*$gdb_prompt $" {
100 ;# Nothing to do, present to avoid a FAIL.
105 # this command does not produce any output
106 # unless there is some problem with the symtabs and psymtabs
107 # so that branch will really never be covered in this tests here!!
110 # guo: on linux this command output is huge. for some reason splitting up
111 # the regexp checks works.
113 send_gdb "maint check-psymtabs\n"
115 -re "^maint check-psymtabs" {
117 -re "$gdb_prompt $" {
118 pass "maint check-psymtabs"
120 timeout { fail "(timeout) maint check-psymtabs" }
123 -re ".*$gdb_prompt $" { fail "maint check-psymtabs" }
124 timeout { fail "(timeout) maint check-psymtabs" }
127 # This command does not produce any output unless there is some problem
128 # with the symtabs, so that branch will really never be covered in the
130 gdb_test_no_output "maint check-symtabs"
132 # Test per-command stats.
133 gdb_test_no_output "maint set per-command on"
135 "Command 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\\)"
136 gdb_test_no_output "maint set per-command off"
138 # The timeout value is raised, because printing all the symbols and
139 # statistical information about Cygwin and Windows libraries takes a lot
141 if [istarget "*-*-cygwin*"] {
142 set oldtimeout $timeout
143 set timeout [expr $timeout + 500]
146 send_gdb "maint print statistics\n"
148 -re "Statistics for\[^\n\r\]*maint\[^\n\r\]*:\r\n Number of \"minimal\" symbols read: $decimal\r\n( Number of \"partial\" symbols read: $decimal\r\n)? Number of \"full\" symbols read: $decimal\r\n Number of \"types\" defined: $decimal\r\n( Number of psym tables \\(not yet expanded\\): $decimal\r\n)?( Number of read CUs: $decimal\r\n Number of unread CUs: $decimal\r\n)? Number of symbol tables: $decimal\r\n Number of symbol tables with line tables: $decimal\r\n Number of symbol tables with blockvectors: $decimal\r\n Total memory used for objfile obstack: $decimal\r\n Total memory used for BFD obstack: $decimal\r\n Total memory used for psymbol cache: $decimal\r\n Total memory used for macro cache: $decimal\r\n Total memory used for file name cache: $decimal\r\n" {
150 -re "$gdb_prompt $" {
151 pass "maint print statistics"
153 timeout { fail "(timeout) maint print statistics" }
156 -re ".*$gdb_prompt $" { fail "maint print statistics" }
157 timeout { fail "(timeout) maint print statistics" }
160 # There aren't any ...
161 gdb_test_no_output "maint print dummy-frames"
163 send_gdb "maint print objfiles\n"
165 # To avoid timeouts, we avoid expects with many .* patterns that match
166 # many lines. Instead, we keep track of which milestones we've seen
167 # in the output, and stop when we've seen all of them.
174 while {$keep_looking} {
178 set output $expect_out(buffer)
179 if {[regexp ".*Object file.*maint($EXEEXT)?: Objfile at ${hex}" $output]} {
182 if {[regexp ".*Psymtabs:\[\r\t \]+\n" $output]} {
185 if {[regexp ".*Symtabs:\[\r\t \]+\n" $output]} {
190 -re ".*$gdb_prompt $" {
194 fail "(timeout) maint print objfiles"
200 proc maint_pass_if {val name} {
201 if $val { pass $name } else { fail $name }
204 maint_pass_if $header "maint print objfiles: header"
205 if { ! $have_gdb_index } {
206 maint_pass_if $psymtabs "maint print objfiles: psymtabs"
208 maint_pass_if $symtabs "maint print objfiles: symtabs"
210 if { ! $have_gdb_index } {
211 set psymbols_output [standard_output_file psymbols_output]
212 set psymbols_output_re [string_to_regexp $psymbols_output]
213 set test_list [list \
214 "maint print psymbols -source" \
215 "maint print psymbols -source ${srcdir}/${subdir}/${srcfile} $psymbols_output" \
216 "maint print psymbols -pc" \
217 "maint print psymbols -pc main $psymbols_output"]
218 foreach { test_name command } $test_list {
219 send_gdb "$command\n"
221 -re "^maint print psymbols \[^\n\]*\r\n$gdb_prompt $" {
222 send_gdb "shell ls $psymbols_output\n"
224 -re "$psymbols_output_re\r\n$gdb_prompt $" {
225 # We want this grep to be as specific as possible,
226 # so it's less likely to match symbol file names in
227 # psymbols_output. Yes, this actually happened;
228 # poor expect got tons of output, and timed out
229 # trying to match it. --- Jim Blandy <jimb@cygnus.com>
230 send_gdb "shell grep 'main.*function' $psymbols_output\n"
232 -re ".main., function, $hex.*$gdb_prompt $" {
235 -re ".*main. .., function, $hex.*$gdb_prompt $" {
238 -re ".*$gdb_prompt $" { fail "$test_name" }
239 timeout { fail "$test_name (timeout)" }
241 gdb_test "shell rm -f $psymbols_output" ".*" \
242 "shell rm -f psymbols_output"
244 -re ".*$gdb_prompt $" { fail "$test_name" }
245 timeout { fail "$test_name (timeout)" }
248 -re ".*$gdb_prompt $" { fail "$test_name" }
249 timeout { fail "$test_name (timeout)" }
255 set msymbols_output [standard_output_file msymbols_output]
256 set msymbols_output_re [string_to_regexp $msymbols_output]
257 send_gdb "maint print msymbols -objfile ${binfile} $msymbols_output\n"
259 -re "^maint print msymbols \[^\n\]*\r\n$gdb_prompt $" {
260 send_gdb "shell ls $msymbols_output\n"
262 -re "$msymbols_output_re\r\n$gdb_prompt $" {
263 send_gdb "shell grep factorial $msymbols_output\n"
265 -re "\\\[ *$decimal\\\] \[tT\]\[ \t\]+$hex \\.?factorial.*$gdb_prompt $" {
266 pass "maint print msymbols"
268 -re ".*$gdb_prompt $" { fail "maint print msymbols" }
269 timeout { fail "maint print msymbols (timeout)" }
271 gdb_test "shell rm -f $msymbols_output" ".*" \
272 "shell rm -f msymbols_output"
274 -re ".*$gdb_prompt $" { fail "maint print msymbols" }
275 timeout { fail "maint print msymbols (timeout)" }
278 -re ".*$gdb_prompt $" { fail "maint print msymbols" }
279 timeout { fail "maint print msymbols (timeout)" }
282 # Check that maint print msymbols allows relative pathnames
284 gdb_test "cd [standard_output_file {}]" \
285 "Working directory .*\..*" \
288 gdb_test_multiple "maint print msymbols -objfile ${testfile} msymbols_output2" "maint print msymbols" {
289 -re "^maint print msymbols \[^\n\]*\r\n$gdb_prompt $" {
290 gdb_test_multiple "shell ls msymbols_output2" "maint print msymbols" {
291 -re "msymbols_output2\r\n$gdb_prompt $" {
292 gdb_test "shell grep factorial msymbols_output2" \
293 "\\\[ *$decimal\\\] \[tT\]\[ \t\]+$hex \\.?factorial.*" \
294 "maint print msymbols"
295 gdb_test "shell rm -f msymbols_output2" ".*"
300 gdb_test "cd ${mydir}" \
301 "Working directory [string_to_regexp ${mydir}]\..*" \
305 # Request symbols for one particular source file so that we don't try to
306 # dump the symbol information for the entire C library - over 500MB nowadays
309 set symbols_output [standard_output_file symbols_output]
310 set symbols_output_re [string_to_regexp $symbols_output]
311 set test_list [list \
312 "maint print symbols -source" \
313 "maint print symbols -source ${srcdir}/${subdir}/${srcfile} $symbols_output" \
314 "maint print symbols -pc" \
315 "maint print symbols -pc main $symbols_output"]
316 foreach { test_name command } $test_list {
317 send_gdb "$command\n"
319 -re "^maint print symbols \[^\n\]*\r\n$gdb_prompt $" {
320 send_gdb "shell ls $symbols_output\n"
322 -re "$symbols_output_re\r\n$gdb_prompt $" {
323 # See comments for `maint print psymbols'.
324 send_gdb "shell grep 'main(.*block' $symbols_output\n"
326 -re "int main\\(int, char \\*\\*, char \\*\\*\\); block.*$gdb_prompt $" {
329 -re ".*$gdb_prompt $" { fail "$test_name" }
330 timeout { fail "$test_name (timeout)" }
332 gdb_test "shell rm -f $symbols_output" ".*" \
333 "shell rm -f symbols_output"
335 -re ".*$gdb_prompt $" { fail "$test_name" }
336 timeout { fail "$test_name (timeout)" }
339 -re ".*$gdb_prompt $" { fail "$test_name" }
340 timeout { fail "$test_name (timeout)" }
344 set msg "maint print type"
345 gdb_test_multiple "maint print type argc" $msg {
346 -re "type node $hex\r\nname .int. \\($hex\\)\r\ntagname .<NULL>. \\($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 $" {
351 if [istarget "hppa*-*-11*"] {
352 setup_xfail hppa*-*-*11* CLLbs14860
353 gdb_test_multiple "maint print unwind &main" "maint print unwind" {
354 -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 $" {
355 pass "maint print unwind"
357 -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 $" {
358 xfail "maint print unwind"
363 set oldtimeout $timeout
364 set timeout [expr $timeout + 300]
366 # It'd be nice to check for every possible section. However, that's
367 # problematic, since the relative ordering wanders from release to
368 # release of the compilers. Instead, we'll just check for two
369 # sections which appear to always come out in the same relative
370 # order. (If that changes, then we should just check for one
373 # And by the way: This testpoint will break for PA64, where a.out's
376 # Standard GNU names.
377 set text_section ".text"
378 set data_section ".data"
380 gdb_test_multiple "maint info sections" "maint info sections" {
381 -re "Exec file:\r\n.*maint($EXEEXT)?., file type.*ER_RO.*$gdb_prompt $" {
382 # Looks like RealView which uses different section names.
383 set text_section ER_RO
384 set data_section ER_RW
385 pass "maint info sections"
387 -re "Exec file:\r\n.*maint($EXEEXT)?., file type.*neardata.*$gdb_prompt $" {
388 # c6x doesn't have .data section. It has .neardata and .fardata section.
389 set data_section ".neardata"
390 pass "maint info sections"
392 -re "Exec file:\r\n.*maint($EXEEXT)?., file type.*$gdb_prompt $" {
393 pass "maint info sections"
397 # Test for new option: maint info sections <section name>
398 # If you don't have a .text section, this will require tweaking.
400 gdb_test_multiple "maint info sections $text_section" \
401 "maint info sections .text" {
402 -re ".* \\.bss .*$gdb_prompt $" {
403 fail "maint info sections .text"
405 -re ".* $data_section .*$gdb_prompt $" {
406 fail "maint info sections .text"
408 -re ".* $text_section .*$gdb_prompt $" {
409 pass "maint info sections .text"
413 # Test for new option: CODE section flag
414 # If your data section is tagged CODE, xfail this test.
416 gdb_test_multiple "maint info sections CODE" "maint info sections CODE" {
417 -re ".* $data_section .*$gdb_prompt $" { fail "maint info sections CODE" }
418 -re ".* $text_section .*$gdb_prompt $" { pass "maint info sections CODE" }
421 # Test for new option: DATA section flag
422 # If your text section is tagged DATA, xfail this test.
424 # The "maint info sections DATA" test is marked for XFAIL on Windows,
425 # because Windows has text sections marked DATA.
426 setup_xfail "*-*-*cygwin*"
427 setup_xfail "*-*-*mingw*"
429 gdb_test_multiple "maint info sections DATA" "maint info sections DATA" {
430 -re ".* $text_section .*$gdb_prompt $" { fail "maint info sections DATA" }
431 -re ".* $data_section .*$gdb_prompt $" { pass "maint info sections DATA" }
432 -re ".* .rodata .*$gdb_prompt $" { pass "maint info sections DATA" }
435 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
437 gdb_test_multiple "maint info breakpoints" "maint info breakpoints" {
438 -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 $" {
439 pass "maint info breakpoints"
441 -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 $" {
442 pass "maint info breakpoints (with shlib events)"
446 gdb_test "maint print" \
447 "\"maintenance print\" must be followed by the name of a print command\\.\r\nList.*unambiguous\\..*" \
448 "maint print w/o args"
450 gdb_test "maint info" \
451 "\"maintenance info\" must be followed by the name of an info command\\.\r\nList.*unambiguous\\..*" \
452 "maint info w/o args"
455 "\"maintenance\" must be followed by the name of a maintenance command\\.\r\nList.*unambiguous\\..*" \
458 # Test that "main info line-table" w/o a file name shows the symtab for
461 set test "maint info line-table w/o a file name"
462 gdb_test_multiple "maint info line-table" $test {
463 -re "symtab: \[^\n\r\]+${srcfile} \\(\\(struct symtab \\*\\) $hex\\)\r\nlinetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+ADDRESS" {
467 -re "symtab: \[^\n\r\]+ \\(\\(struct symtab \\*\\) $hex\\)\r\nlinetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+ADDRESS" {
468 # Match each symtab to avoid overflowing expect's buffer.
471 -re "$decimal\[ \t\]+$decimal\[ \t\]+$hex\r\n" {
472 # Line table entries can be long too:
475 # 0 29 0x00000000004006f6
476 # 1 30 0x00000000004006fa
477 # 2 31 0x0000000000400704
478 # 3 42 0x0000000000400706
479 # 4 43 0x0000000000400719
480 # 5 44 0x0000000000400722
481 # 6 45 0x0000000000400740
483 # 454 129 0x00007ffff7df1d28
484 # 455 0 0x00007ffff7df1d3f
486 # Match each line to avoid overflowing expect's buffer.
489 -re "$gdb_prompt $" {
490 gdb_assert $saw_srcfile $test
494 gdb_test "maint info line-table ${srcfile}" \
495 "symtab: \[^\n\r\]+${srcfile}.*INDEX.*LINE.*ADDRESS.*" \
496 "maint info line-table with filename of current symtab"
498 gdb_test_no_output "maint info line-table ${srcfile2}" \
499 "maint info line-table with filename of symtab that is not currently expanded"
501 gdb_test_no_output "maint expand-symtabs"
503 gdb_test "maint info line-table ${srcfile2}" \
504 "symtab: \[^\n\r\]+${srcfile2}.*INDEX.*LINE.*ADDRESS.*" \
505 "maint info line-table with filename of symtab that is not current"
507 gdb_test_no_output "maint info line-table xxx.c" \
508 "maint info line-table with invalid filename"
510 set timeout $oldtimeout
512 #============test help on maint commands
514 gdb_test "help maint" \
515 "Commands for use by GDB maintainers\\..*Includes commands to dump specific internal GDB structures in.*a human readable form, to cause GDB to deliberately dump core, etc\\..*List of maintenance subcommands:.*maintenance info.*maintenance internal-error.*maintenance print.*maintenance set.*maintenance show.*Type.*help maintenance.*followed by maintenance subcommand name for full documentation\\..*Command name abbreviations are allowed if unambiguous\\..*"
517 gdb_test "help maint info" \
518 "Commands for showing internal info about the program being debugged.*unambiguous\\..*"
520 test_prefix_command_help {"maint print" "maintenance print"} {
521 "Maintenance command for printing GDB internal state\\.\[\r\n\]+"
524 test_prefix_command_help {"maint" "maintenance"} {
525 "Commands for use by GDB maintainers\\.\[\r\n\]+"
526 "Includes commands to dump specific internal GDB structures in\[\r\n\]+"
527 "a human readable form, to cause GDB to deliberately dump core, etc\\.\[\r\n\]+"
530 #set oldtimeout $timeout
531 #set timeout [expr $timeout + 300]
533 gdb_test_multiple "maint dump-me" "maint dump-me" {
534 -re "Should GDB dump core.*\\(y or n\\) $" {
535 gdb_test "n" ".*" "maint dump-me"
537 -re "Undefined maintenance command: .*$gdb_prompt $" {
538 # Command 'maint dump-me' is registered on non-win32 host.
539 unsupported "maint dump-me"
543 send_gdb "maint internal-error\n"
545 -re "A problem internal to GDB has been detected" {
546 pass "maint internal-error"
547 if [gdb_internal_error_resync] {
548 pass "internal-error resync"
550 fail "internal-error resync"
553 -re ".*$gdb_prompt $" {
554 fail "maint internal-error"
555 untested "internal-error resync"
558 fail "maint internal-error (timeout)"
559 untested "internal-error resync"
563 #set timeout $oldtimeout