1) Added conditionals around node structure, giving clean nodes for either
[deliverable/binutils-gdb.git] / gdb / doc / gdb.data-m4
1 _dnl__ Copyright (c) 1988 1989 1990 1991 Free Software Foundation, Inc.
2 _dnl__ This file is part of the source for the GDB manual.
3 @c M4 FRAGMENT: $Id$
4 @node Data, Symbols, Source, Top
5 @chapter Examining Data
6
7 @cindex printing data
8 @cindex examining data
9 @kindex print
10 @kindex inspect
11 @c "inspect" isn't quite a synonym if you're using Epoch, which we don't
12 @c document because it's nonstandard... Under Epoch it displays in a
13 @c different window or something like that.
14 The usual way to examine data in your program is with the @code{print}
15 command (abbreviated @code{p}), or its synonym @code{inspect}. It
16 evaluates and prints the value of any valid expression of the language
17 the program is written in (for now, C or C++). You type
18
19 @example
20 print @var{exp}
21 @end example
22
23 @noindent
24 where @var{exp} is any valid expression (in the source language), and
25 the value of @var{exp} is printed in a format appropriate to its data
26 type.
27
28 A more low-level way of examining data is with the @code{x} command.
29 It examines data in memory at a specified address and prints it in a
30 specified format. @xref{Memory}.
31
32 @menu
33 * Expressions:: Expressions
34 * Variables:: Program Variables
35 * Arrays:: Artificial Arrays
36 * Output formats:: Output formats
37 * Memory:: Examining Memory
38 * Auto Display:: Automatic Display
39 * Print Settings:: Print Settings
40 * Value History:: Value History
41 * Convenience Vars:: Convenience Variables
42 * Registers:: Registers
43 * Floating Point Hardware:: Floating Point Hardware
44 @end menu
45
46 @node Expressions, Variables, Data, Data
47 @section Expressions
48
49 @cindex expressions
50 @code{print} and many other _GDBN__ commands accept an expression and
51 compute its value. Any kind of constant, variable or operator defined
52 by the programming language you are using is legal in an expression in
53 _GDBN__. This includes conditional expressions, function calls, casts
54 and string constants. It unfortunately does not include symbols defined
55 by preprocessor @code{#define} commands, or C++ expressions involving
56 @samp{::}, the name resolution operator.
57 @c FIXME: actually C++ a::b works except in obscure circumstances where it
58 @c FIXME...can conflict with GDB's own name scope resolution.
59
60 Casts are supported in all languages, not just in C, because it is so
61 useful to cast a number into a pointer so as to examine a structure
62 at that address in memory.
63
64 _GDBN__ supports three kinds of operator in addition to those of programming
65 languages:
66
67 @table @code
68 @item @@
69 @samp{@@} is a binary operator for treating parts of memory as arrays.
70 @xref{Arrays}, for more information.
71
72 @item ::
73 @samp{::} allows you to specify a variable in terms of the file or
74 function where it is defined. @xref{Variables}.
75
76 @item @{@var{type}@} @var{addr}
77 Refers to an object of type @var{type} stored at address @var{addr} in
78 memory. @var{addr} may be any expression whose value is an integer or
79 pointer (but parentheses are required around binary operators, just as in
80 a cast). This construct is allowed regardless of what kind of data is
81 normally supposed to reside at @var{addr}.@refill
82 @end table
83
84 @node Variables, Arrays, Expressions, Data
85 @section Program Variables
86
87 The most common kind of expression to use is the name of a variable
88 in your program.
89
90 Variables in expressions are understood in the selected stack frame
91 (@pxref{Selection}); they must either be global (or static) or be visible
92 according to the scope rules of the programming language from the point of
93 execution in that frame. This means that in the function
94
95 @example
96 foo (a)
97 int a;
98 @{
99 bar (a);
100 @{
101 int b = test ();
102 bar (b);
103 @}
104 @}
105 @end example
106
107 @noindent
108 the variable @code{a} is usable whenever the program is executing
109 within the function @code{foo}, but the variable @code{b} is visible
110 only while the program is executing inside the block in which @code{b}
111 is declared.
112
113 @cindex variable name conflict
114 There is an exception: you can refer to a variable or function whose
115 scope is a single source file even if the current execution point is not
116 in this file. But it is possible to have more than one such variable or
117 function with the same name (in different source files). If that happens,
118 referring to that name has unpredictable effects. If you wish, you can
119 specify a variable in a particular file, using the colon-colon notation:
120
121 @cindex colon-colon
122 @kindex ::
123 @example
124 @var{file}::@var{variable}
125 @end example
126
127 @noindent
128 Here @var{file} is the name of the source file whose variable you want.
129
130 @cindex C++ name resolution
131 This use of @samp{::} is very rarely in conflict with the very similar
132 use of the same notation in C++. _GDBN__ also supports use of the C++
133 name resolution operator in _GDBN__ expressions.
134
135 @node Arrays, Output formats, Variables, Data
136 @section Artificial Arrays
137
138 @cindex artificial array
139 @kindex @@
140 It is often useful to print out several successive objects of the
141 same type in memory; a section of an array, or an array of
142 dynamically determined size for which only a pointer exists in the
143 program.
144
145 This can be done by constructing an @dfn{artificial array} with the
146 binary operator @samp{@@}. The left operand of @samp{@@} should be
147 the first element of the desired array, as an individual object.
148 The right operand should be the desired length of the array. The result is
149 an array value whose elements are all of the type of the left argument.
150 The first element is actually the left argument; the second element
151 comes from bytes of memory immediately following those that hold the
152 first element, and so on. Here is an example. If a program says
153
154 @example
155 int *array = (int *) malloc (len * sizeof (int));
156 @end example
157
158 @noindent
159 you can print the contents of @code{array} with
160
161 @example
162 p *array@@len
163 @end example
164
165 The left operand of @samp{@@} must reside in memory. Array values made
166 with @samp{@@} in this way behave just like other arrays in terms of
167 subscripting, and are coerced to pointers when used in expressions.
168 Artificial arrays most often appear in expressions via the value history
169 (@pxref{Value History}), after printing one out.)
170
171 @node Output formats, Memory, Arrays, Data
172 @section Output formats
173
174 @cindex formatted output
175 @cindex output formats
176 By default, _GDBN__ prints a value according to its data type. Sometimes
177 this is not what you want. For example, you might want to print a number
178 in hex, or a pointer in decimal. Or you might want to view data in memory
179 at a certain address as a character string or as an instruction. To do
180 these things, specify an @dfn{output format} when you print a value.
181
182 The simplest use of output formats is to say how to print a value
183 already computed. This is done by starting the arguments of the
184 @code{print} command with a slash and a format letter. The format
185 letters supported are:
186
187 @table @code
188 @item x
189 Regard the bits of the value as an integer, and print the integer in
190 hexadecimal.
191
192 @item d
193 Print as integer in signed decimal.
194
195 @item u
196 Print as integer in unsigned decimal.
197
198 @item o
199 Print as integer in octal.
200
201 @item t
202 Print as integer in binary. The letter @samp{t} stands for ``two''.
203
204 @item a
205 Print as an address, both absolute in hex and as an offset from the
206 nearest preceding symbol. This format can be used to discover where (in
207 what function) an unknown address is located:
208 @example
209 (_GDBP__) p/a 0x54320
210 _0__$3 = 0x54320 <_initialize_vx+396>_1__
211 @end example
212
213
214 @item c
215 Regard as an integer and print it as a character constant.
216
217 @item f
218 Regard the bits of the value as a floating point number and print
219 using typical floating point syntax.
220 @end table
221
222 For example, to print the program counter in hex (@pxref{Registers}), type
223
224 @example
225 p/x $pc
226 @end example
227
228 @noindent
229 Note that no space is required before the slash; this is because command
230 names in _GDBN__ cannot contain a slash.
231
232 To reprint the last value in the value history with a different format,
233 you can use the @code{print} command with just a format and no
234 expression. For example, @samp{p/x} reprints the last value in hex.
235
236 @node Memory, Auto Display, Output formats, Data
237 @section Examining Memory
238
239 @cindex examining memory
240 @table @code
241 @kindex x
242 @item x/@var{nfu} @var{expr}
243 The command @code{x} (for `examine') can be used to examine memory
244 without being constrained by your program's data types. You can specify
245 the unit size @var{u} of memory to inspect, and a repeat count @var{n} of how
246 many of those units to display. @code{x} understands the formats
247 @var{f} used by @code{print}; two additional formats, @samp{s} (string)
248 and @samp{i} (machine instruction) can be used without specifying a unit
249 size.
250 @end table
251
252 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
253 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
254 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
255 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
256 @pxref{Registers}) in hexadecimal (@samp{x}).
257
258 Since the letters indicating unit sizes are all distinct from the
259 letters specifying output formats, you don't have to remember whether
260 unit size or format comes first; either order will work. The output
261 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
262
263 After the format specification, you supply an expression for the address
264 where _GDBN__ is to begin reading from memory. The expression need not
265 have a pointer value (though it may); it is always interpreted as an
266 integer address of a byte of memory. @xref{Expressions} for more
267 information on expressions.
268
269 These are the memory units @var{u} you can specify with the @code{x}
270 command:
271
272 @table @code
273 @item b
274 Examine individual bytes.
275
276 @item h
277 Examine halfwords (two bytes each).
278
279 @item w
280 Examine words (four bytes each).
281
282 @cindex word
283 Many assemblers and cpu designers still use `word' for a 16-bit quantity,
284 as a holdover from specific predecessor machines of the 1970's that really
285 did use two-byte words. But more generally the term `word' has always
286 referred to the size of quantity that a machine normally operates on and
287 stores in its registers. This is 32 bits for all the machines that _GDBN__
288 runs on.
289
290 @item g
291 Examine giant words (8 bytes).
292 @end table
293
294 You can combine these unit specifications with any of the formats
295 described for @code{print}. @xref{Output formats}.
296
297 @code{x} has two additional output specifications which derive the unit
298 size from the data inspected:
299
300 @table @code
301 @item s
302 Print a null-terminated string of characters. Any explicitly specified
303 unit size is ignored; instead, the unit is however many bytes it takes
304 to reach a null character (including the null character).
305
306 @item i
307 Print a machine instruction in assembler syntax (or nearly). Any
308 specified unit size is ignored; the number of bytes in an instruction
309 varies depending on the type of machine, the opcode and the addressing
310 modes used. The command @code{disassemble} gives an alternative way of
311 inspecting machine instructions. @xref{Machine Code}.
312 @end table
313
314 If you omit either the format @var{f} or the unit size @var{u}, @code{x}
315 will use the same one that was used last. If you don't use any letters
316 or digits after the slash, you can omit the slash as well.
317
318 You can also omit the address to examine. Then the address used is just
319 after the last unit examined. This is why string and instruction
320 formats actually compute a unit-size based on the data: so that the next
321 string or instruction examined will start in the right place.
322
323 When the @code{print} command shows a value that resides in memory,
324 @code{print} also sets the default address for the @code{x} command.
325 @code{info line} also sets the default for @code{x}, to the address of
326 the start of the machine code for the specified line (@pxref{Machine
327 Code}), and @code{info breakpoints} sets it to the address of the last
328 breakpoint listed (@pxref{Set Breaks}).
329
330 When you use @key{RET} to repeat an @code{x} command, the address
331 specified previously (if any) is ignored, so that the repeated command
332 examines the successive locations in memory rather than the same ones.
333
334 You can examine several consecutive units of memory with one command by
335 writing a repeat-count after the slash (before the format letters, if
336 any). Omitting the repeat count @var{n} displays one unit of the
337 appropriate size. The repeat count must be a decimal integer. It has
338 the same effect as repeating the @code{x} command @var{n} times except
339 that the output may be more compact, with several units per line. For
340 example,
341
342 @example
343 x/10i $pc
344 @end example
345
346 @noindent
347 prints ten instructions starting with the one to be executed next in the
348 selected frame. After doing this, you could print a further seven
349 instructions with
350
351 @example
352 x/7
353 @end example
354
355 @noindent
356 ---where the format and address are allowed to default.
357
358 @kindex $_
359 @kindex $__
360 The addresses and contents printed by the @code{x} command are not put
361 in the value history because there is often too much of them and they
362 would get in the way. Instead, _GDBN__ makes these values available for
363 subsequent use in expressions as values of the convenience variables
364 @code{$_} and @code{$__}. After an @code{x} command, the last address
365 examined is available for use in expressions in the convenience variable
366 @code{$_}. The contents of that address, as examined, are available in
367 the convenience variable @code{$__}.
368
369 If the @code{x} command has a repeat count, the address and contents saved
370 are from the last memory unit printed; this is not the same as the last
371 address printed if several units were printed on the last line of output.
372
373 @node Auto Display, Print Settings, Memory, Data
374 @section Automatic Display
375 @cindex automatic display
376 @cindex display of expressions
377
378 If you find that you want to print the value of an expression frequently
379 (to see how it changes), you might want to add it to the @dfn{automatic
380 display list} so that _GDBN__ will print its value each time the program stops.
381 Each expression added to the list is given a number to identify it;
382 to remove an expression from the list, you specify that number.
383 The automatic display looks like this:
384
385 @example
386 2: foo = 38
387 3: bar[5] = (struct hack *) 0x3804
388 @end example
389
390 @noindent
391 showing item numbers, expressions and their current values. As with
392 displays you request manually using @code{x} or @code{print}, you can
393 specify the output format you prefer; in fact, @code{display} decides
394 whether to use @code{print} or @code{x} depending on how elaborate your
395 format specification is---it uses @code{x} if you specify a unit size,
396 or one of the two formats (@samp{i} and @samp{s}) that are only
397 supported by @code{x}; otherwise it uses @code{print}.
398
399 @table @code
400 @item display @var{exp}
401 @kindex display
402 Add the expression @var{exp} to the list of expressions to display
403 each time the program stops. @xref{Expressions}.
404
405 @code{display} will not repeat if you press @key{RET} again after using it.
406
407 @item display/@var{fmt} @var{exp}
408 For @var{fmt} specifying only a display format and not a size or
409 count, add the expression @var{exp} to the auto-display list but
410 arranges to display it each time in the specified format @var{fmt}.
411 @xref{Output formats}.
412
413 @item display/@var{fmt} @var{addr}
414 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
415 number of units, add the expression @var{addr} as a memory address to
416 be examined each time the program stops. Examining means in effect
417 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory}.
418 @end table
419
420 For example, @samp{display/i $pc} can be helpful, to see the machine
421 instruction about to be executed each time execution stops (@samp{$pc}
422 is a common name for the program counter; @pxref{Registers}).
423
424 @table @code
425 @item undisplay @var{dnums}@dots{}
426 @itemx delete display @var{dnums}@dots{}
427 @kindex delete display
428 @kindex undisplay
429 Remove item numbers @var{dnums} from the list of expressions to display.
430
431 @code{undisplay} will not repeat if you press @key{RET} after using it.
432 (Otherwise you would just get the error @samp{No display number @dots{}}.)
433
434 @item disable display @var{dnums}@dots{}
435 @kindex disable display
436 Disable the display of item numbers @var{dnums}. A disabled display
437 item is not printed automatically, but is not forgotten. It may be
438 enabled again later.
439
440 @item enable display @var{dnums}@dots{}
441 @kindex enable display
442 Enable display of item numbers @var{dnums}. It becomes effective once
443 again in auto display of its expression, until you specify otherwise.
444
445 @item display
446 Display the current values of the expressions on the list, just as is
447 done when the program stops.
448
449 @item info display
450 @kindex info display
451 Print the list of expressions previously set up to display
452 automatically, each one with its item number, but without showing the
453 values. This includes disabled expressions, which are marked as such.
454 It also includes expressions which would not be displayed right now
455 because they refer to automatic variables not currently available.
456 @end table
457
458 If a display expression refers to local variables, then it does not make
459 sense outside the lexical context for which it was set up. Such an
460 expression is disabled when execution enters a context where one of its
461 variables is not defined. For example, if you give the command
462 @code{display last_char} while inside a function with an argument
463 @code{last_char}, then this argument will be displayed while the program
464 continues to stop inside that function. When it stops elsewhere---where
465 there is no variable @code{last_char}---display is disabled. The next time
466 your program stops where @code{last_char} is meaningful, you can enable the
467 display expression once again.
468
469 @node Print Settings, Value History, Auto Display, Data
470 @section Print Settings
471
472 @cindex format options
473 @cindex print settings
474 _GDBN__ provides the following ways to control how arrays, structures,
475 and symbols are printed.
476
477 @noindent
478 These settings are useful for debugging programs in any language:
479
480 @table @code
481 @item set print address
482 @item set print address on
483 @kindex set print address
484 _GDBN__ will print memory addresses showing the location of stack
485 traces, structure values, pointer values, breakpoints, and so forth,
486 even when it also displays the contents of those addresses. The default
487 is on. For example, this is what a stack frame display looks like, with
488 @code{set print address on}:
489 @smallexample
490 (_GDBP__) f
491 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
492 at input.c:530
493 530 if (lquote != def_lquote)
494 @end smallexample
495
496 @item set print address off
497 Do not print addresses when displaying their contents. For example,
498 this is the same stack frame displayed with @code{set print address off}:
499 @example
500 (_GDBP__) set print addr off
501 (_GDBP__) f
502 #0 set_quotes (lq="<<", rq=">>") at input.c:530
503 530 if (lquote != def_lquote)
504 @end example
505
506 @item show print address
507 @kindex show print address
508 Show whether or not addresses are to be printed.
509
510 @item set print array
511 @itemx set print array on
512 @kindex set print array
513 _GDBN__ will pretty print arrays. This format is more convenient to read,
514 but uses more space. The default is off.
515
516 @item set print array off.
517 Return to compressed format for arrays.
518
519 @item show print array
520 @kindex show print array
521 Show whether compressed or pretty format is selected for displaying
522 arrays.
523
524 @item set print elements @var{number-of-elements}
525 @kindex set print elements
526 If _GDBN__ is printing a large array, it will stop printing after it has
527 printed the number of elements set by the @code{set print elements} command.
528 This limit also applies to the display of strings.
529
530 @item show print elements
531 @kindex show print elements
532 Display the number of elements of a large array that _GDBN__ will print
533 before losing patience.
534
535 @item set print pretty on
536 @kindex set print pretty
537 Cause _GDBN__ to print structures in an indented format with one member per
538 line, like this:
539
540 @example
541 $1 = @{
542 next = 0x0,
543 flags = @{
544 sweet = 1,
545 sour = 1
546 @},
547 meat = 0x54 "Pork"
548 @}
549 @end example
550
551 @item set print pretty off
552 Cause _GDBN__ to print structures in a compact format, like this:
553
554 @smallexample
555 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, meat \
556 = 0x54 "Pork"@}
557 @end smallexample
558
559 @noindent
560 This is the default format.
561
562 @item show print pretty
563 @kindex show print pretty
564 Show which format _GDBN__ will use to print structures.
565
566 @item set print sevenbit-strings on
567 Print using only seven-bit characters; if this option is set,
568 _GDBN__ will display any eight-bit characters (in strings or character
569 values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is
570 displayed as @code{\341}.
571
572 @item set print sevenbit-strings off
573 Print using either seven-bit or eight-bit characters, as required. This
574 is the default.
575
576 @item show print sevenbit-strings
577 Show whether or not _GDBN__ will print only seven-bit characters.
578
579 @item set print union on
580 @kindex set print union
581 Tell _GDBN__ to print unions which are contained in structures. This is the
582 default setting.
583
584 @item set print union off
585 Tell _GDBN__ not to print unions which are contained in structures.
586
587 @item show print union
588 @kindex show print union
589 Ask _GDBN__ whether or not it will print unions which are contained in
590 structures.
591
592 For example, given the declarations
593
594 @smallexample
595 typedef enum @{Tree, Bug@} Species;
596 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
597 typedef enum @{Caterpillar, Cocoon, Butterfly@} Bug_forms;
598
599 struct thing @{
600 Species it;
601 union @{
602 Tree_forms tree;
603 Bug_forms bug;
604 @} form;
605 @};
606
607 struct thing foo = @{Tree, @{Acorn@}@};
608 @end smallexample
609
610 @noindent
611 with @code{set print union on} in effect @samp{p foo} would print
612
613 @smallexample
614 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
615 @end smallexample
616
617 @noindent
618 and with @code{set print union off} in effect it would print
619
620 @smallexample
621 $1 = @{it = Tree, form = @{...@}@}
622 @end smallexample
623 @end table
624
625 @noindent
626 These settings are of interest when debugging C++ programs:
627
628 @table @code
629 @item set print demangle
630 @itemx set print demangle on
631 @kindex set print demangle
632 Print C++ names in their source form rather than in the mangled form
633 in which they are passed to the assembler and linker for type-safe linkage.
634 The default is on.
635
636 @item show print demangle
637 @kindex show print demangle
638 Show whether C++ names will be printed in mangled or demangled form.
639
640 @item set print asm-demangle
641 @itemx set print asm-demangle on
642 @kindex set print asm-demangle
643 Print C++ names in their source form rather than their mangled form, even
644 in assembler code printouts such as instruction disassemblies.
645 The default is off.
646
647 @item show print asm-demangle
648 @kindex show print asm-demangle
649 Show whether C++ names in assembly listings will be printed in mangled
650 or demangled form.
651
652 @item set print object
653 @itemx set print object on
654 @kindex set print object
655 When displaying a pointer to an object, identify the @emph{actual}
656 (derived) type of the object rather than the @emph{declared} type, using
657 the virtual function table.
658
659 @item set print object off
660 Display only the declared type of objects, without reference to the
661 virtual function table. This is the default setting.
662
663 @item show print object
664 @kindex show print object
665 Show whether actual, or declared, object types will be displayed.
666
667 @item set print vtbl
668 @itemx set print vtbl on
669 @kindex set print vtbl
670 Pretty print C++ virtual function tables. The default is off.
671
672 @item set print vtbl off
673 Do not pretty print C++ virtual function tables.
674
675 @item show print vtbl
676 @kindex show print vtbl
677 Show whether C++ virtual function tables are pretty printed, or not.
678
679 @end table
680
681 @node Value History, Convenience Vars, Print Settings, Data
682 @section Value History
683
684 @cindex value history
685 Values printed by the @code{print} command are saved in _GDBN__'s @dfn{value
686 history} so that you can refer to them in other expressions. Values are
687 kept until the symbol table is re-read or discarded (for example with
688 the @code{file} or @code{symbol-file} commands). When the symbol table
689 changes, the value history is discarded, since the values may contain
690 pointers back to the types defined in the symbol table.
691
692 @cindex @code{$}
693 @cindex @code{$$}
694 @cindex history number
695 The values printed are given @dfn{history numbers} for you to refer to them
696 by. These are successive integers starting with one. @code{print} shows you
697 the history number assigned to a value by printing @samp{$@var{num} = }
698 before the value; here @var{num} is the history number.
699
700 To refer to any previous value, use @samp{$} followed by the value's
701 history number. The way @code{print} labels its output is designed to
702 remind you of this. Just @code{$} refers to the most recent value in
703 the history, and @code{$$} refers to the value before that.
704 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
705 is the value just prior to @code{$$}, @code{$$1} is equivalent to
706 @code{$$}, and @code{$$0} is equivalent to @code{$}.
707
708 For example, suppose you have just printed a pointer to a structure and
709 want to see the contents of the structure. It suffices to type
710
711 @example
712 p *$
713 @end example
714
715 If you have a chain of structures where the component @code{next} points
716 to the next one, you can print the contents of the next one with this:
717
718 @example
719 p *$.next
720 @end example
721
722 @noindent
723 You can print successive links in the chain by repeating this
724 command---which you can do by just typing @key{RET}.
725
726 Note that the history records values, not expressions. If the value of
727 @code{x} is 4 and you type these commands:
728
729 @example
730 print x
731 set x=5
732 @end example
733
734 @noindent
735 then the value recorded in the value history by the @code{print} command
736 remains 4 even though the value of @code{x} has changed.
737
738 @table @code
739 @kindex show values
740 @item show values
741 Print the last ten values in the value history, with their item numbers.
742 This is like @samp{p@ $$9} repeated ten times, except that @code{show
743 values} does not change the history.
744
745 @item show values @var{n}
746 Print ten history values centered on history item number @var{n}.
747
748 @item show values +
749 Print ten history values just after the values last printed. If no more
750 values are available, produces no display.
751 @end table
752
753 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
754 same effect as @samp{show values +}.
755
756 @node Convenience Vars, Registers, Value History, Data
757 @section Convenience Variables
758
759 @cindex convenience variables
760 _GDBN__ provides @dfn{convenience variables} that you can use within
761 _GDBN__ to hold on to a value and refer to it later. These variables
762 exist entirely within _GDBN__; they are not part of your program, and
763 setting a convenience variable has no direct effect on further execution
764 of your program. That's why you can use them freely.
765
766 Convenience variables are prefixed with @samp{$}. Any name preceded by
767 @samp{$} can be used for a convenience variable, unless it is one of
768 the predefined machine-specific register names (@pxref{Registers}).
769 (Value history references, in contrast, are @emph{numbers} preceded
770 by @samp{$}. @xref{Value History}.)
771
772 You can save a value in a convenience variable with an assignment
773 expression, just as you would set a variable in your program. Example:
774
775 @example
776 set $foo = *object_ptr
777 @end example
778
779 @noindent
780 would save in @code{$foo} the value contained in the object pointed to by
781 @code{object_ptr}.
782
783 Using a convenience variable for the first time creates it; but its value
784 is @code{void} until you assign a new value. You can alter the value with
785 another assignment at any time.
786
787 Convenience variables have no fixed types. You can assign a convenience
788 variable any type of value, including structures and arrays, even if
789 that variable already has a value of a different type. The convenience
790 variable, when used as an expression, has the type of its current value.
791
792 @table @code
793 @item show convenience
794 @kindex show convenience
795 Print a list of convenience variables used so far, and their values.
796 Abbreviated @code{show con}.
797 @end table
798
799 One of the ways to use a convenience variable is as a counter to be
800 incremented or a pointer to be advanced. For example, to print
801 a field from successive elements of an array of structures:
802
803 _0__@example
804 set $i = 0
805 print bar[$i++]->contents
806 @i{@dots{} repeat that command by typing @key{RET}.}
807 _1__@end example
808
809 Some convenience variables are created automatically by _GDBN__ and given
810 values likely to be useful.
811
812 @table @code
813 @item $_
814 The variable @code{$_} is automatically set by the @code{x} command to
815 the last address examined (@pxref{Memory}). Other commands which
816 provide a default address for @code{x} to examine also set @code{$_}
817 to that address; these commands include @code{info line} and @code{info
818 breakpoint}.
819
820 @item $__
821 The variable @code{$__} is automatically set by the @code{x} command
822 to the value found in the last address examined.
823 @end table
824
825 @node Registers, Floating Point Hardware, Convenience Vars, Data
826 @section Registers
827
828 @cindex registers
829 Machine register contents can be referred to in expressions as variables
830 with names starting with @samp{$}. The names of registers are different
831 for each machine; use @code{info registers} to see the names used on
832 your machine.
833
834 @table @code
835 @item info registers
836 @kindex info registers
837 Print the names and values of all registers (in the selected stack frame).
838
839 @item info registers @var{regname}
840 Print the relativized value of register @var{regname}. @var{regname}
841 may be any register name valid on the machine you are using, with
842 or without the initial @samp{$}.
843 @end table
844
845 The register names @code{$pc} and @code{$sp} are used on most machines
846 for the program counter register and the stack pointer. For example,
847 you could print the program counter in hex with
848 @example
849 p/x $pc
850 @end example
851
852 @noindent
853 or print the instruction to be executed next with
854 @example
855 x/i $pc
856 @end example
857
858 @noindent
859 or add four to the stack pointer with
860 @example
861 set $sp += 4
862 @end example
863
864 @noindent
865 The last is a way of removing one word from the stack, on machines where
866 stacks grow downward in memory (most machines, nowadays). This assumes
867 that the innermost stack frame is selected; setting @code{$sp} is
868 not allowed when other stack frames are selected. (To pop entire frames
869 off the stack, regardless of machine architecture, use @code{return};
870 @pxref{Returning}.)
871
872 Often @code{$fp} is used for a register that contains a pointer to the
873 current stack frame, and @code{$ps} is sometimes used for a register
874 that contains the processor status. These standard register names may
875 be available on your machine even though the @code{info registers}
876 command shows other names. For example, on the SPARC, @code{info
877 registers} displays the processor status register as @code{$psr} but you
878 can also refer to it as @code{$ps}.
879
880 _GDBN__ always considers the contents of an ordinary register as an
881 integer when the register is examined in this way. Some machines have
882 special registers which can hold nothing but floating point; these
883 registers are considered to have floating point values. There is no way
884 to refer to the contents of an ordinary register as floating point value
885 (although you can @emph{print} it as a floating point value with
886 @samp{print/f $@var{regname}}).
887
888 Some registers have distinct ``raw'' and ``virtual'' data formats. This
889 means that the data format in which the register contents are saved by
890 the operating system is not the same one that your program normally
891 sees. For example, the registers of the 68881 floating point
892 coprocessor are always saved in ``extended'' (raw) format, but all C
893 programs expect to work with ``double'' (virtual) format. In such
894 cases, _GDBN__ normally works with the virtual format only (the format that
895 makes sense for your program), but the @code{info registers} command
896 prints the data in both formats.
897
898 Normally, register values are relative to the selected stack frame
899 (@pxref{Selection}). This means that you get the value that the
900 register would contain if all stack frames farther in were exited and
901 their saved registers restored. In order to see the true contents of
902 hardware registers, you must select the innermost frame (with
903 @samp{frame 0}).
904
905 However, _GDBN__ must deduce where registers are saved, from the machine
906 code generated by your compiler. If some registers are not saved, or if
907 _GDBN__ is unable to locate the saved registers, the selected stack
908 frame will make no difference.
909
910 @node Floating Point Hardware, , Registers, Data
911 @section Floating Point Hardware
912 @cindex floating point
913 Depending on the host machine architecture, _GDBN__ may be able to give
914 you more information about the status of the floating point hardware.
915
916 @table @code
917 @item info float
918 @kindex info float
919 If available, provides hardware-dependent information about the floating
920 point unit. The exact contents and layout vary depending on the
921 floating point chip.
922 @end table
923 @c FIXME: this is a cop-out. Try to get examples, explanations. Only
924 @c FIXME...supported currently on arm's and 386's. Mark properly with
925 @c FIXME... m4 macros to isolate general statements from hardware-dep,
926 @c FIXME... at that point.
This page took 0.050272 seconds and 4 git commands to generate.