1 /* Print values for GNU debugger GDB.
2 Copyright 1986, 87, 88, 89, 90, 91, 93, 94, 95, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
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 */
40 extern int asm_demangle; /* Whether to demangle syms in asm printouts */
41 extern int addressprint; /* Whether to print hex addresses in HLL " */
50 /* Last specified output format. */
52 static char last_format = 'x';
54 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
56 static char last_size = 'w';
58 /* Default address to examine next. */
60 static CORE_ADDR next_address;
62 /* Default section to examine next. */
64 static asection *next_section;
66 /* Last address examined. */
68 static CORE_ADDR last_examine_address;
70 /* Contents of last address examined.
71 This is not valid past the end of the `x' command! */
73 static value_ptr last_examine_value;
75 /* Largest offset between a symbolic value and an address, that will be
76 printed as `0x1234 <symbol+offset>'. */
78 static unsigned int max_symbolic_offset = UINT_MAX;
80 /* Append the source filename and linenumber of the symbol when
81 printing a symbolic value as `<symbol at filename:linenum>' if set. */
82 static int print_symbol_filename = 0;
84 /* Number of auto-display expression currently being displayed.
85 So that we can disable it if we get an error or a signal within it.
86 -1 when not doing one. */
88 int current_display_number;
90 /* Flag to low-level print routines that this value is being printed
91 in an epoch window. We'd like to pass this as a parameter, but
92 every routine would need to take it. Perhaps we can encapsulate
93 this in the I/O stream once we have GNU stdio. */
99 /* Chain link to next auto-display item. */
100 struct display *next;
101 /* Expression to be evaluated and displayed. */
102 struct expression *exp;
103 /* Item number of this auto-display item. */
105 /* Display format specified. */
106 struct format_data format;
107 /* Innermost block required by this expression when evaluated */
109 /* Status of this display (enabled or disabled) */
113 /* Chain of expressions whose values should be displayed
114 automatically each time the program stops. */
116 static struct display *display_chain;
118 static int display_number;
120 /* Prototypes for exported functions. */
122 void output_command PARAMS ((char *, int));
124 void _initialize_printcmd PARAMS ((void));
126 /* Prototypes for local functions. */
128 static void delete_display PARAMS ((int));
130 static void enable_display PARAMS ((char *, int));
132 static void disable_display_command PARAMS ((char *, int));
134 static void disassemble_command PARAMS ((char *, int));
136 static void printf_command PARAMS ((char *, int));
138 static void print_frame_nameless_args PARAMS ((struct frame_info *, long,
139 int, int, GDB_FILE *));
141 static void display_info PARAMS ((char *, int));
143 static void do_one_display PARAMS ((struct display *));
145 static void undisplay_command PARAMS ((char *, int));
147 static void free_display PARAMS ((struct display *));
149 static void display_command PARAMS ((char *, int));
151 void x_command PARAMS ((char *, int));
153 static void address_info PARAMS ((char *, int));
155 static void set_command PARAMS ((char *, int));
157 static void call_command PARAMS ((char *, int));
159 static void inspect_command PARAMS ((char *, int));
161 static void print_command PARAMS ((char *, int));
163 static void print_command_1 PARAMS ((char *, int, int));
165 static void validate_format PARAMS ((struct format_data, char *));
167 static void do_examine PARAMS ((struct format_data, CORE_ADDR addr, asection * section));
169 static void print_formatted PARAMS ((value_ptr, int, int));
171 static struct format_data decode_format PARAMS ((char **, int, int));
173 static int print_insn PARAMS ((CORE_ADDR, GDB_FILE *));
175 static void sym_info PARAMS ((char *, int));
178 /* Decode a format specification. *STRING_PTR should point to it.
179 OFORMAT and OSIZE are used as defaults for the format and size
180 if none are given in the format specification.
181 If OSIZE is zero, then the size field of the returned value
182 should be set only if a size is explicitly specified by the
184 The structure returned describes all the data
185 found in the specification. In addition, *STRING_PTR is advanced
186 past the specification and past all whitespace following it. */
188 static struct format_data
189 decode_format (string_ptr, oformat, osize)
194 struct format_data val;
195 register char *p = *string_ptr;
201 if (*p >= '0' && *p <= '9')
202 val.count = atoi (p);
203 while (*p >= '0' && *p <= '9')
206 /* Now process size or format letters that follow. */
210 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
212 else if (*p >= 'a' && *p <= 'z')
218 while (*p == ' ' || *p == '\t')
222 /* Set defaults for format and size if not specified. */
223 if (val.format == '?')
227 /* Neither has been specified. */
228 val.format = oformat;
232 /* If a size is specified, any format makes a reasonable
233 default except 'i'. */
234 val.format = oformat == 'i' ? 'x' : oformat;
236 else if (val.size == '?')
241 /* Pick the appropriate size for an address. */
242 if (TARGET_PTR_BIT == 64)
243 val.size = osize ? 'g' : osize;
244 else if (TARGET_PTR_BIT == 32)
245 val.size = osize ? 'w' : osize;
246 else if (TARGET_PTR_BIT == 16)
247 val.size = osize ? 'h' : osize;
249 /* Bad value for TARGET_PTR_BIT */
253 /* Floating point has to be word or giantword. */
254 if (osize == 'w' || osize == 'g')
257 /* Default it to giantword if the last used size is not
259 val.size = osize ? 'g' : osize;
262 /* Characters default to one byte. */
263 val.size = osize ? 'b' : osize;
266 /* The default is the size most recently specified. */
273 /* Print value VAL on gdb_stdout according to FORMAT, a letter or 0.
274 Do not end with a newline.
275 0 means print VAL according to its own type.
276 SIZE is the letter for the size of datum being printed.
277 This is used to pad hex numbers so they line up. */
280 print_formatted (val, format, size)
281 register value_ptr val;
285 struct type *type = check_typedef (VALUE_TYPE (val));
286 int len = TYPE_LENGTH (type);
288 if (VALUE_LVAL (val) == lval_memory)
290 next_address = VALUE_ADDRESS (val) + len;
291 next_section = VALUE_BFD_SECTION (val);
297 /* FIXME: Need to handle wchar_t's here... */
298 next_address = VALUE_ADDRESS (val)
299 + val_print_string (VALUE_ADDRESS (val), -1, 1, gdb_stdout);
300 next_section = VALUE_BFD_SECTION (val);
304 /* The old comment says
305 "Force output out, print_insn not using _filtered".
306 I'm not completely sure what that means, I suspect most print_insn
307 now do use _filtered, so I guess it's obsolete.
308 --Yes, it does filter now, and so this is obsolete. -JB */
310 /* We often wrap here if there are long symbolic names. */
312 next_address = VALUE_ADDRESS (val)
313 + print_insn (VALUE_ADDRESS (val), gdb_stdout);
314 next_section = VALUE_BFD_SECTION (val);
319 || TYPE_CODE (type) == TYPE_CODE_ARRAY
320 || TYPE_CODE (type) == TYPE_CODE_STRING
321 || TYPE_CODE (type) == TYPE_CODE_STRUCT
322 || TYPE_CODE (type) == TYPE_CODE_UNION)
323 /* If format is 0, use the 'natural' format for
324 * that type of value. If the type is non-scalar,
325 * we have to use language rules to print it as
326 * a series of scalars.
328 value_print (val, gdb_stdout, format, Val_pretty_default);
330 /* User specified format, so don't look to the
331 * the type to tell us what to do.
333 print_scalar_formatted (VALUE_CONTENTS (val), type,
334 format, size, gdb_stdout);
338 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
339 according to letters FORMAT and SIZE on STREAM.
340 FORMAT may not be zero. Formats s and i are not supported at this level.
342 This is how the elements of an array or structure are printed
346 print_scalar_formatted (valaddr, type, format, size, stream)
354 unsigned int len = TYPE_LENGTH (type);
356 if (len > sizeof (LONGEST)
364 if (!TYPE_UNSIGNED (type)
365 || !extract_long_unsigned_integer (valaddr, len, &val_long))
367 /* We can't print it normally, but we can print it in hex.
368 Printing it in the wrong radix is more useful than saying
369 "use /x, you dummy". */
370 /* FIXME: we could also do octal or binary if that was the
372 /* FIXME: we should be using the size field to give us a
373 minimum field width to print. */
376 print_octal_chars (stream, valaddr, len);
377 else if (format == 'd')
378 print_decimal_chars (stream, valaddr, len);
379 else if (format == 't')
380 print_binary_chars (stream, valaddr, len);
382 /* replace with call to print_hex_chars? Looks
383 like val_print_type_code_int is redoing
386 val_print_type_code_int (type, valaddr, stream);
391 /* If we get here, extract_long_unsigned_integer set val_long. */
393 else if (format != 'f')
394 val_long = unpack_long (type, valaddr);
396 /* If we are printing it as unsigned, truncate it in case it is actually
397 a negative signed value (e.g. "print/u (short)-1" should print 65535
398 (if shorts are 16 bits) instead of 4294967295). */
401 if (len < sizeof (LONGEST))
402 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
410 /* no size specified, like in print. Print varying # of digits. */
411 print_longest (stream, 'x', 1, val_long);
420 print_longest (stream, size, 1, val_long);
423 error ("Undefined output size \"%c\".", size);
428 print_longest (stream, 'd', 1, val_long);
432 print_longest (stream, 'u', 0, val_long);
437 print_longest (stream, 'o', 1, val_long);
439 fprintf_filtered (stream, "0");
443 print_address (unpack_pointer (type, valaddr), stream);
447 value_print (value_from_longest (builtin_type_true_char, val_long),
448 stream, 0, Val_pretty_default);
452 if (len == sizeof (float))
453 type = builtin_type_float;
454 else if (len == sizeof (double))
455 type = builtin_type_double;
456 print_floating (valaddr, type, stream);
463 /* Binary; 't' stands for "two". */
465 char bits[8 * (sizeof val_long) + 1];
466 char buf[8 * (sizeof val_long) + 32];
471 width = 8 * (sizeof val_long);
488 error ("Undefined output size \"%c\".", size);
494 bits[width] = (val_long & 1) ? '1' : '0';
499 while (*cp && *cp == '0')
504 strcpy (buf, local_binary_format_prefix ());
506 strcat (buf, local_binary_format_suffix ());
507 fprintf_filtered (stream, buf);
512 error ("Undefined output format \"%c\".", format);
516 /* Specify default address for `x' command.
517 `info lines' uses this. */
520 set_next_address (addr)
525 /* Make address available to the user as $_. */
526 set_internalvar (lookup_internalvar ("_"),
527 value_from_longest (lookup_pointer_type (builtin_type_void),
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 (addr, stream, do_demangle, leadin)
546 struct minimal_symbol *msymbol;
547 struct symbol *symbol;
548 struct symtab *symtab = 0;
549 CORE_ADDR name_location = 0;
551 asection *section = 0;
554 /* Determine if the address is in an overlay, and whether it is mapped. */
555 if (overlay_debugging)
557 section = find_pc_overlay (addr);
558 if (pc_in_unmapped_range (addr, section))
561 addr = overlay_mapped_address (addr, section);
565 /* On some targets, add in extra "flag" bits to PC for
566 disassembly. This should ensure that "rounding errors" in
567 symbol addresses that are masked for disassembly favour the
568 the correct symbol. */
570 #ifdef GDB_TARGET_UNMASK_DISAS_PC
571 addr = GDB_TARGET_UNMASK_DISAS_PC (addr);
574 /* First try to find the address in the symbol table, then
575 in the minsyms. Take the closest one. */
577 /* This is defective in the sense that it only finds text symbols. So
578 really this is kind of pointless--we should make sure that the
579 minimal symbols have everything we need (by changing that we could
580 save some memory, but for many debug format--ELF/DWARF or
581 anything/stabs--it would be inconvenient to eliminate those minimal
583 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
584 symbol = find_pc_sect_function (addr, section);
588 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
590 name = SYMBOL_SOURCE_NAME (symbol);
592 name = SYMBOL_LINKAGE_NAME (symbol);
597 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
599 /* The msymbol is closer to the address than the symbol;
600 use the msymbol instead. */
603 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
605 name = SYMBOL_SOURCE_NAME (msymbol);
607 name = SYMBOL_LINKAGE_NAME (msymbol);
610 if (symbol == NULL && msymbol == NULL)
613 /* On some targets, mask out extra "flag" bits from PC for handsome
616 #ifdef GDB_TARGET_MASK_DISAS_PC
617 name_location = GDB_TARGET_MASK_DISAS_PC (name_location);
618 addr = GDB_TARGET_MASK_DISAS_PC (addr);
621 /* If the nearest symbol is too far away, don't print anything symbolic. */
623 /* For when CORE_ADDR is larger than unsigned int, we do math in
624 CORE_ADDR. But when we detect unsigned wraparound in the
625 CORE_ADDR math, we ignore this test and print the offset,
626 because addr+max_symbolic_offset has wrapped through the end
627 of the address space back to the beginning, giving bogus comparison. */
628 if (addr > name_location + max_symbolic_offset
629 && name_location + max_symbolic_offset > name_location)
632 fputs_filtered (leadin, stream);
634 fputs_filtered ("<*", stream);
636 fputs_filtered ("<", stream);
637 fputs_filtered (name, stream);
638 if (addr != name_location)
639 fprintf_filtered (stream, "+%u", (unsigned int) (addr - name_location));
641 /* Append source filename and line number if desired. Give specific
642 line # of this addr, if we have it; else line # of the nearest symbol. */
643 if (print_symbol_filename)
645 struct symtab_and_line sal;
647 sal = find_pc_sect_line (addr, section, 0);
650 fprintf_filtered (stream, " at %s:%d", sal.symtab->filename, sal.line);
651 else if (symtab && symbol && symbol->line)
652 fprintf_filtered (stream, " at %s:%d", symtab->filename, symbol->line);
654 fprintf_filtered (stream, " in %s", symtab->filename);
657 fputs_filtered ("*>", stream);
659 fputs_filtered (">", stream);
663 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
666 print_address_numeric (addr, use_local, stream)
671 /* This assumes a CORE_ADDR can fit in a LONGEST. Probably a safe
673 print_longest (stream, 'x', use_local, (ULONGEST) addr);
676 /* Print address ADDR symbolically on STREAM.
677 First print it as a number. Then perhaps print
678 <SYMBOL + OFFSET> after the number. */
681 print_address (addr, stream)
685 print_address_numeric (addr, 1, stream);
686 print_address_symbolic (addr, stream, asm_demangle, " ");
689 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
690 controls whether to print the symbolic name "raw" or demangled.
691 Global setting "addressprint" controls whether to print hex address
695 print_address_demangle (addr, stream, do_demangle)
702 fprintf_filtered (stream, "0");
704 else if (addressprint)
706 print_address_numeric (addr, 1, stream);
707 print_address_symbolic (addr, stream, do_demangle, " ");
711 print_address_symbolic (addr, stream, do_demangle, "");
716 /* These are the types that $__ will get after an examine command of one
719 static struct type *examine_i_type;
721 static struct type *examine_b_type;
722 static struct type *examine_h_type;
723 static struct type *examine_w_type;
724 static struct type *examine_g_type;
726 /* Examine data at address ADDR in format FMT.
727 Fetch it from memory and print on gdb_stdout. */
730 do_examine (fmt, addr, sect)
731 struct format_data fmt;
735 register char format = 0;
737 register int count = 1;
738 struct type *val_type = NULL;
740 register int maxelts;
748 /* String or instruction format implies fetch single bytes
749 regardless of the specified size. */
750 if (format == 's' || format == 'i')
754 val_type = examine_i_type;
755 else if (size == 'b')
756 val_type = examine_b_type;
757 else if (size == 'h')
758 val_type = examine_h_type;
759 else if (size == 'w')
760 val_type = examine_w_type;
761 else if (size == 'g')
762 val_type = examine_g_type;
769 if (format == 's' || format == 'i')
772 /* Print as many objects as specified in COUNT, at most maxelts per line,
773 with the address of the next one at the start of each line. */
778 print_address (next_address, gdb_stdout);
779 printf_filtered (":");
784 printf_filtered ("\t");
785 /* Note that print_formatted sets next_address for the next
787 last_examine_address = next_address;
789 if (last_examine_value)
790 value_free (last_examine_value);
792 /* The value to be displayed is not fetched greedily.
793 Instead, to avoid the posibility of a fetched value not
794 being used, its retreval is delayed until the print code
795 uses it. When examining an instruction stream, the
796 disassembler will perform its own memory fetch using just
797 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
798 the disassembler be modified so that LAST_EXAMINE_VALUE
799 is left with the byte sequence from the last complete
800 instruction fetched from memory? */
801 last_examine_value = value_at_lazy (val_type, next_address, sect);
803 if (last_examine_value)
804 release_value (last_examine_value);
806 print_formatted (last_examine_value, format, size);
808 printf_filtered ("\n");
809 gdb_flush (gdb_stdout);
814 validate_format (fmt, cmdname)
815 struct format_data fmt;
819 error ("Size letters are meaningless in \"%s\" command.", cmdname);
821 error ("Item count other than 1 is meaningless in \"%s\" command.",
823 if (fmt.format == 'i' || fmt.format == 's')
824 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
825 fmt.format, cmdname);
828 /* Evaluate string EXP as an expression in the current language and
829 print the resulting value. EXP may contain a format specifier as the
830 first argument ("/x myvar" for example, to print myvar in hex).
834 print_command_1 (exp, inspect, voidprint)
839 struct expression *expr;
840 register struct cleanup *old_chain = 0;
841 register char format = 0;
842 register value_ptr val;
843 struct format_data fmt;
846 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
847 inspect_it = inspect;
849 if (exp && *exp == '/')
852 fmt = decode_format (&exp, last_format, 0);
853 validate_format (fmt, "print");
854 last_format = format = fmt.format;
866 expr = parse_expression (exp);
867 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
870 val = evaluate_expression (expr);
872 /* C++: figure out what type we actually want to print it as. */
873 type = VALUE_TYPE (val);
876 && (TYPE_CODE (type) == TYPE_CODE_PTR
877 || TYPE_CODE (type) == TYPE_CODE_REF)
878 && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT
879 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION))
883 v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
887 type = VALUE_TYPE (val);
892 val = access_value_history (0);
894 if (voidprint || (val && VALUE_TYPE (val) &&
895 TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
897 int histindex = record_latest_value (val);
900 annotate_value_history_begin (histindex, VALUE_TYPE (val));
902 annotate_value_begin (VALUE_TYPE (val));
905 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
906 else if (histindex >= 0)
907 printf_filtered ("$%d = ", histindex);
910 annotate_value_history_value ();
912 print_formatted (val, format, fmt.size);
913 printf_filtered ("\n");
916 annotate_value_history_end ();
918 annotate_value_end ();
921 printf_unfiltered ("\") )\030");
925 do_cleanups (old_chain);
926 inspect_it = 0; /* Reset print routines to normal */
931 print_command (exp, from_tty)
935 print_command_1 (exp, 0, 1);
938 /* Same as print, except in epoch, it gets its own window */
941 inspect_command (exp, from_tty)
945 extern int epoch_interface;
947 print_command_1 (exp, epoch_interface, 1);
950 /* Same as print, except it doesn't print void results. */
953 call_command (exp, from_tty)
957 print_command_1 (exp, 0, 0);
962 output_command (exp, from_tty)
966 struct expression *expr;
967 register struct cleanup *old_chain;
968 register char format = 0;
969 register value_ptr val;
970 struct format_data fmt;
972 if (exp && *exp == '/')
975 fmt = decode_format (&exp, 0, 0);
976 validate_format (fmt, "output");
980 expr = parse_expression (exp);
981 old_chain = make_cleanup ((make_cleanup_func) free_current_contents, &expr);
983 val = evaluate_expression (expr);
985 annotate_value_begin (VALUE_TYPE (val));
987 print_formatted (val, format, fmt.size);
989 annotate_value_end ();
991 do_cleanups (old_chain);
996 set_command (exp, from_tty)
1000 struct expression *expr = parse_expression (exp);
1001 register struct cleanup *old_chain
1002 = make_cleanup ((make_cleanup_func) free_current_contents, &expr);
1003 evaluate_expression (expr);
1004 do_cleanups (old_chain);
1009 sym_info (arg, from_tty)
1013 struct minimal_symbol *msymbol;
1014 struct objfile *objfile;
1015 struct obj_section *osect;
1017 CORE_ADDR addr, sect_addr;
1019 unsigned int offset;
1022 error_no_arg ("address");
1024 addr = parse_and_eval_address (arg);
1025 ALL_OBJSECTIONS (objfile, osect)
1027 sect = osect->the_bfd_section;
1028 sect_addr = overlay_mapped_address (addr, sect);
1030 if (osect->addr <= sect_addr && sect_addr < osect->endaddr &&
1031 (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect)))
1034 offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
1036 printf_filtered ("%s + %u in ",
1037 SYMBOL_SOURCE_NAME (msymbol), offset);
1039 printf_filtered ("%s in ",
1040 SYMBOL_SOURCE_NAME (msymbol));
1041 if (pc_in_unmapped_range (addr, sect))
1042 printf_filtered ("load address range of ");
1043 if (section_is_overlay (sect))
1044 printf_filtered ("%s overlay ",
1045 section_is_mapped (sect) ? "mapped" : "unmapped");
1046 printf_filtered ("section %s", sect->name);
1047 printf_filtered ("\n");
1051 printf_filtered ("No symbol matches %s.\n", arg);
1056 address_info (exp, from_tty)
1060 register struct symbol *sym;
1061 register struct minimal_symbol *msymbol;
1063 register long basereg;
1065 CORE_ADDR load_addr;
1066 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
1067 if exp is a field of `this'. */
1070 error ("Argument required.");
1072 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
1073 &is_a_field_of_this, (struct symtab **) NULL);
1076 if (is_a_field_of_this)
1078 printf_filtered ("Symbol \"");
1079 fprintf_symbol_filtered (gdb_stdout, exp,
1080 current_language->la_language, DMGL_ANSI);
1081 printf_filtered ("\" is a field of the local class variable `this'\n");
1085 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1087 if (msymbol != NULL)
1089 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1091 printf_filtered ("Symbol \"");
1092 fprintf_symbol_filtered (gdb_stdout, exp,
1093 current_language->la_language, DMGL_ANSI);
1094 printf_filtered ("\" is at ");
1095 print_address_numeric (load_addr, 1, gdb_stdout);
1096 printf_filtered (" in a file compiled without debugging");
1097 section = SYMBOL_BFD_SECTION (msymbol);
1098 if (section_is_overlay (section))
1100 load_addr = overlay_unmapped_address (load_addr, section);
1101 printf_filtered (",\n -- loaded at ");
1102 print_address_numeric (load_addr, 1, gdb_stdout);
1103 printf_filtered (" in overlay section %s", section->name);
1105 printf_filtered (".\n");
1108 error ("No symbol \"%s\" in current context.", exp);
1112 printf_filtered ("Symbol \"");
1113 fprintf_symbol_filtered (gdb_stdout, SYMBOL_NAME (sym),
1114 current_language->la_language, DMGL_ANSI);
1115 printf_filtered ("\" is ");
1116 val = SYMBOL_VALUE (sym);
1117 basereg = SYMBOL_BASEREG (sym);
1118 section = SYMBOL_BFD_SECTION (sym);
1120 switch (SYMBOL_CLASS (sym))
1123 case LOC_CONST_BYTES:
1124 printf_filtered ("constant");
1128 printf_filtered ("a label at address ");
1129 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1131 if (section_is_overlay (section))
1133 load_addr = overlay_unmapped_address (load_addr, section);
1134 printf_filtered (",\n -- loaded at ");
1135 print_address_numeric (load_addr, 1, gdb_stdout);
1136 printf_filtered (" in overlay section %s", section->name);
1141 printf_filtered ("a variable in register %s", REGISTER_NAME (val));
1145 printf_filtered ("static storage at address ");
1146 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1148 if (section_is_overlay (section))
1150 load_addr = overlay_unmapped_address (load_addr, section);
1151 printf_filtered (",\n -- loaded at ");
1152 print_address_numeric (load_addr, 1, gdb_stdout);
1153 printf_filtered (" in overlay section %s", section->name);
1158 printf_filtered ("external global (indirect addressing), at address *(");
1159 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1161 printf_filtered (")");
1162 if (section_is_overlay (section))
1164 load_addr = overlay_unmapped_address (load_addr, section);
1165 printf_filtered (",\n -- loaded at ");
1166 print_address_numeric (load_addr, 1, gdb_stdout);
1167 printf_filtered (" in overlay section %s", section->name);
1172 printf_filtered ("an argument in register %s", REGISTER_NAME (val));
1175 case LOC_REGPARM_ADDR:
1176 printf_filtered ("address of an argument in register %s", REGISTER_NAME (val));
1180 printf_filtered ("an argument at offset %ld", val);
1184 printf_filtered ("an argument at frame offset %ld", val);
1188 printf_filtered ("a local variable at frame offset %ld", val);
1192 printf_filtered ("a reference argument at offset %ld", val);
1196 printf_filtered ("a variable at offset %ld from register %s",
1197 val, REGISTER_NAME (basereg));
1200 case LOC_BASEREG_ARG:
1201 printf_filtered ("an argument at offset %ld from register %s",
1202 val, REGISTER_NAME (basereg));
1206 printf_filtered ("a typedef");
1210 printf_filtered ("a function at address ");
1211 #ifdef GDB_TARGET_MASK_DISAS_PC
1212 print_address_numeric
1213 (load_addr = GDB_TARGET_MASK_DISAS_PC (BLOCK_START (SYMBOL_BLOCK_VALUE (sym))),
1216 print_address_numeric (load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)),
1219 if (section_is_overlay (section))
1221 load_addr = overlay_unmapped_address (load_addr, section);
1222 printf_filtered (",\n -- loaded at ");
1223 print_address_numeric (load_addr, 1, gdb_stdout);
1224 printf_filtered (" in overlay section %s", section->name);
1228 case LOC_UNRESOLVED:
1230 struct minimal_symbol *msym;
1232 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, NULL);
1234 printf_filtered ("unresolved");
1237 section = SYMBOL_BFD_SECTION (msym);
1238 printf_filtered ("static storage at address ");
1239 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (msym),
1241 if (section_is_overlay (section))
1243 load_addr = overlay_unmapped_address (load_addr, section);
1244 printf_filtered (",\n -- loaded at ");
1245 print_address_numeric (load_addr, 1, gdb_stdout);
1246 printf_filtered (" in overlay section %s", section->name);
1252 case LOC_THREAD_LOCAL_STATIC:
1254 "a thread-local variable at offset %ld from the thread base register %s",
1255 val, REGISTER_NAME (basereg));
1258 case LOC_OPTIMIZED_OUT:
1259 printf_filtered ("optimized out");
1263 printf_filtered ("of unknown (botched) type");
1266 printf_filtered (".\n");
1270 x_command (exp, from_tty)
1274 struct expression *expr;
1275 struct format_data fmt;
1276 struct cleanup *old_chain;
1279 fmt.format = last_format;
1280 fmt.size = last_size;
1283 if (exp && *exp == '/')
1286 fmt = decode_format (&exp, last_format, last_size);
1289 /* If we have an expression, evaluate it and use it as the address. */
1291 if (exp != 0 && *exp != 0)
1293 expr = parse_expression (exp);
1294 /* Cause expression not to be there any more
1295 if this command is repeated with Newline.
1296 But don't clobber a user-defined command's definition. */
1299 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
1301 val = evaluate_expression (expr);
1302 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
1303 val = value_ind (val);
1304 /* In rvalue contexts, such as this, functions are coerced into
1305 pointers to functions. This makes "x/i main" work. */
1306 if ( /* last_format == 'i'
1307 && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
1308 && VALUE_LVAL (val) == lval_memory)
1309 next_address = VALUE_ADDRESS (val);
1311 next_address = value_as_pointer (val);
1312 if (VALUE_BFD_SECTION (val))
1313 next_section = VALUE_BFD_SECTION (val);
1314 do_cleanups (old_chain);
1317 do_examine (fmt, next_address, next_section);
1319 /* If the examine succeeds, we remember its size and format for next time. */
1320 last_size = fmt.size;
1321 last_format = fmt.format;
1323 /* Set a couple of internal variables if appropriate. */
1324 if (last_examine_value)
1326 /* Make last address examined available to the user as $_. Use
1327 the correct pointer type. */
1328 set_internalvar (lookup_internalvar ("_"),
1329 value_from_longest (
1330 lookup_pointer_type (VALUE_TYPE (last_examine_value)),
1331 (LONGEST) last_examine_address));
1333 /* Make contents of last address examined available to the user as $__. */
1334 /* If the last value has not been fetched from memory then don't
1335 fetch it now - instead mark it by voiding the $__ variable. */
1336 if (VALUE_LAZY (last_examine_value))
1337 set_internalvar (lookup_internalvar ("__"),
1338 allocate_value (builtin_type_void));
1340 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1345 /* Add an expression to the auto-display chain.
1346 Specify the expression. */
1349 display_command (exp, from_tty)
1353 struct format_data fmt;
1354 register struct expression *expr;
1355 register struct display *new;
1359 if (tui_version && *exp == '$')
1360 display_it = ((TuiStatus) tuiDo (
1361 (TuiOpaqueFuncPtr) tui_vSetLayoutTo, exp) == TUI_FAILURE);
1375 fmt = decode_format (&exp, 0, 0);
1376 if (fmt.size && fmt.format == 0)
1378 if (fmt.format == 'i' || fmt.format == 's')
1388 innermost_block = 0;
1389 expr = parse_expression (exp);
1391 new = (struct display *) xmalloc (sizeof (struct display));
1394 new->block = innermost_block;
1395 new->next = display_chain;
1396 new->number = ++display_number;
1398 new->status = enabled;
1399 display_chain = new;
1401 if (from_tty && target_has_execution)
1402 do_one_display (new);
1412 free ((PTR) d->exp);
1416 /* Clear out the display_chain.
1417 Done when new symtabs are loaded, since this invalidates
1418 the types stored in many expressions. */
1423 register struct display *d;
1425 while ((d = display_chain) != NULL)
1427 free ((PTR) d->exp);
1428 display_chain = d->next;
1433 /* Delete the auto-display number NUM. */
1436 delete_display (num)
1439 register struct display *d1, *d;
1442 error ("No display number %d.", num);
1444 if (display_chain->number == num)
1447 display_chain = d1->next;
1451 for (d = display_chain;; d = d->next)
1454 error ("No display number %d.", num);
1455 if (d->next->number == num)
1465 /* Delete some values from the auto-display chain.
1466 Specify the element numbers. */
1469 undisplay_command (args, from_tty)
1473 register char *p = args;
1479 if (query ("Delete all auto-display expressions? "))
1488 while (*p1 >= '0' && *p1 <= '9')
1490 if (*p1 && *p1 != ' ' && *p1 != '\t')
1491 error ("Arguments must be display numbers.");
1495 delete_display (num);
1498 while (*p == ' ' || *p == '\t')
1504 /* Display a single auto-display.
1505 Do nothing if the display cannot be printed in the current context,
1506 or if the display is disabled. */
1512 int within_current_scope;
1514 if (d->status == disabled)
1518 within_current_scope = contained_in (get_selected_block (), d->block);
1520 within_current_scope = 1;
1521 if (!within_current_scope)
1524 current_display_number = d->number;
1526 annotate_display_begin ();
1527 printf_filtered ("%d", d->number);
1528 annotate_display_number_end ();
1529 printf_filtered (": ");
1535 annotate_display_format ();
1537 printf_filtered ("x/");
1538 if (d->format.count != 1)
1539 printf_filtered ("%d", d->format.count);
1540 printf_filtered ("%c", d->format.format);
1541 if (d->format.format != 'i' && d->format.format != 's')
1542 printf_filtered ("%c", d->format.size);
1543 printf_filtered (" ");
1545 annotate_display_expression ();
1547 print_expression (d->exp, gdb_stdout);
1548 annotate_display_expression_end ();
1550 if (d->format.count != 1)
1551 printf_filtered ("\n");
1553 printf_filtered (" ");
1555 val = evaluate_expression (d->exp);
1556 addr = value_as_pointer (val);
1557 if (d->format.format == 'i')
1558 addr = ADDR_BITS_REMOVE (addr);
1560 annotate_display_value ();
1562 do_examine (d->format, addr, VALUE_BFD_SECTION (val));
1566 annotate_display_format ();
1568 if (d->format.format)
1569 printf_filtered ("/%c ", d->format.format);
1571 annotate_display_expression ();
1573 print_expression (d->exp, gdb_stdout);
1574 annotate_display_expression_end ();
1576 printf_filtered (" = ");
1578 annotate_display_expression ();
1580 print_formatted (evaluate_expression (d->exp),
1581 d->format.format, d->format.size);
1582 printf_filtered ("\n");
1585 annotate_display_end ();
1587 gdb_flush (gdb_stdout);
1588 current_display_number = -1;
1591 /* Display all of the values on the auto-display chain which can be
1592 evaluated in the current scope. */
1597 register struct display *d;
1599 for (d = display_chain; d; d = d->next)
1603 /* Delete the auto-display which we were in the process of displaying.
1604 This is done when there is an error or a signal. */
1607 disable_display (num)
1610 register struct display *d;
1612 for (d = display_chain; d; d = d->next)
1613 if (d->number == num)
1615 d->status = disabled;
1618 printf_unfiltered ("No display number %d.\n", num);
1622 disable_current_display ()
1624 if (current_display_number >= 0)
1626 disable_display (current_display_number);
1627 fprintf_unfiltered (gdb_stderr, "Disabling display %d to avoid infinite recursion.\n",
1628 current_display_number);
1630 current_display_number = -1;
1634 display_info (ignore, from_tty)
1638 register struct display *d;
1641 printf_unfiltered ("There are no auto-display expressions now.\n");
1643 printf_filtered ("Auto-display expressions now in effect:\n\
1644 Num Enb Expression\n");
1646 for (d = display_chain; d; d = d->next)
1648 printf_filtered ("%d: %c ", d->number, "ny"[(int) d->status]);
1650 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1652 else if (d->format.format)
1653 printf_filtered ("/%c ", d->format.format);
1654 print_expression (d->exp, gdb_stdout);
1655 if (d->block && !contained_in (get_selected_block (), d->block))
1656 printf_filtered (" (cannot be evaluated in the current context)");
1657 printf_filtered ("\n");
1658 gdb_flush (gdb_stdout);
1663 enable_display (args, from_tty)
1667 register char *p = args;
1670 register struct display *d;
1674 for (d = display_chain; d; d = d->next)
1675 d->status = enabled;
1681 while (*p1 >= '0' && *p1 <= '9')
1683 if (*p1 && *p1 != ' ' && *p1 != '\t')
1684 error ("Arguments must be display numbers.");
1688 for (d = display_chain; d; d = d->next)
1689 if (d->number == num)
1691 d->status = enabled;
1694 printf_unfiltered ("No display number %d.\n", num);
1697 while (*p == ' ' || *p == '\t')
1704 disable_display_command (args, from_tty)
1708 register char *p = args;
1710 register struct display *d;
1714 for (d = display_chain; d; d = d->next)
1715 d->status = disabled;
1721 while (*p1 >= '0' && *p1 <= '9')
1723 if (*p1 && *p1 != ' ' && *p1 != '\t')
1724 error ("Arguments must be display numbers.");
1726 disable_display (atoi (p));
1729 while (*p == ' ' || *p == '\t')
1735 /* Print the value in stack frame FRAME of a variable
1736 specified by a struct symbol. */
1739 print_variable_value (var, frame, stream)
1741 struct frame_info *frame;
1744 value_ptr val = read_var_value (var, frame);
1746 value_print (val, stream, 0, Val_pretty_default);
1749 /* Print the arguments of a stack frame, given the function FUNC
1750 running in that frame (as a symbol), the info on the frame,
1751 and the number of args according to the stack frame (or -1 if unknown). */
1753 /* References here and elsewhere to "number of args according to the
1754 stack frame" appear in all cases to refer to "number of ints of args
1755 according to the stack frame". At least for VAX, i386, isi. */
1758 print_frame_args (func, fi, num, stream)
1759 struct symbol *func;
1760 struct frame_info *fi;
1764 struct block *b = NULL;
1768 register struct symbol *sym;
1769 register value_ptr val;
1770 /* Offset of next stack argument beyond the one we have seen that is
1771 at the highest offset.
1772 -1 if we haven't come to a stack argument yet. */
1773 long highest_offset = -1;
1775 /* Number of ints of arguments that we have printed so far. */
1776 int args_printed = 0;
1780 b = SYMBOL_BLOCK_VALUE (func);
1781 nsyms = BLOCK_NSYMS (b);
1784 for (i = 0; i < nsyms; i++)
1787 sym = BLOCK_SYM (b, i);
1789 /* Keep track of the highest stack argument offset seen, and
1790 skip over any kinds of symbols we don't care about. */
1792 switch (SYMBOL_CLASS (sym))
1797 long current_offset = SYMBOL_VALUE (sym);
1798 arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1800 /* Compute address of next argument by adding the size of
1801 this argument and rounding to an int boundary. */
1803 = ((current_offset + arg_size + sizeof (int) - 1)
1804 & ~(sizeof (int) - 1));
1806 /* If this is the highest offset seen yet, set highest_offset. */
1807 if (highest_offset == -1
1808 || (current_offset > highest_offset))
1809 highest_offset = current_offset;
1811 /* Add the number of ints we're about to print to args_printed. */
1812 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
1815 /* We care about types of symbols, but don't need to keep track of
1816 stack offsets in them. */
1818 case LOC_REGPARM_ADDR:
1820 case LOC_BASEREG_ARG:
1823 /* Other types of symbols we just skip over. */
1828 /* We have to look up the symbol because arguments can have
1829 two entries (one a parameter, one a local) and the one we
1830 want is the local, which lookup_symbol will find for us.
1831 This includes gcc1 (not gcc2) on the sparc when passing a
1832 small structure and gcc2 when the argument type is float
1833 and it is passed as a double and converted to float by
1834 the prologue (in the latter case the type of the LOC_ARG
1835 symbol is double and the type of the LOC_LOCAL symbol is
1837 /* But if the parameter name is null, don't try it.
1838 Null parameter names occur on the RS/6000, for traceback tables.
1839 FIXME, should we even print them? */
1841 if (*SYMBOL_NAME (sym))
1843 struct symbol *nsym;
1844 nsym = lookup_symbol
1846 b, VAR_NAMESPACE, (int *) NULL, (struct symtab **) NULL);
1847 if (SYMBOL_CLASS (nsym) == LOC_REGISTER)
1849 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
1850 it was passed on the stack and loaded into a register,
1851 or passed in a register and stored in a stack slot.
1852 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
1854 Reasons for using the LOC_ARG:
1855 (1) because find_saved_registers may be slow for remote
1857 (2) because registers are often re-used and stack slots
1858 rarely (never?) are. Therefore using the stack slot is
1859 much less likely to print garbage.
1861 Reasons why we might want to use the LOC_REGISTER:
1862 (1) So that the backtrace prints the same value as
1863 "print foo". I see no compelling reason why this needs
1864 to be the case; having the backtrace print the value which
1865 was passed in, and "print foo" print the value as modified
1866 within the called function, makes perfect sense to me.
1868 Additional note: It might be nice if "info args" displayed
1870 One more note: There is a case with sparc structure passing
1871 where we need to use the LOC_REGISTER, but this is dealt with
1872 by creating a single LOC_REGPARM in symbol reading. */
1874 /* Leave sym (the LOC_ARG) alone. */
1881 /* Print the current arg. */
1883 fprintf_filtered (stream, ", ");
1886 annotate_arg_begin ();
1888 fprintf_symbol_filtered (stream, SYMBOL_SOURCE_NAME (sym),
1889 SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
1890 annotate_arg_name_end ();
1891 fputs_filtered ("=", stream);
1893 /* Avoid value_print because it will deref ref parameters. We just
1894 want to print their addresses. Print ??? for args whose address
1895 we do not know. We pass 2 as "recurse" to val_print because our
1896 standard indentation here is 4 spaces, and val_print indents
1897 2 for each recurse. */
1898 val = read_var_value (sym, fi);
1900 annotate_arg_value (val == NULL ? NULL : VALUE_TYPE (val));
1904 if (GDB_TARGET_IS_D10V
1905 && SYMBOL_CLASS (sym) == LOC_REGPARM && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_PTR)
1906 TYPE_LENGTH (VALUE_TYPE (val)) = 2;
1907 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
1908 VALUE_ADDRESS (val),
1909 stream, 0, 0, 2, Val_no_prettyprint);
1912 fputs_filtered ("???", stream);
1914 annotate_arg_end ();
1919 /* Don't print nameless args in situations where we don't know
1920 enough about the stack to find them. */
1925 if (highest_offset == -1)
1926 start = FRAME_ARGS_SKIP;
1928 start = highest_offset;
1930 print_frame_nameless_args (fi, start, num - args_printed,
1935 /* Print nameless args on STREAM.
1936 FI is the frameinfo for this frame, START is the offset
1937 of the first nameless arg, and NUM is the number of nameless args to
1938 print. FIRST is nonzero if this is the first argument (not just
1939 the first nameless arg). */
1942 print_frame_nameless_args (fi, start, num, first, stream)
1943 struct frame_info *fi;
1953 for (i = 0; i < num; i++)
1956 #ifdef NAMELESS_ARG_VALUE
1957 NAMELESS_ARG_VALUE (fi, start, &arg_value);
1959 argsaddr = FRAME_ARGS_ADDRESS (fi);
1963 arg_value = read_memory_integer (argsaddr + start, sizeof (int));
1967 fprintf_filtered (stream, ", ");
1969 #ifdef PRINT_NAMELESS_INTEGER
1970 PRINT_NAMELESS_INTEGER (stream, arg_value);
1972 #ifdef PRINT_TYPELESS_INTEGER
1973 PRINT_TYPELESS_INTEGER (stream, builtin_type_int, (LONGEST) arg_value);
1975 fprintf_filtered (stream, "%ld", arg_value);
1976 #endif /* PRINT_TYPELESS_INTEGER */
1977 #endif /* PRINT_NAMELESS_INTEGER */
1979 start += sizeof (int);
1985 printf_command (arg, from_tty)
1989 register char *f = NULL;
1990 register char *s = arg;
1991 char *string = NULL;
1992 value_ptr *val_args;
1994 char *current_substring;
1996 int allocated_args = 20;
1997 struct cleanup *old_cleanups;
1999 val_args = (value_ptr *) xmalloc (allocated_args * sizeof (value_ptr));
2000 old_cleanups = make_cleanup ((make_cleanup_func) free_current_contents,
2004 error_no_arg ("format-control string and values to print");
2006 /* Skip white space before format string */
2007 while (*s == ' ' || *s == '\t')
2010 /* A format string should follow, enveloped in double quotes */
2012 error ("Bad format string, missing '\"'.");
2014 /* Parse the format-control string and copy it into the string STRING,
2015 processing some kinds of escape sequence. */
2017 f = string = (char *) alloca (strlen (s) + 1);
2025 error ("Bad format string, non-terminated '\"'.");
2037 *f++ = '\007'; /* Bell */
2062 /* ??? TODO: handle other escape sequences */
2063 error ("Unrecognized escape character \\%c in format string.",
2073 /* Skip over " and following space and comma. */
2076 while (*s == ' ' || *s == '\t')
2079 if (*s != ',' && *s != 0)
2080 error ("Invalid argument syntax");
2084 while (*s == ' ' || *s == '\t')
2087 /* Need extra space for the '\0's. Doubling the size is sufficient. */
2088 substrings = alloca (strlen (string) * 2);
2089 current_substring = substrings;
2092 /* Now scan the string for %-specs and see what kinds of args they want.
2093 argclass[I] classifies the %-specs so we can give printf_filtered
2094 something of the right size. */
2098 no_arg, int_arg, string_arg, double_arg, long_long_arg
2100 enum argclass *argclass;
2101 enum argclass this_argclass;
2107 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
2115 while (strchr ("0123456789.hlL-+ #", *f))
2117 if (*f == 'l' || *f == 'L')
2124 this_argclass = string_arg;
2130 this_argclass = double_arg;
2134 error ("`*' not supported for precision or width in printf");
2137 error ("Format specifier `n' not supported in printf");
2140 this_argclass = no_arg;
2145 this_argclass = long_long_arg;
2147 this_argclass = int_arg;
2151 if (this_argclass != no_arg)
2153 strncpy (current_substring, last_arg, f - last_arg);
2154 current_substring += f - last_arg;
2155 *current_substring++ = '\0';
2157 argclass[nargs_wanted++] = this_argclass;
2161 /* Now, parse all arguments and evaluate them.
2162 Store the VALUEs in VAL_ARGS. */
2167 if (nargs == allocated_args)
2168 val_args = (value_ptr *) xrealloc ((char *) val_args,
2169 (allocated_args *= 2)
2170 * sizeof (value_ptr));
2172 val_args[nargs] = parse_to_comma_and_eval (&s1);
2174 /* If format string wants a float, unchecked-convert the value to
2175 floating point of the same size */
2177 if (argclass[nargs] == double_arg)
2179 struct type *type = VALUE_TYPE (val_args[nargs]);
2180 if (TYPE_LENGTH (type) == sizeof (float))
2181 VALUE_TYPE (val_args[nargs]) = builtin_type_float;
2182 if (TYPE_LENGTH (type) == sizeof (double))
2183 VALUE_TYPE (val_args[nargs]) = builtin_type_double;
2191 if (nargs != nargs_wanted)
2192 error ("Wrong number of arguments for specified format-string");
2194 /* Now actually print them. */
2195 current_substring = substrings;
2196 for (i = 0; i < nargs; i++)
2198 switch (argclass[i])
2205 tem = value_as_pointer (val_args[i]);
2207 /* This is a %s argument. Find the length of the string. */
2212 read_memory_section (tem + j, &c, 1,
2213 VALUE_BFD_SECTION (val_args[i]));
2218 /* Copy the string contents into a string inside GDB. */
2219 str = (char *) alloca (j + 1);
2220 read_memory_section (tem, str, j, VALUE_BFD_SECTION (val_args[i]));
2223 printf_filtered (current_substring, str);
2228 double val = value_as_double (val_args[i]);
2229 printf_filtered (current_substring, val);
2233 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2235 long long val = value_as_long (val_args[i]);
2236 printf_filtered (current_substring, val);
2240 error ("long long not supported in printf");
2244 /* FIXME: there should be separate int_arg and long_arg. */
2245 long val = value_as_long (val_args[i]);
2246 printf_filtered (current_substring, val);
2249 default: /* purecov: deadcode */
2250 error ("internal error in printf_command"); /* purecov: deadcode */
2252 /* Skip to the next substring. */
2253 current_substring += strlen (current_substring) + 1;
2255 /* Print the portion of the format string after the last argument. */
2256 printf_filtered (last_arg);
2258 do_cleanups (old_cleanups);
2261 /* Dump a specified section of assembly code. With no command line
2262 arguments, this command will dump the assembly code for the
2263 function surrounding the pc value in the selected frame. With one
2264 argument, it will dump the assembly code surrounding that pc value.
2265 Two arguments are interpeted as bounds within which to dump
2270 disassemble_command (arg, from_tty)
2274 CORE_ADDR low, high;
2276 CORE_ADDR pc, pc_masked;
2285 if (!selected_frame)
2286 error ("No frame selected.\n");
2288 pc = get_frame_pc (selected_frame);
2289 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
2290 error ("No function contains program counter for selected frame.\n");
2292 else if (tui_version)
2293 low = (CORE_ADDR) tuiDo ((TuiOpaqueFuncPtr) tui_vGetLowDisassemblyAddress,
2297 low += FUNCTION_START_OFFSET;
2299 else if (!(space_index = (char *) strchr (arg, ' ')))
2302 pc = parse_and_eval_address (arg);
2303 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
2304 error ("No function contains specified address.\n");
2306 else if (tui_version)
2307 low = (CORE_ADDR) tuiDo ((TuiOpaqueFuncPtr) tui_vGetLowDisassemblyAddress,
2312 if (overlay_debugging)
2314 section = find_pc_overlay (pc);
2315 if (pc_in_unmapped_range (pc, section))
2317 /* find_pc_partial_function will have returned low and high
2318 relative to the symbolic (mapped) address range. Need to
2319 translate them back to the unmapped range where PC is. */
2320 low = overlay_unmapped_address (low, section);
2321 high = overlay_unmapped_address (high, section);
2325 low += FUNCTION_START_OFFSET;
2329 /* Two arguments. */
2330 *space_index = '\0';
2331 low = parse_and_eval_address (arg);
2332 high = parse_and_eval_address (space_index + 1);
2337 m_winPtrIsNull (disassemWin) || !disassemWin->generic.isVisible)
2340 printf_filtered ("Dump of assembler code ");
2343 printf_filtered ("for function %s:\n", name);
2347 printf_filtered ("from ");
2348 print_address_numeric (low, 1, gdb_stdout);
2349 printf_filtered (" to ");
2350 print_address_numeric (high, 1, gdb_stdout);
2351 printf_filtered (":\n");
2354 /* Dump the specified range. */
2357 #ifdef GDB_TARGET_MASK_DISAS_PC
2358 pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
2363 while (pc_masked < high)
2366 print_address (pc_masked, gdb_stdout);
2367 printf_filtered (":\t");
2368 /* We often wrap here if there are long symbolic names. */
2370 pc += print_insn (pc, gdb_stdout);
2371 printf_filtered ("\n");
2373 #ifdef GDB_TARGET_MASK_DISAS_PC
2374 pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
2379 printf_filtered ("End of assembler dump.\n");
2380 gdb_flush (gdb_stdout);
2385 tuiDo ((TuiOpaqueFuncPtr) tui_vAddWinToLayout, DISASSEM_WIN);
2386 tuiDo ((TuiOpaqueFuncPtr) tui_vUpdateSourceWindowsWithAddr, low);
2391 /* Print the instruction at address MEMADDR in debugged memory,
2392 on STREAM. Returns length of the instruction, in bytes. */
2395 print_insn (memaddr, stream)
2399 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2400 TARGET_PRINT_INSN_INFO->endian = BFD_ENDIAN_BIG;
2402 TARGET_PRINT_INSN_INFO->endian = BFD_ENDIAN_LITTLE;
2404 if (TARGET_ARCHITECTURE != NULL)
2405 TARGET_PRINT_INSN_INFO->mach = TARGET_ARCHITECTURE->mach;
2406 /* else: should set .mach=0 but some disassemblers don't grok this */
2408 return TARGET_PRINT_INSN (memaddr, TARGET_PRINT_INSN_INFO);
2413 _initialize_printcmd ()
2415 current_display_number = -1;
2417 add_info ("address", address_info,
2418 "Describe where symbol SYM is stored.");
2420 add_info ("symbol", sym_info,
2421 "Describe what symbol is at location ADDR.\n\
2422 Only for symbols with fixed locations (global or static scope).");
2424 add_com ("x", class_vars, x_command,
2425 concat ("Examine memory: x/FMT ADDRESS.\n\
2426 ADDRESS is an expression for the memory address to examine.\n\
2427 FMT is a repeat count followed by a format letter and a size letter.\n\
2428 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2429 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n",
2430 "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2431 The specified number of objects of the specified size are printed\n\
2432 according to the format.\n\n\
2433 Defaults for format and size letters are those previously used.\n\
2434 Default count is 1. Default address is following last thing printed\n\
2435 with this command or \"print\".", NULL));
2437 add_com ("disassemble", class_vars, disassemble_command,
2438 "Disassemble a specified section of memory.\n\
2439 Default is the function surrounding the pc of the selected frame.\n\
2440 With a single argument, the function surrounding that address is dumped.\n\
2441 Two arguments are taken as a range of memory to dump.");
2443 add_com_alias ("va", "disassemble", class_xdb, 0);
2446 add_com ("whereis", class_vars, whereis_command,
2447 "Print line number and file of definition of variable.");
2450 add_info ("display", display_info,
2451 "Expressions to display when program stops, with code numbers.");
2453 add_cmd ("undisplay", class_vars, undisplay_command,
2454 "Cancel some expressions to be displayed when program stops.\n\
2455 Arguments are the code numbers of the expressions to stop displaying.\n\
2456 No argument means cancel all automatic-display expressions.\n\
2457 \"delete display\" has the same effect as this command.\n\
2458 Do \"info display\" to see current list of code numbers.",
2461 add_com ("display", class_vars, display_command,
2462 "Print value of expression EXP each time the program stops.\n\
2463 /FMT may be used before EXP as in the \"print\" command.\n\
2464 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2465 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2466 and examining is done as in the \"x\" command.\n\n\
2467 With no argument, display all currently requested auto-display expressions.\n\
2468 Use \"undisplay\" to cancel display requests previously made."
2471 add_cmd ("display", class_vars, enable_display,
2472 "Enable some expressions to be displayed when program stops.\n\
2473 Arguments are the code numbers of the expressions to resume displaying.\n\
2474 No argument means enable all automatic-display expressions.\n\
2475 Do \"info display\" to see current list of code numbers.", &enablelist);
2477 add_cmd ("display", class_vars, disable_display_command,
2478 "Disable some expressions to be displayed when program stops.\n\
2479 Arguments are the code numbers of the expressions to stop displaying.\n\
2480 No argument means disable all automatic-display expressions.\n\
2481 Do \"info display\" to see current list of code numbers.", &disablelist);
2483 add_cmd ("display", class_vars, undisplay_command,
2484 "Cancel some expressions to be displayed when program stops.\n\
2485 Arguments are the code numbers of the expressions to stop displaying.\n\
2486 No argument means cancel all automatic-display expressions.\n\
2487 Do \"info display\" to see current list of code numbers.", &deletelist);
2489 add_com ("printf", class_vars, printf_command,
2490 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2491 This is useful for formatted output in user-defined commands.");
2493 add_com ("output", class_vars, output_command,
2494 "Like \"print\" but don't put in value history and don't print newline.\n\
2495 This is useful in user-defined commands.");
2497 add_prefix_cmd ("set", class_vars, set_command,
2498 concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2499 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2500 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2501 with $), a register (a few standard names starting with $), or an actual\n\
2502 variable in the program being debugged. EXP is any valid expression.\n",
2503 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2504 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2505 You can see these environment settings with the \"show\" command.", NULL),
2506 &setlist, "set ", 1, &cmdlist);
2508 add_com ("assign", class_vars, set_command, concat ("Evaluate expression \
2509 EXP and assign result to variable VAR, using assignment\n\
2510 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2511 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2512 with $), a register (a few standard names starting with $), or an actual\n\
2513 variable in the program being debugged. EXP is any valid expression.\n",
2514 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2515 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2516 You can see these environment settings with the \"show\" command.", NULL));
2518 /* "call" is the same as "set", but handy for dbx users to call fns. */
2519 add_com ("call", class_vars, call_command,
2520 "Call a function in the program.\n\
2521 The argument is the function name and arguments, in the notation of the\n\
2522 current working language. The result is printed and saved in the value\n\
2523 history, if it is not void.");
2525 add_cmd ("variable", class_vars, set_command,
2526 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2527 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2528 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2529 with $), a register (a few standard names starting with $), or an actual\n\
2530 variable in the program being debugged. EXP is any valid expression.\n\
2531 This may usually be abbreviated to simply \"set\".",
2534 add_com ("print", class_vars, print_command,
2535 concat ("Print value of expression EXP.\n\
2536 Variables accessible are those of the lexical environment of the selected\n\
2537 stack frame, plus all those whose scope is global or an entire file.\n\
2539 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2540 $$NUM refers to NUM'th value back from the last one.\n\
2541 Names starting with $ refer to registers (with the values they would have\n",
2542 "if the program were to return to the stack frame now selected, restoring\n\
2543 all registers saved by frames farther in) or else to debugger\n\
2544 \"convenience\" variables (any such name not a known register).\n\
2545 Use assignment expressions to give values to convenience variables.\n",
2547 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2548 @ is a binary operator for treating consecutive data objects\n\
2549 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2550 element is FOO, whose second element is stored in the space following\n\
2551 where FOO is stored, etc. FOO must be an expression whose value\n\
2552 resides in memory.\n",
2554 EXP may be preceded with /FMT, where FMT is a format letter\n\
2555 but no count or size letter (see \"x\" command).", NULL));
2556 add_com_alias ("p", "print", class_vars, 1);
2558 add_com ("inspect", class_vars, inspect_command,
2559 "Same as \"print\" command, except that if you are running in the epoch\n\
2560 environment, the value is printed in its own window.");
2563 add_set_cmd ("max-symbolic-offset", no_class, var_uinteger,
2564 (char *) &max_symbolic_offset,
2565 "Set the largest offset that will be printed in <symbol+1234> form.",
2569 add_set_cmd ("symbol-filename", no_class, var_boolean,
2570 (char *) &print_symbol_filename,
2571 "Set printing of source filename and line number with <symbol>.",
2575 /* For examine/instruction a single byte quantity is specified as
2576 the data. This avoids problems with value_at_lazy() requiring a
2577 valid data type (and rejecting VOID). */
2578 examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
2580 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2581 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2582 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2583 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);