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 2008, 2009 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"
48 #include "tui/tui.h" /* For tui_active et.al. */
51 #if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG)
52 # define USE_PRINTF_I64 1
53 # define PRINTF_HAS_LONG_LONG
55 # define USE_PRINTF_I64 0
58 extern int asm_demangle; /* Whether to demangle syms in asm printouts */
67 /* Last specified output format. */
69 static char last_format = 'x';
71 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
73 static char last_size = 'w';
75 /* Default address to examine next. */
77 static CORE_ADDR next_address;
79 /* Number of delay instructions following current disassembled insn. */
81 static int branch_delay_insns;
83 /* Last address examined. */
85 static CORE_ADDR last_examine_address;
87 /* Contents of last address examined.
88 This is not valid past the end of the `x' command! */
90 static struct value *last_examine_value;
92 /* Largest offset between a symbolic value and an address, that will be
93 printed as `0x1234 <symbol+offset>'. */
95 static unsigned int max_symbolic_offset = UINT_MAX;
97 show_max_symbolic_offset (struct ui_file *file, int from_tty,
98 struct cmd_list_element *c, const char *value)
100 fprintf_filtered (file, _("\
101 The largest offset that will be printed in <symbol+1234> form is %s.\n"),
105 /* Append the source filename and linenumber of the symbol when
106 printing a symbolic value as `<symbol at filename:linenum>' if set. */
107 static int print_symbol_filename = 0;
109 show_print_symbol_filename (struct ui_file *file, int from_tty,
110 struct cmd_list_element *c, const char *value)
112 fprintf_filtered (file, _("\
113 Printing of source filename and line number with <symbol> is %s.\n"),
117 /* Number of auto-display expression currently being displayed.
118 So that we can disable it if we get an error or a signal within it.
119 -1 when not doing one. */
121 int current_display_number;
125 /* Chain link to next auto-display item. */
126 struct display *next;
127 /* The expression as the user typed it. */
129 /* Expression to be evaluated and displayed. */
130 struct expression *exp;
131 /* Item number of this auto-display item. */
133 /* Display format specified. */
134 struct format_data format;
135 /* Innermost block required by this expression when evaluated */
137 /* Status of this display (enabled or disabled) */
141 /* Chain of expressions whose values should be displayed
142 automatically each time the program stops. */
144 static struct display *display_chain;
146 static int display_number;
148 /* Prototypes for exported functions. */
150 void output_command (char *, int);
152 void _initialize_printcmd (void);
154 /* Prototypes for local functions. */
156 static void do_one_display (struct display *);
159 /* Decode a format specification. *STRING_PTR should point to it.
160 OFORMAT and OSIZE are used as defaults for the format and size
161 if none are given in the format specification.
162 If OSIZE is zero, then the size field of the returned value
163 should be set only if a size is explicitly specified by the
165 The structure returned describes all the data
166 found in the specification. In addition, *STRING_PTR is advanced
167 past the specification and past all whitespace following it. */
169 static struct format_data
170 decode_format (char **string_ptr, int oformat, int osize)
172 struct format_data val;
173 char *p = *string_ptr;
179 if (*p >= '0' && *p <= '9')
180 val.count = atoi (p);
181 while (*p >= '0' && *p <= '9')
184 /* Now process size or format letters that follow. */
188 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
190 else if (*p >= 'a' && *p <= 'z')
196 while (*p == ' ' || *p == '\t')
200 /* Set defaults for format and size if not specified. */
201 if (val.format == '?')
205 /* Neither has been specified. */
206 val.format = oformat;
210 /* If a size is specified, any format makes a reasonable
211 default except 'i'. */
212 val.format = oformat == 'i' ? 'x' : oformat;
214 else if (val.size == '?')
219 /* Pick the appropriate size for an address. */
220 if (gdbarch_ptr_bit (current_gdbarch) == 64)
221 val.size = osize ? 'g' : osize;
222 else if (gdbarch_ptr_bit (current_gdbarch) == 32)
223 val.size = osize ? 'w' : osize;
224 else if (gdbarch_ptr_bit (current_gdbarch) == 16)
225 val.size = osize ? 'h' : osize;
227 /* Bad value for gdbarch_ptr_bit. */
228 internal_error (__FILE__, __LINE__,
229 _("failed internal consistency check"));
232 /* Floating point has to be word or giantword. */
233 if (osize == 'w' || osize == 'g')
236 /* Default it to giantword if the last used size is not
238 val.size = osize ? 'g' : osize;
241 /* Characters default to one byte. */
242 val.size = osize ? 'b' : osize;
245 /* The default is the size most recently specified. */
252 /* Print value VAL on stream according to OPTIONS.
253 Do not end with a newline.
254 SIZE is the letter for the size of datum being printed.
255 This is used to pad hex numbers so they line up. SIZE is 0
256 for print / output and set for examine. */
259 print_formatted (struct value *val, int size,
260 const struct value_print_options *options,
261 struct ui_file *stream)
263 struct type *type = check_typedef (value_type (val));
264 int len = TYPE_LENGTH (type);
266 if (VALUE_LVAL (val) == lval_memory)
267 next_address = VALUE_ADDRESS (val) + len;
271 switch (options->format)
274 /* FIXME: Need to handle wchar_t's here... */
275 next_address = VALUE_ADDRESS (val)
276 + val_print_string (VALUE_ADDRESS (val), -1, 1, stream,
281 /* We often wrap here if there are long symbolic names. */
283 next_address = (VALUE_ADDRESS (val)
284 + gdb_print_insn (VALUE_ADDRESS (val), stream,
285 &branch_delay_insns));
290 if (options->format == 0 || options->format == 's'
291 || TYPE_CODE (type) == TYPE_CODE_REF
292 || TYPE_CODE (type) == TYPE_CODE_ARRAY
293 || TYPE_CODE (type) == TYPE_CODE_STRING
294 || TYPE_CODE (type) == TYPE_CODE_STRUCT
295 || TYPE_CODE (type) == TYPE_CODE_UNION
296 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
297 value_print (val, stream, options);
299 /* User specified format, so don't look to the the type to
300 tell us what to do. */
301 print_scalar_formatted (value_contents (val), type,
302 options, size, stream);
305 /* Return builtin floating point type of same length as TYPE.
306 If no such type is found, return TYPE itself. */
308 float_type_from_length (struct gdbarch *gdbarch, struct type *type)
310 const struct builtin_type *builtin = builtin_type (gdbarch);
311 unsigned int len = TYPE_LENGTH (type);
313 if (len == TYPE_LENGTH (builtin->builtin_float))
314 type = builtin->builtin_float;
315 else if (len == TYPE_LENGTH (builtin->builtin_double))
316 type = builtin->builtin_double;
317 else if (len == TYPE_LENGTH (builtin->builtin_long_double))
318 type = builtin->builtin_long_double;
323 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
324 according to OPTIONS and SIZE on STREAM.
325 Formats s and i are not supported at this level.
327 This is how the elements of an array or structure are printed
331 print_scalar_formatted (const void *valaddr, struct type *type,
332 const struct value_print_options *options,
333 int size, struct ui_file *stream)
335 LONGEST val_long = 0;
336 unsigned int len = TYPE_LENGTH (type);
337 enum bfd_endian byte_order = gdbarch_byte_order (current_gdbarch);
339 /* If we get here with a string format, try again without it. Go
340 all the way back to the language printers, which may call us
342 if (options->format == 's')
344 struct value_print_options opts = *options;
347 val_print (type, valaddr, 0, 0, stream, 0, &opts,
352 if (len > sizeof(LONGEST) &&
353 (TYPE_CODE (type) == TYPE_CODE_INT
354 || TYPE_CODE (type) == TYPE_CODE_ENUM))
356 switch (options->format)
359 print_octal_chars (stream, valaddr, len, byte_order);
363 print_decimal_chars (stream, valaddr, len, byte_order);
366 print_binary_chars (stream, valaddr, len, byte_order);
369 print_hex_chars (stream, valaddr, len, byte_order);
372 print_char_chars (stream, valaddr, len, byte_order);
379 if (options->format != 'f')
380 val_long = unpack_long (type, valaddr);
382 /* If the value is a pointer, and pointers and addresses are not the
383 same, then at this point, the value's length (in target bytes) is
384 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
385 if (TYPE_CODE (type) == TYPE_CODE_PTR)
386 len = gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT;
388 /* If we are printing it as unsigned, truncate it in case it is actually
389 a negative signed value (e.g. "print/u (short)-1" should print 65535
390 (if shorts are 16 bits) instead of 4294967295). */
391 if (options->format != 'd')
393 if (len < sizeof (LONGEST))
394 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
397 switch (options->format)
402 /* No size specified, like in print. Print varying # of digits. */
403 print_longest (stream, 'x', 1, val_long);
412 print_longest (stream, size, 1, val_long);
415 error (_("Undefined output size \"%c\"."), size);
420 print_longest (stream, 'd', 1, val_long);
424 print_longest (stream, 'u', 0, val_long);
429 print_longest (stream, 'o', 1, val_long);
431 fprintf_filtered (stream, "0");
436 CORE_ADDR addr = unpack_pointer (type, valaddr);
437 print_address (addr, stream);
443 struct value_print_options opts = *options;
445 if (TYPE_UNSIGNED (type))
446 value_print (value_from_longest (builtin_type_true_unsigned_char,
450 value_print (value_from_longest (builtin_type_true_char, val_long),
456 type = float_type_from_length (current_gdbarch, type);
457 print_floating (valaddr, type, stream);
461 internal_error (__FILE__, __LINE__,
462 _("failed internal consistency check"));
465 /* Binary; 't' stands for "two". */
467 char bits[8 * (sizeof val_long) + 1];
468 char buf[8 * (sizeof val_long) + 32];
473 width = 8 * (sizeof val_long);
490 error (_("Undefined output size \"%c\"."), size);
496 bits[width] = (val_long & 1) ? '1' : '0';
501 while (*cp && *cp == '0')
507 fputs_filtered (buf, stream);
512 error (_("Undefined output format \"%c\"."), options->format);
516 /* Specify default address for `x' command.
517 The `info lines' command uses this. */
520 set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr)
522 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
526 /* Make address available to the user as $_. */
527 set_internalvar (lookup_internalvar ("_"),
528 value_from_pointer (ptr_type, addr));
531 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
532 after LEADIN. Print nothing if no symbolic name is found nearby.
533 Optionally also print source file and line number, if available.
534 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
535 or to interpret it as a possible C++ name and convert it back to source
536 form. However note that DO_DEMANGLE can be overridden by the specific
537 settings of the demangle and asm_demangle variables. */
540 print_address_symbolic (CORE_ADDR addr, struct ui_file *stream,
541 int do_demangle, char *leadin)
544 char *filename = NULL;
549 /* Throw away both name and filename. */
550 struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
551 make_cleanup (free_current_contents, &filename);
553 if (build_address_symbolic (addr, do_demangle, &name, &offset,
554 &filename, &line, &unmapped))
556 do_cleanups (cleanup_chain);
560 fputs_filtered (leadin, stream);
562 fputs_filtered ("<*", stream);
564 fputs_filtered ("<", stream);
565 fputs_filtered (name, stream);
567 fprintf_filtered (stream, "+%u", (unsigned int) offset);
569 /* Append source filename and line number if desired. Give specific
570 line # of this addr, if we have it; else line # of the nearest symbol. */
571 if (print_symbol_filename && filename != NULL)
574 fprintf_filtered (stream, " at %s:%d", filename, line);
576 fprintf_filtered (stream, " in %s", filename);
579 fputs_filtered ("*>", stream);
581 fputs_filtered (">", stream);
583 do_cleanups (cleanup_chain);
586 /* Given an address ADDR return all the elements needed to print the
587 address in a symbolic form. NAME can be mangled or not depending
588 on DO_DEMANGLE (and also on the asm_demangle global variable,
589 manipulated via ''set print asm-demangle''). Return 0 in case of
590 success, when all the info in the OUT paramters is valid. Return 1
593 build_address_symbolic (CORE_ADDR addr, /* IN */
594 int do_demangle, /* IN */
595 char **name, /* OUT */
596 int *offset, /* OUT */
597 char **filename, /* OUT */
599 int *unmapped) /* OUT */
601 struct minimal_symbol *msymbol;
602 struct symbol *symbol;
603 CORE_ADDR name_location = 0;
604 struct obj_section *section = NULL;
605 char *name_temp = "";
607 /* Let's say it is mapped (not unmapped). */
610 /* Determine if the address is in an overlay, and whether it is
612 if (overlay_debugging)
614 section = find_pc_overlay (addr);
615 if (pc_in_unmapped_range (addr, section))
618 addr = overlay_mapped_address (addr, section);
622 /* First try to find the address in the symbol table, then
623 in the minsyms. Take the closest one. */
625 /* This is defective in the sense that it only finds text symbols. So
626 really this is kind of pointless--we should make sure that the
627 minimal symbols have everything we need (by changing that we could
628 save some memory, but for many debug format--ELF/DWARF or
629 anything/stabs--it would be inconvenient to eliminate those minimal
631 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
632 symbol = find_pc_sect_function (addr, section);
636 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
637 if (do_demangle || asm_demangle)
638 name_temp = SYMBOL_PRINT_NAME (symbol);
640 name_temp = SYMBOL_LINKAGE_NAME (symbol);
645 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
647 /* The msymbol is closer to the address than the symbol;
648 use the msymbol instead. */
650 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
651 if (do_demangle || asm_demangle)
652 name_temp = SYMBOL_PRINT_NAME (msymbol);
654 name_temp = SYMBOL_LINKAGE_NAME (msymbol);
657 if (symbol == NULL && msymbol == NULL)
660 /* If the nearest symbol is too far away, don't print anything symbolic. */
662 /* For when CORE_ADDR is larger than unsigned int, we do math in
663 CORE_ADDR. But when we detect unsigned wraparound in the
664 CORE_ADDR math, we ignore this test and print the offset,
665 because addr+max_symbolic_offset has wrapped through the end
666 of the address space back to the beginning, giving bogus comparison. */
667 if (addr > name_location + max_symbolic_offset
668 && name_location + max_symbolic_offset > name_location)
671 *offset = addr - name_location;
673 *name = xstrdup (name_temp);
675 if (print_symbol_filename)
677 struct symtab_and_line sal;
679 sal = find_pc_sect_line (addr, section, 0);
683 *filename = xstrdup (sal.symtab->filename);
691 /* Print address ADDR symbolically on STREAM.
692 First print it as a number. Then perhaps print
693 <SYMBOL + OFFSET> after the number. */
696 print_address (CORE_ADDR addr, struct ui_file *stream)
698 fputs_filtered (paddress (addr), stream);
699 print_address_symbolic (addr, stream, asm_demangle, " ");
702 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
703 controls whether to print the symbolic name "raw" or demangled.
704 Global setting "addressprint" controls whether to print hex address
708 print_address_demangle (CORE_ADDR addr, struct ui_file *stream,
711 struct value_print_options opts;
712 get_user_print_options (&opts);
715 fprintf_filtered (stream, "0");
717 else if (opts.addressprint)
719 fputs_filtered (paddress (addr), stream);
720 print_address_symbolic (addr, stream, do_demangle, " ");
724 print_address_symbolic (addr, stream, do_demangle, "");
729 /* These are the types that $__ will get after an examine command of one
732 static struct type *examine_i_type;
734 static struct type *examine_b_type;
735 static struct type *examine_h_type;
736 static struct type *examine_w_type;
737 static struct type *examine_g_type;
739 /* Examine data at address ADDR in format FMT.
740 Fetch it from memory and print on gdb_stdout. */
743 do_examine (struct format_data fmt, CORE_ADDR addr)
748 struct type *val_type = NULL;
751 struct value_print_options opts;
758 /* String or instruction format implies fetch single bytes
759 regardless of the specified size. */
760 if (format == 's' || format == 'i')
764 val_type = examine_i_type;
765 else if (size == 'b')
766 val_type = examine_b_type;
767 else if (size == 'h')
768 val_type = examine_h_type;
769 else if (size == 'w')
770 val_type = examine_w_type;
771 else if (size == 'g')
772 val_type = examine_g_type;
779 if (format == 's' || format == 'i')
782 get_formatted_print_options (&opts, format);
784 /* Print as many objects as specified in COUNT, at most maxelts per line,
785 with the address of the next one at the start of each line. */
790 print_address (next_address, gdb_stdout);
791 printf_filtered (":");
796 printf_filtered ("\t");
797 /* Note that print_formatted sets next_address for the next
799 last_examine_address = next_address;
801 if (last_examine_value)
802 value_free (last_examine_value);
804 /* The value to be displayed is not fetched greedily.
805 Instead, to avoid the possibility of a fetched value not
806 being used, its retrieval is delayed until the print code
807 uses it. When examining an instruction stream, the
808 disassembler will perform its own memory fetch using just
809 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
810 the disassembler be modified so that LAST_EXAMINE_VALUE
811 is left with the byte sequence from the last complete
812 instruction fetched from memory? */
813 last_examine_value = value_at_lazy (val_type, next_address);
815 if (last_examine_value)
816 release_value (last_examine_value);
818 print_formatted (last_examine_value, size, &opts, gdb_stdout);
820 /* Display any branch delay slots following the final insn. */
821 if (format == 'i' && count == 1)
822 count += branch_delay_insns;
824 printf_filtered ("\n");
825 gdb_flush (gdb_stdout);
830 validate_format (struct format_data fmt, char *cmdname)
833 error (_("Size letters are meaningless in \"%s\" command."), cmdname);
835 error (_("Item count other than 1 is meaningless in \"%s\" command."),
837 if (fmt.format == 'i')
838 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
839 fmt.format, cmdname);
842 /* Evaluate string EXP as an expression in the current language and
843 print the resulting value. EXP may contain a format specifier as the
844 first argument ("/x myvar" for example, to print myvar in hex). */
847 print_command_1 (char *exp, int inspect, int voidprint)
849 struct expression *expr;
850 struct cleanup *old_chain = 0;
853 struct format_data fmt;
856 if (exp && *exp == '/')
859 fmt = decode_format (&exp, last_format, 0);
860 validate_format (fmt, "print");
861 last_format = format = fmt.format;
873 expr = parse_expression (exp);
874 old_chain = make_cleanup (free_current_contents, &expr);
876 val = evaluate_expression (expr);
879 val = access_value_history (0);
881 if (voidprint || (val && value_type (val) &&
882 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
884 struct value_print_options opts;
885 int histindex = record_latest_value (val);
888 annotate_value_history_begin (histindex, value_type (val));
890 annotate_value_begin (value_type (val));
893 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"",
895 else if (histindex >= 0)
896 printf_filtered ("$%d = ", histindex);
899 annotate_value_history_value ();
901 get_formatted_print_options (&opts, format);
902 opts.inspect_it = inspect;
904 print_formatted (val, fmt.size, &opts, gdb_stdout);
905 printf_filtered ("\n");
908 annotate_value_history_end ();
910 annotate_value_end ();
913 printf_unfiltered ("\") )\030");
917 do_cleanups (old_chain);
921 print_command (char *exp, int from_tty)
923 print_command_1 (exp, 0, 1);
926 /* Same as print, except in epoch, it gets its own window. */
928 inspect_command (char *exp, int from_tty)
930 extern int epoch_interface;
932 print_command_1 (exp, epoch_interface, 1);
935 /* Same as print, except it doesn't print void results. */
937 call_command (char *exp, int from_tty)
939 print_command_1 (exp, 0, 0);
943 output_command (char *exp, int from_tty)
945 struct expression *expr;
946 struct cleanup *old_chain;
949 struct format_data fmt;
950 struct value_print_options opts;
954 if (exp && *exp == '/')
957 fmt = decode_format (&exp, 0, 0);
958 validate_format (fmt, "output");
962 expr = parse_expression (exp);
963 old_chain = make_cleanup (free_current_contents, &expr);
965 val = evaluate_expression (expr);
967 annotate_value_begin (value_type (val));
969 get_formatted_print_options (&opts, format);
970 print_formatted (val, fmt.size, &opts, gdb_stdout);
972 annotate_value_end ();
975 gdb_flush (gdb_stdout);
977 do_cleanups (old_chain);
981 set_command (char *exp, int from_tty)
983 struct expression *expr = parse_expression (exp);
984 struct cleanup *old_chain =
985 make_cleanup (free_current_contents, &expr);
986 evaluate_expression (expr);
987 do_cleanups (old_chain);
991 sym_info (char *arg, int from_tty)
993 struct minimal_symbol *msymbol;
994 struct objfile *objfile;
995 struct obj_section *osect;
996 CORE_ADDR addr, sect_addr;
1001 error_no_arg (_("address"));
1003 addr = parse_and_eval_address (arg);
1004 ALL_OBJSECTIONS (objfile, osect)
1006 /* Only process each object file once, even if there's a separate
1008 if (objfile->separate_debug_objfile_backlink)
1011 sect_addr = overlay_mapped_address (addr, osect);
1013 if (obj_section_addr (osect) <= sect_addr
1014 && sect_addr < obj_section_endaddr (osect)
1015 && (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, osect)))
1017 const char *obj_name, *mapped, *sec_name, *msym_name;
1019 struct cleanup *old_chain;
1022 offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
1023 mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
1024 sec_name = osect->the_bfd_section->name;
1025 msym_name = SYMBOL_PRINT_NAME (msymbol);
1027 /* Don't print the offset if it is zero.
1028 We assume there's no need to handle i18n of "sym + offset". */
1030 xasprintf (&loc_string, "%s + %u", msym_name, offset);
1032 xasprintf (&loc_string, "%s", msym_name);
1034 /* Use a cleanup to free loc_string in case the user quits
1035 a pagination request inside printf_filtered. */
1036 old_chain = make_cleanup (xfree, loc_string);
1038 gdb_assert (osect->objfile && osect->objfile->name);
1039 obj_name = osect->objfile->name;
1041 if (MULTI_OBJFILE_P ())
1042 if (pc_in_unmapped_range (addr, osect))
1043 if (section_is_overlay (osect))
1044 printf_filtered (_("%s in load address range of "
1045 "%s overlay section %s of %s\n"),
1046 loc_string, mapped, sec_name, obj_name);
1048 printf_filtered (_("%s in load address range of "
1049 "section %s of %s\n"),
1050 loc_string, sec_name, obj_name);
1052 if (section_is_overlay (osect))
1053 printf_filtered (_("%s in %s overlay section %s of %s\n"),
1054 loc_string, mapped, sec_name, obj_name);
1056 printf_filtered (_("%s in section %s of %s\n"),
1057 loc_string, sec_name, obj_name);
1059 if (pc_in_unmapped_range (addr, osect))
1060 if (section_is_overlay (osect))
1061 printf_filtered (_("%s in load address range of %s overlay "
1063 loc_string, mapped, sec_name);
1065 printf_filtered (_("%s in load address range of section %s\n"),
1066 loc_string, sec_name);
1068 if (section_is_overlay (osect))
1069 printf_filtered (_("%s in %s overlay section %s\n"),
1070 loc_string, mapped, sec_name);
1072 printf_filtered (_("%s in section %s\n"),
1073 loc_string, sec_name);
1075 do_cleanups (old_chain);
1079 printf_filtered (_("No symbol matches %s.\n"), arg);
1083 address_info (char *exp, int from_tty)
1086 struct minimal_symbol *msymbol;
1088 struct obj_section *section;
1089 CORE_ADDR load_addr;
1090 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
1091 if exp is a field of `this'. */
1094 error (_("Argument required."));
1096 sym = lookup_symbol (exp, get_selected_block (0), VAR_DOMAIN,
1097 &is_a_field_of_this);
1100 if (is_a_field_of_this)
1102 printf_filtered ("Symbol \"");
1103 fprintf_symbol_filtered (gdb_stdout, exp,
1104 current_language->la_language, DMGL_ANSI);
1105 printf_filtered ("\" is a field of the local class variable ");
1106 if (current_language->la_language == language_objc)
1107 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1109 printf_filtered ("`this'\n");
1113 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1115 if (msymbol != NULL)
1117 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1119 printf_filtered ("Symbol \"");
1120 fprintf_symbol_filtered (gdb_stdout, exp,
1121 current_language->la_language, DMGL_ANSI);
1122 printf_filtered ("\" is at ");
1123 fputs_filtered (paddress (load_addr), gdb_stdout);
1124 printf_filtered (" in a file compiled without debugging");
1125 section = SYMBOL_OBJ_SECTION (msymbol);
1126 if (section_is_overlay (section))
1128 load_addr = overlay_unmapped_address (load_addr, section);
1129 printf_filtered (",\n -- loaded at ");
1130 fputs_filtered (paddress (load_addr), gdb_stdout);
1131 printf_filtered (" in overlay section %s",
1132 section->the_bfd_section->name);
1134 printf_filtered (".\n");
1137 error (_("No symbol \"%s\" in current context."), exp);
1141 printf_filtered ("Symbol \"");
1142 fprintf_symbol_filtered (gdb_stdout, SYMBOL_PRINT_NAME (sym),
1143 current_language->la_language, DMGL_ANSI);
1144 printf_filtered ("\" is ");
1145 val = SYMBOL_VALUE (sym);
1146 section = SYMBOL_OBJ_SECTION (sym);
1148 switch (SYMBOL_CLASS (sym))
1151 case LOC_CONST_BYTES:
1152 printf_filtered ("constant");
1156 printf_filtered ("a label at address ");
1157 fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)),
1159 if (section_is_overlay (section))
1161 load_addr = overlay_unmapped_address (load_addr, section);
1162 printf_filtered (",\n -- loaded at ");
1163 fputs_filtered (paddress (load_addr), gdb_stdout);
1164 printf_filtered (" in overlay section %s",
1165 section->the_bfd_section->name);
1170 /* FIXME: cagney/2004-01-26: It should be possible to
1171 unconditionally call the SYMBOL_OPS method when available.
1172 Unfortunately DWARF 2 stores the frame-base (instead of the
1173 function) location in a function's symbol. Oops! For the
1174 moment enable this when/where applicable. */
1175 SYMBOL_OPS (sym)->describe_location (sym, gdb_stdout);
1179 if (SYMBOL_IS_ARGUMENT (sym))
1180 printf_filtered (_("an argument in register %s"),
1181 gdbarch_register_name (current_gdbarch, val));
1183 printf_filtered (_("a variable in register %s"),
1184 gdbarch_register_name (current_gdbarch, val));
1188 printf_filtered (_("static storage at address "));
1189 fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)),
1191 if (section_is_overlay (section))
1193 load_addr = overlay_unmapped_address (load_addr, section);
1194 printf_filtered (_(",\n -- loaded at "));
1195 fputs_filtered (paddress (load_addr), gdb_stdout);
1196 printf_filtered (_(" in overlay section %s"),
1197 section->the_bfd_section->name);
1201 case LOC_REGPARM_ADDR:
1202 printf_filtered (_("address of an argument in register %s"),
1203 gdbarch_register_name (current_gdbarch, val));
1207 printf_filtered (_("an argument at offset %ld"), val);
1211 printf_filtered (_("a local variable at frame offset %ld"), val);
1215 printf_filtered (_("a reference argument at offset %ld"), val);
1219 printf_filtered (_("a typedef"));
1223 printf_filtered (_("a function at address "));
1224 load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1225 fputs_filtered (paddress (load_addr), gdb_stdout);
1226 if (section_is_overlay (section))
1228 load_addr = overlay_unmapped_address (load_addr, section);
1229 printf_filtered (_(",\n -- loaded at "));
1230 fputs_filtered (paddress (load_addr), gdb_stdout);
1231 printf_filtered (_(" in overlay section %s"),
1232 section->the_bfd_section->name);
1236 case LOC_UNRESOLVED:
1238 struct minimal_symbol *msym;
1240 msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), NULL, NULL);
1242 printf_filtered ("unresolved");
1245 section = SYMBOL_OBJ_SECTION (msym);
1246 load_addr = SYMBOL_VALUE_ADDRESS (msym);
1249 && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
1250 printf_filtered (_("a thread-local variable at offset %s "
1251 "in the thread-local storage for `%s'"),
1252 paddr_nz (load_addr), section->objfile->name);
1255 printf_filtered (_("static storage at address "));
1256 fputs_filtered (paddress (load_addr), gdb_stdout);
1257 if (section_is_overlay (section))
1259 load_addr = overlay_unmapped_address (load_addr, section);
1260 printf_filtered (_(",\n -- loaded at "));
1261 fputs_filtered (paddress (load_addr), gdb_stdout);
1262 printf_filtered (_(" in overlay section %s"),
1263 section->the_bfd_section->name);
1270 case LOC_OPTIMIZED_OUT:
1271 printf_filtered (_("optimized out"));
1275 printf_filtered (_("of unknown (botched) type"));
1278 printf_filtered (".\n");
1283 x_command (char *exp, int from_tty)
1285 struct expression *expr;
1286 struct format_data fmt;
1287 struct cleanup *old_chain;
1290 fmt.format = last_format;
1291 fmt.size = last_size;
1294 if (exp && *exp == '/')
1297 fmt = decode_format (&exp, last_format, last_size);
1300 /* If we have an expression, evaluate it and use it as the address. */
1302 if (exp != 0 && *exp != 0)
1304 expr = parse_expression (exp);
1305 /* Cause expression not to be there any more if this command is
1306 repeated with Newline. But don't clobber a user-defined
1307 command's definition. */
1310 old_chain = make_cleanup (free_current_contents, &expr);
1311 val = evaluate_expression (expr);
1312 if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
1313 val = value_ind (val);
1314 /* In rvalue contexts, such as this, functions are coerced into
1315 pointers to functions. This makes "x/i main" work. */
1316 if (/* last_format == 'i' && */
1317 TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
1318 && VALUE_LVAL (val) == lval_memory)
1319 next_address = VALUE_ADDRESS (val);
1321 next_address = value_as_address (val);
1322 do_cleanups (old_chain);
1325 do_examine (fmt, next_address);
1327 /* If the examine succeeds, we remember its size and format for next
1329 last_size = fmt.size;
1330 last_format = fmt.format;
1332 /* Set a couple of internal variables if appropriate. */
1333 if (last_examine_value)
1335 /* Make last address examined available to the user as $_. Use
1336 the correct pointer type. */
1337 struct type *pointer_type
1338 = lookup_pointer_type (value_type (last_examine_value));
1339 set_internalvar (lookup_internalvar ("_"),
1340 value_from_pointer (pointer_type,
1341 last_examine_address));
1343 /* Make contents of last address examined available to the user
1344 as $__. If the last value has not been fetched from memory
1345 then don't fetch it now; instead mark it by voiding the $__
1347 if (value_lazy (last_examine_value))
1348 set_internalvar (lookup_internalvar ("__"),
1349 allocate_value (builtin_type_void));
1351 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1356 /* Add an expression to the auto-display chain.
1357 Specify the expression. */
1360 display_command (char *exp, int from_tty)
1362 struct format_data fmt;
1363 struct expression *expr;
1364 struct display *new;
1368 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1370 if (tui_active && exp != NULL && *exp == '$')
1371 display_it = (tui_set_layout_for_display_command (exp) == TUI_FAILURE);
1385 fmt = decode_format (&exp, 0, 0);
1386 if (fmt.size && fmt.format == 0)
1388 if (fmt.format == 'i' || fmt.format == 's')
1398 innermost_block = 0;
1399 expr = parse_expression (exp);
1401 new = (struct display *) xmalloc (sizeof (struct display));
1403 new->exp_string = xstrdup (exp);
1405 new->block = innermost_block;
1406 new->next = display_chain;
1407 new->number = ++display_number;
1410 display_chain = new;
1412 if (from_tty && target_has_execution)
1413 do_one_display (new);
1420 free_display (struct display *d)
1422 xfree (d->exp_string);
1427 /* Clear out the display_chain. Done when new symtabs are loaded,
1428 since this invalidates the types stored in many expressions. */
1431 clear_displays (void)
1435 while ((d = display_chain) != NULL)
1437 display_chain = d->next;
1442 /* Delete the auto-display number NUM. */
1445 delete_display (int num)
1447 struct display *d1, *d;
1450 error (_("No display number %d."), num);
1452 if (display_chain->number == num)
1455 display_chain = d1->next;
1459 for (d = display_chain;; d = d->next)
1462 error (_("No display number %d."), num);
1463 if (d->next->number == num)
1473 /* Delete some values from the auto-display chain.
1474 Specify the element numbers. */
1477 undisplay_command (char *args, int from_tty)
1485 if (query (_("Delete all auto-display expressions? ")))
1494 while (*p1 >= '0' && *p1 <= '9')
1496 if (*p1 && *p1 != ' ' && *p1 != '\t')
1497 error (_("Arguments must be display numbers."));
1501 delete_display (num);
1504 while (*p == ' ' || *p == '\t')
1510 /* Display a single auto-display.
1511 Do nothing if the display cannot be printed in the current context,
1512 or if the display is disabled. */
1515 do_one_display (struct display *d)
1517 int within_current_scope;
1519 if (d->enabled_p == 0)
1523 within_current_scope = contained_in (get_selected_block (0), d->block);
1525 within_current_scope = 1;
1526 if (!within_current_scope)
1529 current_display_number = d->number;
1531 annotate_display_begin ();
1532 printf_filtered ("%d", d->number);
1533 annotate_display_number_end ();
1534 printf_filtered (": ");
1540 annotate_display_format ();
1542 printf_filtered ("x/");
1543 if (d->format.count != 1)
1544 printf_filtered ("%d", d->format.count);
1545 printf_filtered ("%c", d->format.format);
1546 if (d->format.format != 'i' && d->format.format != 's')
1547 printf_filtered ("%c", d->format.size);
1548 printf_filtered (" ");
1550 annotate_display_expression ();
1552 puts_filtered (d->exp_string);
1553 annotate_display_expression_end ();
1555 if (d->format.count != 1 || d->format.format == 'i')
1556 printf_filtered ("\n");
1558 printf_filtered (" ");
1560 val = evaluate_expression (d->exp);
1561 addr = value_as_address (val);
1562 if (d->format.format == 'i')
1563 addr = gdbarch_addr_bits_remove (current_gdbarch, addr);
1565 annotate_display_value ();
1567 do_examine (d->format, addr);
1571 struct value_print_options opts;
1573 annotate_display_format ();
1575 if (d->format.format)
1576 printf_filtered ("/%c ", d->format.format);
1578 annotate_display_expression ();
1580 puts_filtered (d->exp_string);
1581 annotate_display_expression_end ();
1583 printf_filtered (" = ");
1585 annotate_display_expression ();
1587 get_formatted_print_options (&opts, d->format.format);
1588 print_formatted (evaluate_expression (d->exp),
1589 d->format.size, &opts, gdb_stdout);
1590 printf_filtered ("\n");
1593 annotate_display_end ();
1595 gdb_flush (gdb_stdout);
1596 current_display_number = -1;
1599 /* Display all of the values on the auto-display chain which can be
1600 evaluated in the current scope. */
1607 for (d = display_chain; d; d = d->next)
1611 /* Delete the auto-display which we were in the process of displaying.
1612 This is done when there is an error or a signal. */
1615 disable_display (int num)
1619 for (d = display_chain; d; d = d->next)
1620 if (d->number == num)
1625 printf_unfiltered (_("No display number %d.\n"), num);
1629 disable_current_display (void)
1631 if (current_display_number >= 0)
1633 disable_display (current_display_number);
1634 fprintf_unfiltered (gdb_stderr, _("\
1635 Disabling display %d to avoid infinite recursion.\n"),
1636 current_display_number);
1638 current_display_number = -1;
1642 display_info (char *ignore, int from_tty)
1647 printf_unfiltered (_("There are no auto-display expressions now.\n"));
1649 printf_filtered (_("Auto-display expressions now in effect:\n\
1650 Num Enb Expression\n"));
1652 for (d = display_chain; d; d = d->next)
1654 printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]);
1656 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1658 else if (d->format.format)
1659 printf_filtered ("/%c ", d->format.format);
1660 puts_filtered (d->exp_string);
1661 if (d->block && !contained_in (get_selected_block (0), d->block))
1662 printf_filtered (_(" (cannot be evaluated in the current context)"));
1663 printf_filtered ("\n");
1664 gdb_flush (gdb_stdout);
1669 enable_display (char *args, int from_tty)
1678 for (d = display_chain; d; d = d->next)
1685 while (*p1 >= '0' && *p1 <= '9')
1687 if (*p1 && *p1 != ' ' && *p1 != '\t')
1688 error (_("Arguments must be display numbers."));
1692 for (d = display_chain; d; d = d->next)
1693 if (d->number == num)
1698 printf_unfiltered (_("No display number %d.\n"), num);
1701 while (*p == ' ' || *p == '\t')
1707 disable_display_command (char *args, int from_tty)
1715 for (d = display_chain; d; d = d->next)
1722 while (*p1 >= '0' && *p1 <= '9')
1724 if (*p1 && *p1 != ' ' && *p1 != '\t')
1725 error (_("Arguments must be display numbers."));
1727 disable_display (atoi (p));
1730 while (*p == ' ' || *p == '\t')
1736 /* Print the value in stack frame FRAME of a variable specified by a
1737 struct symbol. NAME is the name to print; if NULL then VAR's print
1738 name will be used. STREAM is the ui_file on which to print the
1739 value. INDENT specifies the number of indent levels to print
1740 before printing the variable name. */
1743 print_variable_and_value (const char *name, struct symbol *var,
1744 struct frame_info *frame,
1745 struct ui_file *stream, int indent)
1748 struct value_print_options opts;
1751 name = SYMBOL_PRINT_NAME (var);
1753 fprintf_filtered (stream, "%s%s = ", n_spaces (2 * indent), name);
1755 val = read_var_value (var, frame);
1756 get_user_print_options (&opts);
1757 common_val_print (val, stream, indent, &opts, current_language);
1758 fprintf_filtered (stream, "\n");
1762 printf_command (char *arg, int from_tty)
1766 char *string = NULL;
1767 struct value **val_args;
1769 char *current_substring;
1771 int allocated_args = 20;
1772 struct cleanup *old_cleanups;
1774 val_args = xmalloc (allocated_args * sizeof (struct value *));
1775 old_cleanups = make_cleanup (free_current_contents, &val_args);
1778 error_no_arg (_("format-control string and values to print"));
1780 /* Skip white space before format string */
1781 while (*s == ' ' || *s == '\t')
1784 /* A format string should follow, enveloped in double quotes. */
1786 error (_("Bad format string, missing '\"'."));
1788 /* Parse the format-control string and copy it into the string STRING,
1789 processing some kinds of escape sequence. */
1791 f = string = (char *) alloca (strlen (s) + 1);
1799 error (_("Bad format string, non-terminated '\"'."));
1832 /* ??? TODO: handle other escape sequences */
1833 error (_("Unrecognized escape character \\%c in format string."),
1843 /* Skip over " and following space and comma. */
1846 while (*s == ' ' || *s == '\t')
1849 if (*s != ',' && *s != 0)
1850 error (_("Invalid argument syntax"));
1854 while (*s == ' ' || *s == '\t')
1857 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1858 substrings = alloca (strlen (string) * 2);
1859 current_substring = substrings;
1862 /* Now scan the string for %-specs and see what kinds of args they want.
1863 argclass[I] classifies the %-specs so we can give printf_filtered
1864 something of the right size. */
1868 int_arg, long_arg, long_long_arg, ptr_arg, string_arg,
1869 double_arg, long_double_arg, decfloat_arg
1871 enum argclass *argclass;
1872 enum argclass this_argclass;
1877 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1884 int seen_hash = 0, seen_zero = 0, lcount = 0, seen_prec = 0;
1885 int seen_space = 0, seen_plus = 0;
1886 int seen_big_l = 0, seen_h = 0, seen_big_h = 0;
1887 int seen_big_d = 0, seen_double_big_d = 0;
1890 /* Check the validity of the format specifier, and work
1891 out what argument it expects. We only accept C89
1892 format strings, with the exception of long long (which
1893 we autoconf for). */
1895 /* Skip over "%%". */
1902 /* The first part of a format specifier is a set of flag
1904 while (strchr ("0-+ #", *f))
1917 /* The next part of a format specifier is a width. */
1918 while (strchr ("0123456789", *f))
1921 /* The next part of a format specifier is a precision. */
1926 while (strchr ("0123456789", *f))
1930 /* The next part of a format specifier is a length modifier. */
1951 /* Decimal32 modifier. */
1957 /* Decimal64 and Decimal128 modifiers. */
1962 /* Check for a Decimal128. */
1966 seen_double_big_d = 1;
1982 if (seen_space || seen_plus)
1989 this_argclass = int_arg;
1990 else if (lcount == 1)
1991 this_argclass = long_arg;
1993 this_argclass = long_long_arg;
2000 this_argclass = int_arg;
2001 if (lcount || seen_h || seen_big_l)
2003 if (seen_prec || seen_zero || seen_space || seen_plus)
2008 this_argclass = ptr_arg;
2009 if (lcount || seen_h || seen_big_l)
2011 if (seen_prec || seen_zero || seen_space || seen_plus)
2016 this_argclass = string_arg;
2017 if (lcount || seen_h || seen_big_l)
2019 if (seen_zero || seen_space || seen_plus)
2028 if (seen_big_h || seen_big_d || seen_double_big_d)
2029 this_argclass = decfloat_arg;
2030 else if (seen_big_l)
2031 this_argclass = long_double_arg;
2033 this_argclass = double_arg;
2035 if (lcount || seen_h)
2040 error (_("`*' not supported for precision or width in printf"));
2043 error (_("Format specifier `n' not supported in printf"));
2046 error (_("Incomplete format specifier at end of format string"));
2049 error (_("Unrecognized format specifier '%c' in printf"), *f);
2053 error (_("Inappropriate modifiers to format specifier '%c' in printf"),
2058 if (lcount > 1 && USE_PRINTF_I64)
2060 /* Windows' printf does support long long, but not the usual way.
2061 Convert %lld to %I64d. */
2062 int length_before_ll = f - last_arg - 1 - lcount;
2063 strncpy (current_substring, last_arg, length_before_ll);
2064 strcpy (current_substring + length_before_ll, "I64");
2065 current_substring[length_before_ll + 3] =
2066 last_arg[length_before_ll + lcount];
2067 current_substring += length_before_ll + 4;
2071 strncpy (current_substring, last_arg, f - last_arg);
2072 current_substring += f - last_arg;
2074 *current_substring++ = '\0';
2076 argclass[nargs_wanted++] = this_argclass;
2079 /* Now, parse all arguments and evaluate them.
2080 Store the VALUEs in VAL_ARGS. */
2085 if (nargs == allocated_args)
2086 val_args = (struct value **) xrealloc ((char *) val_args,
2087 (allocated_args *= 2)
2088 * sizeof (struct value *));
2090 val_args[nargs] = parse_to_comma_and_eval (&s1);
2098 if (nargs != nargs_wanted)
2099 error (_("Wrong number of arguments for specified format-string"));
2101 /* Now actually print them. */
2102 current_substring = substrings;
2103 for (i = 0; i < nargs; i++)
2105 switch (argclass[i])
2112 tem = value_as_address (val_args[i]);
2114 /* This is a %s argument. Find the length of the string. */
2119 read_memory (tem + j, &c, 1);
2124 /* Copy the string contents into a string inside GDB. */
2125 str = (gdb_byte *) alloca (j + 1);
2127 read_memory (tem, str, j);
2130 printf_filtered (current_substring, (char *) str);
2135 struct type *type = value_type (val_args[i]);
2139 /* If format string wants a float, unchecked-convert the value
2140 to floating point of the same size. */
2141 type = float_type_from_length (current_gdbarch, type);
2142 val = unpack_double (type, value_contents (val_args[i]), &inv);
2144 error (_("Invalid floating value found in program."));
2146 printf_filtered (current_substring, (double) val);
2149 case long_double_arg:
2150 #ifdef HAVE_LONG_DOUBLE
2152 struct type *type = value_type (val_args[i]);
2156 /* If format string wants a float, unchecked-convert the value
2157 to floating point of the same size. */
2158 type = float_type_from_length (current_gdbarch, type);
2159 val = unpack_double (type, value_contents (val_args[i]), &inv);
2161 error (_("Invalid floating value found in program."));
2163 printf_filtered (current_substring, (long double) val);
2167 error (_("long double not supported in printf"));
2170 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2172 long long val = value_as_long (val_args[i]);
2173 printf_filtered (current_substring, val);
2177 error (_("long long not supported in printf"));
2181 int val = value_as_long (val_args[i]);
2182 printf_filtered (current_substring, val);
2187 long val = value_as_long (val_args[i]);
2188 printf_filtered (current_substring, val);
2192 /* Handles decimal floating values. */
2195 const gdb_byte *param_ptr = value_contents (val_args[i]);
2196 #if defined (PRINTF_HAS_DECFLOAT)
2197 /* If we have native support for Decimal floating
2198 printing, handle it here. */
2199 printf_filtered (current_substring, param_ptr);
2202 /* As a workaround until vasprintf has native support for DFP
2203 we convert the DFP values to string and print them using
2204 the %s format specifier. */
2207 int nnull_chars = 0;
2209 /* Parameter data. */
2210 struct type *param_type = value_type (val_args[i]);
2211 unsigned int param_len = TYPE_LENGTH (param_type);
2213 /* DFP output data. */
2214 struct value *dfp_value = NULL;
2218 struct type *dfp_type = NULL;
2219 char decstr[MAX_DECIMAL_STRING];
2221 /* Points to the end of the string so that we can go back
2222 and check for DFP length modifiers. */
2223 eos = current_substring + strlen (current_substring);
2225 /* Look for the float/double format specifier. */
2226 while (*eos != 'f' && *eos != 'e' && *eos != 'E'
2227 && *eos != 'g' && *eos != 'G')
2232 /* Search for the '%' char and extract the size and type of
2233 the output decimal value based on its modifiers
2234 (%Hf, %Df, %DDf). */
2235 while (*--sos != '%')
2240 dfp_type = builtin_type (current_gdbarch)->builtin_decfloat;
2242 else if (*sos == 'D' && *(sos - 1) == 'D')
2245 dfp_type = builtin_type (current_gdbarch)->builtin_declong;
2251 dfp_type = builtin_type (current_gdbarch)->builtin_decdouble;
2255 /* Replace %Hf, %Df and %DDf with %s's. */
2258 /* Go through the whole format string and pull the correct
2259 number of chars back to compensate for the change in the
2260 format specifier. */
2261 while (nnull_chars < nargs - i)
2269 /* Conversion between different DFP types. */
2270 if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT)
2271 decimal_convert (param_ptr, param_len, dec, dfp_len);
2273 /* If this is a non-trivial conversion, just output 0.
2274 A correct converted value can be displayed by explicitly
2275 casting to a DFP type. */
2276 decimal_from_string (dec, dfp_len, "0");
2278 dfp_value = value_from_decfloat (dfp_type, dec);
2280 dfp_ptr = (gdb_byte *) value_contents (dfp_value);
2282 decimal_to_string (dfp_ptr, dfp_len, decstr);
2284 /* Print the DFP value. */
2285 printf_filtered (current_substring, decstr);
2293 /* We avoid the host's %p because pointers are too
2294 likely to be the wrong size. The only interesting
2295 modifier for %p is a width; extract that, and then
2296 handle %p as glibc would: %#x or a literal "(nil)". */
2298 char *p, *fmt, *fmt_p;
2299 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2300 long long val = value_as_long (val_args[i]);
2302 long val = value_as_long (val_args[i]);
2305 fmt = alloca (strlen (current_substring) + 5);
2307 /* Copy up to the leading %. */
2308 p = current_substring;
2312 int is_percent = (*p == '%');
2326 /* Copy any width. */
2327 while (*p >= '0' && *p < '9')
2330 gdb_assert (*p == 'p' && *(p + 1) == '\0');
2333 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2339 printf_filtered (fmt, val);
2345 printf_filtered (fmt, "(nil)");
2351 internal_error (__FILE__, __LINE__,
2352 _("failed internal consistency check"));
2354 /* Skip to the next substring. */
2355 current_substring += strlen (current_substring) + 1;
2357 /* Print the portion of the format string after the last argument. */
2358 puts_filtered (last_arg);
2360 do_cleanups (old_cleanups);
2364 _initialize_printcmd (void)
2366 struct cmd_list_element *c;
2368 current_display_number = -1;
2370 add_info ("address", address_info,
2371 _("Describe where symbol SYM is stored."));
2373 add_info ("symbol", sym_info, _("\
2374 Describe what symbol is at location ADDR.\n\
2375 Only for symbols with fixed locations (global or static scope)."));
2377 add_com ("x", class_vars, x_command, _("\
2378 Examine memory: x/FMT ADDRESS.\n\
2379 ADDRESS is an expression for the memory address to examine.\n\
2380 FMT is a repeat count followed by a format letter and a size letter.\n\
2381 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2382 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2383 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2384 The specified number of objects of the specified size are printed\n\
2385 according to the format.\n\n\
2386 Defaults for format and size letters are those previously used.\n\
2387 Default count is 1. Default address is following last thing printed\n\
2388 with this command or \"print\"."));
2391 add_com ("whereis", class_vars, whereis_command,
2392 _("Print line number and file of definition of variable."));
2395 add_info ("display", display_info, _("\
2396 Expressions to display when program stops, with code numbers."));
2398 add_cmd ("undisplay", class_vars, undisplay_command, _("\
2399 Cancel some expressions to be displayed when program stops.\n\
2400 Arguments are the code numbers of the expressions to stop displaying.\n\
2401 No argument means cancel all automatic-display expressions.\n\
2402 \"delete display\" has the same effect as this command.\n\
2403 Do \"info display\" to see current list of code numbers."),
2406 add_com ("display", class_vars, display_command, _("\
2407 Print value of expression EXP each time the program stops.\n\
2408 /FMT may be used before EXP as in the \"print\" command.\n\
2409 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2410 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2411 and examining is done as in the \"x\" command.\n\n\
2412 With no argument, display all currently requested auto-display expressions.\n\
2413 Use \"undisplay\" to cancel display requests previously made."));
2415 add_cmd ("display", class_vars, enable_display, _("\
2416 Enable some expressions to be displayed when program stops.\n\
2417 Arguments are the code numbers of the expressions to resume displaying.\n\
2418 No argument means enable all automatic-display expressions.\n\
2419 Do \"info display\" to see current list of code numbers."), &enablelist);
2421 add_cmd ("display", class_vars, disable_display_command, _("\
2422 Disable some expressions to be displayed when program stops.\n\
2423 Arguments are the code numbers of the expressions to stop displaying.\n\
2424 No argument means disable all automatic-display expressions.\n\
2425 Do \"info display\" to see current list of code numbers."), &disablelist);
2427 add_cmd ("display", class_vars, undisplay_command, _("\
2428 Cancel some expressions to be displayed when program stops.\n\
2429 Arguments are the code numbers of the expressions to stop displaying.\n\
2430 No argument means cancel all automatic-display expressions.\n\
2431 Do \"info display\" to see current list of code numbers."), &deletelist);
2433 add_com ("printf", class_vars, printf_command, _("\
2434 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2435 This is useful for formatted output in user-defined commands."));
2437 add_com ("output", class_vars, output_command, _("\
2438 Like \"print\" but don't put in value history and don't print newline.\n\
2439 This is useful in user-defined commands."));
2441 add_prefix_cmd ("set", class_vars, set_command, _("\
2442 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2443 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2444 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2445 with $), a register (a few standard names starting with $), or an actual\n\
2446 variable in the program being debugged. EXP is any valid expression.\n\
2447 Use \"set variable\" for variables with names identical to set subcommands.\n\
2449 With a subcommand, this command modifies parts of the gdb environment.\n\
2450 You can see these environment settings with the \"show\" command."),
2451 &setlist, "set ", 1, &cmdlist);
2453 add_com ("assign", class_vars, set_command, _("\
2454 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2455 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2456 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2457 with $), a register (a few standard names starting with $), or an actual\n\
2458 variable in the program being debugged. EXP is any valid expression.\n\
2459 Use \"set variable\" for variables with names identical to set subcommands.\n\
2460 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2461 You can see these environment settings with the \"show\" command."));
2463 /* "call" is the same as "set", but handy for dbx users to call fns. */
2464 c = add_com ("call", class_vars, call_command, _("\
2465 Call a function in the program.\n\
2466 The argument is the function name and arguments, in the notation of the\n\
2467 current working language. The result is printed and saved in the value\n\
2468 history, if it is not void."));
2469 set_cmd_completer (c, expression_completer);
2471 add_cmd ("variable", class_vars, set_command, _("\
2472 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2473 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2474 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2475 with $), a register (a few standard names starting with $), or an actual\n\
2476 variable in the program being debugged. EXP is any valid expression.\n\
2477 This may usually be abbreviated to simply \"set\"."),
2480 c = add_com ("print", class_vars, print_command, _("\
2481 Print value of expression EXP.\n\
2482 Variables accessible are those of the lexical environment of the selected\n\
2483 stack frame, plus all those whose scope is global or an entire file.\n\
2485 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2486 $$NUM refers to NUM'th value back from the last one.\n\
2487 Names starting with $ refer to registers (with the values they would have\n\
2488 if the program were to return to the stack frame now selected, restoring\n\
2489 all registers saved by frames farther in) or else to debugger\n\
2490 \"convenience\" variables (any such name not a known register).\n\
2491 Use assignment expressions to give values to convenience variables.\n\
2493 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2494 @ is a binary operator for treating consecutive data objects\n\
2495 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2496 element is FOO, whose second element is stored in the space following\n\
2497 where FOO is stored, etc. FOO must be an expression whose value\n\
2498 resides in memory.\n\
2500 EXP may be preceded with /FMT, where FMT is a format letter\n\
2501 but no count or size letter (see \"x\" command)."));
2502 set_cmd_completer (c, expression_completer);
2503 add_com_alias ("p", "print", class_vars, 1);
2505 c = add_com ("inspect", class_vars, inspect_command, _("\
2506 Same as \"print\" command, except that if you are running in the epoch\n\
2507 environment, the value is printed in its own window."));
2508 set_cmd_completer (c, expression_completer);
2510 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
2511 &max_symbolic_offset, _("\
2512 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2513 Show the largest offset that will be printed in <symbol+1234> form."), NULL,
2515 show_max_symbolic_offset,
2516 &setprintlist, &showprintlist);
2517 add_setshow_boolean_cmd ("symbol-filename", no_class,
2518 &print_symbol_filename, _("\
2519 Set printing of source filename and line number with <symbol>."), _("\
2520 Show printing of source filename and line number with <symbol>."), NULL,
2522 show_print_symbol_filename,
2523 &setprintlist, &showprintlist);
2525 /* For examine/instruction a single byte quantity is specified as
2526 the data. This avoids problems with value_at_lazy() requiring a
2527 valid data type (and rejecting VOID). */
2528 examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
2530 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2531 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2532 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2533 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);