📄 bashdb.texi
字号:
You can abbreviate the long name of @DBG command to the firstfew letters of the command name, if that abbreviation is unambiguous;and you can repeat the @code{next} o r@code{step} commands by typingjust @key{RET}. Some commands which require a parameter, such as @code{print} remember the argument that was given to them. @menu* Command Syntax:: How to give commands to the BASH debugger* Help:: How to ask for help (help)* Quit:: Leaving the debugger (quit, kill)* Information:: Status and Debugger settings (info, show)* Stopping:: Stopping and continuing (break, watch, step, cont...)* Stack:: Examining the stack frame (where, up, down, frame)* List:: Printing source files (list)* Search:: Searching source files (/pat/ ?pat?)* Data:: Examining data (print, examine, info variables)* Evaluation/Execution:: Arbitrary execution (eval, shell)* Interfacing to the OS:: Interfacing to the OS (cd, pwd)* Auto Display:: Executing expressions on stop (display, undisplay)* Controlling bashdb:: Controlling bashdb (annotate, file, prompt, history...)@end menu@node Command Syntax@section Command syntaxA @acronym{BASH} debugger command is a single line of input. There isno limit on how long it can be. It starts with a command name, whichis followed by arguments whose meaning depends on the command name.For example, the command @code{step} accepts an argument which is thenumber of times to step, as in @samp{step 5}. You can also use the@code{step} command with no arguments. Some commands do not allow anyarguments.@cindex repeating next/step commands@kindex RET @r{(repeat last command)}A blank line as input to @DBG (typing just @key{RET}) means torepeat the previous next or step command. @kindex # @r{(a comment)}@cindex commentAny text from a @kbd{#} to the end of the line is a comment; it doesnothing. This is useful mainly in command files (@pxref{CommandFiles,,Command files}).@node Help@section Getting help (@samp{help})@cindex online documentationOnce inside the @acronym{BASH} debugger, you can always ask it forinformation on its commands, using the command @code{help}.@table @code@kindex h @r{(@code{help})}@item help@itemx hYou can use @code{help} (abbreviated @code{h}) with no arguments todisplay a short list of named classes of commands:@end table @flushleft@smallexamplebashdb<0> @b{help}bashdb commands:List/search source lines: Control script execution:------------------------- ------------------------- l [start|.] [cnt] List cnt lines T [n] Stack trace from line start s [n] Single step [n times] l sub List source code fn n [n] Next, steps over subs - or . List previous/current line <CR>/<Enter> Repeat last n or s w [line] List around line c [linespec] Continue [to linespec] f filename View source in file L List all breakpoints /pat/ Search forward for pat b linespec Set breakpoint ?pat? Search backward for pat del [n].. or D Delete a/all breaks by entry numberDebugger controls: skip skip execution of cmd------------------------- cl linespec Delete breakpoints by H [num] Show last num commands line spec q [exp] or ^D Quit returning exp R [args] Attempt a restart info [cmd] Get info on cmd. u [n] Go up stack by n or 1. !n or hi n Run debugger history n do [n] Go down stack by n or 1. h or ? [cmd] Get help on command W [var] Add watchpoint. If no info [cmd] Get info on cmd no expr, delete all show [cmd] Show settings We [expr] Add Watchpoint arith expr so file read in dbg commands t Toggle trace en/di n enable/disable brkpt, set x y set a debugger variable watchpoint, or display e bash-cmd evaluate a bash command tb linespec Add one-time break disp expr add a display expr a linespec cmd eval "cmd" at linespec M Show module versions A delete all actions x expr evaluate expression ret jump out of fn or source (via declare, let, eval) finish execute until return deb debug into another cond n exp set breakpoint condition shell script !! cmd [args] execute shell command "cmd" with "args" file filename Set script filename to read for current source.Data Examination: also see e, t, x------------------------- p variable Print variable V [[!]pat] List variable(s) matching or not (!) matching pattern pat S [[!]pat] List subroutine names [not] matching pattern patReadline command line editing (emacs/vi mode) is available.For more help, type h <cmd> or consult online-documentation.@end smallexample@end flushleft@c the above line break eliminates huge line overfull...@table @code@item help @var{command}With a command name as @code{help} argument, the @acronym{BASH}debugger displays short information on how to use that command.@examplebashdb<0> @b{help list}l linespec List window lines starting at linespec.l min incr List incr lines starting at 'min' linespec.l List next window of lines.l . Same as above. Long command name: list.@end exampleIn addition to @code{help}, you can use the debugger command@code{info} to inquire about the state of your script, or the state of@DBG itself. The listings under @code{info} in the Indexpoint to all the sub-commands. @xref{Command Index}.@end table@c @group@table @code@kindex info@kindex i @r{(@code{info})}@item infoThis command (abbreviated @code{i}) is for describing the state ofyour program. For example, you can list the arguments given to yourscript with @code{info args}, or list the breakpoints you have setwith @code{info breakpoints}. You can get a complete list of the@code{info} sub-commands with @w{@code{help info}}.@examplebashdb<0> @b{help info}List of info subcommands:info args -- Argument variables (e.g. $1, $2, ...) of the current stack frame.info breakpoints -- Status of user-settable breakpointsinfo display -- Show all display expressionsinfo files -- Source files in the programinfo functions -- All function namesinfo line -- list current line number and and file nameinfo program -- Execution status of the program.info signals -- What debugger does when program gets various signalsinfo source -- Information about the current source fileinfo stack -- Backtrace of the stackinfo terminal -- Print terminal deviceinfo variables -- All global and static variable namesinfo warranty -- Various kinds of warranty you do not havebashdb<1> @b{info source}Current script file is parm.shContains 34 lines.@end example@end table@node Quit@section Quitting the BASH debugger (@samp{quit}, @samp{kill})@table @code@kindex quit @r{[}@var{expression} @ovar{subshell-levels}@r{]}@kindex q @r{(@code{quit})}@item quit @ovar{expression}@item quit @r{[}@var{expression} @ovar{subshell-levels}@r{]}@itemx qTo exit @value{DBG}, use the @code{quit} command (abbreviated@code{q}), or type an end-of-file character (usually @kbd{C-d}). Ifyou do not supply @var{expression}, @DBG will try to terminatenormally or with exit code 0. Otherwise it will terminate using theresult of @var{expression} as the exit code. A simple @code{quit} tries to terminate all nested subshells that maybe in effect. If you are nested a subshell, this is normallyindicated in a debugger prompt by the number of parentheses that thehistory number is inside --- no parenthesis means there is no subshellin effect. The dynamic variable @env{BASH_SUBSHELL} also contains thenumber of subshells in effect. If you want only to terminate some number of subshells but not all ofthem, you can give a count of the number of subshells to leave afterthe return-code expression. To leave just one level of subshell@code{return} does almost the same thing. (See @pxref{Returning,,Returning}) There is a subtle difference between the two though:@code{return} will leave you at the beginning of the next statementwhile @code{quit} may leave you at the place the subshell was invokedwhich may be in the middle of another command such as an assingmentstatement or condition test.If the environment variable @code{BASHDB_QUIT_ON_QUIT} is set, when theprogram terminates, the debugger will also terminate too. This may beuseful if you are debugging a script which calls another script andyou want this inner script just to return to the outer script.@item kill@kindex k @r{(@code{kill})}@itemx kIn situations where @code{quit} doesn't work we provide an alternativeand more forceful quit command: @code{kill}. This sends to the OSnon-maskable KILL signal with the debugger process number. No cleanupof temporary files is done by the program.@end table@node Stopping@section Stopping and Resuming ExecutionOne important use of a debugger is to stop your program @emph{before} itterminates so that if your script might run into trouble, you caninvestigate and find out why. However should your script accidentlycontinue to termination, @DBG has arranged for it not to leave thedebugger without your explicit instruction. That way, you can restartthe program using the same command arguments.Inside @value{DBG}, your script may stop for any of several reasons,such as a signal, a breakpoint, or reaching a new line after adebugger command such as @code{step}. You may then examine andchange variables, set new breakpoints or remove old ones, and thencontinue execution. @menu* Breakpoints:: Breakpoints, watchpoints (break, tbreak, watch, watche, clear)* Resuming Execution:: Resuming execution (continue, step, next, skip, finish, return, debug)* Signals:: Signals@end menu@node Breakpoints@subsection Breakpoints, watchpoints (@samp{break}, @samp{tbreak}, @samp{watch}, @samp{watche}...)@cindex breakpointsA @dfn{breakpoint} makes your script stop whenever a certain point inthe program is reached. For each breakpoint, you can add conditions tocontrol in finer detail whether your script stops. You can set breakpoints specify the place where your script shouldstop the @code{break} command and its variants (@pxref{Set Breaks,,Setting breakpoints}). These commands allow own to specify thelocation by line number and file name or function name.@cindex watchpoints@cindex breakpoint on variable modificationA @dfn{watchpoint} is a special breakpoint that stops your script whenthe value of an expression changes. There is a different command toset watchpoints (@pxref{Set Watchpoints, ,Setting watchpoints}). But aside from that, you can manage a watchpoint like any otherbreakpoint: you delete enable, and disable both breakpoints andwatchpoints using the same commands.You can arrange to have values from your program displayed automaticallywhenever @value{BASH} stops at a breakpoint. @xref{Auto Display,,Automatic display}.@cindex breakpoint numbers@cindex numbers for breakpoints@value{dBGP} assigns a number to each breakpoint when you create it;these numbers are successive integers starting with one. In many ofthe commands for controlling various features of breakpoints you usethe breakpoint number to say which breakpoint you want to change.Each breakpoint may be @dfn{enabled} or @dfn{disabled}; if disabled,it has no effect on your script until you enable it again.@cindex watchpoints numbers@cindex numbers for watchpointsWatchpoint numbers however are distinguished from breakpoint numbers byvirtue of their being suffixed with the either an upper- or lower-case`W'. For example, to enable breakpoint entry 0 along with watchpointentry 1 you would write @samp{enable 1 2w}, the ``2w'' refers to thewatchpoint; ``2W'' would work just as well.@ifset FINISHED@cindex breakpoint ranges@cindex ranges of breakpointsSome @DBG commands accept a range of breakpoints on which tooperate. A breakpoint range is either a single breakpoint number, like@samp{5}, or two such numbers, in increasing order, separated by ahyphen, like @samp{5-7}. When a breakpoint range is given to a command,all breakpoint in that range are operated on.@end ifset@menu* Set Breaks:: Setting breakpoints (break, tbreak)* Set Watchpoints:: Setting watchpoints (watch, watche)* Break Commands:: Breakpoint command lists (command)* Delete Breaks:: Deleting breakpoints (delete, clear)* Disabling:: Disabling breakpoints (disable, enable)* Conditions:: Break conditions (condition)@end menu@node Set Breaks@subsubsection Setting breakpoints (@samp{break} @samp{tbreak})@kindex break@kindex b @r{(@code{break})}@cindex latest breakpointBreakpoints are set with the @code{break} command (abbreviated@code{b}). @table @code@item break @var{function}Set a breakpoint at entry to function @var{function}.@item break @var{linenum}Set a breakpoint at line @var{linenum} in the current source file.The current source file is the last file whose source text was printed.The breakpoint will stop your script just before it executes any of thecode on that line.@item break @var{filename}:@var{linenum}Set a breakpoint at line @var{linenum} in source file @var{filename};@var{filename} has to be one of the files previously read in and hasto be specified exactly as the name used when read in. For a list ofread-in files, use the @samp{info files} command.@ifset FINISHED@item breakWhen called without any arguments, @code{break} sets a breakpoint atthe next instruction to be executed in the selected stack frame(@pxref{Stack, ,Examining the Stack Frame}). In any selected frame but theinnermost, this makes your script stop as soon as control returns tothat frame. If you use @code{break} without an argument in theinnermost frame, @DBG stops the next time it reaches thecurrent location; this may be useful inside loops.@end ifset@item break @dots{} if @var{cond}Set a breakpoint with condition @var{cond}; evaluate the expression@var{cond} each time the breakpoint is reache
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -