⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bashdb.texi

📁 bash debugger. You can use this tool to debug bash shell script
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
program doesn't trap @code{SIGINT}).@node Free Software@unnumberedsec Free software@DBG is @dfn{free software}, protected by the @sc{gnu}General Public License(GPL).  The GPL gives you the freedom to copy or adapt a licensedprogram---but every person getting a copy also gets with it thefreedom to modify that copy (which means that they must get access tothe source code), and the freedom to distribute further copies.Typical software companies use copyrights to limit your freedoms; theFree Software Foundation uses the GPL to preserve these freedoms.Fundamentally, the General Public License is a license which says thatyou have these freedoms and that you cannot take these freedoms awayfrom anyone else.@unnumberedsec Free Software Needs Free DocumentationThe biggest deficiency in the free software community today is not inthe software---it is the lack of good free documentation that we caninclude with the free software.  Many of our most importantprograms do not come with free reference manuals and free introductorytexts.  Documentation is an essential part of any software package;when an important free software package does not come with a freemanual and a free tutorial, that is a major gap.  We have many suchgaps today.Consider Perl, for instance.  The tutorial manuals that peoplenormally use are non-free.  How did this come about?  Because theauthors of those manuals published them with restrictive terms---nocopying, no modification, source files not available---which excludethem from the free software world.That wasn't the first time this sort of thing happened, and it was farfrom the last.  Many times we have heard a GNU user eagerly describe amanual that he is writing, his intended contribution to the community,only to learn that he had ruined everything by signing a publicationcontract to make it non-free.Free documentation, like free software, is a matter of freedom, notprice.  The problem with the non-free manual is not that publisherscharge a price for printed copies---that in itself is fine.  (The FreeSoftware Foundation sells printed copies of manuals, too.)  Theproblem is the restrictions on the use of the manual.  Free manualsare available in source code form, and give you permission to copy andmodify.  Non-free manuals do not allow this.The criteria of freedom for a free manual are roughly the same as forfree software.  Redistribution (including the normal kinds ofcommercial redistribution) must be permitted, so that the manual canaccompany every copy of the program, both on-line and on paper.Permission for modification of the technical content is crucial too.When people modify the software, adding or changing features, if theyare conscientious they will change the manual too---so they canprovide accurate and clear documentation for the modified program.  Amanual that leaves you no choice but to write a new manual to documenta changed version of the program is not really available to ourcommunity.Some kinds of limits on the way modification is handled areacceptable.  For example, requirements to preserve the originalauthor's copyright notice, the distribution terms, or the list ofauthors, are ok.  It is also no problem to require modified versionsto include notice that they were modified.  Even entire sections thatmay not be deleted or changed are acceptable, as long as they dealwith nontechnical topics (like this one).  These kinds of restrictionsare acceptable because they don't obstruct the community's normal useof the manual.However, it must be possible to modify all the @emph{technical}content of the manual, and then distribute the result in all the usualmedia, through all the usual channels.  Otherwise, the restrictionsobstruct the use of the manual, it is not free, and we need anothermanual to replace it.Please spread the word about this issue.  Our community continues tolose manuals to proprietary publishing.  If we spread the word thatfree software needs free reference manuals and free tutorials, perhapsthe next person who wants to contribute by writing documentation willrealize, before it is too late, that only free manuals contribute tothe free software community.If you are writing documentation, please insist on publishing it underthe GNU Free Documentation License or another free documentationlicense.  Remember that this decision requires your approval---youdon't have to let the publisher decide.  Some commercial publisherswill use a free license if you insist, but they will not propose theoption; it is up to you to raise the issue and say firmly that this iswhat you want.  If the publisher you are dealing with refuses, pleasetry other publishers.  If you're not sure whether a proposed licenseis free, write to @email{licensing@@gnu.org}.You can encourage commercial publishers to sell more free, copyleftedmanuals and tutorials by buying them, and particularly by buyingcopies from the publishers that paid for their writing or for majorimprovements.  Meanwhile, try to avoid buying non-free documentationat all.  Check the distribution terms of a manual before you buy it,and insist that whoever seeks your business must respect your freedom.Check the history of the book, and try to reward the publishers thathave paid or pay the authors to work on it.The Free Software Foundation maintains a list of free documentationpublished by other publishers, at@url{http://www.fsf.org/doc/other-free-books.html}.@node Invocation@chapter Getting in and outThis chapter discusses how to start @value{DBG}, and how to get out of it.The essentials are:@itemize @bullet@itemtype @samp{bash --debugger @emph{script-name}} or @samp{bashdb@emph{script-name}} to start @value{DBG}. Or...@item type @samp{bashdb -c @emph{command string}} to give a string to run under the debugger. Or ..@item modify your program to enter the debugger at a particular point:@code{source ../bashdb-trace} and @code{_Dbg_debugger}.@itemtype @kbd{quit} or @kbd{C-d} inside the debugger to exit.@end itemizeThere are also two front-ends available as well. One can alsoenter the debugger inside emacs via the command @code{M-x bashdb}after loading Emacs' Grand Unified Debugger, @code{gud}. See@ref{Emacs,,Using the BASH debugger from @value{Emacs}}. And there issupport in a @value{DDD} for bash.@menu* Starting the BASH debugger::    How to enter the BASH debugger* Quitting the BASH debugger::    How to leave the BASH debugger* Calling from Program::          Calling the debugger from inside your program@end menu@node Starting the BASH debugger@section Starting the BASH debugger@emph{Note: it is important to use a debugger-enabled bash. You willget an error message if the debugger is run under a version of BASHthat does not have debugging support.}As mentioned above, one can enter @DBG via Emacs orDDD. However you don't have to use either of these. And these stillneed a way on their own to get things started.There are in fact two @emph{other} ways to start @value{DBG}.  Thefirst way is to pass the @samp{--debugger} option to bash with thename of your script the scripts arguments following that, or with acommand string (@code{-c}).@examplebash --debugger @var{script} @var{script-arguments...}bash --debugger -c @var{command-string}...@end exampleThis calls a debugger initialization script. It works much like a@acronym{BASH} login profile which may set variables and definefunctions. But this shell profile is customized for debugging and assuch arranges for itself to get called before each statement isexecuted. Although there are some problems at present in I/Oredirection that the method described next doesn't have, it isexpected that over time more features will be enabled in bash when the@samp{--debugger} option is in effect. By default, both debugging inEmacs via GUD (@ref{Emacs,,Using the BASH debugger under Emacs}) anddebugging via @value{DDD} work via this method.The form @samp{bash --debugger -c ...} can be used to get into thedebugger without having to give a script name to debug. Sometimes youmay want to do this just to see how the debugger works: try somedebugger commands or maybe get online help. If you run @code{ddd--bash} without giving a script name, it in fact uses this form.In order for the @samp{--debugger} option to work however, you musthave the debugger scripts installed in a place where @DBG can findthem. For this reason, in developing @value{DBG}, I use a secondmethod more often; it doesn't require the bash debugger to beinstalled. This method uses another script called @code{bashdb} whichallows for giving its own options, the final option is signaled byadding @code{--}). After this, the name of the script to debugged andany the arguments to pass to that script are given. Using this method,one would start the debugger like this:@examplebash @var{path-to-bashdb}/bashdb @var{bashdb-options} -- @var{script} @var{script-arguments...}@end exampleIf you don't need to pass dash options to your program which might getconfused with the debugger options, then you don't need to add the@code{--}.@footnote{And in the interest of full disclosure, althoughthis was not shown in the example it is possible to add the @code{--}@emph{after} the script name to be debugged but before the firstprogram option with a dash.}As with the first method, @code{bash} should be a debugger-enabledbash. If @code{bashdb} has the path to bash in it at the top (e.g. via@code{#!}), and @code{bashdb} can be found in your program-searchpath, then this might be equivalent to the above:@examplebashdb @var{bashdb-options} -- @var{script} @var{script-arguments...}@end exampleThere are two or three disadvantages however of running a debuggerthis way. First @code{$0} will have the value @code{bashdb} ratherthan the script you are trying to run. For some scripts this maychange the behavior of the debugged script. Second a traceback willcontain additional lines showing the ``source''-ing of the debuggedscript from @code{bashdb}. And third, although this way works betterthan the first method, over time this way may come into disuse. An option that you'll probably need to use if bashdb isn't installedbut run out of the source code directory is @samp{-L} which specifiesthe directory that contains the debugger script files.You can further control how bashdb starts up by using command-lineoptions. bashdb itself can remind you of the options available.@noindentType@examplebashdb -h@end example@noindentto display all available options and briefly describe their use.When the bash debugger is invoked either by the @code{bashdb}front-end script or @code{bash --debugging}, the first argument thatdoes not have an associated option flag for @code{bashdb} or@code{bash} (as the case may be) is used as the name a the script fileto be debugged, and any following options get passed the debuggedscript.Options for the @code{bashdb} front-end are shown in thefollowing list.  @menu* Options for the bashdb script::   Options you can pass in starting bashdb@end menu@node Options for the bashdb script@subsection Command-line options for @code{bashdb} scriptYou can run @DBG in various alternative modes---for example, in batchmode or quiet mode. If @code{getopts} support is available the scriptalso allows long-form command options.@table @code@item -h | --help@cindex @code{-h}@cindex @code{--help}This option causes @value{DBG} to print some basic help and exit.@item -V@cindex @code{-V}This option causes @DBG to print its version number,no-warranty blurb, and exit.@item -c | --command @var{cmd}@cindex @code{-c}@cindex @code{--command}Run the string instead of running a script@item -B | --basename@cindex @code{-B}@cindex @code{--basename}This option causes @DBG to print its version number andno-warranty blurb, and exit.@item -n | --nx | --no-init@cindex @code{-n}@cindex @code{--nx}@cindex @code{--no-init}Do not execute commands found in any initialization files.  Normally,@acronym{BASH} executes the commands in these files after all the commandoptions and arguments have been processed.  @xref{Command Files,,Commandfiles}.@item -q | --quiet@cindex @code{-q}@cindex @code{--quiet}``Quiet''.  Do not print the introductory and copyright messages.  Thesemessages are also suppressed in batch mode.@item -t | --terminal | --tty @var{tty}@cindex @code{-t}@cindex @code{--terminal}@cindex @code{--tty}``Terminal output''.  Set the file or terminal that you want debugger commandoutput to go to. Note that the debugger output is independent of thedebugged script output.o@item -L | --library @var{directory}@cindex @code{-L}@cindex @code{--library}Set directory where debugger files reside to @var{directory}. Thedefault location is @code{../lib/bashdb} relative to the place thatthe bashdb script is located. For example if bashdb is located in@code{@value{bindir}/bashdb}, the default library location will be@code{@value{libdir}/bashdb} which may or may not exist. If it doesn'tyou'll get an error when you run bashdb. Only if the default locationis incorrect, should you need to use the @code{-L} option.@item -T | --tempdir @var{directory}@cindex @code{-T}@cindex @code{--tempdir}Set directory to use for writing temporary files.@end table@node Quitting the BASH debugger@section Quitting the BASH debugger@cindex interruptAn interrupt (often @kbd{C-c}) does not exit from @value{DBG}, butrather terminates the action of any @DBG command that is inprogress and returns to @value{DBG} command level.  Inside a debuggercommand interpreter, use @code{quit} command (@pxref{Quit, ,Quittingthe BASH debugger}).There way to terminate the debugger is to use the @code{kill}command. This does more forceful @code{kill -9}. It can be used incases where @code{quit} doesn't work.@node Calling from Program@section Calling the BASH debugger from inside your program@menu* Program-Controlled Line Tracing::* Having the debugger intercept signals::@end menuRunning a program from the debugger adds a bit of overhead and slows

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -