1 /* Print values for GNU debugger GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
5 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>. */
23 #include "gdb_string.h"
29 #include "expression.h"
33 #include "breakpoint.h"
37 #include "symfile.h" /* for overlay functions */
38 #include "objfiles.h" /* ditto */
39 #include "completer.h" /* for completion functions */
41 #include "gdb_assert.h"
46 #include "tui/tui.h" /* For tui_active et.al. */
49 extern int asm_demangle; /* Whether to demangle syms in asm printouts */
50 extern int addressprint; /* Whether to print hex addresses in HLL " */
59 /* Last specified output format. */
61 static char last_format = 'x';
63 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
65 static char last_size = 'w';
67 /* Default address to examine next. */
69 static CORE_ADDR next_address;
71 /* Number of delay instructions following current disassembled insn. */
73 static int branch_delay_insns;
75 /* Last address examined. */
77 static CORE_ADDR last_examine_address;
79 /* Contents of last address examined.
80 This is not valid past the end of the `x' command! */
82 static struct value *last_examine_value;
84 /* Largest offset between a symbolic value and an address, that will be
85 printed as `0x1234 <symbol+offset>'. */
87 static unsigned int max_symbolic_offset = UINT_MAX;
89 show_max_symbolic_offset (struct ui_file *file, int from_tty,
90 struct cmd_list_element *c, const char *value)
92 fprintf_filtered (file, _("\
93 The largest offset that will be printed in <symbol+1234> form is %s.\n"),
97 /* Append the source filename and linenumber of the symbol when
98 printing a symbolic value as `<symbol at filename:linenum>' if set. */
99 static int print_symbol_filename = 0;
101 show_print_symbol_filename (struct ui_file *file, int from_tty,
102 struct cmd_list_element *c, const char *value)
104 fprintf_filtered (file, _("\
105 Printing of source filename and line number with <symbol> is %s.\n"),
109 /* Number of auto-display expression currently being displayed.
110 So that we can disable it if we get an error or a signal within it.
111 -1 when not doing one. */
113 int current_display_number;
115 /* Flag to low-level print routines that this value is being printed
116 in an epoch window. We'd like to pass this as a parameter, but
117 every routine would need to take it. Perhaps we can encapsulate
118 this in the I/O stream once we have GNU stdio. */
124 /* Chain link to next auto-display item. */
125 struct display *next;
126 /* Expression to be evaluated and displayed. */
127 struct expression *exp;
128 /* Item number of this auto-display item. */
130 /* Display format specified. */
131 struct format_data format;
132 /* Innermost block required by this expression when evaluated */
134 /* Status of this display (enabled or disabled) */
138 /* Chain of expressions whose values should be displayed
139 automatically each time the program stops. */
141 static struct display *display_chain;
143 static int display_number;
145 /* Prototypes for exported functions. */
147 void output_command (char *, int);
149 void _initialize_printcmd (void);
151 /* Prototypes for local functions. */
153 static void do_one_display (struct display *);
156 /* Decode a format specification. *STRING_PTR should point to it.
157 OFORMAT and OSIZE are used as defaults for the format and size
158 if none are given in the format specification.
159 If OSIZE is zero, then the size field of the returned value
160 should be set only if a size is explicitly specified by the
162 The structure returned describes all the data
163 found in the specification. In addition, *STRING_PTR is advanced
164 past the specification and past all whitespace following it. */
166 static struct format_data
167 decode_format (char **string_ptr, int oformat, int osize)
169 struct format_data val;
170 char *p = *string_ptr;
176 if (*p >= '0' && *p <= '9')
177 val.count = atoi (p);
178 while (*p >= '0' && *p <= '9')
181 /* Now process size or format letters that follow. */
185 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
187 else if (*p >= 'a' && *p <= 'z')
193 while (*p == ' ' || *p == '\t')
197 /* Set defaults for format and size if not specified. */
198 if (val.format == '?')
202 /* Neither has been specified. */
203 val.format = oformat;
207 /* If a size is specified, any format makes a reasonable
208 default except 'i'. */
209 val.format = oformat == 'i' ? 'x' : oformat;
211 else if (val.size == '?')
216 /* Pick the appropriate size for an address. */
217 if (gdbarch_ptr_bit (current_gdbarch) == 64)
218 val.size = osize ? 'g' : osize;
219 else if (gdbarch_ptr_bit (current_gdbarch) == 32)
220 val.size = osize ? 'w' : osize;
221 else if (gdbarch_ptr_bit (current_gdbarch) == 16)
222 val.size = osize ? 'h' : osize;
224 /* Bad value for gdbarch_ptr_bit. */
225 internal_error (__FILE__, __LINE__,
226 _("failed internal consistency check"));
229 /* Floating point has to be word or giantword. */
230 if (osize == 'w' || osize == 'g')
233 /* Default it to giantword if the last used size is not
235 val.size = osize ? 'g' : osize;
238 /* Characters default to one byte. */
239 val.size = osize ? 'b' : osize;
242 /* The default is the size most recently specified. */
249 /* Print value VAL on stream according to FORMAT, a letter or 0.
250 Do not end with a newline.
251 0 means print VAL according to its own type.
252 SIZE is the letter for the size of datum being printed.
253 This is used to pad hex numbers so they line up. SIZE is 0
254 for print / output and set for examine. */
257 print_formatted (struct value *val, int format, int size,
258 struct ui_file *stream)
260 struct type *type = check_typedef (value_type (val));
261 int len = TYPE_LENGTH (type);
263 if (VALUE_LVAL (val) == lval_memory)
264 next_address = VALUE_ADDRESS (val) + len;
271 /* FIXME: Need to handle wchar_t's here... */
272 next_address = VALUE_ADDRESS (val)
273 + val_print_string (VALUE_ADDRESS (val), -1, 1, stream);
277 /* We often wrap here if there are long symbolic names. */
279 next_address = (VALUE_ADDRESS (val)
280 + gdb_print_insn (VALUE_ADDRESS (val), stream,
281 &branch_delay_insns));
286 if (format == 0 || format == 's'
287 || TYPE_CODE (type) == TYPE_CODE_ARRAY
288 || TYPE_CODE (type) == TYPE_CODE_STRING
289 || TYPE_CODE (type) == TYPE_CODE_STRUCT
290 || TYPE_CODE (type) == TYPE_CODE_UNION
291 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
292 /* If format is 0, use the 'natural' format for that type of
293 value. If the type is non-scalar, we have to use language
294 rules to print it as a series of scalars. */
295 value_print (val, stream, format, Val_pretty_default);
297 /* User specified format, so don't look to the the type to
298 tell us what to do. */
299 print_scalar_formatted (value_contents (val), type,
300 format, size, stream);
303 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
304 according to letters FORMAT and SIZE on STREAM.
305 FORMAT may not be zero. Formats s and i are not supported at this level.
307 This is how the elements of an array or structure are printed
311 print_scalar_formatted (const void *valaddr, struct type *type,
312 int format, int size, struct ui_file *stream)
314 LONGEST val_long = 0;
315 unsigned int len = TYPE_LENGTH (type);
317 /* If we get here with a string format, try again without it. Go
318 all the way back to the language printers, which may call us
322 val_print (type, valaddr, 0, 0, stream, 0, 0, 0, Val_pretty_default);
326 if (len > sizeof(LONGEST) &&
327 (TYPE_CODE (type) == TYPE_CODE_INT
328 || TYPE_CODE (type) == TYPE_CODE_ENUM))
333 print_octal_chars (stream, valaddr, len);
337 print_decimal_chars (stream, valaddr, len);
340 print_binary_chars (stream, valaddr, len);
343 print_hex_chars (stream, valaddr, len);
346 print_char_chars (stream, valaddr, len);
354 val_long = unpack_long (type, valaddr);
356 /* If the value is a pointer, and pointers and addresses are not the
357 same, then at this point, the value's length (in target bytes) is
358 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
359 if (TYPE_CODE (type) == TYPE_CODE_PTR)
360 len = gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT;
362 /* If we are printing it as unsigned, truncate it in case it is actually
363 a negative signed value (e.g. "print/u (short)-1" should print 65535
364 (if shorts are 16 bits) instead of 4294967295). */
367 if (len < sizeof (LONGEST))
368 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
376 /* No size specified, like in print. Print varying # of digits. */
377 print_longest (stream, 'x', 1, val_long);
386 print_longest (stream, size, 1, val_long);
389 error (_("Undefined output size \"%c\"."), size);
394 print_longest (stream, 'd', 1, val_long);
398 print_longest (stream, 'u', 0, val_long);
403 print_longest (stream, 'o', 1, val_long);
405 fprintf_filtered (stream, "0");
410 CORE_ADDR addr = unpack_pointer (type, valaddr);
411 print_address (addr, stream);
416 if (TYPE_UNSIGNED (type))
420 utype = builtin_type (current_gdbarch)->builtin_true_unsigned_char;
421 value_print (value_from_longest (utype, val_long),
422 stream, 0, Val_pretty_default);
425 value_print (value_from_longest (builtin_type_true_char, val_long),
426 stream, 0, Val_pretty_default);
430 if (len == TYPE_LENGTH (builtin_type_float))
431 type = builtin_type_float;
432 else if (len == TYPE_LENGTH (builtin_type_double))
433 type = builtin_type_double;
434 else if (len == TYPE_LENGTH (builtin_type_long_double))
435 type = builtin_type_long_double;
436 print_floating (valaddr, type, stream);
440 internal_error (__FILE__, __LINE__,
441 _("failed internal consistency check"));
444 /* Binary; 't' stands for "two". */
446 char bits[8 * (sizeof val_long) + 1];
447 char buf[8 * (sizeof val_long) + 32];
452 width = 8 * (sizeof val_long);
469 error (_("Undefined output size \"%c\"."), size);
475 bits[width] = (val_long & 1) ? '1' : '0';
480 while (*cp && *cp == '0')
486 fputs_filtered (buf, stream);
491 error (_("Undefined output format \"%c\"."), format);
495 /* Specify default address for `x' command.
496 The `info lines' command uses this. */
499 set_next_address (CORE_ADDR addr)
503 /* Make address available to the user as $_. */
504 set_internalvar (lookup_internalvar ("_"),
505 value_from_pointer (lookup_pointer_type (builtin_type_void),
509 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
510 after LEADIN. Print nothing if no symbolic name is found nearby.
511 Optionally also print source file and line number, if available.
512 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
513 or to interpret it as a possible C++ name and convert it back to source
514 form. However note that DO_DEMANGLE can be overridden by the specific
515 settings of the demangle and asm_demangle variables. */
518 print_address_symbolic (CORE_ADDR addr, struct ui_file *stream,
519 int do_demangle, char *leadin)
522 char *filename = NULL;
527 /* Throw away both name and filename. */
528 struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
529 make_cleanup (free_current_contents, &filename);
531 if (build_address_symbolic (addr, do_demangle, &name, &offset,
532 &filename, &line, &unmapped))
534 do_cleanups (cleanup_chain);
538 fputs_filtered (leadin, stream);
540 fputs_filtered ("<*", stream);
542 fputs_filtered ("<", stream);
543 fputs_filtered (name, stream);
545 fprintf_filtered (stream, "+%u", (unsigned int) offset);
547 /* Append source filename and line number if desired. Give specific
548 line # of this addr, if we have it; else line # of the nearest symbol. */
549 if (print_symbol_filename && filename != NULL)
552 fprintf_filtered (stream, " at %s:%d", filename, line);
554 fprintf_filtered (stream, " in %s", filename);
557 fputs_filtered ("*>", stream);
559 fputs_filtered (">", stream);
561 do_cleanups (cleanup_chain);
564 /* Given an address ADDR return all the elements needed to print the
565 address in a symbolic form. NAME can be mangled or not depending
566 on DO_DEMANGLE (and also on the asm_demangle global variable,
567 manipulated via ''set print asm-demangle''). Return 0 in case of
568 success, when all the info in the OUT paramters is valid. Return 1
571 build_address_symbolic (CORE_ADDR addr, /* IN */
572 int do_demangle, /* IN */
573 char **name, /* OUT */
574 int *offset, /* OUT */
575 char **filename, /* OUT */
577 int *unmapped) /* OUT */
579 struct minimal_symbol *msymbol;
580 struct symbol *symbol;
581 CORE_ADDR name_location = 0;
582 asection *section = 0;
583 char *name_temp = "";
585 /* Let's say it is unmapped. */
588 /* Determine if the address is in an overlay, and whether it is
590 if (overlay_debugging)
592 section = find_pc_overlay (addr);
593 if (pc_in_unmapped_range (addr, section))
596 addr = overlay_mapped_address (addr, section);
600 /* First try to find the address in the symbol table, then
601 in the minsyms. Take the closest one. */
603 /* This is defective in the sense that it only finds text symbols. So
604 really this is kind of pointless--we should make sure that the
605 minimal symbols have everything we need (by changing that we could
606 save some memory, but for many debug format--ELF/DWARF or
607 anything/stabs--it would be inconvenient to eliminate those minimal
609 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
610 symbol = find_pc_sect_function (addr, section);
614 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
615 if (do_demangle || asm_demangle)
616 name_temp = SYMBOL_PRINT_NAME (symbol);
618 name_temp = DEPRECATED_SYMBOL_NAME (symbol);
623 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
625 /* The msymbol is closer to the address than the symbol;
626 use the msymbol instead. */
628 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
629 if (do_demangle || asm_demangle)
630 name_temp = SYMBOL_PRINT_NAME (msymbol);
632 name_temp = DEPRECATED_SYMBOL_NAME (msymbol);
635 if (symbol == NULL && msymbol == NULL)
638 /* If the nearest symbol is too far away, don't print anything symbolic. */
640 /* For when CORE_ADDR is larger than unsigned int, we do math in
641 CORE_ADDR. But when we detect unsigned wraparound in the
642 CORE_ADDR math, we ignore this test and print the offset,
643 because addr+max_symbolic_offset has wrapped through the end
644 of the address space back to the beginning, giving bogus comparison. */
645 if (addr > name_location + max_symbolic_offset
646 && name_location + max_symbolic_offset > name_location)
649 *offset = addr - name_location;
651 *name = xstrdup (name_temp);
653 if (print_symbol_filename)
655 struct symtab_and_line sal;
657 sal = find_pc_sect_line (addr, section, 0);
661 *filename = xstrdup (sal.symtab->filename);
668 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
671 deprecated_print_address_numeric (CORE_ADDR addr, int use_local,
672 struct ui_file *stream)
675 fputs_filtered (paddress (addr), stream);
678 int addr_bit = gdbarch_addr_bit (current_gdbarch);
680 if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
681 addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
682 print_longest (stream, 'x', 0, (ULONGEST) addr);
686 /* Print address ADDR symbolically on STREAM.
687 First print it as a number. Then perhaps print
688 <SYMBOL + OFFSET> after the number. */
691 print_address (CORE_ADDR addr, struct ui_file *stream)
693 deprecated_print_address_numeric (addr, 1, stream);
694 print_address_symbolic (addr, stream, asm_demangle, " ");
697 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
698 controls whether to print the symbolic name "raw" or demangled.
699 Global setting "addressprint" controls whether to print hex address
703 print_address_demangle (CORE_ADDR addr, struct ui_file *stream,
708 fprintf_filtered (stream, "0");
710 else if (addressprint)
712 deprecated_print_address_numeric (addr, 1, stream);
713 print_address_symbolic (addr, stream, do_demangle, " ");
717 print_address_symbolic (addr, stream, do_demangle, "");
722 /* These are the types that $__ will get after an examine command of one
725 static struct type *examine_i_type;
727 static struct type *examine_b_type;
728 static struct type *examine_h_type;
729 static struct type *examine_w_type;
730 static struct type *examine_g_type;
732 /* Examine data at address ADDR in format FMT.
733 Fetch it from memory and print on gdb_stdout. */
736 do_examine (struct format_data fmt, CORE_ADDR addr)
741 struct type *val_type = NULL;
750 /* String or instruction format implies fetch single bytes
751 regardless of the specified size. */
752 if (format == 's' || format == 'i')
756 val_type = examine_i_type;
757 else if (size == 'b')
758 val_type = examine_b_type;
759 else if (size == 'h')
760 val_type = examine_h_type;
761 else if (size == 'w')
762 val_type = examine_w_type;
763 else if (size == 'g')
764 val_type = examine_g_type;
771 if (format == 's' || format == 'i')
774 /* Print as many objects as specified in COUNT, at most maxelts per line,
775 with the address of the next one at the start of each line. */
780 print_address (next_address, gdb_stdout);
781 printf_filtered (":");
786 printf_filtered ("\t");
787 /* Note that print_formatted sets next_address for the next
789 last_examine_address = next_address;
791 if (last_examine_value)
792 value_free (last_examine_value);
794 /* The value to be displayed is not fetched greedily.
795 Instead, to avoid the possibility of a fetched value not
796 being used, its retrieval is delayed until the print code
797 uses it. When examining an instruction stream, the
798 disassembler will perform its own memory fetch using just
799 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
800 the disassembler be modified so that LAST_EXAMINE_VALUE
801 is left with the byte sequence from the last complete
802 instruction fetched from memory? */
803 last_examine_value = value_at_lazy (val_type, next_address);
805 if (last_examine_value)
806 release_value (last_examine_value);
808 print_formatted (last_examine_value, format, size, gdb_stdout);
810 /* Display any branch delay slots following the final insn. */
811 if (format == 'i' && count == 1)
812 count += branch_delay_insns;
814 printf_filtered ("\n");
815 gdb_flush (gdb_stdout);
820 validate_format (struct format_data fmt, char *cmdname)
823 error (_("Size letters are meaningless in \"%s\" command."), cmdname);
825 error (_("Item count other than 1 is meaningless in \"%s\" command."),
827 if (fmt.format == 'i')
828 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
829 fmt.format, cmdname);
832 /* Evaluate string EXP as an expression in the current language and
833 print the resulting value. EXP may contain a format specifier as the
834 first argument ("/x myvar" for example, to print myvar in hex). */
837 print_command_1 (char *exp, int inspect, int voidprint)
839 struct expression *expr;
840 struct cleanup *old_chain = 0;
843 struct format_data fmt;
846 /* Pass inspect flag to the rest of the print routines in a global
848 inspect_it = inspect;
850 if (exp && *exp == '/')
853 fmt = decode_format (&exp, last_format, 0);
854 validate_format (fmt, "print");
855 last_format = format = fmt.format;
867 expr = parse_expression (exp);
868 old_chain = make_cleanup (free_current_contents, &expr);
870 val = evaluate_expression (expr);
873 val = access_value_history (0);
875 if (voidprint || (val && value_type (val) &&
876 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
878 int histindex = record_latest_value (val);
881 annotate_value_history_begin (histindex, value_type (val));
883 annotate_value_begin (value_type (val));
886 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"",
888 else if (histindex >= 0)
889 printf_filtered ("$%d = ", histindex);
892 annotate_value_history_value ();
894 print_formatted (val, format, fmt.size, gdb_stdout);
895 printf_filtered ("\n");
898 annotate_value_history_end ();
900 annotate_value_end ();
903 printf_unfiltered ("\") )\030");
907 do_cleanups (old_chain);
908 inspect_it = 0; /* Reset print routines to normal. */
912 print_command (char *exp, int from_tty)
914 print_command_1 (exp, 0, 1);
917 /* Same as print, except in epoch, it gets its own window. */
919 inspect_command (char *exp, int from_tty)
921 extern int epoch_interface;
923 print_command_1 (exp, epoch_interface, 1);
926 /* Same as print, except it doesn't print void results. */
928 call_command (char *exp, int from_tty)
930 print_command_1 (exp, 0, 0);
934 output_command (char *exp, int from_tty)
936 struct expression *expr;
937 struct cleanup *old_chain;
940 struct format_data fmt;
944 if (exp && *exp == '/')
947 fmt = decode_format (&exp, 0, 0);
948 validate_format (fmt, "output");
952 expr = parse_expression (exp);
953 old_chain = make_cleanup (free_current_contents, &expr);
955 val = evaluate_expression (expr);
957 annotate_value_begin (value_type (val));
959 print_formatted (val, format, fmt.size, gdb_stdout);
961 annotate_value_end ();
964 gdb_flush (gdb_stdout);
966 do_cleanups (old_chain);
970 set_command (char *exp, int from_tty)
972 struct expression *expr = parse_expression (exp);
973 struct cleanup *old_chain =
974 make_cleanup (free_current_contents, &expr);
975 evaluate_expression (expr);
976 do_cleanups (old_chain);
980 sym_info (char *arg, int from_tty)
982 struct minimal_symbol *msymbol;
983 struct objfile *objfile;
984 struct obj_section *osect;
986 CORE_ADDR addr, sect_addr;
991 error_no_arg (_("address"));
993 addr = parse_and_eval_address (arg);
994 ALL_OBJSECTIONS (objfile, osect)
996 /* Only process each object file once, even if there's a separate
998 if (objfile->separate_debug_objfile_backlink)
1001 sect = osect->the_bfd_section;
1002 sect_addr = overlay_mapped_address (addr, sect);
1004 if (osect->addr <= sect_addr && sect_addr < osect->endaddr &&
1005 (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect)))
1008 offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
1010 printf_filtered ("%s + %u in ",
1011 SYMBOL_PRINT_NAME (msymbol), offset);
1013 printf_filtered ("%s in ",
1014 SYMBOL_PRINT_NAME (msymbol));
1015 if (pc_in_unmapped_range (addr, sect))
1016 printf_filtered (_("load address range of "));
1017 if (section_is_overlay (sect))
1018 printf_filtered (_("%s overlay "),
1019 section_is_mapped (sect) ? "mapped" : "unmapped");
1020 printf_filtered (_("section %s"), sect->name);
1021 printf_filtered ("\n");
1025 printf_filtered (_("No symbol matches %s.\n"), arg);
1029 address_info (char *exp, int from_tty)
1032 struct minimal_symbol *msymbol;
1036 CORE_ADDR load_addr;
1037 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
1038 if exp is a field of `this'. */
1041 error (_("Argument required."));
1043 sym = lookup_symbol (exp, get_selected_block (0), VAR_DOMAIN,
1044 &is_a_field_of_this, (struct symtab **) NULL);
1047 if (is_a_field_of_this)
1049 printf_filtered ("Symbol \"");
1050 fprintf_symbol_filtered (gdb_stdout, exp,
1051 current_language->la_language, DMGL_ANSI);
1052 printf_filtered ("\" is a field of the local class variable ");
1053 if (current_language->la_language == language_objc)
1054 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1056 printf_filtered ("`this'\n");
1060 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1062 if (msymbol != NULL)
1064 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1066 printf_filtered ("Symbol \"");
1067 fprintf_symbol_filtered (gdb_stdout, exp,
1068 current_language->la_language, DMGL_ANSI);
1069 printf_filtered ("\" is at ");
1070 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1071 printf_filtered (" in a file compiled without debugging");
1072 section = SYMBOL_BFD_SECTION (msymbol);
1073 if (section_is_overlay (section))
1075 load_addr = overlay_unmapped_address (load_addr, section);
1076 printf_filtered (",\n -- loaded at ");
1077 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1078 printf_filtered (" in overlay section %s", section->name);
1080 printf_filtered (".\n");
1083 error (_("No symbol \"%s\" in current context."), exp);
1087 printf_filtered ("Symbol \"");
1088 fprintf_symbol_filtered (gdb_stdout, DEPRECATED_SYMBOL_NAME (sym),
1089 current_language->la_language, DMGL_ANSI);
1090 printf_filtered ("\" is ");
1091 val = SYMBOL_VALUE (sym);
1092 basereg = SYMBOL_BASEREG (sym);
1093 section = SYMBOL_BFD_SECTION (sym);
1095 switch (SYMBOL_CLASS (sym))
1098 case LOC_CONST_BYTES:
1099 printf_filtered ("constant");
1103 printf_filtered ("a label at address ");
1104 deprecated_print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1106 if (section_is_overlay (section))
1108 load_addr = overlay_unmapped_address (load_addr, section);
1109 printf_filtered (",\n -- loaded at ");
1110 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1111 printf_filtered (" in overlay section %s", section->name);
1116 case LOC_COMPUTED_ARG:
1117 /* FIXME: cagney/2004-01-26: It should be possible to
1118 unconditionally call the SYMBOL_OPS method when available.
1119 Unfortunately DWARF 2 stores the frame-base (instead of the
1120 function) location in a function's symbol. Oops! For the
1121 moment enable this when/where applicable. */
1122 SYMBOL_OPS (sym)->describe_location (sym, gdb_stdout);
1126 printf_filtered (_("a variable in register %s"),
1127 gdbarch_register_name (current_gdbarch, val));
1131 printf_filtered (_("static storage at address "));
1132 deprecated_print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1134 if (section_is_overlay (section))
1136 load_addr = overlay_unmapped_address (load_addr, section);
1137 printf_filtered (_(",\n -- loaded at "));
1138 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1139 printf_filtered (_(" in overlay section %s"), section->name);
1144 printf_filtered (_("external global (indirect addressing), at address *("));
1145 deprecated_print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1147 printf_filtered (")");
1148 if (section_is_overlay (section))
1150 load_addr = overlay_unmapped_address (load_addr, section);
1151 printf_filtered (_(",\n -- loaded at "));
1152 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1153 printf_filtered (_(" in overlay section %s"), section->name);
1158 printf_filtered (_("an argument in register %s"),
1159 gdbarch_register_name (current_gdbarch, val));
1162 case LOC_REGPARM_ADDR:
1163 printf_filtered (_("address of an argument in register %s"),
1164 gdbarch_register_name (current_gdbarch, val));
1168 printf_filtered (_("an argument at offset %ld"), val);
1172 printf_filtered (_("an argument at frame offset %ld"), val);
1176 printf_filtered (_("a local variable at frame offset %ld"), val);
1180 printf_filtered (_("a reference argument at offset %ld"), val);
1184 printf_filtered (_("a variable at offset %ld from register %s"),
1185 val, gdbarch_register_name (current_gdbarch, basereg));
1188 case LOC_BASEREG_ARG:
1189 printf_filtered (_("an argument at offset %ld from register %s"),
1190 val, gdbarch_register_name (current_gdbarch, basereg));
1194 printf_filtered (_("a typedef"));
1198 printf_filtered (_("a function at address "));
1199 load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1200 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1201 if (section_is_overlay (section))
1203 load_addr = overlay_unmapped_address (load_addr, section);
1204 printf_filtered (_(",\n -- loaded at "));
1205 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1206 printf_filtered (_(" in overlay section %s"), section->name);
1210 case LOC_UNRESOLVED:
1212 struct minimal_symbol *msym;
1214 msym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym), NULL, NULL);
1216 printf_filtered ("unresolved");
1219 section = SYMBOL_BFD_SECTION (msym);
1220 printf_filtered (_("static storage at address "));
1221 load_addr = SYMBOL_VALUE_ADDRESS (msym);
1222 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1223 if (section_is_overlay (section))
1225 load_addr = overlay_unmapped_address (load_addr, section);
1226 printf_filtered (_(",\n -- loaded at "));
1227 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1228 printf_filtered (_(" in overlay section %s"), section->name);
1234 case LOC_HP_THREAD_LOCAL_STATIC:
1235 printf_filtered (_("\
1236 a thread-local variable at offset %ld from the thread base register %s"),
1237 val, gdbarch_register_name (current_gdbarch, basereg));
1240 case LOC_OPTIMIZED_OUT:
1241 printf_filtered (_("optimized out"));
1245 printf_filtered (_("of unknown (botched) type"));
1248 printf_filtered (".\n");
1253 x_command (char *exp, int from_tty)
1255 struct expression *expr;
1256 struct format_data fmt;
1257 struct cleanup *old_chain;
1260 fmt.format = last_format;
1261 fmt.size = last_size;
1264 if (exp && *exp == '/')
1267 fmt = decode_format (&exp, last_format, last_size);
1270 /* If we have an expression, evaluate it and use it as the address. */
1272 if (exp != 0 && *exp != 0)
1274 expr = parse_expression (exp);
1275 /* Cause expression not to be there any more if this command is
1276 repeated with Newline. But don't clobber a user-defined
1277 command's definition. */
1280 old_chain = make_cleanup (free_current_contents, &expr);
1281 val = evaluate_expression (expr);
1282 if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
1283 val = value_ind (val);
1284 /* In rvalue contexts, such as this, functions are coerced into
1285 pointers to functions. This makes "x/i main" work. */
1286 if (/* last_format == 'i' && */
1287 TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
1288 && VALUE_LVAL (val) == lval_memory)
1289 next_address = VALUE_ADDRESS (val);
1291 next_address = value_as_address (val);
1292 do_cleanups (old_chain);
1295 do_examine (fmt, next_address);
1297 /* If the examine succeeds, we remember its size and format for next
1299 last_size = fmt.size;
1300 last_format = fmt.format;
1302 /* Set a couple of internal variables if appropriate. */
1303 if (last_examine_value)
1305 /* Make last address examined available to the user as $_. Use
1306 the correct pointer type. */
1307 struct type *pointer_type
1308 = lookup_pointer_type (value_type (last_examine_value));
1309 set_internalvar (lookup_internalvar ("_"),
1310 value_from_pointer (pointer_type,
1311 last_examine_address));
1313 /* Make contents of last address examined available to the user
1314 as $__. If the last value has not been fetched from memory
1315 then don't fetch it now; instead mark it by voiding the $__
1317 if (value_lazy (last_examine_value))
1318 set_internalvar (lookup_internalvar ("__"),
1319 allocate_value (builtin_type_void));
1321 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1326 /* Add an expression to the auto-display chain.
1327 Specify the expression. */
1330 display_command (char *exp, int from_tty)
1332 struct format_data fmt;
1333 struct expression *expr;
1334 struct display *new;
1338 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1340 if (tui_active && exp != NULL && *exp == '$')
1341 display_it = (tui_set_layout_for_display_command (exp) == TUI_FAILURE);
1355 fmt = decode_format (&exp, 0, 0);
1356 if (fmt.size && fmt.format == 0)
1358 if (fmt.format == 'i' || fmt.format == 's')
1368 innermost_block = 0;
1369 expr = parse_expression (exp);
1371 new = (struct display *) xmalloc (sizeof (struct display));
1374 new->block = innermost_block;
1375 new->next = display_chain;
1376 new->number = ++display_number;
1379 display_chain = new;
1381 if (from_tty && target_has_execution)
1382 do_one_display (new);
1389 free_display (struct display *d)
1395 /* Clear out the display_chain. Done when new symtabs are loaded,
1396 since this invalidates the types stored in many expressions. */
1399 clear_displays (void)
1403 while ((d = display_chain) != NULL)
1406 display_chain = d->next;
1411 /* Delete the auto-display number NUM. */
1414 delete_display (int num)
1416 struct display *d1, *d;
1419 error (_("No display number %d."), num);
1421 if (display_chain->number == num)
1424 display_chain = d1->next;
1428 for (d = display_chain;; d = d->next)
1431 error (_("No display number %d."), num);
1432 if (d->next->number == num)
1442 /* Delete some values from the auto-display chain.
1443 Specify the element numbers. */
1446 undisplay_command (char *args, int from_tty)
1454 if (query ("Delete all auto-display expressions? "))
1463 while (*p1 >= '0' && *p1 <= '9')
1465 if (*p1 && *p1 != ' ' && *p1 != '\t')
1466 error (_("Arguments must be display numbers."));
1470 delete_display (num);
1473 while (*p == ' ' || *p == '\t')
1479 /* Display a single auto-display.
1480 Do nothing if the display cannot be printed in the current context,
1481 or if the display is disabled. */
1484 do_one_display (struct display *d)
1486 int within_current_scope;
1488 if (d->enabled_p == 0)
1492 within_current_scope = contained_in (get_selected_block (0), d->block);
1494 within_current_scope = 1;
1495 if (!within_current_scope)
1498 current_display_number = d->number;
1500 annotate_display_begin ();
1501 printf_filtered ("%d", d->number);
1502 annotate_display_number_end ();
1503 printf_filtered (": ");
1509 annotate_display_format ();
1511 printf_filtered ("x/");
1512 if (d->format.count != 1)
1513 printf_filtered ("%d", d->format.count);
1514 printf_filtered ("%c", d->format.format);
1515 if (d->format.format != 'i' && d->format.format != 's')
1516 printf_filtered ("%c", d->format.size);
1517 printf_filtered (" ");
1519 annotate_display_expression ();
1521 print_expression (d->exp, gdb_stdout);
1522 annotate_display_expression_end ();
1524 if (d->format.count != 1 || d->format.format == 'i')
1525 printf_filtered ("\n");
1527 printf_filtered (" ");
1529 val = evaluate_expression (d->exp);
1530 addr = value_as_address (val);
1531 if (d->format.format == 'i')
1532 addr = gdbarch_addr_bits_remove (current_gdbarch, addr);
1534 annotate_display_value ();
1536 do_examine (d->format, addr);
1540 annotate_display_format ();
1542 if (d->format.format)
1543 printf_filtered ("/%c ", d->format.format);
1545 annotate_display_expression ();
1547 print_expression (d->exp, gdb_stdout);
1548 annotate_display_expression_end ();
1550 printf_filtered (" = ");
1552 annotate_display_expression ();
1554 print_formatted (evaluate_expression (d->exp),
1555 d->format.format, d->format.size, gdb_stdout);
1556 printf_filtered ("\n");
1559 annotate_display_end ();
1561 gdb_flush (gdb_stdout);
1562 current_display_number = -1;
1565 /* Display all of the values on the auto-display chain which can be
1566 evaluated in the current scope. */
1573 for (d = display_chain; d; d = d->next)
1577 /* Delete the auto-display which we were in the process of displaying.
1578 This is done when there is an error or a signal. */
1581 disable_display (int num)
1585 for (d = display_chain; d; d = d->next)
1586 if (d->number == num)
1591 printf_unfiltered (_("No display number %d.\n"), num);
1595 disable_current_display (void)
1597 if (current_display_number >= 0)
1599 disable_display (current_display_number);
1600 fprintf_unfiltered (gdb_stderr, _("\
1601 Disabling display %d to avoid infinite recursion.\n"),
1602 current_display_number);
1604 current_display_number = -1;
1608 display_info (char *ignore, int from_tty)
1613 printf_unfiltered (_("There are no auto-display expressions now.\n"));
1615 printf_filtered (_("Auto-display expressions now in effect:\n\
1616 Num Enb Expression\n"));
1618 for (d = display_chain; d; d = d->next)
1620 printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]);
1622 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1624 else if (d->format.format)
1625 printf_filtered ("/%c ", d->format.format);
1626 print_expression (d->exp, gdb_stdout);
1627 if (d->block && !contained_in (get_selected_block (0), d->block))
1628 printf_filtered (_(" (cannot be evaluated in the current context)"));
1629 printf_filtered ("\n");
1630 gdb_flush (gdb_stdout);
1635 enable_display (char *args, int from_tty)
1644 for (d = display_chain; d; d = d->next)
1651 while (*p1 >= '0' && *p1 <= '9')
1653 if (*p1 && *p1 != ' ' && *p1 != '\t')
1654 error (_("Arguments must be display numbers."));
1658 for (d = display_chain; d; d = d->next)
1659 if (d->number == num)
1664 printf_unfiltered (_("No display number %d.\n"), num);
1667 while (*p == ' ' || *p == '\t')
1673 disable_display_command (char *args, int from_tty)
1681 for (d = display_chain; d; d = d->next)
1688 while (*p1 >= '0' && *p1 <= '9')
1690 if (*p1 && *p1 != ' ' && *p1 != '\t')
1691 error (_("Arguments must be display numbers."));
1693 disable_display (atoi (p));
1696 while (*p == ' ' || *p == '\t')
1702 /* Print the value in stack frame FRAME of a variable specified by a
1706 print_variable_value (struct symbol *var, struct frame_info *frame,
1707 struct ui_file *stream)
1709 struct value *val = read_var_value (var, frame);
1711 value_print (val, stream, 0, Val_pretty_default);
1715 printf_command (char *arg, int from_tty)
1719 char *string = NULL;
1720 struct value **val_args;
1722 char *current_substring;
1724 int allocated_args = 20;
1725 struct cleanup *old_cleanups;
1727 val_args = xmalloc (allocated_args * sizeof (struct value *));
1728 old_cleanups = make_cleanup (free_current_contents, &val_args);
1731 error_no_arg (_("format-control string and values to print"));
1733 /* Skip white space before format string */
1734 while (*s == ' ' || *s == '\t')
1737 /* A format string should follow, enveloped in double quotes. */
1739 error (_("Bad format string, missing '\"'."));
1741 /* Parse the format-control string and copy it into the string STRING,
1742 processing some kinds of escape sequence. */
1744 f = string = (char *) alloca (strlen (s) + 1);
1752 error (_("Bad format string, non-terminated '\"'."));
1785 /* ??? TODO: handle other escape sequences */
1786 error (_("Unrecognized escape character \\%c in format string."),
1796 /* Skip over " and following space and comma. */
1799 while (*s == ' ' || *s == '\t')
1802 if (*s != ',' && *s != 0)
1803 error (_("Invalid argument syntax"));
1807 while (*s == ' ' || *s == '\t')
1810 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1811 substrings = alloca (strlen (string) * 2);
1812 current_substring = substrings;
1815 /* Now scan the string for %-specs and see what kinds of args they want.
1816 argclass[I] classifies the %-specs so we can give printf_filtered
1817 something of the right size. */
1821 int_arg, long_arg, long_long_arg, ptr_arg, string_arg,
1822 double_arg, long_double_arg
1824 enum argclass *argclass;
1825 enum argclass this_argclass;
1830 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1837 int seen_hash = 0, seen_zero = 0, lcount = 0, seen_prec = 0;
1838 int seen_space = 0, seen_plus = 0;
1839 int seen_big_l = 0, seen_h = 0;
1842 /* Check the validity of the format specifier, and work
1843 out what argument it expects. We only accept C89
1844 format strings, with the exception of long long (which
1845 we autoconf for). */
1847 /* Skip over "%%". */
1854 /* The first part of a format specifier is a set of flag
1856 while (strchr ("0-+ #", *f))
1869 /* The next part of a format specifier is a width. */
1870 while (strchr ("0123456789", *f))
1873 /* The next part of a format specifier is a precision. */
1878 while (strchr ("0123456789", *f))
1882 /* The next part of a format specifier is a length modifier. */
1914 if (seen_space || seen_plus)
1921 this_argclass = int_arg;
1922 else if (lcount == 1)
1923 this_argclass = long_arg;
1925 this_argclass = long_long_arg;
1932 this_argclass = int_arg;
1933 if (lcount || seen_h || seen_big_l)
1935 if (seen_prec || seen_zero || seen_space || seen_plus)
1940 this_argclass = ptr_arg;
1941 if (lcount || seen_h || seen_big_l)
1943 if (seen_prec || seen_zero || seen_space || seen_plus)
1948 this_argclass = string_arg;
1949 if (lcount || seen_h || seen_big_l)
1951 if (seen_zero || seen_space || seen_plus)
1961 this_argclass = long_double_arg;
1963 this_argclass = double_arg;
1965 if (lcount || seen_h)
1970 error (_("`*' not supported for precision or width in printf"));
1973 error (_("Format specifier `n' not supported in printf"));
1976 error (_("Incomplete format specifier at end of format string"));
1979 error (_("Unrecognized format specifier '%c' in printf"), *f);
1983 error (_("Inappropriate modifiers to format specifier '%c' in printf"),
1987 strncpy (current_substring, last_arg, f - last_arg);
1988 current_substring += f - last_arg;
1989 *current_substring++ = '\0';
1991 argclass[nargs_wanted++] = this_argclass;
1994 /* Now, parse all arguments and evaluate them.
1995 Store the VALUEs in VAL_ARGS. */
2000 if (nargs == allocated_args)
2001 val_args = (struct value **) xrealloc ((char *) val_args,
2002 (allocated_args *= 2)
2003 * sizeof (struct value *));
2005 val_args[nargs] = parse_to_comma_and_eval (&s1);
2007 /* If format string wants a float, unchecked-convert the value to
2008 floating point of the same size */
2010 if (argclass[nargs] == double_arg)
2012 struct type *type = value_type (val_args[nargs]);
2013 if (TYPE_LENGTH (type) == sizeof (float))
2014 deprecated_set_value_type (val_args[nargs], builtin_type_float);
2015 if (TYPE_LENGTH (type) == sizeof (double))
2016 deprecated_set_value_type (val_args[nargs], builtin_type_double);
2024 if (nargs != nargs_wanted)
2025 error (_("Wrong number of arguments for specified format-string"));
2027 /* Now actually print them. */
2028 current_substring = substrings;
2029 for (i = 0; i < nargs; i++)
2031 switch (argclass[i])
2038 tem = value_as_address (val_args[i]);
2040 /* This is a %s argument. Find the length of the string. */
2045 read_memory (tem + j, &c, 1);
2050 /* Copy the string contents into a string inside GDB. */
2051 str = (gdb_byte *) alloca (j + 1);
2053 read_memory (tem, str, j);
2056 printf_filtered (current_substring, (char *) str);
2061 double val = value_as_double (val_args[i]);
2062 printf_filtered (current_substring, val);
2065 case long_double_arg:
2066 #ifdef HAVE_LONG_DOUBLE
2068 long double val = value_as_double (val_args[i]);
2069 printf_filtered (current_substring, val);
2073 error (_("long double not supported in printf"));
2076 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2078 long long val = value_as_long (val_args[i]);
2079 printf_filtered (current_substring, val);
2083 error (_("long long not supported in printf"));
2087 int val = value_as_long (val_args[i]);
2088 printf_filtered (current_substring, val);
2093 long val = value_as_long (val_args[i]);
2094 printf_filtered (current_substring, val);
2099 /* We avoid the host's %p because pointers are too
2100 likely to be the wrong size. The only interesting
2101 modifier for %p is a width; extract that, and then
2102 handle %p as glibc would: %#x or a literal "(nil)". */
2104 char *p, *fmt, *fmt_p;
2105 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2106 long long val = value_as_long (val_args[i]);
2108 long val = value_as_long (val_args[i]);
2111 fmt = alloca (strlen (current_substring) + 5);
2113 /* Copy up to the leading %. */
2114 p = current_substring;
2118 int is_percent = (*p == '%');
2132 /* Copy any width. */
2133 while (*p >= '0' && *p < '9')
2136 gdb_assert (*p == 'p' && *(p + 1) == '\0');
2139 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2145 printf_filtered (fmt, val);
2151 printf_filtered (fmt, "(nil)");
2157 internal_error (__FILE__, __LINE__,
2158 _("failed internal consistency check"));
2160 /* Skip to the next substring. */
2161 current_substring += strlen (current_substring) + 1;
2163 /* Print the portion of the format string after the last argument. */
2164 puts_filtered (last_arg);
2166 do_cleanups (old_cleanups);
2170 _initialize_printcmd (void)
2172 struct cmd_list_element *c;
2174 current_display_number = -1;
2176 add_info ("address", address_info,
2177 _("Describe where symbol SYM is stored."));
2179 add_info ("symbol", sym_info, _("\
2180 Describe what symbol is at location ADDR.\n\
2181 Only for symbols with fixed locations (global or static scope)."));
2183 add_com ("x", class_vars, x_command, _("\
2184 Examine memory: x/FMT ADDRESS.\n\
2185 ADDRESS is an expression for the memory address to examine.\n\
2186 FMT is a repeat count followed by a format letter and a size letter.\n\
2187 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2188 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2189 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2190 The specified number of objects of the specified size are printed\n\
2191 according to the format.\n\n\
2192 Defaults for format and size letters are those previously used.\n\
2193 Default count is 1. Default address is following last thing printed\n\
2194 with this command or \"print\"."));
2197 add_com ("whereis", class_vars, whereis_command,
2198 _("Print line number and file of definition of variable."));
2201 add_info ("display", display_info, _("\
2202 Expressions to display when program stops, with code numbers."));
2204 add_cmd ("undisplay", class_vars, undisplay_command, _("\
2205 Cancel some expressions to be displayed when program stops.\n\
2206 Arguments are the code numbers of the expressions to stop displaying.\n\
2207 No argument means cancel all automatic-display expressions.\n\
2208 \"delete display\" has the same effect as this command.\n\
2209 Do \"info display\" to see current list of code numbers."),
2212 add_com ("display", class_vars, display_command, _("\
2213 Print value of expression EXP each time the program stops.\n\
2214 /FMT may be used before EXP as in the \"print\" command.\n\
2215 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2216 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2217 and examining is done as in the \"x\" command.\n\n\
2218 With no argument, display all currently requested auto-display expressions.\n\
2219 Use \"undisplay\" to cancel display requests previously made."));
2221 add_cmd ("display", class_vars, enable_display, _("\
2222 Enable some expressions to be displayed when program stops.\n\
2223 Arguments are the code numbers of the expressions to resume displaying.\n\
2224 No argument means enable all automatic-display expressions.\n\
2225 Do \"info display\" to see current list of code numbers."), &enablelist);
2227 add_cmd ("display", class_vars, disable_display_command, _("\
2228 Disable some expressions to be displayed when program stops.\n\
2229 Arguments are the code numbers of the expressions to stop displaying.\n\
2230 No argument means disable all automatic-display expressions.\n\
2231 Do \"info display\" to see current list of code numbers."), &disablelist);
2233 add_cmd ("display", class_vars, undisplay_command, _("\
2234 Cancel some expressions to be displayed when program stops.\n\
2235 Arguments are the code numbers of the expressions to stop displaying.\n\
2236 No argument means cancel all automatic-display expressions.\n\
2237 Do \"info display\" to see current list of code numbers."), &deletelist);
2239 add_com ("printf", class_vars, printf_command, _("\
2240 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2241 This is useful for formatted output in user-defined commands."));
2243 add_com ("output", class_vars, output_command, _("\
2244 Like \"print\" but don't put in value history and don't print newline.\n\
2245 This is useful in user-defined commands."));
2247 add_prefix_cmd ("set", class_vars, set_command, _("\
2248 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2249 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2250 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2251 with $), a register (a few standard names starting with $), or an actual\n\
2252 variable in the program being debugged. EXP is any valid expression.\n\
2253 Use \"set variable\" for variables with names identical to set subcommands.\n\
2255 With a subcommand, this command modifies parts of the gdb environment.\n\
2256 You can see these environment settings with the \"show\" command."),
2257 &setlist, "set ", 1, &cmdlist);
2259 add_com ("assign", class_vars, set_command, _("\
2260 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2261 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2262 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2263 with $), a register (a few standard names starting with $), or an actual\n\
2264 variable in the program being debugged. EXP is any valid expression.\n\
2265 Use \"set variable\" for variables with names identical to set subcommands.\n\
2266 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2267 You can see these environment settings with the \"show\" command."));
2269 /* "call" is the same as "set", but handy for dbx users to call fns. */
2270 c = add_com ("call", class_vars, call_command, _("\
2271 Call a function in the program.\n\
2272 The argument is the function name and arguments, in the notation of the\n\
2273 current working language. The result is printed and saved in the value\n\
2274 history, if it is not void."));
2275 set_cmd_completer (c, location_completer);
2277 add_cmd ("variable", class_vars, set_command, _("\
2278 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2279 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2280 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2281 with $), a register (a few standard names starting with $), or an actual\n\
2282 variable in the program being debugged. EXP is any valid expression.\n\
2283 This may usually be abbreviated to simply \"set\"."),
2286 c = add_com ("print", class_vars, print_command, _("\
2287 Print value of expression EXP.\n\
2288 Variables accessible are those of the lexical environment of the selected\n\
2289 stack frame, plus all those whose scope is global or an entire file.\n\
2291 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2292 $$NUM refers to NUM'th value back from the last one.\n\
2293 Names starting with $ refer to registers (with the values they would have\n\
2294 if the program were to return to the stack frame now selected, restoring\n\
2295 all registers saved by frames farther in) or else to debugger\n\
2296 \"convenience\" variables (any such name not a known register).\n\
2297 Use assignment expressions to give values to convenience variables.\n\
2299 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2300 @ is a binary operator for treating consecutive data objects\n\
2301 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2302 element is FOO, whose second element is stored in the space following\n\
2303 where FOO is stored, etc. FOO must be an expression whose value\n\
2304 resides in memory.\n\
2306 EXP may be preceded with /FMT, where FMT is a format letter\n\
2307 but no count or size letter (see \"x\" command)."));
2308 set_cmd_completer (c, location_completer);
2309 add_com_alias ("p", "print", class_vars, 1);
2311 c = add_com ("inspect", class_vars, inspect_command, _("\
2312 Same as \"print\" command, except that if you are running in the epoch\n\
2313 environment, the value is printed in its own window."));
2314 set_cmd_completer (c, location_completer);
2316 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
2317 &max_symbolic_offset, _("\
2318 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2319 Show the largest offset that will be printed in <symbol+1234> form."), NULL,
2321 show_max_symbolic_offset,
2322 &setprintlist, &showprintlist);
2323 add_setshow_boolean_cmd ("symbol-filename", no_class,
2324 &print_symbol_filename, _("\
2325 Set printing of source filename and line number with <symbol>."), _("\
2326 Show printing of source filename and line number with <symbol>."), NULL,
2328 show_print_symbol_filename,
2329 &setprintlist, &showprintlist);
2331 /* For examine/instruction a single byte quantity is specified as
2332 the data. This avoids problems with value_at_lazy() requiring a
2333 valid data type (and rejecting VOID). */
2334 examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
2336 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2337 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2338 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2339 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);