📄 maint.exp
字号:
# Copyright (C) 1998 Free Software Foundation, Inc.# This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.# # This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.# # You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Please email any bugs, comments, and/or additions to this file to:# bug-gdb@prep.ai.mit.edu# This file was written by Elena Zannoni (ezannoni@cygnus.com)# this file tests maintenance commands and help on those.# source file used is break.c#maintenance check-symtabs -- Check consistency of psymtabs and symtabs#maintenance space -- Set the display of space usage#maintenance time -- Set the display of time usage#maintenance demangle -- Demangle a C++ mangled name#maintenance dump-me -- Get fatal error; make debugger dump its core#maintenance print -- Maintenance command for printing GDB internal state#maintenance info -- Commands for showing internal info about the program being debugged#maintenance internal-error -- Give GDB an internal error.##maintenance print statistics -- Print statistics about internal gdb state#maintenance print objfiles -- Print dump of current object file definitions#maintenance print psymbols -- Print dump of current partial symbol definitions#maintenance print msymbols -- Print dump of current minimal symbol definitions#maintenance print symbols -- Print dump of current symbol definitions#maintenance print type -- Print a type chain for a given symbol#maintenance print unwind -- Print unwind table entry at given address###maintenance info sections -- List the BFD sections of the exec and core files#maintenance info breakpoints -- Status of all breakpoints#if $tracelevel then { strace $tracelevel }global usestubs## test running programs#set prms_id 0set bug_id 0set testfile "break"set srcfile ${testfile}.cset binfile ${objdir}/${subdir}/${testfile}if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } { gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."}gdb_exitgdb_startgdb_reinitialize_dir $srcdir/$subdirgdb_load ${binfile}if ![runto_main] then { perror "tests suppressed"}# The commands we test here produce many lines of output; disable "press # <return> to continue" prompts.send_gdb "set height 0\n"gdb_expect -re "$gdb_prompt $"# use a larger expect input buffer for long help outputs.match_max 6000## this command does not produce any output# unless there is some problem with the symtabs and psymtabs# so that branch will really never be covered in this tests here!!## guo: on linux this command output is huge. for some reason splitting up# the regexp checks works.#send_gdb "maint check-symtabs\n"gdb_expect { -re "^maint check-symtabs" { gdb_expect { -re "$gdb_prompt $" \ { pass "maint check-symtabs" } timeout { fail "(timeout) maint check-symtabs" } } } -re ".*$gdb_prompt $" { fail "maint check-symtabs" } timeout { fail "(timeout) maint check-symtabs" } }send_gdb "maint space\n"gdb_expect { -re "\"maintenance space\" takes a numeric argument\\..*$gdb_prompt $"\ { pass "maint space" } -re ".*$gdb_prompt $" { fail "maint space" } timeout { fail "(timeout) maint space" } }send_gdb "maint space 1\n"gdb_expect { -re "Space used: $decimal \\(\\+$decimal for this command\\).*$gdb_prompt $"\ { pass "maint space 1" } -re ".*$gdb_prompt $" { fail "maint space 1" } timeout { fail "(timeout) maint space 1" } }send_gdb "maint time\n"gdb_expect { -re "\"maintenance time\" takes a numeric argument\\..*Space used: $decimal \\(\\+$decimal for this command\\).*$gdb_prompt $"\ { pass "maint time" } -re ".*$gdb_prompt $" { fail "maint time" } timeout { fail "(timeout) maint time" } }send_gdb "maint time 1\n"gdb_expect { -re "Command execution time: $decimal.*Space used: $decimal \\(\\+$decimal for this command\\).*$gdb_prompt $"\ { pass "maint time 1" } -re ".*$gdb_prompt $" { fail "maint time 1" } timeout { fail "(timeout) maint time 1" } }send_gdb "maint time 0\n"gdb_expect { -re "Space used: $decimal \\(\\+$decimal for this command\\).*$gdb_prompt $"\ { pass "maint time 0" } -re ".*$gdb_prompt $" { fail "maint time 0" } timeout { fail "(timeout) maint time 0" } }send_gdb "maint space 0\n"gdb_expect { -re "maint space 0\r\n$gdb_prompt $"\ { pass "maint space 0" } -re ".*$gdb_prompt $" { fail "maint space 0" } timeout { fail "(timeout) maint space 0" } }send_gdb "maint demangle\n"gdb_expect { -re "\"maintenance demangle\" takes an argument to demangle\\..*$gdb_prompt $"\ { pass "maint demangle" } -re ".*$gdb_prompt $" { fail "maint demangle" } timeout { fail "(timeout) maint demangle" } }send_gdb "maint demangle main\n"gdb_expect { -re "Can't demangle \"main\".*$gdb_prompt $"\ { pass "maint demangle" } -re ".*$gdb_prompt $" { fail "maint demangle" } timeout { fail "(timeout) maint demangle" } }send_gdb "maint print statistics\n"gdb_expect { -re "Statistics for.*break.*Number of \"minimal\" symbols read.*Number of \"partial\" symbols read.*Number of \"types\" defined.*Total memory used for psymbol obstack.*Total memory used for psymbol cache.*Total memory used for symbol obstack.*Total memory used for type obstack.*$gdb_prompt $"\ { pass "maint print statistics" } -re ".*$gdb_prompt $" { fail "maint print statistics" } timeout { fail "(timeout) maint print statistics" } }send_gdb "maint print objfiles\n"# To avoid timeouts, we avoid expects with many .* patterns that match# many lines. Instead, we keep track of which milestones we've seen# in the output, and stop when we've seen all of them.set header 0set psymtabs 0set symtabs 0set keep_looking 1while {$keep_looking} { gdb_expect { -re ".*Object file.*break: Objfile at $hex, bfd at $hex, \[0-9\]* minsyms\[\r\t \]+\n" { set header 1 } -re ".*Psymtabs:\[\r\t \]+\n" { set psymtabs 1 } -re ".*Symtabs:\[\r\t \]+\n" { set symtabs 1 } -re ".*$gdb_prompt $" { set keep_looking 0 } timeout { fail "(timeout) maint print objfiles" set keep_looking 0 } }}proc maint_pass_if {val name} { if $val { pass $name } else { fail $name }}maint_pass_if $header "maint print objfiles: header"maint_pass_if $psymtabs "maint print objfiles: psymtabs"maint_pass_if $symtabs "maint print objfiles: symtabs"send_gdb "maint print psymbols\n"gdb_expect { -re "print-psymbols takes an output file name and optional symbol file name.*$gdb_prompt $"\ { pass "maint print psymbols w/o args" } -re ".*$gdb_prompt $" { fail "maint print psymbols w/o args" } timeout { fail "(timeout) maint print psymbols w/o args" } }send_gdb "maint print psymbols psymbols_output\n"gdb_expect { -re "^maint print psymbols psymbols_output\r\n$gdb_prompt $"\ { send_gdb "shell ls psymbols_output\n" gdb_expect { -re "psymbols_output\r\n$gdb_prompt $"\ { # We want this grep to be as specific as possible, # so it's less likely to match symbol file names in # psymbols_output. Yes, this actually happened; # poor expect got tons of output, and timed out # trying to match it. --- Jim Blandy <jimb@cygnus.com> send_gdb "shell grep 'main.*function' psymbols_output\n" gdb_expect { -re ".main., function, $hex.*$gdb_prompt $"\ { pass "maint print psymbols 1" } -re ".*main. .., function, $hex.*$gdb_prompt $"\ { pass "maint print psymbols 2" } -re ".*$gdb_prompt $" { fail "maint print psymbols" } timeout { fail "(timeout) maint print psymbols" } } gdb_test "shell rm -f psymbols_output" "" } -re ".*$gdb_prompt $" { fail "maint print psymbols" } timeout { fail "(timeout) maint print psymbols" } } } -re ".*$gdb_prompt $" { fail "maint print psymbols" } timeout { fail "(timeout) maint print psymbols" } }send_gdb "maint print msymbols\n"gdb_expect { -re "print-msymbols takes an output file name and optional symbol file name.*$gdb_prompt $"\ { pass "maint print msymbols w/o args" } -re ".*$gdb_prompt $" { fail "maint print msymbols w/o args" } timeout { fail "(timeout) maint print msymbols w/o args" } }send_gdb "maint print msymbols msymbols_output\n"gdb_expect { -re "^maint print msymbols msymbols_output\r\n$gdb_prompt $"\ { send_gdb "shell ls msymbols_output\n" gdb_expect { -re "msymbols_output\r\n$gdb_prompt $"\ { send_gdb "shell grep factorial msymbols_output\n" gdb_expect { -re "\\\[ *$decimal\\\] T\[ \t\]+$hex factorial.*$gdb_prompt $"\ { pass "maint print msymbols" } -re ".*$gdb_prompt $" { fail "maint print msymbols" } timeout { fail "(timeout) maint print msymbols" } } gdb_test "shell rm -f msymbols_output" "" } -re ".*$gdb_prompt $" { fail "maint print msymbols" } timeout { fail "(timeout) maint print msymbols" } } } -re ".*$gdb_prompt $" { fail "maint print msymbols" } timeout { fail "(timeout) maint print msymbols" } }send_gdb "maint print symbols\n"gdb_expect { -re "Arguments missing: an output file name and an optional symbol file name.*$gdb_prompt $"\ { pass "maint print symbols w/o args" } -re ".*$gdb_prompt $" { fail "maint print symbols w/o args" } timeout { fail "(timeout) maint print symbols w/o args" } }# This command can legitimately take many minutes to execute. If the# executable is dynamically linked, then you get all the debugging# info for the entire library --- 89Mb on my system. -jimbset old_timeout $timeoutset timeout 600send_gdb "maint print symbols symbols_output\n"gdb_expect { -re "^maint print symbols symbols_output\r\n$gdb_prompt $"\ { send_gdb "shell ls symbols_output\n" gdb_expect { -re "symbols_output\r\n$gdb_prompt $"\ { # See comments for `maint print psymbols'. send_gdb "shell grep 'main(.*block' symbols_output\n" gdb_expect { -re "int main\\(int, char \\*\\*, char \\*\\*\\); block.*$gdb_prompt $"\ { pass "maint print symbols" } -re ".*$gdb_prompt $" { fail "maint print symbols" } timeout { fail "(timeout) maint print symbols" } } gdb_test "shell rm -f symbols_output" ""
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -