📄 gdb.texinfo
字号:
completion on an overloaded symbol.For more information about overloaded functions, see @ref{C plus plusexpressions, ,C@t{++} expressions}. You can use the command @code{setoverload-resolution off} to disable overload resolution;see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.@node Help@section Getting help@cindex online documentation@kindex helpYou can always ask @value{GDBN} itself for information 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:@smallexample(@value{GDBP}) helpList of classes of commands:aliases -- Aliases of other commandsbreakpoints -- Making program stop at certain pointsdata -- Examining datafiles -- Specifying and examining filesinternals -- Maintenance commandsobscure -- Obscure featuresrunning -- Running the programstack -- Examining the stackstatus -- Status inquiriessupport -- Support facilitiestracepoints -- Tracing of program execution without@* stopping the programuser-defined -- User-defined commandsType "help" followed by a class name for a list ofcommands in that class.Type "help" followed by command name for fulldocumentation.Command name abbreviations are allowed if unambiguous.(@value{GDBP})@end smallexample@c the above line break eliminates huge line overfull...@item help @var{class}Using one of the general help classes as an argument, you can get alist of the individual commands in that class. For example, here is thehelp display for the class @code{status}:@smallexample(@value{GDBP}) help statusStatus inquiries.List of commands:@c Line break in "show" line falsifies real output, but needed@c to fit in smallbook page size.info -- Generic command for showing things about the program being debuggedshow -- Generic command for showing things about the debuggerType "help" followed by command name for fulldocumentation.Command name abbreviations are allowed if unambiguous.(@value{GDBP})@end smallexample@item help @var{command}With a command name as @code{help} argument, @value{GDBN} displays ashort paragraph on how to use that command.@kindex apropos@item apropos @var{args}The @code{apropos @var{args}} command searches through all of the @value{GDBN}commands, and their documentation, for the regular expression specified in@var{args}. It prints out all matches found. For example:@smallexampleapropos reload@end smallexample@noindentresults in:@smallexample@c @groupset symbol-reloading -- Set dynamic symbol table reloading multiple times in one runshow symbol-reloading -- Show dynamic symbol table reloading multiple times in one run@c @end group@end smallexample@kindex complete@item complete @var{args}The @code{complete @var{args}} command lists all the possible completionsfor the beginning of a command. Use @var{args} to specify the beginning of thecommand you want completed. For example:@smallexamplecomplete i@end smallexample@noindent results in:@smallexample@groupifignoreinfoinspect@end group@end smallexample@noindent This is intended for use by @sc{gnu} Emacs.@end tableIn addition to @code{help}, you can use the @value{GDBN} commands @code{info}and @code{show} to inquire about the state of your program, or the stateof @value{GDBN} itself. Each command supports many topics of inquiry; thismanual introduces each of them in the appropriate context. The listingsunder @code{info} and under @code{show} in the Index point toall the sub-commands. @xref{Index}.@c @group@table @code@kindex info@kindex i @r{(@code{info})}@item infoThis command (abbreviated @code{i}) is for describing the state of yourprogram. For example, you can list the arguments given to your programwith @code{info args}, list the registers currently in use with @code{inforegisters}, or list the breakpoints you have set with @code{info breakpoints}.You can get a complete list of the @code{info} sub-commands with@w{@code{help info}}.@kindex set@item setYou can assign the result of an expression to an environment variable with@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with@code{set prompt $}.@kindex show@item showIn contrast to @code{info}, @code{show} is for describing the state of@value{GDBN} itself.You can change most of the things you can @code{show}, by using therelated command @code{set}; for example, you can control what numbersystem is used for displays with @code{set radix}, or simply inquirewhich is currently in use with @code{show radix}.@kindex info setTo display all the settable parameters and their currentvalues, you can use @code{show} with no arguments; you may also use@code{info set}. Both commands produce the same display.@c FIXME: "info set" violates the rule that "info" is for state of@c FIXME...program. Ck w/ GNU: "info set" to be called something else,@c FIXME...or change desc of rule---eg "state of prog and debugging session"?@end table@c @end groupHere are three miscellaneous @code{show} subcommands, all of which areexceptional in lacking corresponding @code{set} commands:@table @code@kindex show version@cindex version number@item show versionShow what version of @value{GDBN} is running. You should include thisinformation in @value{GDBN} bug-reports. If multiple versions of@value{GDBN} are in use at your site, you may need to determine whichversion of @value{GDBN} you are running; as @value{GDBN} evolves, newcommands are introduced, and old ones may wither away. Also, manysystem vendors ship variant versions of @value{GDBN}, and there arevariant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.The version number is the same as the one announced when you start@value{GDBN}.@kindex show copying@item show copyingDisplay information about permission for copying @value{GDBN}.@kindex show warranty@item show warrantyDisplay the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,if your version of @value{GDBN} comes with one.@end table@node Running@chapter Running Programs Under @value{GDBN}When you run a program under @value{GDBN}, you must first generatedebugging information when you compile it.You may start @value{GDBN} with its arguments, if any, in an environmentof your choice. If you are doing native debugging, you may redirectyour program's input and output, debug an already running process, orkill a child process.@menu* Compilation:: Compiling for debugging* Starting:: Starting your program* Arguments:: Your program's arguments* Environment:: Your program's environment* Working Directory:: Your program's working directory* Input/Output:: Your program's input and output* Attach:: Debugging an already-running process* Kill Process:: Killing the child process* Threads:: Debugging programs with multiple threads* Processes:: Debugging programs with multiple processes@end menu@node Compilation@section Compiling for debuggingIn order to debug a program effectively, you need to generatedebugging information when you compile it. This debugging informationis stored in the object file; it describes the data type of eachvariable or function and the correspondence between source line numbersand addresses in the executable code.To request debugging information, specify the @samp{-g} option when you runthe compiler.Most compilers do not include information about preprocessor macros inthe debugging information if you specify the @option{-g} flag alone,because this information is rather large. Version 3.1 of @value{NGCC},the @sc{gnu} C compiler, provides macro information if you specify theoptions @option{-gdwarf-2} and @option{-g3}; the former option requestsdebugging information in the Dwarf 2 format, and the latter requests``extra information''. In the future, we hope to find more compact waysto represent macro information, so that it can be included with@option{-g} alone.Many C compilers are unable to handle the @samp{-g} and @samp{-O}options together. Using those compilers, you cannot generate optimizedexecutables containing debugging information.@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with orwithout @samp{-O}, making it possible to debug optimized code. Werecommend that you @emph{always} use @samp{-g} whenever you compile aprogram. You may think your program is correct, but there is no sensein pushing your luck.@cindex optimized code, debugging@cindex debugging optimized codeWhen you debug a program compiled with @samp{-g -O}, remember that theoptimizer is rearranging your code; the debugger shows you what isreally there. Do not be too surprised when the execution path does notexactly match your source file! An extreme example: if you define avariable, but never use it, @value{GDBN} never sees thatvariable---because the compiler optimizes it out of existence.Some things do not work as well with @samp{-g -O} as with just@samp{-g}, particularly on machines with instruction scheduling. If indoubt, recompile with @samp{-g} alone, and if this fixes the problem,please report it to us as a bug (including a test case!).@xref{Variables}, for more information about debugging optimized code.Older versions of the @sc{gnu} C compiler permitted a variant option@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports thisformat; if your @sc{gnu} C compiler has this option, do not use it.@need 2000@node Starting@section Starting your program@cindex starting@cindex running@table @code@kindex run@kindex r @r{(@code{run})}@item run@itemx rUse the @code{run} command to start your program under @value{GDBN}.You must first specify the program name (except on VxWorks) with anargument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of@value{GDBN}}), or by using the @code{file} or @code{exec-file} command(@pxref{Files, ,Commands to specify files}).@end tableIf you are running your program in an execution environment thatsupports processes, @code{run} creates an inferior process and makesthat process run your program. (In environments without processes,@code{run} jumps to the start of your program.)The execution of a program is affected by certain information itreceives from its superior. @value{GDBN} provides ways to specify thisinformation, which you must do @emph{before} starting your program. (Youcan change it after starting your program, but such changes only affectyour program the next time you start it.) This information may bedivided into four categories:@table @asis@item The @emph{arguments.}Specify the arguments to give your program as the arguments of the@code{run} command. If a shell is available on your target, the shellis used to pass the arguments, so that you may use normal conventions(such as wildcard expansion or variable substitution) in describingthe arguments.In Unix systems, you can control which shell is used with the@code{SHELL} environment variable.@xref{Arguments, ,Your program's arguments}.@item The @emph{environment.}Your program normally inherits its environment from @value{GDBN}, but you canuse the @value{GDBN} commands @code{set environment} and @code{unsetenvironment} to change parts of the environment that affectyour program. @xref{Environment, ,Your program's environment}.@item The @emph{working directory.}Your program inherits its working directory from @value{GDBN}. You can setthe @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.@xref{Working Directory, ,Your program's working directory}.@item The @emph{standard input and output.}Your program normally uses the same device for standard input andstandard output as @value{GDBN} is using. You can redirect input and outputin the @code{run} command line, or you can use the @code{tty} command toset a different device for your program.@xref{Input/Output, ,Your program's input and output}.@cindex pipes@emph{Warning:} While input and output redirection work, you cannot usepipes to pass the output of the program you are debugging to anotherprogram; if you attempt this, @value{GDBN} is likely to wind up debugging thewrong program.@end tableWhen you issue the @code{run} command, your program begins to executeimmediately. @xref{Stopping, ,Stopping and continuing}, for discussionof how to arrange for your program to stop. Once your program hasstopped, you may call functions in your program, using the @code{print}or @code{call} commands. @xref{Data, ,Examining Data}.If the modification time of your symbol file has changed since the lasttime @value{GDBN} read its symbols, @val
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -