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 /* Prototypes for local functions. */
126 static void delete_display PARAMS ((int));
128 static void enable_display PARAMS ((char *, int));
130 static void disable_display_command PARAMS ((char *, int));
132 static void disassemble_command PARAMS ((char *, int));
134 static void printf_command PARAMS ((char *, int));
136 static void print_frame_nameless_args PARAMS ((struct frame_info *, long,
137 int, int, GDB_FILE *));
139 static void display_info PARAMS ((char *, int));
141 static void do_one_display PARAMS ((struct display *));
143 static void undisplay_command PARAMS ((char *, int));
145 static void free_display PARAMS ((struct display *));
147 static void display_command PARAMS ((char *, int));
149 static void x_command PARAMS ((char *, int));
151 static void address_info PARAMS ((char *, int));
153 static void set_command PARAMS ((char *, int));
155 static void output_command PARAMS ((char *, int));
157 static void call_command PARAMS ((char *, int));
159 static void inspect_command PARAMS ((char *, int));
161 static void print_command PARAMS ((char *, int));
163 static void print_command_1 PARAMS ((char *, int, int));
165 static void validate_format PARAMS ((struct format_data, char *));
167 static void do_examine PARAMS ((struct format_data, CORE_ADDR addr, asection *section));
169 static void print_formatted PARAMS ((value_ptr, int, int));
171 static struct format_data decode_format PARAMS ((char **, int, int));
173 static int print_insn PARAMS ((CORE_ADDR, GDB_FILE *));
176 /* Decode a format specification. *STRING_PTR should point to it.
177 OFORMAT and OSIZE are used as defaults for the format and size
178 if none are given in the format specification.
179 If OSIZE is zero, then the size field of the returned value
180 should be set only if a size is explicitly specified by the
182 The structure returned describes all the data
183 found in the specification. In addition, *STRING_PTR is advanced
184 past the specification and past all whitespace following it. */
186 static struct format_data
187 decode_format (string_ptr, oformat, osize)
192 struct format_data val;
193 register char *p = *string_ptr;
199 if (*p >= '0' && *p <= '9')
200 val.count = atoi (p);
201 while (*p >= '0' && *p <= '9') p++;
203 /* Now process size or format letters that follow. */
207 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
209 else if (*p >= 'a' && *p <= 'z')
215 while (*p == ' ' || *p == '\t') p++;
218 /* Set defaults for format and size if not specified. */
219 if (val.format == '?')
223 /* Neither has been specified. */
224 val.format = oformat;
228 /* If a size is specified, any format makes a reasonable
229 default except 'i'. */
230 val.format = oformat == 'i' ? 'x' : oformat;
232 else if (val.size == '?')
237 /* Pick the appropriate size for an address. */
238 if (TARGET_PTR_BIT == 64)
239 val.size = osize ? 'g' : osize;
240 else if (TARGET_PTR_BIT == 32)
241 val.size = osize ? 'w' : osize;
242 else if (TARGET_PTR_BIT == 16)
243 val.size = osize ? 'h' : osize;
245 /* Bad value for TARGET_PTR_BIT */
249 /* Floating point has to be word or giantword. */
250 if (osize == 'w' || osize == 'g')
253 /* Default it to giantword if the last used size is not
255 val.size = osize ? 'g' : osize;
258 /* Characters default to one byte. */
259 val.size = osize ? 'b' : osize;
262 /* The default is the size most recently specified. */
269 /* Print value VAL on gdb_stdout according to FORMAT, a letter or 0.
270 Do not end with a newline.
271 0 means print VAL according to its own type.
272 SIZE is the letter for the size of datum being printed.
273 This is used to pad hex numbers so they line up. */
276 print_formatted (val, format, size)
277 register value_ptr val;
281 struct type *type = check_typedef (VALUE_TYPE (val));
282 int len = TYPE_LENGTH (type);
284 if (VALUE_LVAL (val) == lval_memory)
286 next_address = VALUE_ADDRESS (val) + len;
287 next_section = VALUE_BFD_SECTION (val);
293 next_address = VALUE_ADDRESS (val)
294 + val_print_string (VALUE_ADDRESS (val), 0, gdb_stdout);
295 next_section = VALUE_BFD_SECTION (val);
299 /* The old comment says
300 "Force output out, print_insn not using _filtered".
301 I'm not completely sure what that means, I suspect most print_insn
302 now do use _filtered, so I guess it's obsolete. */
303 /* We often wrap here if there are long symbolic names. */
305 next_address = VALUE_ADDRESS (val)
306 + print_insn (VALUE_ADDRESS (val), gdb_stdout);
307 next_section = VALUE_BFD_SECTION (val);
312 || TYPE_CODE (type) == TYPE_CODE_ARRAY
313 || TYPE_CODE (type) == TYPE_CODE_STRING
314 || TYPE_CODE (type) == TYPE_CODE_STRUCT
315 || TYPE_CODE (type) == TYPE_CODE_UNION)
316 value_print (val, gdb_stdout, format, Val_pretty_default);
318 print_scalar_formatted (VALUE_CONTENTS (val), type,
319 format, size, gdb_stdout);
323 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
324 according to letters FORMAT and SIZE on STREAM.
325 FORMAT may not be zero. Formats s and i are not supported at this level.
327 This is how the elements of an array or structure are printed
331 print_scalar_formatted (valaddr, type, format, size, stream)
339 unsigned int len = TYPE_LENGTH (type);
341 if (len > sizeof (LONGEST)
349 if (! TYPE_UNSIGNED (type)
350 || ! extract_long_unsigned_integer (valaddr, len, &val_long))
352 /* We can't print it normally, but we can print it in hex.
353 Printing it in the wrong radix is more useful than saying
354 "use /x, you dummy". */
355 /* FIXME: we could also do octal or binary if that was the
357 /* FIXME: we should be using the size field to give us a
358 minimum field width to print. */
359 val_print_type_code_int (type, valaddr, stream);
363 /* If we get here, extract_long_unsigned_integer set val_long. */
365 else if (format != 'f')
366 val_long = unpack_long (type, valaddr);
368 /* If we are printing it as unsigned, truncate it in case it is actually
369 a negative signed value (e.g. "print/u (short)-1" should print 65535
370 (if shorts are 16 bits) instead of 4294967295). */
373 if (len < sizeof (LONGEST))
374 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
382 /* no size specified, like in print. Print varying # of digits. */
383 print_longest (stream, 'x', 1, val_long);
392 print_longest (stream, size, 1, val_long);
395 error ("Undefined output size \"%c\".", size);
400 print_longest (stream, 'd', 1, val_long);
404 print_longest (stream, 'u', 0, val_long);
409 print_longest (stream, 'o', 1, val_long);
411 fprintf_filtered (stream, "0");
415 print_address (unpack_pointer (type, valaddr), stream);
419 value_print (value_from_longest (builtin_type_char, val_long), stream, 0,
424 if (len == sizeof (float))
425 type = builtin_type_float;
426 else if (len == sizeof (double))
427 type = builtin_type_double;
428 print_floating (valaddr, type, stream);
435 /* Binary; 't' stands for "two". */
437 char bits[8*(sizeof val_long) + 1];
442 width = 8*(sizeof val_long);
459 error ("Undefined output size \"%c\".", size);
465 bits[width] = (val_long & 1) ? '1' : '0';
470 while (*cp && *cp == '0')
475 fprintf_filtered (stream, local_binary_format_prefix());
476 fprintf_filtered (stream, cp);
477 fprintf_filtered (stream, local_binary_format_suffix());
482 error ("Undefined output format \"%c\".", format);
486 /* Specify default address for `x' command.
487 `info lines' uses this. */
490 set_next_address (addr)
495 /* Make address available to the user as $_. */
496 set_internalvar (lookup_internalvar ("_"),
497 value_from_longest (lookup_pointer_type (builtin_type_void),
501 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
502 after LEADIN. Print nothing if no symbolic name is found nearby.
503 Optionally also print source file and line number, if available.
504 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
505 or to interpret it as a possible C++ name and convert it back to source
506 form. However note that DO_DEMANGLE can be overridden by the specific
507 settings of the demangle and asm_demangle variables. */
510 print_address_symbolic (addr, stream, do_demangle, leadin)
516 struct minimal_symbol *msymbol;
517 struct symbol *symbol;
518 struct symtab *symtab = 0;
519 CORE_ADDR name_location = 0;
521 asection *section = 0;
524 /* Determine if the address is in an overlay, and whether it is mapped. */
525 if (overlay_debugging)
527 section = find_pc_overlay (addr);
528 if (pc_in_unmapped_range (addr, section))
531 addr = overlay_mapped_address (addr, section);
535 /* On some targets, add in extra "flag" bits to PC for
536 disassembly. This should ensure that "rounding errors" in
537 symbol addresses that are masked for disassembly favour the
538 the correct symbol. */
540 #ifdef GDB_TARGET_UNMASK_DISAS_PC
541 addr = GDB_TARGET_UNMASK_DISAS_PC (addr);
544 /* First try to find the address in the symbol table, then
545 in the minsyms. Take the closest one. */
547 /* This is defective in the sense that it only finds text symbols. So
548 really this is kind of pointless--we should make sure that the
549 minimal symbols have everything we need (by changing that we could
550 save some memory, but for many debug format--ELF/DWARF or
551 anything/stabs--it would be inconvenient to eliminate those minimal
553 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
554 symbol = find_pc_sect_function (addr, section);
558 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
560 name = SYMBOL_SOURCE_NAME (symbol);
562 name = SYMBOL_LINKAGE_NAME (symbol);
567 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
569 /* The msymbol is closer to the address than the symbol;
570 use the msymbol instead. */
573 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
575 name = SYMBOL_SOURCE_NAME (msymbol);
577 name = SYMBOL_LINKAGE_NAME (msymbol);
580 if (symbol == NULL && msymbol == NULL)
583 /* On some targets, mask out extra "flag" bits from PC for handsome
586 #ifdef GDB_TARGET_MASK_DISAS_PC
587 name_location = GDB_TARGET_MASK_DISAS_PC (name_location);
588 addr = GDB_TARGET_MASK_DISAS_PC (addr);
591 /* If the nearest symbol is too far away, don't print anything symbolic. */
593 /* For when CORE_ADDR is larger than unsigned int, we do math in
594 CORE_ADDR. But when we detect unsigned wraparound in the
595 CORE_ADDR math, we ignore this test and print the offset,
596 because addr+max_symbolic_offset has wrapped through the end
597 of the address space back to the beginning, giving bogus comparison. */
598 if (addr > name_location + max_symbolic_offset
599 && name_location + max_symbolic_offset > name_location)
602 fputs_filtered (leadin, stream);
604 fputs_filtered ("<*", stream);
606 fputs_filtered ("<", stream);
607 fputs_filtered (name, stream);
608 if (addr != name_location)
609 fprintf_filtered (stream, "+%u", (unsigned int)(addr - name_location));
611 /* Append source filename and line number if desired. Give specific
612 line # of this addr, if we have it; else line # of the nearest symbol. */
613 if (print_symbol_filename)
615 struct symtab_and_line sal;
617 sal = find_pc_sect_line (addr, section, 0);
620 fprintf_filtered (stream, " at %s:%d", sal.symtab->filename, sal.line);
621 else if (symtab && symbol && symbol->line)
622 fprintf_filtered (stream, " at %s:%d", symtab->filename, symbol->line);
624 fprintf_filtered (stream, " in %s", symtab->filename);
627 fputs_filtered ("*>", stream);
629 fputs_filtered (">", stream);
632 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
635 print_address_numeric (addr, use_local, stream)
640 /* This assumes a CORE_ADDR can fit in a LONGEST. Probably a safe
642 print_longest (stream, 'x', use_local, (ULONGEST) addr);
645 /* Print address ADDR symbolically on STREAM.
646 First print it as a number. Then perhaps print
647 <SYMBOL + OFFSET> after the number. */
650 print_address (addr, stream)
654 print_address_numeric (addr, 1, stream);
655 print_address_symbolic (addr, stream, asm_demangle, " ");
658 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
659 controls whether to print the symbolic name "raw" or demangled.
660 Global setting "addressprint" controls whether to print hex address
664 print_address_demangle (addr, stream, do_demangle)
671 fprintf_filtered (stream, "0");
673 else if (addressprint)
675 print_address_numeric (addr, 1, stream);
676 print_address_symbolic (addr, stream, do_demangle, " ");
680 print_address_symbolic (addr, stream, do_demangle, "");
685 /* These are the types that $__ will get after an examine command of one
688 static struct type *examine_b_type;
689 static struct type *examine_h_type;
690 static struct type *examine_w_type;
691 static struct type *examine_g_type;
693 /* Examine data at address ADDR in format FMT.
694 Fetch it from memory and print on gdb_stdout. */
697 do_examine (fmt, addr, sect)
698 struct format_data fmt;
702 register char format = 0;
704 register int count = 1;
705 struct type *val_type = NULL;
707 register int maxelts;
715 /* String or instruction format implies fetch single bytes
716 regardless of the specified size. */
717 if (format == 's' || format == 'i')
721 val_type = examine_b_type;
722 else if (size == 'h')
723 val_type = examine_h_type;
724 else if (size == 'w')
725 val_type = examine_w_type;
726 else if (size == 'g')
727 val_type = examine_g_type;
734 if (format == 's' || format == 'i')
737 /* Print as many objects as specified in COUNT, at most maxelts per line,
738 with the address of the next one at the start of each line. */
743 print_address (next_address, gdb_stdout);
744 printf_filtered (":");
749 printf_filtered ("\t");
750 /* Note that print_formatted sets next_address for the next
752 last_examine_address = next_address;
753 last_examine_value = value_at (val_type, next_address, sect);
754 print_formatted (last_examine_value, format, size);
756 printf_filtered ("\n");
757 gdb_flush (gdb_stdout);
762 validate_format (fmt, cmdname)
763 struct format_data fmt;
767 error ("Size letters are meaningless in \"%s\" command.", cmdname);
769 error ("Item count other than 1 is meaningless in \"%s\" command.",
771 if (fmt.format == 'i' || fmt.format == 's')
772 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
773 fmt.format, cmdname);
776 /* Evaluate string EXP as an expression in the current language and
777 print the resulting value. EXP may contain a format specifier as the
778 first argument ("/x myvar" for example, to print myvar in hex).
782 print_command_1 (exp, inspect, voidprint)
787 struct expression *expr;
788 register struct cleanup *old_chain = 0;
789 register char format = 0;
790 register value_ptr val;
791 struct format_data fmt;
794 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
795 inspect_it = inspect;
797 if (exp && *exp == '/')
800 fmt = decode_format (&exp, last_format, 0);
801 validate_format (fmt, "print");
802 last_format = format = fmt.format;
813 extern int objectprint;
815 expr = parse_expression (exp);
816 old_chain = make_cleanup (free_current_contents, &expr);
818 val = evaluate_expression (expr);
820 /* C++: figure out what type we actually want to print it as. */
821 type = VALUE_TYPE (val);
824 && ( TYPE_CODE (type) == TYPE_CODE_PTR
825 || TYPE_CODE (type) == TYPE_CODE_REF)
826 && ( TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT
827 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION))
831 v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
835 type = VALUE_TYPE (val);
840 val = access_value_history (0);
842 if (voidprint || (val && VALUE_TYPE (val) &&
843 TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
845 int histindex = record_latest_value (val);
848 annotate_value_history_begin (histindex, VALUE_TYPE (val));
850 annotate_value_begin (VALUE_TYPE (val));
853 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
855 if (histindex >= 0) printf_filtered ("$%d = ", histindex);
858 annotate_value_history_value ();
860 print_formatted (val, format, fmt.size);
861 printf_filtered ("\n");
864 annotate_value_history_end ();
866 annotate_value_end ();
869 printf_unfiltered("\") )\030");
873 do_cleanups (old_chain);
874 inspect_it = 0; /* Reset print routines to normal */
879 print_command (exp, from_tty)
883 print_command_1 (exp, 0, 1);
886 /* Same as print, except in epoch, it gets its own window */
889 inspect_command (exp, from_tty)
893 extern int epoch_interface;
895 print_command_1 (exp, epoch_interface, 1);
898 /* Same as print, except it doesn't print void results. */
901 call_command (exp, from_tty)
905 print_command_1 (exp, 0, 0);
910 output_command (exp, from_tty)
914 struct expression *expr;
915 register struct cleanup *old_chain;
916 register char format = 0;
917 register value_ptr val;
918 struct format_data fmt;
920 if (exp && *exp == '/')
923 fmt = decode_format (&exp, 0, 0);
924 validate_format (fmt, "output");
928 expr = parse_expression (exp);
929 old_chain = make_cleanup (free_current_contents, &expr);
931 val = evaluate_expression (expr);
933 annotate_value_begin (VALUE_TYPE (val));
935 print_formatted (val, format, fmt.size);
937 annotate_value_end ();
939 do_cleanups (old_chain);
944 set_command (exp, from_tty)
948 struct expression *expr = parse_expression (exp);
949 register struct cleanup *old_chain
950 = make_cleanup (free_current_contents, &expr);
951 evaluate_expression (expr);
952 do_cleanups (old_chain);
957 sym_info (arg, from_tty)
961 struct minimal_symbol *msymbol;
962 struct objfile *objfile;
963 struct obj_section *osect;
965 CORE_ADDR addr, sect_addr;
970 error_no_arg ("address");
972 addr = parse_and_eval_address (arg);
973 ALL_OBJSECTIONS (objfile, osect)
975 sect = osect->the_bfd_section;
976 sect_addr = overlay_mapped_address (addr, sect);
978 if (osect->addr <= sect_addr && sect_addr < osect->endaddr &&
979 (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect)))
982 offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
984 printf_filtered ("%s + %u in ",
985 SYMBOL_SOURCE_NAME (msymbol), offset);
987 printf_filtered ("%s in ",
988 SYMBOL_SOURCE_NAME (msymbol));
989 if (pc_in_unmapped_range (addr, sect))
990 printf_filtered ("load address range of ");
991 if (section_is_overlay (sect))
992 printf_filtered ("%s overlay ",
993 section_is_mapped (sect) ? "mapped" : "unmapped");
994 printf_filtered ("section %s", sect->name);
995 printf_filtered ("\n");
999 printf_filtered ("No symbol matches %s.\n", arg);
1004 address_info (exp, from_tty)
1008 register struct symbol *sym;
1009 register struct minimal_symbol *msymbol;
1011 register long basereg;
1013 CORE_ADDR load_addr;
1014 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
1015 if exp is a field of `this'. */
1018 error ("Argument required.");
1020 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
1021 &is_a_field_of_this, (struct symtab **)NULL);
1024 if (is_a_field_of_this)
1026 printf_filtered ("Symbol \"");
1027 fprintf_symbol_filtered (gdb_stdout, exp,
1028 current_language->la_language, DMGL_ANSI);
1029 printf_filtered ("\" is a field of the local class variable `this'\n");
1033 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1035 if (msymbol != NULL)
1037 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1039 printf_filtered ("Symbol \"");
1040 fprintf_symbol_filtered (gdb_stdout, exp,
1041 current_language->la_language, DMGL_ANSI);
1042 printf_filtered ("\" is at ");
1043 print_address_numeric (load_addr, 1, gdb_stdout);
1044 printf_filtered (" in a file compiled without debugging");
1045 section = SYMBOL_BFD_SECTION (msymbol);
1046 if (section_is_overlay (section))
1048 load_addr = overlay_unmapped_address (load_addr, section);
1049 printf_filtered (",\n -- loaded at ");
1050 print_address_numeric (load_addr, 1, gdb_stdout);
1051 printf_filtered (" in overlay section %s", section->name);
1053 printf_filtered (".\n");
1056 error ("No symbol \"%s\" in current context.", exp);
1060 printf_filtered ("Symbol \"");
1061 fprintf_symbol_filtered (gdb_stdout, SYMBOL_NAME (sym),
1062 current_language->la_language, DMGL_ANSI);
1063 printf_filtered ("\" is ");
1064 val = SYMBOL_VALUE (sym);
1065 basereg = SYMBOL_BASEREG (sym);
1066 section = SYMBOL_BFD_SECTION (sym);
1068 switch (SYMBOL_CLASS (sym))
1071 case LOC_CONST_BYTES:
1072 printf_filtered ("constant");
1076 printf_filtered ("a label at address ");
1077 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1079 if (section_is_overlay (section))
1081 load_addr = overlay_unmapped_address (load_addr, section);
1082 printf_filtered (",\n -- loaded at ");
1083 print_address_numeric (load_addr, 1, gdb_stdout);
1084 printf_filtered (" in overlay section %s", section->name);
1089 printf_filtered ("a variable in register %s", reg_names[val]);
1093 printf_filtered ("static storage at address ");
1094 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
1096 if (section_is_overlay (section))
1098 load_addr = overlay_unmapped_address (load_addr, section);
1099 printf_filtered (",\n -- loaded at ");
1100 print_address_numeric (load_addr, 1, gdb_stdout);
1101 printf_filtered (" in overlay section %s", section->name);
1106 printf_filtered ("an argument in register %s", reg_names[val]);
1109 case LOC_REGPARM_ADDR:
1110 printf_filtered ("address of an argument in register %s", reg_names[val]);
1114 printf_filtered ("an argument at offset %ld", val);
1118 printf_filtered ("an argument at frame offset %ld", val);
1122 printf_filtered ("a local variable at frame offset %ld", val);
1126 printf_filtered ("a reference argument at offset %ld", val);
1130 printf_filtered ("a variable at offset %ld from register %s",
1131 val, reg_names[basereg]);
1134 case LOC_BASEREG_ARG:
1135 printf_filtered ("an argument at offset %ld from register %s",
1136 val, reg_names[basereg]);
1140 printf_filtered ("a typedef");
1144 printf_filtered ("a function at address ");
1145 #ifdef GDB_TARGET_MASK_DISAS_PC
1146 print_address_numeric
1147 (load_addr= GDB_TARGET_MASK_DISAS_PC (BLOCK_START (SYMBOL_BLOCK_VALUE (sym))),
1150 print_address_numeric (load_addr=BLOCK_START (SYMBOL_BLOCK_VALUE (sym)),
1153 if (section_is_overlay (section))
1155 load_addr = overlay_unmapped_address (load_addr, section);
1156 printf_filtered (",\n -- loaded at ");
1157 print_address_numeric (load_addr, 1, gdb_stdout);
1158 printf_filtered (" in overlay section %s", section->name);
1162 case LOC_UNRESOLVED:
1164 struct minimal_symbol *msym;
1166 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, NULL);
1168 printf_filtered ("unresolved");
1171 section = SYMBOL_BFD_SECTION (msym);
1172 printf_filtered ("static storage at address ");
1173 print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (msym),
1175 if (section_is_overlay (section))
1177 load_addr = overlay_unmapped_address (load_addr, section);
1178 printf_filtered (",\n -- loaded at ");
1179 print_address_numeric (load_addr, 1, gdb_stdout);
1180 printf_filtered (" in overlay section %s", section->name);
1186 case LOC_OPTIMIZED_OUT:
1187 printf_filtered ("optimized out");
1191 printf_filtered ("of unknown (botched) type");
1194 printf_filtered (".\n");
1198 x_command (exp, from_tty)
1202 struct expression *expr;
1203 struct format_data fmt;
1204 struct cleanup *old_chain;
1207 fmt.format = last_format;
1208 fmt.size = last_size;
1211 if (exp && *exp == '/')
1214 fmt = decode_format (&exp, last_format, last_size);
1217 /* If we have an expression, evaluate it and use it as the address. */
1219 if (exp != 0 && *exp != 0)
1221 expr = parse_expression (exp);
1222 /* Cause expression not to be there any more
1223 if this command is repeated with Newline.
1224 But don't clobber a user-defined command's definition. */
1227 old_chain = make_cleanup (free_current_contents, &expr);
1228 val = evaluate_expression (expr);
1229 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
1230 val = value_ind (val);
1231 /* In rvalue contexts, such as this, functions are coerced into
1232 pointers to functions. This makes "x/i main" work. */
1233 if (/* last_format == 'i'
1234 && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
1235 && VALUE_LVAL (val) == lval_memory)
1236 next_address = VALUE_ADDRESS (val);
1238 next_address = value_as_pointer (val);
1239 if (VALUE_BFD_SECTION (val))
1240 next_section = VALUE_BFD_SECTION (val);
1241 do_cleanups (old_chain);
1244 do_examine (fmt, next_address, next_section);
1246 /* If the examine succeeds, we remember its size and format for next time. */
1247 last_size = fmt.size;
1248 last_format = fmt.format;
1250 /* Set a couple of internal variables if appropriate. */
1251 if (last_examine_value)
1253 /* Make last address examined available to the user as $_. Use
1254 the correct pointer type. */
1255 set_internalvar (lookup_internalvar ("_"),
1256 value_from_longest (
1257 lookup_pointer_type (VALUE_TYPE (last_examine_value)),
1258 (LONGEST) last_examine_address));
1260 /* Make contents of last address examined available to the user as $__.*/
1261 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1266 /* Add an expression to the auto-display chain.
1267 Specify the expression. */
1270 display_command (exp, from_tty)
1274 struct format_data fmt;
1275 register struct expression *expr;
1276 register struct display *new;
1287 fmt = decode_format (&exp, 0, 0);
1288 if (fmt.size && fmt.format == 0)
1290 if (fmt.format == 'i' || fmt.format == 's')
1300 innermost_block = 0;
1301 expr = parse_expression (exp);
1303 new = (struct display *) xmalloc (sizeof (struct display));
1306 new->block = innermost_block;
1307 new->next = display_chain;
1308 new->number = ++display_number;
1310 new->status = enabled;
1311 display_chain = new;
1313 if (from_tty && target_has_execution)
1314 do_one_display (new);
1327 /* Clear out the display_chain.
1328 Done when new symtabs are loaded, since this invalidates
1329 the types stored in many expressions. */
1334 register struct display *d;
1336 while ((d = display_chain) != NULL)
1339 display_chain = d->next;
1344 /* Delete the auto-display number NUM. */
1347 delete_display (num)
1350 register struct display *d1, *d;
1353 error ("No display number %d.", num);
1355 if (display_chain->number == num)
1358 display_chain = d1->next;
1362 for (d = display_chain; ; d = d->next)
1365 error ("No display number %d.", num);
1366 if (d->next->number == num)
1376 /* Delete some values from the auto-display chain.
1377 Specify the element numbers. */
1380 undisplay_command (args, from_tty)
1384 register char *p = args;
1390 if (query ("Delete all auto-display expressions? "))
1399 while (*p1 >= '0' && *p1 <= '9') p1++;
1400 if (*p1 && *p1 != ' ' && *p1 != '\t')
1401 error ("Arguments must be display numbers.");
1405 delete_display (num);
1408 while (*p == ' ' || *p == '\t') p++;
1413 /* Display a single auto-display.
1414 Do nothing if the display cannot be printed in the current context,
1415 or if the display is disabled. */
1421 int within_current_scope;
1423 if (d->status == disabled)
1427 within_current_scope = contained_in (get_selected_block (), d->block);
1429 within_current_scope = 1;
1430 if (!within_current_scope)
1433 current_display_number = d->number;
1435 annotate_display_begin ();
1436 printf_filtered ("%d", d->number);
1437 annotate_display_number_end ();
1438 printf_filtered (": ");
1444 annotate_display_format ();
1446 printf_filtered ("x/");
1447 if (d->format.count != 1)
1448 printf_filtered ("%d", d->format.count);
1449 printf_filtered ("%c", d->format.format);
1450 if (d->format.format != 'i' && d->format.format != 's')
1451 printf_filtered ("%c", d->format.size);
1452 printf_filtered (" ");
1454 annotate_display_expression ();
1456 print_expression (d->exp, gdb_stdout);
1457 annotate_display_expression_end ();
1459 if (d->format.count != 1)
1460 printf_filtered ("\n");
1462 printf_filtered (" ");
1464 val = evaluate_expression (d->exp);
1465 addr = value_as_pointer (val);
1466 if (d->format.format == 'i')
1467 addr = ADDR_BITS_REMOVE (addr);
1469 annotate_display_value ();
1471 do_examine (d->format, addr, VALUE_BFD_SECTION (val));
1475 annotate_display_format ();
1477 if (d->format.format)
1478 printf_filtered ("/%c ", d->format.format);
1480 annotate_display_expression ();
1482 print_expression (d->exp, gdb_stdout);
1483 annotate_display_expression_end ();
1485 printf_filtered (" = ");
1487 annotate_display_expression ();
1489 print_formatted (evaluate_expression (d->exp),
1490 d->format.format, d->format.size);
1491 printf_filtered ("\n");
1494 annotate_display_end ();
1496 gdb_flush (gdb_stdout);
1497 current_display_number = -1;
1500 /* Display all of the values on the auto-display chain which can be
1501 evaluated in the current scope. */
1506 register struct display *d;
1508 for (d = display_chain; d; d = d->next)
1512 /* Delete the auto-display which we were in the process of displaying.
1513 This is done when there is an error or a signal. */
1516 disable_display (num)
1519 register struct display *d;
1521 for (d = display_chain; d; d = d->next)
1522 if (d->number == num)
1524 d->status = disabled;
1527 printf_unfiltered ("No display number %d.\n", num);
1531 disable_current_display ()
1533 if (current_display_number >= 0)
1535 disable_display (current_display_number);
1536 fprintf_unfiltered (gdb_stderr, "Disabling display %d to avoid infinite recursion.\n",
1537 current_display_number);
1539 current_display_number = -1;
1543 display_info (ignore, from_tty)
1547 register struct display *d;
1550 printf_unfiltered ("There are no auto-display expressions now.\n");
1552 printf_filtered ("Auto-display expressions now in effect:\n\
1553 Num Enb Expression\n");
1555 for (d = display_chain; d; d = d->next)
1557 printf_filtered ("%d: %c ", d->number, "ny"[(int)d->status]);
1559 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1561 else if (d->format.format)
1562 printf_filtered ("/%c ", d->format.format);
1563 print_expression (d->exp, gdb_stdout);
1564 if (d->block && !contained_in (get_selected_block (), d->block))
1565 printf_filtered (" (cannot be evaluated in the current context)");
1566 printf_filtered ("\n");
1567 gdb_flush (gdb_stdout);
1572 enable_display (args, from_tty)
1576 register char *p = args;
1579 register struct display *d;
1583 for (d = display_chain; d; d = d->next)
1584 d->status = enabled;
1590 while (*p1 >= '0' && *p1 <= '9')
1592 if (*p1 && *p1 != ' ' && *p1 != '\t')
1593 error ("Arguments must be display numbers.");
1597 for (d = display_chain; d; d = d->next)
1598 if (d->number == num)
1600 d->status = enabled;
1603 printf_unfiltered ("No display number %d.\n", num);
1606 while (*p == ' ' || *p == '\t')
1613 disable_display_command (args, from_tty)
1617 register char *p = args;
1619 register struct display *d;
1623 for (d = display_chain; d; d = d->next)
1624 d->status = disabled;
1630 while (*p1 >= '0' && *p1 <= '9')
1632 if (*p1 && *p1 != ' ' && *p1 != '\t')
1633 error ("Arguments must be display numbers.");
1635 disable_display (atoi (p));
1638 while (*p == ' ' || *p == '\t')
1644 /* Print the value in stack frame FRAME of a variable
1645 specified by a struct symbol. */
1648 print_variable_value (var, frame, stream)
1650 struct frame_info *frame;
1653 value_ptr val = read_var_value (var, frame);
1655 value_print (val, stream, 0, Val_pretty_default);
1658 /* Print the arguments of a stack frame, given the function FUNC
1659 running in that frame (as a symbol), the info on the frame,
1660 and the number of args according to the stack frame (or -1 if unknown). */
1662 /* References here and elsewhere to "number of args according to the
1663 stack frame" appear in all cases to refer to "number of ints of args
1664 according to the stack frame". At least for VAX, i386, isi. */
1667 print_frame_args (func, fi, num, stream)
1668 struct symbol *func;
1669 struct frame_info *fi;
1673 struct block *b = NULL;
1677 register struct symbol *sym;
1678 register value_ptr val;
1679 /* Offset of next stack argument beyond the one we have seen that is
1680 at the highest offset.
1681 -1 if we haven't come to a stack argument yet. */
1682 long highest_offset = -1;
1684 /* Number of ints of arguments that we have printed so far. */
1685 int args_printed = 0;
1689 b = SYMBOL_BLOCK_VALUE (func);
1690 nsyms = BLOCK_NSYMS (b);
1693 for (i = 0; i < nsyms; i++)
1696 sym = BLOCK_SYM (b, i);
1698 /* Keep track of the highest stack argument offset seen, and
1699 skip over any kinds of symbols we don't care about. */
1701 switch (SYMBOL_CLASS (sym)) {
1705 long current_offset = SYMBOL_VALUE (sym);
1706 arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1708 /* Compute address of next argument by adding the size of
1709 this argument and rounding to an int boundary. */
1711 = ((current_offset + arg_size + sizeof (int) - 1)
1712 & ~(sizeof (int) - 1));
1714 /* If this is the highest offset seen yet, set highest_offset. */
1715 if (highest_offset == -1
1716 || (current_offset > highest_offset))
1717 highest_offset = current_offset;
1719 /* Add the number of ints we're about to print to args_printed. */
1720 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
1723 /* We care about types of symbols, but don't need to keep track of
1724 stack offsets in them. */
1726 case LOC_REGPARM_ADDR:
1728 case LOC_BASEREG_ARG:
1731 /* Other types of symbols we just skip over. */
1736 /* We have to look up the symbol because arguments can have
1737 two entries (one a parameter, one a local) and the one we
1738 want is the local, which lookup_symbol will find for us.
1739 This includes gcc1 (not gcc2) on the sparc when passing a
1740 small structure and gcc2 when the argument type is float
1741 and it is passed as a double and converted to float by
1742 the prologue (in the latter case the type of the LOC_ARG
1743 symbol is double and the type of the LOC_LOCAL symbol is
1745 /* But if the parameter name is null, don't try it.
1746 Null parameter names occur on the RS/6000, for traceback tables.
1747 FIXME, should we even print them? */
1749 if (*SYMBOL_NAME (sym))
1751 struct symbol *nsym;
1752 nsym = lookup_symbol
1754 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
1755 if (SYMBOL_CLASS (nsym) == LOC_REGISTER)
1757 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
1758 it was passed on the stack and loaded into a register,
1759 or passed in a register and stored in a stack slot.
1760 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
1762 Reasons for using the LOC_ARG:
1763 (1) because find_saved_registers may be slow for remote
1765 (2) because registers are often re-used and stack slots
1766 rarely (never?) are. Therefore using the stack slot is
1767 much less likely to print garbage.
1769 Reasons why we might want to use the LOC_REGISTER:
1770 (1) So that the backtrace prints the same value as
1771 "print foo". I see no compelling reason why this needs
1772 to be the case; having the backtrace print the value which
1773 was passed in, and "print foo" print the value as modified
1774 within the called function, makes perfect sense to me.
1776 Additional note: It might be nice if "info args" displayed
1778 One more note: There is a case with sparc structure passing
1779 where we need to use the LOC_REGISTER, but this is dealt with
1780 by creating a single LOC_REGPARM in symbol reading. */
1782 /* Leave sym (the LOC_ARG) alone. */
1789 /* Print the current arg. */
1791 fprintf_filtered (stream, ", ");
1794 annotate_arg_begin ();
1796 fprintf_symbol_filtered (stream, SYMBOL_SOURCE_NAME (sym),
1797 SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
1798 annotate_arg_name_end ();
1799 fputs_filtered ("=", stream);
1801 /* Avoid value_print because it will deref ref parameters. We just
1802 want to print their addresses. Print ??? for args whose address
1803 we do not know. We pass 2 as "recurse" to val_print because our
1804 standard indentation here is 4 spaces, and val_print indents
1805 2 for each recurse. */
1806 val = read_var_value (sym, fi);
1808 annotate_arg_value (val == NULL ? NULL : VALUE_TYPE (val));
1811 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val),
1812 stream, 0, 0, 2, Val_no_prettyprint);
1814 fputs_filtered ("???", stream);
1816 annotate_arg_end ();
1821 /* Don't print nameless args in situations where we don't know
1822 enough about the stack to find them. */
1827 if (highest_offset == -1)
1828 start = FRAME_ARGS_SKIP;
1830 start = highest_offset;
1832 print_frame_nameless_args (fi, start, num - args_printed,
1837 /* Print nameless args on STREAM.
1838 FI is the frameinfo for this frame, START is the offset
1839 of the first nameless arg, and NUM is the number of nameless args to
1840 print. FIRST is nonzero if this is the first argument (not just
1841 the first nameless arg). */
1844 print_frame_nameless_args (fi, start, num, first, stream)
1845 struct frame_info *fi;
1855 for (i = 0; i < num; i++)
1858 #ifdef NAMELESS_ARG_VALUE
1859 NAMELESS_ARG_VALUE (fi, start, &arg_value);
1861 argsaddr = FRAME_ARGS_ADDRESS (fi);
1865 arg_value = read_memory_integer (argsaddr + start, sizeof (int));
1869 fprintf_filtered (stream, ", ");
1871 #ifdef PRINT_NAMELESS_INTEGER
1872 PRINT_NAMELESS_INTEGER (stream, arg_value);
1874 #ifdef PRINT_TYPELESS_INTEGER
1875 PRINT_TYPELESS_INTEGER (stream, builtin_type_int, (LONGEST) arg_value);
1877 fprintf_filtered (stream, "%ld", arg_value);
1878 #endif /* PRINT_TYPELESS_INTEGER */
1879 #endif /* PRINT_NAMELESS_INTEGER */
1881 start += sizeof (int);
1887 printf_command (arg, from_tty)
1892 register char *s = arg;
1894 value_ptr *val_args;
1896 char *current_substring;
1898 int allocated_args = 20;
1899 struct cleanup *old_cleanups;
1901 val_args = (value_ptr *) xmalloc (allocated_args * sizeof (value_ptr));
1902 old_cleanups = make_cleanup (free_current_contents, &val_args);
1905 error_no_arg ("format-control string and values to print");
1907 /* Skip white space before format string */
1908 while (*s == ' ' || *s == '\t') s++;
1910 /* A format string should follow, enveloped in double quotes */
1912 error ("Bad format string, missing '\"'.");
1914 /* Parse the format-control string and copy it into the string STRING,
1915 processing some kinds of escape sequence. */
1917 f = string = (char *) alloca (strlen (s) + 1);
1925 error ("Bad format string, non-terminated '\"'.");
1937 *f++ = '\007'; /* Bell */
1962 /* ??? TODO: handle other escape sequences */
1963 error ("Unrecognized escape character \\%c in format string.",
1973 /* Skip over " and following space and comma. */
1976 while (*s == ' ' || *s == '\t') s++;
1978 if (*s != ',' && *s != 0)
1979 error ("Invalid argument syntax");
1982 while (*s == ' ' || *s == '\t') s++;
1984 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1985 substrings = alloca (strlen (string) * 2);
1986 current_substring = substrings;
1989 /* Now scan the string for %-specs and see what kinds of args they want.
1990 argclass[I] classifies the %-specs so we can give printf_filtered
1991 something of the right size. */
1993 enum argclass {no_arg, int_arg, string_arg, double_arg, long_long_arg};
1994 enum argclass *argclass;
1995 enum argclass this_argclass;
2001 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
2009 while (strchr ("0123456789.hlL-+ #", *f))
2011 if (*f == 'l' || *f == 'L')
2018 this_argclass = string_arg;
2024 this_argclass = double_arg;
2028 error ("`*' not supported for precision or width in printf");
2031 error ("Format specifier `n' not supported in printf");
2034 this_argclass = no_arg;
2039 this_argclass = long_long_arg;
2041 this_argclass = int_arg;
2045 if (this_argclass != no_arg)
2047 strncpy (current_substring, last_arg, f - last_arg);
2048 current_substring += f - last_arg;
2049 *current_substring++ = '\0';
2051 argclass[nargs_wanted++] = this_argclass;
2055 /* Now, parse all arguments and evaluate them.
2056 Store the VALUEs in VAL_ARGS. */
2061 if (nargs == allocated_args)
2062 val_args = (value_ptr *) xrealloc ((char *) val_args,
2063 (allocated_args *= 2)
2064 * sizeof (value_ptr));
2066 val_args[nargs] = parse_to_comma_and_eval (&s1);
2068 /* If format string wants a float, unchecked-convert the value to
2069 floating point of the same size */
2071 if (argclass[nargs] == double_arg)
2073 struct type *type = VALUE_TYPE (val_args[nargs]);
2074 if (TYPE_LENGTH (type) == sizeof (float))
2075 VALUE_TYPE (val_args[nargs]) = builtin_type_float;
2076 if (TYPE_LENGTH (type) == sizeof (double))
2077 VALUE_TYPE (val_args[nargs]) = builtin_type_double;
2085 if (nargs != nargs_wanted)
2086 error ("Wrong number of arguments for specified format-string");
2088 /* Now actually print them. */
2089 current_substring = substrings;
2090 for (i = 0; i < nargs; i++)
2092 switch (argclass[i])
2099 tem = value_as_pointer (val_args[i]);
2101 /* This is a %s argument. Find the length of the string. */
2106 read_memory_section (tem + j, &c, 1,
2107 VALUE_BFD_SECTION (val_args[i]));
2112 /* Copy the string contents into a string inside GDB. */
2113 str = (char *) alloca (j + 1);
2114 read_memory_section (tem, str, j, VALUE_BFD_SECTION (val_args[i]));
2117 printf_filtered (current_substring, str);
2122 double val = value_as_double (val_args[i]);
2123 printf_filtered (current_substring, val);
2127 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2129 long long val = value_as_long (val_args[i]);
2130 printf_filtered (current_substring, val);
2134 error ("long long not supported in printf");
2138 /* FIXME: there should be separate int_arg and long_arg. */
2139 long val = value_as_long (val_args[i]);
2140 printf_filtered (current_substring, val);
2144 error ("internal error in printf_command");
2146 /* Skip to the next substring. */
2147 current_substring += strlen (current_substring) + 1;
2149 /* Print the portion of the format string after the last argument. */
2150 printf_filtered (last_arg);
2152 do_cleanups (old_cleanups);
2155 /* Dump a specified section of assembly code. With no command line
2156 arguments, this command will dump the assembly code for the
2157 function surrounding the pc value in the selected frame. With one
2158 argument, it will dump the assembly code surrounding that pc value.
2159 Two arguments are interpeted as bounds within which to dump
2164 disassemble_command (arg, from_tty)
2168 CORE_ADDR low, high;
2170 CORE_ADDR pc, pc_masked;
2177 if (!selected_frame)
2178 error ("No frame selected.\n");
2180 pc = get_frame_pc (selected_frame);
2181 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
2182 error ("No function contains program counter for selected frame.\n");
2183 low += FUNCTION_START_OFFSET;
2185 else if (!(space_index = (char *) strchr (arg, ' ')))
2188 pc = parse_and_eval_address (arg);
2189 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
2190 error ("No function contains specified address.\n");
2191 if (overlay_debugging)
2193 section = find_pc_overlay (pc);
2194 if (pc_in_unmapped_range (pc, section))
2196 /* find_pc_partial_function will have returned low and high
2197 relative to the symbolic (mapped) address range. Need to
2198 translate them back to the unmapped range where PC is. */
2199 low = overlay_unmapped_address (low, section);
2200 high = overlay_unmapped_address (high, section);
2203 low += FUNCTION_START_OFFSET;
2207 /* Two arguments. */
2208 *space_index = '\0';
2209 low = parse_and_eval_address (arg);
2210 high = parse_and_eval_address (space_index + 1);
2213 printf_filtered ("Dump of assembler code ");
2216 printf_filtered ("for function %s:\n", name);
2220 printf_filtered ("from ");
2221 print_address_numeric (low, 1, gdb_stdout);
2222 printf_filtered (" to ");
2223 print_address_numeric (high, 1, gdb_stdout);
2224 printf_filtered (":\n");
2227 /* Dump the specified range. */
2230 #ifdef GDB_TARGET_MASK_DISAS_PC
2231 pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
2236 while (pc_masked < high)
2239 print_address (pc_masked, gdb_stdout);
2240 printf_filtered (":\t");
2241 /* We often wrap here if there are long symbolic names. */
2243 pc += print_insn (pc, gdb_stdout);
2244 printf_filtered ("\n");
2246 #ifdef GDB_TARGET_MASK_DISAS_PC
2247 pc_masked = GDB_TARGET_MASK_DISAS_PC (pc);
2252 printf_filtered ("End of assembler dump.\n");
2253 gdb_flush (gdb_stdout);
2256 /* Print the instruction at address MEMADDR in debugged memory,
2257 on STREAM. Returns length of the instruction, in bytes. */
2260 print_insn (memaddr, stream)
2264 /* If there's no disassembler, something is very wrong. */
2265 if (tm_print_insn == NULL)
2268 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2269 tm_print_insn_info.endian = BFD_ENDIAN_BIG;
2271 tm_print_insn_info.endian = BFD_ENDIAN_LITTLE;
2273 if (target_architecture != NULL)
2274 tm_print_insn_info.mach = target_architecture->mach;
2275 /* else: should set .mach=0 but some disassemblers don't grok this */
2277 return (*tm_print_insn) (memaddr, &tm_print_insn_info);
2282 _initialize_printcmd ()
2284 current_display_number = -1;
2286 add_info ("address", address_info,
2287 "Describe where symbol SYM is stored.");
2289 add_info ("symbol", sym_info,
2290 "Describe what symbol is at location ADDR.\n\
2291 Only for symbols with fixed locations (global or static scope).");
2293 add_com ("x", class_vars, x_command,
2294 concat ("Examine memory: x/FMT ADDRESS.\n\
2295 ADDRESS is an expression for the memory address to examine.\n\
2296 FMT is a repeat count followed by a format letter and a size letter.\n\
2297 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2298 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n",
2299 "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2300 The specified number of objects of the specified size are printed\n\
2301 according to the format.\n\n\
2302 Defaults for format and size letters are those previously used.\n\
2303 Default count is 1. Default address is following last thing printed\n\
2304 with this command or \"print\".", NULL));
2306 add_com ("disassemble", class_vars, disassemble_command,
2307 "Disassemble a specified section of memory.\n\
2308 Default is the function surrounding the pc of the selected frame.\n\
2309 With a single argument, the function surrounding that address is dumped.\n\
2310 Two arguments are taken as a range of memory to dump.");
2313 add_com ("whereis", class_vars, whereis_command,
2314 "Print line number and file of definition of variable.");
2317 add_info ("display", display_info,
2318 "Expressions to display when program stops, with code numbers.");
2320 add_cmd ("undisplay", class_vars, undisplay_command,
2321 "Cancel some expressions to be displayed when program stops.\n\
2322 Arguments are the code numbers of the expressions to stop displaying.\n\
2323 No argument means cancel all automatic-display expressions.\n\
2324 \"delete display\" has the same effect as this command.\n\
2325 Do \"info display\" to see current list of code numbers.",
2328 add_com ("display", class_vars, display_command,
2329 "Print value of expression EXP each time the program stops.\n\
2330 /FMT may be used before EXP as in the \"print\" command.\n\
2331 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2332 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2333 and examining is done as in the \"x\" command.\n\n\
2334 With no argument, display all currently requested auto-display expressions.\n\
2335 Use \"undisplay\" to cancel display requests previously made."
2338 add_cmd ("display", class_vars, enable_display,
2339 "Enable some expressions to be displayed when program stops.\n\
2340 Arguments are the code numbers of the expressions to resume displaying.\n\
2341 No argument means enable all automatic-display expressions.\n\
2342 Do \"info display\" to see current list of code numbers.", &enablelist);
2344 add_cmd ("display", class_vars, disable_display_command,
2345 "Disable some expressions to be displayed when program stops.\n\
2346 Arguments are the code numbers of the expressions to stop displaying.\n\
2347 No argument means disable all automatic-display expressions.\n\
2348 Do \"info display\" to see current list of code numbers.", &disablelist);
2350 add_cmd ("display", class_vars, undisplay_command,
2351 "Cancel some expressions to be displayed when program stops.\n\
2352 Arguments are the code numbers of the expressions to stop displaying.\n\
2353 No argument means cancel all automatic-display expressions.\n\
2354 Do \"info display\" to see current list of code numbers.", &deletelist);
2356 add_com ("printf", class_vars, printf_command,
2357 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2358 This is useful for formatted output in user-defined commands.");
2360 add_com ("output", class_vars, output_command,
2361 "Like \"print\" but don't put in value history and don't print newline.\n\
2362 This is useful in user-defined commands.");
2364 add_prefix_cmd ("set", class_vars, set_command,
2365 concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2366 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2367 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2368 with $), a register (a few standard names starting with $), or an actual\n\
2369 variable in the program being debugged. EXP is any valid expression.\n",
2370 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2371 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2372 You can see these environment settings with the \"show\" command.", NULL),
2373 &setlist, "set ", 1, &cmdlist);
2375 /* "call" is the same as "set", but handy for dbx users to call fns. */
2376 add_com ("call", class_vars, call_command,
2377 "Call a function in the program.\n\
2378 The argument is the function name and arguments, in the notation of the\n\
2379 current working language. The result is printed and saved in the value\n\
2380 history, if it is not void.");
2382 add_cmd ("variable", class_vars, set_command,
2383 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2384 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2385 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2386 with $), a register (a few standard names starting with $), or an actual\n\
2387 variable in the program being debugged. EXP is any valid expression.\n\
2388 This may usually be abbreviated to simply \"set\".",
2391 add_com ("print", class_vars, print_command,
2392 concat ("Print value of expression EXP.\n\
2393 Variables accessible are those of the lexical environment of the selected\n\
2394 stack frame, plus all those whose scope is global or an entire file.\n\
2396 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2397 $$NUM refers to NUM'th value back from the last one.\n\
2398 Names starting with $ refer to registers (with the values they would have\n",
2399 "if the program were to return to the stack frame now selected, restoring\n\
2400 all registers saved by frames farther in) or else to debugger\n\
2401 \"convenience\" variables (any such name not a known register).\n\
2402 Use assignment expressions to give values to convenience variables.\n",
2404 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2405 @ is a binary operator for treating consecutive data objects\n\
2406 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2407 element is FOO, whose second element is stored in the space following\n\
2408 where FOO is stored, etc. FOO must be an expression whose value\n\
2409 resides in memory.\n",
2411 EXP may be preceded with /FMT, where FMT is a format letter\n\
2412 but no count or size letter (see \"x\" command).", NULL));
2413 add_com_alias ("p", "print", class_vars, 1);
2415 add_com ("inspect", class_vars, inspect_command,
2416 "Same as \"print\" command, except that if you are running in the epoch\n\
2417 environment, the value is printed in its own window.");
2420 add_set_cmd ("max-symbolic-offset", no_class, var_uinteger,
2421 (char *)&max_symbolic_offset,
2422 "Set the largest offset that will be printed in <symbol+1234> form.",
2426 add_set_cmd ("symbol-filename", no_class, var_boolean,
2427 (char *)&print_symbol_filename,
2428 "Set printing of source filename and line number with <symbol>.",
2432 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2433 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2434 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2435 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);
2437 INIT_DISASSEMBLE_INFO_NO_ARCH (tm_print_insn_info, gdb_stdout, (fprintf_ftype)fprintf_filtered);
2438 tm_print_insn_info.flavour = bfd_target_unknown_flavour;
2439 tm_print_insn_info.read_memory_func = dis_asm_read_memory;
2440 tm_print_insn_info.memory_error_func = dis_asm_memory_error;
2441 tm_print_insn_info.print_address_func = dis_asm_print_address;