1 /* Print values for GNU debugger GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
25 #include "gdb_string.h"
31 #include "expression.h"
35 #include "breakpoint.h"
39 #include "symfile.h" /* for overlay functions */
40 #include "objfiles.h" /* ditto */
41 #include "completer.h" /* for completion functions */
43 #include "gdb_assert.h"
47 extern int asm_demangle
; /* Whether to demangle syms in asm printouts */
48 extern int addressprint
; /* Whether to print hex addresses in HLL " */
57 /* Last specified output format. */
59 static char last_format
= 'x';
61 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
63 static char last_size
= 'w';
65 /* Default address to examine next. */
67 static CORE_ADDR next_address
;
69 /* Default section to examine next. */
71 static asection
*next_section
;
73 /* Last address examined. */
75 static CORE_ADDR last_examine_address
;
77 /* Contents of last address examined.
78 This is not valid past the end of the `x' command! */
80 static struct value
*last_examine_value
;
82 /* Largest offset between a symbolic value and an address, that will be
83 printed as `0x1234 <symbol+offset>'. */
85 static unsigned int max_symbolic_offset
= UINT_MAX
;
87 /* Append the source filename and linenumber of the symbol when
88 printing a symbolic value as `<symbol at filename:linenum>' if set. */
89 static int print_symbol_filename
= 0;
91 /* Number of auto-display expression currently being displayed.
92 So that we can disable it if we get an error or a signal within it.
93 -1 when not doing one. */
95 int current_display_number
;
97 /* Flag to low-level print routines that this value is being printed
98 in an epoch window. We'd like to pass this as a parameter, but
99 every routine would need to take it. Perhaps we can encapsulate
100 this in the I/O stream once we have GNU stdio. */
106 /* Chain link to next auto-display item. */
107 struct display
*next
;
108 /* Expression to be evaluated and displayed. */
109 struct expression
*exp
;
110 /* Item number of this auto-display item. */
112 /* Display format specified. */
113 struct format_data format
;
114 /* Innermost block required by this expression when evaluated */
116 /* Status of this display (enabled or disabled) */
120 /* Chain of expressions whose values should be displayed
121 automatically each time the program stops. */
123 static struct display
*display_chain
;
125 static int display_number
;
127 /* Prototypes for exported functions. */
129 void output_command (char *, int);
131 void _initialize_printcmd (void);
133 /* Prototypes for local functions. */
135 static void delete_display (int);
137 static void enable_display (char *, int);
139 static void disable_display_command (char *, int);
141 static void printf_command (char *, int);
143 static void display_info (char *, int);
145 static void do_one_display (struct display
*);
147 static void undisplay_command (char *, int);
149 static void free_display (struct display
*);
151 static void display_command (char *, int);
153 void x_command (char *, int);
155 static void address_info (char *, int);
157 static void set_command (char *, int);
159 static void call_command (char *, int);
161 static void inspect_command (char *, int);
163 static void print_command (char *, int);
165 static void print_command_1 (char *, int, int);
167 static void validate_format (struct format_data
, char *);
169 static void do_examine (struct format_data
, CORE_ADDR addr
,
172 static void print_formatted (struct value
*, int, int, struct ui_file
*);
174 static struct format_data
decode_format (char **, int, int);
176 static void sym_info (char *, int);
179 /* Decode a format specification. *STRING_PTR should point to it.
180 OFORMAT and OSIZE are used as defaults for the format and size
181 if none are given in the format specification.
182 If OSIZE is zero, then the size field of the returned value
183 should be set only if a size is explicitly specified by the
185 The structure returned describes all the data
186 found in the specification. In addition, *STRING_PTR is advanced
187 past the specification and past all whitespace following it. */
189 static struct format_data
190 decode_format (char **string_ptr
, int oformat
, int osize
)
192 struct format_data val
;
193 register char *p
= *string_ptr
;
199 if (*p
>= '0' && *p
<= '9')
200 val
.count
= atoi (p
);
201 while (*p
>= '0' && *p
<= '9')
204 /* Now process size or format letters that follow. */
208 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
210 else if (*p
>= 'a' && *p
<= 'z')
216 while (*p
== ' ' || *p
== '\t')
220 /* Set defaults for format and size if not specified. */
221 if (val
.format
== '?')
225 /* Neither has been specified. */
226 val
.format
= oformat
;
230 /* If a size is specified, any format makes a reasonable
231 default except 'i'. */
232 val
.format
= oformat
== 'i' ? 'x' : oformat
;
234 else if (val
.size
== '?')
239 /* Pick the appropriate size for an address. */
240 if (TARGET_PTR_BIT
== 64)
241 val
.size
= osize
? 'g' : osize
;
242 else if (TARGET_PTR_BIT
== 32)
243 val
.size
= osize
? 'w' : osize
;
244 else if (TARGET_PTR_BIT
== 16)
245 val
.size
= osize
? 'h' : osize
;
247 /* Bad value for TARGET_PTR_BIT */
248 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
251 /* Floating point has to be word or giantword. */
252 if (osize
== 'w' || osize
== 'g')
255 /* Default it to giantword if the last used size is not
257 val
.size
= osize
? 'g' : osize
;
260 /* Characters default to one byte. */
261 val
.size
= osize
? 'b' : osize
;
264 /* The default is the size most recently specified. */
271 /* Print value VAL on stream according to FORMAT, a letter or 0.
272 Do not end with a newline.
273 0 means print VAL according to its own type.
274 SIZE is the letter for the size of datum being printed.
275 This is used to pad hex numbers so they line up. */
278 print_formatted (struct value
*val
, register int format
, int size
,
279 struct ui_file
*stream
)
281 struct type
*type
= check_typedef (VALUE_TYPE (val
));
282 int len
= TYPE_LENGTH (type
);
284 if (VALUE_LVAL (val
) == lval_memory
)
286 next_address
= VALUE_ADDRESS (val
) + len
;
287 next_section
= VALUE_BFD_SECTION (val
);
293 /* FIXME: Need to handle wchar_t's here... */
294 next_address
= VALUE_ADDRESS (val
)
295 + val_print_string (VALUE_ADDRESS (val
), -1, 1, stream
);
296 next_section
= VALUE_BFD_SECTION (val
);
300 /* The old comment says
301 "Force output out, print_insn not using _filtered".
302 I'm not completely sure what that means, I suspect most print_insn
303 now do use _filtered, so I guess it's obsolete.
304 --Yes, it does filter now, and so this is obsolete. -JB */
306 /* We often wrap here if there are long symbolic names. */
308 next_address
= VALUE_ADDRESS (val
)
309 + gdb_print_insn (VALUE_ADDRESS (val
), stream
);
310 next_section
= VALUE_BFD_SECTION (val
);
315 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
316 || TYPE_CODE (type
) == TYPE_CODE_STRING
317 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
318 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
319 /* If format is 0, use the 'natural' format for
320 * that type of value. If the type is non-scalar,
321 * we have to use language rules to print it as
322 * a series of scalars.
324 value_print (val
, stream
, format
, Val_pretty_default
);
326 /* User specified format, so don't look to the
327 * the type to tell us what to do.
329 print_scalar_formatted (VALUE_CONTENTS (val
), type
,
330 format
, size
, stream
);
334 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
335 according to letters FORMAT and SIZE on STREAM.
336 FORMAT may not be zero. Formats s and i are not supported at this level.
338 This is how the elements of an array or structure are printed
342 print_scalar_formatted (void *valaddr
, struct type
*type
, int format
, int size
,
343 struct ui_file
*stream
)
346 unsigned int len
= TYPE_LENGTH (type
);
348 if (len
> sizeof (LONGEST
)
356 if (!TYPE_UNSIGNED (type
)
357 || !extract_long_unsigned_integer (valaddr
, len
, &val_long
))
359 /* We can't print it normally, but we can print it in hex.
360 Printing it in the wrong radix is more useful than saying
361 "use /x, you dummy". */
362 /* FIXME: we could also do octal or binary if that was the
364 /* FIXME: we should be using the size field to give us a
365 minimum field width to print. */
368 print_octal_chars (stream
, valaddr
, len
);
369 else if (format
== 'd')
370 print_decimal_chars (stream
, valaddr
, len
);
371 else if (format
== 't')
372 print_binary_chars (stream
, valaddr
, len
);
374 /* replace with call to print_hex_chars? Looks
375 like val_print_type_code_int is redoing
378 val_print_type_code_int (type
, valaddr
, stream
);
383 /* If we get here, extract_long_unsigned_integer set val_long. */
385 else if (format
!= 'f')
386 val_long
= unpack_long (type
, valaddr
);
388 /* If the value is a pointer, and pointers and addresses are not the
389 same, then at this point, the value's length (in target bytes) is
390 TARGET_ADDR_BIT/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
391 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
392 len
= TARGET_ADDR_BIT
/ TARGET_CHAR_BIT
;
394 /* If we are printing it as unsigned, truncate it in case it is actually
395 a negative signed value (e.g. "print/u (short)-1" should print 65535
396 (if shorts are 16 bits) instead of 4294967295). */
399 if (len
< sizeof (LONGEST
))
400 val_long
&= ((LONGEST
) 1 << HOST_CHAR_BIT
* len
) - 1;
408 /* no size specified, like in print. Print varying # of digits. */
409 print_longest (stream
, 'x', 1, val_long
);
418 print_longest (stream
, size
, 1, val_long
);
421 error ("Undefined output size \"%c\".", size
);
426 print_longest (stream
, 'd', 1, val_long
);
430 print_longest (stream
, 'u', 0, val_long
);
435 print_longest (stream
, 'o', 1, val_long
);
437 fprintf_filtered (stream
, "0");
442 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
443 print_address (addr
, stream
);
448 value_print (value_from_longest (builtin_type_true_char
, val_long
),
449 stream
, 0, Val_pretty_default
);
453 if (len
== TYPE_LENGTH (builtin_type_float
))
454 type
= builtin_type_float
;
455 else if (len
== TYPE_LENGTH (builtin_type_double
))
456 type
= builtin_type_double
;
457 else if (len
== TYPE_LENGTH (builtin_type_long_double
))
458 type
= builtin_type_long_double
;
459 print_floating (valaddr
, type
, stream
);
463 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
466 /* Binary; 't' stands for "two". */
468 char bits
[8 * (sizeof val_long
) + 1];
469 char buf
[8 * (sizeof val_long
) + 32];
474 width
= 8 * (sizeof val_long
);
491 error ("Undefined output size \"%c\".", size
);
497 bits
[width
] = (val_long
& 1) ? '1' : '0';
502 while (*cp
&& *cp
== '0')
507 strcpy (buf
, local_binary_format_prefix ());
509 strcat (buf
, local_binary_format_suffix ());
510 fputs_filtered (buf
, stream
);
515 error ("Undefined output format \"%c\".", format
);
519 /* Specify default address for `x' command.
520 `info lines' uses this. */
523 set_next_address (CORE_ADDR addr
)
527 /* Make address available to the user as $_. */
528 set_internalvar (lookup_internalvar ("_"),
529 value_from_pointer (lookup_pointer_type (builtin_type_void
),
533 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
534 after LEADIN. Print nothing if no symbolic name is found nearby.
535 Optionally also print source file and line number, if available.
536 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
537 or to interpret it as a possible C++ name and convert it back to source
538 form. However note that DO_DEMANGLE can be overridden by the specific
539 settings of the demangle and asm_demangle variables. */
542 print_address_symbolic (CORE_ADDR addr
, struct ui_file
*stream
, int do_demangle
,
546 char *filename
= NULL
;
551 /* throw away both name and filename */
552 struct cleanup
*cleanup_chain
= make_cleanup (free_current_contents
, &name
);
553 make_cleanup (free_current_contents
, &filename
);
555 if (build_address_symbolic (addr
, do_demangle
, &name
, &offset
, &filename
, &line
, &unmapped
))
557 do_cleanups (cleanup_chain
);
561 fputs_filtered (leadin
, stream
);
563 fputs_filtered ("<*", stream
);
565 fputs_filtered ("<", stream
);
566 fputs_filtered (name
, stream
);
568 fprintf_filtered (stream
, "+%u", (unsigned int) offset
);
570 /* Append source filename and line number if desired. Give specific
571 line # of this addr, if we have it; else line # of the nearest symbol. */
572 if (print_symbol_filename
&& filename
!= NULL
)
575 fprintf_filtered (stream
, " at %s:%d", filename
, line
);
577 fprintf_filtered (stream
, " in %s", filename
);
580 fputs_filtered ("*>", stream
);
582 fputs_filtered (">", stream
);
584 do_cleanups (cleanup_chain
);
587 /* Given an address ADDR return all the elements needed to print the
588 address in a symbolic form. NAME can be mangled or not depending
589 on DO_DEMANGLE (and also on the asm_demangle global variable,
590 manipulated via ''set print asm-demangle''). Return 0 in case of
591 success, when all the info in the OUT paramters is valid. Return 1
594 build_address_symbolic (CORE_ADDR addr
, /* IN */
595 int do_demangle
, /* IN */
596 char **name
, /* OUT */
597 int *offset
, /* OUT */
598 char **filename
, /* OUT */
600 int *unmapped
) /* OUT */
602 struct minimal_symbol
*msymbol
;
603 struct symbol
*symbol
;
604 struct symtab
*symtab
= 0;
605 CORE_ADDR name_location
= 0;
606 asection
*section
= 0;
607 char *name_temp
= "";
609 /* Let's say it is unmapped. */
612 /* Determine if the address is in an overlay, and whether it is
614 if (overlay_debugging
)
616 section
= find_pc_overlay (addr
);
617 if (pc_in_unmapped_range (addr
, section
))
620 addr
= overlay_mapped_address (addr
, section
);
624 /* First try to find the address in the symbol table, then
625 in the minsyms. Take the closest one. */
627 /* This is defective in the sense that it only finds text symbols. So
628 really this is kind of pointless--we should make sure that the
629 minimal symbols have everything we need (by changing that we could
630 save some memory, but for many debug format--ELF/DWARF or
631 anything/stabs--it would be inconvenient to eliminate those minimal
633 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
634 symbol
= find_pc_sect_function (addr
, section
);
638 name_location
= BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
));
639 if (do_demangle
|| asm_demangle
)
640 name_temp
= SYMBOL_PRINT_NAME (symbol
);
642 name_temp
= DEPRECATED_SYMBOL_NAME (symbol
);
647 if (SYMBOL_VALUE_ADDRESS (msymbol
) > name_location
|| symbol
== NULL
)
649 /* The msymbol is closer to the address than the symbol;
650 use the msymbol instead. */
653 name_location
= SYMBOL_VALUE_ADDRESS (msymbol
);
654 if (do_demangle
|| asm_demangle
)
655 name_temp
= SYMBOL_PRINT_NAME (msymbol
);
657 name_temp
= DEPRECATED_SYMBOL_NAME (msymbol
);
660 if (symbol
== NULL
&& msymbol
== NULL
)
663 /* If the nearest symbol is too far away, don't print anything symbolic. */
665 /* For when CORE_ADDR is larger than unsigned int, we do math in
666 CORE_ADDR. But when we detect unsigned wraparound in the
667 CORE_ADDR math, we ignore this test and print the offset,
668 because addr+max_symbolic_offset has wrapped through the end
669 of the address space back to the beginning, giving bogus comparison. */
670 if (addr
> name_location
+ max_symbolic_offset
671 && name_location
+ max_symbolic_offset
> name_location
)
674 *offset
= addr
- name_location
;
676 *name
= xstrdup (name_temp
);
678 if (print_symbol_filename
)
680 struct symtab_and_line sal
;
682 sal
= find_pc_sect_line (addr
, section
, 0);
686 *filename
= xstrdup (sal
.symtab
->filename
);
689 else if (symtab
&& symbol
&& symbol
->line
)
691 *filename
= xstrdup (symtab
->filename
);
692 *line
= symbol
->line
;
696 *filename
= xstrdup (symtab
->filename
);
703 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
706 print_address_numeric (CORE_ADDR addr
, int use_local
, struct ui_file
*stream
)
708 /* Truncate address to the size of a target address, avoiding shifts
709 larger or equal than the width of a CORE_ADDR. The local
710 variable ADDR_BIT stops the compiler reporting a shift overflow
711 when it won't occur. */
712 /* NOTE: This assumes that the significant address information is
713 kept in the least significant bits of ADDR - the upper bits were
714 either zero or sign extended. Should ADDRESS_TO_POINTER() or
715 some ADDRESS_TO_PRINTABLE() be used to do the conversion? */
717 int addr_bit
= TARGET_ADDR_BIT
;
719 if (addr_bit
< (sizeof (CORE_ADDR
) * HOST_CHAR_BIT
))
720 addr
&= ((CORE_ADDR
) 1 << addr_bit
) - 1;
721 print_longest (stream
, 'x', use_local
, (ULONGEST
) addr
);
724 /* Print address ADDR symbolically on STREAM.
725 First print it as a number. Then perhaps print
726 <SYMBOL + OFFSET> after the number. */
729 print_address (CORE_ADDR addr
, struct ui_file
*stream
)
731 print_address_numeric (addr
, 1, stream
);
732 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
735 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
736 controls whether to print the symbolic name "raw" or demangled.
737 Global setting "addressprint" controls whether to print hex address
741 print_address_demangle (CORE_ADDR addr
, struct ui_file
*stream
, int do_demangle
)
745 fprintf_filtered (stream
, "0");
747 else if (addressprint
)
749 print_address_numeric (addr
, 1, stream
);
750 print_address_symbolic (addr
, stream
, do_demangle
, " ");
754 print_address_symbolic (addr
, stream
, do_demangle
, "");
759 /* These are the types that $__ will get after an examine command of one
762 static struct type
*examine_i_type
;
764 static struct type
*examine_b_type
;
765 static struct type
*examine_h_type
;
766 static struct type
*examine_w_type
;
767 static struct type
*examine_g_type
;
769 /* Examine data at address ADDR in format FMT.
770 Fetch it from memory and print on gdb_stdout. */
773 do_examine (struct format_data fmt
, CORE_ADDR addr
, asection
*sect
)
775 register char format
= 0;
777 register int count
= 1;
778 struct type
*val_type
= NULL
;
780 register int maxelts
;
788 /* String or instruction format implies fetch single bytes
789 regardless of the specified size. */
790 if (format
== 's' || format
== 'i')
794 val_type
= examine_i_type
;
795 else if (size
== 'b')
796 val_type
= examine_b_type
;
797 else if (size
== 'h')
798 val_type
= examine_h_type
;
799 else if (size
== 'w')
800 val_type
= examine_w_type
;
801 else if (size
== 'g')
802 val_type
= examine_g_type
;
809 if (format
== 's' || format
== 'i')
812 /* Print as many objects as specified in COUNT, at most maxelts per line,
813 with the address of the next one at the start of each line. */
818 print_address (next_address
, gdb_stdout
);
819 printf_filtered (":");
824 printf_filtered ("\t");
825 /* Note that print_formatted sets next_address for the next
827 last_examine_address
= next_address
;
829 if (last_examine_value
)
830 value_free (last_examine_value
);
832 /* The value to be displayed is not fetched greedily.
833 Instead, to avoid the posibility of a fetched value not
834 being used, its retreval is delayed until the print code
835 uses it. When examining an instruction stream, the
836 disassembler will perform its own memory fetch using just
837 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
838 the disassembler be modified so that LAST_EXAMINE_VALUE
839 is left with the byte sequence from the last complete
840 instruction fetched from memory? */
841 last_examine_value
= value_at_lazy (val_type
, next_address
, sect
);
843 if (last_examine_value
)
844 release_value (last_examine_value
);
846 print_formatted (last_examine_value
, format
, size
, gdb_stdout
);
848 printf_filtered ("\n");
849 gdb_flush (gdb_stdout
);
854 validate_format (struct format_data fmt
, char *cmdname
)
857 error ("Size letters are meaningless in \"%s\" command.", cmdname
);
859 error ("Item count other than 1 is meaningless in \"%s\" command.",
861 if (fmt
.format
== 'i' || fmt
.format
== 's')
862 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
863 fmt
.format
, cmdname
);
866 /* Evaluate string EXP as an expression in the current language and
867 print the resulting value. EXP may contain a format specifier as the
868 first argument ("/x myvar" for example, to print myvar in hex).
872 print_command_1 (char *exp
, int inspect
, int voidprint
)
874 struct expression
*expr
;
875 register struct cleanup
*old_chain
= 0;
876 register char format
= 0;
878 struct format_data fmt
;
881 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
882 inspect_it
= inspect
;
884 if (exp
&& *exp
== '/')
887 fmt
= decode_format (&exp
, last_format
, 0);
888 validate_format (fmt
, "print");
889 last_format
= format
= fmt
.format
;
901 expr
= parse_expression (exp
);
902 old_chain
= make_cleanup (free_current_contents
, &expr
);
904 val
= evaluate_expression (expr
);
907 val
= access_value_history (0);
909 if (voidprint
|| (val
&& VALUE_TYPE (val
) &&
910 TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_VOID
))
912 int histindex
= record_latest_value (val
);
915 annotate_value_history_begin (histindex
, VALUE_TYPE (val
));
917 annotate_value_begin (VALUE_TYPE (val
));
920 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp
, histindex
);
921 else if (histindex
>= 0)
922 printf_filtered ("$%d = ", histindex
);
925 annotate_value_history_value ();
927 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
928 printf_filtered ("\n");
931 annotate_value_history_end ();
933 annotate_value_end ();
936 printf_unfiltered ("\") )\030");
940 do_cleanups (old_chain
);
941 inspect_it
= 0; /* Reset print routines to normal */
946 print_command (char *exp
, int from_tty
)
948 print_command_1 (exp
, 0, 1);
951 /* Same as print, except in epoch, it gets its own window */
954 inspect_command (char *exp
, int from_tty
)
956 extern int epoch_interface
;
958 print_command_1 (exp
, epoch_interface
, 1);
961 /* Same as print, except it doesn't print void results. */
964 call_command (char *exp
, int from_tty
)
966 print_command_1 (exp
, 0, 0);
971 output_command (char *exp
, int from_tty
)
973 struct expression
*expr
;
974 register struct cleanup
*old_chain
;
975 register char format
= 0;
977 struct format_data fmt
;
979 if (exp
&& *exp
== '/')
982 fmt
= decode_format (&exp
, 0, 0);
983 validate_format (fmt
, "output");
987 expr
= parse_expression (exp
);
988 old_chain
= make_cleanup (free_current_contents
, &expr
);
990 val
= evaluate_expression (expr
);
992 annotate_value_begin (VALUE_TYPE (val
));
994 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
996 annotate_value_end ();
999 gdb_flush (gdb_stdout
);
1001 do_cleanups (old_chain
);
1006 set_command (char *exp
, int from_tty
)
1008 struct expression
*expr
= parse_expression (exp
);
1009 register struct cleanup
*old_chain
=
1010 make_cleanup (free_current_contents
, &expr
);
1011 evaluate_expression (expr
);
1012 do_cleanups (old_chain
);
1017 sym_info (char *arg
, int from_tty
)
1019 struct minimal_symbol
*msymbol
;
1020 struct objfile
*objfile
;
1021 struct obj_section
*osect
;
1023 CORE_ADDR addr
, sect_addr
;
1025 unsigned int offset
;
1028 error_no_arg ("address");
1030 addr
= parse_and_eval_address (arg
);
1031 ALL_OBJSECTIONS (objfile
, osect
)
1033 sect
= osect
->the_bfd_section
;
1034 sect_addr
= overlay_mapped_address (addr
, sect
);
1036 if (osect
->addr
<= sect_addr
&& sect_addr
< osect
->endaddr
&&
1037 (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr
, sect
)))
1040 offset
= sect_addr
- SYMBOL_VALUE_ADDRESS (msymbol
);
1042 printf_filtered ("%s + %u in ",
1043 SYMBOL_PRINT_NAME (msymbol
), offset
);
1045 printf_filtered ("%s in ",
1046 SYMBOL_PRINT_NAME (msymbol
));
1047 if (pc_in_unmapped_range (addr
, sect
))
1048 printf_filtered ("load address range of ");
1049 if (section_is_overlay (sect
))
1050 printf_filtered ("%s overlay ",
1051 section_is_mapped (sect
) ? "mapped" : "unmapped");
1052 printf_filtered ("section %s", sect
->name
);
1053 printf_filtered ("\n");
1057 printf_filtered ("No symbol matches %s.\n", arg
);
1062 address_info (char *exp
, int from_tty
)
1064 register struct symbol
*sym
;
1065 register struct minimal_symbol
*msymbol
;
1067 register long basereg
;
1069 CORE_ADDR load_addr
;
1070 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
1071 if exp is a field of `this'. */
1074 error ("Argument required.");
1076 sym
= lookup_symbol (exp
, get_selected_block (0), VAR_DOMAIN
,
1077 &is_a_field_of_this
, (struct symtab
**) NULL
);
1080 if (is_a_field_of_this
)
1082 printf_filtered ("Symbol \"");
1083 fprintf_symbol_filtered (gdb_stdout
, exp
,
1084 current_language
->la_language
, DMGL_ANSI
);
1085 printf_filtered ("\" is a field of the local class variable ");
1086 if (current_language
->la_language
== language_objc
)
1087 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1089 printf_filtered ("`this'\n");
1093 msymbol
= lookup_minimal_symbol (exp
, NULL
, NULL
);
1095 if (msymbol
!= NULL
)
1097 load_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
1099 printf_filtered ("Symbol \"");
1100 fprintf_symbol_filtered (gdb_stdout
, exp
,
1101 current_language
->la_language
, DMGL_ANSI
);
1102 printf_filtered ("\" is at ");
1103 print_address_numeric (load_addr
, 1, gdb_stdout
);
1104 printf_filtered (" in a file compiled without debugging");
1105 section
= SYMBOL_BFD_SECTION (msymbol
);
1106 if (section_is_overlay (section
))
1108 load_addr
= overlay_unmapped_address (load_addr
, section
);
1109 printf_filtered (",\n -- loaded at ");
1110 print_address_numeric (load_addr
, 1, gdb_stdout
);
1111 printf_filtered (" in overlay section %s", section
->name
);
1113 printf_filtered (".\n");
1116 error ("No symbol \"%s\" in current context.", exp
);
1120 printf_filtered ("Symbol \"");
1121 fprintf_symbol_filtered (gdb_stdout
, DEPRECATED_SYMBOL_NAME (sym
),
1122 current_language
->la_language
, DMGL_ANSI
);
1123 printf_filtered ("\" is ");
1124 val
= SYMBOL_VALUE (sym
);
1125 basereg
= SYMBOL_BASEREG (sym
);
1126 section
= SYMBOL_BFD_SECTION (sym
);
1128 switch (SYMBOL_CLASS (sym
))
1131 case LOC_CONST_BYTES
:
1132 printf_filtered ("constant");
1136 printf_filtered ("a label at address ");
1137 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1139 if (section_is_overlay (section
))
1141 load_addr
= overlay_unmapped_address (load_addr
, section
);
1142 printf_filtered (",\n -- loaded at ");
1143 print_address_numeric (load_addr
, 1, gdb_stdout
);
1144 printf_filtered (" in overlay section %s", section
->name
);
1149 case LOC_COMPUTED_ARG
:
1150 (SYMBOL_LOCATION_FUNCS (sym
)->describe_location
) (sym
, gdb_stdout
);
1154 printf_filtered ("a variable in register %s", REGISTER_NAME (val
));
1158 printf_filtered ("static storage at address ");
1159 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1161 if (section_is_overlay (section
))
1163 load_addr
= overlay_unmapped_address (load_addr
, section
);
1164 printf_filtered (",\n -- loaded at ");
1165 print_address_numeric (load_addr
, 1, gdb_stdout
);
1166 printf_filtered (" in overlay section %s", section
->name
);
1171 printf_filtered ("external global (indirect addressing), at address *(");
1172 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1174 printf_filtered (")");
1175 if (section_is_overlay (section
))
1177 load_addr
= overlay_unmapped_address (load_addr
, section
);
1178 printf_filtered (",\n -- loaded at ");
1179 print_address_numeric (load_addr
, 1, gdb_stdout
);
1180 printf_filtered (" in overlay section %s", section
->name
);
1185 printf_filtered ("an argument in register %s", REGISTER_NAME (val
));
1188 case LOC_REGPARM_ADDR
:
1189 printf_filtered ("address of an argument in register %s", REGISTER_NAME (val
));
1193 printf_filtered ("an argument at offset %ld", val
);
1197 printf_filtered ("an argument at frame offset %ld", val
);
1201 printf_filtered ("a local variable at frame offset %ld", val
);
1205 printf_filtered ("a reference argument at offset %ld", val
);
1209 printf_filtered ("a variable at offset %ld from register %s",
1210 val
, REGISTER_NAME (basereg
));
1213 case LOC_BASEREG_ARG
:
1214 printf_filtered ("an argument at offset %ld from register %s",
1215 val
, REGISTER_NAME (basereg
));
1219 printf_filtered ("a typedef");
1223 printf_filtered ("a function at address ");
1224 print_address_numeric (load_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)),
1226 if (section_is_overlay (section
))
1228 load_addr
= overlay_unmapped_address (load_addr
, section
);
1229 printf_filtered (",\n -- loaded at ");
1230 print_address_numeric (load_addr
, 1, gdb_stdout
);
1231 printf_filtered (" in overlay section %s", section
->name
);
1235 case LOC_UNRESOLVED
:
1237 struct minimal_symbol
*msym
;
1239 msym
= lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym
), NULL
, NULL
);
1241 printf_filtered ("unresolved");
1244 section
= SYMBOL_BFD_SECTION (msym
);
1245 printf_filtered ("static storage at address ");
1246 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (msym
),
1248 if (section_is_overlay (section
))
1250 load_addr
= overlay_unmapped_address (load_addr
, section
);
1251 printf_filtered (",\n -- loaded at ");
1252 print_address_numeric (load_addr
, 1, gdb_stdout
);
1253 printf_filtered (" in overlay section %s", section
->name
);
1259 case LOC_HP_THREAD_LOCAL_STATIC
:
1261 "a thread-local variable at offset %ld from the thread base register %s",
1262 val
, REGISTER_NAME (basereg
));
1265 case LOC_OPTIMIZED_OUT
:
1266 printf_filtered ("optimized out");
1270 printf_filtered ("of unknown (botched) type");
1273 printf_filtered (".\n");
1277 x_command (char *exp
, int from_tty
)
1279 struct expression
*expr
;
1280 struct format_data fmt
;
1281 struct cleanup
*old_chain
;
1284 fmt
.format
= last_format
;
1285 fmt
.size
= last_size
;
1288 if (exp
&& *exp
== '/')
1291 fmt
= decode_format (&exp
, last_format
, last_size
);
1294 /* If we have an expression, evaluate it and use it as the address. */
1296 if (exp
!= 0 && *exp
!= 0)
1298 expr
= parse_expression (exp
);
1299 /* Cause expression not to be there any more
1300 if this command is repeated with Newline.
1301 But don't clobber a user-defined command's definition. */
1304 old_chain
= make_cleanup (free_current_contents
, &expr
);
1305 val
= evaluate_expression (expr
);
1306 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_REF
)
1307 val
= value_ind (val
);
1308 /* In rvalue contexts, such as this, functions are coerced into
1309 pointers to functions. This makes "x/i main" work. */
1310 if (/* last_format == 'i' && */
1311 TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FUNC
1312 && VALUE_LVAL (val
) == lval_memory
)
1313 next_address
= VALUE_ADDRESS (val
);
1315 next_address
= value_as_address (val
);
1316 if (VALUE_BFD_SECTION (val
))
1317 next_section
= VALUE_BFD_SECTION (val
);
1318 do_cleanups (old_chain
);
1321 do_examine (fmt
, next_address
, next_section
);
1323 /* If the examine succeeds, we remember its size and format for next time. */
1324 last_size
= fmt
.size
;
1325 last_format
= fmt
.format
;
1327 /* Set a couple of internal variables if appropriate. */
1328 if (last_examine_value
)
1330 /* Make last address examined available to the user as $_. Use
1331 the correct pointer type. */
1332 struct type
*pointer_type
1333 = lookup_pointer_type (VALUE_TYPE (last_examine_value
));
1334 set_internalvar (lookup_internalvar ("_"),
1335 value_from_pointer (pointer_type
,
1336 last_examine_address
));
1338 /* Make contents of last address examined available to the user as $__. */
1339 /* If the last value has not been fetched from memory then don't
1340 fetch it now - instead mark it by voiding the $__ variable. */
1341 if (VALUE_LAZY (last_examine_value
))
1342 set_internalvar (lookup_internalvar ("__"),
1343 allocate_value (builtin_type_void
));
1345 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1350 /* Add an expression to the auto-display chain.
1351 Specify the expression. */
1354 display_command (char *exp
, int from_tty
)
1356 struct format_data fmt
;
1357 register struct expression
*expr
;
1358 register struct display
*new;
1362 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1364 if (tui_active
&& *exp
== '$')
1365 display_it
= (tui_set_layout (exp
) == TUI_FAILURE
);
1379 fmt
= decode_format (&exp
, 0, 0);
1380 if (fmt
.size
&& fmt
.format
== 0)
1382 if (fmt
.format
== 'i' || fmt
.format
== 's')
1392 innermost_block
= 0;
1393 expr
= parse_expression (exp
);
1395 new = (struct display
*) xmalloc (sizeof (struct display
));
1398 new->block
= innermost_block
;
1399 new->next
= display_chain
;
1400 new->number
= ++display_number
;
1403 display_chain
= new;
1405 if (from_tty
&& target_has_execution
)
1406 do_one_display (new);
1413 free_display (struct display
*d
)
1419 /* Clear out the display_chain.
1420 Done when new symtabs are loaded, since this invalidates
1421 the types stored in many expressions. */
1424 clear_displays (void)
1426 register struct display
*d
;
1428 while ((d
= display_chain
) != NULL
)
1431 display_chain
= d
->next
;
1436 /* Delete the auto-display number NUM. */
1439 delete_display (int num
)
1441 register struct display
*d1
, *d
;
1444 error ("No display number %d.", num
);
1446 if (display_chain
->number
== num
)
1449 display_chain
= d1
->next
;
1453 for (d
= display_chain
;; d
= d
->next
)
1456 error ("No display number %d.", num
);
1457 if (d
->next
->number
== num
)
1467 /* Delete some values from the auto-display chain.
1468 Specify the element numbers. */
1471 undisplay_command (char *args
, int from_tty
)
1473 register char *p
= args
;
1479 if (query ("Delete all auto-display expressions? "))
1488 while (*p1
>= '0' && *p1
<= '9')
1490 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1491 error ("Arguments must be display numbers.");
1495 delete_display (num
);
1498 while (*p
== ' ' || *p
== '\t')
1504 /* Display a single auto-display.
1505 Do nothing if the display cannot be printed in the current context,
1506 or if the display is disabled. */
1509 do_one_display (struct display
*d
)
1511 int within_current_scope
;
1513 if (d
->enabled_p
== 0)
1517 within_current_scope
= contained_in (get_selected_block (0), d
->block
);
1519 within_current_scope
= 1;
1520 if (!within_current_scope
)
1523 current_display_number
= d
->number
;
1525 annotate_display_begin ();
1526 printf_filtered ("%d", d
->number
);
1527 annotate_display_number_end ();
1528 printf_filtered (": ");
1534 annotate_display_format ();
1536 printf_filtered ("x/");
1537 if (d
->format
.count
!= 1)
1538 printf_filtered ("%d", d
->format
.count
);
1539 printf_filtered ("%c", d
->format
.format
);
1540 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1541 printf_filtered ("%c", d
->format
.size
);
1542 printf_filtered (" ");
1544 annotate_display_expression ();
1546 print_expression (d
->exp
, gdb_stdout
);
1547 annotate_display_expression_end ();
1549 if (d
->format
.count
!= 1)
1550 printf_filtered ("\n");
1552 printf_filtered (" ");
1554 val
= evaluate_expression (d
->exp
);
1555 addr
= value_as_address (val
);
1556 if (d
->format
.format
== 'i')
1557 addr
= ADDR_BITS_REMOVE (addr
);
1559 annotate_display_value ();
1561 do_examine (d
->format
, addr
, VALUE_BFD_SECTION (val
));
1565 annotate_display_format ();
1567 if (d
->format
.format
)
1568 printf_filtered ("/%c ", d
->format
.format
);
1570 annotate_display_expression ();
1572 print_expression (d
->exp
, gdb_stdout
);
1573 annotate_display_expression_end ();
1575 printf_filtered (" = ");
1577 annotate_display_expression ();
1579 print_formatted (evaluate_expression (d
->exp
),
1580 d
->format
.format
, d
->format
.size
, gdb_stdout
);
1581 printf_filtered ("\n");
1584 annotate_display_end ();
1586 gdb_flush (gdb_stdout
);
1587 current_display_number
= -1;
1590 /* Display all of the values on the auto-display chain which can be
1591 evaluated in the current scope. */
1596 register struct display
*d
;
1598 for (d
= display_chain
; d
; d
= d
->next
)
1602 /* Delete the auto-display which we were in the process of displaying.
1603 This is done when there is an error or a signal. */
1606 disable_display (int num
)
1608 register struct display
*d
;
1610 for (d
= display_chain
; d
; d
= d
->next
)
1611 if (d
->number
== num
)
1616 printf_unfiltered ("No display number %d.\n", num
);
1620 disable_current_display (void)
1622 if (current_display_number
>= 0)
1624 disable_display (current_display_number
);
1625 fprintf_unfiltered (gdb_stderr
, "Disabling display %d to avoid infinite recursion.\n",
1626 current_display_number
);
1628 current_display_number
= -1;
1632 display_info (char *ignore
, int from_tty
)
1634 register struct display
*d
;
1637 printf_unfiltered ("There are no auto-display expressions now.\n");
1639 printf_filtered ("Auto-display expressions now in effect:\n\
1640 Num Enb Expression\n");
1642 for (d
= display_chain
; d
; d
= d
->next
)
1644 printf_filtered ("%d: %c ", d
->number
, "ny"[(int) d
->enabled_p
]);
1646 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1648 else if (d
->format
.format
)
1649 printf_filtered ("/%c ", d
->format
.format
);
1650 print_expression (d
->exp
, gdb_stdout
);
1651 if (d
->block
&& !contained_in (get_selected_block (0), d
->block
))
1652 printf_filtered (" (cannot be evaluated in the current context)");
1653 printf_filtered ("\n");
1654 gdb_flush (gdb_stdout
);
1659 enable_display (char *args
, int from_tty
)
1661 register char *p
= args
;
1664 register struct display
*d
;
1668 for (d
= display_chain
; d
; d
= d
->next
)
1675 while (*p1
>= '0' && *p1
<= '9')
1677 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1678 error ("Arguments must be display numbers.");
1682 for (d
= display_chain
; d
; d
= d
->next
)
1683 if (d
->number
== num
)
1688 printf_unfiltered ("No display number %d.\n", num
);
1691 while (*p
== ' ' || *p
== '\t')
1698 disable_display_command (char *args
, int from_tty
)
1700 register char *p
= args
;
1702 register struct display
*d
;
1706 for (d
= display_chain
; d
; d
= d
->next
)
1713 while (*p1
>= '0' && *p1
<= '9')
1715 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1716 error ("Arguments must be display numbers.");
1718 disable_display (atoi (p
));
1721 while (*p
== ' ' || *p
== '\t')
1727 /* Print the value in stack frame FRAME of a variable
1728 specified by a struct symbol. */
1731 print_variable_value (struct symbol
*var
, struct frame_info
*frame
,
1732 struct ui_file
*stream
)
1734 struct value
*val
= read_var_value (var
, frame
);
1736 value_print (val
, stream
, 0, Val_pretty_default
);
1741 printf_command (char *arg
, int from_tty
)
1743 register char *f
= NULL
;
1744 register char *s
= arg
;
1745 char *string
= NULL
;
1746 struct value
**val_args
;
1748 char *current_substring
;
1750 int allocated_args
= 20;
1751 struct cleanup
*old_cleanups
;
1753 val_args
= (struct value
**) xmalloc (allocated_args
1754 * sizeof (struct value
*));
1755 old_cleanups
= make_cleanup (free_current_contents
, &val_args
);
1758 error_no_arg ("format-control string and values to print");
1760 /* Skip white space before format string */
1761 while (*s
== ' ' || *s
== '\t')
1764 /* A format string should follow, enveloped in double quotes */
1766 error ("Bad format string, missing '\"'.");
1768 /* Parse the format-control string and copy it into the string STRING,
1769 processing some kinds of escape sequence. */
1771 f
= string
= (char *) alloca (strlen (s
) + 1);
1779 error ("Bad format string, non-terminated '\"'.");
1812 /* ??? TODO: handle other escape sequences */
1813 error ("Unrecognized escape character \\%c in format string.",
1823 /* Skip over " and following space and comma. */
1826 while (*s
== ' ' || *s
== '\t')
1829 if (*s
!= ',' && *s
!= 0)
1830 error ("Invalid argument syntax");
1834 while (*s
== ' ' || *s
== '\t')
1837 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1838 substrings
= alloca (strlen (string
) * 2);
1839 current_substring
= substrings
;
1842 /* Now scan the string for %-specs and see what kinds of args they want.
1843 argclass[I] classifies the %-specs so we can give printf_filtered
1844 something of the right size. */
1848 no_arg
, int_arg
, string_arg
, double_arg
, long_long_arg
1850 enum argclass
*argclass
;
1851 enum argclass this_argclass
;
1857 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1865 while (strchr ("0123456789.hlL-+ #", *f
))
1867 if (*f
== 'l' || *f
== 'L')
1874 this_argclass
= string_arg
;
1880 this_argclass
= double_arg
;
1884 error ("`*' not supported for precision or width in printf");
1887 error ("Format specifier `n' not supported in printf");
1890 this_argclass
= no_arg
;
1895 this_argclass
= long_long_arg
;
1897 this_argclass
= int_arg
;
1901 if (this_argclass
!= no_arg
)
1903 strncpy (current_substring
, last_arg
, f
- last_arg
);
1904 current_substring
+= f
- last_arg
;
1905 *current_substring
++ = '\0';
1907 argclass
[nargs_wanted
++] = this_argclass
;
1911 /* Now, parse all arguments and evaluate them.
1912 Store the VALUEs in VAL_ARGS. */
1917 if (nargs
== allocated_args
)
1918 val_args
= (struct value
**) xrealloc ((char *) val_args
,
1919 (allocated_args
*= 2)
1920 * sizeof (struct value
*));
1922 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
1924 /* If format string wants a float, unchecked-convert the value to
1925 floating point of the same size */
1927 if (argclass
[nargs
] == double_arg
)
1929 struct type
*type
= VALUE_TYPE (val_args
[nargs
]);
1930 if (TYPE_LENGTH (type
) == sizeof (float))
1931 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
1932 if (TYPE_LENGTH (type
) == sizeof (double))
1933 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
1941 if (nargs
!= nargs_wanted
)
1942 error ("Wrong number of arguments for specified format-string");
1944 /* Now actually print them. */
1945 current_substring
= substrings
;
1946 for (i
= 0; i
< nargs
; i
++)
1948 switch (argclass
[i
])
1955 tem
= value_as_address (val_args
[i
]);
1957 /* This is a %s argument. Find the length of the string. */
1962 read_memory (tem
+ j
, &c
, 1);
1967 /* Copy the string contents into a string inside GDB. */
1968 str
= (char *) alloca (j
+ 1);
1970 read_memory (tem
, str
, j
);
1973 printf_filtered (current_substring
, str
);
1978 double val
= value_as_double (val_args
[i
]);
1979 printf_filtered (current_substring
, val
);
1983 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
1985 long long val
= value_as_long (val_args
[i
]);
1986 printf_filtered (current_substring
, val
);
1990 error ("long long not supported in printf");
1994 /* FIXME: there should be separate int_arg and long_arg. */
1995 long val
= value_as_long (val_args
[i
]);
1996 printf_filtered (current_substring
, val
);
1999 default: /* purecov: deadcode */
2000 error ("internal error in printf_command"); /* purecov: deadcode */
2002 /* Skip to the next substring. */
2003 current_substring
+= strlen (current_substring
) + 1;
2005 /* Print the portion of the format string after the last argument. */
2006 puts_filtered (last_arg
);
2008 do_cleanups (old_cleanups
);
2012 _initialize_printcmd (void)
2014 struct cmd_list_element
*c
;
2016 current_display_number
= -1;
2018 add_info ("address", address_info
,
2019 "Describe where symbol SYM is stored.");
2021 add_info ("symbol", sym_info
,
2022 "Describe what symbol is at location ADDR.\n\
2023 Only for symbols with fixed locations (global or static scope).");
2025 add_com ("x", class_vars
, x_command
,
2026 concat ("Examine memory: x/FMT ADDRESS.\n\
2027 ADDRESS is an expression for the memory address to examine.\n\
2028 FMT is a repeat count followed by a format letter and a size letter.\n\
2029 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2030 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n",
2031 "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2032 The specified number of objects of the specified size are printed\n\
2033 according to the format.\n\n\
2034 Defaults for format and size letters are those previously used.\n\
2035 Default count is 1. Default address is following last thing printed\n\
2036 with this command or \"print\".", NULL
));
2039 add_com ("whereis", class_vars
, whereis_command
,
2040 "Print line number and file of definition of variable.");
2043 add_info ("display", display_info
,
2044 "Expressions to display when program stops, with code numbers.");
2046 add_cmd ("undisplay", class_vars
, undisplay_command
,
2047 "Cancel some expressions to be displayed when program stops.\n\
2048 Arguments are the code numbers of the expressions to stop displaying.\n\
2049 No argument means cancel all automatic-display expressions.\n\
2050 \"delete display\" has the same effect as this command.\n\
2051 Do \"info display\" to see current list of code numbers.",
2054 add_com ("display", class_vars
, display_command
,
2055 "Print value of expression EXP each time the program stops.\n\
2056 /FMT may be used before EXP as in the \"print\" command.\n\
2057 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2058 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2059 and examining is done as in the \"x\" command.\n\n\
2060 With no argument, display all currently requested auto-display expressions.\n\
2061 Use \"undisplay\" to cancel display requests previously made."
2064 add_cmd ("display", class_vars
, enable_display
,
2065 "Enable some expressions to be displayed when program stops.\n\
2066 Arguments are the code numbers of the expressions to resume displaying.\n\
2067 No argument means enable all automatic-display expressions.\n\
2068 Do \"info display\" to see current list of code numbers.", &enablelist
);
2070 add_cmd ("display", class_vars
, disable_display_command
,
2071 "Disable some expressions to be displayed when program stops.\n\
2072 Arguments are the code numbers of the expressions to stop displaying.\n\
2073 No argument means disable all automatic-display expressions.\n\
2074 Do \"info display\" to see current list of code numbers.", &disablelist
);
2076 add_cmd ("display", class_vars
, undisplay_command
,
2077 "Cancel some expressions to be displayed when program stops.\n\
2078 Arguments are the code numbers of the expressions to stop displaying.\n\
2079 No argument means cancel all automatic-display expressions.\n\
2080 Do \"info display\" to see current list of code numbers.", &deletelist
);
2082 add_com ("printf", class_vars
, printf_command
,
2083 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2084 This is useful for formatted output in user-defined commands.");
2086 add_com ("output", class_vars
, output_command
,
2087 "Like \"print\" but don't put in value history and don't print newline.\n\
2088 This is useful in user-defined commands.");
2090 add_prefix_cmd ("set", class_vars
, set_command
,
2091 concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2092 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2093 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2094 with $), a register (a few standard names starting with $), or an actual\n\
2095 variable in the program being debugged. EXP is any valid expression.\n",
2096 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2097 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2098 You can see these environment settings with the \"show\" command.", NULL
),
2099 &setlist
, "set ", 1, &cmdlist
);
2101 add_com ("assign", class_vars
, set_command
, concat ("Evaluate expression \
2102 EXP and assign result to variable VAR, using assignment\n\
2103 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2104 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2105 with $), a register (a few standard names starting with $), or an actual\n\
2106 variable in the program being debugged. EXP is any valid expression.\n",
2107 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2108 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2109 You can see these environment settings with the \"show\" command.", NULL
));
2111 /* "call" is the same as "set", but handy for dbx users to call fns. */
2112 c
= add_com ("call", class_vars
, call_command
,
2113 "Call a function in the program.\n\
2114 The argument is the function name and arguments, in the notation of the\n\
2115 current working language. The result is printed and saved in the value\n\
2116 history, if it is not void.");
2117 set_cmd_completer (c
, location_completer
);
2119 add_cmd ("variable", class_vars
, set_command
,
2120 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2121 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2122 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2123 with $), a register (a few standard names starting with $), or an actual\n\
2124 variable in the program being debugged. EXP is any valid expression.\n\
2125 This may usually be abbreviated to simply \"set\".",
2128 c
= add_com ("print", class_vars
, print_command
,
2129 concat ("Print value of expression EXP.\n\
2130 Variables accessible are those of the lexical environment of the selected\n\
2131 stack frame, plus all those whose scope is global or an entire file.\n\
2133 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2134 $$NUM refers to NUM'th value back from the last one.\n\
2135 Names starting with $ refer to registers (with the values they would have\n",
2136 "if the program were to return to the stack frame now selected, restoring\n\
2137 all registers saved by frames farther in) or else to debugger\n\
2138 \"convenience\" variables (any such name not a known register).\n\
2139 Use assignment expressions to give values to convenience variables.\n",
2141 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2142 @ is a binary operator for treating consecutive data objects\n\
2143 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2144 element is FOO, whose second element is stored in the space following\n\
2145 where FOO is stored, etc. FOO must be an expression whose value\n\
2146 resides in memory.\n",
2148 EXP may be preceded with /FMT, where FMT is a format letter\n\
2149 but no count or size letter (see \"x\" command).", NULL
));
2150 set_cmd_completer (c
, location_completer
);
2151 add_com_alias ("p", "print", class_vars
, 1);
2153 c
= add_com ("inspect", class_vars
, inspect_command
,
2154 "Same as \"print\" command, except that if you are running in the epoch\n\
2155 environment, the value is printed in its own window.");
2156 set_cmd_completer (c
, location_completer
);
2159 add_set_cmd ("max-symbolic-offset", no_class
, var_uinteger
,
2160 (char *) &max_symbolic_offset
,
2161 "Set the largest offset that will be printed in <symbol+1234> form.",
2165 add_set_cmd ("symbol-filename", no_class
, var_boolean
,
2166 (char *) &print_symbol_filename
,
2167 "Set printing of source filename and line number with <symbol>.",
2171 /* For examine/instruction a single byte quantity is specified as
2172 the data. This avoids problems with value_at_lazy() requiring a
2173 valid data type (and rejecting VOID). */
2174 examine_i_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_i_type", NULL
);
2176 examine_b_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_b_type", NULL
);
2177 examine_h_type
= init_type (TYPE_CODE_INT
, 2, 0, "examine_h_type", NULL
);
2178 examine_w_type
= init_type (TYPE_CODE_INT
, 4, 0, "examine_w_type", NULL
);
2179 examine_g_type
= init_type (TYPE_CODE_INT
, 8, 0, "examine_g_type", NULL
);