2013-09-20 Chung-Lin Tang <cltang@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / maint.exp
1 # Copyright 1998-2013 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
17
18 # this file tests maintenance commands and help on those.
19
20 # source file used is break.c
21
22
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 demangle -- Demangle a C++ mangled name
29 #maintenance dump-me -- Get fatal error; make debugger dump its core
30 #maintenance print -- Maintenance command for printing GDB internal state
31 #maintenance info -- Commands for showing internal info about the program being debugged
32 #maintenance internal-error -- Give GDB an internal error.
33 #
34 #maintenance print dummy-frames -- Print the dummy frame stack
35 #maintenance print statistics -- Print statistics about internal gdb state
36 #maintenance print objfiles -- Print dump of current object file definitions
37 #maintenance print psymbols -- Print dump of current partial symbol definitions
38 #maintenance print msymbols -- Print dump of current minimal symbol definitions
39 #maintenance print symbols -- Print dump of current symbol definitions
40 #maintenance print type -- Print a type chain for a given symbol
41 #maintenance print unwind -- Print unwind table entry at given address
42 #
43 #
44 #maintenance info sections -- List the BFD sections of the exec and core files
45 #maintenance info breakpoints -- Status of all breakpoints
46 #
47
48
49
50 standard_testfile break.c break1.c
51
52 if {[prepare_for_testing $testfile.exp $testfile \
53 [list $srcfile $srcfile2] {debug nowarnings}]} {
54 untested $testfile.exp
55 return -1
56 }
57
58 # The commands we test here produce many lines of output; disable "press
59 # <return> to continue" prompts.
60 gdb_test_no_output "set height 0"
61
62 # Tests that require that no program is running
63
64 gdb_file_cmd ${binfile}
65
66 # Test for a regression where this command would internal-error if the
67 # program wasn't running.
68 gdb_test "maint print registers" "Name.*Nr.*Rel.*Offset.*Size.*Type.*"
69
70 # Test "mt expand-symtabs" here as it's easier to verify before we
71 # run the program.
72 gdb_test_no_output "mt set per on" "mt set per on for expand-symtabs"
73 gdb_test_multiple "mt expand-symtabs $subdir/break\[.\]c$" \
74 "mt expand-symtabs" {
75 -re "#primary symtabs: (1|2) \\(\[+\](0|1|2)\\),.*$gdb_prompt $" {
76 # This should expand at most two primary symtabs.
77 # "Normally" it will not expand any, because the symtab
78 # holding "main" will already have been expanded, but if the
79 # file is compiled with -fdebug-types-section then a second primary
80 # symtab for break.c will be created for any types.
81 pass "mt expand-symtabs"
82 }
83 }
84 gdb_test "mt set per off" ".*" "mt set per off for expand-symtabs"
85
86 # Tests that can or should be done with a running program
87
88 gdb_load ${binfile}
89
90 if ![runto_main] then {
91 perror "tests suppressed"
92 }
93
94 # If we're using .gdb_index there will be no psymtabs.
95 set have_gdb_index 0
96 gdb_test_multiple "maint info sections .gdb_index" "check for .gdb_index" {
97 -re ": .gdb_index.*$gdb_prompt $" {
98 set have_gdb_index 1
99 }
100 -re ".*$gdb_prompt $" {
101 ;# Nothing to do, present to avoid a FAIL.
102 }
103 }
104
105 #
106 # this command does not produce any output
107 # unless there is some problem with the symtabs and psymtabs
108 # so that branch will really never be covered in this tests here!!
109 #
110
111 # guo: on linux this command output is huge. for some reason splitting up
112 # the regexp checks works.
113 #
114 send_gdb "maint check-psymtabs\n"
115 gdb_expect {
116 -re "^maint check-psymtabs" {
117 gdb_expect {
118 -re "$gdb_prompt $" {
119 pass "maint check-psymtabs"
120 }
121 timeout { fail "(timeout) maint check-psymtabs" }
122 }
123 }
124 -re ".*$gdb_prompt $" { fail "maint check-psymtabs" }
125 timeout { fail "(timeout) maint check-psymtabs" }
126 }
127
128 # This command does not produce any output unless there is some problem
129 # with the symtabs, so that branch will really never be covered in the
130 # tests here!!
131 gdb_test_no_output "maint check-symtabs"
132
133 gdb_test_no_output "maint set per-command on"
134
135 gdb_test "maint set per-command off" \
136 "Command execution time: \[0-9.\]+ \\(cpu\\), \[0-9.\]+ \\(wall\\)\[\r\n\]+Space used: $decimal \\(\\+$decimal for this command\\)\[\r\n\]+#symtabs: $decimal \\(\\+$decimal\\), #primary symtabs: $decimal \\(\\+$decimal\\), #blocks: $decimal \\(\\+$decimal\\)"
137
138 gdb_test "maint demangle" \
139 "\"maintenance demangle\" takes an argument to demangle\\."
140
141 gdb_test "maint demangle main" "Can't demangle \"main\""
142
143
144
145 # The timeout value is raised, because printing all the symbols and
146 # statistical information about Cygwin and Windows libraries takes a lot
147 # of time.
148 if [istarget "*-*-cygwin*"] {
149 set oldtimeout $timeout
150 set timeout [expr $timeout + 500]
151 }
152
153 send_gdb "maint print statistics\n"
154 gdb_expect {
155 -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" {
156 gdb_expect {
157 -re "$gdb_prompt $" {
158 pass "maint print statistics"
159 }
160 timeout { fail "(timeout) maint print statistics" }
161 }
162 }
163 -re ".*$gdb_prompt $" { fail "maint print statistics" }
164 timeout { fail "(timeout) maint print statistics" }
165 }
166
167 # There aren't any ...
168 gdb_test_no_output "maint print dummy-frames"
169
170 send_gdb "maint print objfiles\n"
171
172 # To avoid timeouts, we avoid expects with many .* patterns that match
173 # many lines. Instead, we keep track of which milestones we've seen
174 # in the output, and stop when we've seen all of them.
175
176 set header 0
177 set psymtabs 0
178 set symtabs 0
179 set keep_looking 1
180
181 while {$keep_looking} {
182 gdb_expect {
183
184 -re ".*Object file.*maint($EXEEXT)?: Objfile at $hex, bfd at $hex, \[0-9\]* minsyms\[\r\t \]+\n" { set header 1 }
185 -re ".*Psymtabs:\[\r\t \]+\n" { set psymtabs 1 }
186 -re ".*Symtabs:\[\r\t \]+\n" { set symtabs 1 }
187
188 -re ".*$gdb_prompt $" {
189 set keep_looking 0
190 }
191 timeout {
192 fail "(timeout) maint print objfiles"
193 set keep_looking 0
194 }
195 }
196 }
197
198 proc maint_pass_if {val name} {
199 if $val { pass $name } else { fail $name }
200 }
201
202 maint_pass_if $header "maint print objfiles: header"
203 if { ! $have_gdb_index } {
204 maint_pass_if $psymtabs "maint print objfiles: psymtabs"
205 }
206 maint_pass_if $symtabs "maint print objfiles: symtabs"
207
208 gdb_test "maint print psymbols" \
209 "print-psymbols takes an output file name and optional symbol file name" \
210 "maint print psymbols w/o args"
211
212 if { ! $have_gdb_index } {
213 set psymbols_output [standard_output_file psymbols_output]
214 send_gdb "maint print psymbols $psymbols_output ${srcdir}/${subdir}/${srcfile}\n"
215 gdb_expect {
216 -re "^maint print psymbols $psymbols_output \[^\n\]*\r\n$gdb_prompt $" {
217 send_gdb "shell ls $psymbols_output\n"
218 gdb_expect {
219 -re "$psymbols_output\r\n$gdb_prompt $" {
220 # We want this grep to be as specific as possible,
221 # so it's less likely to match symbol file names in
222 # psymbols_output. Yes, this actually happened;
223 # poor expect got tons of output, and timed out
224 # trying to match it. --- Jim Blandy <jimb@cygnus.com>
225 send_gdb "shell grep 'main.*function' $psymbols_output\n"
226 gdb_expect {
227 -re ".main., function, $hex.*$gdb_prompt $" {
228 pass "maint print psymbols 1"
229 }
230 -re ".*main. .., function, $hex.*$gdb_prompt $" {
231 pass "maint print psymbols 2"
232 }
233 -re ".*$gdb_prompt $" { fail "maint print psymbols" }
234 timeout { fail "(timeout) maint print psymbols" }
235 }
236 gdb_test "shell rm -f $psymbols_output" ".*" \
237 "shell rm -f psymbols_output"
238 }
239 -re ".*$gdb_prompt $" { fail "maint print psymbols" }
240 timeout { fail "(timeout) maint print psymbols" }
241 }
242 }
243 -re ".*$gdb_prompt $" { fail "maint print psymbols" }
244 timeout { fail "(timeout) maint print psymbols" }
245 }
246 }
247
248 gdb_test "maint print msymbols" \
249 "print-msymbols takes an output file name and optional symbol file name" \
250 "maint print msymbols w/o args"
251
252
253 set msymbols_output [standard_output_file msymbols_output]
254 send_gdb "maint print msymbols $msymbols_output ${binfile}\n"
255 gdb_expect {
256 -re "^maint print msymbols $msymbols_output \[^\n\]*\r\n$gdb_prompt $" {
257 send_gdb "shell ls $msymbols_output\n"
258 gdb_expect {
259 -re "$msymbols_output\r\n$gdb_prompt $" {
260 send_gdb "shell grep factorial $msymbols_output\n"
261 gdb_expect {
262 -re "\\\[ *$decimal\\\] \[tT\]\[ \t\]+$hex \\.?factorial.*$gdb_prompt $" {
263 pass "maint print msymbols"
264 }
265 -re ".*$gdb_prompt $" { fail "maint print msymbols" }
266 timeout { fail "(timeout) maint print msymbols" }
267 }
268 gdb_test "shell rm -f $msymbols_output" ".*" \
269 "shell rm -f msymbols_output"
270 }
271 -re ".*$gdb_prompt $" { fail "maint print msymbols" }
272 timeout { fail "(timeout) maint print msymbols" }
273 }
274 }
275 -re ".*$gdb_prompt $" { fail "maint print msymbols" }
276 timeout { fail "(timeout) maint print msymbols" }
277 }
278
279 # Check that maint print msymbols allows relative pathnames
280 set mydir [pwd]
281 gdb_test "cd ${objdir}" \
282 "Working directory [string_to_regexp ${objdir}]\..*" \
283 "cd to objdir"
284
285 gdb_test_multiple "maint print msymbols msymbols_output2 ${subdir}/${testfile}" "maint print msymbols" {
286 -re "^maint print msymbols msymbols_output2 \[^\n\]*\r\n$gdb_prompt $" {
287 gdb_test_multiple "shell ls msymbols_output2" "maint print msymbols" {
288 -re "msymbols_output2\r\n$gdb_prompt $" {
289 gdb_test_multiple "shell grep factorial msymbols_output2" "maint print msymbols" {
290 -re "\\\[ *$decimal\\\] \[tT\]\[ \t\]+$hex \\.?factorial.*$gdb_prompt $" {
291 pass "maint print msymbols"
292 }
293 -re ".*$gdb_prompt $" {
294 fail "maint print msymbols"
295 }
296 timeout {
297 fail "(timeout) maint print msymbols"
298 }
299 }
300 gdb_test "shell rm -f msymbols_output2" ".*" \
301 "shell rm -f msymbols_output2"
302 }
303 -re ".*$gdb_prompt $" {
304 fail "maint print msymbols"
305 }
306 timeout {
307 fail "(timeout) maint print msymbols"
308 }
309 }
310 }
311 -re ".*$gdb_prompt $" {
312 fail "maint print msymbols"
313 }
314 timeout {
315 fail "(timeout) maint print msymbols"
316 }
317 }
318 gdb_test "cd ${mydir}" \
319 "Working directory [string_to_regexp ${mydir}]\..*" \
320 "cd to mydir"
321
322 gdb_test "maint print symbols" \
323 "Arguments missing: an output file name and an optional symbol file name" \
324 "maint print symbols w/o args"
325
326
327 # Request symbols for one particular source file so that we don't try to
328 # dump the symbol information for the entire C library - over 500MB nowadays
329 # for GNU libc.
330
331 set symbols_output [standard_output_file symbols_output]
332 send_gdb "maint print symbols $symbols_output ${srcdir}/${subdir}/${srcfile}\n"
333 gdb_expect {
334 -re "^maint print symbols $symbols_output \[^\n\]*\r\n$gdb_prompt $" {
335 send_gdb "shell ls $symbols_output\n"
336 gdb_expect {
337 -re "$symbols_output\r\n$gdb_prompt $" {
338 # See comments for `maint print psymbols'.
339 send_gdb "shell grep 'main(.*block' $symbols_output\n"
340 gdb_expect {
341 -re "int main\\(int, char \\*\\*, char \\*\\*\\); block.*$gdb_prompt $" {
342 pass "maint print symbols"
343 }
344 -re ".*$gdb_prompt $" { fail "maint print symbols" }
345 timeout { fail "(timeout) maint print symbols" }
346 }
347 gdb_test "shell rm -f $symbols_output" ".*" \
348 "shell rm -f symbols_output"
349 }
350 -re ".*$gdb_prompt $" { fail "maint print symbols" }
351 timeout { fail "(timeout) maint print symbols" }
352 }
353 }
354 -re ".*$gdb_prompt $" { fail "maint print symbols" }
355 timeout { fail "(timeout) maint print symbols" }
356 }
357
358 set msg "maint print type"
359 gdb_test_multiple "maint print type argc" $msg {
360 -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\nvptr_basetype $hex\r\nvptr_fieldno -1\r\n$gdb_prompt $" {
361 pass $msg
362 }
363 }
364
365 if [istarget "hppa*-*-11*"] {
366 setup_xfail hppa*-*-*11* CLLbs14860
367 gdb_test_multiple "maint print unwind &main" "maint print unwind" {
368 -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 $" {
369 pass "maint print unwind"
370 }
371 -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 $" {
372 xfail "maint print unwind"
373 }
374 }
375 }
376
377 set oldtimeout $timeout
378 set timeout [expr $timeout + 300]
379
380 # It'd be nice to check for every possible section. However, that's
381 # problematic, since the relative ordering wanders from release to
382 # release of the compilers. Instead, we'll just check for two
383 # sections which appear to always come out in the same relative
384 # order. (If that changes, then we should just check for one
385 # section.)
386 #
387 # And by the way: This testpoint will break for PA64, where a.out's
388 # are ELF files.
389
390 # Standard GNU names.
391 set text_section ".text"
392 set data_section ".data"
393
394 gdb_test_multiple "maint info sections" "maint info sections" {
395 -re "Exec file:\r\n.*maint($EXEEXT)?., file type.*ER_RO.*$gdb_prompt $" {
396 # Looks like RealView which uses different section names.
397 set text_section ER_RO
398 set data_section ER_RW
399 pass "maint info sections"
400 }
401 -re "Exec file:\r\n.*maint($EXEEXT)?., file type.*neardata.*$gdb_prompt $" {
402 # c6x doesn't have .data section. It has .neardata and .fardata section.
403 set data_section ".neardata"
404 pass "maint info sections"
405 }
406 -re "Exec file:\r\n.*maint($EXEEXT)?., file type.*$gdb_prompt $" {
407 pass "maint info sections"
408 }
409 }
410
411 # Test for new option: maint info sections <section name>
412 # If you don't have a .text section, this will require tweaking.
413
414 gdb_test_multiple "maint info sections $text_section" \
415 "maint info sections .text" {
416 -re ".* \\.bss .*$gdb_prompt $" {
417 fail "maint info sections .text"
418 }
419 -re ".* $data_section .*$gdb_prompt $" {
420 fail "maint info sections .text"
421 }
422 -re ".* $text_section .*$gdb_prompt $" {
423 pass "maint info sections .text"
424 }
425 }
426
427 # Test for new option: CODE section flag
428 # If your data section is tagged CODE, xfail this test.
429
430 gdb_test_multiple "maint info sections CODE" "maint info sections CODE" {
431 -re ".* $data_section .*$gdb_prompt $" { fail "maint info sections CODE" }
432 -re ".* $text_section .*$gdb_prompt $" { pass "maint info sections CODE" }
433 }
434
435 # Test for new option: DATA section flag
436 # If your text section is tagged DATA, xfail this test.
437 #
438 # The "maint info sections DATA" test is marked for XFAIL on Windows,
439 # because Windows has text sections marked DATA.
440 setup_xfail "*-*-*cygwin*"
441 setup_xfail "*-*-*mingw*"
442
443 gdb_test_multiple "maint info sections DATA" "maint info sections DATA" {
444 -re ".* $text_section .*$gdb_prompt $" { fail "maint info sections DATA" }
445 -re ".* $data_section .*$gdb_prompt $" { pass "maint info sections DATA" }
446 -re ".* .rodata .*$gdb_prompt $" { pass "maint info sections DATA" }
447 }
448
449 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
450
451 gdb_test_multiple "maint info breakpoints" "maint info breakpoints" {
452 -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 $" {
453 pass "maint info breakpoints"
454 }
455 -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 $" {
456 pass "maint info breakpoints (with shlib events)"
457 }
458 }
459
460 gdb_test "maint print" \
461 "\"maintenance print\" must be followed by the name of a print command\\.\r\nList.*unambiguous\\..*" \
462 "maint print w/o args"
463
464 gdb_test "maint info" \
465 "\"maintenance info\" must be followed by the name of an info command\\.\r\nList.*unambiguous\\..*" \
466 "maint info w/o args"
467
468 gdb_test "maint" \
469 "\"maintenance\" must be followed by the name of a maintenance command\\.\r\nList.*unambiguous\\..*" \
470 "maint w/o args"
471
472 set timeout $oldtimeout
473
474 #============test help on maint commands
475
476 gdb_test "help maint" \
477 "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,.*to test internal functions such as the C../ObjC demangler, 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\\..*"
478
479 gdb_test "help maint info" \
480 "Commands for showing internal info about the program being debugged.*unambiguous\\..*"
481
482 test_prefix_command_help {"maint print" "maintenance print"} {
483 "Maintenance command for printing GDB internal state\\.\[\r\n\]+"
484 }
485
486 test_prefix_command_help {"maint" "maintenance"} {
487 "Commands for use by GDB maintainers\\.\[\r\n\]+"
488 "Includes commands to dump specific internal GDB structures in\[\r\n\]+"
489 "a human readable form, to cause GDB to deliberately dump core,\[\r\n\]+"
490 "to test internal functions such as the C\\+\\+/ObjC demangler, etc\\.\[\r\n\]+"
491 }
492
493 #set oldtimeout $timeout
494 #set timeout [expr $timeout + 300]
495
496 gdb_test_multiple "maint dump-me" "maint dump-me" {
497 -re "Should GDB dump core.*\\(y or n\\) $" {
498 gdb_test "n" ".*" "maint dump-me"
499 }
500 -re "Undefined maintenance command: .*$gdb_prompt $" {
501 # Command 'maint dump-me' is registered on non-win32 host.
502 unsupported "maint dump-me"
503 }
504 }
505
506 send_gdb "maint internal-error\n"
507 gdb_expect {
508 -re "A problem internal to GDB has been detected" {
509 pass "maint internal-error"
510 if [gdb_internal_error_resync] {
511 pass "internal-error resync"
512 } else {
513 fail "internal-error resync"
514 }
515 }
516 -re ".*$gdb_prompt $" {
517 fail "maint internal-error"
518 untested "internal-error resync"
519 }
520 timeout {
521 fail "maint internal-error (timeout)"
522 untested "internal-error resync"
523 }
524 }
525
526 #set timeout $oldtimeout
527
528
529 gdb_exit
530 return 0
This page took 0.040637 seconds and 4 git commands to generate.