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"
47 #include "tui/tui.h" /* For tui_active et.al. */
50 extern int asm_demangle; /* Whether to demangle syms in asm printouts */
51 extern int addressprint; /* Whether to print hex addresses in HLL " */
60 /* Last specified output format. */
62 static char last_format = 'x';
64 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
66 static char last_size = 'w';
68 /* Default address to examine next. */
70 static CORE_ADDR next_address;
72 /* Number of delay instructions following current disassembled insn. */
74 static int branch_delay_insns;
76 /* Last address examined. */
78 static CORE_ADDR last_examine_address;
80 /* Contents of last address examined.
81 This is not valid past the end of the `x' command! */
83 static struct value *last_examine_value;
85 /* Largest offset between a symbolic value and an address, that will be
86 printed as `0x1234 <symbol+offset>'. */
88 static unsigned int max_symbolic_offset = UINT_MAX;
90 show_max_symbolic_offset (struct ui_file *file, int from_tty,
91 struct cmd_list_element *c, const char *value)
93 fprintf_filtered (file, _("\
94 The largest offset that will be printed in <symbol+1234> form is %s.\n"),
98 /* Append the source filename and linenumber of the symbol when
99 printing a symbolic value as `<symbol at filename:linenum>' if set. */
100 static int print_symbol_filename = 0;
102 show_print_symbol_filename (struct ui_file *file, int from_tty,
103 struct cmd_list_element *c, const char *value)
105 fprintf_filtered (file, _("\
106 Printing of source filename and line number with <symbol> is %s.\n"),
110 /* Number of auto-display expression currently being displayed.
111 So that we can disable it if we get an error or a signal within it.
112 -1 when not doing one. */
114 int current_display_number;
116 /* Flag to low-level print routines that this value is being printed
117 in an epoch window. We'd like to pass this as a parameter, but
118 every routine would need to take it. Perhaps we can encapsulate
119 this in the I/O stream once we have GNU stdio. */
125 /* Chain link to next auto-display item. */
126 struct display *next;
127 /* Expression to be evaluated and displayed. */
128 struct expression *exp;
129 /* Item number of this auto-display item. */
131 /* Display format specified. */
132 struct format_data format;
133 /* Innermost block required by this expression when evaluated */
135 /* Status of this display (enabled or disabled) */
139 /* Chain of expressions whose values should be displayed
140 automatically each time the program stops. */
142 static struct display *display_chain;
144 static int display_number;
146 /* Prototypes for exported functions. */
148 void output_command (char *, int);
150 void _initialize_printcmd (void);
152 /* Prototypes for local functions. */
154 static void do_one_display (struct display *);
157 /* Decode a format specification. *STRING_PTR should point to it.
158 OFORMAT and OSIZE are used as defaults for the format and size
159 if none are given in the format specification.
160 If OSIZE is zero, then the size field of the returned value
161 should be set only if a size is explicitly specified by the
163 The structure returned describes all the data
164 found in the specification. In addition, *STRING_PTR is advanced
165 past the specification and past all whitespace following it. */
167 static struct format_data
168 decode_format (char **string_ptr, int oformat, int osize)
170 struct format_data val;
171 char *p = *string_ptr;
177 if (*p >= '0' && *p <= '9')
178 val.count = atoi (p);
179 while (*p >= '0' && *p <= '9')
182 /* Now process size or format letters that follow. */
186 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
188 else if (*p >= 'a' && *p <= 'z')
194 while (*p == ' ' || *p == '\t')
198 /* Set defaults for format and size if not specified. */
199 if (val.format == '?')
203 /* Neither has been specified. */
204 val.format = oformat;
208 /* If a size is specified, any format makes a reasonable
209 default except 'i'. */
210 val.format = oformat == 'i' ? 'x' : oformat;
212 else if (val.size == '?')
217 /* Pick the appropriate size for an address. */
218 if (gdbarch_ptr_bit (current_gdbarch) == 64)
219 val.size = osize ? 'g' : osize;
220 else if (gdbarch_ptr_bit (current_gdbarch) == 32)
221 val.size = osize ? 'w' : osize;
222 else if (gdbarch_ptr_bit (current_gdbarch) == 16)
223 val.size = osize ? 'h' : osize;
225 /* Bad value for gdbarch_ptr_bit. */
226 internal_error (__FILE__, __LINE__,
227 _("failed internal consistency check"));
230 /* Floating point has to be word or giantword. */
231 if (osize == 'w' || osize == 'g')
234 /* Default it to giantword if the last used size is not
236 val.size = osize ? 'g' : osize;
239 /* Characters default to one byte. */
240 val.size = osize ? 'b' : osize;
243 /* The default is the size most recently specified. */
250 /* Print value VAL on stream according to FORMAT, a letter or 0.
251 Do not end with a newline.
252 0 means print VAL according to its own type.
253 SIZE is the letter for the size of datum being printed.
254 This is used to pad hex numbers so they line up. SIZE is 0
255 for print / output and set for examine. */
258 print_formatted (struct value *val, int format, int size,
259 struct ui_file *stream)
261 struct type *type = check_typedef (value_type (val));
262 int len = TYPE_LENGTH (type);
264 if (VALUE_LVAL (val) == lval_memory)
265 next_address = VALUE_ADDRESS (val) + len;
272 /* FIXME: Need to handle wchar_t's here... */
273 next_address = VALUE_ADDRESS (val)
274 + val_print_string (VALUE_ADDRESS (val), -1, 1, stream);
278 /* We often wrap here if there are long symbolic names. */
280 next_address = (VALUE_ADDRESS (val)
281 + gdb_print_insn (VALUE_ADDRESS (val), stream,
282 &branch_delay_insns));
287 if (format == 0 || format == 's'
288 || TYPE_CODE (type) == TYPE_CODE_ARRAY
289 || TYPE_CODE (type) == TYPE_CODE_STRING
290 || TYPE_CODE (type) == TYPE_CODE_STRUCT
291 || TYPE_CODE (type) == TYPE_CODE_UNION
292 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
293 /* If format is 0, use the 'natural' format for that type of
294 value. If the type is non-scalar, we have to use language
295 rules to print it as a series of scalars. */
296 value_print (val, stream, format, Val_pretty_default);
298 /* User specified format, so don't look to the the type to
299 tell us what to do. */
300 print_scalar_formatted (value_contents (val), type,
301 format, size, stream);
304 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
305 according to letters FORMAT and SIZE on STREAM.
306 FORMAT may not be zero. Formats s and i are not supported at this level.
308 This is how the elements of an array or structure are printed
312 print_scalar_formatted (const void *valaddr, struct type *type,
313 int format, int size, struct ui_file *stream)
315 LONGEST val_long = 0;
316 unsigned int len = TYPE_LENGTH (type);
318 /* If we get here with a string format, try again without it. Go
319 all the way back to the language printers, which may call us
323 val_print (type, valaddr, 0, 0, stream, 0, 0, 0, Val_pretty_default);
327 if (len > sizeof(LONGEST) &&
328 (TYPE_CODE (type) == TYPE_CODE_INT
329 || TYPE_CODE (type) == TYPE_CODE_ENUM))
334 print_octal_chars (stream, valaddr, len);
338 print_decimal_chars (stream, valaddr, len);
341 print_binary_chars (stream, valaddr, len);
344 print_hex_chars (stream, valaddr, len);
347 print_char_chars (stream, valaddr, len);
355 val_long = unpack_long (type, valaddr);
357 /* If the value is a pointer, and pointers and addresses are not the
358 same, then at this point, the value's length (in target bytes) is
359 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
360 if (TYPE_CODE (type) == TYPE_CODE_PTR)
361 len = gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT;
363 /* If we are printing it as unsigned, truncate it in case it is actually
364 a negative signed value (e.g. "print/u (short)-1" should print 65535
365 (if shorts are 16 bits) instead of 4294967295). */
368 if (len < sizeof (LONGEST))
369 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
377 /* No size specified, like in print. Print varying # of digits. */
378 print_longest (stream, 'x', 1, val_long);
387 print_longest (stream, size, 1, val_long);
390 error (_("Undefined output size \"%c\"."), size);
395 print_longest (stream, 'd', 1, val_long);
399 print_longest (stream, 'u', 0, val_long);
404 print_longest (stream, 'o', 1, val_long);
406 fprintf_filtered (stream, "0");
411 CORE_ADDR addr = unpack_pointer (type, valaddr);
412 print_address (addr, stream);
417 if (TYPE_UNSIGNED (type))
421 utype = builtin_type (current_gdbarch)->builtin_true_unsigned_char;
422 value_print (value_from_longest (utype, val_long),
423 stream, 0, Val_pretty_default);
426 value_print (value_from_longest (builtin_type_true_char, val_long),
427 stream, 0, Val_pretty_default);
431 if (len == TYPE_LENGTH (builtin_type_float))
432 type = builtin_type_float;
433 else if (len == TYPE_LENGTH (builtin_type_double))
434 type = builtin_type_double;
435 else if (len == TYPE_LENGTH (builtin_type_long_double))
436 type = builtin_type_long_double;
437 print_floating (valaddr, type, stream);
441 internal_error (__FILE__, __LINE__,
442 _("failed internal consistency check"));
445 /* Binary; 't' stands for "two". */
447 char bits[8 * (sizeof val_long) + 1];
448 char buf[8 * (sizeof val_long) + 32];
453 width = 8 * (sizeof val_long);
470 error (_("Undefined output size \"%c\"."), size);
476 bits[width] = (val_long & 1) ? '1' : '0';
481 while (*cp && *cp == '0')
487 fputs_filtered (buf, stream);
492 error (_("Undefined output format \"%c\"."), format);
496 /* Specify default address for `x' command.
497 The `info lines' command uses this. */
500 set_next_address (CORE_ADDR addr)
504 /* Make address available to the user as $_. */
505 set_internalvar (lookup_internalvar ("_"),
506 value_from_pointer (lookup_pointer_type (builtin_type_void),
510 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
511 after LEADIN. Print nothing if no symbolic name is found nearby.
512 Optionally also print source file and line number, if available.
513 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
514 or to interpret it as a possible C++ name and convert it back to source
515 form. However note that DO_DEMANGLE can be overridden by the specific
516 settings of the demangle and asm_demangle variables. */
519 print_address_symbolic (CORE_ADDR addr, struct ui_file *stream,
520 int do_demangle, char *leadin)
523 char *filename = NULL;
528 /* Throw away both name and filename. */
529 struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
530 make_cleanup (free_current_contents, &filename);
532 if (build_address_symbolic (addr, do_demangle, &name, &offset,
533 &filename, &line, &unmapped))
535 do_cleanups (cleanup_chain);
539 fputs_filtered (leadin, stream);
541 fputs_filtered ("<*", stream);
543 fputs_filtered ("<", stream);
544 fputs_filtered (name, stream);
546 fprintf_filtered (stream, "+%u", (unsigned int) offset);
548 /* Append source filename and line number if desired. Give specific
549 line # of this addr, if we have it; else line # of the nearest symbol. */
550 if (print_symbol_filename && filename != NULL)
553 fprintf_filtered (stream, " at %s:%d", filename, line);
555 fprintf_filtered (stream, " in %s", filename);
558 fputs_filtered ("*>", stream);
560 fputs_filtered (">", stream);
562 do_cleanups (cleanup_chain);
565 /* Given an address ADDR return all the elements needed to print the
566 address in a symbolic form. NAME can be mangled or not depending
567 on DO_DEMANGLE (and also on the asm_demangle global variable,
568 manipulated via ''set print asm-demangle''). Return 0 in case of
569 success, when all the info in the OUT paramters is valid. Return 1
572 build_address_symbolic (CORE_ADDR addr, /* IN */
573 int do_demangle, /* IN */
574 char **name, /* OUT */
575 int *offset, /* OUT */
576 char **filename, /* OUT */
578 int *unmapped) /* OUT */
580 struct minimal_symbol *msymbol;
581 struct symbol *symbol;
582 CORE_ADDR name_location = 0;
583 asection *section = 0;
584 char *name_temp = "";
586 /* Let's say it is unmapped. */
589 /* Determine if the address is in an overlay, and whether it is
591 if (overlay_debugging)
593 section = find_pc_overlay (addr);
594 if (pc_in_unmapped_range (addr, section))
597 addr = overlay_mapped_address (addr, section);
601 /* First try to find the address in the symbol table, then
602 in the minsyms. Take the closest one. */
604 /* This is defective in the sense that it only finds text symbols. So
605 really this is kind of pointless--we should make sure that the
606 minimal symbols have everything we need (by changing that we could
607 save some memory, but for many debug format--ELF/DWARF or
608 anything/stabs--it would be inconvenient to eliminate those minimal
610 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
611 symbol = find_pc_sect_function (addr, section);
615 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
616 if (do_demangle || asm_demangle)
617 name_temp = SYMBOL_PRINT_NAME (symbol);
619 name_temp = DEPRECATED_SYMBOL_NAME (symbol);
624 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
626 /* The msymbol is closer to the address than the symbol;
627 use the msymbol instead. */
629 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
630 if (do_demangle || asm_demangle)
631 name_temp = SYMBOL_PRINT_NAME (msymbol);
633 name_temp = DEPRECATED_SYMBOL_NAME (msymbol);
636 if (symbol == NULL && msymbol == NULL)
639 /* If the nearest symbol is too far away, don't print anything symbolic. */
641 /* For when CORE_ADDR is larger than unsigned int, we do math in
642 CORE_ADDR. But when we detect unsigned wraparound in the
643 CORE_ADDR math, we ignore this test and print the offset,
644 because addr+max_symbolic_offset has wrapped through the end
645 of the address space back to the beginning, giving bogus comparison. */
646 if (addr > name_location + max_symbolic_offset
647 && name_location + max_symbolic_offset > name_location)
650 *offset = addr - name_location;
652 *name = xstrdup (name_temp);
654 if (print_symbol_filename)
656 struct symtab_and_line sal;
658 sal = find_pc_sect_line (addr, section, 0);
662 *filename = xstrdup (sal.symtab->filename);
669 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
672 deprecated_print_address_numeric (CORE_ADDR addr, int use_local,
673 struct ui_file *stream)
676 fputs_filtered (paddress (addr), stream);
679 int addr_bit = gdbarch_addr_bit (current_gdbarch);
681 if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
682 addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
683 print_longest (stream, 'x', 0, (ULONGEST) addr);
687 /* Print address ADDR symbolically on STREAM.
688 First print it as a number. Then perhaps print
689 <SYMBOL + OFFSET> after the number. */
692 print_address (CORE_ADDR addr, struct ui_file *stream)
694 deprecated_print_address_numeric (addr, 1, stream);
695 print_address_symbolic (addr, stream, asm_demangle, " ");
698 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
699 controls whether to print the symbolic name "raw" or demangled.
700 Global setting "addressprint" controls whether to print hex address
704 print_address_demangle (CORE_ADDR addr, struct ui_file *stream,
709 fprintf_filtered (stream, "0");
711 else if (addressprint)
713 deprecated_print_address_numeric (addr, 1, stream);
714 print_address_symbolic (addr, stream, do_demangle, " ");
718 print_address_symbolic (addr, stream, do_demangle, "");
723 /* These are the types that $__ will get after an examine command of one
726 static struct type *examine_i_type;
728 static struct type *examine_b_type;
729 static struct type *examine_h_type;
730 static struct type *examine_w_type;
731 static struct type *examine_g_type;
733 /* Examine data at address ADDR in format FMT.
734 Fetch it from memory and print on gdb_stdout. */
737 do_examine (struct format_data fmt, CORE_ADDR addr)
742 struct type *val_type = NULL;
751 /* String or instruction format implies fetch single bytes
752 regardless of the specified size. */
753 if (format == 's' || format == 'i')
757 val_type = examine_i_type;
758 else if (size == 'b')
759 val_type = examine_b_type;
760 else if (size == 'h')
761 val_type = examine_h_type;
762 else if (size == 'w')
763 val_type = examine_w_type;
764 else if (size == 'g')
765 val_type = examine_g_type;
772 if (format == 's' || format == 'i')
775 /* Print as many objects as specified in COUNT, at most maxelts per line,
776 with the address of the next one at the start of each line. */
781 print_address (next_address, gdb_stdout);
782 printf_filtered (":");
787 printf_filtered ("\t");
788 /* Note that print_formatted sets next_address for the next
790 last_examine_address = next_address;
792 if (last_examine_value)
793 value_free (last_examine_value);
795 /* The value to be displayed is not fetched greedily.
796 Instead, to avoid the possibility of a fetched value not
797 being used, its retrieval is delayed until the print code
798 uses it. When examining an instruction stream, the
799 disassembler will perform its own memory fetch using just
800 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
801 the disassembler be modified so that LAST_EXAMINE_VALUE
802 is left with the byte sequence from the last complete
803 instruction fetched from memory? */
804 last_examine_value = value_at_lazy (val_type, next_address);
806 if (last_examine_value)
807 release_value (last_examine_value);
809 print_formatted (last_examine_value, format, size, gdb_stdout);
811 /* Display any branch delay slots following the final insn. */
812 if (format == 'i' && count == 1)
813 count += branch_delay_insns;
815 printf_filtered ("\n");
816 gdb_flush (gdb_stdout);
821 validate_format (struct format_data fmt, char *cmdname)
824 error (_("Size letters are meaningless in \"%s\" command."), cmdname);
826 error (_("Item count other than 1 is meaningless in \"%s\" command."),
828 if (fmt.format == 'i')
829 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
830 fmt.format, cmdname);
833 /* Evaluate string EXP as an expression in the current language and
834 print the resulting value. EXP may contain a format specifier as the
835 first argument ("/x myvar" for example, to print myvar in hex). */
838 print_command_1 (char *exp, int inspect, int voidprint)
840 struct expression *expr;
841 struct cleanup *old_chain = 0;
844 struct format_data fmt;
847 /* Pass inspect flag to the rest of the print routines in a global
849 inspect_it = inspect;
851 if (exp && *exp == '/')
854 fmt = decode_format (&exp, last_format, 0);
855 validate_format (fmt, "print");
856 last_format = format = fmt.format;
868 expr = parse_expression (exp);
869 old_chain = make_cleanup (free_current_contents, &expr);
871 val = evaluate_expression (expr);
874 val = access_value_history (0);
876 if (voidprint || (val && value_type (val) &&
877 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
879 int histindex = record_latest_value (val);
882 annotate_value_history_begin (histindex, value_type (val));
884 annotate_value_begin (value_type (val));
887 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"",
889 else if (histindex >= 0)
890 printf_filtered ("$%d = ", histindex);
893 annotate_value_history_value ();
895 print_formatted (val, format, fmt.size, gdb_stdout);
896 printf_filtered ("\n");
899 annotate_value_history_end ();
901 annotate_value_end ();
904 printf_unfiltered ("\") )\030");
908 do_cleanups (old_chain);
909 inspect_it = 0; /* Reset print routines to normal. */
913 print_command (char *exp, int from_tty)
915 print_command_1 (exp, 0, 1);
918 /* Same as print, except in epoch, it gets its own window. */
920 inspect_command (char *exp, int from_tty)
922 extern int epoch_interface;
924 print_command_1 (exp, epoch_interface, 1);
927 /* Same as print, except it doesn't print void results. */
929 call_command (char *exp, int from_tty)
931 print_command_1 (exp, 0, 0);
935 output_command (char *exp, int from_tty)
937 struct expression *expr;
938 struct cleanup *old_chain;
941 struct format_data fmt;
945 if (exp && *exp == '/')
948 fmt = decode_format (&exp, 0, 0);
949 validate_format (fmt, "output");
953 expr = parse_expression (exp);
954 old_chain = make_cleanup (free_current_contents, &expr);
956 val = evaluate_expression (expr);
958 annotate_value_begin (value_type (val));
960 print_formatted (val, format, fmt.size, gdb_stdout);
962 annotate_value_end ();
965 gdb_flush (gdb_stdout);
967 do_cleanups (old_chain);
971 set_command (char *exp, int from_tty)
973 struct expression *expr = parse_expression (exp);
974 struct cleanup *old_chain =
975 make_cleanup (free_current_contents, &expr);
976 evaluate_expression (expr);
977 do_cleanups (old_chain);
981 sym_info (char *arg, int from_tty)
983 struct minimal_symbol *msymbol;
984 struct objfile *objfile;
985 struct obj_section *osect;
987 CORE_ADDR addr, sect_addr;
992 error_no_arg (_("address"));
994 addr = parse_and_eval_address (arg);
995 ALL_OBJSECTIONS (objfile, osect)
997 /* Only process each object file once, even if there's a separate
999 if (objfile->separate_debug_objfile_backlink)
1002 sect = osect->the_bfd_section;
1003 sect_addr = overlay_mapped_address (addr, sect);
1005 if (osect->addr <= sect_addr && sect_addr < osect->endaddr &&
1006 (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect)))
1009 offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
1011 printf_filtered ("%s + %u in ",
1012 SYMBOL_PRINT_NAME (msymbol), offset);
1014 printf_filtered ("%s in ",
1015 SYMBOL_PRINT_NAME (msymbol));
1016 if (pc_in_unmapped_range (addr, sect))
1017 printf_filtered (_("load address range of "));
1018 if (section_is_overlay (sect))
1019 printf_filtered (_("%s overlay "),
1020 section_is_mapped (sect) ? "mapped" : "unmapped");
1021 printf_filtered (_("section %s"), sect->name);
1022 printf_filtered ("\n");
1026 printf_filtered (_("No symbol matches %s.\n"), arg);
1030 address_info (char *exp, int from_tty)
1033 struct minimal_symbol *msymbol;
1037 CORE_ADDR load_addr;
1038 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
1039 if exp is a field of `this'. */
1042 error (_("Argument required."));
1044 sym = lookup_symbol (exp, get_selected_block (0), VAR_DOMAIN,
1045 &is_a_field_of_this, (struct symtab **) NULL);
1048 if (is_a_field_of_this)
1050 printf_filtered ("Symbol \"");
1051 fprintf_symbol_filtered (gdb_stdout, exp,
1052 current_language->la_language, DMGL_ANSI);
1053 printf_filtered ("\" is a field of the local class variable ");
1054 if (current_language->la_language == language_objc)
1055 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1057 printf_filtered ("`this'\n");
1061 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1063 if (msymbol != NULL)
1065 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1067 printf_filtered ("Symbol \"");
1068 fprintf_symbol_filtered (gdb_stdout, exp,
1069 current_language->la_language, DMGL_ANSI);
1070 printf_filtered ("\" is at ");
1071 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1072 printf_filtered (" in a file compiled without debugging");
1073 section = SYMBOL_BFD_SECTION (msymbol);
1074 if (section_is_overlay (section))
1076 load_addr = overlay_unmapped_address (load_addr, section);
1077 printf_filtered (",\n -- loaded at ");
1078 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1079 printf_filtered (" in overlay section %s", section->name);
1081 printf_filtered (".\n");
1084 error (_("No symbol \"%s\" in current context."), exp);
1088 printf_filtered ("Symbol \"");
1089 fprintf_symbol_filtered (gdb_stdout, DEPRECATED_SYMBOL_NAME (sym),
1090 current_language->la_language, DMGL_ANSI);
1091 printf_filtered ("\" is ");
1092 val = SYMBOL_VALUE (sym);
1093 basereg = SYMBOL_BASEREG (sym);
1094 section = SYMBOL_BFD_SECTION (sym);
1096 switch (SYMBOL_CLASS (sym))
1099 case LOC_CONST_BYTES:
1100 printf_filtered ("constant");
1104 printf_filtered ("a label at address ");
1105 deprecated_print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1107 if (section_is_overlay (section))
1109 load_addr = overlay_unmapped_address (load_addr, section);
1110 printf_filtered (",\n -- loaded at ");
1111 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1112 printf_filtered (" in overlay section %s", section->name);
1117 case LOC_COMPUTED_ARG:
1118 /* FIXME: cagney/2004-01-26: It should be possible to
1119 unconditionally call the SYMBOL_OPS method when available.
1120 Unfortunately DWARF 2 stores the frame-base (instead of the
1121 function) location in a function's symbol. Oops! For the
1122 moment enable this when/where applicable. */
1123 SYMBOL_OPS (sym)->describe_location (sym, gdb_stdout);
1127 printf_filtered (_("a variable in register %s"),
1128 gdbarch_register_name (current_gdbarch, val));
1132 printf_filtered (_("static storage at address "));
1133 deprecated_print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1135 if (section_is_overlay (section))
1137 load_addr = overlay_unmapped_address (load_addr, section);
1138 printf_filtered (_(",\n -- loaded at "));
1139 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1140 printf_filtered (_(" in overlay section %s"), section->name);
1145 printf_filtered (_("external global (indirect addressing), at address *("));
1146 deprecated_print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1148 printf_filtered (")");
1149 if (section_is_overlay (section))
1151 load_addr = overlay_unmapped_address (load_addr, section);
1152 printf_filtered (_(",\n -- loaded at "));
1153 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1154 printf_filtered (_(" in overlay section %s"), section->name);
1159 printf_filtered (_("an argument in register %s"),
1160 gdbarch_register_name (current_gdbarch, val));
1163 case LOC_REGPARM_ADDR:
1164 printf_filtered (_("address of an argument in register %s"),
1165 gdbarch_register_name (current_gdbarch, val));
1169 printf_filtered (_("an argument at offset %ld"), val);
1173 printf_filtered (_("an argument at frame offset %ld"), val);
1177 printf_filtered (_("a local variable at frame offset %ld"), val);
1181 printf_filtered (_("a reference argument at offset %ld"), val);
1185 printf_filtered (_("a variable at offset %ld from register %s"),
1186 val, gdbarch_register_name (current_gdbarch, basereg));
1189 case LOC_BASEREG_ARG:
1190 printf_filtered (_("an argument at offset %ld from register %s"),
1191 val, gdbarch_register_name (current_gdbarch, basereg));
1195 printf_filtered (_("a typedef"));
1199 printf_filtered (_("a function at address "));
1200 load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1201 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1202 if (section_is_overlay (section))
1204 load_addr = overlay_unmapped_address (load_addr, section);
1205 printf_filtered (_(",\n -- loaded at "));
1206 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1207 printf_filtered (_(" in overlay section %s"), section->name);
1211 case LOC_UNRESOLVED:
1213 struct minimal_symbol *msym;
1215 msym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym), NULL, NULL);
1217 printf_filtered ("unresolved");
1220 section = SYMBOL_BFD_SECTION (msym);
1221 printf_filtered (_("static storage at address "));
1222 load_addr = SYMBOL_VALUE_ADDRESS (msym);
1223 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1224 if (section_is_overlay (section))
1226 load_addr = overlay_unmapped_address (load_addr, section);
1227 printf_filtered (_(",\n -- loaded at "));
1228 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
1229 printf_filtered (_(" in overlay section %s"), section->name);
1235 case LOC_HP_THREAD_LOCAL_STATIC:
1236 printf_filtered (_("\
1237 a thread-local variable at offset %ld from the thread base register %s"),
1238 val, gdbarch_register_name (current_gdbarch, basereg));
1241 case LOC_OPTIMIZED_OUT:
1242 printf_filtered (_("optimized out"));
1246 printf_filtered (_("of unknown (botched) type"));
1249 printf_filtered (".\n");
1254 x_command (char *exp, int from_tty)
1256 struct expression *expr;
1257 struct format_data fmt;
1258 struct cleanup *old_chain;
1261 fmt.format = last_format;
1262 fmt.size = last_size;
1265 if (exp && *exp == '/')
1268 fmt = decode_format (&exp, last_format, last_size);
1271 /* If we have an expression, evaluate it and use it as the address. */
1273 if (exp != 0 && *exp != 0)
1275 expr = parse_expression (exp);
1276 /* Cause expression not to be there any more if this command is
1277 repeated with Newline. But don't clobber a user-defined
1278 command's definition. */
1281 old_chain = make_cleanup (free_current_contents, &expr);
1282 val = evaluate_expression (expr);
1283 if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
1284 val = value_ind (val);
1285 /* In rvalue contexts, such as this, functions are coerced into
1286 pointers to functions. This makes "x/i main" work. */
1287 if (/* last_format == 'i' && */
1288 TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
1289 && VALUE_LVAL (val) == lval_memory)
1290 next_address = VALUE_ADDRESS (val);
1292 next_address = value_as_address (val);
1293 do_cleanups (old_chain);
1296 do_examine (fmt, next_address);
1298 /* If the examine succeeds, we remember its size and format for next
1300 last_size = fmt.size;
1301 last_format = fmt.format;
1303 /* Set a couple of internal variables if appropriate. */
1304 if (last_examine_value)
1306 /* Make last address examined available to the user as $_. Use
1307 the correct pointer type. */
1308 struct type *pointer_type
1309 = lookup_pointer_type (value_type (last_examine_value));
1310 set_internalvar (lookup_internalvar ("_"),
1311 value_from_pointer (pointer_type,
1312 last_examine_address));
1314 /* Make contents of last address examined available to the user
1315 as $__. If the last value has not been fetched from memory
1316 then don't fetch it now; instead mark it by voiding the $__
1318 if (value_lazy (last_examine_value))
1319 set_internalvar (lookup_internalvar ("__"),
1320 allocate_value (builtin_type_void));
1322 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1327 /* Add an expression to the auto-display chain.
1328 Specify the expression. */
1331 display_command (char *exp, int from_tty)
1333 struct format_data fmt;
1334 struct expression *expr;
1335 struct display *new;
1339 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1341 if (tui_active && exp != NULL && *exp == '$')
1342 display_it = (tui_set_layout_for_display_command (exp) == TUI_FAILURE);
1356 fmt = decode_format (&exp, 0, 0);
1357 if (fmt.size && fmt.format == 0)
1359 if (fmt.format == 'i' || fmt.format == 's')
1369 innermost_block = 0;
1370 expr = parse_expression (exp);
1372 new = (struct display *) xmalloc (sizeof (struct display));
1375 new->block = innermost_block;
1376 new->next = display_chain;
1377 new->number = ++display_number;
1380 display_chain = new;
1382 if (from_tty && target_has_execution)
1383 do_one_display (new);
1390 free_display (struct display *d)
1396 /* Clear out the display_chain. Done when new symtabs are loaded,
1397 since this invalidates the types stored in many expressions. */
1400 clear_displays (void)
1404 while ((d = display_chain) != NULL)
1407 display_chain = d->next;
1412 /* Delete the auto-display number NUM. */
1415 delete_display (int num)
1417 struct display *d1, *d;
1420 error (_("No display number %d."), num);
1422 if (display_chain->number == num)
1425 display_chain = d1->next;
1429 for (d = display_chain;; d = d->next)
1432 error (_("No display number %d."), num);
1433 if (d->next->number == num)
1443 /* Delete some values from the auto-display chain.
1444 Specify the element numbers. */
1447 undisplay_command (char *args, int from_tty)
1455 if (query ("Delete all auto-display expressions? "))
1464 while (*p1 >= '0' && *p1 <= '9')
1466 if (*p1 && *p1 != ' ' && *p1 != '\t')
1467 error (_("Arguments must be display numbers."));
1471 delete_display (num);
1474 while (*p == ' ' || *p == '\t')
1480 /* Display a single auto-display.
1481 Do nothing if the display cannot be printed in the current context,
1482 or if the display is disabled. */
1485 do_one_display (struct display *d)
1487 int within_current_scope;
1489 if (d->enabled_p == 0)
1493 within_current_scope = contained_in (get_selected_block (0), d->block);
1495 within_current_scope = 1;
1496 if (!within_current_scope)
1499 current_display_number = d->number;
1501 annotate_display_begin ();
1502 printf_filtered ("%d", d->number);
1503 annotate_display_number_end ();
1504 printf_filtered (": ");
1510 annotate_display_format ();
1512 printf_filtered ("x/");
1513 if (d->format.count != 1)
1514 printf_filtered ("%d", d->format.count);
1515 printf_filtered ("%c", d->format.format);
1516 if (d->format.format != 'i' && d->format.format != 's')
1517 printf_filtered ("%c", d->format.size);
1518 printf_filtered (" ");
1520 annotate_display_expression ();
1522 print_expression (d->exp, gdb_stdout);
1523 annotate_display_expression_end ();
1525 if (d->format.count != 1 || d->format.format == 'i')
1526 printf_filtered ("\n");
1528 printf_filtered (" ");
1530 val = evaluate_expression (d->exp);
1531 addr = value_as_address (val);
1532 if (d->format.format == 'i')
1533 addr = gdbarch_addr_bits_remove (current_gdbarch, addr);
1535 annotate_display_value ();
1537 do_examine (d->format, addr);
1541 annotate_display_format ();
1543 if (d->format.format)
1544 printf_filtered ("/%c ", d->format.format);
1546 annotate_display_expression ();
1548 print_expression (d->exp, gdb_stdout);
1549 annotate_display_expression_end ();
1551 printf_filtered (" = ");
1553 annotate_display_expression ();
1555 print_formatted (evaluate_expression (d->exp),
1556 d->format.format, d->format.size, gdb_stdout);
1557 printf_filtered ("\n");
1560 annotate_display_end ();
1562 gdb_flush (gdb_stdout);
1563 current_display_number = -1;
1566 /* Display all of the values on the auto-display chain which can be
1567 evaluated in the current scope. */
1574 for (d = display_chain; d; d = d->next)
1578 /* Delete the auto-display which we were in the process of displaying.
1579 This is done when there is an error or a signal. */
1582 disable_display (int num)
1586 for (d = display_chain; d; d = d->next)
1587 if (d->number == num)
1592 printf_unfiltered (_("No display number %d.\n"), num);
1596 disable_current_display (void)
1598 if (current_display_number >= 0)
1600 disable_display (current_display_number);
1601 fprintf_unfiltered (gdb_stderr, _("\
1602 Disabling display %d to avoid infinite recursion.\n"),
1603 current_display_number);
1605 current_display_number = -1;
1609 display_info (char *ignore, int from_tty)
1614 printf_unfiltered (_("There are no auto-display expressions now.\n"));
1616 printf_filtered (_("Auto-display expressions now in effect:\n\
1617 Num Enb Expression\n"));
1619 for (d = display_chain; d; d = d->next)
1621 printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]);
1623 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1625 else if (d->format.format)
1626 printf_filtered ("/%c ", d->format.format);
1627 print_expression (d->exp, gdb_stdout);
1628 if (d->block && !contained_in (get_selected_block (0), d->block))
1629 printf_filtered (_(" (cannot be evaluated in the current context)"));
1630 printf_filtered ("\n");
1631 gdb_flush (gdb_stdout);
1636 enable_display (char *args, int from_tty)
1645 for (d = display_chain; d; d = d->next)
1652 while (*p1 >= '0' && *p1 <= '9')
1654 if (*p1 && *p1 != ' ' && *p1 != '\t')
1655 error (_("Arguments must be display numbers."));
1659 for (d = display_chain; d; d = d->next)
1660 if (d->number == num)
1665 printf_unfiltered (_("No display number %d.\n"), num);
1668 while (*p == ' ' || *p == '\t')
1674 disable_display_command (char *args, int from_tty)
1682 for (d = display_chain; d; d = d->next)
1689 while (*p1 >= '0' && *p1 <= '9')
1691 if (*p1 && *p1 != ' ' && *p1 != '\t')
1692 error (_("Arguments must be display numbers."));
1694 disable_display (atoi (p));
1697 while (*p == ' ' || *p == '\t')
1703 /* Print the value in stack frame FRAME of a variable specified by a
1707 print_variable_value (struct symbol *var, struct frame_info *frame,
1708 struct ui_file *stream)
1710 struct value *val = read_var_value (var, frame);
1712 value_print (val, stream, 0, Val_pretty_default);
1716 printf_command (char *arg, int from_tty)
1720 char *string = NULL;
1721 struct value **val_args;
1723 char *current_substring;
1725 int allocated_args = 20;
1726 struct cleanup *old_cleanups;
1728 val_args = xmalloc (allocated_args * sizeof (struct value *));
1729 old_cleanups = make_cleanup (free_current_contents, &val_args);
1732 error_no_arg (_("format-control string and values to print"));
1734 /* Skip white space before format string */
1735 while (*s == ' ' || *s == '\t')
1738 /* A format string should follow, enveloped in double quotes. */
1740 error (_("Bad format string, missing '\"'."));
1742 /* Parse the format-control string and copy it into the string STRING,
1743 processing some kinds of escape sequence. */
1745 f = string = (char *) alloca (strlen (s) + 1);
1753 error (_("Bad format string, non-terminated '\"'."));
1786 /* ??? TODO: handle other escape sequences */
1787 error (_("Unrecognized escape character \\%c in format string."),
1797 /* Skip over " and following space and comma. */
1800 while (*s == ' ' || *s == '\t')
1803 if (*s != ',' && *s != 0)
1804 error (_("Invalid argument syntax"));
1808 while (*s == ' ' || *s == '\t')
1811 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1812 substrings = alloca (strlen (string) * 2);
1813 current_substring = substrings;
1816 /* Now scan the string for %-specs and see what kinds of args they want.
1817 argclass[I] classifies the %-specs so we can give printf_filtered
1818 something of the right size. */
1822 int_arg, long_arg, long_long_arg, ptr_arg, string_arg,
1823 double_arg, long_double_arg, decfloat_arg
1825 enum argclass *argclass;
1826 enum argclass this_argclass;
1831 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1838 int seen_hash = 0, seen_zero = 0, lcount = 0, seen_prec = 0;
1839 int seen_space = 0, seen_plus = 0;
1840 int seen_big_l = 0, seen_h = 0;
1843 /* Check the validity of the format specifier, and work
1844 out what argument it expects. We only accept C89
1845 format strings, with the exception of long long (which
1846 we autoconf for). */
1848 /* Skip over "%%". */
1855 /* The first part of a format specifier is a set of flag
1857 while (strchr ("0-+ #", *f))
1870 /* The next part of a format specifier is a width. */
1871 while (strchr ("0123456789", *f))
1874 /* The next part of a format specifier is a precision. */
1879 while (strchr ("0123456789", *f))
1883 /* The next part of a format specifier is a length modifier. */
1915 if (seen_space || seen_plus)
1922 this_argclass = int_arg;
1923 else if (lcount == 1)
1924 this_argclass = long_arg;
1926 this_argclass = long_long_arg;
1932 /* DFP Decimal32 types. */
1934 this_argclass = decfloat_arg;
1936 #ifndef PRINTF_HAS_DECFLOAT
1937 if (lcount || seen_h || seen_big_l)
1939 if (seen_prec || seen_zero || seen_space || seen_plus)
1944 /* DFP Decimal64 and Decimal128 types. */
1946 this_argclass = decfloat_arg;
1948 #ifndef PRINTF_HAS_DECFLOAT
1949 if (lcount || seen_h || seen_big_l)
1951 if (seen_prec || seen_zero || seen_space || seen_plus)
1954 /* Check for a Decimal128. */
1955 if (*(f + 1) == 'D')
1961 this_argclass = int_arg;
1962 if (lcount || seen_h || seen_big_l)
1964 if (seen_prec || seen_zero || seen_space || seen_plus)
1969 this_argclass = ptr_arg;
1970 if (lcount || seen_h || seen_big_l)
1972 if (seen_prec || seen_zero || seen_space || seen_plus)
1977 this_argclass = string_arg;
1978 if (lcount || seen_h || seen_big_l)
1980 if (seen_zero || seen_space || seen_plus)
1990 this_argclass = long_double_arg;
1992 this_argclass = double_arg;
1994 if (lcount || seen_h)
1999 error (_("`*' not supported for precision or width in printf"));
2002 error (_("Format specifier `n' not supported in printf"));
2005 error (_("Incomplete format specifier at end of format string"));
2008 error (_("Unrecognized format specifier '%c' in printf"), *f);
2012 error (_("Inappropriate modifiers to format specifier '%c' in printf"),
2016 strncpy (current_substring, last_arg, f - last_arg);
2017 current_substring += f - last_arg;
2018 *current_substring++ = '\0';
2020 argclass[nargs_wanted++] = this_argclass;
2023 /* Now, parse all arguments and evaluate them.
2024 Store the VALUEs in VAL_ARGS. */
2029 if (nargs == allocated_args)
2030 val_args = (struct value **) xrealloc ((char *) val_args,
2031 (allocated_args *= 2)
2032 * sizeof (struct value *));
2034 val_args[nargs] = parse_to_comma_and_eval (&s1);
2036 /* If format string wants a float, unchecked-convert the value to
2037 floating point of the same size */
2039 if (argclass[nargs] == double_arg)
2041 struct type *type = value_type (val_args[nargs]);
2042 if (TYPE_LENGTH (type) == sizeof (float))
2043 deprecated_set_value_type (val_args[nargs], builtin_type_float);
2044 if (TYPE_LENGTH (type) == sizeof (double))
2045 deprecated_set_value_type (val_args[nargs], builtin_type_double);
2053 if (nargs != nargs_wanted)
2054 error (_("Wrong number of arguments for specified format-string"));
2056 /* Now actually print them. */
2057 current_substring = substrings;
2058 for (i = 0; i < nargs; i++)
2060 switch (argclass[i])
2067 tem = value_as_address (val_args[i]);
2069 /* This is a %s argument. Find the length of the string. */
2074 read_memory (tem + j, &c, 1);
2079 /* Copy the string contents into a string inside GDB. */
2080 str = (gdb_byte *) alloca (j + 1);
2082 read_memory (tem, str, j);
2085 printf_filtered (current_substring, (char *) str);
2090 double val = value_as_double (val_args[i]);
2091 printf_filtered (current_substring, val);
2094 case long_double_arg:
2095 #ifdef HAVE_LONG_DOUBLE
2097 long double val = value_as_double (val_args[i]);
2098 printf_filtered (current_substring, val);
2102 error (_("long double not supported in printf"));
2105 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2107 long long val = value_as_long (val_args[i]);
2108 printf_filtered (current_substring, val);
2112 error (_("long long not supported in printf"));
2116 int val = value_as_long (val_args[i]);
2117 printf_filtered (current_substring, val);
2122 long val = value_as_long (val_args[i]);
2123 printf_filtered (current_substring, val);
2127 /* Handles decimal floating point values. */
2132 unsigned int dfp_len = TYPE_LENGTH (value_type (val_args[i]));
2133 unsigned char *dfp_value_ptr = (unsigned char *) value_contents_all (val_args[i])
2134 + value_offset (val_args[i]);
2136 #if defined (PRINTF_HAS_DECFLOAT)
2137 printf_filtered (current_substring, dfp_value_ptr);
2139 if (TYPE_CODE (value_type (val_args[i])) != TYPE_CODE_DECFLOAT)
2140 error (_("Cannot convert parameter to decfloat."));
2142 /* As a workaround until vasprintf has native support for DFP
2143 we convert the DFP values to string and print them using
2144 the %s format specifier. */
2145 decimal_to_string (dfp_value_ptr, dfp_len, decstr);
2147 /* Points to the end of the string so that we can go back
2148 and check for DFP format specifiers. */
2149 eos = current_substring + strlen (current_substring);
2151 /* Replace %H, %D and %DD with %s's. */
2152 while (*--eos != '%')
2153 if (*eos == 'D' && *(eos - 1) == 'D')
2157 /* If we've found a %DD format specifier we need to go
2158 through the whole string pulling back one character
2159 since this format specifier has two chars. */
2160 while (eos < last_arg)
2166 else if (*eos == 'D' || *eos == 'H')
2169 /* Print the DFP value. */
2170 printf_filtered (current_substring, decstr);
2177 /* We avoid the host's %p because pointers are too
2178 likely to be the wrong size. The only interesting
2179 modifier for %p is a width; extract that, and then
2180 handle %p as glibc would: %#x or a literal "(nil)". */
2182 char *p, *fmt, *fmt_p;
2183 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2184 long long val = value_as_long (val_args[i]);
2186 long val = value_as_long (val_args[i]);
2189 fmt = alloca (strlen (current_substring) + 5);
2191 /* Copy up to the leading %. */
2192 p = current_substring;
2196 int is_percent = (*p == '%');
2210 /* Copy any width. */
2211 while (*p >= '0' && *p < '9')
2214 gdb_assert (*p == 'p' && *(p + 1) == '\0');
2217 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2223 printf_filtered (fmt, val);
2229 printf_filtered (fmt, "(nil)");
2235 internal_error (__FILE__, __LINE__,
2236 _("failed internal consistency check"));
2238 /* Skip to the next substring. */
2239 current_substring += strlen (current_substring) + 1;
2241 /* Print the portion of the format string after the last argument. */
2242 puts_filtered (last_arg);
2244 do_cleanups (old_cleanups);
2248 _initialize_printcmd (void)
2250 struct cmd_list_element *c;
2252 current_display_number = -1;
2254 add_info ("address", address_info,
2255 _("Describe where symbol SYM is stored."));
2257 add_info ("symbol", sym_info, _("\
2258 Describe what symbol is at location ADDR.\n\
2259 Only for symbols with fixed locations (global or static scope)."));
2261 add_com ("x", class_vars, x_command, _("\
2262 Examine memory: x/FMT ADDRESS.\n\
2263 ADDRESS is an expression for the memory address to examine.\n\
2264 FMT is a repeat count followed by a format letter and a size letter.\n\
2265 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2266 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2267 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2268 The specified number of objects of the specified size are printed\n\
2269 according to the format.\n\n\
2270 Defaults for format and size letters are those previously used.\n\
2271 Default count is 1. Default address is following last thing printed\n\
2272 with this command or \"print\"."));
2275 add_com ("whereis", class_vars, whereis_command,
2276 _("Print line number and file of definition of variable."));
2279 add_info ("display", display_info, _("\
2280 Expressions to display when program stops, with code numbers."));
2282 add_cmd ("undisplay", class_vars, undisplay_command, _("\
2283 Cancel some expressions to be displayed when program stops.\n\
2284 Arguments are the code numbers of the expressions to stop displaying.\n\
2285 No argument means cancel all automatic-display expressions.\n\
2286 \"delete display\" has the same effect as this command.\n\
2287 Do \"info display\" to see current list of code numbers."),
2290 add_com ("display", class_vars, display_command, _("\
2291 Print value of expression EXP each time the program stops.\n\
2292 /FMT may be used before EXP as in the \"print\" command.\n\
2293 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2294 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2295 and examining is done as in the \"x\" command.\n\n\
2296 With no argument, display all currently requested auto-display expressions.\n\
2297 Use \"undisplay\" to cancel display requests previously made."));
2299 add_cmd ("display", class_vars, enable_display, _("\
2300 Enable some expressions to be displayed when program stops.\n\
2301 Arguments are the code numbers of the expressions to resume displaying.\n\
2302 No argument means enable all automatic-display expressions.\n\
2303 Do \"info display\" to see current list of code numbers."), &enablelist);
2305 add_cmd ("display", class_vars, disable_display_command, _("\
2306 Disable some expressions to be displayed when program stops.\n\
2307 Arguments are the code numbers of the expressions to stop displaying.\n\
2308 No argument means disable all automatic-display expressions.\n\
2309 Do \"info display\" to see current list of code numbers."), &disablelist);
2311 add_cmd ("display", class_vars, undisplay_command, _("\
2312 Cancel some expressions to be displayed when program stops.\n\
2313 Arguments are the code numbers of the expressions to stop displaying.\n\
2314 No argument means cancel all automatic-display expressions.\n\
2315 Do \"info display\" to see current list of code numbers."), &deletelist);
2317 add_com ("printf", class_vars, printf_command, _("\
2318 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2319 This is useful for formatted output in user-defined commands."));
2321 add_com ("output", class_vars, output_command, _("\
2322 Like \"print\" but don't put in value history and don't print newline.\n\
2323 This is useful in user-defined commands."));
2325 add_prefix_cmd ("set", class_vars, set_command, _("\
2326 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2327 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2328 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2329 with $), a register (a few standard names starting with $), or an actual\n\
2330 variable in the program being debugged. EXP is any valid expression.\n\
2331 Use \"set variable\" for variables with names identical to set subcommands.\n\
2333 With a subcommand, this command modifies parts of the gdb environment.\n\
2334 You can see these environment settings with the \"show\" command."),
2335 &setlist, "set ", 1, &cmdlist);
2337 add_com ("assign", class_vars, set_command, _("\
2338 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2339 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2340 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2341 with $), a register (a few standard names starting with $), or an actual\n\
2342 variable in the program being debugged. EXP is any valid expression.\n\
2343 Use \"set variable\" for variables with names identical to set subcommands.\n\
2344 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2345 You can see these environment settings with the \"show\" command."));
2347 /* "call" is the same as "set", but handy for dbx users to call fns. */
2348 c = add_com ("call", class_vars, call_command, _("\
2349 Call a function in the program.\n\
2350 The argument is the function name and arguments, in the notation of the\n\
2351 current working language. The result is printed and saved in the value\n\
2352 history, if it is not void."));
2353 set_cmd_completer (c, location_completer);
2355 add_cmd ("variable", class_vars, set_command, _("\
2356 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2357 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2358 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2359 with $), a register (a few standard names starting with $), or an actual\n\
2360 variable in the program being debugged. EXP is any valid expression.\n\
2361 This may usually be abbreviated to simply \"set\"."),
2364 c = add_com ("print", class_vars, print_command, _("\
2365 Print value of expression EXP.\n\
2366 Variables accessible are those of the lexical environment of the selected\n\
2367 stack frame, plus all those whose scope is global or an entire file.\n\
2369 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2370 $$NUM refers to NUM'th value back from the last one.\n\
2371 Names starting with $ refer to registers (with the values they would have\n\
2372 if the program were to return to the stack frame now selected, restoring\n\
2373 all registers saved by frames farther in) or else to debugger\n\
2374 \"convenience\" variables (any such name not a known register).\n\
2375 Use assignment expressions to give values to convenience variables.\n\
2377 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2378 @ is a binary operator for treating consecutive data objects\n\
2379 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2380 element is FOO, whose second element is stored in the space following\n\
2381 where FOO is stored, etc. FOO must be an expression whose value\n\
2382 resides in memory.\n\
2384 EXP may be preceded with /FMT, where FMT is a format letter\n\
2385 but no count or size letter (see \"x\" command)."));
2386 set_cmd_completer (c, location_completer);
2387 add_com_alias ("p", "print", class_vars, 1);
2389 c = add_com ("inspect", class_vars, inspect_command, _("\
2390 Same as \"print\" command, except that if you are running in the epoch\n\
2391 environment, the value is printed in its own window."));
2392 set_cmd_completer (c, location_completer);
2394 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
2395 &max_symbolic_offset, _("\
2396 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2397 Show the largest offset that will be printed in <symbol+1234> form."), NULL,
2399 show_max_symbolic_offset,
2400 &setprintlist, &showprintlist);
2401 add_setshow_boolean_cmd ("symbol-filename", no_class,
2402 &print_symbol_filename, _("\
2403 Set printing of source filename and line number with <symbol>."), _("\
2404 Show printing of source filename and line number with <symbol>."), NULL,
2406 show_print_symbol_filename,
2407 &setprintlist, &showprintlist);
2409 /* For examine/instruction a single byte quantity is specified as
2410 the data. This avoids problems with value_at_lazy() requiring a
2411 valid data type (and rejecting VOID). */
2412 examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
2414 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2415 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2416 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2417 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);