1 /* Print values for GNU debugger GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1993, 1994, 1995
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 /* Pointer to the target-dependent disassembly function. */
121 int (*tm_print_insn) PARAMS ((bfd_vma, disassemble_info *));
122 disassemble_info tm_print_insn_info;
124 /* Functions exported for general use: */
126 void output_command PARAMS ((char *, int));
129 /* Prototypes for local functions. */
131 static void delete_display PARAMS ((int));
133 static void enable_display PARAMS ((char *, int));
135 static void disable_display_command PARAMS ((char *, int));
137 static void disassemble_command PARAMS ((char *, int));
139 static void printf_command PARAMS ((char *, int));
141 static void print_frame_nameless_args PARAMS ((struct frame_info *, long,
142 int, int, GDB_FILE *));
144 static void display_info PARAMS ((char *, int));
146 static void do_one_display PARAMS ((struct display *));
148 static void undisplay_command PARAMS ((char *, int));
150 static void free_display PARAMS ((struct display *));
152 static void display_command PARAMS ((char *, int));
154 void x_command PARAMS ((char *, int));
156 static void address_info PARAMS ((char *, int));
158 static void set_command PARAMS ((char *, int));
160 static void call_command PARAMS ((char *, int));
162 static void inspect_command PARAMS ((char *, int));
164 static void print_command PARAMS ((char *, int));
166 static void print_command_1 PARAMS ((char *, int, int));
168 static void validate_format PARAMS ((struct format_data, char *));
170 static void do_examine PARAMS ((struct format_data, CORE_ADDR addr, asection *section));
172 static void print_formatted PARAMS ((value_ptr, int, int));
174 static struct format_data decode_format PARAMS ((char **, int, int));
176 static int print_insn PARAMS ((CORE_ADDR, GDB_FILE *));
179 /* Decode a format specification. *STRING_PTR should point to it.
180 OFORMAT and OSIZE are used as defaults for the format and size
181 if none are given in the format specification.
182 If OSIZE is zero, then the size field of the returned value
183 should be set only if a size is explicitly specified by the
185 The structure returned describes all the data
186 found in the specification. In addition, *STRING_PTR is advanced
187 past the specification and past all whitespace following it. */
189 static struct format_data
190 decode_format (string_ptr, oformat, osize)
195 struct format_data val;
196 register char *p = *string_ptr;
202 if (*p >= '0' && *p <= '9')
203 val.count = atoi (p);
204 while (*p >= '0' && *p <= '9') p++;
206 /* Now process size or format letters that follow. */
210 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
212 else if (*p >= 'a' && *p <= 'z')
218 while (*p == ' ' || *p == '\t') p++;
221 /* Set defaults for format and size if not specified. */
222 if (val.format == '?')
226 /* Neither has been specified. */
227 val.format = oformat;
231 /* If a size is specified, any format makes a reasonable
232 default except 'i'. */
233 val.format = oformat == 'i' ? 'x' : oformat;
235 else if (val.size == '?')
240 /* Pick the appropriate size for an address. */
241 if (TARGET_PTR_BIT == 64)
242 val.size = osize ? 'g' : osize;
243 else if (TARGET_PTR_BIT == 32)
244 val.size = osize ? 'w' : osize;
245 else if (TARGET_PTR_BIT == 16)
246 val.size = osize ? 'h' : osize;
248 /* Bad value for TARGET_PTR_BIT */
252 /* Floating point has to be word or giantword. */
253 if (osize == 'w' || osize == 'g')
256 /* Default it to giantword if the last used size is not
258 val.size = osize ? 'g' : osize;
261 /* Characters default to one byte. */
262 val.size = osize ? 'b' : osize;
265 /* The default is the size most recently specified. */
272 /* Print value VAL on gdb_stdout according to FORMAT, a letter or 0.
273 Do not end with a newline.
274 0 means print VAL according to its own type.
275 SIZE is the letter for the size of datum being printed.
276 This is used to pad hex numbers so they line up. */
279 print_formatted (val, format, size)
280 register value_ptr val;
284 struct type *type = check_typedef (VALUE_TYPE (val));
285 int len = TYPE_LENGTH (type);
287 if (VALUE_LVAL (val) == lval_memory)
289 next_address = VALUE_ADDRESS (val) + len;
290 next_section = VALUE_BFD_SECTION (val);
296 next_address = VALUE_ADDRESS (val)
297 + val_print_string (VALUE_ADDRESS (val), 0, gdb_stdout);
298 next_section = VALUE_BFD_SECTION (val);
302 /* The old comment says
303 "Force output out, print_insn not using _filtered".
304 I'm not completely sure what that means, I suspect most print_insn
305 now do use _filtered, so I guess it's obsolete. */
306 /* We often wrap here if there are long symbolic names. */
308 next_address = VALUE_ADDRESS (val)
309 + print_insn (VALUE_ADDRESS (val), gdb_stdout);
310 next_section = VALUE_BFD_SECTION (val);
315 || TYPE_CODE (type) == TYPE_CODE_ARRAY
316 || TYPE_CODE (type) == TYPE_CODE_STRING
317 || TYPE_CODE (type) == TYPE_CODE_STRUCT
318 || TYPE_CODE (type) == TYPE_CODE_UNION)
319 value_print (val, gdb_stdout, format, Val_pretty_default);
321 print_scalar_formatted (VALUE_CONTENTS (val), type,
322 format, size, gdb_stdout);
326 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
327 according to letters FORMAT and SIZE on STREAM.
328 FORMAT may not be zero. Formats s and i are not supported at this level.
330 This is how the elements of an array or structure are printed
334 print_scalar_formatted (valaddr, type, format, size, stream)
342 unsigned int len = TYPE_LENGTH (type);
344 if (len > sizeof (LONGEST)
352 if (! TYPE_UNSIGNED (type)
353 || ! extract_long_unsigned_integer (valaddr, len, &val_long))
355 /* We can't print it normally, but we can print it in hex.
356 Printing it in the wrong radix is more useful than saying
357 "use /x, you dummy". */
358 /* FIXME: we could also do octal or binary if that was the
360 /* FIXME: we should be using the size field to give us a
361 minimum field width to print. */
362 val_print_type_code_int (type, valaddr, stream);
366 /* If we get here, extract_long_unsigned_integer set val_long. */
368 else if (format != 'f')
369 val_long = unpack_long (type, valaddr);
371 /* If we are printing it as unsigned, truncate it in case it is actually
372 a negative signed value (e.g. "print/u (short)-1" should print 65535
373 (if shorts are 16 bits) instead of 4294967295). */
376 if (len < sizeof (LONGEST))
377 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
385 /* no size specified, like in print. Print varying # of digits. */
386 print_longest (stream, 'x', 1, val_long);
395 print_longest (stream, size, 1, val_long);
398 error ("Undefined output size \"%c\".", size);
403 print_longest (stream, 'd', 1, val_long);
407 print_longest (stream, 'u', 0, val_long);
412 print_longest (stream, 'o', 1, val_long);
414 fprintf_filtered (stream, "0");
418 print_address (unpack_pointer (type, valaddr), stream);
422 value_print (value_from_longest (builtin_type_char, val_long), stream, 0,
427 if (len == sizeof (float))
428 type = builtin_type_float;
429 else if (len == sizeof (double))
430 type = builtin_type_double;
431 print_floating (valaddr, type, stream);
438 /* Binary; 't' stands for "two". */
440 char bits[8*(sizeof val_long) + 1];
445 width = 8*(sizeof val_long);
462 error ("Undefined output size \"%c\".", size);
468 bits[width] = (val_long & 1) ? '1' : '0';
473 while (*cp && *cp == '0')
478 fprintf_filtered (stream, local_binary_format_prefix());
479 fprintf_filtered (stream, cp);
480 fprintf_filtered (stream, local_binary_format_suffix());
485 error ("Undefined output format \"%c\".", format);
489 /* Specify default address for `x' command.
490 `info lines' uses this. */
493 set_next_address (addr)
498 /* Make address available to the user as $_. */
499 set_internalvar (lookup_internalvar ("_"),
500 value_from_longest (lookup_pointer_type (builtin_type_void),
504 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
505 after LEADIN. Print nothing if no symbolic name is found nearby.
506 Optionally also print source file and line number, if available.
507 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
508 or to interpret it as a possible C++ name and convert it back to source
509 form. However note that DO_DEMANGLE can be overridden by the specific
510 settings of the demangle and asm_demangle variables. */
513 print_address_symbolic (addr, stream, do_demangle, leadin)
519 struct minimal_symbol *msymbol;
520 struct symbol *symbol;
521 struct symtab *symtab = 0;
522 CORE_ADDR name_location = 0;
524 asection *section = 0;
527 /* Determine if the address is in an overlay, and whether it is mapped. */
528 if (overlay_debugging)
530 section = find_pc_overlay (addr);
531 if (pc_in_unmapped_range (addr, section))
534 addr = overlay_mapped_address (addr, section);
538 /* On some targets, add in extra "flag" bits to PC for
539 disassembly. This should ensure that "rounding errors" in
540 symbol addresses that are masked for disassembly favour the
541 the correct symbol. */
543 #ifdef GDB_TARGET_UNMASK_DISAS_PC
544 addr = GDB_TARGET_UNMASK_DISAS_PC (addr);
547 /* First try to find the address in the symbol table, then
548 in the minsyms. Take the closest one. */
550 /* This is defective in the sense that it only finds text symbols. So
551 really this is kind of pointless--we should make sure that the
552 minimal symbols have everything we need (by changing that we could
553 save some memory, but for many debug format--ELF/DWARF or
554 anything/stabs--it would be inconvenient to eliminate those minimal
556 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
557 symbol = find_pc_sect_function (addr, section);
561 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
563 name = SYMBOL_SOURCE_NAME (symbol);
565 name = SYMBOL_LINKAGE_NAME (symbol);
570 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
572 /* The msymbol is closer to the address than the symbol;
573 use the msymbol instead. */
576 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
578 name = SYMBOL_SOURCE_NAME (msymbol);
580 name = SYMBOL_LINKAGE_NAME (msymbol);
583 if (symbol == NULL && msymbol == NULL)
586 /* On some targets, mask out extra "flag" bits from PC for handsome
589 #ifdef GDB_TARGET_MASK_DISAS_PC
590 name_location = GDB_TARGET_MASK_DISAS_PC (name_location);
591 addr = GDB_TARGET_MASK_DISAS_PC (addr);
594 /* If the nearest symbol is too far away, don't print anything symbolic. */
596 /* For when CORE_ADDR is larger than unsigned int, we do math in
597 CORE_ADDR. But when we detect unsigned wraparound in the
598 CORE_ADDR math, we ignore this test and print the offset,
599 because addr+max_symbolic_offset has wrapped through the end
600 of the address space back to the beginning, giving bogus comparison. */
601 if (addr > name_location + max_symbolic_offset
602 && name_location + max_symbolic_offset > name_location)
605 fputs_filtered (leadin, stream);
607 fputs_filtered ("<*", stream);
609 fputs_filtered ("<", stream);
610 fputs_filtered (name, stream);
611 if (addr != name_location)
612 fprintf_filtered (stream, "+%u", (unsigned int)(addr - name_location));
614 /* Append source filename and line number if desired. Give specific
615 line # of this addr, if we have it; else line # of the nearest symbol. */
616 if (print_symbol_filename)
618 struct symtab_and_line sal;
620 sal = find_pc_sect_line (addr, section, 0);
623 fprintf_filtered (stream, " at %s:%d", sal.symtab->filename, sal.line);
624 else if (symtab && symbol && symbol->line)
625 fprintf_filtered (stream, " at %s:%d", symtab->filename, symbol->line);
627 fprintf_filtered (stream, " in %s", symtab->filename);
630 fputs_filtered ("*>", stream);
632 fputs_filtered (">", stream);
635 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
638 print_address_numeric (addr, use_local, stream)
643 /* This assumes a CORE_ADDR can fit in a LONGEST. Probably a safe
645 print_longest (stream, 'x', use_local, (ULONGEST) addr);
648 /* Print address ADDR symbolically on STREAM.
649 First print it as a number. Then perhaps print
650 <SYMBOL + OFFSET> after the number. */
653 print_address (addr, stream)
657 print_address_numeric (addr, 1, stream);
658 print_address_symbolic (addr, stream, asm_demangle, " ");
661 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
662 controls whether to print the symbolic name "raw" or demangled.
663 Global setting "addressprint" controls whether to print hex address
667 print_address_demangle (addr, stream, do_demangle)
674 fprintf_filtered (stream, "0");
676 else if (addressprint)
678 print_address_numeric (addr, 1, stream);
679 print_address_symbolic (addr, stream, do_demangle, " ");
683 print_address_symbolic (addr, stream, do_demangle, "");
688 /* These are the types that $__ will get after an examine command of one
691 static struct type *examine_b_type;
692 static struct type *examine_h_type;
693 static struct type *examine_w_type;
694 static struct type *examine_g_type;
696 /* Examine data at address ADDR in format FMT.
697 Fetch it from memory and print on gdb_stdout. */
700 do_examine (fmt, addr, sect)
701 struct format_data fmt;
705 register char format = 0;
707 register int count = 1;
708 struct type *val_type = NULL;
710 register int maxelts;
718 /* String or instruction format implies fetch single bytes
719 regardless of the specified size. */
720 if (format == 's' || format == 'i')
724 val_type = examine_b_type;
725 else if (size == 'h')
726 val_type = examine_h_type;
727 else if (size == 'w')
728 val_type = examine_w_type;
729 else if (size == 'g')
730 val_type = examine_g_type;
737 if (format == 's' || format == 'i')
740 /* Print as many objects as specified in COUNT, at most maxelts per line,
741 with the address of the next one at the start of each line. */
746 print_address (next_address, gdb_stdout);
747 printf_filtered (":");
752 printf_filtered ("\t");
753 /* Note that print_formatted sets next_address for the next
755 last_examine_address = next_address;
756 last_examine_value = value_at (val_type, next_address, sect);
757 print_formatted (last_examine_value, format, size);
759 printf_filtered ("\n");
760 gdb_flush (gdb_stdout);
765 validate_format (fmt, cmdname)
766 struct format_data fmt;
770 error ("Size letters are meaningless in \"%s\" command.", cmdname);
772 error ("Item count other than 1 is meaningless in \"%s\" command.",
774 if (fmt.format == 'i' || fmt.format == 's')
775 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
776 fmt.format, cmdname);
779 /* Evaluate string EXP as an expression in the current language and
780 print the resulting value. EXP may contain a format specifier as the
781 first argument ("/x myvar" for example, to print myvar in hex).
785 print_command_1 (exp, inspect, voidprint)
790 struct expression *expr;
791 register struct cleanup *old_chain = 0;
792 register char format = 0;
793 register value_ptr val;
794 struct format_data fmt;
797 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
798 inspect_it = inspect;
800 if (exp && *exp == '/')
803 fmt = decode_format (&exp, last_format, 0);
804 validate_format (fmt, "print");
805 last_format = format = fmt.format;
816 extern int objectprint;
818 expr = parse_expression (exp);
819 old_chain = make_cleanup (free_current_contents, &expr);
821 val = evaluate_expression (expr);
823 /* C++: figure out what type we actually want to print it as. */
824 type = VALUE_TYPE (val);
827 && ( TYPE_CODE (type) == TYPE_CODE_PTR
828 || TYPE_CODE (type) == TYPE_CODE_REF)
829 && ( TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT
830 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION))
834 v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
838 type = VALUE_TYPE (val);
843 val = access_value_history (0);
845 if (voidprint || (val && VALUE_TYPE (val) &&
846 TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
848 int histindex = record_latest_value (val);
851 annotate_value_history_begin (histindex, VALUE_TYPE (val));
853 annotate_value_begin (VALUE_TYPE (val));
856 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
858 if (histindex >= 0) printf_filtered ("$%d = ", histindex);
861 annotate_value_history_value ();
863 print_formatted (val, format, fmt.size);
864 printf_filtered ("\n");
867 annotate_value_history_end ();
869 annotate_value_end ();
872 printf_unfiltered("\") )\030");
876 do_cleanups (old_chain);
877 inspect_it = 0; /* Reset print routines to normal */
882 print_command (exp, from_tty)
886 print_command_1 (exp, 0, 1);
889 /* Same as print, except in epoch, it gets its own window */
892 inspect_command (exp, from_tty)
896 extern int epoch_interface;
898 print_command_1 (exp, epoch_interface, 1);
901 /* Same as print, except it doesn't print void results. */
904 call_command (exp, from_tty)
908 print_command_1 (exp, 0, 0);
913 output_command (exp, from_tty)
917 struct expression *expr;
918 register struct cleanup *old_chain;
919 register char format = 0;
920 register value_ptr val;
921 struct format_data fmt;
923 if (exp && *exp == '/')
926 fmt = decode_format (&exp, 0, 0);
927 validate_format (fmt, "output");
931 expr = parse_expression (exp);
932 old_chain = make_cleanup (free_current_contents, &expr);
934 val = evaluate_expression (expr);
936 annotate_value_begin (VALUE_TYPE (val));
938 print_formatted (val, format, fmt.size);
940 annotate_value_end ();
942 do_cleanups (old_chain);
947 set_command (exp, from_tty)
951 struct expression *expr = parse_expression (exp);
952 register struct cleanup *old_chain
953 = make_cleanup (free_current_contents, &expr);
954 evaluate_expression (expr);
955 do_cleanups (old_chain);
960 sym_info (arg, from_tty)
964 struct minimal_symbol *msymbol;
965 struct objfile *objfile;
966 struct obj_section *osect;
968 CORE_ADDR addr, sect_addr;
973 error_no_arg ("address");
975 addr = parse_and_eval_address (arg);
976 ALL_OBJSECTIONS (objfile, osect)
978 sect = osect->the_bfd_section;
979 sect_addr = overlay_mapped_address (addr, sect);
981 if (osect->addr <= sect_addr && sect_addr < osect->endaddr &&
982 (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect)))
985 offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
987 printf_filtered ("%s + %u in ",
988 SYMBOL_SOURCE_NAME (msymbol), offset);
990 printf_filtered ("%s in ",
991 SYMBOL_SOURCE_NAME (msymbol));
992 if (pc_in_unmapped_range (addr, sect))
993 printf_filtered ("load address range of ");
994 if (section_is_overlay (sect))
995 printf_filtered ("%s overlay ",
996 section_is_mapped (sect) ? "mapped" : "unmapped");
997 printf_filtered ("section %s", sect->name);
998 printf_filtered ("\n");
1002 printf_filtered ("No symbol matches %s.\n", arg);
1007 address_info (exp, from_tty)
1011 register struct symbol *sym;
1012 register struct minimal_symbol *msymbol;
1014 register long basereg;
1016 CORE_ADDR load_addr;
1017 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
1018 if exp is a field of `this'. */
1021 error ("Argument required.");
1023 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
1024 &is_a_field_of_this, (struct symtab **)NULL);
1027 if (is_a_field_of_this)
1029 printf_filtered ("Symbol \"");
1030 fprintf_symbol_filtered (gdb_stdout, exp,
1031 current_language->la_language, DMGL_ANSI);
1032 printf_filtered ("\" is a field of the local class variable `this'\n");
1036 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1038 if (msymbol != NULL)
1040 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1042 printf_filtered ("Symbol \"");
1043 fprintf_symbol_filtered (gdb_stdout, exp,
1044 current_language->la_language, DMGL_ANSI);
1045 printf_filtered ("\" is at ");
1046 print_address_numeric (load_addr, 1, gdb_stdout);
1047 printf_filtered (" in a file compiled without debugging");
1048 section = SYMBOL_BFD_SECTION (msymbol);
1049 if (section_is_overlay (section))
1051 load_addr = overlay_unmapped_address (load_addr, section);
1052 printf_filtered (",\n -- loaded at ");
1053 print_address_numeric (load_addr, 1, gdb_stdout);
1054 printf_filtered (" in overlay section %s", section->name);
1056 printf_filtered (".\n");
1059 error ("No symbol \"%s\" in current context.", exp);
1063 printf_filtered ("Symbol \"");
1064 fprintf_symbol_filtered (gdb_stdout, SYMBOL_NAME (sym),
1065 current_language->la_language, DMGL_ANSI);
1066 printf_filtered ("\" is ");
1067 val = SYMBOL_VALUE (sym);
1068 basereg = SYMBOL_BASEREG (sym);
1069 section = SYMBOL_BFD_SECTION (sym);
1071 switch (SYMBOL_CLASS (sym))
1074 case LOC_CONST_BYTES:
1075 printf_filtered ("constant");
1079 printf_filtered ("a label at address ");
1080 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1082 if (section_is_overlay (section))
1084 load_addr = overlay_unmapped_address (load_addr, section);
1085 printf_filtered (",\n -- loaded at ");
1086 print_address_numeric (load_addr, 1, gdb_stdout);
1087 printf_filtered (" in overlay section %s", section->name);
1092 printf_filtered ("a variable in register %s", reg_names[val]);
1096 printf_filtered ("static storage at address ");
1097 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1099 if (section_is_overlay (section))
1101 load_addr = overlay_unmapped_address (load_addr, section);
1102 printf_filtered (",\n -- loaded at ");
1103 print_address_numeric (load_addr, 1, gdb_stdout);
1104 printf_filtered (" in overlay section %s", section->name);
1109 printf_filtered ("an argument in register %s", reg_names[val]);
1112 case LOC_REGPARM_ADDR:
1113 printf_filtered ("address of an argument in register %s", reg_names[val]);
1117 printf_filtered ("an argument at offset %ld", val);
1121 printf_filtered ("an argument at frame offset %ld", val);
1125 printf_filtered ("a local variable at frame offset %ld", val);
1129 printf_filtered ("a reference argument at offset %ld", val);
1133 printf_filtered ("a variable at offset %ld from register %s",
1134 val, reg_names[basereg]);
1137 case LOC_BASEREG_ARG:
1138 printf_filtered ("an argument at offset %ld from register %s",
1139 val, reg_names[basereg]);
1143 printf_filtered ("a typedef");
1147 printf_filtered ("a function at address ");
1148 #ifdef GDB_TARGET_MASK_DISAS_PC
1149 print_address_numeric
1150 (load_addr= GDB_TARGET_MASK_DISAS_PC (BLOCK_START (SYMBOL_BLOCK_VALUE (sym))),
1153 print_address_numeric (load_addr=BLOCK_START (SYMBOL_BLOCK_VALUE (sym)),
1156 if (section_is_overlay (section))
1158 load_addr = overlay_unmapped_address (load_addr, section);
1159 printf_filtered (",\n -- loaded at ");
1160 print_address_numeric (load_addr, 1, gdb_stdout);
1161 printf_filtered (" in overlay section %s", section->name);
1165 case LOC_UNRESOLVED:
1167 struct minimal_symbol *msym;
1169 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, NULL);
1171 printf_filtered ("unresolved");
1174 section = SYMBOL_BFD_SECTION (msym);
1175 printf_filtered ("static storage at address ");
1176 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (msym),
1178 if (section_is_overlay (section))
1180 load_addr = overlay_unmapped_address (load_addr, section);
1181 printf_filtered (",\n -- loaded at ");
1182 print_address_numeric (load_addr, 1, gdb_stdout);
1183 printf_filtered (" in overlay section %s", section->name);
1189 case LOC_OPTIMIZED_OUT:
1190 printf_filtered ("optimized out");
1194 printf_filtered ("of unknown (botched) type");
1197 printf_filtered (".\n");
1201 x_command (exp, from_tty)
1205 struct expression *expr;
1206 struct format_data fmt;
1207 struct cleanup *old_chain;
1210 fmt.format = last_format;
1211 fmt.size = last_size;
1214 if (exp && *exp == '/')
1217 fmt = decode_format (&exp, last_format, last_size);
1220 /* If we have an expression, evaluate it and use it as the address. */
1222 if (exp != 0 && *exp != 0)
1224 expr = parse_expression (exp);
1225 /* Cause expression not to be there any more
1226 if this command is repeated with Newline.
1227 But don't clobber a user-defined command's definition. */
1230 old_chain = make_cleanup (free_current_contents, &expr);
1231 val = evaluate_expression (expr);
1232 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
1233 val = value_ind (val);
1234 /* In rvalue contexts, such as this, functions are coerced into
1235 pointers to functions. This makes "x/i main" work. */
1236 if (/* last_format == 'i'
1237 && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
1238 && VALUE_LVAL (val) == lval_memory)
1239 next_address = VALUE_ADDRESS (val);
1241 next_address = value_as_pointer (val);
1242 if (VALUE_BFD_SECTION (val))
1243 next_section = VALUE_BFD_SECTION (val);
1244 do_cleanups (old_chain);
1247 do_examine (fmt, next_address, next_section);
1249 /* If the examine succeeds, we remember its size and format for next time. */
1250 last_size = fmt.size;
1251 last_format = fmt.format;
1253 /* Set a couple of internal variables if appropriate. */
1254 if (last_examine_value)
1256 /* Make last address examined available to the user as $_. Use
1257 the correct pointer type. */
1258 set_internalvar (lookup_internalvar ("_"),
1259 value_from_longest (
1260 lookup_pointer_type (VALUE_TYPE (last_examine_value)),
1261 (LONGEST) last_examine_address));
1263 /* Make contents of last address examined available to the user as $__.*/
1264 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1269 /* Add an expression to the auto-display chain.
1270 Specify the expression. */
1273 display_command (exp, from_tty)
1277 struct format_data fmt;
1278 register struct expression *expr;
1279 register struct display *new;
1290 fmt = decode_format (&exp, 0, 0);
1291 if (fmt.size && fmt.format == 0)
1293 if (fmt.format == 'i' || fmt.format == 's')
1303 innermost_block = 0;
1304 expr = parse_expression (exp);
1306 new = (struct display *) xmalloc (sizeof (struct display));
1309 new->block = innermost_block;
1310 new->next = display_chain;
1311 new->number = ++display_number;
1313 new->status = enabled;
1314 display_chain = new;
1316 if (from_tty && target_has_execution)
1317 do_one_display (new);
1330 /* Clear out the display_chain.
1331 Done when new symtabs are loaded, since this invalidates
1332 the types stored in many expressions. */
1337 register struct display *d;
1339 while ((d = display_chain) != NULL)
1342 display_chain = d->next;
1347 /* Delete the auto-display number NUM. */
1350 delete_display (num)
1353 register struct display *d1, *d;
1356 error ("No display number %d.", num);
1358 if (display_chain->number == num)
1361 display_chain = d1->next;
1365 for (d = display_chain; ; d = d->next)
1368 error ("No display number %d.", num);
1369 if (d->next->number == num)
1379 /* Delete some values from the auto-display chain.
1380 Specify the element numbers. */
1383 undisplay_command (args, from_tty)
1387 register char *p = args;
1393 if (query ("Delete all auto-display expressions? "))
1402 while (*p1 >= '0' && *p1 <= '9') p1++;
1403 if (*p1 && *p1 != ' ' && *p1 != '\t')
1404 error ("Arguments must be display numbers.");
1408 delete_display (num);
1411 while (*p == ' ' || *p == '\t') p++;
1416 /* Display a single auto-display.
1417 Do nothing if the display cannot be printed in the current context,
1418 or if the display is disabled. */
1424 int within_current_scope;
1426 if (d->status == disabled)
1430 within_current_scope = contained_in (get_selected_block (), d->block);
1432 within_current_scope = 1;
1433 if (!within_current_scope)
1436 current_display_number = d->number;
1438 annotate_display_begin ();
1439 printf_filtered ("%d", d->number);
1440 annotate_display_number_end ();
1441 printf_filtered (": ");
1447 annotate_display_format ();
1449 printf_filtered ("x/");
1450 if (d->format.count != 1)
1451 printf_filtered ("%d", d->format.count);
1452 printf_filtered ("%c", d->format.format);
1453 if (d->format.format != 'i' && d->format.format != 's')
1454 printf_filtered ("%c", d->format.size);
1455 printf_filtered (" ");
1457 annotate_display_expression ();
1459 print_expression (d->exp, gdb_stdout);
1460 annotate_display_expression_end ();
1462 if (d->format.count != 1)
1463 printf_filtered ("\n");
1465 printf_filtered (" ");
1467 val = evaluate_expression (d->exp);
1468 addr = value_as_pointer (val);
1469 if (d->format.format == 'i')
1470 addr = ADDR_BITS_REMOVE (addr);
1472 annotate_display_value ();
1474 do_examine (d->format, addr, VALUE_BFD_SECTION (val));
1478 annotate_display_format ();
1480 if (d->format.format)
1481 printf_filtered ("/%c ", d->format.format);
1483 annotate_display_expression ();
1485 print_expression (d->exp, gdb_stdout);
1486 annotate_display_expression_end ();
1488 printf_filtered (" = ");
1490 annotate_display_expression ();
1492 print_formatted (evaluate_expression (d->exp),
1493 d->format.format, d->format.size);
1494 printf_filtered ("\n");
1497 annotate_display_end ();
1499 gdb_flush (gdb_stdout);
1500 current_display_number = -1;
1503 /* Display all of the values on the auto-display chain which can be
1504 evaluated in the current scope. */
1509 register struct display *d;
1511 for (d = display_chain; d; d = d->next)
1515 /* Delete the auto-display which we were in the process of displaying.
1516 This is done when there is an error or a signal. */
1519 disable_display (num)
1522 register struct display *d;
1524 for (d = display_chain; d; d = d->next)
1525 if (d->number == num)
1527 d->status = disabled;
1530 printf_unfiltered ("No display number %d.\n", num);
1534 disable_current_display ()
1536 if (current_display_number >= 0)
1538 disable_display (current_display_number);
1539 fprintf_unfiltered (gdb_stderr, "Disabling display %d to avoid infinite recursion.\n",
1540 current_display_number);
1542 current_display_number = -1;
1546 display_info (ignore, from_tty)
1550 register struct display *d;
1553 printf_unfiltered ("There are no auto-display expressions now.\n");
1555 printf_filtered ("Auto-display expressions now in effect:\n\
1556 Num Enb Expression\n");
1558 for (d = display_chain; d; d = d->next)
1560 printf_filtered ("%d: %c ", d->number, "ny"[(int)d->status]);
1562 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1564 else if (d->format.format)
1565 printf_filtered ("/%c ", d->format.format);
1566 print_expression (d->exp, gdb_stdout);
1567 if (d->block && !contained_in (get_selected_block (), d->block))
1568 printf_filtered (" (cannot be evaluated in the current context)");
1569 printf_filtered ("\n");
1570 gdb_flush (gdb_stdout);
1575 enable_display (args, from_tty)
1579 register char *p = args;
1582 register struct display *d;
1586 for (d = display_chain; d; d = d->next)
1587 d->status = enabled;
1593 while (*p1 >= '0' && *p1 <= '9')
1595 if (*p1 && *p1 != ' ' && *p1 != '\t')
1596 error ("Arguments must be display numbers.");
1600 for (d = display_chain; d; d = d->next)
1601 if (d->number == num)
1603 d->status = enabled;
1606 printf_unfiltered ("No display number %d.\n", num);
1609 while (*p == ' ' || *p == '\t')
1616 disable_display_command (args, from_tty)
1620 register char *p = args;
1622 register struct display *d;
1626 for (d = display_chain; d; d = d->next)
1627 d->status = disabled;
1633 while (*p1 >= '0' && *p1 <= '9')
1635 if (*p1 && *p1 != ' ' && *p1 != '\t')
1636 error ("Arguments must be display numbers.");
1638 disable_display (atoi (p));
1641 while (*p == ' ' || *p == '\t')
1647 /* Print the value in stack frame FRAME of a variable
1648 specified by a struct symbol. */
1651 print_variable_value (var, frame, stream)
1653 struct frame_info *frame;
1656 value_ptr val = read_var_value (var, frame);
1658 value_print (val, stream, 0, Val_pretty_default);
1661 /* Print the arguments of a stack frame, given the function FUNC
1662 running in that frame (as a symbol), the info on the frame,
1663 and the number of args according to the stack frame (or -1 if unknown). */
1665 /* References here and elsewhere to "number of args according to the
1666 stack frame" appear in all cases to refer to "number of ints of args
1667 according to the stack frame". At least for VAX, i386, isi. */
1670 print_frame_args (func, fi, num, stream)
1671 struct symbol *func;
1672 struct frame_info *fi;
1676 struct block *b = NULL;
1680 register struct symbol *sym;
1681 register value_ptr val;
1682 /* Offset of next stack argument beyond the one we have seen that is
1683 at the highest offset.
1684 -1 if we haven't come to a stack argument yet. */
1685 long highest_offset = -1;
1687 /* Number of ints of arguments that we have printed so far. */
1688 int args_printed = 0;
1692 b = SYMBOL_BLOCK_VALUE (func);
1693 nsyms = BLOCK_NSYMS (b);
1696 for (i = 0; i < nsyms; i++)
1699 sym = BLOCK_SYM (b, i);
1701 /* Keep track of the highest stack argument offset seen, and
1702 skip over any kinds of symbols we don't care about. */
1704 switch (SYMBOL_CLASS (sym)) {
1708 long current_offset = SYMBOL_VALUE (sym);
1709 arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1711 /* Compute address of next argument by adding the size of
1712 this argument and rounding to an int boundary. */
1714 = ((current_offset + arg_size + sizeof (int) - 1)
1715 & ~(sizeof (int) - 1));
1717 /* If this is the highest offset seen yet, set highest_offset. */
1718 if (highest_offset == -1
1719 || (current_offset > highest_offset))
1720 highest_offset = current_offset;
1722 /* Add the number of ints we're about to print to args_printed. */
1723 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
1726 /* We care about types of symbols, but don't need to keep track of
1727 stack offsets in them. */
1729 case LOC_REGPARM_ADDR:
1731 case LOC_BASEREG_ARG:
1734 /* Other types of symbols we just skip over. */
1739 /* We have to look up the symbol because arguments can have
1740 two entries (one a parameter, one a local) and the one we
1741 want is the local, which lookup_symbol will find for us.
1742 This includes gcc1 (not gcc2) on the sparc when passing a
1743 small structure and gcc2 when the argument type is float
1744 and it is passed as a double and converted to float by
1745 the prologue (in the latter case the type of the LOC_ARG
1746 symbol is double and the type of the LOC_LOCAL symbol is
1748 /* But if the parameter name is null, don't try it.
1749 Null parameter names occur on the RS/6000, for traceback tables.
1750 FIXME, should we even print them? */
1752 if (*SYMBOL_NAME (sym))
1754 struct symbol *nsym;
1755 nsym = lookup_symbol
1757 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
1758 if (SYMBOL_CLASS (nsym) == LOC_REGISTER)
1760 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
1761 it was passed on the stack and loaded into a register,
1762 or passed in a register and stored in a stack slot.
1763 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
1765 Reasons for using the LOC_ARG:
1766 (1) because find_saved_registers may be slow for remote
1768 (2) because registers are often re-used and stack slots
1769 rarely (never?) are. Therefore using the stack slot is
1770 much less likely to print garbage.
1772 Reasons why we might want to use the LOC_REGISTER:
1773 (1) So that the backtrace prints the same value as
1774 "print foo". I see no compelling reason why this needs
1775 to be the case; having the backtrace print the value which
1776 was passed in, and "print foo" print the value as modified
1777 within the called function, makes perfect sense to me.
1779 Additional note: It might be nice if "info args" displayed
1781 One more note: There is a case with sparc structure passing
1782 where we need to use the LOC_REGISTER, but this is dealt with
1783 by creating a single LOC_REGPARM in symbol reading. */
1785 /* Leave sym (the LOC_ARG) alone. */
1792 /* Print the current arg. */
1794 fprintf_filtered (stream, ", ");
1797 annotate_arg_begin ();
1799 fprintf_symbol_filtered (stream, SYMBOL_SOURCE_NAME (sym),
1800 SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
1801 annotate_arg_name_end ();
1802 fputs_filtered ("=", stream);
1804 /* Avoid value_print because it will deref ref parameters. We just
1805 want to print their addresses. Print ??? for args whose address
1806 we do not know. We pass 2 as "recurse" to val_print because our
1807 standard indentation here is 4 spaces, and val_print indents
1808 2 for each recurse. */
1809 val = read_var_value (sym, fi);
1811 annotate_arg_value (val == NULL ? NULL : VALUE_TYPE (val));
1815 #ifdef GDB_TARGET_IS_D10V
1816 if (SYMBOL_CLASS(sym) == LOC_REGPARM && TYPE_CODE(VALUE_TYPE(val)) == TYPE_CODE_PTR)
1817 TYPE_LENGTH(VALUE_TYPE(val)) = 2;
1819 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val),
1820 stream, 0, 0, 2, Val_no_prettyprint);
1823 fputs_filtered ("???", stream);
1825 annotate_arg_end ();
1830 /* Don't print nameless args in situations where we don't know
1831 enough about the stack to find them. */
1836 if (highest_offset == -1)
1837 start = FRAME_ARGS_SKIP;
1839 start = highest_offset;
1841 print_frame_nameless_args (fi, start, num - args_printed,
1846 /* Print nameless args on STREAM.
1847 FI is the frameinfo for this frame, START is the offset
1848 of the first nameless arg, and NUM is the number of nameless args to
1849 print. FIRST is nonzero if this is the first argument (not just
1850 the first nameless arg). */
1853 print_frame_nameless_args (fi, start, num, first, stream)
1854 struct frame_info *fi;
1864 for (i = 0; i < num; i++)
1867 #ifdef NAMELESS_ARG_VALUE
1868 NAMELESS_ARG_VALUE (fi, start, &arg_value);
1870 argsaddr = FRAME_ARGS_ADDRESS (fi);
1874 arg_value = read_memory_integer (argsaddr + start, sizeof (int));
1878 fprintf_filtered (stream, ", ");
1880 #ifdef PRINT_NAMELESS_INTEGER
1881 PRINT_NAMELESS_INTEGER (stream, arg_value);
1883 #ifdef PRINT_TYPELESS_INTEGER
1884 PRINT_TYPELESS_INTEGER (stream, builtin_type_int, (LONGEST) arg_value);
1886 fprintf_filtered (stream, "%ld", arg_value);
1887 #endif /* PRINT_TYPELESS_INTEGER */
1888 #endif /* PRINT_NAMELESS_INTEGER */
1890 start += sizeof (int);
1896 printf_command (arg, from_tty)
1901 register char *s = arg;
1903 value_ptr *val_args;
1905 char *current_substring;
1907 int allocated_args = 20;
1908 struct cleanup *old_cleanups;
1910 val_args = (value_ptr *) xmalloc (allocated_args * sizeof (value_ptr));
1911 old_cleanups = make_cleanup (free_current_contents, &val_args);
1914 error_no_arg ("format-control string and values to print");
1916 /* Skip white space before format string */
1917 while (*s == ' ' || *s == '\t') s++;
1919 /* A format string should follow, enveloped in double quotes */
1921 error ("Bad format string, missing '\"'.");
1923 /* Parse the format-control string and copy it into the string STRING,
1924 processing some kinds of escape sequence. */
1926 f = string = (char *) alloca (strlen (s) + 1);
1934 error ("Bad format string, non-terminated '\"'.");
1946 *f++ = '\007'; /* Bell */
1971 /* ??? TODO: handle other escape sequences */
1972 error ("Unrecognized escape character \\%c in format string.",
1982 /* Skip over " and following space and comma. */
1985 while (*s == ' ' || *s == '\t') s++;
1987 if (*s != ',' && *s != 0)
1988 error ("Invalid argument syntax");
1991 while (*s == ' ' || *s == '\t') s++;
1993 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1994 substrings = alloca (strlen (string) * 2);
1995 current_substring = substrings;
1998 /* Now scan the string for %-specs and see what kinds of args they want.
1999 argclass[I] classifies the %-specs so we can give printf_filtered
2000 something of the right size. */
2002 enum argclass {no_arg, int_arg, string_arg, double_arg, long_long_arg};
2003 enum argclass *argclass;
2004 enum argclass this_argclass;
2010 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
2018 while (strchr ("0123456789.hlL-+ #", *f))
2020 if (*f == 'l' || *f == 'L')
2027 this_argclass = string_arg;
2033 this_argclass = double_arg;
2037 error ("`*' not supported for precision or width in printf");
2040 error ("Format specifier `n' not supported in printf");
2043 this_argclass = no_arg;
2048 this_argclass = long_long_arg;
2050 this_argclass = int_arg;
2054 if (this_argclass != no_arg)
2056 strncpy (current_substring, last_arg, f - last_arg);
2057 current_substring += f - last_arg;
2058 *current_substring++ = '\0';
2060 argclass[nargs_wanted++] = this_argclass;
2064 /* Now, parse all arguments and evaluate them.
2065 Store the VALUEs in VAL_ARGS. */
2070 if (nargs == allocated_args)
2071 val_args = (value_ptr *) xrealloc ((char *) val_args,
2072 (allocated_args *= 2)
2073 * sizeof (value_ptr));
2075 val_args[nargs] = parse_to_comma_and_eval (&s1);
2077 /* If format string wants a float, unchecked-convert the value to
2078 floating point of the same size */
2080 if (argclass[nargs] == double_arg)
2082 struct type *type = VALUE_TYPE (val_args[nargs]);
2083 if (TYPE_LENGTH (type) == sizeof (float))
2084 VALUE_TYPE (val_args[nargs]) = builtin_type_float;
2085 if (TYPE_LENGTH (type) == sizeof (double))
2086 VALUE_TYPE (val_args[nargs]) = builtin_type_double;
2094 if (nargs != nargs_wanted)
2095 error ("Wrong number of arguments for specified format-string");
2097 /* Now actually print them. */
2098 current_substring = substrings;
2099 for (i = 0; i < nargs; i++)
2101 switch (argclass[i])
2108 tem = value_as_pointer (val_args[i]);
2110 /* This is a %s argument. Find the length of the string. */
2115 read_memory_section (tem + j, &c, 1,
2116 VALUE_BFD_SECTION (val_args[i]));
2121 /* Copy the string contents into a string inside GDB. */
2122 str = (char *) alloca (j + 1);
2123 read_memory_section (tem, str, j, VALUE_BFD_SECTION (val_args[i]));
2126 printf_filtered (current_substring, str);
2131 double val = value_as_double (val_args[i]);
2132 printf_filtered (current_substring, val);
2136 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2138 long long val = value_as_long (val_args[i]);
2139 printf_filtered (current_substring, val);
2143 error ("long long not supported in printf");
2147 /* FIXME: there should be separate int_arg and long_arg. */
2148 long val = value_as_long (val_args[i]);
2149 printf_filtered (current_substring, val);
2153 error ("internal error in printf_command");
2155 /* Skip to the next substring. */
2156 current_substring += strlen (current_substring) + 1;
2158 /* Print the portion of the format string after the last argument. */
2159 printf_filtered (last_arg);
2161 do_cleanups (old_cleanups);
2164 /* Dump a specified section of assembly code. With no command line
2165 arguments, this command will dump the assembly code for the
2166 function surrounding the pc value in the selected frame. With one
2167 argument, it will dump the assembly code surrounding that pc value.
2168 Two arguments are interpeted as bounds within which to dump
2173 disassemble_command (arg, from_tty)
2177 CORE_ADDR low, high;
2179 CORE_ADDR pc, pc_masked;
2186 if (!selected_frame)
2187 error ("No frame selected.\n");
2189 pc = get_frame_pc (selected_frame);
2190 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
2191 error ("No function contains program counter for selected frame.\n");
2192 low += FUNCTION_START_OFFSET;
2195 else if (!(space_index = (char *) strchr (arg, ' ')))
2198 pc = parse_and_eval_address (arg);
2199 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
2200 error ("No function contains specified address.\n");
2201 low += FUNCTION_START_OFFSET;
2203 if (overlay_debugging)
2205 section = find_pc_overlay (pc);
2206 if (pc_in_unmapped_range (pc, section))
2208 /* find_pc_partial_function will have returned low and high
2209 relative to the symbolic (mapped) address range. Need to
2210 translate them back to the unmapped range where PC is. */
2212 low = overlay_unmapped_address (low, section);
2213 high = overlay_unmapped_address (high, section);
2219 /* Two arguments. */
2220 *space_index = '\0';
2221 low = parse_and_eval_address (arg);
2222 high = parse_and_eval_address (space_index + 1);
2226 printf_filtered ("Dump of assembler code ");
2229 printf_filtered ("for function %s:\n", name);
2233 printf_filtered ("from ");
2234 print_address_numeric (low, 1, gdb_stdout);
2235 printf_filtered (" to ");
2236 print_address_numeric (high, 1, gdb_stdout);
2237 printf_filtered (":\n");
2240 /* Dump the specified range. */
2243 #ifdef GDB_TARGET_MASK_DISAS_PC
2244 pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
2249 while (pc_masked <= high)
2252 print_address (pc_masked, gdb_stdout);
2253 printf_filtered (":\t");
2254 /* We often wrap here if there are long symbolic names. */
2256 pc += print_insn (pc, gdb_stdout);
2257 printf_filtered ("\n");
2259 #ifdef GDB_TARGET_MASK_DISAS_PC
2260 pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
2265 printf_filtered ("End of assembler dump.\n");
2266 gdb_flush (gdb_stdout);
2269 /* Print the instruction at address MEMADDR in debugged memory,
2270 on STREAM. Returns length of the instruction, in bytes. */
2273 print_insn (memaddr, stream)
2277 /* If there's no disassembler, something is very wrong. */
2278 if (tm_print_insn == NULL)
2281 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2282 tm_print_insn_info.endian = BFD_ENDIAN_BIG;
2284 tm_print_insn_info.endian = BFD_ENDIAN_LITTLE;
2286 if (target_architecture != NULL)
2287 tm_print_insn_info.mach = target_architecture->mach;
2288 /* else: should set .mach=0 but some disassemblers don't grok this */
2290 return (*tm_print_insn) (memaddr, &tm_print_insn_info);
2295 _initialize_printcmd ()
2297 current_display_number = -1;
2299 add_info ("address", address_info,
2300 "Describe where symbol SYM is stored.");
2302 add_info ("symbol", sym_info,
2303 "Describe what symbol is at location ADDR.\n\
2304 Only for symbols with fixed locations (global or static scope).");
2306 add_com ("x", class_vars, x_command,
2307 concat ("Examine memory: x/FMT ADDRESS.\n\
2308 ADDRESS is an expression for the memory address to examine.\n\
2309 FMT is a repeat count followed by a format letter and a size letter.\n\
2310 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2311 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n",
2312 "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2313 The specified number of objects of the specified size are printed\n\
2314 according to the format.\n\n\
2315 Defaults for format and size letters are those previously used.\n\
2316 Default count is 1. Default address is following last thing printed\n\
2317 with this command or \"print\".", NULL));
2319 add_com ("disassemble", class_vars, disassemble_command,
2320 "Disassemble a specified section of memory.\n\
2321 Default is the function surrounding the pc of the selected frame.\n\
2322 With a single argument, the function surrounding that address is dumped.\n\
2323 Two arguments are taken as a range of memory to dump.");
2326 add_com ("whereis", class_vars, whereis_command,
2327 "Print line number and file of definition of variable.");
2330 add_info ("display", display_info,
2331 "Expressions to display when program stops, with code numbers.");
2333 add_cmd ("undisplay", class_vars, undisplay_command,
2334 "Cancel some expressions to be displayed when program stops.\n\
2335 Arguments are the code numbers of the expressions to stop displaying.\n\
2336 No argument means cancel all automatic-display expressions.\n\
2337 \"delete display\" has the same effect as this command.\n\
2338 Do \"info display\" to see current list of code numbers.",
2341 add_com ("display", class_vars, display_command,
2342 "Print value of expression EXP each time the program stops.\n\
2343 /FMT may be used before EXP as in the \"print\" command.\n\
2344 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2345 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2346 and examining is done as in the \"x\" command.\n\n\
2347 With no argument, display all currently requested auto-display expressions.\n\
2348 Use \"undisplay\" to cancel display requests previously made."
2351 add_cmd ("display", class_vars, enable_display,
2352 "Enable some expressions to be displayed when program stops.\n\
2353 Arguments are the code numbers of the expressions to resume displaying.\n\
2354 No argument means enable all automatic-display expressions.\n\
2355 Do \"info display\" to see current list of code numbers.", &enablelist);
2357 add_cmd ("display", class_vars, disable_display_command,
2358 "Disable some expressions to be displayed when program stops.\n\
2359 Arguments are the code numbers of the expressions to stop displaying.\n\
2360 No argument means disable all automatic-display expressions.\n\
2361 Do \"info display\" to see current list of code numbers.", &disablelist);
2363 add_cmd ("display", class_vars, undisplay_command,
2364 "Cancel some expressions to be displayed when program stops.\n\
2365 Arguments are the code numbers of the expressions to stop displaying.\n\
2366 No argument means cancel all automatic-display expressions.\n\
2367 Do \"info display\" to see current list of code numbers.", &deletelist);
2369 add_com ("printf", class_vars, printf_command,
2370 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2371 This is useful for formatted output in user-defined commands.");
2373 add_com ("output", class_vars, output_command,
2374 "Like \"print\" but don't put in value history and don't print newline.\n\
2375 This is useful in user-defined commands.");
2377 add_prefix_cmd ("set", class_vars, set_command,
2378 concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2379 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2380 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2381 with $), a register (a few standard names starting with $), or an actual\n\
2382 variable in the program being debugged. EXP is any valid expression.\n",
2383 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2384 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2385 You can see these environment settings with the \"show\" command.", NULL),
2386 &setlist, "set ", 1, &cmdlist);
2388 /* "call" is the same as "set", but handy for dbx users to call fns. */
2389 add_com ("call", class_vars, call_command,
2390 "Call a function in the program.\n\
2391 The argument is the function name and arguments, in the notation of the\n\
2392 current working language. The result is printed and saved in the value\n\
2393 history, if it is not void.");
2395 add_cmd ("variable", class_vars, set_command,
2396 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2397 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2398 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2399 with $), a register (a few standard names starting with $), or an actual\n\
2400 variable in the program being debugged. EXP is any valid expression.\n\
2401 This may usually be abbreviated to simply \"set\".",
2404 add_com ("print", class_vars, print_command,
2405 concat ("Print value of expression EXP.\n\
2406 Variables accessible are those of the lexical environment of the selected\n\
2407 stack frame, plus all those whose scope is global or an entire file.\n\
2409 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2410 $$NUM refers to NUM'th value back from the last one.\n\
2411 Names starting with $ refer to registers (with the values they would have\n",
2412 "if the program were to return to the stack frame now selected, restoring\n\
2413 all registers saved by frames farther in) or else to debugger\n\
2414 \"convenience\" variables (any such name not a known register).\n\
2415 Use assignment expressions to give values to convenience variables.\n",
2417 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2418 @ is a binary operator for treating consecutive data objects\n\
2419 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2420 element is FOO, whose second element is stored in the space following\n\
2421 where FOO is stored, etc. FOO must be an expression whose value\n\
2422 resides in memory.\n",
2424 EXP may be preceded with /FMT, where FMT is a format letter\n\
2425 but no count or size letter (see \"x\" command).", NULL));
2426 add_com_alias ("p", "print", class_vars, 1);
2428 add_com ("inspect", class_vars, inspect_command,
2429 "Same as \"print\" command, except that if you are running in the epoch\n\
2430 environment, the value is printed in its own window.");
2433 add_set_cmd ("max-symbolic-offset", no_class, var_uinteger,
2434 (char *)&max_symbolic_offset,
2435 "Set the largest offset that will be printed in <symbol+1234> form.",
2439 add_set_cmd ("symbol-filename", no_class, var_boolean,
2440 (char *)&print_symbol_filename,
2441 "Set printing of source filename and line number with <symbol>.",
2445 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2446 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2447 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2448 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);
2450 INIT_DISASSEMBLE_INFO_NO_ARCH (tm_print_insn_info, gdb_stdout, (fprintf_ftype)fprintf_filtered);
2451 tm_print_insn_info.flavour = bfd_target_unknown_flavour;
2452 tm_print_insn_info.read_memory_func = dis_asm_read_memory;
2453 tm_print_insn_info.memory_error_func = dis_asm_memory_error;
2454 tm_print_insn_info.print_address_func = dis_asm_print_address;