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