571568304aa809a52a469ec143cbe20c42c707f9
[external/binutils.git] / gdb / doc / gdb.info-3
1 This is Info file ./gdb.info, produced by Makeinfo version 1.68 from
2 the input file gdb.texinfo.
3
4 START-INFO-DIR-ENTRY
5 * Gdb: (gdb).                     The GNU debugger.
6 END-INFO-DIR-ENTRY
7    This file documents the GNU debugger GDB.
8
9    This is the Seventh Edition, February 1999, of `Debugging with GDB:
10 the GNU Source-Level Debugger' for GDB Version 4.18.
11
12    Copyright (C) 1988-1999 Free Software Foundation, Inc.
13
14    Permission is granted to make and distribute verbatim copies of this
15 manual provided the copyright notice and this permission notice are
16 preserved on all copies.
17
18    Permission is granted to copy and distribute modified versions of
19 this manual under the conditions for verbatim copying, provided also
20 that the entire resulting derived work is distributed under the terms
21 of a permission notice identical to this one.
22
23    Permission is granted to copy and distribute translations of this
24 manual into another language, under the above conditions for modified
25 versions.
26
27 \1f
28 File: gdb.info,  Node: Break Commands,  Next: Breakpoint Menus,  Prev: Conditions,  Up: Breakpoints
29
30 Breakpoint command lists
31 ------------------------
32
33    You can give any breakpoint (or watchpoint or catchpoint) a series of
34 commands to execute when your program stops due to that breakpoint.  For
35 example, you might want to print the values of certain expressions, or
36 enable other breakpoints.
37
38 `commands [BNUM]'
39 `... COMMAND-LIST ...'
40 `end'
41      Specify a list of commands for breakpoint number BNUM.  The
42      commands themselves appear on the following lines.  Type a line
43      containing just `end' to terminate the commands.
44
45      To remove all commands from a breakpoint, type `commands' and
46      follow it immediately with `end'; that is, give no commands.
47
48      With no BNUM argument, `commands' refers to the last breakpoint,
49      watchpoint, or catchpoint set (not to the breakpoint most recently
50      encountered).
51
52    Pressing <RET> as a means of repeating the last GDB command is
53 disabled within a COMMAND-LIST.
54
55    You can use breakpoint commands to start your program up again.
56 Simply use the `continue' command, or `step', or any other command that
57 resumes execution.
58
59    Any other commands in the command list, after a command that resumes
60 execution, are ignored.  This is because any time you resume execution
61 (even with a simple `next' or `step'), you may encounter another
62 breakpoint--which could have its own command list, leading to
63 ambiguities about which list to execute.
64
65    If the first command you specify in a command list is `silent', the
66 usual message about stopping at a breakpoint is not printed.  This may
67 be desirable for breakpoints that are to print a specific message and
68 then continue.  If none of the remaining commands print anything, you
69 see no sign that the breakpoint was reached.  `silent' is meaningful
70 only at the beginning of a breakpoint command list.
71
72    The commands `echo', `output', and `printf' allow you to print
73 precisely controlled output, and are often useful in silent
74 breakpoints.  *Note Commands for controlled output: Output.
75
76    For example, here is how you could use breakpoint commands to print
77 the value of `x' at entry to `foo' whenever `x' is positive.
78
79      break foo if x>0
80      commands
81      silent
82      printf "x is %d\n",x
83      cont
84      end
85
86    One application for breakpoint commands is to compensate for one bug
87 so you can test for another.  Put a breakpoint just after the erroneous
88 line of code, give it a condition to detect the case in which something
89 erroneous has been done, and give it commands to assign correct values
90 to any variables that need them.  End with the `continue' command so
91 that your program does not stop, and start with the `silent' command so
92 that no output is produced.  Here is an example:
93
94      break 403
95      commands
96      silent
97      set x = y + 4
98      cont
99      end
100
101 \1f
102 File: gdb.info,  Node: Breakpoint Menus,  Prev: Break Commands,  Up: Breakpoints
103
104 Breakpoint menus
105 ----------------
106
107    Some programming languages (notably C++) permit a single function
108 name to be defined several times, for application in different contexts.
109 This is called "overloading".  When a function name is overloaded,
110 `break FUNCTION' is not enough to tell GDB where you want a breakpoint.
111 If you realize this is a problem, you can use something like `break
112 FUNCTION(TYPES)' to specify which particular version of the function
113 you want.  Otherwise, GDB offers you a menu of numbered choices for
114 different possible breakpoints, and waits for your selection with the
115 prompt `>'.  The first two options are always `[0] cancel' and `[1]
116 all'.  Typing `1' sets a breakpoint at each definition of FUNCTION, and
117 typing `0' aborts the `break' command without setting any new
118 breakpoints.
119
120    For example, the following session excerpt shows an attempt to set a
121 breakpoint at the overloaded symbol `String::after'.  We choose three
122 particular definitions of that function name:
123
124      (gdb) b String::after
125      [0] cancel
126      [1] all
127      [2] file:String.cc; line number:867
128      [3] file:String.cc; line number:860
129      [4] file:String.cc; line number:875
130      [5] file:String.cc; line number:853
131      [6] file:String.cc; line number:846
132      [7] file:String.cc; line number:735
133      > 2 4 6
134      Breakpoint 1 at 0xb26c: file String.cc, line 867.
135      Breakpoint 2 at 0xb344: file String.cc, line 875.
136      Breakpoint 3 at 0xafcc: file String.cc, line 846.
137      Multiple breakpoints were set.
138      Use the "delete" command to delete unwanted
139       breakpoints.
140      (gdb)
141
142 \1f
143 File: gdb.info,  Node: Continuing and Stepping,  Next: Signals,  Prev: Breakpoints,  Up: Stopping
144
145 Continuing and stepping
146 =======================
147
148    "Continuing" means resuming program execution until your program
149 completes normally.  In contrast, "stepping" means executing just one
150 more "step" of your program, where "step" may mean either one line of
151 source code, or one machine instruction (depending on what particular
152 command you use).  Either when continuing or when stepping, your
153 program may stop even sooner, due to a breakpoint or a signal.  (If due
154 to a signal, you may want to use `handle', or use `signal 0' to resume
155 execution.  *Note Signals: Signals.)
156
157 `continue [IGNORE-COUNT]'
158 `c [IGNORE-COUNT]'
159 `fg [IGNORE-COUNT]'
160      Resume program execution, at the address where your program last
161      stopped; any breakpoints set at that address are bypassed.  The
162      optional argument IGNORE-COUNT allows you to specify a further
163      number of times to ignore a breakpoint at this location; its
164      effect is like that of `ignore' (*note Break conditions:
165      Conditions.).
166
167      The argument IGNORE-COUNT is meaningful only when your program
168      stopped due to a breakpoint.  At other times, the argument to
169      `continue' is ignored.
170
171      The synonyms `c' and `fg' are provided purely for convenience, and
172      have exactly the same behavior as `continue'.
173
174    To resume execution at a different place, you can use `return'
175 (*note Returning from a function: Returning.) to go back to the calling
176 function; or `jump' (*note Continuing at a different address: Jumping.)
177 to go to an arbitrary location in your program.
178
179    A typical technique for using stepping is to set a breakpoint (*note
180 Breakpoints; watchpoints; and catchpoints: Breakpoints.) at the
181 beginning of the function or the section of your program where a problem
182 is believed to lie, run your program until it stops at that breakpoint,
183 and then step through the suspect area, examining the variables that are
184 interesting, until you see the problem happen.
185
186 `step'
187      Continue running your program until control reaches a different
188      source line, then stop it and return control to GDB.  This command
189      is abbreviated `s'.
190
191           *Warning:* If you use the `step' command while control is
192           within a function that was compiled without debugging
193           information, execution proceeds until control reaches a
194           function that does have debugging information.  Likewise, it
195           will not step into a function which is compiled without
196           debugging information.  To step through functions without
197           debugging information, use the `stepi' command, described
198           below.
199
200      The `step' command now only stops at the first instruction of a
201      source line.  This prevents the multiple stops that used to occur
202      in switch statements, for loops, etc.  `step' continues to stop if
203      a function that has debugging information is called within the
204      line.
205
206      Also, the `step' command now only enters a subroutine if there is
207      line number information for the subroutine.  Otherwise it acts
208      like the `next' command.  This avoids problems when using `cc -gl'
209      on MIPS machines.  Previously, `step' entered subroutines if there
210      was any debugging information about the routine.
211
212 `step COUNT'
213      Continue running as in `step', but do so COUNT times.  If a
214      breakpoint is reached, or a signal not related to stepping occurs
215      before COUNT steps, stepping stops right away.
216
217 `next [COUNT]'
218      Continue to the next source line in the current (innermost) stack
219      frame.  This is similar to `step', but function calls that appear
220      within the line of code are executed without stopping.  Execution
221      stops when control reaches a different line of code at the
222      original stack level that was executing when you gave the `next'
223      command.  This command is abbreviated `n'.
224
225      An argument COUNT is a repeat count, as for `step'.
226
227      The `next' command now only stops at the first instruction of a
228      source line.  This prevents the multiple stops that used to occur
229      in switch statements, for loops, etc.
230
231 `finish'
232      Continue running until just after function in the selected stack
233      frame returns.  Print the returned value (if any).
234
235      Contrast this with the `return' command (*note Returning from a
236      function: Returning.).
237
238 `until'
239 `u'
240      Continue running until a source line past the current line, in the
241      current stack frame, is reached.  This command is used to avoid
242      single stepping through a loop more than once.  It is like the
243      `next' command, except that when `until' encounters a jump, it
244      automatically continues execution until the program counter is
245      greater than the address of the jump.
246
247      This means that when you reach the end of a loop after single
248      stepping though it, `until' makes your program continue execution
249      until it exits the loop.  In contrast, a `next' command at the end
250      of a loop simply steps back to the beginning of the loop, which
251      forces you to step through the next iteration.
252
253      `until' always stops your program if it attempts to exit the
254      current stack frame.
255
256      `until' may produce somewhat counterintuitive results if the order
257      of machine code does not match the order of the source lines.  For
258      example, in the following excerpt from a debugging session, the `f'
259      (`frame') command shows that execution is stopped at line `206';
260      yet when we use `until', we get to line `195':
261
262           (gdb) f
263           #0  main (argc=4, argv=0xf7fffae8) at m4.c:206
264           206                 expand_input();
265           (gdb) until
266           195             for ( ; argc > 0; NEXTARG) {
267
268      This happened because, for execution efficiency, the compiler had
269      generated code for the loop closure test at the end, rather than
270      the start, of the loop--even though the test in a C `for'-loop is
271      written before the body of the loop.  The `until' command appeared
272      to step back to the beginning of the loop when it advanced to this
273      expression; however, it has not really gone to an earlier
274      statement--not in terms of the actual machine code.
275
276      `until' with no argument works by means of single instruction
277      stepping, and hence is slower than `until' with an argument.
278
279 `until LOCATION'
280 `u LOCATION'
281      Continue running your program until either the specified location
282      is reached, or the current stack frame returns.  LOCATION is any of
283      the forms of argument acceptable to `break' (*note Setting
284      breakpoints: Set Breaks.).  This form of the command uses
285      breakpoints, and hence is quicker than `until' without an argument.
286
287 `stepi'
288 `si'
289      Execute one machine instruction, then stop and return to the
290      debugger.
291
292      It is often useful to do `display/i $pc' when stepping by machine
293      instructions.  This makes GDB automatically display the next
294      instruction to be executed, each time your program stops.  *Note
295      Automatic display: Auto Display.
296
297      An argument is a repeat count, as in `step'.
298
299 `nexti'
300 `ni'
301      Execute one machine instruction, but if it is a function call,
302      proceed until the function returns.
303
304      An argument is a repeat count, as in `next'.
305
306 \1f
307 File: gdb.info,  Node: Signals,  Next: Thread Stops,  Prev: Continuing and Stepping,  Up: Stopping
308
309 Signals
310 =======
311
312    A signal is an asynchronous event that can happen in a program.  The
313 operating system defines the possible kinds of signals, and gives each
314 kind a name and a number.  For example, in Unix `SIGINT' is the signal
315 a program gets when you type an interrupt (often `C-c'); `SIGSEGV' is
316 the signal a program gets from referencing a place in memory far away
317 from all the areas in use; `SIGALRM' occurs when the alarm clock timer
318 goes off (which happens only if your program has requested an alarm).
319
320    Some signals, including `SIGALRM', are a normal part of the
321 functioning of your program.  Others, such as `SIGSEGV', indicate
322 errors; these signals are "fatal" (kill your program immediately) if the
323 program has not specified in advance some other way to handle the
324 signal.  `SIGINT' does not indicate an error in your program, but it is
325 normally fatal so it can carry out the purpose of the interrupt: to
326 kill the program.
327
328    GDB has the ability to detect any occurrence of a signal in your
329 program.  You can tell GDB in advance what to do for each kind of
330 signal.
331
332    Normally, GDB is set up to ignore non-erroneous signals like
333 `SIGALRM' (so as not to interfere with their role in the functioning of
334 your program) but to stop your program immediately whenever an error
335 signal happens.  You can change these settings with the `handle'
336 command.
337
338 `info signals'
339      Print a table of all the kinds of signals and how GDB has been
340      told to handle each one.  You can use this to see the signal
341      numbers of all the defined types of signals.
342
343      `info handle' is the new alias for `info signals'.
344
345 `handle SIGNAL KEYWORDS...'
346      Change the way GDB handles signal SIGNAL.  SIGNAL can be the
347      number of a signal or its name (with or without the `SIG' at the
348      beginning).  The KEYWORDS say what change to make.
349
350    The keywords allowed by the `handle' command can be abbreviated.
351 Their full names are:
352
353 `nostop'
354      GDB should not stop your program when this signal happens.  It may
355      still print a message telling you that the signal has come in.
356
357 `stop'
358      GDB should stop your program when this signal happens.  This
359      implies the `print' keyword as well.
360
361 `print'
362      GDB should print a message when this signal happens.
363
364 `noprint'
365      GDB should not mention the occurrence of the signal at all.  This
366      implies the `nostop' keyword as well.
367
368 `pass'
369      GDB should allow your program to see this signal; your program can
370      handle the signal, or else it may terminate if the signal is fatal
371      and not handled.
372
373 `nopass'
374      GDB should not allow your program to see this signal.
375
376    When a signal stops your program, the signal is not visible until you
377 continue.  Your program sees the signal then, if `pass' is in effect
378 for the signal in question *at that time*.  In other words, after GDB
379 reports a signal, you can use the `handle' command with `pass' or
380 `nopass' to control whether your program sees that signal when you
381 continue.
382
383    You can also use the `signal' command to prevent your program from
384 seeing a signal, or cause it to see a signal it normally would not see,
385 or to give it any signal at any time.  For example, if your program
386 stopped due to some sort of memory reference error, you might store
387 correct values into the erroneous variables and continue, hoping to see
388 more execution; but your program would probably terminate immediately as
389 a result of the fatal signal once it saw the signal.  To prevent this,
390 you can continue with `signal 0'.  *Note Giving your program a signal:
391 Signaling.
392
393 \1f
394 File: gdb.info,  Node: Thread Stops,  Prev: Signals,  Up: Stopping
395
396 Stopping and starting multi-thread programs
397 ===========================================
398
399    When your program has multiple threads (*note Debugging programs
400 with multiple threads: Threads.), you can choose whether to set
401 breakpoints on all threads, or on a particular thread.
402
403 `break LINESPEC thread THREADNO'
404 `break LINESPEC thread THREADNO if ...'
405      LINESPEC specifies source lines; there are several ways of writing
406      them, but the effect is always to specify some source line.
407
408      Use the qualifier `thread THREADNO' with a breakpoint command to
409      specify that you only want GDB to stop the program when a
410      particular thread reaches this breakpoint.  THREADNO is one of the
411      numeric thread identifiers assigned by GDB, shown in the first
412      column of the `info threads' display.
413
414      If you do not specify `thread THREADNO' when you set a breakpoint,
415      the breakpoint applies to *all* threads of your program.
416
417      You can use the `thread' qualifier on conditional breakpoints as
418      well; in this case, place `thread THREADNO' before the breakpoint
419      condition, like this:
420
421           (gdb) break frik.c:13 thread 28 if bartab > lim
422
423    Whenever your program stops under GDB for any reason, *all* threads
424 of execution stop, not just the current thread.  This allows you to
425 examine the overall state of the program, including switching between
426 threads, without worrying that things may change underfoot.
427
428    Conversely, whenever you restart the program, *all* threads start
429 executing.  *This is true even when single-stepping* with commands like
430 `step' or `next'.
431
432    In particular, GDB cannot single-step all threads in lockstep.
433 Since thread scheduling is up to your debugging target's operating
434 system (not controlled by GDB), other threads may execute more than one
435 statement while the current thread completes a single step.  Moreover,
436 in general other threads stop in the middle of a statement, rather than
437 at a clean statement boundary, when the program stops.
438
439    You might even find your program stopped in another thread after
440 continuing or even single-stepping.  This happens whenever some other
441 thread runs into a breakpoint, a signal, or an exception before the
442 first thread completes whatever you requested.
443
444    On some OSes, you can lock the OS scheduler and thus allow only a
445 single thread to run.
446
447 `set scheduler-locking MODE'
448      Set the scheduler locking mode.  If it is `off', then there is no
449      locking and any thread may run at any time.  If `on', then only the
450      current thread may run when the inferior is resumed.  The `step'
451      mode optimizes for single-stepping.  It stops other threads from
452      "seizing the prompt" by preempting the current thread while you are
453      stepping.  Other threads will only rarely (or never) get a chance
454      to run when you step.  They are more likely to run when you "next"
455      over a function call, and they are completely free to run when you
456      use commands like "continue", "until", or "finish".  However,
457      unless another thread hits a breakpoint during its timeslice, they
458      will never steal the GDB prompt away from the thread that you are
459      debugging.
460
461 `show scheduler-locking'
462      Display the current scheduler locking mode.
463
464 \1f
465 File: gdb.info,  Node: Stack,  Next: Source,  Prev: Stopping,  Up: Top
466
467 Examining the Stack
468 *******************
469
470    When your program has stopped, the first thing you need to know is
471 where it stopped and how it got there.
472
473    Each time your program performs a function call, information about
474 the call is generated.  That information includes the location of the
475 call in your program, the arguments of the call, and the local
476 variables of the function being called.  The information is saved in a
477 block of data called a "stack frame".  The stack frames are allocated
478 in a region of memory called the "call stack".
479
480    When your program stops, the GDB commands for examining the stack
481 allow you to see all of this information.
482
483    One of the stack frames is "selected" by GDB and many GDB commands
484 refer implicitly to the selected frame.  In particular, whenever you
485 ask GDB for the value of a variable in your program, the value is found
486 in the selected frame.  There are special GDB commands to select
487 whichever frame you are interested in. *Note Selecting a frame:
488 Selection.
489
490    When your program stops, GDB automatically selects the currently
491 executing frame and describes it briefly, similar to the `frame'
492 command (*note Information about a frame: Frame Info.).
493
494 * Menu:
495
496 * Frames::                      Stack frames
497 * Backtrace::                   Backtraces
498 * Selection::                   Selecting a frame
499 * Frame Info::                  Information on a frame
500 * Alpha/MIPS Stack::            Alpha and MIPS machines and the function stack
501
502 \1f
503 File: gdb.info,  Node: Frames,  Next: Backtrace,  Prev: Stack,  Up: Stack
504
505 Stack frames
506 ============
507
508    The call stack is divided up into contiguous pieces called "stack
509 frames", or "frames" for short; each frame is the data associated with
510 one call to one function.  The frame contains the arguments given to
511 the function, the function's local variables, and the address at which
512 the function is executing.
513
514    When your program is started, the stack has only one frame, that of
515 the function `main'.  This is called the "initial" frame or the
516 "outermost" frame.  Each time a function is called, a new frame is
517 made.  Each time a function returns, the frame for that function
518 invocation is eliminated.  If a function is recursive, there can be
519 many frames for the same function.  The frame for the function in which
520 execution is actually occurring is called the "innermost" frame.  This
521 is the most recently created of all the stack frames that still exist.
522
523    Inside your program, stack frames are identified by their addresses.
524 A stack frame consists of many bytes, each of which has its own
525 address; each kind of computer has a convention for choosing one byte
526 whose address serves as the address of the frame.  Usually this address
527 is kept in a register called the "frame pointer register" while
528 execution is going on in that frame.
529
530    GDB assigns numbers to all existing stack frames, starting with zero
531 for the innermost frame, one for the frame that called it, and so on
532 upward.  These numbers do not really exist in your program; they are
533 assigned by GDB to give you a way of designating stack frames in GDB
534 commands.
535
536    Some compilers provide a way to compile functions so that they
537 operate without stack frames.  (For example, the `gcc' option
538 `-fomit-frame-pointer' generates functions without a frame.)  This is
539 occasionally done with heavily used library functions to save the frame
540 setup time.  GDB has limited facilities for dealing with these function
541 invocations.  If the innermost function invocation has no stack frame,
542 GDB nevertheless regards it as though it had a separate frame, which is
543 numbered zero as usual, allowing correct tracing of the function call
544 chain.  However, GDB has no provision for frameless functions elsewhere
545 in the stack.
546
547 `frame ARGS'
548      The `frame' command allows you to move from one stack frame to
549      another, and to print the stack frame you select.  ARGS may be
550      either the address of the frame or the stack frame number.
551      Without an argument, `frame' prints the current stack frame.
552
553 `select-frame'
554      The `select-frame' command allows you to move from one stack frame
555      to another without printing the frame.  This is the silent version
556      of `frame'.
557
558 \1f
559 File: gdb.info,  Node: Backtrace,  Next: Selection,  Prev: Frames,  Up: Stack
560
561 Backtraces
562 ==========
563
564    A backtrace is a summary of how your program got where it is.  It
565 shows one line per frame, for many frames, starting with the currently
566 executing frame (frame zero), followed by its caller (frame one), and
567 on up the stack.
568
569 `backtrace'
570 `bt'
571      Print a backtrace of the entire stack: one line per frame for all
572      frames in the stack.
573
574      You can stop the backtrace at any time by typing the system
575      interrupt character, normally `C-c'.
576
577 `backtrace N'
578 `bt N'
579      Similar, but print only the innermost N frames.
580
581 `backtrace -N'
582 `bt -N'
583      Similar, but print only the outermost N frames.
584
585    The names `where' and `info stack' (abbreviated `info s') are
586 additional aliases for `backtrace'.
587
588    Each line in the backtrace shows the frame number and the function
589 name.  The program counter value is also shown--unless you use `set
590 print address off'.  The backtrace also shows the source file name and
591 line number, as well as the arguments to the function.  The program
592 counter value is omitted if it is at the beginning of the code for that
593 line number.
594
595    Here is an example of a backtrace.  It was made with the command `bt
596 3', so it shows the innermost three frames.
597
598      #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
599          at builtin.c:993
600      #1  0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
601      #2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
602          at macro.c:71
603      (More stack frames follow...)
604
605 The display for frame zero does not begin with a program counter value,
606 indicating that your program has stopped at the beginning of the code
607 for line `993' of `builtin.c'.
608
609 \1f
610 File: gdb.info,  Node: Selection,  Next: Frame Info,  Prev: Backtrace,  Up: Stack
611
612 Selecting a frame
613 =================
614
615    Most commands for examining the stack and other data in your program
616 work on whichever stack frame is selected at the moment.  Here are the
617 commands for selecting a stack frame; all of them finish by printing a
618 brief description of the stack frame just selected.
619
620 `frame N'
621 `f N'
622      Select frame number N.  Recall that frame zero is the innermost
623      (currently executing) frame, frame one is the frame that called the
624      innermost one, and so on.  The highest-numbered frame is the one
625      for `main'.
626
627 `frame ADDR'
628 `f ADDR'
629      Select the frame at address ADDR.  This is useful mainly if the
630      chaining of stack frames has been damaged by a bug, making it
631      impossible for GDB to assign numbers properly to all frames.  In
632      addition, this can be useful when your program has multiple stacks
633      and switches between them.
634
635      On the SPARC architecture, `frame' needs two addresses to select
636      an arbitrary frame: a frame pointer and a stack pointer.
637
638      On the MIPS and Alpha architecture, it needs two addresses: a stack
639      pointer and a program counter.
640
641      On the 29k architecture, it needs three addresses: a register stack
642      pointer, a program counter, and a memory stack pointer.
643
644 `up N'
645      Move N frames up the stack.  For positive numbers N, this advances
646      toward the outermost frame, to higher frame numbers, to frames
647      that have existed longer.  N defaults to one.
648
649 `down N'
650      Move N frames down the stack.  For positive numbers N, this
651      advances toward the innermost frame, to lower frame numbers, to
652      frames that were created more recently.  N defaults to one.  You
653      may abbreviate `down' as `do'.
654
655    All of these commands end by printing two lines of output describing
656 the frame.  The first line shows the frame number, the function name,
657 the arguments, and the source file and line number of execution in that
658 frame.  The second line shows the text of that source line.
659
660    For example:
661
662      (gdb) up
663      #1  0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
664          at env.c:10
665      10              read_input_file (argv[i]);
666
667    After such a printout, the `list' command with no arguments prints
668 ten lines centered on the point of execution in the frame.  *Note
669 Printing source lines: List.
670
671 `up-silently N'
672 `down-silently N'
673      These two commands are variants of `up' and `down', respectively;
674      they differ in that they do their work silently, without causing
675      display of the new frame.  They are intended primarily for use in
676      GDB command scripts, where the output might be unnecessary and
677      distracting.
678
679 \1f
680 File: gdb.info,  Node: Frame Info,  Next: Alpha/MIPS Stack,  Prev: Selection,  Up: Stack
681
682 Information about a frame
683 =========================
684
685    There are several other commands to print information about the
686 selected stack frame.
687
688 `frame'
689 `f'
690      When used without any argument, this command does not change which
691      frame is selected, but prints a brief description of the currently
692      selected stack frame.  It can be abbreviated `f'.  With an
693      argument, this command is used to select a stack frame.  *Note
694      Selecting a frame: Selection.
695
696 `info frame'
697 `info f'
698      This command prints a verbose description of the selected stack
699      frame, including:
700
701         * the address of the frame
702
703         * the address of the next frame down (called by this frame)
704
705         * the address of the next frame up (caller of this frame)
706
707         * the language in which the source code corresponding to this
708           frame is written
709
710         * the address of the frame's arguments
711
712         * the program counter saved in it (the address of execution in
713           the caller frame)
714
715         * which registers were saved in the frame
716
717      The verbose description is useful when something has gone wrong
718      that has made the stack format fail to fit the usual conventions.
719
720 `info frame ADDR'
721 `info f ADDR'
722      Print a verbose description of the frame at address ADDR, without
723      selecting that frame.  The selected frame remains unchanged by this
724      command.  This requires the same kind of address (more than one
725      for some architectures) that you specify in the `frame' command.
726      *Note Selecting a frame: Selection.
727
728 `info args'
729      Print the arguments of the selected frame, each on a separate line.
730
731 `info locals'
732      Print the local variables of the selected frame, each on a separate
733      line.  These are all variables (declared either static or
734      automatic) accessible at the point of execution of the selected
735      frame.
736
737 `info catch'
738      Print a list of all the exception handlers that are active in the
739      current stack frame at the current point of execution.  To see
740      other exception handlers, visit the associated frame (using the
741      `up', `down', or `frame' commands); then type `info catch'.  *Note
742      Setting catchpoints: Set Catchpoints.
743
744 \1f
745 File: gdb.info,  Node: Alpha/MIPS Stack,  Prev: Frame Info,  Up: Stack
746
747 MIPS/Alpha machines and the function stack
748 ==========================================
749
750    Alpha- and MIPS-based computers use an unusual stack frame, which
751 sometimes requires GDB to search backward in the object code to find
752 the beginning of a function.
753
754    To improve response time (especially for embedded applications, where
755 GDB may be restricted to a slow serial line for this search) you may
756 want to limit the size of this search, using one of these commands:
757
758 `set heuristic-fence-post LIMIT'
759      Restrict GDB to examining at most LIMIT bytes in its search for
760      the beginning of a function.  A value of 0 (the default) means
761      there is no limit.  However, except for 0, the larger the limit
762      the more bytes `heuristic-fence-post' must search and therefore
763      the longer it takes to run.
764
765 `show heuristic-fence-post'
766      Display the current limit.
767
768 These commands are available *only* when GDB is configured for
769 debugging programs on Alpha or MIPS processors.
770
771 \1f
772 File: gdb.info,  Node: Source,  Next: Data,  Prev: Stack,  Up: Top
773
774 Examining Source Files
775 **********************
776
777    GDB can print parts of your program's source, since the debugging
778 information recorded in the program tells GDB what source files were
779 used to build it.  When your program stops, GDB spontaneously prints
780 the line where it stopped.  Likewise, when you select a stack frame
781 (*note Selecting a frame: Selection.), GDB prints the line where
782 execution in that frame has stopped.  You can print other portions of
783 source files by explicit command.
784
785    If you use GDB through its GNU Emacs interface, you may prefer to use
786 Emacs facilities to view source; *note Using GDB under GNU Emacs:
787 Emacs..
788
789 * Menu:
790
791 * List::                        Printing source lines
792
793 * Search::                      Searching source files
794
795 * Source Path::                 Specifying source directories
796 * Machine Code::                Source and machine code
797
798 \1f
799 File: gdb.info,  Node: List,  Next: Search,  Prev: Source,  Up: Source
800
801 Printing source lines
802 =====================
803
804    To print lines from a source file, use the `list' command
805 (abbreviated `l').  By default, ten lines are printed.  There are
806 several ways to specify what part of the file you want to print.
807
808    Here are the forms of the `list' command most commonly used:
809
810 `list LINENUM'
811      Print lines centered around line number LINENUM in the current
812      source file.
813
814 `list FUNCTION'
815      Print lines centered around the beginning of function FUNCTION.
816
817 `list'
818      Print more lines.  If the last lines printed were printed with a
819      `list' command, this prints lines following the last lines
820      printed; however, if the last line printed was a solitary line
821      printed as part of displaying a stack frame (*note Examining the
822      Stack: Stack.), this prints lines centered around that line.
823
824 `list -'
825      Print lines just before the lines last printed.
826
827    By default, GDB prints ten source lines with any of these forms of
828 the `list' command.  You can change this using `set listsize':
829
830 `set listsize COUNT'
831      Make the `list' command display COUNT source lines (unless the
832      `list' argument explicitly specifies some other number).
833
834 `show listsize'
835      Display the number of lines that `list' prints.
836
837    Repeating a `list' command with <RET> discards the argument, so it
838 is equivalent to typing just `list'.  This is more useful than listing
839 the same lines again.  An exception is made for an argument of `-';
840 that argument is preserved in repetition so that each repetition moves
841 up in the source file.
842
843    In general, the `list' command expects you to supply zero, one or two
844 "linespecs".  Linespecs specify source lines; there are several ways of
845 writing them but the effect is always to specify some source line.
846 Here is a complete description of the possible arguments for `list':
847
848 `list LINESPEC'
849      Print lines centered around the line specified by LINESPEC.
850
851 `list FIRST,LAST'
852      Print lines from FIRST to LAST.  Both arguments are linespecs.
853
854 `list ,LAST'
855      Print lines ending with LAST.
856
857 `list FIRST,'
858      Print lines starting with FIRST.
859
860 `list +'
861      Print lines just after the lines last printed.
862
863 `list -'
864      Print lines just before the lines last printed.
865
866 `list'
867      As described in the preceding table.
868
869    Here are the ways of specifying a single source line--all the kinds
870 of linespec.
871
872 `NUMBER'
873      Specifies line NUMBER of the current source file.  When a `list'
874      command has two linespecs, this refers to the same source file as
875      the first linespec.
876
877 `+OFFSET'
878      Specifies the line OFFSET lines after the last line printed.  When
879      used as the second linespec in a `list' command that has two, this
880      specifies the line OFFSET lines down from the first linespec.
881
882 `-OFFSET'
883      Specifies the line OFFSET lines before the last line printed.
884
885 `FILENAME:NUMBER'
886      Specifies line NUMBER in the source file FILENAME.
887
888 `FUNCTION'
889      Specifies the line that begins the body of the function FUNCTION.
890      For example: in C, this is the line with the open brace.
891
892 `FILENAME:FUNCTION'
893      Specifies the line of the open-brace that begins the body of the
894      function FUNCTION in the file FILENAME.  You only need the file
895      name with a function name to avoid ambiguity when there are
896      identically named functions in different source files.
897
898 `*ADDRESS'
899      Specifies the line containing the program address ADDRESS.
900      ADDRESS may be any expression.
901
902 \1f
903 File: gdb.info,  Node: Search,  Next: Source Path,  Prev: List,  Up: Source
904
905 Searching source files
906 ======================
907
908    There are two commands for searching through the current source file
909 for a regular expression.
910
911 `forward-search REGEXP'
912 `search REGEXP'
913      The command `forward-search REGEXP' checks each line, starting
914      with the one following the last line listed, for a match for
915      REGEXP.  It lists the line that is found.  You can use the synonym
916      `search REGEXP' or abbreviate the command name as `fo'.
917
918 `reverse-search REGEXP'
919      The command `reverse-search REGEXP' checks each line, starting
920      with the one before the last line listed and going backward, for a
921      match for REGEXP.  It lists the line that is found.  You can
922      abbreviate this command as `rev'.
923
924 \1f
925 File: gdb.info,  Node: Source Path,  Next: Machine Code,  Prev: Search,  Up: Source
926
927 Specifying source directories
928 =============================
929
930    Executable programs sometimes do not record the directories of the
931 source files from which they were compiled, just the names.  Even when
932 they do, the directories could be moved between the compilation and
933 your debugging session.  GDB has a list of directories to search for
934 source files; this is called the "source path".  Each time GDB wants a
935 source file, it tries all the directories in the list, in the order
936 they are present in the list, until it finds a file with the desired
937 name.  Note that the executable search path is *not* used for this
938 purpose.  Neither is the current working directory, unless it happens
939 to be in the source path.
940
941    If GDB cannot find a source file in the source path, and the object
942 program records a directory, GDB tries that directory too.  If the
943 source path is empty, and there is no record of the compilation
944 directory, GDB looks in the current directory as a last resort.
945
946    Whenever you reset or rearrange the source path, GDB clears out any
947 information it has cached about where source files are found and where
948 each line is in the file.
949
950    When you start GDB, its source path is empty.  To add other
951 directories, use the `directory' command.
952
953 `directory DIRNAME ...'
954
955 `dir DIRNAME ...'
956      Add directory DIRNAME to the front of the source path.  Several
957      directory names may be given to this command, separated by `:' or
958      whitespace.  You may specify a directory that is already in the
959      source path; this moves it forward, so GDB searches it sooner.
960
961      You can use the string `$cdir' to refer to the compilation
962      directory (if one is recorded), and `$cwd' to refer to the current
963      working directory.  `$cwd' is not the same as `.'--the former
964      tracks the current working directory as it changes during your GDB
965      session, while the latter is immediately expanded to the current
966      directory at the time you add an entry to the source path.
967
968 `directory'
969      Reset the source path to empty again.  This requires confirmation.
970
971 `show directories'
972      Print the source path: show which directories it contains.
973
974    If your source path is cluttered with directories that are no longer
975 of interest, GDB may sometimes cause confusion by finding the wrong
976 versions of source.  You can correct the situation as follows:
977
978   1. Use `directory' with no argument to reset the source path to empty.
979
980   2. Use `directory' with suitable arguments to reinstall the
981      directories you want in the source path.  You can add all the
982      directories in one command.
983
984 \1f
985 File: gdb.info,  Node: Machine Code,  Prev: Source Path,  Up: Source
986
987 Source and machine code
988 =======================
989
990    You can use the command `info line' to map source lines to program
991 addresses (and vice versa), and the command `disassemble' to display a
992 range of addresses as machine instructions.  When run under GNU Emacs
993 mode, the `info line' command now causes the arrow to point to the line
994 specified.  Also, `info line' prints addresses in symbolic form as well
995 as hex.
996
997 `info line LINESPEC'
998      Print the starting and ending addresses of the compiled code for
999      source line LINESPEC.  You can specify source lines in any of the
1000      ways understood by the `list' command (*note Printing source
1001      lines: List.).
1002
1003    For example, we can use `info line' to discover the location of the
1004 object code for the first line of function `m4_changequote':
1005
1006      (gdb) info line m4_changecom
1007      Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
1008
1009 We can also inquire (using `*ADDR' as the form for LINESPEC) what
1010 source line covers a particular address:
1011      (gdb) info line *0x63ff
1012      Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
1013
1014    After `info line', the default address for the `x' command is
1015 changed to the starting address of the line, so that `x/i' is
1016 sufficient to begin examining the machine code (*note Examining memory:
1017 Memory.).  Also, this address is saved as the value of the convenience
1018 variable `$_' (*note Convenience variables: Convenience Vars.).
1019
1020 `disassemble'
1021      This specialized command dumps a range of memory as machine
1022      instructions.  The default memory range is the function
1023      surrounding the program counter of the selected frame.  A single
1024      argument to this command is a program counter value; GDB dumps the
1025      function surrounding this value.  Two arguments specify a range of
1026      addresses (first inclusive, second exclusive) to dump.
1027
1028    The following example shows the disassembly of a range of addresses
1029 of HP PA-RISC 2.0 code:
1030
1031      (gdb) disas 0x32c4 0x32e4
1032      Dump of assembler code from 0x32c4 to 0x32e4:
1033      0x32c4 <main+204>:      addil 0,dp
1034      0x32c8 <main+208>:      ldw 0x22c(sr0,r1),r26
1035      0x32cc <main+212>:      ldil 0x3000,r31
1036      0x32d0 <main+216>:      ble 0x3f8(sr4,r31)
1037      0x32d4 <main+220>:      ldo 0(r31),rp
1038      0x32d8 <main+224>:      addil -0x800,dp
1039      0x32dc <main+228>:      ldo 0x588(r1),r26
1040      0x32e0 <main+232>:      ldil 0x3000,r31
1041      End of assembler dump.
1042
1043    Some architectures have more than one commonly-used set of
1044 instruction mnemonics or other syntax.
1045
1046 `set assembly-language INSTRUCTION-SET'
1047      Select the instruction set to use when disassembling the program
1048      via the `disassemble' or `x/i' commands.
1049
1050      Currently this command is only defined for the Intel x86 family.
1051      You can set INSTRUCTION-SET to either `i386' or `i8086'.  The
1052      default is `i386'.
1053
1054 \1f
1055 File: gdb.info,  Node: Data,  Next: Languages,  Prev: Source,  Up: Top
1056
1057 Examining Data
1058 **************
1059
1060    The usual way to examine data in your program is with the `print'
1061 command (abbreviated `p'), or its synonym `inspect'.  It evaluates and
1062 prints the value of an expression of the language your program is
1063 written in (*note Using GDB with Different Languages: Languages.).
1064
1065 `print EXP'
1066 `print /F EXP'
1067      EXP is an expression (in the source language).  By default the
1068      value of EXP is printed in a format appropriate to its data type;
1069      you can choose a different format by specifying `/F', where F is a
1070      letter specifying the format; *note Output formats: Output
1071      Formats..
1072
1073 `print'
1074 `print /F'
1075      If you omit EXP, GDB displays the last value again (from the
1076      "value history"; *note Value history: Value History.).  This
1077      allows you to conveniently inspect the same value in an
1078      alternative format.
1079
1080    A more low-level way of examining data is with the `x' command.  It
1081 examines data in memory at a specified address and prints it in a
1082 specified format.  *Note Examining memory: Memory.
1083
1084    If you are interested in information about types, or about how the
1085 fields of a struct or class are declared, use the `ptype EXP' command
1086 rather than `print'. *Note Examining the Symbol Table: Symbols.
1087
1088 * Menu:
1089
1090 * Expressions::                 Expressions
1091 * Variables::                   Program variables
1092 * Arrays::                      Artificial arrays
1093 * Output Formats::              Output formats
1094 * Memory::                      Examining memory
1095 * Auto Display::                Automatic display
1096 * Print Settings::              Print settings
1097 * Value History::               Value history
1098 * Convenience Vars::            Convenience variables
1099 * Registers::                   Registers
1100
1101 * Floating Point Hardware::     Floating point hardware
1102
1103 \1f
1104 File: gdb.info,  Node: Expressions,  Next: Variables,  Prev: Data,  Up: Data
1105
1106 Expressions
1107 ===========
1108
1109    `print' and many other GDB commands accept an expression and compute
1110 its value.  Any kind of constant, variable or operator defined by the
1111 programming language you are using is valid in an expression in GDB.
1112 This includes conditional expressions, function calls, casts and string
1113 constants.  It unfortunately does not include symbols defined by
1114 preprocessor `#define' commands.
1115
1116    GDB now supports array constants in expressions input by the user.
1117 The syntax is {ELEMENT, ELEMENT...}.  For example, you can now use the
1118 command `print {1, 2, 3}' to build up an array in memory that is
1119 malloc'd in the target program.
1120
1121    Because C is so widespread, most of the expressions shown in
1122 examples in this manual are in C.  *Note Using GDB with Different
1123 Languages: Languages, for information on how to use expressions in other
1124 languages.
1125
1126    In this section, we discuss operators that you can use in GDB
1127 expressions regardless of your programming language.
1128
1129    Casts are supported in all languages, not just in C, because it is so
1130 useful to cast a number into a pointer in order to examine a structure
1131 at that address in memory.
1132
1133    GDB supports these operators, in addition to those common to
1134 programming languages:
1135
1136 `@'
1137      `@' is a binary operator for treating parts of memory as arrays.
1138      *Note Artificial arrays: Arrays, for more information.
1139
1140 `::'
1141      `::' allows you to specify a variable in terms of the file or
1142      function where it is defined.  *Note Program variables: Variables.
1143
1144 `{TYPE} ADDR'
1145      Refers to an object of type TYPE stored at address ADDR in memory.
1146      ADDR may be any expression whose value is an integer or pointer
1147      (but parentheses are required around binary operators, just as in
1148      a cast).  This construct is allowed regardless of what kind of
1149      data is normally supposed to reside at ADDR.
1150
1151 \1f
1152 File: gdb.info,  Node: Variables,  Next: Arrays,  Prev: Expressions,  Up: Data
1153
1154 Program variables
1155 =================
1156
1157    The most common kind of expression to use is the name of a variable
1158 in your program.
1159
1160    Variables in expressions are understood in the selected stack frame
1161 (*note Selecting a frame: Selection.); they must be either:
1162
1163    * global (or file-static)
1164
1165 or
1166
1167    * visible according to the scope rules of the programming language
1168      from the point of execution in that frame
1169
1170 This means that in the function
1171
1172      foo (a)
1173           int a;
1174      {
1175        bar (a);
1176        {
1177          int b = test ();
1178          bar (b);
1179        }
1180      }
1181
1182 you can examine and use the variable `a' whenever your program is
1183 executing within the function `foo', but you can only use or examine
1184 the variable `b' while your program is executing inside the block where
1185 `b' is declared.
1186
1187    There is an exception: you can refer to a variable or function whose
1188 scope is a single source file even if the current execution point is not
1189 in this file.  But it is possible to have more than one such variable or
1190 function with the same name (in different source files).  If that
1191 happens, referring to that name has unpredictable effects.  If you wish,
1192 you can specify a static variable in a particular function or file,
1193 using the colon-colon notation:
1194
1195      FILE::VARIABLE
1196      FUNCTION::VARIABLE
1197
1198 Here FILE or FUNCTION is the name of the context for the static
1199 VARIABLE.  In the case of file names, you can use quotes to make sure
1200 GDB parses the file name as a single word--for example, to print a
1201 global value of `x' defined in `f2.c':
1202
1203      (gdb) p 'f2.c'::x
1204
1205    This use of `::' is very rarely in conflict with the very similar
1206 use of the same notation in C++.  GDB also supports use of the C++
1207 scope resolution operator in GDB expressions.
1208
1209      *Warning:* Occasionally, a local variable may appear to have the
1210      wrong value at certain points in a function--just after entry to a
1211      new scope, and just before exit.
1212    You may see this problem when you are stepping by machine
1213 instructions.  This is because, on most machines, it takes more than
1214 one instruction to set up a stack frame (including local variable
1215 definitions); if you are stepping by machine instructions, variables
1216 may appear to have the wrong values until the stack frame is completely
1217 built.  On exit, it usually also takes more than one machine
1218 instruction to destroy a stack frame; after you begin stepping through
1219 that group of instructions, local variable definitions may be gone.
1220
1221    This may also happen when the compiler does significant
1222 optimizations.  To be sure of always seeing accurate values, turn off
1223 all optimization when compiling.
1224