📄 gdb.texinfo
字号:
the @code{p} command, since it can print the value ofany expression---and that expression can include subroutine calls andassignments.@smallexample(@value{GDBP}) @b{p len_lquote=strlen(lquote)}$5 = 7(@value{GDBP}) @b{p len_rquote=strlen(rquote)}$6 = 9@end smallexample@noindentIs that enough to fix the problem of using the new quotes with the@code{m4} built-in @code{defn}? We can allow @code{m4} to continueexecuting with the @code{c} (@code{continue}) command, and then try theexample that caused trouble initially:@smallexample(@value{GDBP}) @b{c}Continuing.@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}baz0000@end smallexample@noindentSuccess! The new quotes now work just as well as the default ones. Theproblem seems to have been just the two typos defining the wronglengths. We allow @code{m4} exit by giving it an EOF as input:@smallexample@b{C-d}Program exited normally.@end smallexample@noindentThe message @samp{Program exited normally.} is from @value{GDBN}; itindicates @code{m4} has finished executing. We can end our @value{GDBN}session with the @value{GDBN} @code{quit} command.@smallexample(@value{GDBP}) @b{quit}@end smallexample@node Invocation@chapter Getting In and Out of @value{GDBN}This chapter discusses how to start @value{GDBN}, and how to get out of it.The essentials are:@itemize @bullet@itemtype @samp{@value{GDBP}} to start @value{GDBN}.@itemtype @kbd{quit} or @kbd{C-d} to exit.@end itemize@menu* Invoking GDB:: How to start @value{GDBN}* Quitting GDB:: How to quit @value{GDBN}* Shell Commands:: How to use shell commands inside @value{GDBN}* Logging output:: How to log @value{GDBN}'s output to a file@end menu@node Invoking GDB@section Invoking @value{GDBN}Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,@value{GDBN} reads commands from the terminal until you tell it to exit.You can also run @code{@value{GDBP}} with a variety of arguments and options,to specify more of your debugging environment at the outset.The command-line options described here are designedto cover a variety of situations; in some environments, some of theseoptions may effectively be unavailable.The most usual way to start @value{GDBN} is with one argument,specifying an executable program:@smallexample@value{GDBP} @var{program}@end smallexample@noindentYou can also start with both an executable program and a core filespecified:@smallexample@value{GDBP} @var{program} @var{core}@end smallexampleYou can, instead, specify a process ID as a second argument, if you wantto debug a running process:@smallexample@value{GDBP} @var{program} 1234@end smallexample@noindentwould attach @value{GDBN} to process @code{1234} (unless you also have a filenamed @file{1234}; @value{GDBN} does check for a core file first).Taking advantage of the second command-line argument requires a fairlycomplete operating system; when you use @value{GDBN} as a remotedebugger attached to a bare board, there may not be any notion of``process'', and there is often no way to get a core dump. @value{GDBN}will warn you if it is unable to attach or to read core dumps.You can optionally have @code{@value{GDBP}} pass any arguments after theexecutable file to the inferior using @code{--args}. This option stopsoption processing.@smallexamplegdb --args gcc -O2 -c foo.c@end smallexampleThis will cause @code{@value{GDBP}} to debug @code{gcc}, and to set@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.You can run @code{@value{GDBP}} without printing the front material, which describes@value{GDBN}'s non-warranty, by specifying @code{-silent}:@smallexample@value{GDBP} -silent@end smallexample@noindentYou can further control how @value{GDBN} starts up by using command-lineoptions. @value{GDBN} itself can remind you of the options available.@noindentType@smallexample@value{GDBP} -help@end smallexample@noindentto display all available options and briefly describe their use(@samp{@value{GDBP} -h} is a shorter equivalent).All options and command line arguments you give are processedin sequential order. The order makes a difference when the@samp{-x} option is used.@menu* File Options:: Choosing files* Mode Options:: Choosing modes@end menu@node File Options@subsection Choosing filesWhen @value{GDBN} starts, it reads any arguments other than options asspecifying an executable file and core file (or process ID). This isthe same as if the arguments were specified by the @samp{-se} and@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads thefirst argument that does not have an associated option flag asequivalent to the @samp{-se} option followed by that argument; and thesecond argument that does not have an associated option flag, if any, asequivalent to the @samp{-c}/@samp{-p} option followed by that argument.)If the second argument begins with a decimal digit, @value{GDBN} willfirst attempt to attach to it as a process, and if that fails, attemptto open it as a corefile. If you have a corefile whose name begins witha digit, you can prevent @value{GDBN} from treating it as a pid byprefixing it with @file{./}, eg. @file{./12345}.If @value{GDBN} has not been configured to included core file support,such as for most embedded targets, then it will complain about a secondargument and ignore it.Many options have both long and short forms; both are shown in thefollowing list. @value{GDBN} also recognizes the long forms if you truncatethem, so long as enough of the option is present to be unambiguous.(If you prefer, you can flag option arguments with @samp{--} ratherthan @samp{-}, though we illustrate the more usual convention.)@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This@c way, both those who look for -foo and --foo in the index, will find@c it.@table @code@item -symbols @var{file}@itemx -s @var{file}@cindex @code{--symbols}@cindex @code{-s}Read symbol table from file @var{file}.@item -exec @var{file}@itemx -e @var{file}@cindex @code{--exec}@cindex @code{-e}Use file @var{file} as the executable file to execute when appropriate,and for examining pure data in conjunction with a core dump.@item -se @var{file}@cindex @code{--se}Read symbol table from file @var{file} and use it as the executablefile.@item -core @var{file}@itemx -c @var{file}@cindex @code{--core}@cindex @code{-c}Use file @var{file} as a core dump to examine.@item -c @var{number}@item -pid @var{number}@itemx -p @var{number}@cindex @code{--pid}@cindex @code{-p}Connect to process ID @var{number}, as with the @code{attach} command.If there is no such process, @value{GDBN} will attempt to open a corefile named @var{number}.@item -command @var{file}@itemx -x @var{file}@cindex @code{--command}@cindex @code{-x}Execute @value{GDBN} commands from file @var{file}. @xref{CommandFiles,, Command files}.@item -directory @var{directory}@itemx -d @var{directory}@cindex @code{--directory}@cindex @code{-d}Add @var{directory} to the path to search for source files.@item -m@itemx -mapped@cindex @code{--mapped}@cindex @code{-m}@emph{Warning: this option depends on operating system facilities that are notsupported on all systems.}@*If memory-mapped files are available on your system through the @code{mmap}system call, you can use this optionto have @value{GDBN} write the symbols from yourprogram into a reusable file in the current directory. If the program you are debugging iscalled @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.Future @value{GDBN} debugging sessions notice the presence of this file,and can quickly map in symbol information from it, rather than readingthe symbol table from the executable program.The @file{.syms} file is specific to the host machine where @value{GDBN}is run. It holds an exact image of the internal @value{GDBN} symboltable. It cannot be shared across multiple host platforms.@item -r@itemx -readnow@cindex @code{--readnow}@cindex @code{-r}Read each symbol file's entire symbol table immediately, rather thanthe default, which is to read it incrementally as it is needed.This makes startup slower, but makes future operations faster.@end tableYou typically combine the @code{-mapped} and @code{-readnow} options inorder to build a @file{.syms} file that contains complete symbolinformation. (@xref{Files,,Commands to specify files}, for informationon @file{.syms} files.) A simple @value{GDBN} invocation to do nothingbut build a @file{.syms} file for future use is:@smallexamplegdb -batch -nx -mapped -readnow programname@end smallexample@node Mode Options@subsection Choosing modesYou can run @value{GDBN} in various alternative modes---for example, inbatch mode or quiet mode.@table @code@item -nx@itemx -n@cindex @code{--nx}@cindex @code{-n}Do not execute commands found in any initialization files. Normally,@value{GDBN} executes the commands in these files after all the commandoptions and arguments have been processed. @xref{Command Files,,Commandfiles}.@item -quiet@itemx -silent@itemx -q@cindex @code{--quiet}@cindex @code{--silent}@cindex @code{-q}``Quiet''. Do not print the introductory and copyright messages. Thesemessages are also suppressed in batch mode.@item -batch@cindex @code{--batch}Run in batch mode. Exit with status @code{0} after processing all thecommand files specified with @samp{-x} (and all commands frominitialization files, if not inhibited with @samp{-n}). Exit withnonzero status if an error occurs in executing the @value{GDBN} commandsin the command files.Batch mode may be useful for running @value{GDBN} as a filter, forexample to download and run a program on another computer; in order tomake this more useful, the message@smallexampleProgram exited normally.@end smallexample@noindent(which is ordinarily issued whenever a program running under@value{GDBN} control terminates) is not issued when running in batchmode.@item -nowindows@itemx -nw@cindex @code{--nowindows}@cindex @code{-nw}``No windows''. If @value{GDBN} comes with a graphical user interface(GUI) built in, then this option tells @value{GDBN} to only use the command-lineinterface. If no GUI is available, this option has no effect.@item -windows@itemx -w@cindex @code{--windows}@cindex @code{-w}If @value{GDBN} includes a GUI, then this option requires it to beused if possible.@item -cd @var{directory}@cindex @code{--cd}Run @value{GDBN} using @var{directory} as its working directory,instead of the current directory.@item -fullname@itemx -f@cindex @code{--fullname}@cindex @code{-f}@sc{gnu} Emacs sets this option when it runs @value{GDBN} as asubprocess. It tells @value{GDBN} to output the full file name and linenumber in a standard, recognizable fashion each time a stack frame isdisplayed (which includes each time your program stops). Thisrecognizable format looks like two @samp{\032} characters, followed bythe file name, line number and character position separated by colons,and a newline. The Emacs-to-@value{GDBN} interface program uses the two@samp{\032} characters as a signal to display the source code for theframe.@item -epoch
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -