📄 gdb.texinfo
字号:
@item InteractionThe user interface to GDB's control variables has been simplifiedand consolidated in two commands, @code{set} and @code{show}. Outputlines are now broken at readable places, rather than overflowing ontothe next line. You can suppress output of machine-level addresses,displaying only source language information.@item C++GDB now supports C++ multiple inheritance (if used with a GCCversion 2 compiler), and also has limited support for C++ exceptionhandling, with the commands @code{catch} and @code{info catch}: GDBcan break when an exception is raised, before the stack is peeled backto the exception handler's context.@item Modula-2GDB now has preliminary support for the GNU Modula-2 compiler,currently under development at the State University of New York atBuffalo. Coordinated development of both GDB and the GNU Modula-2compiler will continue into 1992. Other Modula-2 compilers arecurrently not supported, and attempting to debug programs compiled withthem will likely result in an error as the symbol table of theexecutable is read in.@item Command RationalizationMany GDB commands have been renamed to make them easier to rememberand use. In particular, the subcommands of @code{info} and@code{show}/@code{set} are grouped to make the former refer to the stateof your program, and the latter refer to the state of GDB itself.@xref{Renamed Commands}, for details on what commands were renamed.@item Shared LibrariesGDB 4 can debug programs and core files that use SunOS, SVR4, or IBM RS/6000shared libraries.@item Reference CardGDB 4 has a reference card. @xref{Formatting Documentation,,Formattingthe Documentation}, for instructions to print it.@item Work in ProgressKernel debugging for BSD and Mach systems; Tahoe and HPPA architecturesupport.@end table_fi__(_GENERIC__ || !_H8__)_if__(!_BARE__)@node Sample Session@chapter A Sample _GDBN__ SessionYou can use this manual at your leisure to read all about _GDBN__.However, a handful of commands are enough to get started using thedebugger. This chapter illustrates these commands.@iftexIn this sample session, we emphasize user input like this: @b{input},to make it easier to pick out from the surrounding output.@end iftex@c FIXME: this example may not be appropriate for some configs, where@c FIXME...primary interest is in remote use._0__One of the preliminary versions of GNU @code{m4} (a generic macroprocessor) exhibits the following bug: sometimes, when we change itsquote strings from the default, the commands used to capture one macro'sdefinition in another stop working. In the following short @code{m4}session, we define a macro @code{foo} which expands to @code{0000}; wethen use the @code{m4} built-in @code{defn} to define @code{bar} as thesame thing. However, when we change the open quote string to@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the sameprocedure fails to define a new synonym @code{baz}:@smallexample$ @b{cd gnu/m4}$ @b{./m4}@b{define(foo,0000)}@b{foo}0000@b{define(bar,defn(`foo'))}@b{bar}0000@b{changequote(<QUOTE>,<UNQUOTE>)}@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}@b{baz}@b{C-d}m4: End of input: 0: fatal error: EOF in string@end smallexample@noindentLet's use _GDBN__ to try to see what's going on.@smallexample$ @b{_GDBP__ m4}@c FIXME: this falsifies the exact text played out, to permit smallbook@c FIXME... format to come out better.GDB is free software and you are welcome to distribute copies of it under certain conditions; type "show copying" to see the conditions.There is absolutely no warranty for GDB; type "show warranty" for details.GDB _GDB_VN__, Copyright 1992 Free Software Foundation, Inc...(_GDBP__)@end smallexample@noindent_GDBN__ reads only enough symbol data to know where to find the rest whenneeded; as a result, the first prompt comes up very quickly. We nowtell _GDBN__ to use a narrower display width than usual, so that exampleswill fit in this manual.@smallexample(_GDBP__) @b{set width 70}@end smallexample@noindentLet's see how the @code{m4} built-in @code{changequote} works.Having looked at the source, we know the relevant subroutine is@code{m4_changequote}, so we set a breakpoint there with _GDBN__'s@code{break} command.@smallexample(_GDBP__) @b{break m4_changequote}Breakpoint 1 at 0x62f4: file builtin.c, line 879.@end smallexample@noindentUsing the @code{run} command, we start @code{m4} running under _GDBN__control; as long as control does not reach the @code{m4_changequote}subroutine, the program runs as usual:@smallexample(_GDBP__) @b{run}Starting program: /work/Editorial/gdb/gnu/m4/m4@b{define(foo,0000)}@b{foo}0000@end smallexample@noindentTo trigger the breakpoint, we call @code{changequote}. _GDBN__suspends execution of @code{m4}, displaying information about thecontext where it stops.@smallexample@b{changequote(<QUOTE>,<UNQUOTE>)}Breakpoint 1, m4_changequote (argc=3, argv=0x33c70) at builtin.c:879879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))@end smallexample@noindentNow we use the command @code{n} (@code{next}) to advance execution tothe next line of the current function.@smallexample(_GDBP__) @b{n}882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\ : nil,@end smallexample@noindent@code{set_quotes} looks like a promising subroutine. We can go into itby using the command @code{s} (@code{step}) instead of @code{next}.@code{step} goes to the next line to be executed in @emph{any}subroutine, so it steps into @code{set_quotes}.@smallexample(_GDBP__) @b{s}set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") at input.c:530530 if (lquote != def_lquote)@end smallexample@noindentThe display that shows the subroutine where @code{m4} is nowsuspended (and its arguments) is called a stack frame display. Itshows a summary of the stack. We can use the @code{backtrace}command (which can also be spelled @code{bt}), to see where we arein the stack as a whole: the @code{backtrace} command displays astack frame for each active subroutine.@smallexample(_GDBP__) @b{bt}#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>") at input.c:530#1 0x6344 in m4_changequote (argc=3, argv=0x33c70) at builtin.c:882#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30) at macro.c:71#4 0x79dc in expand_input () at macro.c:40#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195@end smallexample@noindentLet's step through a few more lines to see what happens. The first twotimes, we can use @samp{s}; the next two times we use @code{n} to avoidfalling into the @code{xstrdup} subroutine.@smallexample(_GDBP__) @b{s}0x3b5c 532 if (rquote != def_rquote)(_GDBP__) @b{s}0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \def_lquote : xstrdup(lq);(_GDBP__) @b{n}536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ : xstrdup(rq);(_GDBP__) @b{n}538 len_lquote = strlen(rquote);@end smallexample@noindentThe last line displayed looks a little odd; let's examine the variables@code{lquote} and @code{rquote} to see if they are in fact the new leftand right quotes we specified. We can use the command @code{p}(@code{print}) to see their values.@smallexample(_GDBP__) @b{p lquote}$1 = 0x35d40 "<QUOTE>"(_GDBP__) @b{p rquote}$2 = 0x35d50 "<UNQUOTE>"@end smallexample@noindent@code{lquote} and @code{rquote} are indeed the new left and right quotes.Let's look at some context; we can display ten lines of sourcesurrounding the current line, with the @code{l} (@code{list}) command.@smallexample(_GDBP__) @b{l}533 xfree(rquote);534535 lquote = (lq == nil || *lq == '\0') ? def_lquote\ : xstrdup (lq);536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ : xstrdup (rq);537538 len_lquote = strlen(rquote);539 len_rquote = strlen(lquote);540 @}541542 void@end smallexample@noindentLet's step past the two lines that set @code{len_lquote} and@code{len_rquote}, and then examine the values of those variables.@smallexample(_GDBP__) @b{n}539 len_rquote = strlen(lquote);(_GDBP__) @b{n}540 @}(_GDBP__) @b{p len_lquote}$3 = 9(_GDBP__) @b{p len_rquote}$4 = 7@end smallexample@noindentThat certainly looks wrong, assuming @code{len_lquote} and@code{len_rquote} are meant to be the lengths of @code{lquote} and@code{rquote} respectively. Let's try setting them to better values.We can use the @code{p} command for this, since it'll print the value ofany expression---and that expression can include subroutine calls andassignments.@smallexample(_GDBP__) @b{p len_lquote=strlen(lquote)}$5 = 7(_GDBP__) @b{p len_rquote=strlen(rquote)}$6 = 9@end smallexample@noindentLet's see if that fixes 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(_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'll let @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 _GDBN__; itindicates @code{m4} has finished executing. We can end our _GDBN__session with the _GDBN__ @code{quit} command.@smallexample(_GDBP__) @b{quit}_1__@end smallexample_fi__(!_BARE__)@node Invocation@chapter Getting In and Out of _GDBN__This chapter discusses how to start _GDBN__, and how to get out of it.(The essentials: type @samp{_GDBP__} to start GDB, and type @kbd{quit}or @kbd{C-d} to exit.)@menu* Invoking _GDBN__:: Starting _GDBN__* Leaving _GDBN__:: Leaving _GDBN___if__(!_BARE__)* Shell Commands:: Shell Commands_fi__(!_BARE__)@end menu@node Invoking _GDBN__@section Starting _GDBN___if__(_H8__) For details on starting up _GDBP__ as aremote debugger attached to a Hitachi H8/300 board, see @ref{HitachiH8/300 Remote,,_GDBN__ and the Hitachi H8/300}._fi__(_H8__)Start _GDBN__ by running the program @code{_GDBP__}. Once it's running,_GDBN__ reads commands from the terminal until you tell it to exit.You can also run @code{_GDBP__} with a variety of arguments and options,to specify more of your debugging environment at the outset._if__(_GENERIC__)The command-line options described here are designedto cover a variety of situations; in some environments, some of theseoptions may effectively be unavailable. _fi__(_GENERIC__)The most usual way to start _GDBN__ is with one argument,specifying an executable program:@example_GDBP__ @var{program}@end example_if__(!_BARE__)@noindent
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -