1 /* Print values for GNU debugger GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1993, 1994, 1995,
4 1998, 2000 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
30 #include "expression.h"
34 #include "breakpoint.h"
38 #include "symfile.h" /* for overlay functions */
39 #include "objfiles.h" /* ditto */
44 extern int asm_demangle; /* Whether to demangle syms in asm printouts */
45 extern int addressprint; /* Whether to print hex addresses in HLL " */
54 /* Last specified output format. */
56 static char last_format = 'x';
58 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
60 static char last_size = 'w';
62 /* Default address to examine next. */
64 static CORE_ADDR next_address;
66 /* Default section to examine next. */
68 static asection *next_section;
70 /* Last address examined. */
72 static CORE_ADDR last_examine_address;
74 /* Contents of last address examined.
75 This is not valid past the end of the `x' command! */
77 static value_ptr last_examine_value;
79 /* Largest offset between a symbolic value and an address, that will be
80 printed as `0x1234 <symbol+offset>'. */
82 static unsigned int max_symbolic_offset = UINT_MAX;
84 /* Append the source filename and linenumber of the symbol when
85 printing a symbolic value as `<symbol at filename:linenum>' if set. */
86 static int print_symbol_filename = 0;
88 /* Number of auto-display expression currently being displayed.
89 So that we can disable it if we get an error or a signal within it.
90 -1 when not doing one. */
92 int current_display_number;
94 /* Flag to low-level print routines that this value is being printed
95 in an epoch window. We'd like to pass this as a parameter, but
96 every routine would need to take it. Perhaps we can encapsulate
97 this in the I/O stream once we have GNU stdio. */
103 /* Chain link to next auto-display item. */
104 struct display *next;
105 /* Expression to be evaluated and displayed. */
106 struct expression *exp;
107 /* Item number of this auto-display item. */
109 /* Display format specified. */
110 struct format_data format;
111 /* Innermost block required by this expression when evaluated */
113 /* Status of this display (enabled or disabled) */
117 /* Chain of expressions whose values should be displayed
118 automatically each time the program stops. */
120 static struct display *display_chain;
122 static int display_number;
124 /* Prototypes for exported functions. */
126 void output_command (char *, int);
128 void _initialize_printcmd (void);
130 /* Prototypes for local functions. */
132 static void delete_display (int);
134 static void enable_display (char *, int);
136 static void disable_display_command (char *, int);
138 static void disassemble_command (char *, int);
140 static void printf_command (char *, int);
142 static void print_frame_nameless_args (struct frame_info *, long,
143 int, int, struct ui_file *);
145 static void display_info (char *, int);
147 static void do_one_display (struct display *);
149 static void undisplay_command (char *, int);
151 static void free_display (struct display *);
153 static void display_command (char *, int);
155 void x_command (char *, int);
157 static void address_info (char *, int);
159 static void set_command (char *, int);
161 static void call_command (char *, int);
163 static void inspect_command (char *, int);
165 static void print_command (char *, int);
167 static void print_command_1 (char *, int, int);
169 static void validate_format (struct format_data, char *);
171 static void do_examine (struct format_data, CORE_ADDR addr,
174 static void print_formatted (value_ptr, int, int, struct ui_file *);
176 static struct format_data decode_format (char **, int, int);
178 static int print_insn (CORE_ADDR, struct ui_file *);
180 static void sym_info (char *, int);
183 /* Decode a format specification. *STRING_PTR should point to it.
184 OFORMAT and OSIZE are used as defaults for the format and size
185 if none are given in the format specification.
186 If OSIZE is zero, then the size field of the returned value
187 should be set only if a size is explicitly specified by the
189 The structure returned describes all the data
190 found in the specification. In addition, *STRING_PTR is advanced
191 past the specification and past all whitespace following it. */
193 static struct format_data
194 decode_format (string_ptr, oformat, osize)
199 struct format_data val;
200 register char *p = *string_ptr;
206 if (*p >= '0' && *p <= '9')
207 val.count = atoi (p);
208 while (*p >= '0' && *p <= '9')
211 /* Now process size or format letters that follow. */
215 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
217 else if (*p >= 'a' && *p <= 'z')
223 while (*p == ' ' || *p == '\t')
227 /* Set defaults for format and size if not specified. */
228 if (val.format == '?')
232 /* Neither has been specified. */
233 val.format = oformat;
237 /* If a size is specified, any format makes a reasonable
238 default except 'i'. */
239 val.format = oformat == 'i' ? 'x' : oformat;
241 else if (val.size == '?')
246 /* Pick the appropriate size for an address. */
247 if (TARGET_PTR_BIT == 64)
248 val.size = osize ? 'g' : osize;
249 else if (TARGET_PTR_BIT == 32)
250 val.size = osize ? 'w' : osize;
251 else if (TARGET_PTR_BIT == 16)
252 val.size = osize ? 'h' : osize;
254 /* Bad value for TARGET_PTR_BIT */
258 /* Floating point has to be word or giantword. */
259 if (osize == 'w' || osize == 'g')
262 /* Default it to giantword if the last used size is not
264 val.size = osize ? 'g' : osize;
267 /* Characters default to one byte. */
268 val.size = osize ? 'b' : osize;
271 /* The default is the size most recently specified. */
278 /* Print value VAL on stream according to FORMAT, a letter or 0.
279 Do not end with a newline.
280 0 means print VAL according to its own type.
281 SIZE is the letter for the size of datum being printed.
282 This is used to pad hex numbers so they line up. */
285 print_formatted (val, format, size, stream)
286 register value_ptr val;
289 struct ui_file *stream;
291 struct type *type = check_typedef (VALUE_TYPE (val));
292 int len = TYPE_LENGTH (type);
294 if (VALUE_LVAL (val) == lval_memory)
296 next_address = VALUE_ADDRESS (val) + len;
297 next_section = VALUE_BFD_SECTION (val);
303 /* FIXME: Need to handle wchar_t's here... */
304 next_address = VALUE_ADDRESS (val)
305 + val_print_string (VALUE_ADDRESS (val), -1, 1, stream);
306 next_section = VALUE_BFD_SECTION (val);
310 /* The old comment says
311 "Force output out, print_insn not using _filtered".
312 I'm not completely sure what that means, I suspect most print_insn
313 now do use _filtered, so I guess it's obsolete.
314 --Yes, it does filter now, and so this is obsolete. -JB */
316 /* We often wrap here if there are long symbolic names. */
318 next_address = VALUE_ADDRESS (val)
319 + print_insn (VALUE_ADDRESS (val), stream);
320 next_section = VALUE_BFD_SECTION (val);
325 || TYPE_CODE (type) == TYPE_CODE_ARRAY
326 || TYPE_CODE (type) == TYPE_CODE_STRING
327 || TYPE_CODE (type) == TYPE_CODE_STRUCT
328 || TYPE_CODE (type) == TYPE_CODE_UNION)
329 /* If format is 0, use the 'natural' format for
330 * that type of value. If the type is non-scalar,
331 * we have to use language rules to print it as
332 * a series of scalars.
334 value_print (val, stream, format, Val_pretty_default);
336 /* User specified format, so don't look to the
337 * the type to tell us what to do.
339 print_scalar_formatted (VALUE_CONTENTS (val), type,
340 format, size, stream);
344 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
345 according to letters FORMAT and SIZE on STREAM.
346 FORMAT may not be zero. Formats s and i are not supported at this level.
348 This is how the elements of an array or structure are printed
352 print_scalar_formatted (valaddr, type, format, size, stream)
357 struct ui_file *stream;
360 unsigned int len = TYPE_LENGTH (type);
362 if (len > sizeof (LONGEST)
370 if (!TYPE_UNSIGNED (type)
371 || !extract_long_unsigned_integer (valaddr, len, &val_long))
373 /* We can't print it normally, but we can print it in hex.
374 Printing it in the wrong radix is more useful than saying
375 "use /x, you dummy". */
376 /* FIXME: we could also do octal or binary if that was the
378 /* FIXME: we should be using the size field to give us a
379 minimum field width to print. */
382 print_octal_chars (stream, valaddr, len);
383 else if (format == 'd')
384 print_decimal_chars (stream, valaddr, len);
385 else if (format == 't')
386 print_binary_chars (stream, valaddr, len);
388 /* replace with call to print_hex_chars? Looks
389 like val_print_type_code_int is redoing
392 val_print_type_code_int (type, valaddr, stream);
397 /* If we get here, extract_long_unsigned_integer set val_long. */
399 else if (format != 'f')
400 val_long = unpack_long (type, valaddr);
402 /* If we are printing it as unsigned, truncate it in case it is actually
403 a negative signed value (e.g. "print/u (short)-1" should print 65535
404 (if shorts are 16 bits) instead of 4294967295). */
407 if (len < sizeof (LONGEST))
408 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
416 /* no size specified, like in print. Print varying # of digits. */
417 print_longest (stream, 'x', 1, val_long);
426 print_longest (stream, size, 1, val_long);
429 error ("Undefined output size \"%c\".", size);
434 print_longest (stream, 'd', 1, val_long);
438 print_longest (stream, 'u', 0, val_long);
443 print_longest (stream, 'o', 1, val_long);
445 fprintf_filtered (stream, "0");
450 CORE_ADDR addr = unpack_pointer (type, valaddr);
451 print_address (addr, stream);
456 value_print (value_from_longest (builtin_type_true_char, val_long),
457 stream, 0, Val_pretty_default);
461 if (len == sizeof (float))
462 type = builtin_type_float;
463 else if (len == sizeof (double))
464 type = builtin_type_double;
465 print_floating (valaddr, type, stream);
472 /* Binary; 't' stands for "two". */
474 char bits[8 * (sizeof val_long) + 1];
475 char buf[8 * (sizeof val_long) + 32];
480 width = 8 * (sizeof val_long);
497 error ("Undefined output size \"%c\".", size);
503 bits[width] = (val_long & 1) ? '1' : '0';
508 while (*cp && *cp == '0')
513 strcpy (buf, local_binary_format_prefix ());
515 strcat (buf, local_binary_format_suffix ());
516 fprintf_filtered (stream, buf);
521 error ("Undefined output format \"%c\".", format);
525 /* Specify default address for `x' command.
526 `info lines' uses this. */
529 set_next_address (addr)
534 /* Make address available to the user as $_. */
535 set_internalvar (lookup_internalvar ("_"),
536 value_from_pointer (lookup_pointer_type (builtin_type_void),
540 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
541 after LEADIN. Print nothing if no symbolic name is found nearby.
542 Optionally also print source file and line number, if available.
543 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
544 or to interpret it as a possible C++ name and convert it back to source
545 form. However note that DO_DEMANGLE can be overridden by the specific
546 settings of the demangle and asm_demangle variables. */
549 print_address_symbolic (addr, stream, do_demangle, leadin)
551 struct ui_file *stream;
556 char *filename = NULL;
561 /* throw away both name and filename */
562 struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
563 make_cleanup (free_current_contents, &filename);
565 if (build_address_symbolic (addr, do_demangle, &name, &offset, &filename, &line, &unmapped))
567 do_cleanups (cleanup_chain);
571 fputs_filtered (leadin, stream);
573 fputs_filtered ("<*", stream);
575 fputs_filtered ("<", stream);
576 fputs_filtered (name, stream);
578 fprintf_filtered (stream, "+%u", (unsigned int) offset);
580 /* Append source filename and line number if desired. Give specific
581 line # of this addr, if we have it; else line # of the nearest symbol. */
582 if (print_symbol_filename && filename != NULL)
585 fprintf_filtered (stream, " at %s:%d", filename, line);
587 fprintf_filtered (stream, " in %s", filename);
590 fputs_filtered ("*>", stream);
592 fputs_filtered (">", stream);
594 do_cleanups (cleanup_chain);
597 /* Given an address ADDR return all the elements needed to print the
598 address in a symbolic form. NAME can be mangled or not depending
599 on DO_DEMANGLE (and also on the asm_demangle global variable,
600 manipulated via ''set print asm-demangle''). Return 0 in case of
601 success, when all the info in the OUT paramters is valid. Return 1
604 build_address_symbolic (CORE_ADDR addr, /* IN */
605 int do_demangle, /* IN */
606 char **name, /* OUT */
607 int *offset, /* OUT */
608 char **filename, /* OUT */
610 int *unmapped) /* OUT */
612 struct minimal_symbol *msymbol;
613 struct symbol *symbol;
614 struct symtab *symtab = 0;
615 CORE_ADDR name_location = 0;
616 asection *section = 0;
617 char *name_temp = "";
619 /* Let's say it is unmapped. */
622 /* Determine if the address is in an overlay, and whether it is
624 if (overlay_debugging)
626 section = find_pc_overlay (addr);
627 if (pc_in_unmapped_range (addr, section))
630 addr = overlay_mapped_address (addr, section);
634 /* On some targets, add in extra "flag" bits to PC for
635 disassembly. This should ensure that "rounding errors" in
636 symbol addresses that are masked for disassembly favour the
637 the correct symbol. */
639 #ifdef GDB_TARGET_UNMASK_DISAS_PC
640 addr = GDB_TARGET_UNMASK_DISAS_PC (addr);
643 /* First try to find the address in the symbol table, then
644 in the minsyms. Take the closest one. */
646 /* This is defective in the sense that it only finds text symbols. So
647 really this is kind of pointless--we should make sure that the
648 minimal symbols have everything we need (by changing that we could
649 save some memory, but for many debug format--ELF/DWARF or
650 anything/stabs--it would be inconvenient to eliminate those minimal
652 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
653 symbol = find_pc_sect_function (addr, section);
657 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
659 name_temp = SYMBOL_SOURCE_NAME (symbol);
661 name_temp = SYMBOL_LINKAGE_NAME (symbol);
666 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
668 /* The msymbol is closer to the address than the symbol;
669 use the msymbol instead. */
672 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
674 name_temp = SYMBOL_SOURCE_NAME (msymbol);
676 name_temp = SYMBOL_LINKAGE_NAME (msymbol);
679 if (symbol == NULL && msymbol == NULL)
682 /* On some targets, mask out extra "flag" bits from PC for handsome
685 #ifdef GDB_TARGET_MASK_DISAS_PC
686 name_location = GDB_TARGET_MASK_DISAS_PC (name_location);
687 addr = GDB_TARGET_MASK_DISAS_PC (addr);
690 /* If the nearest symbol is too far away, don't print anything symbolic. */
692 /* For when CORE_ADDR is larger than unsigned int, we do math in
693 CORE_ADDR. But when we detect unsigned wraparound in the
694 CORE_ADDR math, we ignore this test and print the offset,
695 because addr+max_symbolic_offset has wrapped through the end
696 of the address space back to the beginning, giving bogus comparison. */
697 if (addr > name_location + max_symbolic_offset
698 && name_location + max_symbolic_offset > name_location)
701 *offset = addr - name_location;
703 *name = xstrdup (name_temp);
705 if (print_symbol_filename)
707 struct symtab_and_line sal;
709 sal = find_pc_sect_line (addr, section, 0);
713 *filename = xstrdup (sal.symtab->filename);
716 else if (symtab && symbol && symbol->line)
718 *filename = xstrdup (symtab->filename);
719 *line = symbol->line;
723 *filename = xstrdup (symtab->filename);
730 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
733 print_address_numeric (addr, use_local, stream)
736 struct ui_file *stream;
738 /* Truncate address to the size of a target pointer, avoiding shifts
739 larger or equal than the width of a CORE_ADDR. The local
740 variable PTR_BIT stops the compiler reporting a shift overflow
741 when it won't occure. */
742 /* NOTE: This assumes that the significant address information is
743 kept in the least significant bits of ADDR - the upper bits were
744 either zero or sign extended. Should ADDRESS_TO_POINTER() or
745 some ADDRESS_TO_PRINTABLE() be used to do the conversion? */
746 int ptr_bit = TARGET_PTR_BIT;
747 if (ptr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
748 addr &= ((CORE_ADDR) 1 << ptr_bit) - 1;
749 print_longest (stream, 'x', use_local, (ULONGEST) addr);
752 /* Print address ADDR symbolically on STREAM.
753 First print it as a number. Then perhaps print
754 <SYMBOL + OFFSET> after the number. */
757 print_address (addr, stream)
759 struct ui_file *stream;
761 print_address_numeric (addr, 1, stream);
762 print_address_symbolic (addr, stream, asm_demangle, " ");
765 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
766 controls whether to print the symbolic name "raw" or demangled.
767 Global setting "addressprint" controls whether to print hex address
771 print_address_demangle (addr, stream, do_demangle)
773 struct ui_file *stream;
778 fprintf_filtered (stream, "0");
780 else if (addressprint)
782 print_address_numeric (addr, 1, stream);
783 print_address_symbolic (addr, stream, do_demangle, " ");
787 print_address_symbolic (addr, stream, do_demangle, "");
792 /* These are the types that $__ will get after an examine command of one
795 static struct type *examine_i_type;
797 static struct type *examine_b_type;
798 static struct type *examine_h_type;
799 static struct type *examine_w_type;
800 static struct type *examine_g_type;
802 /* Examine data at address ADDR in format FMT.
803 Fetch it from memory and print on gdb_stdout. */
806 do_examine (fmt, addr, sect)
807 struct format_data fmt;
811 register char format = 0;
813 register int count = 1;
814 struct type *val_type = NULL;
816 register int maxelts;
824 /* String or instruction format implies fetch single bytes
825 regardless of the specified size. */
826 if (format == 's' || format == 'i')
830 val_type = examine_i_type;
831 else if (size == 'b')
832 val_type = examine_b_type;
833 else if (size == 'h')
834 val_type = examine_h_type;
835 else if (size == 'w')
836 val_type = examine_w_type;
837 else if (size == 'g')
838 val_type = examine_g_type;
845 if (format == 's' || format == 'i')
848 /* Print as many objects as specified in COUNT, at most maxelts per line,
849 with the address of the next one at the start of each line. */
854 print_address (next_address, gdb_stdout);
855 printf_filtered (":");
860 printf_filtered ("\t");
861 /* Note that print_formatted sets next_address for the next
863 last_examine_address = next_address;
865 if (last_examine_value)
866 value_free (last_examine_value);
868 /* The value to be displayed is not fetched greedily.
869 Instead, to avoid the posibility of a fetched value not
870 being used, its retreval is delayed until the print code
871 uses it. When examining an instruction stream, the
872 disassembler will perform its own memory fetch using just
873 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
874 the disassembler be modified so that LAST_EXAMINE_VALUE
875 is left with the byte sequence from the last complete
876 instruction fetched from memory? */
877 last_examine_value = value_at_lazy (val_type, next_address, sect);
879 if (last_examine_value)
880 release_value (last_examine_value);
882 print_formatted (last_examine_value, format, size, gdb_stdout);
884 printf_filtered ("\n");
885 gdb_flush (gdb_stdout);
890 validate_format (fmt, cmdname)
891 struct format_data fmt;
895 error ("Size letters are meaningless in \"%s\" command.", cmdname);
897 error ("Item count other than 1 is meaningless in \"%s\" command.",
899 if (fmt.format == 'i' || fmt.format == 's')
900 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
901 fmt.format, cmdname);
904 /* Evaluate string EXP as an expression in the current language and
905 print the resulting value. EXP may contain a format specifier as the
906 first argument ("/x myvar" for example, to print myvar in hex).
910 print_command_1 (exp, inspect, voidprint)
915 struct expression *expr;
916 register struct cleanup *old_chain = 0;
917 register char format = 0;
918 register value_ptr val;
919 struct format_data fmt;
922 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
923 inspect_it = inspect;
925 if (exp && *exp == '/')
928 fmt = decode_format (&exp, last_format, 0);
929 validate_format (fmt, "print");
930 last_format = format = fmt.format;
942 expr = parse_expression (exp);
943 old_chain = make_cleanup (free_current_contents, &expr);
945 val = evaluate_expression (expr);
947 /* C++: figure out what type we actually want to print it as. */
948 type = VALUE_TYPE (val);
951 && (TYPE_CODE (type) == TYPE_CODE_PTR
952 || TYPE_CODE (type) == TYPE_CODE_REF)
953 && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT
954 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION))
958 v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
962 type = VALUE_TYPE (val);
967 val = access_value_history (0);
969 if (voidprint || (val && VALUE_TYPE (val) &&
970 TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
972 int histindex = record_latest_value (val);
975 annotate_value_history_begin (histindex, VALUE_TYPE (val));
977 annotate_value_begin (VALUE_TYPE (val));
980 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
981 else if (histindex >= 0)
982 printf_filtered ("$%d = ", histindex);
985 annotate_value_history_value ();
987 print_formatted (val, format, fmt.size, gdb_stdout);
988 printf_filtered ("\n");
991 annotate_value_history_end ();
993 annotate_value_end ();
996 printf_unfiltered ("\") )\030");
1000 do_cleanups (old_chain);
1001 inspect_it = 0; /* Reset print routines to normal */
1006 print_command (exp, from_tty)
1010 print_command_1 (exp, 0, 1);
1013 /* Same as print, except in epoch, it gets its own window */
1016 inspect_command (exp, from_tty)
1020 extern int epoch_interface;
1022 print_command_1 (exp, epoch_interface, 1);
1025 /* Same as print, except it doesn't print void results. */
1028 call_command (exp, from_tty)
1032 print_command_1 (exp, 0, 0);
1037 output_command (exp, from_tty)
1041 struct expression *expr;
1042 register struct cleanup *old_chain;
1043 register char format = 0;
1044 register value_ptr val;
1045 struct format_data fmt;
1047 if (exp && *exp == '/')
1050 fmt = decode_format (&exp, 0, 0);
1051 validate_format (fmt, "output");
1052 format = fmt.format;
1055 expr = parse_expression (exp);
1056 old_chain = make_cleanup (free_current_contents, &expr);
1058 val = evaluate_expression (expr);
1060 annotate_value_begin (VALUE_TYPE (val));
1062 print_formatted (val, format, fmt.size, gdb_stdout);
1064 annotate_value_end ();
1067 gdb_flush (gdb_stdout);
1069 do_cleanups (old_chain);
1074 set_command (exp, from_tty)
1078 struct expression *expr = parse_expression (exp);
1079 register struct cleanup *old_chain =
1080 make_cleanup (free_current_contents, &expr);
1081 evaluate_expression (expr);
1082 do_cleanups (old_chain);
1087 sym_info (arg, from_tty)
1091 struct minimal_symbol *msymbol;
1092 struct objfile *objfile;
1093 struct obj_section *osect;
1095 CORE_ADDR addr, sect_addr;
1097 unsigned int offset;
1100 error_no_arg ("address");
1102 addr = parse_and_eval_address (arg);
1103 ALL_OBJSECTIONS (objfile, osect)
1105 sect = osect->the_bfd_section;
1106 sect_addr = overlay_mapped_address (addr, sect);
1108 if (osect->addr <= sect_addr && sect_addr < osect->endaddr &&
1109 (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect)))
1112 offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
1114 printf_filtered ("%s + %u in ",
1115 SYMBOL_SOURCE_NAME (msymbol), offset);
1117 printf_filtered ("%s in ",
1118 SYMBOL_SOURCE_NAME (msymbol));
1119 if (pc_in_unmapped_range (addr, sect))
1120 printf_filtered ("load address range of ");
1121 if (section_is_overlay (sect))
1122 printf_filtered ("%s overlay ",
1123 section_is_mapped (sect) ? "mapped" : "unmapped");
1124 printf_filtered ("section %s", sect->name);
1125 printf_filtered ("\n");
1129 printf_filtered ("No symbol matches %s.\n", arg);
1134 address_info (exp, from_tty)
1138 register struct symbol *sym;
1139 register struct minimal_symbol *msymbol;
1141 register long basereg;
1143 CORE_ADDR load_addr;
1144 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
1145 if exp is a field of `this'. */
1148 error ("Argument required.");
1150 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
1151 &is_a_field_of_this, (struct symtab **) NULL);
1154 if (is_a_field_of_this)
1156 printf_filtered ("Symbol \"");
1157 fprintf_symbol_filtered (gdb_stdout, exp,
1158 current_language->la_language, DMGL_ANSI);
1159 printf_filtered ("\" is a field of the local class variable `this'\n");
1163 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1165 if (msymbol != NULL)
1167 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1169 printf_filtered ("Symbol \"");
1170 fprintf_symbol_filtered (gdb_stdout, exp,
1171 current_language->la_language, DMGL_ANSI);
1172 printf_filtered ("\" is at ");
1173 print_address_numeric (load_addr, 1, gdb_stdout);
1174 printf_filtered (" in a file compiled without debugging");
1175 section = SYMBOL_BFD_SECTION (msymbol);
1176 if (section_is_overlay (section))
1178 load_addr = overlay_unmapped_address (load_addr, section);
1179 printf_filtered (",\n -- loaded at ");
1180 print_address_numeric (load_addr, 1, gdb_stdout);
1181 printf_filtered (" in overlay section %s", section->name);
1183 printf_filtered (".\n");
1186 error ("No symbol \"%s\" in current context.", exp);
1190 printf_filtered ("Symbol \"");
1191 fprintf_symbol_filtered (gdb_stdout, SYMBOL_NAME (sym),
1192 current_language->la_language, DMGL_ANSI);
1193 printf_filtered ("\" is ");
1194 val = SYMBOL_VALUE (sym);
1195 basereg = SYMBOL_BASEREG (sym);
1196 section = SYMBOL_BFD_SECTION (sym);
1198 switch (SYMBOL_CLASS (sym))
1201 case LOC_CONST_BYTES:
1202 printf_filtered ("constant");
1206 printf_filtered ("a label at address ");
1207 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1209 if (section_is_overlay (section))
1211 load_addr = overlay_unmapped_address (load_addr, section);
1212 printf_filtered (",\n -- loaded at ");
1213 print_address_numeric (load_addr, 1, gdb_stdout);
1214 printf_filtered (" in overlay section %s", section->name);
1219 printf_filtered ("a variable in register %s", REGISTER_NAME (val));
1223 printf_filtered ("static storage at address ");
1224 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1226 if (section_is_overlay (section))
1228 load_addr = overlay_unmapped_address (load_addr, section);
1229 printf_filtered (",\n -- loaded at ");
1230 print_address_numeric (load_addr, 1, gdb_stdout);
1231 printf_filtered (" in overlay section %s", section->name);
1236 printf_filtered ("external global (indirect addressing), at address *(");
1237 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1239 printf_filtered (")");
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);
1250 printf_filtered ("an argument in register %s", REGISTER_NAME (val));
1253 case LOC_REGPARM_ADDR:
1254 printf_filtered ("address of an argument in register %s", REGISTER_NAME (val));
1258 printf_filtered ("an argument at offset %ld", val);
1262 printf_filtered ("an argument at frame offset %ld", val);
1266 printf_filtered ("a local variable at frame offset %ld", val);
1270 printf_filtered ("a reference argument at offset %ld", val);
1274 printf_filtered ("a variable at offset %ld from register %s",
1275 val, REGISTER_NAME (basereg));
1278 case LOC_BASEREG_ARG:
1279 printf_filtered ("an argument at offset %ld from register %s",
1280 val, REGISTER_NAME (basereg));
1284 printf_filtered ("a typedef");
1288 printf_filtered ("a function at address ");
1289 #ifdef GDB_TARGET_MASK_DISAS_PC
1290 print_address_numeric
1291 (load_addr = GDB_TARGET_MASK_DISAS_PC (BLOCK_START (SYMBOL_BLOCK_VALUE (sym))),
1294 print_address_numeric (load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)),
1297 if (section_is_overlay (section))
1299 load_addr = overlay_unmapped_address (load_addr, section);
1300 printf_filtered (",\n -- loaded at ");
1301 print_address_numeric (load_addr, 1, gdb_stdout);
1302 printf_filtered (" in overlay section %s", section->name);
1306 case LOC_UNRESOLVED:
1308 struct minimal_symbol *msym;
1310 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, NULL);
1312 printf_filtered ("unresolved");
1315 section = SYMBOL_BFD_SECTION (msym);
1316 printf_filtered ("static storage at address ");
1317 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (msym),
1319 if (section_is_overlay (section))
1321 load_addr = overlay_unmapped_address (load_addr, section);
1322 printf_filtered (",\n -- loaded at ");
1323 print_address_numeric (load_addr, 1, gdb_stdout);
1324 printf_filtered (" in overlay section %s", section->name);
1330 case LOC_THREAD_LOCAL_STATIC:
1332 "a thread-local variable at offset %ld from the thread base register %s",
1333 val, REGISTER_NAME (basereg));
1336 case LOC_OPTIMIZED_OUT:
1337 printf_filtered ("optimized out");
1341 printf_filtered ("of unknown (botched) type");
1344 printf_filtered (".\n");
1348 x_command (exp, from_tty)
1352 struct expression *expr;
1353 struct format_data fmt;
1354 struct cleanup *old_chain;
1357 fmt.format = last_format;
1358 fmt.size = last_size;
1361 if (exp && *exp == '/')
1364 fmt = decode_format (&exp, last_format, last_size);
1367 /* If we have an expression, evaluate it and use it as the address. */
1369 if (exp != 0 && *exp != 0)
1371 expr = parse_expression (exp);
1372 /* Cause expression not to be there any more
1373 if this command is repeated with Newline.
1374 But don't clobber a user-defined command's definition. */
1377 old_chain = make_cleanup (free_current_contents, &expr);
1378 val = evaluate_expression (expr);
1379 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
1380 val = value_ind (val);
1381 /* In rvalue contexts, such as this, functions are coerced into
1382 pointers to functions. This makes "x/i main" work. */
1383 if ( /* last_format == 'i'
1384 && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
1385 && VALUE_LVAL (val) == lval_memory)
1386 next_address = VALUE_ADDRESS (val);
1388 next_address = value_as_pointer (val);
1389 if (VALUE_BFD_SECTION (val))
1390 next_section = VALUE_BFD_SECTION (val);
1391 do_cleanups (old_chain);
1394 do_examine (fmt, next_address, next_section);
1396 /* If the examine succeeds, we remember its size and format for next time. */
1397 last_size = fmt.size;
1398 last_format = fmt.format;
1400 /* Set a couple of internal variables if appropriate. */
1401 if (last_examine_value)
1403 /* Make last address examined available to the user as $_. Use
1404 the correct pointer type. */
1405 struct type *pointer_type
1406 = lookup_pointer_type (VALUE_TYPE (last_examine_value));
1407 set_internalvar (lookup_internalvar ("_"),
1408 value_from_pointer (pointer_type,
1409 last_examine_address));
1411 /* Make contents of last address examined available to the user as $__. */
1412 /* If the last value has not been fetched from memory then don't
1413 fetch it now - instead mark it by voiding the $__ variable. */
1414 if (VALUE_LAZY (last_examine_value))
1415 set_internalvar (lookup_internalvar ("__"),
1416 allocate_value (builtin_type_void));
1418 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1423 /* Add an expression to the auto-display chain.
1424 Specify the expression. */
1427 display_command (exp, from_tty)
1431 struct format_data fmt;
1432 register struct expression *expr;
1433 register struct display *new;
1437 if (tui_version && *exp == '$')
1438 display_it = ((TuiStatus) tuiDo (
1439 (TuiOpaqueFuncPtr) tui_vSetLayoutTo, exp) == TUI_FAILURE);
1453 fmt = decode_format (&exp, 0, 0);
1454 if (fmt.size && fmt.format == 0)
1456 if (fmt.format == 'i' || fmt.format == 's')
1466 innermost_block = 0;
1467 expr = parse_expression (exp);
1469 new = (struct display *) xmalloc (sizeof (struct display));
1472 new->block = innermost_block;
1473 new->next = display_chain;
1474 new->number = ++display_number;
1476 new->status = enabled;
1477 display_chain = new;
1479 if (from_tty && target_has_execution)
1480 do_one_display (new);
1490 free ((PTR) d->exp);
1494 /* Clear out the display_chain.
1495 Done when new symtabs are loaded, since this invalidates
1496 the types stored in many expressions. */
1501 register struct display *d;
1503 while ((d = display_chain) != NULL)
1505 free ((PTR) d->exp);
1506 display_chain = d->next;
1511 /* Delete the auto-display number NUM. */
1514 delete_display (num)
1517 register struct display *d1, *d;
1520 error ("No display number %d.", num);
1522 if (display_chain->number == num)
1525 display_chain = d1->next;
1529 for (d = display_chain;; d = d->next)
1532 error ("No display number %d.", num);
1533 if (d->next->number == num)
1543 /* Delete some values from the auto-display chain.
1544 Specify the element numbers. */
1547 undisplay_command (args, from_tty)
1551 register char *p = args;
1557 if (query ("Delete all auto-display expressions? "))
1566 while (*p1 >= '0' && *p1 <= '9')
1568 if (*p1 && *p1 != ' ' && *p1 != '\t')
1569 error ("Arguments must be display numbers.");
1573 delete_display (num);
1576 while (*p == ' ' || *p == '\t')
1582 /* Display a single auto-display.
1583 Do nothing if the display cannot be printed in the current context,
1584 or if the display is disabled. */
1590 int within_current_scope;
1592 if (d->status == disabled)
1596 within_current_scope = contained_in (get_selected_block (), d->block);
1598 within_current_scope = 1;
1599 if (!within_current_scope)
1602 current_display_number = d->number;
1604 annotate_display_begin ();
1605 printf_filtered ("%d", d->number);
1606 annotate_display_number_end ();
1607 printf_filtered (": ");
1613 annotate_display_format ();
1615 printf_filtered ("x/");
1616 if (d->format.count != 1)
1617 printf_filtered ("%d", d->format.count);
1618 printf_filtered ("%c", d->format.format);
1619 if (d->format.format != 'i' && d->format.format != 's')
1620 printf_filtered ("%c", d->format.size);
1621 printf_filtered (" ");
1623 annotate_display_expression ();
1625 print_expression (d->exp, gdb_stdout);
1626 annotate_display_expression_end ();
1628 if (d->format.count != 1)
1629 printf_filtered ("\n");
1631 printf_filtered (" ");
1633 val = evaluate_expression (d->exp);
1634 addr = value_as_pointer (val);
1635 if (d->format.format == 'i')
1636 addr = ADDR_BITS_REMOVE (addr);
1638 annotate_display_value ();
1640 do_examine (d->format, addr, VALUE_BFD_SECTION (val));
1644 annotate_display_format ();
1646 if (d->format.format)
1647 printf_filtered ("/%c ", d->format.format);
1649 annotate_display_expression ();
1651 print_expression (d->exp, gdb_stdout);
1652 annotate_display_expression_end ();
1654 printf_filtered (" = ");
1656 annotate_display_expression ();
1658 print_formatted (evaluate_expression (d->exp),
1659 d->format.format, d->format.size, gdb_stdout);
1660 printf_filtered ("\n");
1663 annotate_display_end ();
1665 gdb_flush (gdb_stdout);
1666 current_display_number = -1;
1669 /* Display all of the values on the auto-display chain which can be
1670 evaluated in the current scope. */
1675 register struct display *d;
1677 for (d = display_chain; d; d = d->next)
1681 /* Delete the auto-display which we were in the process of displaying.
1682 This is done when there is an error or a signal. */
1685 disable_display (num)
1688 register struct display *d;
1690 for (d = display_chain; d; d = d->next)
1691 if (d->number == num)
1693 d->status = disabled;
1696 printf_unfiltered ("No display number %d.\n", num);
1700 disable_current_display ()
1702 if (current_display_number >= 0)
1704 disable_display (current_display_number);
1705 fprintf_unfiltered (gdb_stderr, "Disabling display %d to avoid infinite recursion.\n",
1706 current_display_number);
1708 current_display_number = -1;
1712 display_info (ignore, from_tty)
1716 register struct display *d;
1719 printf_unfiltered ("There are no auto-display expressions now.\n");
1721 printf_filtered ("Auto-display expressions now in effect:\n\
1722 Num Enb Expression\n");
1724 for (d = display_chain; d; d = d->next)
1726 printf_filtered ("%d: %c ", d->number, "ny"[(int) d->status]);
1728 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1730 else if (d->format.format)
1731 printf_filtered ("/%c ", d->format.format);
1732 print_expression (d->exp, gdb_stdout);
1733 if (d->block && !contained_in (get_selected_block (), d->block))
1734 printf_filtered (" (cannot be evaluated in the current context)");
1735 printf_filtered ("\n");
1736 gdb_flush (gdb_stdout);
1741 enable_display (args, from_tty)
1745 register char *p = args;
1748 register struct display *d;
1752 for (d = display_chain; d; d = d->next)
1753 d->status = enabled;
1759 while (*p1 >= '0' && *p1 <= '9')
1761 if (*p1 && *p1 != ' ' && *p1 != '\t')
1762 error ("Arguments must be display numbers.");
1766 for (d = display_chain; d; d = d->next)
1767 if (d->number == num)
1769 d->status = enabled;
1772 printf_unfiltered ("No display number %d.\n", num);
1775 while (*p == ' ' || *p == '\t')
1782 disable_display_command (args, from_tty)
1786 register char *p = args;
1788 register struct display *d;
1792 for (d = display_chain; d; d = d->next)
1793 d->status = disabled;
1799 while (*p1 >= '0' && *p1 <= '9')
1801 if (*p1 && *p1 != ' ' && *p1 != '\t')
1802 error ("Arguments must be display numbers.");
1804 disable_display (atoi (p));
1807 while (*p == ' ' || *p == '\t')
1813 /* Print the value in stack frame FRAME of a variable
1814 specified by a struct symbol. */
1817 print_variable_value (var, frame, stream)
1819 struct frame_info *frame;
1820 struct ui_file *stream;
1822 value_ptr val = read_var_value (var, frame);
1824 value_print (val, stream, 0, Val_pretty_default);
1827 /* Print the arguments of a stack frame, given the function FUNC
1828 running in that frame (as a symbol), the info on the frame,
1829 and the number of args according to the stack frame (or -1 if unknown). */
1831 /* References here and elsewhere to "number of args according to the
1832 stack frame" appear in all cases to refer to "number of ints of args
1833 according to the stack frame". At least for VAX, i386, isi. */
1836 print_frame_args (func, fi, num, stream)
1837 struct symbol *func;
1838 struct frame_info *fi;
1840 struct ui_file *stream;
1842 struct block *b = NULL;
1846 register struct symbol *sym;
1847 register value_ptr val;
1848 /* Offset of next stack argument beyond the one we have seen that is
1849 at the highest offset.
1850 -1 if we haven't come to a stack argument yet. */
1851 long highest_offset = -1;
1853 /* Number of ints of arguments that we have printed so far. */
1854 int args_printed = 0;
1856 struct cleanup *old_chain;
1857 struct ui_stream *stb;
1859 stb = ui_out_stream_new (uiout);
1860 old_chain = make_cleanup_ui_out_stream_delete (stb);
1865 b = SYMBOL_BLOCK_VALUE (func);
1866 nsyms = BLOCK_NSYMS (b);
1869 for (i = 0; i < nsyms; i++)
1872 sym = BLOCK_SYM (b, i);
1874 /* Keep track of the highest stack argument offset seen, and
1875 skip over any kinds of symbols we don't care about. */
1877 switch (SYMBOL_CLASS (sym))
1882 long current_offset = SYMBOL_VALUE (sym);
1883 arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1885 /* Compute address of next argument by adding the size of
1886 this argument and rounding to an int boundary. */
1888 ((current_offset + arg_size + sizeof (int) - 1)
1889 & ~(sizeof (int) - 1));
1891 /* If this is the highest offset seen yet, set highest_offset. */
1892 if (highest_offset == -1
1893 || (current_offset > highest_offset))
1894 highest_offset = current_offset;
1896 /* Add the number of ints we're about to print to args_printed. */
1897 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
1900 /* We care about types of symbols, but don't need to keep track of
1901 stack offsets in them. */
1903 case LOC_REGPARM_ADDR:
1905 case LOC_BASEREG_ARG:
1908 /* Other types of symbols we just skip over. */
1913 /* We have to look up the symbol because arguments can have
1914 two entries (one a parameter, one a local) and the one we
1915 want is the local, which lookup_symbol will find for us.
1916 This includes gcc1 (not gcc2) on the sparc when passing a
1917 small structure and gcc2 when the argument type is float
1918 and it is passed as a double and converted to float by
1919 the prologue (in the latter case the type of the LOC_ARG
1920 symbol is double and the type of the LOC_LOCAL symbol is
1922 /* But if the parameter name is null, don't try it.
1923 Null parameter names occur on the RS/6000, for traceback tables.
1924 FIXME, should we even print them? */
1926 if (*SYMBOL_NAME (sym))
1928 struct symbol *nsym;
1929 nsym = lookup_symbol
1931 b, VAR_NAMESPACE, (int *) NULL, (struct symtab **) NULL);
1932 if (SYMBOL_CLASS (nsym) == LOC_REGISTER)
1934 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
1935 it was passed on the stack and loaded into a register,
1936 or passed in a register and stored in a stack slot.
1937 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
1939 Reasons for using the LOC_ARG:
1940 (1) because find_saved_registers may be slow for remote
1942 (2) because registers are often re-used and stack slots
1943 rarely (never?) are. Therefore using the stack slot is
1944 much less likely to print garbage.
1946 Reasons why we might want to use the LOC_REGISTER:
1947 (1) So that the backtrace prints the same value as
1948 "print foo". I see no compelling reason why this needs
1949 to be the case; having the backtrace print the value which
1950 was passed in, and "print foo" print the value as modified
1951 within the called function, makes perfect sense to me.
1953 Additional note: It might be nice if "info args" displayed
1955 One more note: There is a case with sparc structure passing
1956 where we need to use the LOC_REGISTER, but this is dealt with
1957 by creating a single LOC_REGPARM in symbol reading. */
1959 /* Leave sym (the LOC_ARG) alone. */
1967 /* Print the current arg. */
1969 ui_out_text (uiout, ", ");
1970 ui_out_wrap_hint (uiout, " ");
1972 annotate_arg_begin ();
1974 ui_out_list_begin (uiout, NULL);
1975 fprintf_symbol_filtered (stb->stream, SYMBOL_SOURCE_NAME (sym),
1976 SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
1977 ui_out_field_stream (uiout, "name", stb);
1978 annotate_arg_name_end ();
1979 ui_out_text (uiout, "=");
1981 /* Print the current arg. */
1983 fprintf_filtered (stream, ", ");
1986 annotate_arg_begin ();
1988 fprintf_symbol_filtered (stream, SYMBOL_SOURCE_NAME (sym),
1989 SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
1990 annotate_arg_name_end ();
1991 fputs_filtered ("=", stream);
1994 /* Avoid value_print because it will deref ref parameters. We just
1995 want to print their addresses. Print ??? for args whose address
1996 we do not know. We pass 2 as "recurse" to val_print because our
1997 standard indentation here is 4 spaces, and val_print indents
1998 2 for each recurse. */
1999 val = read_var_value (sym, fi);
2001 annotate_arg_value (val == NULL ? NULL : VALUE_TYPE (val));
2005 if (GDB_TARGET_IS_D10V
2006 && SYMBOL_CLASS (sym) == LOC_REGPARM && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_PTR)
2007 TYPE_LENGTH (VALUE_TYPE (val)) = 2;
2009 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
2010 VALUE_ADDRESS (val),
2011 stb->stream, 0, 0, 2, Val_no_prettyprint);
2012 ui_out_field_stream (uiout, "value", stb);
2015 ui_out_text (uiout, "???");
2017 ui_out_list_end (uiout);
2019 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
2020 VALUE_ADDRESS (val),
2021 stream, 0, 0, 2, Val_no_prettyprint);
2024 fputs_filtered ("???", stream);
2027 annotate_arg_end ();
2032 /* Don't print nameless args in situations where we don't know
2033 enough about the stack to find them. */
2038 if (highest_offset == -1)
2039 start = FRAME_ARGS_SKIP;
2041 start = highest_offset;
2043 print_frame_nameless_args (fi, start, num - args_printed,
2047 do_cleanups (old_chain);
2048 #endif /* no UI_OUT */
2051 /* Print nameless args on STREAM.
2052 FI is the frameinfo for this frame, START is the offset
2053 of the first nameless arg, and NUM is the number of nameless args to
2054 print. FIRST is nonzero if this is the first argument (not just
2055 the first nameless arg). */
2058 print_frame_nameless_args (fi, start, num, first, stream)
2059 struct frame_info *fi;
2063 struct ui_file *stream;
2069 for (i = 0; i < num; i++)
2072 #ifdef NAMELESS_ARG_VALUE
2073 NAMELESS_ARG_VALUE (fi, start, &arg_value);
2075 argsaddr = FRAME_ARGS_ADDRESS (fi);
2079 arg_value = read_memory_integer (argsaddr + start, sizeof (int));
2083 fprintf_filtered (stream, ", ");
2085 #ifdef PRINT_NAMELESS_INTEGER
2086 PRINT_NAMELESS_INTEGER (stream, arg_value);
2088 #ifdef PRINT_TYPELESS_INTEGER
2089 PRINT_TYPELESS_INTEGER (stream, builtin_type_int, (LONGEST) arg_value);
2091 fprintf_filtered (stream, "%ld", arg_value);
2092 #endif /* PRINT_TYPELESS_INTEGER */
2093 #endif /* PRINT_NAMELESS_INTEGER */
2095 start += sizeof (int);
2101 printf_command (arg, from_tty)
2105 register char *f = NULL;
2106 register char *s = arg;
2107 char *string = NULL;
2108 value_ptr *val_args;
2110 char *current_substring;
2112 int allocated_args = 20;
2113 struct cleanup *old_cleanups;
2115 val_args = (value_ptr *) xmalloc (allocated_args * sizeof (value_ptr));
2116 old_cleanups = make_cleanup (free_current_contents, &val_args);
2119 error_no_arg ("format-control string and values to print");
2121 /* Skip white space before format string */
2122 while (*s == ' ' || *s == '\t')
2125 /* A format string should follow, enveloped in double quotes */
2127 error ("Bad format string, missing '\"'.");
2129 /* Parse the format-control string and copy it into the string STRING,
2130 processing some kinds of escape sequence. */
2132 f = string = (char *) alloca (strlen (s) + 1);
2140 error ("Bad format string, non-terminated '\"'.");
2152 *f++ = '\007'; /* Bell */
2177 /* ??? TODO: handle other escape sequences */
2178 error ("Unrecognized escape character \\%c in format string.",
2188 /* Skip over " and following space and comma. */
2191 while (*s == ' ' || *s == '\t')
2194 if (*s != ',' && *s != 0)
2195 error ("Invalid argument syntax");
2199 while (*s == ' ' || *s == '\t')
2202 /* Need extra space for the '\0's. Doubling the size is sufficient. */
2203 substrings = alloca (strlen (string) * 2);
2204 current_substring = substrings;
2207 /* Now scan the string for %-specs and see what kinds of args they want.
2208 argclass[I] classifies the %-specs so we can give printf_filtered
2209 something of the right size. */
2213 no_arg, int_arg, string_arg, double_arg, long_long_arg
2215 enum argclass *argclass;
2216 enum argclass this_argclass;
2222 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
2230 while (strchr ("0123456789.hlL-+ #", *f))
2232 if (*f == 'l' || *f == 'L')
2239 this_argclass = string_arg;
2245 this_argclass = double_arg;
2249 error ("`*' not supported for precision or width in printf");
2252 error ("Format specifier `n' not supported in printf");
2255 this_argclass = no_arg;
2260 this_argclass = long_long_arg;
2262 this_argclass = int_arg;
2266 if (this_argclass != no_arg)
2268 strncpy (current_substring, last_arg, f - last_arg);
2269 current_substring += f - last_arg;
2270 *current_substring++ = '\0';
2272 argclass[nargs_wanted++] = this_argclass;
2276 /* Now, parse all arguments and evaluate them.
2277 Store the VALUEs in VAL_ARGS. */
2282 if (nargs == allocated_args)
2283 val_args = (value_ptr *) xrealloc ((char *) val_args,
2284 (allocated_args *= 2)
2285 * sizeof (value_ptr));
2287 val_args[nargs] = parse_to_comma_and_eval (&s1);
2289 /* If format string wants a float, unchecked-convert the value to
2290 floating point of the same size */
2292 if (argclass[nargs] == double_arg)
2294 struct type *type = VALUE_TYPE (val_args[nargs]);
2295 if (TYPE_LENGTH (type) == sizeof (float))
2296 VALUE_TYPE (val_args[nargs]) = builtin_type_float;
2297 if (TYPE_LENGTH (type) == sizeof (double))
2298 VALUE_TYPE (val_args[nargs]) = builtin_type_double;
2306 if (nargs != nargs_wanted)
2307 error ("Wrong number of arguments for specified format-string");
2309 /* Now actually print them. */
2310 current_substring = substrings;
2311 for (i = 0; i < nargs; i++)
2313 switch (argclass[i])
2320 tem = value_as_pointer (val_args[i]);
2322 /* This is a %s argument. Find the length of the string. */
2327 read_memory (tem + j, &c, 1);
2332 /* Copy the string contents into a string inside GDB. */
2333 str = (char *) alloca (j + 1);
2334 read_memory (tem, str, j);
2337 printf_filtered (current_substring, str);
2342 double val = value_as_double (val_args[i]);
2343 printf_filtered (current_substring, val);
2347 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2349 long long val = value_as_long (val_args[i]);
2350 printf_filtered (current_substring, val);
2354 error ("long long not supported in printf");
2358 /* FIXME: there should be separate int_arg and long_arg. */
2359 long val = value_as_long (val_args[i]);
2360 printf_filtered (current_substring, val);
2363 default: /* purecov: deadcode */
2364 error ("internal error in printf_command"); /* purecov: deadcode */
2366 /* Skip to the next substring. */
2367 current_substring += strlen (current_substring) + 1;
2369 /* Print the portion of the format string after the last argument. */
2370 printf_filtered (last_arg);
2372 do_cleanups (old_cleanups);
2375 /* Dump a specified section of assembly code. With no command line
2376 arguments, this command will dump the assembly code for the
2377 function surrounding the pc value in the selected frame. With one
2378 argument, it will dump the assembly code surrounding that pc value.
2379 Two arguments are interpeted as bounds within which to dump
2384 disassemble_command (arg, from_tty)
2388 CORE_ADDR low, high;
2390 CORE_ADDR pc, pc_masked;
2399 if (!selected_frame)
2400 error ("No frame selected.\n");
2402 pc = get_frame_pc (selected_frame);
2403 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
2404 error ("No function contains program counter for selected frame.\n");
2406 else if (tui_version)
2407 low = (CORE_ADDR) tuiDo ((TuiOpaqueFuncPtr) tui_vGetLowDisassemblyAddress,
2411 low += FUNCTION_START_OFFSET;
2413 else if (!(space_index = (char *) strchr (arg, ' ')))
2416 pc = parse_and_eval_address (arg);
2417 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
2418 error ("No function contains specified address.\n");
2420 else if (tui_version)
2421 low = (CORE_ADDR) tuiDo ((TuiOpaqueFuncPtr) tui_vGetLowDisassemblyAddress,
2426 if (overlay_debugging)
2428 section = find_pc_overlay (pc);
2429 if (pc_in_unmapped_range (pc, section))
2431 /* find_pc_partial_function will have returned low and high
2432 relative to the symbolic (mapped) address range. Need to
2433 translate them back to the unmapped range where PC is. */
2434 low = overlay_unmapped_address (low, section);
2435 high = overlay_unmapped_address (high, section);
2439 low += FUNCTION_START_OFFSET;
2443 /* Two arguments. */
2444 *space_index = '\0';
2445 low = parse_and_eval_address (arg);
2446 high = parse_and_eval_address (space_index + 1);
2451 m_winPtrIsNull (disassemWin) || !disassemWin->generic.isVisible)
2454 printf_filtered ("Dump of assembler code ");
2457 printf_filtered ("for function %s:\n", name);
2461 printf_filtered ("from ");
2462 print_address_numeric (low, 1, gdb_stdout);
2463 printf_filtered (" to ");
2464 print_address_numeric (high, 1, gdb_stdout);
2465 printf_filtered (":\n");
2468 /* Dump the specified range. */
2471 #ifdef GDB_TARGET_MASK_DISAS_PC
2472 pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
2477 while (pc_masked < high)
2480 print_address (pc_masked, gdb_stdout);
2481 printf_filtered (":\t");
2482 /* We often wrap here if there are long symbolic names. */
2484 pc += print_insn (pc, gdb_stdout);
2485 printf_filtered ("\n");
2487 #ifdef GDB_TARGET_MASK_DISAS_PC
2488 pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
2493 printf_filtered ("End of assembler dump.\n");
2494 gdb_flush (gdb_stdout);
2499 tuiDo ((TuiOpaqueFuncPtr) tui_vAddWinToLayout, DISASSEM_WIN);
2500 tuiDo ((TuiOpaqueFuncPtr) tui_vUpdateSourceWindowsWithAddr, low);
2505 /* Print the instruction at address MEMADDR in debugged memory,
2506 on STREAM. Returns length of the instruction, in bytes. */
2509 print_insn (memaddr, stream)
2511 struct ui_file *stream;
2513 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2514 TARGET_PRINT_INSN_INFO->endian = BFD_ENDIAN_BIG;
2516 TARGET_PRINT_INSN_INFO->endian = BFD_ENDIAN_LITTLE;
2518 if (TARGET_ARCHITECTURE != NULL)
2519 TARGET_PRINT_INSN_INFO->mach = TARGET_ARCHITECTURE->mach;
2520 /* else: should set .mach=0 but some disassemblers don't grok this */
2522 return TARGET_PRINT_INSN (memaddr, TARGET_PRINT_INSN_INFO);
2527 _initialize_printcmd ()
2529 current_display_number = -1;
2531 add_info ("address", address_info,
2532 "Describe where symbol SYM is stored.");
2534 add_info ("symbol", sym_info,
2535 "Describe what symbol is at location ADDR.\n\
2536 Only for symbols with fixed locations (global or static scope).");
2538 add_com ("x", class_vars, x_command,
2539 concat ("Examine memory: x/FMT ADDRESS.\n\
2540 ADDRESS is an expression for the memory address to examine.\n\
2541 FMT is a repeat count followed by a format letter and a size letter.\n\
2542 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2543 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n",
2544 "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2545 The specified number of objects of the specified size are printed\n\
2546 according to the format.\n\n\
2547 Defaults for format and size letters are those previously used.\n\
2548 Default count is 1. Default address is following last thing printed\n\
2549 with this command or \"print\".", NULL));
2551 add_com ("disassemble", class_vars, disassemble_command,
2552 "Disassemble a specified section of memory.\n\
2553 Default is the function surrounding the pc of the selected frame.\n\
2554 With a single argument, the function surrounding that address is dumped.\n\
2555 Two arguments are taken as a range of memory to dump.");
2557 add_com_alias ("va", "disassemble", class_xdb, 0);
2560 add_com ("whereis", class_vars, whereis_command,
2561 "Print line number and file of definition of variable.");
2564 add_info ("display", display_info,
2565 "Expressions to display when program stops, with code numbers.");
2567 add_cmd ("undisplay", class_vars, undisplay_command,
2568 "Cancel some expressions to be displayed when program stops.\n\
2569 Arguments are the code numbers of the expressions to stop displaying.\n\
2570 No argument means cancel all automatic-display expressions.\n\
2571 \"delete display\" has the same effect as this command.\n\
2572 Do \"info display\" to see current list of code numbers.",
2575 add_com ("display", class_vars, display_command,
2576 "Print value of expression EXP each time the program stops.\n\
2577 /FMT may be used before EXP as in the \"print\" command.\n\
2578 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2579 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2580 and examining is done as in the \"x\" command.\n\n\
2581 With no argument, display all currently requested auto-display expressions.\n\
2582 Use \"undisplay\" to cancel display requests previously made."
2585 add_cmd ("display", class_vars, enable_display,
2586 "Enable some expressions to be displayed when program stops.\n\
2587 Arguments are the code numbers of the expressions to resume displaying.\n\
2588 No argument means enable all automatic-display expressions.\n\
2589 Do \"info display\" to see current list of code numbers.", &enablelist);
2591 add_cmd ("display", class_vars, disable_display_command,
2592 "Disable some expressions to be displayed when program stops.\n\
2593 Arguments are the code numbers of the expressions to stop displaying.\n\
2594 No argument means disable all automatic-display expressions.\n\
2595 Do \"info display\" to see current list of code numbers.", &disablelist);
2597 add_cmd ("display", class_vars, undisplay_command,
2598 "Cancel some expressions to be displayed when program stops.\n\
2599 Arguments are the code numbers of the expressions to stop displaying.\n\
2600 No argument means cancel all automatic-display expressions.\n\
2601 Do \"info display\" to see current list of code numbers.", &deletelist);
2603 add_com ("printf", class_vars, printf_command,
2604 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2605 This is useful for formatted output in user-defined commands.");
2607 add_com ("output", class_vars, output_command,
2608 "Like \"print\" but don't put in value history and don't print newline.\n\
2609 This is useful in user-defined commands.");
2611 add_prefix_cmd ("set", class_vars, set_command,
2612 concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2613 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2614 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2615 with $), a register (a few standard names starting with $), or an actual\n\
2616 variable in the program being debugged. EXP is any valid expression.\n",
2617 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2618 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2619 You can see these environment settings with the \"show\" command.", NULL),
2620 &setlist, "set ", 1, &cmdlist);
2622 add_com ("assign", class_vars, set_command, concat ("Evaluate expression \
2623 EXP and assign result to variable VAR, using assignment\n\
2624 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2625 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2626 with $), a register (a few standard names starting with $), or an actual\n\
2627 variable in the program being debugged. EXP is any valid expression.\n",
2628 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2629 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2630 You can see these environment settings with the \"show\" command.", NULL));
2632 /* "call" is the same as "set", but handy for dbx users to call fns. */
2633 add_com ("call", class_vars, call_command,
2634 "Call a function in the program.\n\
2635 The argument is the function name and arguments, in the notation of the\n\
2636 current working language. The result is printed and saved in the value\n\
2637 history, if it is not void.");
2639 add_cmd ("variable", class_vars, set_command,
2640 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2641 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2642 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2643 with $), a register (a few standard names starting with $), or an actual\n\
2644 variable in the program being debugged. EXP is any valid expression.\n\
2645 This may usually be abbreviated to simply \"set\".",
2648 add_com ("print", class_vars, print_command,
2649 concat ("Print value of expression EXP.\n\
2650 Variables accessible are those of the lexical environment of the selected\n\
2651 stack frame, plus all those whose scope is global or an entire file.\n\
2653 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2654 $$NUM refers to NUM'th value back from the last one.\n\
2655 Names starting with $ refer to registers (with the values they would have\n",
2656 "if the program were to return to the stack frame now selected, restoring\n\
2657 all registers saved by frames farther in) or else to debugger\n\
2658 \"convenience\" variables (any such name not a known register).\n\
2659 Use assignment expressions to give values to convenience variables.\n",
2661 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2662 @ is a binary operator for treating consecutive data objects\n\
2663 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2664 element is FOO, whose second element is stored in the space following\n\
2665 where FOO is stored, etc. FOO must be an expression whose value\n\
2666 resides in memory.\n",
2668 EXP may be preceded with /FMT, where FMT is a format letter\n\
2669 but no count or size letter (see \"x\" command).", NULL));
2670 add_com_alias ("p", "print", class_vars, 1);
2672 add_com ("inspect", class_vars, inspect_command,
2673 "Same as \"print\" command, except that if you are running in the epoch\n\
2674 environment, the value is printed in its own window.");
2677 add_set_cmd ("max-symbolic-offset", no_class, var_uinteger,
2678 (char *) &max_symbolic_offset,
2679 "Set the largest offset that will be printed in <symbol+1234> form.",
2683 add_set_cmd ("symbol-filename", no_class, var_boolean,
2684 (char *) &print_symbol_filename,
2685 "Set printing of source filename and line number with <symbol>.",
2689 /* For examine/instruction a single byte quantity is specified as
2690 the data. This avoids problems with value_at_lazy() requiring a
2691 valid data type (and rejecting VOID). */
2692 examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
2694 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2695 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2696 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2697 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);