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, Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
28 #include "expression.h"
32 #include "breakpoint.h"
36 #include "symfile.h" /* for overlay functions */
37 #include "objfiles.h" /* ditto */
39 extern int asm_demangle; /* Whether to demangle syms in asm printouts */
40 extern int addressprint; /* Whether to print hex addresses in HLL " */
49 /* Last specified output format. */
51 static char last_format = 'x';
53 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
55 static char last_size = 'w';
57 /* Default address to examine next. */
59 static CORE_ADDR next_address;
61 /* Default section to examine next. */
63 static asection *next_section;
65 /* Last address examined. */
67 static CORE_ADDR last_examine_address;
69 /* Contents of last address examined.
70 This is not valid past the end of the `x' command! */
72 static value_ptr last_examine_value;
74 /* Largest offset between a symbolic value and an address, that will be
75 printed as `0x1234 <symbol+offset>'. */
77 static unsigned int max_symbolic_offset = UINT_MAX;
79 /* Append the source filename and linenumber of the symbol when
80 printing a symbolic value as `<symbol at filename:linenum>' if set. */
81 static int print_symbol_filename = 0;
83 /* Number of auto-display expression currently being displayed.
84 So that we can disable it if we get an error or a signal within it.
85 -1 when not doing one. */
87 int current_display_number;
89 /* Flag to low-level print routines that this value is being printed
90 in an epoch window. We'd like to pass this as a parameter, but
91 every routine would need to take it. Perhaps we can encapsulate
92 this in the I/O stream once we have GNU stdio. */
98 /* Chain link to next auto-display item. */
100 /* Expression to be evaluated and displayed. */
101 struct expression *exp;
102 /* Item number of this auto-display item. */
104 /* Display format specified. */
105 struct format_data format;
106 /* Innermost block required by this expression when evaluated */
108 /* Status of this display (enabled or disabled) */
112 /* Chain of expressions whose values should be displayed
113 automatically each time the program stops. */
115 static struct display *display_chain;
117 static int display_number;
119 /* Prototypes for exported functions. */
121 void output_command PARAMS ((char *, int));
123 void _initialize_printcmd PARAMS ((void));
125 /* Prototypes for local functions. */
127 static void delete_display PARAMS ((int));
129 static void enable_display PARAMS ((char *, int));
131 static void disable_display_command PARAMS ((char *, int));
133 static void disassemble_command PARAMS ((char *, int));
135 static void printf_command PARAMS ((char *, int));
137 static void print_frame_nameless_args PARAMS ((struct frame_info *, long,
138 int, int, GDB_FILE *));
140 static void display_info PARAMS ((char *, int));
142 static void do_one_display PARAMS ((struct display *));
144 static void undisplay_command PARAMS ((char *, int));
146 static void free_display PARAMS ((struct display *));
148 static void display_command PARAMS ((char *, int));
150 void x_command PARAMS ((char *, int));
152 static void address_info PARAMS ((char *, int));
154 static void set_command PARAMS ((char *, int));
156 static void call_command PARAMS ((char *, int));
158 static void inspect_command PARAMS ((char *, int));
160 static void print_command PARAMS ((char *, int));
162 static void print_command_1 PARAMS ((char *, int, int));
164 static void validate_format PARAMS ((struct format_data, char *));
166 static void do_examine PARAMS ((struct format_data, CORE_ADDR addr, asection *section));
168 static void print_formatted PARAMS ((value_ptr, int, int));
170 static struct format_data decode_format PARAMS ((char **, int, int));
172 static int print_insn PARAMS ((CORE_ADDR, GDB_FILE *));
174 static void sym_info PARAMS ((char *, int));
177 /* Decode a format specification. *STRING_PTR should point to it.
178 OFORMAT and OSIZE are used as defaults for the format and size
179 if none are given in the format specification.
180 If OSIZE is zero, then the size field of the returned value
181 should be set only if a size is explicitly specified by the
183 The structure returned describes all the data
184 found in the specification. In addition, *STRING_PTR is advanced
185 past the specification and past all whitespace following it. */
187 static struct format_data
188 decode_format (string_ptr, oformat, osize)
193 struct format_data val;
194 register char *p = *string_ptr;
200 if (*p >= '0' && *p <= '9')
201 val.count = atoi (p);
202 while (*p >= '0' && *p <= '9') p++;
204 /* Now process size or format letters that follow. */
208 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
210 else if (*p >= 'a' && *p <= 'z')
216 while (*p == ' ' || *p == '\t') p++;
219 /* Set defaults for format and size if not specified. */
220 if (val.format == '?')
224 /* Neither has been specified. */
225 val.format = oformat;
229 /* If a size is specified, any format makes a reasonable
230 default except 'i'. */
231 val.format = oformat == 'i' ? 'x' : oformat;
233 else if (val.size == '?')
238 /* Pick the appropriate size for an address. */
239 if (TARGET_PTR_BIT == 64)
240 val.size = osize ? 'g' : osize;
241 else if (TARGET_PTR_BIT == 32)
242 val.size = osize ? 'w' : osize;
243 else if (TARGET_PTR_BIT == 16)
244 val.size = osize ? 'h' : osize;
246 /* Bad value for TARGET_PTR_BIT */
250 /* Floating point has to be word or giantword. */
251 if (osize == 'w' || osize == 'g')
254 /* Default it to giantword if the last used size is not
256 val.size = osize ? 'g' : osize;
259 /* Characters default to one byte. */
260 val.size = osize ? 'b' : osize;
263 /* The default is the size most recently specified. */
270 /* Print value VAL on gdb_stdout according to FORMAT, a letter or 0.
271 Do not end with a newline.
272 0 means print VAL according to its own type.
273 SIZE is the letter for the size of datum being printed.
274 This is used to pad hex numbers so they line up. */
277 print_formatted (val, format, size)
278 register value_ptr val;
282 struct type *type = check_typedef (VALUE_TYPE (val));
283 int len = TYPE_LENGTH (type);
285 if (VALUE_LVAL (val) == lval_memory)
287 next_address = VALUE_ADDRESS (val) + len;
288 next_section = VALUE_BFD_SECTION (val);
294 /* FIXME: Need to handle wchar_t's here... */
295 next_address = VALUE_ADDRESS (val)
296 + val_print_string (VALUE_ADDRESS (val), -1, 1, gdb_stdout);
297 next_section = VALUE_BFD_SECTION (val);
301 /* The old comment says
302 "Force output out, print_insn not using _filtered".
303 I'm not completely sure what that means, I suspect most print_insn
304 now do use _filtered, so I guess it's obsolete.
305 --Yes, it does filter now, and so this is obsolete. -JB */
307 /* We often wrap here if there are long symbolic names. */
309 next_address = VALUE_ADDRESS (val)
310 + print_insn (VALUE_ADDRESS (val), gdb_stdout);
311 next_section = VALUE_BFD_SECTION (val);
316 || TYPE_CODE (type) == TYPE_CODE_ARRAY
317 || TYPE_CODE (type) == TYPE_CODE_STRING
318 || TYPE_CODE (type) == TYPE_CODE_STRUCT
319 || TYPE_CODE (type) == TYPE_CODE_UNION)
320 /* If format is 0, use the 'natural' format for
321 * that type of value. If the type is non-scalar,
322 * we have to use language rules to print it as
323 * a series of scalars.
325 value_print (val, gdb_stdout, format, Val_pretty_default);
327 /* User specified format, so don't look to the
328 * the type to tell us what to do.
330 print_scalar_formatted (VALUE_CONTENTS (val), type,
331 format, size, gdb_stdout);
335 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
336 according to letters FORMAT and SIZE on STREAM.
337 FORMAT may not be zero. Formats s and i are not supported at this level.
339 This is how the elements of an array or structure are printed
343 print_scalar_formatted (valaddr, type, format, size, stream)
351 unsigned int len = TYPE_LENGTH (type);
353 if (len > sizeof (LONGEST)
361 if (! TYPE_UNSIGNED (type)
362 || ! extract_long_unsigned_integer (valaddr, len, &val_long))
364 /* We can't print it normally, but we can print it in hex.
365 Printing it in the wrong radix is more useful than saying
366 "use /x, you dummy". */
367 /* FIXME: we could also do octal or binary if that was the
369 /* FIXME: we should be using the size field to give us a
370 minimum field width to print. */
373 print_octal_chars (stream, valaddr, len);
374 else if( format == 'd' )
375 print_decimal_chars (stream, valaddr, len );
376 else if( format == 't' )
377 print_binary_chars (stream, valaddr, len);
380 /* replace with call to print_hex_chars? Looks
381 like val_print_type_code_int is redoing
384 val_print_type_code_int (type, valaddr, stream);
389 /* If we get here, extract_long_unsigned_integer set val_long. */
391 else if (format != 'f')
392 val_long = unpack_long (type, valaddr);
394 /* If we are printing it as unsigned, truncate it in case it is actually
395 a negative signed value (e.g. "print/u (short)-1" should print 65535
396 (if shorts are 16 bits) instead of 4294967295). */
399 if (len < sizeof (LONGEST))
400 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
408 /* no size specified, like in print. Print varying # of digits. */
409 print_longest (stream, 'x', 1, val_long);
418 print_longest (stream, size, 1, val_long);
421 error ("Undefined output size \"%c\".", size);
426 print_longest (stream, 'd', 1, val_long);
430 print_longest (stream, 'u', 0, val_long);
435 print_longest (stream, 'o', 1, val_long);
437 fprintf_filtered (stream, "0");
441 print_address (unpack_pointer (type, valaddr), stream);
445 value_print (value_from_longest (builtin_type_char, val_long), stream, 0,
450 if (len == sizeof (float))
451 type = builtin_type_float;
452 else if (len == sizeof (double))
453 type = builtin_type_double;
454 print_floating (valaddr, type, stream);
461 /* Binary; 't' stands for "two". */
463 char bits[8*(sizeof val_long) + 1];
464 char buf[8*(sizeof val_long) + 32];
469 width = 8*(sizeof val_long);
486 error ("Undefined output size \"%c\".", size);
492 bits[width] = (val_long & 1) ? '1' : '0';
497 while (*cp && *cp == '0')
502 strcpy (buf, local_binary_format_prefix());
504 strcat (buf, local_binary_format_suffix());
505 fprintf_filtered (stream, buf);
510 error ("Undefined output format \"%c\".", format);
514 /* Specify default address for `x' command.
515 `info lines' uses this. */
518 set_next_address (addr)
523 /* Make address available to the user as $_. */
524 set_internalvar (lookup_internalvar ("_"),
525 value_from_longest (lookup_pointer_type (builtin_type_void),
529 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
530 after LEADIN. Print nothing if no symbolic name is found nearby.
531 Optionally also print source file and line number, if available.
532 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
533 or to interpret it as a possible C++ name and convert it back to source
534 form. However note that DO_DEMANGLE can be overridden by the specific
535 settings of the demangle and asm_demangle variables. */
538 print_address_symbolic (addr, stream, do_demangle, leadin)
544 struct minimal_symbol *msymbol;
545 struct symbol *symbol;
546 struct symtab *symtab = 0;
547 CORE_ADDR name_location = 0;
549 asection *section = 0;
552 /* Determine if the address is in an overlay, and whether it is mapped. */
553 if (overlay_debugging)
555 section = find_pc_overlay (addr);
556 if (pc_in_unmapped_range (addr, section))
559 addr = overlay_mapped_address (addr, section);
563 /* On some targets, add in extra "flag" bits to PC for
564 disassembly. This should ensure that "rounding errors" in
565 symbol addresses that are masked for disassembly favour the
566 the correct symbol. */
568 #ifdef GDB_TARGET_UNMASK_DISAS_PC
569 addr = GDB_TARGET_UNMASK_DISAS_PC (addr);
572 /* First try to find the address in the symbol table, then
573 in the minsyms. Take the closest one. */
575 /* This is defective in the sense that it only finds text symbols. So
576 really this is kind of pointless--we should make sure that the
577 minimal symbols have everything we need (by changing that we could
578 save some memory, but for many debug format--ELF/DWARF or
579 anything/stabs--it would be inconvenient to eliminate those minimal
581 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
582 symbol = find_pc_sect_function (addr, section);
586 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
588 name = SYMBOL_SOURCE_NAME (symbol);
590 name = SYMBOL_LINKAGE_NAME (symbol);
595 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
597 /* The msymbol is closer to the address than the symbol;
598 use the msymbol instead. */
601 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
603 name = SYMBOL_SOURCE_NAME (msymbol);
605 name = SYMBOL_LINKAGE_NAME (msymbol);
608 if (symbol == NULL && msymbol == NULL)
611 /* On some targets, mask out extra "flag" bits from PC for handsome
614 #ifdef GDB_TARGET_MASK_DISAS_PC
615 name_location = GDB_TARGET_MASK_DISAS_PC (name_location);
616 addr = GDB_TARGET_MASK_DISAS_PC (addr);
619 /* If the nearest symbol is too far away, don't print anything symbolic. */
621 /* For when CORE_ADDR is larger than unsigned int, we do math in
622 CORE_ADDR. But when we detect unsigned wraparound in the
623 CORE_ADDR math, we ignore this test and print the offset,
624 because addr+max_symbolic_offset has wrapped through the end
625 of the address space back to the beginning, giving bogus comparison. */
626 if (addr > name_location + max_symbolic_offset
627 && name_location + max_symbolic_offset > name_location)
630 fputs_filtered (leadin, stream);
632 fputs_filtered ("<*", stream);
634 fputs_filtered ("<", stream);
635 fputs_filtered (name, stream);
636 if (addr != name_location)
637 fprintf_filtered (stream, "+%u", (unsigned int)(addr - name_location));
639 /* Append source filename and line number if desired. Give specific
640 line # of this addr, if we have it; else line # of the nearest symbol. */
641 if (print_symbol_filename)
643 struct symtab_and_line sal;
645 sal = find_pc_sect_line (addr, section, 0);
648 fprintf_filtered (stream, " at %s:%d", sal.symtab->filename, sal.line);
649 else if (symtab && symbol && symbol->line)
650 fprintf_filtered (stream, " at %s:%d", symtab->filename, symbol->line);
652 fprintf_filtered (stream, " in %s", symtab->filename);
655 fputs_filtered ("*>", stream);
657 fputs_filtered (">", stream);
661 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
664 print_address_numeric (addr, use_local, stream)
669 /* This assumes a CORE_ADDR can fit in a LONGEST. Probably a safe
671 print_longest (stream, 'x', use_local, (ULONGEST) addr);
674 /* Print address ADDR symbolically on STREAM.
675 First print it as a number. Then perhaps print
676 <SYMBOL + OFFSET> after the number. */
679 print_address (addr, stream)
683 print_address_numeric (addr, 1, stream);
684 print_address_symbolic (addr, stream, asm_demangle, " ");
687 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
688 controls whether to print the symbolic name "raw" or demangled.
689 Global setting "addressprint" controls whether to print hex address
693 print_address_demangle (addr, stream, do_demangle)
700 fprintf_filtered (stream, "0");
702 else if (addressprint)
704 print_address_numeric (addr, 1, stream);
705 print_address_symbolic (addr, stream, do_demangle, " ");
709 print_address_symbolic (addr, stream, do_demangle, "");
714 /* These are the types that $__ will get after an examine command of one
717 static struct type *examine_i_type;
719 static struct type *examine_b_type;
720 static struct type *examine_h_type;
721 static struct type *examine_w_type;
722 static struct type *examine_g_type;
724 /* Examine data at address ADDR in format FMT.
725 Fetch it from memory and print on gdb_stdout. */
728 do_examine (fmt, addr, sect)
729 struct format_data fmt;
733 register char format = 0;
735 register int count = 1;
736 struct type *val_type = NULL;
738 register int maxelts;
746 /* String or instruction format implies fetch single bytes
747 regardless of the specified size. */
748 if (format == 's' || format == 'i')
752 val_type = examine_i_type;
753 else if (size == 'b')
754 val_type = examine_b_type;
755 else if (size == 'h')
756 val_type = examine_h_type;
757 else if (size == 'w')
758 val_type = examine_w_type;
759 else if (size == 'g')
760 val_type = examine_g_type;
767 if (format == 's' || format == 'i')
770 /* Print as many objects as specified in COUNT, at most maxelts per line,
771 with the address of the next one at the start of each line. */
776 print_address (next_address, gdb_stdout);
777 printf_filtered (":");
782 printf_filtered ("\t");
783 /* Note that print_formatted sets next_address for the next
785 last_examine_address = next_address;
787 if (last_examine_value)
788 value_free (last_examine_value);
790 /* The value to be displayed is not fetched greedily.
791 Instead, to avoid the posibility of a fetched value not
792 being used, its retreval is delayed until the print code
793 uses it. When examining an instruction stream, the
794 disassembler will perform its own memory fetch using just
795 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
796 the disassembler be modified so that LAST_EXAMINE_VALUE
797 is left with the byte sequence from the last complete
798 instruction fetched from memory? */
799 last_examine_value = value_at_lazy (val_type, next_address, sect);
801 if (last_examine_value)
802 release_value (last_examine_value);
804 print_formatted (last_examine_value, format, size);
806 printf_filtered ("\n");
807 gdb_flush (gdb_stdout);
812 validate_format (fmt, cmdname)
813 struct format_data fmt;
817 error ("Size letters are meaningless in \"%s\" command.", cmdname);
819 error ("Item count other than 1 is meaningless in \"%s\" command.",
821 if (fmt.format == 'i' || fmt.format == 's')
822 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
823 fmt.format, cmdname);
826 /* Evaluate string EXP as an expression in the current language and
827 print the resulting value. EXP may contain a format specifier as the
828 first argument ("/x myvar" for example, to print myvar in hex).
832 print_command_1 (exp, inspect, voidprint)
837 struct expression *expr;
838 register struct cleanup *old_chain = 0;
839 register char format = 0;
840 register value_ptr val;
841 struct format_data fmt;
844 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
845 inspect_it = inspect;
847 if (exp && *exp == '/')
850 fmt = decode_format (&exp, last_format, 0);
851 validate_format (fmt, "print");
852 last_format = format = fmt.format;
863 extern int objectprint;
865 expr = parse_expression (exp);
866 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
869 val = evaluate_expression (expr);
871 /* C++: figure out what type we actually want to print it as. */
872 type = VALUE_TYPE (val);
875 && ( TYPE_CODE (type) == TYPE_CODE_PTR
876 || TYPE_CODE (type) == TYPE_CODE_REF)
877 && ( TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT
878 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION))
882 v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
886 type = VALUE_TYPE (val);
891 val = access_value_history (0);
893 if (voidprint || (val && VALUE_TYPE (val) &&
894 TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
896 int histindex = record_latest_value (val);
899 annotate_value_history_begin (histindex, VALUE_TYPE (val));
901 annotate_value_begin (VALUE_TYPE (val));
904 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
906 if (histindex >= 0) printf_filtered ("$%d = ", histindex);
909 annotate_value_history_value ();
911 print_formatted (val, format, fmt.size);
912 printf_filtered ("\n");
915 annotate_value_history_end ();
917 annotate_value_end ();
920 printf_unfiltered("\") )\030");
924 do_cleanups (old_chain);
925 inspect_it = 0; /* Reset print routines to normal */
930 print_command (exp, from_tty)
934 print_command_1 (exp, 0, 1);
937 /* Same as print, except in epoch, it gets its own window */
940 inspect_command (exp, from_tty)
944 extern int epoch_interface;
946 print_command_1 (exp, epoch_interface, 1);
949 /* Same as print, except it doesn't print void results. */
952 call_command (exp, from_tty)
956 print_command_1 (exp, 0, 0);
961 output_command (exp, from_tty)
965 struct expression *expr;
966 register struct cleanup *old_chain;
967 register char format = 0;
968 register value_ptr val;
969 struct format_data fmt;
971 if (exp && *exp == '/')
974 fmt = decode_format (&exp, 0, 0);
975 validate_format (fmt, "output");
979 expr = parse_expression (exp);
980 old_chain = make_cleanup ((make_cleanup_func) free_current_contents, &expr);
982 val = evaluate_expression (expr);
984 annotate_value_begin (VALUE_TYPE (val));
986 print_formatted (val, format, fmt.size);
988 annotate_value_end ();
990 do_cleanups (old_chain);
995 set_command (exp, from_tty)
999 struct expression *expr = parse_expression (exp);
1000 register struct cleanup *old_chain
1001 = make_cleanup ((make_cleanup_func) free_current_contents, &expr);
1002 evaluate_expression (expr);
1003 do_cleanups (old_chain);
1008 sym_info (arg, from_tty)
1012 struct minimal_symbol *msymbol;
1013 struct objfile *objfile;
1014 struct obj_section *osect;
1016 CORE_ADDR addr, sect_addr;
1018 unsigned int offset;
1021 error_no_arg ("address");
1023 addr = parse_and_eval_address (arg);
1024 ALL_OBJSECTIONS (objfile, osect)
1026 sect = osect->the_bfd_section;
1027 sect_addr = overlay_mapped_address (addr, sect);
1029 if (osect->addr <= sect_addr && sect_addr < osect->endaddr &&
1030 (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect)))
1033 offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
1035 printf_filtered ("%s + %u in ",
1036 SYMBOL_SOURCE_NAME (msymbol), offset);
1038 printf_filtered ("%s in ",
1039 SYMBOL_SOURCE_NAME (msymbol));
1040 if (pc_in_unmapped_range (addr, sect))
1041 printf_filtered ("load address range of ");
1042 if (section_is_overlay (sect))
1043 printf_filtered ("%s overlay ",
1044 section_is_mapped (sect) ? "mapped" : "unmapped");
1045 printf_filtered ("section %s", sect->name);
1046 printf_filtered ("\n");
1050 printf_filtered ("No symbol matches %s.\n", arg);
1055 address_info (exp, from_tty)
1059 register struct symbol *sym;
1060 register struct minimal_symbol *msymbol;
1062 register long basereg;
1064 CORE_ADDR load_addr;
1065 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
1066 if exp is a field of `this'. */
1069 error ("Argument required.");
1071 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
1072 &is_a_field_of_this, (struct symtab **)NULL);
1075 if (is_a_field_of_this)
1077 printf_filtered ("Symbol \"");
1078 fprintf_symbol_filtered (gdb_stdout, exp,
1079 current_language->la_language, DMGL_ANSI);
1080 printf_filtered ("\" is a field of the local class variable `this'\n");
1084 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1086 if (msymbol != NULL)
1088 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1090 printf_filtered ("Symbol \"");
1091 fprintf_symbol_filtered (gdb_stdout, exp,
1092 current_language->la_language, DMGL_ANSI);
1093 printf_filtered ("\" is at ");
1094 print_address_numeric (load_addr, 1, gdb_stdout);
1095 printf_filtered (" in a file compiled without debugging");
1096 section = SYMBOL_BFD_SECTION (msymbol);
1097 if (section_is_overlay (section))
1099 load_addr = overlay_unmapped_address (load_addr, section);
1100 printf_filtered (",\n -- loaded at ");
1101 print_address_numeric (load_addr, 1, gdb_stdout);
1102 printf_filtered (" in overlay section %s", section->name);
1104 printf_filtered (".\n");
1107 error ("No symbol \"%s\" in current context.", exp);
1111 printf_filtered ("Symbol \"");
1112 fprintf_symbol_filtered (gdb_stdout, SYMBOL_NAME (sym),
1113 current_language->la_language, DMGL_ANSI);
1114 printf_filtered ("\" is ");
1115 val = SYMBOL_VALUE (sym);
1116 basereg = SYMBOL_BASEREG (sym);
1117 section = SYMBOL_BFD_SECTION (sym);
1119 switch (SYMBOL_CLASS (sym))
1122 case LOC_CONST_BYTES:
1123 printf_filtered ("constant");
1127 printf_filtered ("a label at address ");
1128 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1130 if (section_is_overlay (section))
1132 load_addr = overlay_unmapped_address (load_addr, section);
1133 printf_filtered (",\n -- loaded at ");
1134 print_address_numeric (load_addr, 1, gdb_stdout);
1135 printf_filtered (" in overlay section %s", section->name);
1140 printf_filtered ("a variable in register %s", REGISTER_NAME (val));
1144 printf_filtered ("static storage at address ");
1145 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1147 if (section_is_overlay (section))
1149 load_addr = overlay_unmapped_address (load_addr, section);
1150 printf_filtered (",\n -- loaded at ");
1151 print_address_numeric (load_addr, 1, gdb_stdout);
1152 printf_filtered (" in overlay section %s", section->name);
1157 printf_filtered ("external global (indirect addressing), at address *(");
1158 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1160 printf_filtered (")");
1161 if (section_is_overlay (section))
1163 load_addr = overlay_unmapped_address (load_addr, section);
1164 printf_filtered (",\n -- loaded at ");
1165 print_address_numeric (load_addr, 1, gdb_stdout);
1166 printf_filtered (" in overlay section %s", section->name);
1171 printf_filtered ("an argument in register %s", REGISTER_NAME (val));
1174 case LOC_REGPARM_ADDR:
1175 printf_filtered ("address of an argument in register %s", REGISTER_NAME (val));
1179 printf_filtered ("an argument at offset %ld", val);
1183 printf_filtered ("an argument at frame offset %ld", val);
1187 printf_filtered ("a local variable at frame offset %ld", val);
1191 printf_filtered ("a reference argument at offset %ld", val);
1195 printf_filtered ("a variable at offset %ld from register %s",
1196 val, REGISTER_NAME (basereg));
1199 case LOC_BASEREG_ARG:
1200 printf_filtered ("an argument at offset %ld from register %s",
1201 val, REGISTER_NAME (basereg));
1205 printf_filtered ("a typedef");
1209 printf_filtered ("a function at address ");
1210 #ifdef GDB_TARGET_MASK_DISAS_PC
1211 print_address_numeric
1212 (load_addr= GDB_TARGET_MASK_DISAS_PC (BLOCK_START (SYMBOL_BLOCK_VALUE (sym))),
1215 print_address_numeric (load_addr=BLOCK_START (SYMBOL_BLOCK_VALUE (sym)),
1218 if (section_is_overlay (section))
1220 load_addr = overlay_unmapped_address (load_addr, section);
1221 printf_filtered (",\n -- loaded at ");
1222 print_address_numeric (load_addr, 1, gdb_stdout);
1223 printf_filtered (" in overlay section %s", section->name);
1227 case LOC_UNRESOLVED:
1229 struct minimal_symbol *msym;
1231 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, NULL);
1233 printf_filtered ("unresolved");
1236 section = SYMBOL_BFD_SECTION (msym);
1237 printf_filtered ("static storage at address ");
1238 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (msym),
1240 if (section_is_overlay (section))
1242 load_addr = overlay_unmapped_address (load_addr, section);
1243 printf_filtered (",\n -- loaded at ");
1244 print_address_numeric (load_addr, 1, gdb_stdout);
1245 printf_filtered (" in overlay section %s", section->name);
1251 case LOC_THREAD_LOCAL_STATIC:
1253 "a thread-local variable at offset %ld from the thread base register %s",
1254 val, REGISTER_NAME (basereg));
1257 case LOC_OPTIMIZED_OUT:
1258 printf_filtered ("optimized out");
1262 printf_filtered ("of unknown (botched) type");
1265 printf_filtered (".\n");
1269 x_command (exp, from_tty)
1273 struct expression *expr;
1274 struct format_data fmt;
1275 struct cleanup *old_chain;
1278 fmt.format = last_format;
1279 fmt.size = last_size;
1282 if (exp && *exp == '/')
1285 fmt = decode_format (&exp, last_format, last_size);
1288 /* If we have an expression, evaluate it and use it as the address. */
1290 if (exp != 0 && *exp != 0)
1292 expr = parse_expression (exp);
1293 /* Cause expression not to be there any more
1294 if this command is repeated with Newline.
1295 But don't clobber a user-defined command's definition. */
1298 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
1300 val = evaluate_expression (expr);
1301 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
1302 val = value_ind (val);
1303 /* In rvalue contexts, such as this, functions are coerced into
1304 pointers to functions. This makes "x/i main" work. */
1305 if (/* last_format == 'i'
1306 && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
1307 && VALUE_LVAL (val) == lval_memory)
1308 next_address = VALUE_ADDRESS (val);
1310 next_address = value_as_pointer (val);
1311 if (VALUE_BFD_SECTION (val))
1312 next_section = VALUE_BFD_SECTION (val);
1313 do_cleanups (old_chain);
1316 do_examine (fmt, next_address, next_section);
1318 /* If the examine succeeds, we remember its size and format for next time. */
1319 last_size = fmt.size;
1320 last_format = fmt.format;
1322 /* Set a couple of internal variables if appropriate. */
1323 if (last_examine_value)
1325 /* Make last address examined available to the user as $_. Use
1326 the correct pointer type. */
1327 set_internalvar (lookup_internalvar ("_"),
1328 value_from_longest (
1329 lookup_pointer_type (VALUE_TYPE (last_examine_value)),
1330 (LONGEST) last_examine_address));
1332 /* Make contents of last address examined available to the user as $__.*/
1333 /* If the last value has not been fetched from memory then don't
1334 fetch it now - instead mark it by voiding the $__ variable. */
1335 if (VALUE_LAZY (last_examine_value))
1336 set_internalvar (lookup_internalvar ("__"),
1337 allocate_value (builtin_type_void));
1339 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1344 /* Add an expression to the auto-display chain.
1345 Specify the expression. */
1348 display_command (exp, from_tty)
1352 struct format_data fmt;
1353 register struct expression *expr;
1354 register struct display *new;
1358 if (tui_version && *exp == '$')
1359 display_it = ((TuiStatus)tuiDo(
1360 (TuiOpaqueFuncPtr)tui_vSetLayoutTo, exp) == TUI_FAILURE);
1374 fmt = decode_format (&exp, 0, 0);
1375 if (fmt.size && fmt.format == 0)
1377 if (fmt.format == 'i' || fmt.format == 's')
1387 innermost_block = 0;
1388 expr = parse_expression (exp);
1390 new = (struct display *) xmalloc (sizeof (struct display));
1393 new->block = innermost_block;
1394 new->next = display_chain;
1395 new->number = ++display_number;
1397 new->status = enabled;
1398 display_chain = new;
1400 if (from_tty && target_has_execution)
1401 do_one_display (new);
1415 /* Clear out the display_chain.
1416 Done when new symtabs are loaded, since this invalidates
1417 the types stored in many expressions. */
1422 register struct display *d;
1424 while ((d = display_chain) != NULL)
1427 display_chain = d->next;
1432 /* Delete the auto-display number NUM. */
1435 delete_display (num)
1438 register struct display *d1, *d;
1441 error ("No display number %d.", num);
1443 if (display_chain->number == num)
1446 display_chain = d1->next;
1450 for (d = display_chain; ; d = d->next)
1453 error ("No display number %d.", num);
1454 if (d->next->number == num)
1464 /* Delete some values from the auto-display chain.
1465 Specify the element numbers. */
1468 undisplay_command (args, from_tty)
1472 register char *p = args;
1478 if (query ("Delete all auto-display expressions? "))
1487 while (*p1 >= '0' && *p1 <= '9') p1++;
1488 if (*p1 && *p1 != ' ' && *p1 != '\t')
1489 error ("Arguments must be display numbers.");
1493 delete_display (num);
1496 while (*p == ' ' || *p == '\t') p++;
1501 /* Display a single auto-display.
1502 Do nothing if the display cannot be printed in the current context,
1503 or if the display is disabled. */
1509 int within_current_scope;
1511 if (d->status == disabled)
1515 within_current_scope = contained_in (get_selected_block (), d->block);
1517 within_current_scope = 1;
1518 if (!within_current_scope)
1521 current_display_number = d->number;
1523 annotate_display_begin ();
1524 printf_filtered ("%d", d->number);
1525 annotate_display_number_end ();
1526 printf_filtered (": ");
1532 annotate_display_format ();
1534 printf_filtered ("x/");
1535 if (d->format.count != 1)
1536 printf_filtered ("%d", d->format.count);
1537 printf_filtered ("%c", d->format.format);
1538 if (d->format.format != 'i' && d->format.format != 's')
1539 printf_filtered ("%c", d->format.size);
1540 printf_filtered (" ");
1542 annotate_display_expression ();
1544 print_expression (d->exp, gdb_stdout);
1545 annotate_display_expression_end ();
1547 if (d->format.count != 1)
1548 printf_filtered ("\n");
1550 printf_filtered (" ");
1552 val = evaluate_expression (d->exp);
1553 addr = value_as_pointer (val);
1554 if (d->format.format == 'i')
1555 addr = ADDR_BITS_REMOVE (addr);
1557 annotate_display_value ();
1559 do_examine (d->format, addr, VALUE_BFD_SECTION (val));
1563 annotate_display_format ();
1565 if (d->format.format)
1566 printf_filtered ("/%c ", d->format.format);
1568 annotate_display_expression ();
1570 print_expression (d->exp, gdb_stdout);
1571 annotate_display_expression_end ();
1573 printf_filtered (" = ");
1575 annotate_display_expression ();
1577 print_formatted (evaluate_expression (d->exp),
1578 d->format.format, d->format.size);
1579 printf_filtered ("\n");
1582 annotate_display_end ();
1584 gdb_flush (gdb_stdout);
1585 current_display_number = -1;
1588 /* Display all of the values on the auto-display chain which can be
1589 evaluated in the current scope. */
1594 register struct display *d;
1596 for (d = display_chain; d; d = d->next)
1600 /* Delete the auto-display which we were in the process of displaying.
1601 This is done when there is an error or a signal. */
1604 disable_display (num)
1607 register struct display *d;
1609 for (d = display_chain; d; d = d->next)
1610 if (d->number == num)
1612 d->status = disabled;
1615 printf_unfiltered ("No display number %d.\n", num);
1619 disable_current_display ()
1621 if (current_display_number >= 0)
1623 disable_display (current_display_number);
1624 fprintf_unfiltered (gdb_stderr, "Disabling display %d to avoid infinite recursion.\n",
1625 current_display_number);
1627 current_display_number = -1;
1631 display_info (ignore, from_tty)
1635 register struct display *d;
1638 printf_unfiltered ("There are no auto-display expressions now.\n");
1640 printf_filtered ("Auto-display expressions now in effect:\n\
1641 Num Enb Expression\n");
1643 for (d = display_chain; d; d = d->next)
1645 printf_filtered ("%d: %c ", d->number, "ny"[(int)d->status]);
1647 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1649 else if (d->format.format)
1650 printf_filtered ("/%c ", d->format.format);
1651 print_expression (d->exp, gdb_stdout);
1652 if (d->block && !contained_in (get_selected_block (), d->block))
1653 printf_filtered (" (cannot be evaluated in the current context)");
1654 printf_filtered ("\n");
1655 gdb_flush (gdb_stdout);
1660 enable_display (args, from_tty)
1664 register char *p = args;
1667 register struct display *d;
1671 for (d = display_chain; d; d = d->next)
1672 d->status = enabled;
1678 while (*p1 >= '0' && *p1 <= '9')
1680 if (*p1 && *p1 != ' ' && *p1 != '\t')
1681 error ("Arguments must be display numbers.");
1685 for (d = display_chain; d; d = d->next)
1686 if (d->number == num)
1688 d->status = enabled;
1691 printf_unfiltered ("No display number %d.\n", num);
1694 while (*p == ' ' || *p == '\t')
1701 disable_display_command (args, from_tty)
1705 register char *p = args;
1707 register struct display *d;
1711 for (d = display_chain; d; d = d->next)
1712 d->status = disabled;
1718 while (*p1 >= '0' && *p1 <= '9')
1720 if (*p1 && *p1 != ' ' && *p1 != '\t')
1721 error ("Arguments must be display numbers.");
1723 disable_display (atoi (p));
1726 while (*p == ' ' || *p == '\t')
1732 /* Print the value in stack frame FRAME of a variable
1733 specified by a struct symbol. */
1736 print_variable_value (var, frame, stream)
1738 struct frame_info *frame;
1741 value_ptr val = read_var_value (var, frame);
1743 value_print (val, stream, 0, Val_pretty_default);
1746 /* Print the arguments of a stack frame, given the function FUNC
1747 running in that frame (as a symbol), the info on the frame,
1748 and the number of args according to the stack frame (or -1 if unknown). */
1750 /* References here and elsewhere to "number of args according to the
1751 stack frame" appear in all cases to refer to "number of ints of args
1752 according to the stack frame". At least for VAX, i386, isi. */
1755 print_frame_args (func, fi, num, stream)
1756 struct symbol *func;
1757 struct frame_info *fi;
1761 struct block *b = NULL;
1765 register struct symbol *sym;
1766 register value_ptr val;
1767 /* Offset of next stack argument beyond the one we have seen that is
1768 at the highest offset.
1769 -1 if we haven't come to a stack argument yet. */
1770 long highest_offset = -1;
1772 /* Number of ints of arguments that we have printed so far. */
1773 int args_printed = 0;
1777 b = SYMBOL_BLOCK_VALUE (func);
1778 nsyms = BLOCK_NSYMS (b);
1781 for (i = 0; i < nsyms; i++)
1784 sym = BLOCK_SYM (b, i);
1786 /* Keep track of the highest stack argument offset seen, and
1787 skip over any kinds of symbols we don't care about. */
1789 switch (SYMBOL_CLASS (sym)) {
1793 long current_offset = SYMBOL_VALUE (sym);
1794 arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1796 /* Compute address of next argument by adding the size of
1797 this argument and rounding to an int boundary. */
1799 = ((current_offset + arg_size + sizeof (int) - 1)
1800 & ~(sizeof (int) - 1));
1802 /* If this is the highest offset seen yet, set highest_offset. */
1803 if (highest_offset == -1
1804 || (current_offset > highest_offset))
1805 highest_offset = current_offset;
1807 /* Add the number of ints we're about to print to args_printed. */
1808 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
1811 /* We care about types of symbols, but don't need to keep track of
1812 stack offsets in them. */
1814 case LOC_REGPARM_ADDR:
1816 case LOC_BASEREG_ARG:
1819 /* Other types of symbols we just skip over. */
1824 /* We have to look up the symbol because arguments can have
1825 two entries (one a parameter, one a local) and the one we
1826 want is the local, which lookup_symbol will find for us.
1827 This includes gcc1 (not gcc2) on the sparc when passing a
1828 small structure and gcc2 when the argument type is float
1829 and it is passed as a double and converted to float by
1830 the prologue (in the latter case the type of the LOC_ARG
1831 symbol is double and the type of the LOC_LOCAL symbol is
1833 /* But if the parameter name is null, don't try it.
1834 Null parameter names occur on the RS/6000, for traceback tables.
1835 FIXME, should we even print them? */
1837 if (*SYMBOL_NAME (sym))
1839 struct symbol *nsym;
1840 nsym = lookup_symbol
1842 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
1843 if (SYMBOL_CLASS (nsym) == LOC_REGISTER)
1845 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
1846 it was passed on the stack and loaded into a register,
1847 or passed in a register and stored in a stack slot.
1848 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
1850 Reasons for using the LOC_ARG:
1851 (1) because find_saved_registers may be slow for remote
1853 (2) because registers are often re-used and stack slots
1854 rarely (never?) are. Therefore using the stack slot is
1855 much less likely to print garbage.
1857 Reasons why we might want to use the LOC_REGISTER:
1858 (1) So that the backtrace prints the same value as
1859 "print foo". I see no compelling reason why this needs
1860 to be the case; having the backtrace print the value which
1861 was passed in, and "print foo" print the value as modified
1862 within the called function, makes perfect sense to me.
1864 Additional note: It might be nice if "info args" displayed
1866 One more note: There is a case with sparc structure passing
1867 where we need to use the LOC_REGISTER, but this is dealt with
1868 by creating a single LOC_REGPARM in symbol reading. */
1870 /* Leave sym (the LOC_ARG) alone. */
1877 /* Print the current arg. */
1879 fprintf_filtered (stream, ", ");
1882 annotate_arg_begin ();
1884 fprintf_symbol_filtered (stream, SYMBOL_SOURCE_NAME (sym),
1885 SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
1886 annotate_arg_name_end ();
1887 fputs_filtered ("=", stream);
1889 /* Avoid value_print because it will deref ref parameters. We just
1890 want to print their addresses. Print ??? for args whose address
1891 we do not know. We pass 2 as "recurse" to val_print because our
1892 standard indentation here is 4 spaces, and val_print indents
1893 2 for each recurse. */
1894 val = read_var_value (sym, fi);
1896 annotate_arg_value (val == NULL ? NULL : VALUE_TYPE (val));
1900 #ifdef GDB_TARGET_IS_D10V
1901 if (SYMBOL_CLASS(sym) == LOC_REGPARM && TYPE_CODE(VALUE_TYPE(val)) == TYPE_CODE_PTR)
1902 TYPE_LENGTH(VALUE_TYPE(val)) = 2;
1904 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
1905 VALUE_ADDRESS (val),
1906 stream, 0, 0, 2, Val_no_prettyprint);
1909 fputs_filtered ("???", stream);
1911 annotate_arg_end ();
1916 /* Don't print nameless args in situations where we don't know
1917 enough about the stack to find them. */
1922 if (highest_offset == -1)
1923 start = FRAME_ARGS_SKIP;
1925 start = highest_offset;
1927 print_frame_nameless_args (fi, start, num - args_printed,
1932 /* Print nameless args on STREAM.
1933 FI is the frameinfo for this frame, START is the offset
1934 of the first nameless arg, and NUM is the number of nameless args to
1935 print. FIRST is nonzero if this is the first argument (not just
1936 the first nameless arg). */
1939 print_frame_nameless_args (fi, start, num, first, stream)
1940 struct frame_info *fi;
1950 for (i = 0; i < num; i++)
1953 #ifdef NAMELESS_ARG_VALUE
1954 NAMELESS_ARG_VALUE (fi, start, &arg_value);
1956 argsaddr = FRAME_ARGS_ADDRESS (fi);
1960 arg_value = read_memory_integer (argsaddr + start, sizeof (int));
1964 fprintf_filtered (stream, ", ");
1966 #ifdef PRINT_NAMELESS_INTEGER
1967 PRINT_NAMELESS_INTEGER (stream, arg_value);
1969 #ifdef PRINT_TYPELESS_INTEGER
1970 PRINT_TYPELESS_INTEGER (stream, builtin_type_int, (LONGEST) arg_value);
1972 fprintf_filtered (stream, "%ld", arg_value);
1973 #endif /* PRINT_TYPELESS_INTEGER */
1974 #endif /* PRINT_NAMELESS_INTEGER */
1976 start += sizeof (int);
1982 printf_command (arg, from_tty)
1986 register char *f = NULL;
1987 register char *s = arg;
1988 char *string = NULL;
1989 value_ptr *val_args;
1991 char *current_substring;
1993 int allocated_args = 20;
1994 struct cleanup *old_cleanups;
1996 val_args = (value_ptr *) xmalloc (allocated_args * sizeof (value_ptr));
1997 old_cleanups = make_cleanup ((make_cleanup_func) free_current_contents,
2001 error_no_arg ("format-control string and values to print");
2003 /* Skip white space before format string */
2004 while (*s == ' ' || *s == '\t') s++;
2006 /* A format string should follow, enveloped in double quotes */
2008 error ("Bad format string, missing '\"'.");
2010 /* Parse the format-control string and copy it into the string STRING,
2011 processing some kinds of escape sequence. */
2013 f = string = (char *) alloca (strlen (s) + 1);
2021 error ("Bad format string, non-terminated '\"'.");
2033 *f++ = '\007'; /* Bell */
2058 /* ??? TODO: handle other escape sequences */
2059 error ("Unrecognized escape character \\%c in format string.",
2069 /* Skip over " and following space and comma. */
2072 while (*s == ' ' || *s == '\t') s++;
2074 if (*s != ',' && *s != 0)
2075 error ("Invalid argument syntax");
2078 while (*s == ' ' || *s == '\t') s++;
2080 /* Need extra space for the '\0's. Doubling the size is sufficient. */
2081 substrings = alloca (strlen (string) * 2);
2082 current_substring = substrings;
2085 /* Now scan the string for %-specs and see what kinds of args they want.
2086 argclass[I] classifies the %-specs so we can give printf_filtered
2087 something of the right size. */
2089 enum argclass {no_arg, int_arg, string_arg, double_arg, long_long_arg};
2090 enum argclass *argclass;
2091 enum argclass this_argclass;
2097 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
2105 while (strchr ("0123456789.hlL-+ #", *f))
2107 if (*f == 'l' || *f == 'L')
2114 this_argclass = string_arg;
2120 this_argclass = double_arg;
2124 error ("`*' not supported for precision or width in printf");
2127 error ("Format specifier `n' not supported in printf");
2130 this_argclass = no_arg;
2135 this_argclass = long_long_arg;
2137 this_argclass = int_arg;
2141 if (this_argclass != no_arg)
2143 strncpy (current_substring, last_arg, f - last_arg);
2144 current_substring += f - last_arg;
2145 *current_substring++ = '\0';
2147 argclass[nargs_wanted++] = this_argclass;
2151 /* Now, parse all arguments and evaluate them.
2152 Store the VALUEs in VAL_ARGS. */
2157 if (nargs == allocated_args)
2158 val_args = (value_ptr *) xrealloc ((char *) val_args,
2159 (allocated_args *= 2)
2160 * sizeof (value_ptr));
2162 val_args[nargs] = parse_to_comma_and_eval (&s1);
2164 /* If format string wants a float, unchecked-convert the value to
2165 floating point of the same size */
2167 if (argclass[nargs] == double_arg)
2169 struct type *type = VALUE_TYPE (val_args[nargs]);
2170 if (TYPE_LENGTH (type) == sizeof (float))
2171 VALUE_TYPE (val_args[nargs]) = builtin_type_float;
2172 if (TYPE_LENGTH (type) == sizeof (double))
2173 VALUE_TYPE (val_args[nargs]) = builtin_type_double;
2181 if (nargs != nargs_wanted)
2182 error ("Wrong number of arguments for specified format-string");
2184 /* Now actually print them. */
2185 current_substring = substrings;
2186 for (i = 0; i < nargs; i++)
2188 switch (argclass[i])
2195 tem = value_as_pointer (val_args[i]);
2197 /* This is a %s argument. Find the length of the string. */
2202 read_memory_section (tem + j, &c, 1,
2203 VALUE_BFD_SECTION (val_args[i]));
2208 /* Copy the string contents into a string inside GDB. */
2209 str = (char *) alloca (j + 1);
2210 read_memory_section (tem, str, j, VALUE_BFD_SECTION (val_args[i]));
2213 printf_filtered (current_substring, str);
2218 double val = value_as_double (val_args[i]);
2219 printf_filtered (current_substring, val);
2223 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2225 long long val = value_as_long (val_args[i]);
2226 printf_filtered (current_substring, val);
2230 error ("long long not supported in printf");
2234 /* FIXME: there should be separate int_arg and long_arg. */
2235 long val = value_as_long (val_args[i]);
2236 printf_filtered (current_substring, val);
2239 default: /* purecov: deadcode */
2240 error ("internal error in printf_command"); /* purecov: deadcode */
2242 /* Skip to the next substring. */
2243 current_substring += strlen (current_substring) + 1;
2245 /* Print the portion of the format string after the last argument. */
2246 printf_filtered (last_arg);
2248 do_cleanups (old_cleanups);
2251 /* Dump a specified section of assembly code. With no command line
2252 arguments, this command will dump the assembly code for the
2253 function surrounding the pc value in the selected frame. With one
2254 argument, it will dump the assembly code surrounding that pc value.
2255 Two arguments are interpeted as bounds within which to dump
2260 disassemble_command (arg, from_tty)
2264 CORE_ADDR low, high;
2266 CORE_ADDR pc, pc_masked;
2275 if (!selected_frame)
2276 error ("No frame selected.\n");
2278 pc = get_frame_pc (selected_frame);
2279 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
2280 error ("No function contains program counter for selected frame.\n");
2282 else if (tui_version)
2283 low = (CORE_ADDR)tuiDo((TuiOpaqueFuncPtr)tui_vGetLowDisassemblyAddress,
2287 low += FUNCTION_START_OFFSET;
2289 else if (!(space_index = (char *) strchr (arg, ' ')))
2292 pc = parse_and_eval_address (arg);
2293 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
2294 error ("No function contains specified address.\n");
2296 else if (tui_version)
2297 low = (CORE_ADDR)tuiDo((TuiOpaqueFuncPtr)tui_vGetLowDisassemblyAddress,
2302 if (overlay_debugging)
2304 section = find_pc_overlay (pc);
2305 if (pc_in_unmapped_range (pc, section))
2307 /* find_pc_partial_function will have returned low and high
2308 relative to the symbolic (mapped) address range. Need to
2309 translate them back to the unmapped range where PC is. */
2310 low = overlay_unmapped_address (low, section);
2311 high = overlay_unmapped_address (high, section);
2315 low += FUNCTION_START_OFFSET;
2319 /* Two arguments. */
2320 *space_index = '\0';
2321 low = parse_and_eval_address (arg);
2322 high = parse_and_eval_address (space_index + 1);
2327 m_winPtrIsNull(disassemWin) || !disassemWin->generic.isVisible)
2330 printf_filtered ("Dump of assembler code ");
2333 printf_filtered ("for function %s:\n", name);
2337 printf_filtered ("from ");
2338 print_address_numeric (low, 1, gdb_stdout);
2339 printf_filtered (" to ");
2340 print_address_numeric (high, 1, gdb_stdout);
2341 printf_filtered (":\n");
2344 /* Dump the specified range. */
2347 #ifdef GDB_TARGET_MASK_DISAS_PC
2348 pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
2353 while (pc_masked < high)
2356 print_address (pc_masked, gdb_stdout);
2357 printf_filtered (":\t");
2358 /* We often wrap here if there are long symbolic names. */
2360 pc += print_insn (pc, gdb_stdout);
2361 printf_filtered ("\n");
2363 #ifdef GDB_TARGET_MASK_DISAS_PC
2364 pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
2369 printf_filtered ("End of assembler dump.\n");
2370 gdb_flush (gdb_stdout);
2375 tuiDo((TuiOpaqueFuncPtr)tui_vAddWinToLayout, DISASSEM_WIN);
2376 tuiDo((TuiOpaqueFuncPtr)tui_vUpdateSourceWindowsWithAddr, low);
2381 /* Print the instruction at address MEMADDR in debugged memory,
2382 on STREAM. Returns length of the instruction, in bytes. */
2385 print_insn (memaddr, stream)
2389 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2390 TARGET_PRINT_INSN_INFO->endian = BFD_ENDIAN_BIG;
2392 TARGET_PRINT_INSN_INFO->endian = BFD_ENDIAN_LITTLE;
2394 if (TARGET_ARCHITECTURE != NULL)
2395 TARGET_PRINT_INSN_INFO->mach = TARGET_ARCHITECTURE->mach;
2396 /* else: should set .mach=0 but some disassemblers don't grok this */
2398 return TARGET_PRINT_INSN (memaddr, TARGET_PRINT_INSN_INFO);
2403 _initialize_printcmd ()
2405 current_display_number = -1;
2407 add_info ("address", address_info,
2408 "Describe where symbol SYM is stored.");
2410 add_info ("symbol", sym_info,
2411 "Describe what symbol is at location ADDR.\n\
2412 Only for symbols with fixed locations (global or static scope).");
2414 add_com ("x", class_vars, x_command,
2415 concat ("Examine memory: x/FMT ADDRESS.\n\
2416 ADDRESS is an expression for the memory address to examine.\n\
2417 FMT is a repeat count followed by a format letter and a size letter.\n\
2418 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2419 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n",
2420 "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2421 The specified number of objects of the specified size are printed\n\
2422 according to the format.\n\n\
2423 Defaults for format and size letters are those previously used.\n\
2424 Default count is 1. Default address is following last thing printed\n\
2425 with this command or \"print\".", NULL));
2427 add_com ("disassemble", class_vars, disassemble_command,
2428 "Disassemble a specified section of memory.\n\
2429 Default is the function surrounding the pc of the selected frame.\n\
2430 With a single argument, the function surrounding that address is dumped.\n\
2431 Two arguments are taken as a range of memory to dump.");
2433 add_com_alias ("va", "disassemble", class_xdb, 0);
2436 add_com ("whereis", class_vars, whereis_command,
2437 "Print line number and file of definition of variable.");
2440 add_info ("display", display_info,
2441 "Expressions to display when program stops, with code numbers.");
2443 add_cmd ("undisplay", class_vars, undisplay_command,
2444 "Cancel some expressions to be displayed when program stops.\n\
2445 Arguments are the code numbers of the expressions to stop displaying.\n\
2446 No argument means cancel all automatic-display expressions.\n\
2447 \"delete display\" has the same effect as this command.\n\
2448 Do \"info display\" to see current list of code numbers.",
2451 add_com ("display", class_vars, display_command,
2452 "Print value of expression EXP each time the program stops.\n\
2453 /FMT may be used before EXP as in the \"print\" command.\n\
2454 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2455 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2456 and examining is done as in the \"x\" command.\n\n\
2457 With no argument, display all currently requested auto-display expressions.\n\
2458 Use \"undisplay\" to cancel display requests previously made."
2461 add_cmd ("display", class_vars, enable_display,
2462 "Enable some expressions to be displayed when program stops.\n\
2463 Arguments are the code numbers of the expressions to resume displaying.\n\
2464 No argument means enable all automatic-display expressions.\n\
2465 Do \"info display\" to see current list of code numbers.", &enablelist);
2467 add_cmd ("display", class_vars, disable_display_command,
2468 "Disable some expressions to be displayed when program stops.\n\
2469 Arguments are the code numbers of the expressions to stop displaying.\n\
2470 No argument means disable all automatic-display expressions.\n\
2471 Do \"info display\" to see current list of code numbers.", &disablelist);
2473 add_cmd ("display", class_vars, undisplay_command,
2474 "Cancel some expressions to be displayed when program stops.\n\
2475 Arguments are the code numbers of the expressions to stop displaying.\n\
2476 No argument means cancel all automatic-display expressions.\n\
2477 Do \"info display\" to see current list of code numbers.", &deletelist);
2479 add_com ("printf", class_vars, printf_command,
2480 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2481 This is useful for formatted output in user-defined commands.");
2483 add_com ("output", class_vars, output_command,
2484 "Like \"print\" but don't put in value history and don't print newline.\n\
2485 This is useful in user-defined commands.");
2487 add_prefix_cmd ("set", class_vars, set_command,
2488 concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2489 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2490 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2491 with $), a register (a few standard names starting with $), or an actual\n\
2492 variable in the program being debugged. EXP is any valid expression.\n",
2493 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2494 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2495 You can see these environment settings with the \"show\" command.", NULL),
2496 &setlist, "set ", 1, &cmdlist);
2498 add_com("assign", class_vars, set_command, concat ("Evaluate expression \
2499 EXP and assign result to variable VAR, using assignment\n\
2500 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2501 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2502 with $), a register (a few standard names starting with $), or an actual\n\
2503 variable in the program being debugged. EXP is any valid expression.\n",
2504 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2505 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2506 You can see these environment settings with the \"show\" command.", NULL));
2508 /* "call" is the same as "set", but handy for dbx users to call fns. */
2509 add_com ("call", class_vars, call_command,
2510 "Call a function in the program.\n\
2511 The argument is the function name and arguments, in the notation of the\n\
2512 current working language. The result is printed and saved in the value\n\
2513 history, if it is not void.");
2515 add_cmd ("variable", class_vars, set_command,
2516 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2517 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2518 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2519 with $), a register (a few standard names starting with $), or an actual\n\
2520 variable in the program being debugged. EXP is any valid expression.\n\
2521 This may usually be abbreviated to simply \"set\".",
2524 add_com ("print", class_vars, print_command,
2525 concat ("Print value of expression EXP.\n\
2526 Variables accessible are those of the lexical environment of the selected\n\
2527 stack frame, plus all those whose scope is global or an entire file.\n\
2529 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2530 $$NUM refers to NUM'th value back from the last one.\n\
2531 Names starting with $ refer to registers (with the values they would have\n",
2532 "if the program were to return to the stack frame now selected, restoring\n\
2533 all registers saved by frames farther in) or else to debugger\n\
2534 \"convenience\" variables (any such name not a known register).\n\
2535 Use assignment expressions to give values to convenience variables.\n",
2537 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2538 @ is a binary operator for treating consecutive data objects\n\
2539 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2540 element is FOO, whose second element is stored in the space following\n\
2541 where FOO is stored, etc. FOO must be an expression whose value\n\
2542 resides in memory.\n",
2544 EXP may be preceded with /FMT, where FMT is a format letter\n\
2545 but no count or size letter (see \"x\" command).", NULL));
2546 add_com_alias ("p", "print", class_vars, 1);
2548 add_com ("inspect", class_vars, inspect_command,
2549 "Same as \"print\" command, except that if you are running in the epoch\n\
2550 environment, the value is printed in its own window.");
2553 add_set_cmd ("max-symbolic-offset", no_class, var_uinteger,
2554 (char *)&max_symbolic_offset,
2555 "Set the largest offset that will be printed in <symbol+1234> form.",
2559 add_set_cmd ("symbol-filename", no_class, var_boolean,
2560 (char *)&print_symbol_filename,
2561 "Set printing of source filename and line number with <symbol>.",
2565 /* For examine/instruction a single byte quantity is specified as
2566 the data. This avoids problems with value_at_lazy() requiring a
2567 valid data type (and rejecting VOID). */
2568 examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
2570 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2571 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2572 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2573 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);