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