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, GDB_FILE *));
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 stream 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, stream)
281 register value_ptr val;
286 struct type *type = check_typedef (VALUE_TYPE (val));
287 int len = TYPE_LENGTH (type);
289 if (VALUE_LVAL (val) == lval_memory)
291 next_address = VALUE_ADDRESS (val) + len;
292 next_section = VALUE_BFD_SECTION (val);
298 /* FIXME: Need to handle wchar_t's here... */
299 next_address = VALUE_ADDRESS (val)
300 + val_print_string (VALUE_ADDRESS (val), -1, 1, stream);
301 next_section = VALUE_BFD_SECTION (val);
305 /* The old comment says
306 "Force output out, print_insn not using _filtered".
307 I'm not completely sure what that means, I suspect most print_insn
308 now do use _filtered, so I guess it's obsolete.
309 --Yes, it does filter now, and so this is obsolete. -JB */
311 /* We often wrap here if there are long symbolic names. */
313 next_address = VALUE_ADDRESS (val)
314 + print_insn (VALUE_ADDRESS (val), stream);
315 next_section = VALUE_BFD_SECTION (val);
320 || TYPE_CODE (type) == TYPE_CODE_ARRAY
321 || TYPE_CODE (type) == TYPE_CODE_STRING
322 || TYPE_CODE (type) == TYPE_CODE_STRUCT
323 || TYPE_CODE (type) == TYPE_CODE_UNION)
324 /* If format is 0, use the 'natural' format for
325 * that type of value. If the type is non-scalar,
326 * we have to use language rules to print it as
327 * a series of scalars.
329 value_print (val, stream, format, Val_pretty_default);
331 /* User specified format, so don't look to the
332 * the type to tell us what to do.
334 print_scalar_formatted (VALUE_CONTENTS (val), type,
335 format, size, stream);
339 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
340 according to letters FORMAT and SIZE on STREAM.
341 FORMAT may not be zero. Formats s and i are not supported at this level.
343 This is how the elements of an array or structure are printed
347 print_scalar_formatted (valaddr, type, format, size, stream)
355 unsigned int len = TYPE_LENGTH (type);
357 if (len > sizeof (LONGEST)
365 if (!TYPE_UNSIGNED (type)
366 || !extract_long_unsigned_integer (valaddr, len, &val_long))
368 /* We can't print it normally, but we can print it in hex.
369 Printing it in the wrong radix is more useful than saying
370 "use /x, you dummy". */
371 /* FIXME: we could also do octal or binary if that was the
373 /* FIXME: we should be using the size field to give us a
374 minimum field width to print. */
377 print_octal_chars (stream, valaddr, len);
378 else if (format == 'd')
379 print_decimal_chars (stream, valaddr, len);
380 else if (format == 't')
381 print_binary_chars (stream, valaddr, len);
383 /* replace with call to print_hex_chars? Looks
384 like val_print_type_code_int is redoing
387 val_print_type_code_int (type, valaddr, stream);
392 /* If we get here, extract_long_unsigned_integer set val_long. */
394 else if (format != 'f')
395 val_long = unpack_long (type, valaddr);
397 /* If we are printing it as unsigned, truncate it in case it is actually
398 a negative signed value (e.g. "print/u (short)-1" should print 65535
399 (if shorts are 16 bits) instead of 4294967295). */
402 if (len < sizeof (LONGEST))
403 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
411 /* no size specified, like in print. Print varying # of digits. */
412 print_longest (stream, 'x', 1, val_long);
421 print_longest (stream, size, 1, val_long);
424 error ("Undefined output size \"%c\".", size);
429 print_longest (stream, 'd', 1, val_long);
433 print_longest (stream, 'u', 0, val_long);
438 print_longest (stream, 'o', 1, val_long);
440 fprintf_filtered (stream, "0");
444 print_address (unpack_pointer (type, valaddr), stream);
448 value_print (value_from_longest (builtin_type_true_char, val_long),
449 stream, 0, Val_pretty_default);
453 if (len == sizeof (float))
454 type = builtin_type_float;
455 else if (len == sizeof (double))
456 type = builtin_type_double;
457 print_floating (valaddr, type, stream);
464 /* Binary; 't' stands for "two". */
466 char bits[8 * (sizeof val_long) + 1];
467 char buf[8 * (sizeof val_long) + 32];
472 width = 8 * (sizeof val_long);
489 error ("Undefined output size \"%c\".", size);
495 bits[width] = (val_long & 1) ? '1' : '0';
500 while (*cp && *cp == '0')
505 strcpy (buf, local_binary_format_prefix ());
507 strcat (buf, local_binary_format_suffix ());
508 fprintf_filtered (stream, buf);
513 error ("Undefined output format \"%c\".", format);
517 /* Specify default address for `x' command.
518 `info lines' uses this. */
521 set_next_address (addr)
526 /* Make address available to the user as $_. */
527 set_internalvar (lookup_internalvar ("_"),
528 value_from_longest (lookup_pointer_type (builtin_type_void),
532 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
533 after LEADIN. Print nothing if no symbolic name is found nearby.
534 Optionally also print source file and line number, if available.
535 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
536 or to interpret it as a possible C++ name and convert it back to source
537 form. However note that DO_DEMANGLE can be overridden by the specific
538 settings of the demangle and asm_demangle variables. */
541 print_address_symbolic (addr, stream, do_demangle, leadin)
547 struct minimal_symbol *msymbol;
548 struct symbol *symbol;
549 struct symtab *symtab = 0;
550 CORE_ADDR name_location = 0;
552 asection *section = 0;
555 /* Determine if the address is in an overlay, and whether it is mapped. */
556 if (overlay_debugging)
558 section = find_pc_overlay (addr);
559 if (pc_in_unmapped_range (addr, section))
562 addr = overlay_mapped_address (addr, section);
566 /* On some targets, add in extra "flag" bits to PC for
567 disassembly. This should ensure that "rounding errors" in
568 symbol addresses that are masked for disassembly favour the
569 the correct symbol. */
571 #ifdef GDB_TARGET_UNMASK_DISAS_PC
572 addr = GDB_TARGET_UNMASK_DISAS_PC (addr);
575 /* First try to find the address in the symbol table, then
576 in the minsyms. Take the closest one. */
578 /* This is defective in the sense that it only finds text symbols. So
579 really this is kind of pointless--we should make sure that the
580 minimal symbols have everything we need (by changing that we could
581 save some memory, but for many debug format--ELF/DWARF or
582 anything/stabs--it would be inconvenient to eliminate those minimal
584 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
585 symbol = find_pc_sect_function (addr, section);
589 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
591 name = SYMBOL_SOURCE_NAME (symbol);
593 name = SYMBOL_LINKAGE_NAME (symbol);
598 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
600 /* The msymbol is closer to the address than the symbol;
601 use the msymbol instead. */
604 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
606 name = SYMBOL_SOURCE_NAME (msymbol);
608 name = SYMBOL_LINKAGE_NAME (msymbol);
611 if (symbol == NULL && msymbol == NULL)
614 /* On some targets, mask out extra "flag" bits from PC for handsome
617 #ifdef GDB_TARGET_MASK_DISAS_PC
618 name_location = GDB_TARGET_MASK_DISAS_PC (name_location);
619 addr = GDB_TARGET_MASK_DISAS_PC (addr);
622 /* If the nearest symbol is too far away, don't print anything symbolic. */
624 /* For when CORE_ADDR is larger than unsigned int, we do math in
625 CORE_ADDR. But when we detect unsigned wraparound in the
626 CORE_ADDR math, we ignore this test and print the offset,
627 because addr+max_symbolic_offset has wrapped through the end
628 of the address space back to the beginning, giving bogus comparison. */
629 if (addr > name_location + max_symbolic_offset
630 && name_location + max_symbolic_offset > name_location)
633 fputs_filtered (leadin, stream);
635 fputs_filtered ("<*", stream);
637 fputs_filtered ("<", stream);
638 fputs_filtered (name, stream);
639 if (addr != name_location)
640 fprintf_filtered (stream, "+%u", (unsigned int) (addr - name_location));
642 /* Append source filename and line number if desired. Give specific
643 line # of this addr, if we have it; else line # of the nearest symbol. */
644 if (print_symbol_filename)
646 struct symtab_and_line sal;
648 sal = find_pc_sect_line (addr, section, 0);
651 fprintf_filtered (stream, " at %s:%d", sal.symtab->filename, sal.line);
652 else if (symtab && symbol && symbol->line)
653 fprintf_filtered (stream, " at %s:%d", symtab->filename, symbol->line);
655 fprintf_filtered (stream, " in %s", symtab->filename);
658 fputs_filtered ("*>", stream);
660 fputs_filtered (">", stream);
664 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
667 print_address_numeric (addr, use_local, stream)
672 /* This assumes a CORE_ADDR can fit in a LONGEST. Probably a safe
674 print_longest (stream, 'x', use_local, (ULONGEST) addr);
677 /* Print address ADDR symbolically on STREAM.
678 First print it as a number. Then perhaps print
679 <SYMBOL + OFFSET> after the number. */
682 print_address (addr, stream)
686 print_address_numeric (addr, 1, stream);
687 print_address_symbolic (addr, stream, asm_demangle, " ");
690 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
691 controls whether to print the symbolic name "raw" or demangled.
692 Global setting "addressprint" controls whether to print hex address
696 print_address_demangle (addr, stream, do_demangle)
703 fprintf_filtered (stream, "0");
705 else if (addressprint)
707 print_address_numeric (addr, 1, stream);
708 print_address_symbolic (addr, stream, do_demangle, " ");
712 print_address_symbolic (addr, stream, do_demangle, "");
717 /* These are the types that $__ will get after an examine command of one
720 static struct type *examine_i_type;
722 static struct type *examine_b_type;
723 static struct type *examine_h_type;
724 static struct type *examine_w_type;
725 static struct type *examine_g_type;
727 /* Examine data at address ADDR in format FMT.
728 Fetch it from memory and print on gdb_stdout. */
731 do_examine (fmt, addr, sect)
732 struct format_data fmt;
736 register char format = 0;
738 register int count = 1;
739 struct type *val_type = NULL;
741 register int maxelts;
749 /* String or instruction format implies fetch single bytes
750 regardless of the specified size. */
751 if (format == 's' || format == 'i')
755 val_type = examine_i_type;
756 else if (size == 'b')
757 val_type = examine_b_type;
758 else if (size == 'h')
759 val_type = examine_h_type;
760 else if (size == 'w')
761 val_type = examine_w_type;
762 else if (size == 'g')
763 val_type = examine_g_type;
770 if (format == 's' || format == 'i')
773 /* Print as many objects as specified in COUNT, at most maxelts per line,
774 with the address of the next one at the start of each line. */
779 print_address (next_address, gdb_stdout);
780 printf_filtered (":");
785 printf_filtered ("\t");
786 /* Note that print_formatted sets next_address for the next
788 last_examine_address = next_address;
790 if (last_examine_value)
791 value_free (last_examine_value);
793 /* The value to be displayed is not fetched greedily.
794 Instead, to avoid the posibility of a fetched value not
795 being used, its retreval is delayed until the print code
796 uses it. When examining an instruction stream, the
797 disassembler will perform its own memory fetch using just
798 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
799 the disassembler be modified so that LAST_EXAMINE_VALUE
800 is left with the byte sequence from the last complete
801 instruction fetched from memory? */
802 last_examine_value = value_at_lazy (val_type, next_address, sect);
804 if (last_examine_value)
805 release_value (last_examine_value);
807 print_formatted (last_examine_value, format, size, gdb_stdout);
809 printf_filtered ("\n");
810 gdb_flush (gdb_stdout);
815 validate_format (fmt, cmdname)
816 struct format_data fmt;
820 error ("Size letters are meaningless in \"%s\" command.", cmdname);
822 error ("Item count other than 1 is meaningless in \"%s\" command.",
824 if (fmt.format == 'i' || fmt.format == 's')
825 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
826 fmt.format, cmdname);
829 /* Evaluate string EXP as an expression in the current language and
830 print the resulting value. EXP may contain a format specifier as the
831 first argument ("/x myvar" for example, to print myvar in hex).
835 print_command_1 (exp, inspect, voidprint)
840 struct expression *expr;
841 register struct cleanup *old_chain = 0;
842 register char format = 0;
843 register value_ptr val;
844 struct format_data fmt;
847 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
848 inspect_it = inspect;
850 if (exp && *exp == '/')
853 fmt = decode_format (&exp, last_format, 0);
854 validate_format (fmt, "print");
855 last_format = format = fmt.format;
867 expr = parse_expression (exp);
868 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
871 val = evaluate_expression (expr);
873 /* C++: figure out what type we actually want to print it as. */
874 type = VALUE_TYPE (val);
877 && (TYPE_CODE (type) == TYPE_CODE_PTR
878 || TYPE_CODE (type) == TYPE_CODE_REF)
879 && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT
880 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION))
884 v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
888 type = VALUE_TYPE (val);
893 val = access_value_history (0);
895 if (voidprint || (val && VALUE_TYPE (val) &&
896 TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
898 int histindex = record_latest_value (val);
901 annotate_value_history_begin (histindex, VALUE_TYPE (val));
903 annotate_value_begin (VALUE_TYPE (val));
906 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
907 else if (histindex >= 0)
908 printf_filtered ("$%d = ", histindex);
911 annotate_value_history_value ();
913 print_formatted (val, format, fmt.size, gdb_stdout);
914 printf_filtered ("\n");
917 annotate_value_history_end ();
919 annotate_value_end ();
922 printf_unfiltered ("\") )\030");
926 do_cleanups (old_chain);
927 inspect_it = 0; /* Reset print routines to normal */
932 print_command (exp, from_tty)
936 print_command_1 (exp, 0, 1);
939 /* Same as print, except in epoch, it gets its own window */
942 inspect_command (exp, from_tty)
946 extern int epoch_interface;
948 print_command_1 (exp, epoch_interface, 1);
951 /* Same as print, except it doesn't print void results. */
954 call_command (exp, from_tty)
958 print_command_1 (exp, 0, 0);
963 output_command (exp, from_tty)
967 struct expression *expr;
968 register struct cleanup *old_chain;
969 register char format = 0;
970 register value_ptr val;
971 struct format_data fmt;
973 if (exp && *exp == '/')
976 fmt = decode_format (&exp, 0, 0);
977 validate_format (fmt, "output");
981 expr = parse_expression (exp);
982 old_chain = make_cleanup ((make_cleanup_func) free_current_contents, &expr);
984 val = evaluate_expression (expr);
986 annotate_value_begin (VALUE_TYPE (val));
988 print_formatted (val, format, fmt.size, gdb_stdout);
990 annotate_value_end ();
993 gdb_flush (gdb_stdout);
995 do_cleanups (old_chain);
1000 set_command (exp, from_tty)
1004 struct expression *expr = parse_expression (exp);
1005 register struct cleanup *old_chain
1006 = make_cleanup ((make_cleanup_func) free_current_contents, &expr);
1007 evaluate_expression (expr);
1008 do_cleanups (old_chain);
1013 sym_info (arg, from_tty)
1017 struct minimal_symbol *msymbol;
1018 struct objfile *objfile;
1019 struct obj_section *osect;
1021 CORE_ADDR addr, sect_addr;
1023 unsigned int offset;
1026 error_no_arg ("address");
1028 addr = parse_and_eval_address (arg);
1029 ALL_OBJSECTIONS (objfile, osect)
1031 sect = osect->the_bfd_section;
1032 sect_addr = overlay_mapped_address (addr, sect);
1034 if (osect->addr <= sect_addr && sect_addr < osect->endaddr &&
1035 (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect)))
1038 offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
1040 printf_filtered ("%s + %u in ",
1041 SYMBOL_SOURCE_NAME (msymbol), offset);
1043 printf_filtered ("%s in ",
1044 SYMBOL_SOURCE_NAME (msymbol));
1045 if (pc_in_unmapped_range (addr, sect))
1046 printf_filtered ("load address range of ");
1047 if (section_is_overlay (sect))
1048 printf_filtered ("%s overlay ",
1049 section_is_mapped (sect) ? "mapped" : "unmapped");
1050 printf_filtered ("section %s", sect->name);
1051 printf_filtered ("\n");
1055 printf_filtered ("No symbol matches %s.\n", arg);
1060 address_info (exp, from_tty)
1064 register struct symbol *sym;
1065 register struct minimal_symbol *msymbol;
1067 register long basereg;
1069 CORE_ADDR load_addr;
1070 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
1071 if exp is a field of `this'. */
1074 error ("Argument required.");
1076 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
1077 &is_a_field_of_this, (struct symtab **) NULL);
1080 if (is_a_field_of_this)
1082 printf_filtered ("Symbol \"");
1083 fprintf_symbol_filtered (gdb_stdout, exp,
1084 current_language->la_language, DMGL_ANSI);
1085 printf_filtered ("\" is a field of the local class variable `this'\n");
1089 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1091 if (msymbol != NULL)
1093 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1095 printf_filtered ("Symbol \"");
1096 fprintf_symbol_filtered (gdb_stdout, exp,
1097 current_language->la_language, DMGL_ANSI);
1098 printf_filtered ("\" is at ");
1099 print_address_numeric (load_addr, 1, gdb_stdout);
1100 printf_filtered (" in a file compiled without debugging");
1101 section = SYMBOL_BFD_SECTION (msymbol);
1102 if (section_is_overlay (section))
1104 load_addr = overlay_unmapped_address (load_addr, section);
1105 printf_filtered (",\n -- loaded at ");
1106 print_address_numeric (load_addr, 1, gdb_stdout);
1107 printf_filtered (" in overlay section %s", section->name);
1109 printf_filtered (".\n");
1112 error ("No symbol \"%s\" in current context.", exp);
1116 printf_filtered ("Symbol \"");
1117 fprintf_symbol_filtered (gdb_stdout, SYMBOL_NAME (sym),
1118 current_language->la_language, DMGL_ANSI);
1119 printf_filtered ("\" is ");
1120 val = SYMBOL_VALUE (sym);
1121 basereg = SYMBOL_BASEREG (sym);
1122 section = SYMBOL_BFD_SECTION (sym);
1124 switch (SYMBOL_CLASS (sym))
1127 case LOC_CONST_BYTES:
1128 printf_filtered ("constant");
1132 printf_filtered ("a label at address ");
1133 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1135 if (section_is_overlay (section))
1137 load_addr = overlay_unmapped_address (load_addr, section);
1138 printf_filtered (",\n -- loaded at ");
1139 print_address_numeric (load_addr, 1, gdb_stdout);
1140 printf_filtered (" in overlay section %s", section->name);
1145 printf_filtered ("a variable in register %s", REGISTER_NAME (val));
1149 printf_filtered ("static storage at address ");
1150 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1152 if (section_is_overlay (section))
1154 load_addr = overlay_unmapped_address (load_addr, section);
1155 printf_filtered (",\n -- loaded at ");
1156 print_address_numeric (load_addr, 1, gdb_stdout);
1157 printf_filtered (" in overlay section %s", section->name);
1162 printf_filtered ("external global (indirect addressing), at address *(");
1163 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1165 printf_filtered (")");
1166 if (section_is_overlay (section))
1168 load_addr = overlay_unmapped_address (load_addr, section);
1169 printf_filtered (",\n -- loaded at ");
1170 print_address_numeric (load_addr, 1, gdb_stdout);
1171 printf_filtered (" in overlay section %s", section->name);
1176 printf_filtered ("an argument in register %s", REGISTER_NAME (val));
1179 case LOC_REGPARM_ADDR:
1180 printf_filtered ("address of an argument in register %s", REGISTER_NAME (val));
1184 printf_filtered ("an argument at offset %ld", val);
1188 printf_filtered ("an argument at frame offset %ld", val);
1192 printf_filtered ("a local variable at frame offset %ld", val);
1196 printf_filtered ("a reference argument at offset %ld", val);
1200 printf_filtered ("a variable at offset %ld from register %s",
1201 val, REGISTER_NAME (basereg));
1204 case LOC_BASEREG_ARG:
1205 printf_filtered ("an argument at offset %ld from register %s",
1206 val, REGISTER_NAME (basereg));
1210 printf_filtered ("a typedef");
1214 printf_filtered ("a function at address ");
1215 #ifdef GDB_TARGET_MASK_DISAS_PC
1216 print_address_numeric
1217 (load_addr = GDB_TARGET_MASK_DISAS_PC (BLOCK_START (SYMBOL_BLOCK_VALUE (sym))),
1220 print_address_numeric (load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)),
1223 if (section_is_overlay (section))
1225 load_addr = overlay_unmapped_address (load_addr, section);
1226 printf_filtered (",\n -- loaded at ");
1227 print_address_numeric (load_addr, 1, gdb_stdout);
1228 printf_filtered (" in overlay section %s", section->name);
1232 case LOC_UNRESOLVED:
1234 struct minimal_symbol *msym;
1236 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, NULL);
1238 printf_filtered ("unresolved");
1241 section = SYMBOL_BFD_SECTION (msym);
1242 printf_filtered ("static storage at address ");
1243 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (msym),
1245 if (section_is_overlay (section))
1247 load_addr = overlay_unmapped_address (load_addr, section);
1248 printf_filtered (",\n -- loaded at ");
1249 print_address_numeric (load_addr, 1, gdb_stdout);
1250 printf_filtered (" in overlay section %s", section->name);
1256 case LOC_THREAD_LOCAL_STATIC:
1258 "a thread-local variable at offset %ld from the thread base register %s",
1259 val, REGISTER_NAME (basereg));
1262 case LOC_OPTIMIZED_OUT:
1263 printf_filtered ("optimized out");
1267 printf_filtered ("of unknown (botched) type");
1270 printf_filtered (".\n");
1274 x_command (exp, from_tty)
1278 struct expression *expr;
1279 struct format_data fmt;
1280 struct cleanup *old_chain;
1283 fmt.format = last_format;
1284 fmt.size = last_size;
1287 if (exp && *exp == '/')
1290 fmt = decode_format (&exp, last_format, last_size);
1293 /* If we have an expression, evaluate it and use it as the address. */
1295 if (exp != 0 && *exp != 0)
1297 expr = parse_expression (exp);
1298 /* Cause expression not to be there any more
1299 if this command is repeated with Newline.
1300 But don't clobber a user-defined command's definition. */
1303 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
1305 val = evaluate_expression (expr);
1306 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
1307 val = value_ind (val);
1308 /* In rvalue contexts, such as this, functions are coerced into
1309 pointers to functions. This makes "x/i main" work. */
1310 if ( /* last_format == 'i'
1311 && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
1312 && VALUE_LVAL (val) == lval_memory)
1313 next_address = VALUE_ADDRESS (val);
1315 next_address = value_as_pointer (val);
1316 if (VALUE_BFD_SECTION (val))
1317 next_section = VALUE_BFD_SECTION (val);
1318 do_cleanups (old_chain);
1321 do_examine (fmt, next_address, next_section);
1323 /* If the examine succeeds, we remember its size and format for next time. */
1324 last_size = fmt.size;
1325 last_format = fmt.format;
1327 /* Set a couple of internal variables if appropriate. */
1328 if (last_examine_value)
1330 /* Make last address examined available to the user as $_. Use
1331 the correct pointer type. */
1332 set_internalvar (lookup_internalvar ("_"),
1333 value_from_longest (
1334 lookup_pointer_type (VALUE_TYPE (last_examine_value)),
1335 (LONGEST) last_examine_address));
1337 /* Make contents of last address examined available to the user as $__. */
1338 /* If the last value has not been fetched from memory then don't
1339 fetch it now - instead mark it by voiding the $__ variable. */
1340 if (VALUE_LAZY (last_examine_value))
1341 set_internalvar (lookup_internalvar ("__"),
1342 allocate_value (builtin_type_void));
1344 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1349 /* Add an expression to the auto-display chain.
1350 Specify the expression. */
1353 display_command (exp, from_tty)
1357 struct format_data fmt;
1358 register struct expression *expr;
1359 register struct display *new;
1363 if (tui_version && *exp == '$')
1364 display_it = ((TuiStatus) tuiDo (
1365 (TuiOpaqueFuncPtr) tui_vSetLayoutTo, exp) == TUI_FAILURE);
1379 fmt = decode_format (&exp, 0, 0);
1380 if (fmt.size && fmt.format == 0)
1382 if (fmt.format == 'i' || fmt.format == 's')
1392 innermost_block = 0;
1393 expr = parse_expression (exp);
1395 new = (struct display *) xmalloc (sizeof (struct display));
1398 new->block = innermost_block;
1399 new->next = display_chain;
1400 new->number = ++display_number;
1402 new->status = enabled;
1403 display_chain = new;
1405 if (from_tty && target_has_execution)
1406 do_one_display (new);
1416 free ((PTR) d->exp);
1420 /* Clear out the display_chain.
1421 Done when new symtabs are loaded, since this invalidates
1422 the types stored in many expressions. */
1427 register struct display *d;
1429 while ((d = display_chain) != NULL)
1431 free ((PTR) d->exp);
1432 display_chain = d->next;
1437 /* Delete the auto-display number NUM. */
1440 delete_display (num)
1443 register struct display *d1, *d;
1446 error ("No display number %d.", num);
1448 if (display_chain->number == num)
1451 display_chain = d1->next;
1455 for (d = display_chain;; d = d->next)
1458 error ("No display number %d.", num);
1459 if (d->next->number == num)
1469 /* Delete some values from the auto-display chain.
1470 Specify the element numbers. */
1473 undisplay_command (args, from_tty)
1477 register char *p = args;
1483 if (query ("Delete all auto-display expressions? "))
1492 while (*p1 >= '0' && *p1 <= '9')
1494 if (*p1 && *p1 != ' ' && *p1 != '\t')
1495 error ("Arguments must be display numbers.");
1499 delete_display (num);
1502 while (*p == ' ' || *p == '\t')
1508 /* Display a single auto-display.
1509 Do nothing if the display cannot be printed in the current context,
1510 or if the display is disabled. */
1516 int within_current_scope;
1518 if (d->status == disabled)
1522 within_current_scope = contained_in (get_selected_block (), d->block);
1524 within_current_scope = 1;
1525 if (!within_current_scope)
1528 current_display_number = d->number;
1530 annotate_display_begin ();
1531 printf_filtered ("%d", d->number);
1532 annotate_display_number_end ();
1533 printf_filtered (": ");
1539 annotate_display_format ();
1541 printf_filtered ("x/");
1542 if (d->format.count != 1)
1543 printf_filtered ("%d", d->format.count);
1544 printf_filtered ("%c", d->format.format);
1545 if (d->format.format != 'i' && d->format.format != 's')
1546 printf_filtered ("%c", d->format.size);
1547 printf_filtered (" ");
1549 annotate_display_expression ();
1551 print_expression (d->exp, gdb_stdout);
1552 annotate_display_expression_end ();
1554 if (d->format.count != 1)
1555 printf_filtered ("\n");
1557 printf_filtered (" ");
1559 val = evaluate_expression (d->exp);
1560 addr = value_as_pointer (val);
1561 if (d->format.format == 'i')
1562 addr = ADDR_BITS_REMOVE (addr);
1564 annotate_display_value ();
1566 do_examine (d->format, addr, VALUE_BFD_SECTION (val));
1570 annotate_display_format ();
1572 if (d->format.format)
1573 printf_filtered ("/%c ", d->format.format);
1575 annotate_display_expression ();
1577 print_expression (d->exp, gdb_stdout);
1578 annotate_display_expression_end ();
1580 printf_filtered (" = ");
1582 annotate_display_expression ();
1584 print_formatted (evaluate_expression (d->exp),
1585 d->format.format, d->format.size, gdb_stdout);
1586 printf_filtered ("\n");
1589 annotate_display_end ();
1591 gdb_flush (gdb_stdout);
1592 current_display_number = -1;
1595 /* Display all of the values on the auto-display chain which can be
1596 evaluated in the current scope. */
1601 register struct display *d;
1603 for (d = display_chain; d; d = d->next)
1607 /* Delete the auto-display which we were in the process of displaying.
1608 This is done when there is an error or a signal. */
1611 disable_display (num)
1614 register struct display *d;
1616 for (d = display_chain; d; d = d->next)
1617 if (d->number == num)
1619 d->status = disabled;
1622 printf_unfiltered ("No display number %d.\n", num);
1626 disable_current_display ()
1628 if (current_display_number >= 0)
1630 disable_display (current_display_number);
1631 fprintf_unfiltered (gdb_stderr, "Disabling display %d to avoid infinite recursion.\n",
1632 current_display_number);
1634 current_display_number = -1;
1638 display_info (ignore, from_tty)
1642 register struct display *d;
1645 printf_unfiltered ("There are no auto-display expressions now.\n");
1647 printf_filtered ("Auto-display expressions now in effect:\n\
1648 Num Enb Expression\n");
1650 for (d = display_chain; d; d = d->next)
1652 printf_filtered ("%d: %c ", d->number, "ny"[(int) d->status]);
1654 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1656 else if (d->format.format)
1657 printf_filtered ("/%c ", d->format.format);
1658 print_expression (d->exp, gdb_stdout);
1659 if (d->block && !contained_in (get_selected_block (), d->block))
1660 printf_filtered (" (cannot be evaluated in the current context)");
1661 printf_filtered ("\n");
1662 gdb_flush (gdb_stdout);
1667 enable_display (args, from_tty)
1671 register char *p = args;
1674 register struct display *d;
1678 for (d = display_chain; d; d = d->next)
1679 d->status = enabled;
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)
1695 d->status = enabled;
1698 printf_unfiltered ("No display number %d.\n", num);
1701 while (*p == ' ' || *p == '\t')
1708 disable_display_command (args, from_tty)
1712 register char *p = args;
1714 register struct display *d;
1718 for (d = display_chain; d; d = d->next)
1719 d->status = disabled;
1725 while (*p1 >= '0' && *p1 <= '9')
1727 if (*p1 && *p1 != ' ' && *p1 != '\t')
1728 error ("Arguments must be display numbers.");
1730 disable_display (atoi (p));
1733 while (*p == ' ' || *p == '\t')
1739 /* Print the value in stack frame FRAME of a variable
1740 specified by a struct symbol. */
1743 print_variable_value (var, frame, stream)
1745 struct frame_info *frame;
1748 value_ptr val = read_var_value (var, frame);
1750 value_print (val, stream, 0, Val_pretty_default);
1753 /* Print the arguments of a stack frame, given the function FUNC
1754 running in that frame (as a symbol), the info on the frame,
1755 and the number of args according to the stack frame (or -1 if unknown). */
1757 /* References here and elsewhere to "number of args according to the
1758 stack frame" appear in all cases to refer to "number of ints of args
1759 according to the stack frame". At least for VAX, i386, isi. */
1762 print_frame_args (func, fi, num, stream)
1763 struct symbol *func;
1764 struct frame_info *fi;
1768 struct block *b = NULL;
1772 register struct symbol *sym;
1773 register value_ptr val;
1774 /* Offset of next stack argument beyond the one we have seen that is
1775 at the highest offset.
1776 -1 if we haven't come to a stack argument yet. */
1777 long highest_offset = -1;
1779 /* Number of ints of arguments that we have printed so far. */
1780 int args_printed = 0;
1784 b = SYMBOL_BLOCK_VALUE (func);
1785 nsyms = BLOCK_NSYMS (b);
1788 for (i = 0; i < nsyms; i++)
1791 sym = BLOCK_SYM (b, i);
1793 /* Keep track of the highest stack argument offset seen, and
1794 skip over any kinds of symbols we don't care about. */
1796 switch (SYMBOL_CLASS (sym))
1801 long current_offset = SYMBOL_VALUE (sym);
1802 arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1804 /* Compute address of next argument by adding the size of
1805 this argument and rounding to an int boundary. */
1807 = ((current_offset + arg_size + sizeof (int) - 1)
1808 & ~(sizeof (int) - 1));
1810 /* If this is the highest offset seen yet, set highest_offset. */
1811 if (highest_offset == -1
1812 || (current_offset > highest_offset))
1813 highest_offset = current_offset;
1815 /* Add the number of ints we're about to print to args_printed. */
1816 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
1819 /* We care about types of symbols, but don't need to keep track of
1820 stack offsets in them. */
1822 case LOC_REGPARM_ADDR:
1824 case LOC_BASEREG_ARG:
1827 /* Other types of symbols we just skip over. */
1832 /* We have to look up the symbol because arguments can have
1833 two entries (one a parameter, one a local) and the one we
1834 want is the local, which lookup_symbol will find for us.
1835 This includes gcc1 (not gcc2) on the sparc when passing a
1836 small structure and gcc2 when the argument type is float
1837 and it is passed as a double and converted to float by
1838 the prologue (in the latter case the type of the LOC_ARG
1839 symbol is double and the type of the LOC_LOCAL symbol is
1841 /* But if the parameter name is null, don't try it.
1842 Null parameter names occur on the RS/6000, for traceback tables.
1843 FIXME, should we even print them? */
1845 if (*SYMBOL_NAME (sym))
1847 struct symbol *nsym;
1848 nsym = lookup_symbol
1850 b, VAR_NAMESPACE, (int *) NULL, (struct symtab **) NULL);
1851 if (SYMBOL_CLASS (nsym) == LOC_REGISTER)
1853 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
1854 it was passed on the stack and loaded into a register,
1855 or passed in a register and stored in a stack slot.
1856 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
1858 Reasons for using the LOC_ARG:
1859 (1) because find_saved_registers may be slow for remote
1861 (2) because registers are often re-used and stack slots
1862 rarely (never?) are. Therefore using the stack slot is
1863 much less likely to print garbage.
1865 Reasons why we might want to use the LOC_REGISTER:
1866 (1) So that the backtrace prints the same value as
1867 "print foo". I see no compelling reason why this needs
1868 to be the case; having the backtrace print the value which
1869 was passed in, and "print foo" print the value as modified
1870 within the called function, makes perfect sense to me.
1872 Additional note: It might be nice if "info args" displayed
1874 One more note: There is a case with sparc structure passing
1875 where we need to use the LOC_REGISTER, but this is dealt with
1876 by creating a single LOC_REGPARM in symbol reading. */
1878 /* Leave sym (the LOC_ARG) alone. */
1885 /* Print the current arg. */
1887 fprintf_filtered (stream, ", ");
1890 annotate_arg_begin ();
1892 fprintf_symbol_filtered (stream, SYMBOL_SOURCE_NAME (sym),
1893 SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
1894 annotate_arg_name_end ();
1895 fputs_filtered ("=", stream);
1897 /* Avoid value_print because it will deref ref parameters. We just
1898 want to print their addresses. Print ??? for args whose address
1899 we do not know. We pass 2 as "recurse" to val_print because our
1900 standard indentation here is 4 spaces, and val_print indents
1901 2 for each recurse. */
1902 val = read_var_value (sym, fi);
1904 annotate_arg_value (val == NULL ? NULL : VALUE_TYPE (val));
1908 if (GDB_TARGET_IS_D10V
1909 && SYMBOL_CLASS (sym) == LOC_REGPARM && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_PTR)
1910 TYPE_LENGTH (VALUE_TYPE (val)) = 2;
1911 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
1912 VALUE_ADDRESS (val),
1913 stream, 0, 0, 2, Val_no_prettyprint);
1916 fputs_filtered ("???", stream);
1918 annotate_arg_end ();
1923 /* Don't print nameless args in situations where we don't know
1924 enough about the stack to find them. */
1929 if (highest_offset == -1)
1930 start = FRAME_ARGS_SKIP;
1932 start = highest_offset;
1934 print_frame_nameless_args (fi, start, num - args_printed,
1939 /* Print nameless args on STREAM.
1940 FI is the frameinfo for this frame, START is the offset
1941 of the first nameless arg, and NUM is the number of nameless args to
1942 print. FIRST is nonzero if this is the first argument (not just
1943 the first nameless arg). */
1946 print_frame_nameless_args (fi, start, num, first, stream)
1947 struct frame_info *fi;
1957 for (i = 0; i < num; i++)
1960 #ifdef NAMELESS_ARG_VALUE
1961 NAMELESS_ARG_VALUE (fi, start, &arg_value);
1963 argsaddr = FRAME_ARGS_ADDRESS (fi);
1967 arg_value = read_memory_integer (argsaddr + start, sizeof (int));
1971 fprintf_filtered (stream, ", ");
1973 #ifdef PRINT_NAMELESS_INTEGER
1974 PRINT_NAMELESS_INTEGER (stream, arg_value);
1976 #ifdef PRINT_TYPELESS_INTEGER
1977 PRINT_TYPELESS_INTEGER (stream, builtin_type_int, (LONGEST) arg_value);
1979 fprintf_filtered (stream, "%ld", arg_value);
1980 #endif /* PRINT_TYPELESS_INTEGER */
1981 #endif /* PRINT_NAMELESS_INTEGER */
1983 start += sizeof (int);
1989 printf_command (arg, from_tty)
1993 register char *f = NULL;
1994 register char *s = arg;
1995 char *string = NULL;
1996 value_ptr *val_args;
1998 char *current_substring;
2000 int allocated_args = 20;
2001 struct cleanup *old_cleanups;
2003 val_args = (value_ptr *) xmalloc (allocated_args * sizeof (value_ptr));
2004 old_cleanups = make_cleanup ((make_cleanup_func) free_current_contents,
2008 error_no_arg ("format-control string and values to print");
2010 /* Skip white space before format string */
2011 while (*s == ' ' || *s == '\t')
2014 /* A format string should follow, enveloped in double quotes */
2016 error ("Bad format string, missing '\"'.");
2018 /* Parse the format-control string and copy it into the string STRING,
2019 processing some kinds of escape sequence. */
2021 f = string = (char *) alloca (strlen (s) + 1);
2029 error ("Bad format string, non-terminated '\"'.");
2041 *f++ = '\007'; /* Bell */
2066 /* ??? TODO: handle other escape sequences */
2067 error ("Unrecognized escape character \\%c in format string.",
2077 /* Skip over " and following space and comma. */
2080 while (*s == ' ' || *s == '\t')
2083 if (*s != ',' && *s != 0)
2084 error ("Invalid argument syntax");
2088 while (*s == ' ' || *s == '\t')
2091 /* Need extra space for the '\0's. Doubling the size is sufficient. */
2092 substrings = alloca (strlen (string) * 2);
2093 current_substring = substrings;
2096 /* Now scan the string for %-specs and see what kinds of args they want.
2097 argclass[I] classifies the %-specs so we can give printf_filtered
2098 something of the right size. */
2102 no_arg, int_arg, string_arg, double_arg, long_long_arg
2104 enum argclass *argclass;
2105 enum argclass this_argclass;
2111 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
2119 while (strchr ("0123456789.hlL-+ #", *f))
2121 if (*f == 'l' || *f == 'L')
2128 this_argclass = string_arg;
2134 this_argclass = double_arg;
2138 error ("`*' not supported for precision or width in printf");
2141 error ("Format specifier `n' not supported in printf");
2144 this_argclass = no_arg;
2149 this_argclass = long_long_arg;
2151 this_argclass = int_arg;
2155 if (this_argclass != no_arg)
2157 strncpy (current_substring, last_arg, f - last_arg);
2158 current_substring += f - last_arg;
2159 *current_substring++ = '\0';
2161 argclass[nargs_wanted++] = this_argclass;
2165 /* Now, parse all arguments and evaluate them.
2166 Store the VALUEs in VAL_ARGS. */
2171 if (nargs == allocated_args)
2172 val_args = (value_ptr *) xrealloc ((char *) val_args,
2173 (allocated_args *= 2)
2174 * sizeof (value_ptr));
2176 val_args[nargs] = parse_to_comma_and_eval (&s1);
2178 /* If format string wants a float, unchecked-convert the value to
2179 floating point of the same size */
2181 if (argclass[nargs] == double_arg)
2183 struct type *type = VALUE_TYPE (val_args[nargs]);
2184 if (TYPE_LENGTH (type) == sizeof (float))
2185 VALUE_TYPE (val_args[nargs]) = builtin_type_float;
2186 if (TYPE_LENGTH (type) == sizeof (double))
2187 VALUE_TYPE (val_args[nargs]) = builtin_type_double;
2195 if (nargs != nargs_wanted)
2196 error ("Wrong number of arguments for specified format-string");
2198 /* Now actually print them. */
2199 current_substring = substrings;
2200 for (i = 0; i < nargs; i++)
2202 switch (argclass[i])
2209 tem = value_as_pointer (val_args[i]);
2211 /* This is a %s argument. Find the length of the string. */
2216 read_memory_section (tem + j, &c, 1,
2217 VALUE_BFD_SECTION (val_args[i]));
2222 /* Copy the string contents into a string inside GDB. */
2223 str = (char *) alloca (j + 1);
2224 read_memory_section (tem, str, j, VALUE_BFD_SECTION (val_args[i]));
2227 printf_filtered (current_substring, str);
2232 double val = value_as_double (val_args[i]);
2233 printf_filtered (current_substring, val);
2237 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2239 long long val = value_as_long (val_args[i]);
2240 printf_filtered (current_substring, val);
2244 error ("long long not supported in printf");
2248 /* FIXME: there should be separate int_arg and long_arg. */
2249 long val = value_as_long (val_args[i]);
2250 printf_filtered (current_substring, val);
2253 default: /* purecov: deadcode */
2254 error ("internal error in printf_command"); /* purecov: deadcode */
2256 /* Skip to the next substring. */
2257 current_substring += strlen (current_substring) + 1;
2259 /* Print the portion of the format string after the last argument. */
2260 printf_filtered (last_arg);
2262 do_cleanups (old_cleanups);
2265 /* Dump a specified section of assembly code. With no command line
2266 arguments, this command will dump the assembly code for the
2267 function surrounding the pc value in the selected frame. With one
2268 argument, it will dump the assembly code surrounding that pc value.
2269 Two arguments are interpeted as bounds within which to dump
2274 disassemble_command (arg, from_tty)
2278 CORE_ADDR low, high;
2280 CORE_ADDR pc, pc_masked;
2289 if (!selected_frame)
2290 error ("No frame selected.\n");
2292 pc = get_frame_pc (selected_frame);
2293 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
2294 error ("No function contains program counter for selected frame.\n");
2296 else if (tui_version)
2297 low = (CORE_ADDR) tuiDo ((TuiOpaqueFuncPtr) tui_vGetLowDisassemblyAddress,
2301 low += FUNCTION_START_OFFSET;
2303 else if (!(space_index = (char *) strchr (arg, ' ')))
2306 pc = parse_and_eval_address (arg);
2307 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
2308 error ("No function contains specified address.\n");
2310 else if (tui_version)
2311 low = (CORE_ADDR) tuiDo ((TuiOpaqueFuncPtr) tui_vGetLowDisassemblyAddress,
2316 if (overlay_debugging)
2318 section = find_pc_overlay (pc);
2319 if (pc_in_unmapped_range (pc, section))
2321 /* find_pc_partial_function will have returned low and high
2322 relative to the symbolic (mapped) address range. Need to
2323 translate them back to the unmapped range where PC is. */
2324 low = overlay_unmapped_address (low, section);
2325 high = overlay_unmapped_address (high, section);
2329 low += FUNCTION_START_OFFSET;
2333 /* Two arguments. */
2334 *space_index = '\0';
2335 low = parse_and_eval_address (arg);
2336 high = parse_and_eval_address (space_index + 1);
2341 m_winPtrIsNull (disassemWin) || !disassemWin->generic.isVisible)
2344 printf_filtered ("Dump of assembler code ");
2347 printf_filtered ("for function %s:\n", name);
2351 printf_filtered ("from ");
2352 print_address_numeric (low, 1, gdb_stdout);
2353 printf_filtered (" to ");
2354 print_address_numeric (high, 1, gdb_stdout);
2355 printf_filtered (":\n");
2358 /* Dump the specified range. */
2361 #ifdef GDB_TARGET_MASK_DISAS_PC
2362 pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
2367 while (pc_masked < high)
2370 print_address (pc_masked, gdb_stdout);
2371 printf_filtered (":\t");
2372 /* We often wrap here if there are long symbolic names. */
2374 pc += print_insn (pc, gdb_stdout);
2375 printf_filtered ("\n");
2377 #ifdef GDB_TARGET_MASK_DISAS_PC
2378 pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
2383 printf_filtered ("End of assembler dump.\n");
2384 gdb_flush (gdb_stdout);
2389 tuiDo ((TuiOpaqueFuncPtr) tui_vAddWinToLayout, DISASSEM_WIN);
2390 tuiDo ((TuiOpaqueFuncPtr) tui_vUpdateSourceWindowsWithAddr, low);
2395 /* Print the instruction at address MEMADDR in debugged memory,
2396 on STREAM. Returns length of the instruction, in bytes. */
2399 print_insn (memaddr, stream)
2403 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2404 TARGET_PRINT_INSN_INFO->endian = BFD_ENDIAN_BIG;
2406 TARGET_PRINT_INSN_INFO->endian = BFD_ENDIAN_LITTLE;
2408 if (TARGET_ARCHITECTURE != NULL)
2409 TARGET_PRINT_INSN_INFO->mach = TARGET_ARCHITECTURE->mach;
2410 /* else: should set .mach=0 but some disassemblers don't grok this */
2412 return TARGET_PRINT_INSN (memaddr, TARGET_PRINT_INSN_INFO);
2417 _initialize_printcmd ()
2419 current_display_number = -1;
2421 add_info ("address", address_info,
2422 "Describe where symbol SYM is stored.");
2424 add_info ("symbol", sym_info,
2425 "Describe what symbol is at location ADDR.\n\
2426 Only for symbols with fixed locations (global or static scope).");
2428 add_com ("x", class_vars, x_command,
2429 concat ("Examine memory: x/FMT ADDRESS.\n\
2430 ADDRESS is an expression for the memory address to examine.\n\
2431 FMT is a repeat count followed by a format letter and a size letter.\n\
2432 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2433 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n",
2434 "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2435 The specified number of objects of the specified size are printed\n\
2436 according to the format.\n\n\
2437 Defaults for format and size letters are those previously used.\n\
2438 Default count is 1. Default address is following last thing printed\n\
2439 with this command or \"print\".", NULL));
2441 add_com ("disassemble", class_vars, disassemble_command,
2442 "Disassemble a specified section of memory.\n\
2443 Default is the function surrounding the pc of the selected frame.\n\
2444 With a single argument, the function surrounding that address is dumped.\n\
2445 Two arguments are taken as a range of memory to dump.");
2447 add_com_alias ("va", "disassemble", class_xdb, 0);
2450 add_com ("whereis", class_vars, whereis_command,
2451 "Print line number and file of definition of variable.");
2454 add_info ("display", display_info,
2455 "Expressions to display when program stops, with code numbers.");
2457 add_cmd ("undisplay", class_vars, undisplay_command,
2458 "Cancel some expressions to be displayed when program stops.\n\
2459 Arguments are the code numbers of the expressions to stop displaying.\n\
2460 No argument means cancel all automatic-display expressions.\n\
2461 \"delete display\" has the same effect as this command.\n\
2462 Do \"info display\" to see current list of code numbers.",
2465 add_com ("display", class_vars, display_command,
2466 "Print value of expression EXP each time the program stops.\n\
2467 /FMT may be used before EXP as in the \"print\" command.\n\
2468 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2469 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2470 and examining is done as in the \"x\" command.\n\n\
2471 With no argument, display all currently requested auto-display expressions.\n\
2472 Use \"undisplay\" to cancel display requests previously made."
2475 add_cmd ("display", class_vars, enable_display,
2476 "Enable some expressions to be displayed when program stops.\n\
2477 Arguments are the code numbers of the expressions to resume displaying.\n\
2478 No argument means enable all automatic-display expressions.\n\
2479 Do \"info display\" to see current list of code numbers.", &enablelist);
2481 add_cmd ("display", class_vars, disable_display_command,
2482 "Disable some expressions to be displayed when program stops.\n\
2483 Arguments are the code numbers of the expressions to stop displaying.\n\
2484 No argument means disable all automatic-display expressions.\n\
2485 Do \"info display\" to see current list of code numbers.", &disablelist);
2487 add_cmd ("display", class_vars, undisplay_command,
2488 "Cancel some expressions to be displayed when program stops.\n\
2489 Arguments are the code numbers of the expressions to stop displaying.\n\
2490 No argument means cancel all automatic-display expressions.\n\
2491 Do \"info display\" to see current list of code numbers.", &deletelist);
2493 add_com ("printf", class_vars, printf_command,
2494 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2495 This is useful for formatted output in user-defined commands.");
2497 add_com ("output", class_vars, output_command,
2498 "Like \"print\" but don't put in value history and don't print newline.\n\
2499 This is useful in user-defined commands.");
2501 add_prefix_cmd ("set", class_vars, set_command,
2502 concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2503 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2504 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2505 with $), a register (a few standard names starting with $), or an actual\n\
2506 variable in the program being debugged. EXP is any valid expression.\n",
2507 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2508 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2509 You can see these environment settings with the \"show\" command.", NULL),
2510 &setlist, "set ", 1, &cmdlist);
2512 add_com ("assign", class_vars, set_command, concat ("Evaluate expression \
2513 EXP and assign result to variable VAR, using assignment\n\
2514 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2515 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2516 with $), a register (a few standard names starting with $), or an actual\n\
2517 variable in the program being debugged. EXP is any valid expression.\n",
2518 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2519 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2520 You can see these environment settings with the \"show\" command.", NULL));
2522 /* "call" is the same as "set", but handy for dbx users to call fns. */
2523 add_com ("call", class_vars, call_command,
2524 "Call a function in the program.\n\
2525 The argument is the function name and arguments, in the notation of the\n\
2526 current working language. The result is printed and saved in the value\n\
2527 history, if it is not void.");
2529 add_cmd ("variable", class_vars, set_command,
2530 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2531 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2532 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2533 with $), a register (a few standard names starting with $), or an actual\n\
2534 variable in the program being debugged. EXP is any valid expression.\n\
2535 This may usually be abbreviated to simply \"set\".",
2538 add_com ("print", class_vars, print_command,
2539 concat ("Print value of expression EXP.\n\
2540 Variables accessible are those of the lexical environment of the selected\n\
2541 stack frame, plus all those whose scope is global or an entire file.\n\
2543 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2544 $$NUM refers to NUM'th value back from the last one.\n\
2545 Names starting with $ refer to registers (with the values they would have\n",
2546 "if the program were to return to the stack frame now selected, restoring\n\
2547 all registers saved by frames farther in) or else to debugger\n\
2548 \"convenience\" variables (any such name not a known register).\n\
2549 Use assignment expressions to give values to convenience variables.\n",
2551 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2552 @ is a binary operator for treating consecutive data objects\n\
2553 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2554 element is FOO, whose second element is stored in the space following\n\
2555 where FOO is stored, etc. FOO must be an expression whose value\n\
2556 resides in memory.\n",
2558 EXP may be preceded with /FMT, where FMT is a format letter\n\
2559 but no count or size letter (see \"x\" command).", NULL));
2560 add_com_alias ("p", "print", class_vars, 1);
2562 add_com ("inspect", class_vars, inspect_command,
2563 "Same as \"print\" command, except that if you are running in the epoch\n\
2564 environment, the value is printed in its own window.");
2567 add_set_cmd ("max-symbolic-offset", no_class, var_uinteger,
2568 (char *) &max_symbolic_offset,
2569 "Set the largest offset that will be printed in <symbol+1234> form.",
2573 add_set_cmd ("symbol-filename", no_class, var_boolean,
2574 (char *) &print_symbol_filename,
2575 "Set printing of source filename and line number with <symbol>.",
2579 /* For examine/instruction a single byte quantity is specified as
2580 the data. This avoids problems with value_at_lazy() requiring a
2581 valid data type (and rejecting VOID). */
2582 examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
2584 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2585 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2586 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2587 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);