📄 gdb.texinfo
字号:
@noindentYou can either press @key{RET} at this point, to run the @code{infobreakpoints} command, or backspace and enter something else, if@samp{breakpoints} doesn't look like the command you expected. (If youwere sure you wanted @code{info breakpoints} in the first place, youmight as well just type @key{RET} immediately after @samp{info bre},to exploit command abbreviations rather than command completion).If there is more than one possibility for the next word when you press@key{TAB}, _GDBN__ will sound a bell. You can either supply morecharacters and try again, or just press @key{TAB} a second time, and_GDBN__ will display all the possible completions for that word. Forexample, you might want to set a breakpoint on a subroutine whose namebegins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} _GDBN__just sounds the bell. Typing @key{TAB} again will display all thefunction names in your program that begin with those characters, forexample:@example(_GDBP__) b make_ @key{TAB}@exdent _GDBN__ sounds bell; press @key{TAB} again, to see:make_a_section_from_file make_environ make_abs_section make_function_type make_blockvector make_pointer_type make_cleanup make_reference_type make_command make_symbol_completion_list(GDBP__) b make_@end example@noindentAfter displaying the available possibilities, _GDBN__ copies yourpartial input (@samp{b make_} in the example) so you can finish thecommand.If you just want to see the list of alternatives in the first place, youcan press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}means @kbd{@key{META} ?}. You can type this_if__(_GENERIC__||!_DOSHOST__)either by holding down akey designated as the @key{META} shift on your keyboard (if there isone) while typing @kbd{?}, or_fi__(_GENERIC__||!_DOSHOST__)as @key{ESC} followed by @kbd{?}.@cindex quotes in commands@cindex completion of quoted stringsSometimes the string you need, while logically a ``word'', may containparentheses or other characters that _GDBN__ normally excludes from itsnotion of a word. To permit word completion to work in this situation,you may enclose words in @code{'} (single quote marks) in _GDBN__ commands.The most likely situation where you might need this is in typing thename of a C++ function. This is because C++ allows function overloading(multiple definitions of the same function, distinguished by argumenttype). For example, when you want to set a breakpoint you may need todistinguish whether you mean the version of @code{name} that takes an@code{int} parameter, @code{name(int)}, or the version that takes a@code{float} parameter, @code{name(float)}. To use the word-completionfacilities in this situation, type a single quote @code{'} at thebeginning of the function name. This alerts _GDBN__ that it may need toconsider more information than usual when you press @key{TAB} or@kbd{M-?} to request word completion:@example(_GDBP__) b 'bubble( @key{M-?}bubble(double,double) bubble(int,int)(_GDBP__) b 'bubble(@end exampleIn some cases, _GDBN__ can tell that completing a name will requirequotes. When this happens, _GDBN__ will insert the quote for you (whilecompleting as much as it can) if you do not type the quote in the firstplace:@example(_GDBP__) b bub @key{TAB}@exdent _GDBN__ alters your input line to the following, and rings a bell:(_GDBP__) b 'bubble(@end example@noindentIn general, _GDBN__ can tell that a quote is needed (and inserts it) ifyou have not yet started typing the argument list when you ask forcompletion on an overloaded symbol.@node Help@section Getting Help@cindex online documentation@kindex helpYou can always ask _GDBN__ itself for information on its commands, using thecommand @code{help}.@table @code@item help@itemx h@kindex hYou can use @code{help} (abbreviated @code{h}) with no arguments todisplay a short list of named classes of commands:@smallexample(_GDBP__) helpList of classes of commands:running -- Running the programstack -- Examining the stackdata -- Examining databreakpoints -- Making program stop at certain pointsfiles -- Specifying and examining filesstatus -- Status inquiriessupport -- Support facilitiesuser-defined -- User-defined commandsaliases -- Aliases of other commandsobscure -- Obscure featuresType "help" followed by a class name for a list of commands in that class.Type "help" followed by command name for full documentation.Command name abbreviations are allowed if unambiguous.(_GDBP__)@end smallexample@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(_GDBP__) help statusStatus inquiries.List of commands:show -- Generic command for showing things set with "set"info -- Generic command for printing statusType "help" followed by command name for full documentation.Command name abbreviations are allowed if unambiguous.(_GDBP__)@end smallexample@item help @var{command}With a command name as @code{help} argument, _GDBN__ will display ashort paragraph on how to use that command.@end tableIn addition to @code{help}, you can use the _GDBN__ commands @code{info}and @code{show} to inquire about the state of your program, or the stateof _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@item info@kindex info@kindex iThis command (abbreviated @code{i}) is for describing the state of yourprogram; for example, it can list the arguments given to your program(@code{info args}), the registers currently in use (@code{inforegisters}), or the breakpoints you have set (@code{info breakpoints}).You can get a complete list of the @code{info} sub-commands with@w{@code{help info}}.@kindex show@item showIn contrast, @code{show} is for describing the state of _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 _GDBN__ is running. You should include thisinformation in _GDBN__ bug-reports. If multiple versions of _GDBN__ are inuse at your site, you may occasionally want to make sure what versionof _GDBN__ you are running; as _GDBN__ evolves, new commands are introduced,and old ones may wither away. The version number is also announcedwhen you start _GDBN__ with no arguments.@kindex show copying@item show copyingDisplay information about permission for copying _GDBN__.@kindex show warranty@item show warrantyDisplay the GNU ``NO WARRANTY'' statement.@end table@node Running@chapter Running Programs Under _GDBN__To debug a program, you must run it under _GDBN__.@menu* Compilation:: Compiling for Debugging* Starting:: Starting your Program_if__(!_BARE__)* 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* Process Information:: Additional Process Information_fi__(!_BARE__)@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.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._GCC__, the GNU C compiler, supports @samp{-g} with or without@samp{-O}, making it possible to debug optimized code. We recommendthat you @emph{always} use @samp{-g} whenever you compile a program.You may think your program is correct, but there is no sense in pushingyour 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 will show you what'sreally there. Don't be too surprised when the execution path doesn'texactly match your source file! An extreme example: if you define avariable, but never use it, _GDBN__ will never see 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 as a bug (including a test case!).Older versions of the GNU C compiler permitted a variant option@w{@samp{-gg}} for debugging information. _GDBN__ no longer supports thisformat; if your GNU C compiler has this option, do not use it.@ignore@comment As far as I know, there are no cases in which _GDBN__ will@comment produce strange output in this case. (but no promises).If your program includes archives made with the @code{ar} program, andif the object files used as input to @code{ar} were compiled without the@samp{-g} option and have names longer than 15 characters, _GDBN__ will getconfused reading your program's symbol table. No error message will begiven, but _GDBN__ may behave strangely. The reason for this problem is adeficiency in the Unix archive file format, which cannot represent filenames longer than 15 characters.To avoid this problem, compile the archive members with the @samp{-g}option or use shorter file names. Alternatively, use a version of GNU@code{ar} dated more recently than August 1989.@end ignore@node Starting@section Starting your Program@cindex starting@cindex running@table @code@item run@itemx r@kindex runUse the @code{run} command to start your program under _GDBN__. You mustfirst specify the program name_if__(_VXWORKS__)(except on VxWorks)_fi__(_VXWORKS__)with an argument to_GDBN__ (@pxref{Invocation, ,Getting In and Out of _GDBN__}), or by using the@code{file} or @code{exec-file} command (@pxref{Files, ,Commands toSpecify Files}).@end table_if__(!_BARE__)If 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. _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 will 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 usedwith the @code{SHELL} environment variable. @xref{Arguments, ,YourProgram's Arguments}.@item The @emph{environment.}Your program normally inherits its environment from _GDBN__, but you canuse the _GDBN__ commands @code{set environment} and @code{unsetenvironment} to change parts of the environment that will be given toyour program. @xref{Environment, ,Your Program's Environment}.@item The @emph{working directory.}Your program inherits its working directory from _GDBN__. You can set_GDBN__'s working directory with the @code{cd} command in _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 _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, _GDBN__ is likely to wind up debugging thewrong program.@end table_fi__(!_BARE__)When 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 calls functions in your program, using the @code{print}or @code{call} commands. @xref{Data, ,Examining Data}.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -