1 /* Print values for GNU debugger GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "expression.h"
31 #include "breakpoint.h"
34 /* These are just for containing_function_bounds. It might be better
35 to move containing_function_bounds to blockframe.c or thereabouts. */
40 extern int asm_demangle; /* Whether to demangle syms in asm printouts */
41 extern int addressprint; /* Whether to print hex addresses in HLL " */
50 /* Last specified output format. */
52 static char last_format = 'x';
54 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
56 static char last_size = 'w';
58 /* Default address to examine next. */
60 static CORE_ADDR next_address;
62 /* Last address examined. */
64 static CORE_ADDR last_examine_address;
66 /* Contents of last address examined.
67 This is not valid past the end of the `x' command! */
69 static value last_examine_value;
71 /* Largest offset between a symbolic value and an address, that will be
72 printed as `0x1234 <symbol+offset>'. */
74 static unsigned int max_symbolic_offset = UINT_MAX;
76 /* Number of auto-display expression currently being displayed.
77 So that we can disable it if we get an error or a signal within it.
78 -1 when not doing one. */
80 int current_display_number;
82 /* Flag to low-level print routines that this value is being printed
83 in an epoch window. We'd like to pass this as a parameter, but
84 every routine would need to take it. Perhaps we can encapsulate
85 this in the I/O stream once we have GNU stdio. */
91 /* Chain link to next auto-display item. */
93 /* Expression to be evaluated and displayed. */
94 struct expression *exp;
95 /* Item number of this auto-display item. */
97 /* Display format specified. */
98 struct format_data format;
99 /* Innermost block required by this expression when evaluated */
101 /* Status of this display (enabled or disabled) */
105 /* Chain of expressions whose values should be displayed
106 automatically each time the program stops. */
108 static struct display *display_chain;
110 static int display_number;
112 /* Prototypes for local functions */
115 delete_display PARAMS ((int));
118 enable_display PARAMS ((char *, int));
121 disable_display_command PARAMS ((char *, int));
124 disassemble_command PARAMS ((char *, int));
127 containing_function_bounds PARAMS ((CORE_ADDR, CORE_ADDR *, CORE_ADDR *));
130 printf_command PARAMS ((char *, int));
133 print_frame_nameless_args PARAMS ((struct frame_info *, long, int, int,
137 display_info PARAMS ((char *, int));
140 do_one_display PARAMS ((struct display *));
143 undisplay_command PARAMS ((char *, int));
146 free_display PARAMS ((struct display *));
149 display_command PARAMS ((char *, int));
152 x_command PARAMS ((char *, int));
155 address_info PARAMS ((char *, int));
158 set_command PARAMS ((char *, int));
161 output_command PARAMS ((char *, int));
164 call_command PARAMS ((char *, int));
167 inspect_command PARAMS ((char *, int));
170 print_command PARAMS ((char *, int));
173 print_command_1 PARAMS ((char *, int, int));
176 validate_format PARAMS ((struct format_data, char *));
179 do_examine PARAMS ((struct format_data, CORE_ADDR));
182 print_formatted PARAMS ((value, int, int));
184 static struct format_data
185 decode_format PARAMS ((char **, int, int));
188 /* Decode a format specification. *STRING_PTR should point to it.
189 OFORMAT and OSIZE are used as defaults for the format and size
190 if none are given in the format specification.
191 If OSIZE is zero, then the size field of the returned value
192 should be set only if a size is explicitly specified by the
194 The structure returned describes all the data
195 found in the specification. In addition, *STRING_PTR is advanced
196 past the specification and past all whitespace following it. */
198 static struct format_data
199 decode_format (string_ptr, oformat, osize)
204 struct format_data val;
205 register char *p = *string_ptr;
211 if (*p >= '0' && *p <= '9')
212 val.count = atoi (p);
213 while (*p >= '0' && *p <= '9') p++;
215 /* Now process size or format letters that follow. */
219 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
228 else if (*p >= 'a' && *p <= 'z')
235 /* Make sure 'g' size is not used on integer types.
236 Well, actually, we can handle hex. */
237 if (val.size == 'g' && val.format != 'f' && val.format != 'x')
241 while (*p == ' ' || *p == '\t') p++;
244 /* Set defaults for format and size if not specified. */
245 if (val.format == '?')
249 /* Neither has been specified. */
250 val.format = oformat;
254 /* If a size is specified, any format makes a reasonable
255 default except 'i'. */
256 val.format = oformat == 'i' ? 'x' : oformat;
258 else if (val.size == '?')
263 /* Addresses must be words. */
264 val.size = osize ? 'w' : osize;
267 /* Floating point has to be word or giantword. */
268 if (osize == 'w' || osize == 'g')
271 /* Default it to giantword if the last used size is not
273 val.size = osize ? 'g' : osize;
276 /* Characters default to one byte. */
277 val.size = osize ? 'b' : osize;
280 /* The default is the size most recently specified. */
287 /* Print value VAL on stdout according to FORMAT, a letter or 0.
288 Do not end with a newline.
289 0 means print VAL according to its own type.
290 SIZE is the letter for the size of datum being printed.
291 This is used to pad hex numbers so they line up. */
294 print_formatted (val, format, size)
299 int len = TYPE_LENGTH (VALUE_TYPE (val));
301 if (VALUE_LVAL (val) == lval_memory)
302 next_address = VALUE_ADDRESS (val) + len;
307 next_address = VALUE_ADDRESS (val)
308 + value_print (value_addr (val), stdout, format, Val_pretty_default);
312 wrap_here (""); /* Force output out, print_insn not using _filtered */
313 next_address = VALUE_ADDRESS (val)
314 + print_insn (VALUE_ADDRESS (val), stdout);
319 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_ARRAY
320 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_STRING
321 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_STRUCT
322 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_UNION
323 || VALUE_REPEATED (val))
324 value_print (val, stdout, format, Val_pretty_default);
326 print_scalar_formatted (VALUE_CONTENTS (val), VALUE_TYPE (val),
327 format, size, stdout);
331 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
332 according to letters FORMAT and SIZE on STREAM.
333 FORMAT may not be zero. Formats s and i are not supported at this level.
335 This is how the elements of an array or structure are printed
339 print_scalar_formatted (valaddr, type, format, size, stream)
347 int len = TYPE_LENGTH (type);
349 if (size == 'g' && sizeof (LONGEST) < 8
352 /* ok, we're going to have to get fancy here. Assumption: a
353 long is four bytes. FIXME. */
354 unsigned long v1, v2;
356 v1 = unpack_long (builtin_type_long, valaddr);
357 v2 = unpack_long (builtin_type_long, valaddr + 4);
359 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
360 /* Swap the two for printing */
373 fprintf_filtered (stream, local_hex_format_custom("08x%08"), v1, v2);
376 error ("Output size \"g\" unimplemented for format \"%c\".",
382 val_long = unpack_long (type, valaddr);
384 /* If value is unsigned, truncate it in case negative. */
387 if (len == sizeof (char))
388 val_long &= (1 << 8 * sizeof(char)) - 1;
389 else if (len == sizeof (short))
390 val_long &= (1 << 8 * sizeof(short)) - 1;
391 else if (len == sizeof (long))
392 val_long &= (unsigned long) - 1;
400 /* no size specified, like in print. Print varying # of digits. */
401 #if defined (LONG_LONG)
402 fprintf_filtered (stream, local_hex_format_custom("ll"), val_long);
403 #else /* not LONG_LONG. */
404 fprintf_filtered (stream, local_hex_format_custom("l"), val_long);
405 #endif /* not LONG_LONG. */
408 #if defined (LONG_LONG)
412 fprintf_filtered (stream, local_hex_format_custom("02ll"), val_long);
415 fprintf_filtered (stream, local_hex_format_custom("04ll"), val_long);
418 fprintf_filtered (stream, local_hex_format_custom("08ll"), val_long);
421 fprintf_filtered (stream, local_hex_format_custom("016ll"), val_long);
424 error ("Undefined output size \"%c\".", size);
426 #else /* not LONG_LONG. */
430 fprintf_filtered (stream, local_hex_format_custom("02"), val_long);
433 fprintf_filtered (stream, local_hex_format_custom("04"), val_long);
436 fprintf_filtered (stream, local_hex_format_custom("08"), val_long);
439 fprintf_filtered (stream, local_hex_format_custom("016"), val_long);
442 error ("Undefined output size \"%c\".", size);
444 #endif /* not LONG_LONG */
449 fprintf_filtered (stream, local_decimal_format_custom("ll"), val_long);
451 fprintf_filtered (stream, local_decimal_format(), val_long);
457 fprintf_filtered (stream, "%llu", val_long);
459 fprintf_filtered (stream, "%u", val_long);
466 fprintf_filtered (stream, local_octal_format_custom("ll"), val_long);
468 fprintf_filtered (stream, local_octal_format(), val_long);
471 fprintf_filtered (stream, "0");
475 print_address (unpack_pointer (type, valaddr), stream);
479 value_print (value_from_longest (builtin_type_char, val_long), stream, 0,
484 if (len == sizeof (float))
485 type = builtin_type_float;
486 else if (len == sizeof (double))
487 type = builtin_type_double;
488 print_floating (valaddr, type, stream);
495 /* Binary; 't' stands for "two". */
497 char bits[8*(sizeof val_long) + 1];
502 width = 8*(sizeof val_long);
519 error ("Undefined output size \"%c\".", size);
525 bits[width] = (val_long & 1) ? '1' : '0';
530 while (*cp && *cp == '0')
535 fprintf_filtered (stream, local_binary_format_prefix());
536 fprintf_filtered (stream, cp);
537 fprintf_filtered (stream, local_binary_format_suffix());
542 error ("Undefined output format \"%c\".", format);
546 /* Specify default address for `x' command.
547 `info lines' uses this. */
550 set_next_address (addr)
555 /* Make address available to the user as $_. */
556 set_internalvar (lookup_internalvar ("_"),
557 value_from_longest (lookup_pointer_type (builtin_type_void),
561 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
562 after LEADIN. Print nothing if no symbolic name is found nearby.
563 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
564 or to interpret it as a possible C++ name and convert it back to source
565 form. However note that DO_DEMANGLE can be overridden by the specific
566 settings of the demangle and asm_demangle variables. */
569 print_address_symbolic (addr, stream, do_demangle, leadin)
575 CORE_ADDR name_location;
576 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (addr);
578 /* If nothing comes out, don't print anything symbolic. */
583 /* If the nearest symbol is too far away, ditto. */
585 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
587 /* For when CORE_ADDR is larger than unsigned int, we do math in
588 CORE_ADDR. But when we detect unsigned wraparound in the
589 CORE_ADDR math, we ignore this test and print the offset,
590 because addr+max_symbolic_offset has wrapped through the end
591 of the address space back to the beginning, giving bogus comparison. */
592 if (addr > name_location + max_symbolic_offset
593 && name_location + max_symbolic_offset > name_location)
596 fputs_filtered (leadin, stream);
597 fputs_filtered ("<", stream);
599 fputs_filtered (SYMBOL_SOURCE_NAME (msymbol), stream);
601 fputs_filtered (SYMBOL_LINKAGE_NAME (msymbol), stream);
602 if (addr != name_location)
603 fprintf_filtered (stream, "+%d>", (int)(addr - name_location));
605 fputs_filtered (">", stream);
608 /* Print address ADDR symbolically on STREAM.
609 First print it as a number. Then perhaps print
610 <SYMBOL + OFFSET> after the number. */
613 print_address (addr, stream)
617 #ifdef ADDR_BITS_REMOVE
618 fprintf_filtered (stream, local_hex_format(), ADDR_BITS_REMOVE(addr));
620 fprintf_filtered (stream, local_hex_format(), addr);
622 print_address_symbolic (addr, stream, asm_demangle, " ");
625 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
626 controls whether to print the symbolic name "raw" or demangled.
627 Global setting "addressprint" controls whether to print hex address
631 print_address_demangle (addr, stream, do_demangle)
637 fprintf_filtered (stream, "0");
638 } else if (addressprint) {
639 fprintf_filtered (stream, local_hex_format(), addr);
640 print_address_symbolic (addr, stream, do_demangle, " ");
642 print_address_symbolic (addr, stream, do_demangle, "");
647 /* Examine data at address ADDR in format FMT.
648 Fetch it from memory and print on stdout. */
651 do_examine (fmt, addr)
652 struct format_data fmt;
655 register char format = 0;
657 register int count = 1;
658 struct type *val_type;
660 register int maxelts;
667 /* String or instruction format implies fetch single bytes
668 regardless of the specified size. */
669 if (format == 's' || format == 'i')
673 val_type = builtin_type_char;
674 else if (size == 'h')
675 val_type = builtin_type_short;
676 else if (size == 'w')
677 val_type = builtin_type_long;
678 else if (size == 'g')
680 val_type = builtin_type_double;
682 val_type = builtin_type_long_long;
690 if (format == 's' || format == 'i')
693 /* Print as many objects as specified in COUNT, at most maxelts per line,
694 with the address of the next one at the start of each line. */
698 print_address (next_address, stdout);
699 printf_filtered (":");
704 printf_filtered ("\t");
705 /* Note that print_formatted sets next_address for the next
707 last_examine_address = next_address;
708 last_examine_value = value_at (val_type, next_address);
709 print_formatted (last_examine_value, format, size);
711 printf_filtered ("\n");
717 validate_format (fmt, cmdname)
718 struct format_data fmt;
722 error ("Size letters are meaningless in \"%s\" command.", cmdname);
724 error ("Item count other than 1 is meaningless in \"%s\" command.",
726 if (fmt.format == 'i' || fmt.format == 's')
727 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
728 fmt.format, cmdname);
731 /* Evaluate string EXP as an expression in the current language and
732 print the resulting value. EXP may contain a format specifier as the
733 first argument ("/x myvar" for example, to print myvar in hex).
737 print_command_1 (exp, inspect, voidprint)
742 struct expression *expr;
743 register struct cleanup *old_chain = 0;
744 register char format = 0;
746 struct format_data fmt;
749 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
750 inspect_it = inspect;
752 if (exp && *exp == '/')
755 fmt = decode_format (&exp, last_format, 0);
756 validate_format (fmt, "print");
757 last_format = format = fmt.format;
768 extern int objectprint;
770 expr = parse_expression (exp);
771 old_chain = make_cleanup (free_current_contents, &expr);
773 val = evaluate_expression (expr);
775 /* C++: figure out what type we actually want to print it as. */
776 type = VALUE_TYPE (val);
779 && ( TYPE_CODE (type) == TYPE_CODE_PTR
780 || TYPE_CODE (type) == TYPE_CODE_REF)
781 && ( TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT
782 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION))
786 v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
790 type = VALUE_TYPE (val);
795 val = access_value_history (0);
797 if (voidprint || (val && VALUE_TYPE (val) &&
798 TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
800 int histindex = record_latest_value (val);
803 printf ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
805 if (histindex >= 0) printf_filtered ("$%d = ", histindex);
807 print_formatted (val, format, fmt.size);
808 printf_filtered ("\n");
814 do_cleanups (old_chain);
815 inspect_it = 0; /* Reset print routines to normal */
820 print_command (exp, from_tty)
824 print_command_1 (exp, 0, 1);
827 /* Same as print, except in epoch, it gets its own window */
830 inspect_command (exp, from_tty)
834 extern int epoch_interface;
836 print_command_1 (exp, epoch_interface, 1);
839 /* Same as print, except it doesn't print void results. */
842 call_command (exp, from_tty)
846 print_command_1 (exp, 0, 0);
851 output_command (exp, from_tty)
855 struct expression *expr;
856 register struct cleanup *old_chain;
857 register char format = 0;
859 struct format_data fmt;
861 if (exp && *exp == '/')
864 fmt = decode_format (&exp, 0, 0);
865 validate_format (fmt, "output");
869 expr = parse_expression (exp);
870 old_chain = make_cleanup (free_current_contents, &expr);
872 val = evaluate_expression (expr);
874 print_formatted (val, format, fmt.size);
876 do_cleanups (old_chain);
881 set_command (exp, from_tty)
885 struct expression *expr = parse_expression (exp);
886 register struct cleanup *old_chain
887 = make_cleanup (free_current_contents, &expr);
888 evaluate_expression (expr);
889 do_cleanups (old_chain);
894 address_info (exp, from_tty)
898 register struct symbol *sym;
899 register struct minimal_symbol *msymbol;
901 register long basereg;
902 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
903 if exp is a field of `this'. */
906 error ("Argument required.");
908 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
909 &is_a_field_of_this, (struct symtab **)NULL);
912 if (is_a_field_of_this)
914 printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp);
918 msymbol = lookup_minimal_symbol (exp, (struct objfile *) NULL);
921 printf ("Symbol \"%s\" is at %s in a file compiled without debugging.\n",
922 exp, local_hex_string(SYMBOL_VALUE_ADDRESS (msymbol)));
924 error ("No symbol \"%s\" in current context.", exp);
928 printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym));
929 val = SYMBOL_VALUE (sym);
930 basereg = SYMBOL_BASEREG (sym);
932 switch (SYMBOL_CLASS (sym))
935 case LOC_CONST_BYTES:
940 printf ("a label at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
944 printf ("a variable in register %s", reg_names[val]);
948 printf ("static storage at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
952 printf ("an argument in register %s", reg_names[val]);
955 case LOC_REGPARM_ADDR:
956 printf ("address of an argument in register %s", reg_names[val]);
960 if (SYMBOL_BASEREG_VALID (sym))
962 printf ("an argument at offset %ld from register %s",
963 val, reg_names[basereg]);
967 printf ("an argument at offset %ld", val);
972 if (SYMBOL_BASEREG_VALID (sym))
974 printf ("an argument at offset %ld from register %s",
975 val, reg_names[basereg]);
979 printf ("an argument at frame offset %ld", val);
984 if (SYMBOL_BASEREG_VALID (sym))
986 printf ("a local variable at offset %ld from register %s",
987 val, reg_names[basereg]);
991 printf ("a local variable at frame offset %ld", val);
996 printf ("a reference argument at offset %ld", val);
1000 printf ("a typedef");
1004 printf ("a function at address %s",
1005 local_hex_string(BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
1008 case LOC_OPTIMIZED_OUT:
1009 printf_filtered ("optimized out");
1013 printf ("of unknown (botched) type");
1020 x_command (exp, from_tty)
1024 struct expression *expr;
1025 struct format_data fmt;
1026 struct cleanup *old_chain;
1029 fmt.format = last_format;
1030 fmt.size = last_size;
1033 if (exp && *exp == '/')
1036 fmt = decode_format (&exp, last_format, last_size);
1039 /* If we have an expression, evaluate it and use it as the address. */
1041 if (exp != 0 && *exp != 0)
1043 expr = parse_expression (exp);
1044 /* Cause expression not to be there any more
1045 if this command is repeated with Newline.
1046 But don't clobber a user-defined command's definition. */
1049 old_chain = make_cleanup (free_current_contents, &expr);
1050 val = evaluate_expression (expr);
1051 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
1052 val = value_ind (val);
1053 /* In rvalue contexts, such as this, functions are coerced into
1054 pointers to functions. This makes "x/i main" work. */
1055 if (/* last_format == 'i'
1056 && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
1057 && VALUE_LVAL (val) == lval_memory)
1058 next_address = VALUE_ADDRESS (val);
1060 next_address = value_as_pointer (val);
1061 do_cleanups (old_chain);
1064 do_examine (fmt, next_address);
1066 /* If the examine succeeds, we remember its size and format for next time. */
1067 last_size = fmt.size;
1068 last_format = fmt.format;
1070 /* Set a couple of internal variables if appropriate. */
1071 if (last_examine_value)
1073 /* Make last address examined available to the user as $_. Use
1074 the correct pointer type. */
1075 set_internalvar (lookup_internalvar ("_"),
1076 value_from_longest (
1077 lookup_pointer_type (VALUE_TYPE (last_examine_value)),
1078 (LONGEST) last_examine_address));
1080 /* Make contents of last address examined available to the user as $__.*/
1081 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1086 /* Add an expression to the auto-display chain.
1087 Specify the expression. */
1090 display_command (exp, from_tty)
1094 struct format_data fmt;
1095 register struct expression *expr;
1096 register struct display *new;
1107 fmt = decode_format (&exp, 0, 0);
1108 if (fmt.size && fmt.format == 0)
1110 if (fmt.format == 'i' || fmt.format == 's')
1120 innermost_block = 0;
1121 expr = parse_expression (exp);
1123 new = (struct display *) xmalloc (sizeof (struct display));
1126 new->block = innermost_block;
1127 new->next = display_chain;
1128 new->number = ++display_number;
1130 new->status = enabled;
1131 display_chain = new;
1133 if (from_tty && target_has_execution)
1134 do_one_display (new);
1147 /* Clear out the display_chain.
1148 Done when new symtabs are loaded, since this invalidates
1149 the types stored in many expressions. */
1154 register struct display *d;
1156 while ((d = display_chain) != NULL)
1159 display_chain = d->next;
1164 /* Delete the auto-display number NUM. */
1167 delete_display (num)
1170 register struct display *d1, *d;
1173 error ("No display number %d.", num);
1175 if (display_chain->number == num)
1178 display_chain = d1->next;
1182 for (d = display_chain; ; d = d->next)
1185 error ("No display number %d.", num);
1186 if (d->next->number == num)
1196 /* Delete some values from the auto-display chain.
1197 Specify the element numbers. */
1200 undisplay_command (args, from_tty)
1204 register char *p = args;
1210 if (query ("Delete all auto-display expressions? "))
1219 while (*p1 >= '0' && *p1 <= '9') p1++;
1220 if (*p1 && *p1 != ' ' && *p1 != '\t')
1221 error ("Arguments must be display numbers.");
1225 delete_display (num);
1228 while (*p == ' ' || *p == '\t') p++;
1233 /* Display a single auto-display.
1234 Do nothing if the display cannot be printed in the current context,
1235 or if the display is disabled. */
1241 int within_current_scope;
1243 if (d->status == disabled)
1247 within_current_scope = contained_in (get_selected_block (), d->block);
1249 within_current_scope = 1;
1250 if (!within_current_scope)
1253 current_display_number = d->number;
1255 printf_filtered ("%d: ", d->number);
1260 printf_filtered ("x/");
1261 if (d->format.count != 1)
1262 printf_filtered ("%d", d->format.count);
1263 printf_filtered ("%c", d->format.format);
1264 if (d->format.format != 'i' && d->format.format != 's')
1265 printf_filtered ("%c", d->format.size);
1266 printf_filtered (" ");
1267 print_expression (d->exp, stdout);
1268 if (d->format.count != 1)
1269 printf_filtered ("\n");
1271 printf_filtered (" ");
1273 addr = value_as_pointer (evaluate_expression (d->exp));
1274 if (d->format.format == 'i')
1275 addr = ADDR_BITS_REMOVE (addr);
1277 do_examine (d->format, addr);
1281 if (d->format.format)
1282 printf_filtered ("/%c ", d->format.format);
1283 print_expression (d->exp, stdout);
1284 printf_filtered (" = ");
1285 print_formatted (evaluate_expression (d->exp),
1286 d->format.format, d->format.size);
1287 printf_filtered ("\n");
1291 current_display_number = -1;
1294 /* Display all of the values on the auto-display chain which can be
1295 evaluated in the current scope. */
1300 register struct display *d;
1302 for (d = display_chain; d; d = d->next)
1306 /* Delete the auto-display which we were in the process of displaying.
1307 This is done when there is an error or a signal. */
1310 disable_display (num)
1313 register struct display *d;
1315 for (d = display_chain; d; d = d->next)
1316 if (d->number == num)
1318 d->status = disabled;
1321 printf ("No display number %d.\n", num);
1325 disable_current_display ()
1327 if (current_display_number >= 0)
1329 disable_display (current_display_number);
1330 fprintf (stderr, "Disabling display %d to avoid infinite recursion.\n",
1331 current_display_number);
1333 current_display_number = -1;
1337 display_info (ignore, from_tty)
1341 register struct display *d;
1344 printf ("There are no auto-display expressions now.\n");
1346 printf_filtered ("Auto-display expressions now in effect:\n\
1347 Num Enb Expression\n");
1349 for (d = display_chain; d; d = d->next)
1351 printf_filtered ("%d: %c ", d->number, "ny"[(int)d->status]);
1353 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1355 else if (d->format.format)
1356 printf_filtered ("/%c ", d->format.format);
1357 print_expression (d->exp, stdout);
1358 if (d->block && !contained_in (get_selected_block (), d->block))
1359 printf_filtered (" (cannot be evaluated in the current context)");
1360 printf_filtered ("\n");
1366 enable_display (args, from_tty)
1370 register char *p = args;
1373 register struct display *d;
1377 for (d = display_chain; d; d = d->next)
1378 d->status = enabled;
1384 while (*p1 >= '0' && *p1 <= '9')
1386 if (*p1 && *p1 != ' ' && *p1 != '\t')
1387 error ("Arguments must be display numbers.");
1391 for (d = display_chain; d; d = d->next)
1392 if (d->number == num)
1394 d->status = enabled;
1397 printf ("No display number %d.\n", num);
1400 while (*p == ' ' || *p == '\t')
1407 disable_display_command (args, from_tty)
1411 register char *p = args;
1413 register struct display *d;
1417 for (d = display_chain; d; d = d->next)
1418 d->status = disabled;
1424 while (*p1 >= '0' && *p1 <= '9')
1426 if (*p1 && *p1 != ' ' && *p1 != '\t')
1427 error ("Arguments must be display numbers.");
1429 disable_display (atoi (p));
1432 while (*p == ' ' || *p == '\t')
1438 /* Print the value in stack frame FRAME of a variable
1439 specified by a struct symbol. */
1442 print_variable_value (var, frame, stream)
1447 value val = read_var_value (var, frame);
1448 value_print (val, stream, 0, Val_pretty_default);
1451 /* Print the arguments of a stack frame, given the function FUNC
1452 running in that frame (as a symbol), the info on the frame,
1453 and the number of args according to the stack frame (or -1 if unknown). */
1455 /* References here and elsewhere to "number of args according to the
1456 stack frame" appear in all cases to refer to "number of ints of args
1457 according to the stack frame". At least for VAX, i386, isi. */
1460 print_frame_args (func, fi, num, stream)
1461 struct symbol *func;
1462 struct frame_info *fi;
1470 register struct symbol *sym;
1472 /* Offset of next stack argument beyond the one we have seen that is
1473 at the highest offset.
1474 -1 if we haven't come to a stack argument yet. */
1475 long highest_offset = -1;
1477 /* Number of ints of arguments that we have printed so far. */
1478 int args_printed = 0;
1482 b = SYMBOL_BLOCK_VALUE (func);
1483 nsyms = BLOCK_NSYMS (b);
1486 for (i = 0; i < nsyms; i++)
1489 sym = BLOCK_SYM (b, i);
1491 /* Keep track of the highest stack argument offset seen, and
1492 skip over any kinds of symbols we don't care about. */
1494 switch (SYMBOL_CLASS (sym)) {
1498 long current_offset = SYMBOL_VALUE (sym);
1500 arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1502 /* Compute address of next argument by adding the size of
1503 this argument and rounding to an int boundary. */
1505 = ((current_offset + arg_size + sizeof (int) - 1)
1506 & ~(sizeof (int) - 1));
1508 /* If this is the highest offset seen yet, set highest_offset. */
1509 if (highest_offset == -1
1510 || (current_offset > highest_offset))
1511 highest_offset = current_offset;
1513 /* Add the number of ints we're about to print to args_printed. */
1514 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
1517 /* We care about types of symbols, but don't need to keep track of
1518 stack offsets in them. */
1520 case LOC_REGPARM_ADDR:
1524 /* Other types of symbols we just skip over. */
1529 /* We have to look up the symbol because arguments can have
1530 two entries (one a parameter, one a local) and the one we
1531 want is the local, which lookup_symbol will find for us.
1532 This includes gcc1 (not gcc2) on the sparc when passing a
1533 small structure and gcc2 when the argument type is float
1534 and it is passed as a double and converted to float by
1535 the prologue (in the latter case the type of the LOC_ARG
1536 symbol is double and the type of the LOC_LOCAL symbol is
1537 float). It's possible this should be dealt with in
1538 symbol reading the way it now is for LOC_REGPARM. */
1539 /* But if the parameter name is null, don't try it.
1540 Null parameter names occur on the RS/6000, for traceback tables.
1541 FIXME, should we even print them? */
1543 if (*SYMBOL_NAME (sym))
1546 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
1548 /* Print the current arg. */
1550 fprintf_filtered (stream, ", ");
1552 fprintf_symbol_filtered (stream, SYMBOL_SOURCE_NAME (sym),
1553 SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
1554 fputs_filtered ("=", stream);
1556 /* Avoid value_print because it will deref ref parameters. We just
1557 want to print their addresses. Print ??? for args whose address
1558 we do not know. We pass 2 as "recurse" to val_print because our
1559 standard indentation here is 4 spaces, and val_print indents
1560 2 for each recurse. */
1561 val = read_var_value (sym, FRAME_INFO_ID (fi));
1563 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val),
1564 stream, 0, 0, 2, Val_no_prettyprint);
1566 fputs_filtered ("???", stream);
1570 /* Don't print nameless args in situations where we don't know
1571 enough about the stack to find them. */
1576 if (highest_offset == -1)
1577 start = FRAME_ARGS_SKIP;
1579 start = highest_offset;
1581 print_frame_nameless_args (fi, start, num - args_printed,
1586 /* Print nameless args on STREAM.
1587 FI is the frameinfo for this frame, START is the offset
1588 of the first nameless arg, and NUM is the number of nameless args to
1589 print. FIRST is nonzero if this is the first argument (not just
1590 the first nameless arg). */
1592 print_frame_nameless_args (fi, start, num, first, stream)
1593 struct frame_info *fi;
1603 for (i = 0; i < num; i++)
1606 #ifdef NAMELESS_ARG_VALUE
1607 NAMELESS_ARG_VALUE (fi, start, &arg_value);
1609 argsaddr = FRAME_ARGS_ADDRESS (fi);
1613 arg_value = read_memory_integer (argsaddr + start, sizeof (int));
1617 fprintf_filtered (stream, ", ");
1619 #ifdef PRINT_NAMELESS_INTEGER
1620 PRINT_NAMELESS_INTEGER (stream, arg_value);
1622 #ifdef PRINT_TYPELESS_INTEGER
1623 PRINT_TYPELESS_INTEGER (stream, builtin_type_int, (LONGEST) arg_value);
1625 fprintf_filtered (stream, "%d", arg_value);
1626 #endif /* PRINT_TYPELESS_INTEGER */
1627 #endif /* PRINT_NAMELESS_INTEGER */
1629 start += sizeof (int);
1635 printf_command (arg, from_tty)
1640 register char *s = arg;
1644 int allocated_args = 20;
1647 val_args = (value *) xmalloc (allocated_args * sizeof (value));
1650 error_no_arg ("format-control string and values to print");
1652 /* Skip white space before format string */
1653 while (*s == ' ' || *s == '\t') s++;
1655 /* A format string should follow, enveloped in double quotes */
1657 error ("Bad format string, missing '\"'.");
1659 /* Parse the format-control string and copy it into the string STRING,
1660 processing some kinds of escape sequence. */
1662 f = string = (char *) alloca (strlen (s) + 1);
1669 error ("Bad format string, non-terminated '\"'.");
1670 /* doesn't return */
1691 /* ??? TODO: handle other escape sequences */
1692 error ("Unrecognized \\ escape character in format string.");
1701 /* Skip over " and following space and comma. */
1704 while (*s == ' ' || *s == '\t') s++;
1706 if (*s != ',' && *s != 0)
1707 error ("Invalid argument syntax");
1710 while (*s == ' ' || *s == '\t') s++;
1713 /* Now scan the string for %-specs and see what kinds of args they want.
1714 argclass[I] classifies the %-specs so we can give vprintf something
1715 of the right size. */
1717 enum argclass {int_arg, string_arg, double_arg, long_long_arg};
1718 enum argclass *argclass;
1724 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1731 while (strchr ("0123456789.hlL-+ #", *f))
1733 if (*f == 'l' || *f == 'L')
1738 argclass[nargs_wanted++] = string_arg;
1739 else if (*f == 'e' || *f == 'f' || *f == 'g')
1740 argclass[nargs_wanted++] = double_arg;
1741 else if (lcount > 1)
1742 argclass[nargs_wanted++] = long_long_arg;
1744 argclass[nargs_wanted++] = int_arg;
1748 /* Now, parse all arguments and evaluate them.
1749 Store the VALUEs in VAL_ARGS. */
1754 if (nargs == allocated_args)
1755 val_args = (value *) xrealloc ((char *) val_args,
1756 (allocated_args *= 2)
1759 val_args[nargs] = parse_to_comma_and_eval (&s1);
1761 /* If format string wants a float, unchecked-convert the value to
1762 floating point of the same size */
1764 if (argclass[nargs] == double_arg)
1766 if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (float))
1767 VALUE_TYPE (val_args[nargs]) = builtin_type_float;
1768 if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (double))
1769 VALUE_TYPE (val_args[nargs]) = builtin_type_double;
1777 if (nargs != nargs_wanted)
1778 error ("Wrong number of arguments for specified format-string");
1780 /* Now lay out an argument-list containing the arguments
1781 as doubles, integers and C pointers. */
1783 arg_bytes = (char *) alloca (sizeof (double) * nargs);
1785 for (i = 0; i < nargs; i++)
1787 if (argclass[i] == string_arg)
1792 tem = value_as_pointer (val_args[i]);
1794 /* This is a %s argument. Find the length of the string. */
1799 read_memory (tem + j, &c, 1);
1804 /* Copy the string contents into a string inside GDB. */
1805 str = (char *) alloca (j + 1);
1806 read_memory (tem, str, j);
1809 /* Pass address of internal copy as the arg to vprintf. */
1810 *((int *) &arg_bytes[argindex]) = (int) str;
1811 argindex += sizeof (int);
1813 else if (VALUE_TYPE (val_args[i])->code == TYPE_CODE_FLT)
1815 *((double *) &arg_bytes[argindex]) = value_as_double (val_args[i]);
1816 argindex += sizeof (double);
1820 if (argclass[i] == long_long_arg)
1822 *(long long *) &arg_bytes[argindex] = value_as_long (val_args[i]);
1823 argindex += sizeof (long long);
1828 *((long *) &arg_bytes[argindex]) = value_as_long (val_args[i]);
1829 argindex += sizeof (long);
1834 /* There is not a standard way to make a va_list, so we need
1835 to do various things for different systems. */
1836 #if defined (__INT_VARARGS_H)
1841 list.__va_stk = (int *) arg_bytes;
1842 list.__va_reg = (int *) arg_bytes;
1843 vprintf (string, list);
1845 #else /* No __INT_VARARGS_H. */
1846 vprintf (string, arg_bytes);
1847 #endif /* No __INT_VARARGS_H. */
1850 /* Helper function for asdump_command. Finds the bounds of a function
1851 for a specified section of text. PC is an address within the
1852 function which you want bounds for; *LOW and *HIGH are set to the
1853 beginning (inclusive) and end (exclusive) of the function. This
1854 function returns 1 on success and 0 on failure. */
1857 containing_function_bounds (pc, low, high)
1858 CORE_ADDR pc, *low, *high;
1862 struct obj_section *sec;
1864 if (!find_pc_partial_function (pc, 0, low))
1867 sec = find_pc_section (pc);
1870 limit = sec->endaddr;
1873 while (scan < limit)
1876 if (!find_pc_partial_function (scan, 0, high))
1885 /* Dump a specified section of assembly code. With no command line
1886 arguments, this command will dump the assembly code for the
1887 function surrounding the pc value in the selected frame. With one
1888 argument, it will dump the assembly code surrounding that pc value.
1889 Two arguments are interpeted as bounds within which to dump
1894 disassemble_command (arg, from_tty)
1898 CORE_ADDR low, high;
1904 if (!selected_frame)
1905 error ("No frame selected.\n");
1907 pc = get_frame_pc (selected_frame);
1908 if (!containing_function_bounds (pc, &low, &high))
1909 error ("No function contains pc specified by selected frame.\n");
1911 else if (!(space_index = (char *) strchr (arg, ' ')))
1914 pc = parse_and_eval_address (arg);
1915 if (!containing_function_bounds (pc, &low, &high))
1916 error ("No function contains specified pc.\n");
1920 /* Two arguments. */
1921 *space_index = '\0';
1922 low = parse_and_eval_address (arg);
1923 high = parse_and_eval_address (space_index + 1);
1926 printf_filtered ("Dump of assembler code ");
1930 find_pc_partial_function (pc, &name, 0);
1931 printf_filtered ("for function %s:\n", name);
1935 printf_filtered ("from %s ", local_hex_string(low));
1936 printf_filtered ("to %s:\n", local_hex_string(high));
1939 /* Dump the specified range. */
1940 for (pc = low; pc < high; )
1943 print_address (pc, stdout);
1944 printf_filtered (":\t");
1945 pc += print_insn (pc, stdout);
1946 printf_filtered ("\n");
1948 printf_filtered ("End of assembler dump.\n");
1954 _initialize_printcmd ()
1956 current_display_number = -1;
1958 add_info ("address", address_info,
1959 "Describe where variable VAR is stored.");
1961 add_com ("x", class_vars, x_command,
1962 "Examine memory: x/FMT ADDRESS.\n\
1963 ADDRESS is an expression for the memory address to examine.\n\
1964 FMT is a repeat count followed by a format letter and a size letter.\n\
1965 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1966 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
1967 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1968 The specified number of objects of the specified size are printed\n\
1969 according to the format.\n\n\
1970 Defaults for format and size letters are those previously used.\n\
1971 Default count is 1. Default address is following last thing printed\n\
1972 with this command or \"print\".");
1974 add_com ("disassemble", class_vars, disassemble_command,
1975 "Disassemble a specified section of memory.\n\
1976 Default is the function surrounding the pc of the selected frame.\n\
1977 With a single argument, the function surrounding that address is dumped.\n\
1978 Two arguments are taken as a range of memory to dump.");
1981 add_com ("whereis", class_vars, whereis_command,
1982 "Print line number and file of definition of variable.");
1985 add_info ("display", display_info,
1986 "Expressions to display when program stops, with code numbers.");
1988 add_cmd ("undisplay", class_vars, undisplay_command,
1989 "Cancel some expressions to be displayed when program stops.\n\
1990 Arguments are the code numbers of the expressions to stop displaying.\n\
1991 No argument means cancel all automatic-display expressions.\n\
1992 \"delete display\" has the same effect as this command.\n\
1993 Do \"info display\" to see current list of code numbers.",
1996 add_com ("display", class_vars, display_command,
1997 "Print value of expression EXP each time the program stops.\n\
1998 /FMT may be used before EXP as in the \"print\" command.\n\
1999 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2000 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2001 and examining is done as in the \"x\" command.\n\n\
2002 With no argument, display all currently requested auto-display expressions.\n\
2003 Use \"undisplay\" to cancel display requests previously made.");
2005 add_cmd ("display", class_vars, enable_display,
2006 "Enable some expressions to be displayed when program stops.\n\
2007 Arguments are the code numbers of the expressions to resume displaying.\n\
2008 No argument means enable all automatic-display expressions.\n\
2009 Do \"info display\" to see current list of code numbers.", &enablelist);
2011 add_cmd ("display", class_vars, disable_display_command,
2012 "Disable some expressions to be displayed when program stops.\n\
2013 Arguments are the code numbers of the expressions to stop displaying.\n\
2014 No argument means disable all automatic-display expressions.\n\
2015 Do \"info display\" to see current list of code numbers.", &disablelist);
2017 add_cmd ("display", class_vars, undisplay_command,
2018 "Cancel some expressions to be displayed when program stops.\n\
2019 Arguments are the code numbers of the expressions to stop displaying.\n\
2020 No argument means cancel all automatic-display expressions.\n\
2021 Do \"info display\" to see current list of code numbers.", &deletelist);
2023 add_com ("printf", class_vars, printf_command,
2024 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2025 This is useful for formatted output in user-defined commands.");
2026 add_com ("output", class_vars, output_command,
2027 "Like \"print\" but don't put in value history and don't print newline.\n\
2028 This is useful in user-defined commands.");
2030 add_prefix_cmd ("set", class_vars, set_command,
2031 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2032 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2033 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2034 with $), a register (a few standard names starting with $), or an actual\n\
2035 variable in the program being debugged. EXP is any valid expression.\n\
2036 Use \"set variable\" for variables with names identical to set subcommands.\n\
2037 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2038 You can see these environment settings with the \"show\" command.",
2039 &setlist, "set ", 1, &cmdlist);
2041 /* "call" is the same as "set", but handy for dbx users to call fns. */
2042 add_com ("call", class_vars, call_command,
2043 "Call a function in the inferior process.\n\
2044 The argument is the function name and arguments, in the notation of the\n\
2045 current working language. The result is printed and saved in the value\n\
2046 history, if it is not void.");
2048 add_cmd ("variable", class_vars, set_command,
2049 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2050 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2051 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2052 with $), a register (a few standard names starting with $), or an actual\n\
2053 variable in the program being debugged. EXP is any valid expression.\n\
2054 This may usually be abbreviated to simply \"set\".",
2057 add_com ("print", class_vars, print_command,
2058 concat ("Print value of expression EXP.\n\
2059 Variables accessible are those of the lexical environment of the selected\n\
2060 stack frame, plus all those whose scope is global or an entire file.\n\
2062 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2063 $$NUM refers to NUM'th value back from the last one.\n\
2064 Names starting with $ refer to registers (with the values they would have\n\
2065 if the program were to return to the stack frame now selected, restoring\n\
2066 all registers saved by frames farther in) or else to debugger\n\
2067 \"convenience\" variables (any such name not a known register).\n\
2068 Use assignment expressions to give values to convenience variables.\n",
2070 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2071 @ is a binary operator for treating consecutive data objects\n\
2072 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2073 element is FOO, whose second element is stored in the space following\n\
2074 where FOO is stored, etc. FOO must be an expression whose value\n\
2075 resides in memory.\n",
2077 EXP may be preceded with /FMT, where FMT is a format letter\n\
2078 but no count or size letter (see \"x\" command).", NULL));
2079 add_com_alias ("p", "print", class_vars, 1);
2081 add_com ("inspect", class_vars, inspect_command,
2082 "Same as \"print\" command, except that if you are running in the epoch\n\
2083 environment, the value is printed in its own window.");
2086 add_set_cmd ("max-symbolic-offset", no_class, var_uinteger,
2087 (char *)&max_symbolic_offset,
2088 "Set the largest offset that will be printed in <symbol+1234> form.",