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 extern int asm_demangle; /* Whether to demangle syms in asm printouts */
35 extern int addressprint; /* Whether to print hex addresses in HLL " */
44 /* Last specified output format. */
46 static char last_format = 'x';
48 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
50 static char last_size = 'w';
52 /* Default address to examine next. */
54 static CORE_ADDR next_address;
56 /* Last address examined. */
58 static CORE_ADDR last_examine_address;
60 /* Contents of last address examined.
61 This is not valid past the end of the `x' command! */
63 static value last_examine_value;
65 /* Number of auto-display expression currently being displayed.
66 So that we can deleted it if we get an error or a signal within it.
67 -1 when not doing one. */
69 int current_display_number;
71 /* Flag to low-level print routines that this value is being printed
72 in an epoch window. We'd like to pass this as a parameter, but
73 every routine would need to take it. Perhaps we can encapsulate
74 this in the I/O stream once we have GNU stdio. */
80 /* Chain link to next auto-display item. */
82 /* Expression to be evaluated and displayed. */
83 struct expression *exp;
84 /* Item number of this auto-display item. */
86 /* Display format specified. */
87 struct format_data format;
88 /* Innermost block required by this expression when evaluated */
90 /* Status of this display (enabled or disabled) */
94 /* Chain of expressions whose values should be displayed
95 automatically each time the program stops. */
97 static struct display *display_chain;
99 static int display_number;
101 /* Prototypes for local functions */
104 delete_display PARAMS ((int));
107 enable_display PARAMS ((char *, int));
110 disable_display_command PARAMS ((char *, int));
113 disassemble_command PARAMS ((char *, int));
116 containing_function_bounds PARAMS ((CORE_ADDR, CORE_ADDR *, CORE_ADDR *));
119 printf_command PARAMS ((char *, int));
122 print_frame_nameless_args PARAMS ((CORE_ADDR, long, int, int, FILE *));
125 display_info PARAMS ((char *, int));
128 do_one_display PARAMS ((struct display *));
131 undisplay_command PARAMS ((char *, int));
134 free_display PARAMS ((struct display *));
137 display_command PARAMS ((char *, int));
140 ptype_command PARAMS ((char *, int));
143 ptype_eval PARAMS ((struct expression *));
146 whatis_command PARAMS ((char *, int));
149 whatis_exp 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_STRUCT
321 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_UNION
322 || VALUE_REPEATED (val))
323 value_print (val, stdout, format, Val_pretty_default);
325 print_scalar_formatted (VALUE_CONTENTS (val), VALUE_TYPE (val),
326 format, size, stdout);
330 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
331 according to letters FORMAT and SIZE on STREAM.
332 FORMAT may not be zero. Formats s and i are not supported at this level.
334 This is how the elements of an array or structure are printed
338 print_scalar_formatted (valaddr, type, format, size, stream)
346 int len = TYPE_LENGTH (type);
348 if (size == 'g' && sizeof (LONGEST) < 8
351 /* ok, we're going to have to get fancy here. Assumption: a
352 long is four bytes. FIXME. */
353 unsigned long v1, v2;
355 v1 = unpack_long (builtin_type_long, valaddr);
356 v2 = unpack_long (builtin_type_long, valaddr + 4);
358 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
359 /* Swap the two for printing */
372 fprintf_filtered (stream, local_hex_format_custom("08x%08"), v1, v2);
375 error ("Output size \"g\" unimplemented for format \"%c\".",
381 val_long = unpack_long (type, valaddr);
383 /* If value is unsigned, truncate it in case negative. */
386 if (len == sizeof (char))
387 val_long &= (1 << 8 * sizeof(char)) - 1;
388 else if (len == sizeof (short))
389 val_long &= (1 << 8 * sizeof(short)) - 1;
390 else if (len == sizeof (long))
391 val_long &= (unsigned long) - 1;
399 /* no size specified, like in print. Print varying # of digits. */
400 #if defined (LONG_LONG)
401 fprintf_filtered (stream, local_hex_format_custom("ll"), val_long);
402 #else /* not LONG_LONG. */
403 fprintf_filtered (stream, local_hex_format_custom("l"), val_long);
404 #endif /* not LONG_LONG. */
407 #if defined (LONG_LONG)
411 fprintf_filtered (stream, local_hex_format_custom("02ll"), val_long);
414 fprintf_filtered (stream, local_hex_format_custom("04ll"), val_long);
417 fprintf_filtered (stream, local_hex_format_custom("08ll"), val_long);
420 fprintf_filtered (stream, local_hex_format_custom("016ll"), val_long);
423 error ("Undefined output size \"%c\".", size);
425 #else /* not LONG_LONG. */
429 fprintf_filtered (stream, local_hex_format_custom("02"), val_long);
432 fprintf_filtered (stream, local_hex_format_custom("04"), val_long);
435 fprintf_filtered (stream, local_hex_format_custom("08"), val_long);
438 fprintf_filtered (stream, local_hex_format_custom("016"), val_long);
441 error ("Undefined output size \"%c\".", size);
443 #endif /* not LONG_LONG */
448 fprintf_filtered (stream, "%lld", val_long);
450 fprintf_filtered (stream, "%d", val_long);
456 fprintf_filtered (stream, "%llu", val_long);
458 fprintf_filtered (stream, "%u", val_long);
465 fprintf_filtered (stream, local_octal_format_custom("ll"), val_long);
467 fprintf_filtered (stream, local_octal_format(), val_long);
470 fprintf_filtered (stream, "0");
474 print_address (unpack_pointer (type, valaddr), stream);
478 value_print (value_from_longest (builtin_type_char, val_long), stream, 0,
483 if (len == sizeof (float))
484 type = builtin_type_float;
485 else if (len == sizeof (double))
486 type = builtin_type_double;
487 print_floating (valaddr, type, stream);
494 /* Binary; 't' stands for "two". */
496 char bits[8*(sizeof val_long) + 1];
501 width = 8*(sizeof val_long);
518 error ("Undefined output size \"%c\".", size);
524 bits[width] = (val_long & 1) ? '1' : '0';
529 while (*cp && *cp == '0')
534 fprintf_filtered (stream, cp);
539 error ("Undefined output format \"%c\".", format);
543 /* Specify default address for `x' command.
544 `info lines' uses this. */
547 set_next_address (addr)
552 /* Make address available to the user as $_. */
553 set_internalvar (lookup_internalvar ("_"),
554 value_from_longest (lookup_pointer_type (builtin_type_void),
558 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
559 after LEADIN. Print nothing if no symbolic name is found nearby.
560 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
561 or to interpret it as a possible C++ name and convert it back to source
565 print_address_symbolic (addr, stream, do_demangle, leadin)
572 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (addr);
574 /* If nothing comes out, don't print anything symbolic. */
579 fputs_filtered (leadin, stream);
580 fputs_filtered ("<", stream);
582 fputs_demangled (msymbol -> name, stream, DMGL_ANSI | DMGL_PARAMS);
584 fputs_filtered (msymbol -> name, stream);
585 name_location = msymbol -> address;
586 if (addr - name_location)
587 fprintf_filtered (stream, "+%d>", addr - name_location);
589 fputs_filtered (">", stream);
592 /* Print address ADDR symbolically on STREAM.
593 First print it as a number. Then perhaps print
594 <SYMBOL + OFFSET> after the number. */
597 print_address (addr, stream)
601 #ifdef ADDR_BITS_REMOVE
602 fprintf_filtered (stream, local_hex_format(), ADDR_BITS_REMOVE(addr));
604 fprintf_filtered (stream, local_hex_format(), addr);
606 print_address_symbolic (addr, stream, asm_demangle, " ");
609 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
610 controls whether to print the symbolic name "raw" or demangled.
611 Global setting "addressprint" controls whether to print hex address
615 print_address_demangle (addr, stream, do_demangle)
621 fprintf_filtered (stream, "0");
622 } else if (addressprint) {
623 fprintf_filtered (stream, local_hex_format(), addr);
624 print_address_symbolic (addr, stream, do_demangle, " ");
626 print_address_symbolic (addr, stream, do_demangle, "");
631 /* Examine data at address ADDR in format FMT.
632 Fetch it from memory and print on stdout. */
635 do_examine (fmt, addr)
636 struct format_data fmt;
639 register char format = 0;
641 register int count = 1;
642 struct type *val_type;
644 register int maxelts;
651 /* String or instruction format implies fetch single bytes
652 regardless of the specified size. */
653 if (format == 's' || format == 'i')
657 val_type = builtin_type_char;
658 else if (size == 'h')
659 val_type = builtin_type_short;
660 else if (size == 'w')
661 val_type = builtin_type_long;
662 else if (size == 'g')
664 val_type = builtin_type_double;
666 val_type = builtin_type_long_long;
674 if (format == 's' || format == 'i')
677 /* Print as many objects as specified in COUNT, at most maxelts per line,
678 with the address of the next one at the start of each line. */
682 print_address (next_address, stdout);
683 printf_filtered (":");
688 printf_filtered ("\t");
689 /* Note that print_formatted sets next_address for the next
691 last_examine_address = next_address;
692 last_examine_value = value_at (val_type, next_address);
693 print_formatted (last_examine_value, format, size);
695 printf_filtered ("\n");
701 validate_format (fmt, cmdname)
702 struct format_data fmt;
706 error ("Size letters are meaningless in \"%s\" command.", cmdname);
708 error ("Item count other than 1 is meaningless in \"%s\" command.",
710 if (fmt.format == 'i' || fmt.format == 's')
711 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
712 fmt.format, cmdname);
716 print_command_1 (exp, inspect, voidprint)
721 struct expression *expr;
722 register struct cleanup *old_chain = 0;
723 register char format = 0;
725 struct format_data fmt;
728 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
729 inspect_it = inspect;
731 if (exp && *exp == '/')
734 fmt = decode_format (&exp, last_format, 0);
735 validate_format (fmt, "print");
736 last_format = format = fmt.format;
747 extern int objectprint;
749 expr = parse_expression (exp);
750 old_chain = make_cleanup (free_current_contents, &expr);
752 val = evaluate_expression (expr);
754 /* C++: figure out what type we actually want to print it as. */
755 type = VALUE_TYPE (val);
758 && ( TYPE_CODE (type) == TYPE_CODE_PTR
759 || TYPE_CODE (type) == TYPE_CODE_REF)
760 && ( TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT
761 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION))
765 v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
769 type = VALUE_TYPE (val);
774 val = access_value_history (0);
776 if (voidprint || (val && VALUE_TYPE (val) &&
777 TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
779 int histindex = record_latest_value (val);
782 printf ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
784 if (histindex >= 0) printf_filtered ("$%d = ", histindex);
786 print_formatted (val, format, fmt.size);
787 printf_filtered ("\n");
793 do_cleanups (old_chain);
794 inspect_it = 0; /* Reset print routines to normal */
799 print_command (exp, from_tty)
803 print_command_1 (exp, 0, 1);
806 /* Same as print, except in epoch, it gets its own window */
809 inspect_command (exp, from_tty)
813 extern int epoch_interface;
815 print_command_1 (exp, epoch_interface, 1);
818 /* Same as print, except it doesn't print void results. */
821 call_command (exp, from_tty)
825 print_command_1 (exp, 0, 0);
830 output_command (exp, from_tty)
834 struct expression *expr;
835 register struct cleanup *old_chain;
836 register char format = 0;
838 struct format_data fmt;
840 if (exp && *exp == '/')
843 fmt = decode_format (&exp, 0, 0);
844 validate_format (fmt, "output");
848 expr = parse_expression (exp);
849 old_chain = make_cleanup (free_current_contents, &expr);
851 val = evaluate_expression (expr);
853 print_formatted (val, format, fmt.size);
855 do_cleanups (old_chain);
860 set_command (exp, from_tty)
864 struct expression *expr = parse_expression (exp);
865 register struct cleanup *old_chain
866 = make_cleanup (free_current_contents, &expr);
867 evaluate_expression (expr);
868 do_cleanups (old_chain);
873 address_info (exp, from_tty)
877 register struct symbol *sym;
878 register struct minimal_symbol *msymbol;
880 register long basereg;
881 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
882 if exp is a field of `this'. */
885 error ("Argument required.");
887 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
888 &is_a_field_of_this, (struct symtab **)NULL);
891 if (is_a_field_of_this)
893 printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp);
897 msymbol = lookup_minimal_symbol (exp, (struct objfile *) NULL);
900 printf ("Symbol \"%s\" is at %s in a file compiled without debugging.\n",
901 exp, local_hex_string(msymbol -> address));
903 error ("No symbol \"%s\" in current context.", exp);
907 printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym));
908 val = SYMBOL_VALUE (sym);
909 basereg = SYMBOL_BASEREG (sym);
911 switch (SYMBOL_CLASS (sym))
914 case LOC_CONST_BYTES:
919 printf ("a label at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
923 printf ("a variable in register %s", reg_names[val]);
927 printf ("static storage at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
931 printf ("an argument in register %s", reg_names[val]);
935 if (SYMBOL_BASEREG_VALID (sym))
937 printf ("an argument at offset %ld from register %s",
938 val, reg_names[basereg]);
942 printf ("an argument at offset %ld", val);
947 if (SYMBOL_BASEREG_VALID (sym))
949 printf ("an argument at offset %ld from register %s",
950 val, reg_names[basereg]);
954 printf ("an argument at frame offset %ld", val);
959 if (SYMBOL_BASEREG_VALID (sym))
961 printf ("a local variable at offset %ld from register %s",
962 val, reg_names[basereg]);
966 printf ("a local variable at frame offset %ld", val);
971 printf ("a reference argument at offset %ld", val);
975 printf ("a typedef");
979 printf ("a function at address %s",
980 local_hex_string(BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
984 printf ("of unknown (botched) type");
991 x_command (exp, from_tty)
995 struct expression *expr;
996 struct format_data fmt;
997 struct cleanup *old_chain;
1000 fmt.format = last_format;
1001 fmt.size = last_size;
1004 if (exp && *exp == '/')
1007 fmt = decode_format (&exp, last_format, last_size);
1010 /* If we have an expression, evaluate it and use it as the address. */
1012 if (exp != 0 && *exp != 0)
1014 expr = parse_expression (exp);
1015 /* Cause expression not to be there any more
1016 if this command is repeated with Newline.
1017 But don't clobber a user-defined command's definition. */
1020 old_chain = make_cleanup (free_current_contents, &expr);
1021 val = evaluate_expression (expr);
1022 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
1023 val = value_ind (val);
1024 /* In rvalue contexts, such as this, functions are coerced into
1025 pointers to functions. This makes "x/i main" work. */
1026 if (/* last_format == 'i'
1027 && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
1028 && VALUE_LVAL (val) == lval_memory)
1029 next_address = VALUE_ADDRESS (val);
1031 next_address = value_as_pointer (val);
1032 do_cleanups (old_chain);
1035 do_examine (fmt, next_address);
1037 /* If the examine succeeds, we remember its size and format for next time. */
1038 last_size = fmt.size;
1039 last_format = fmt.format;
1041 /* Set a couple of internal variables if appropriate. */
1042 if (last_examine_value)
1044 /* Make last address examined available to the user as $_. Use
1045 the correct pointer type. */
1046 set_internalvar (lookup_internalvar ("_"),
1047 value_from_longest (
1048 lookup_pointer_type (VALUE_TYPE (last_examine_value)),
1049 (LONGEST) last_examine_address));
1051 /* Make contents of last address examined available to the user as $__.*/
1052 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1056 /* Commands for printing types of things. */
1058 /* Print type of EXP, or last thing in value history if EXP == NULL.
1059 show is passed to type_print. */
1061 whatis_exp (exp, show)
1065 struct expression *expr;
1067 register struct cleanup *old_chain;
1071 expr = parse_expression (exp);
1072 old_chain = make_cleanup (free_current_contents, &expr);
1073 val = evaluate_type (expr);
1076 val = access_value_history (0);
1078 printf_filtered ("type = ");
1079 type_print (VALUE_TYPE (val), "", stdout, show);
1080 printf_filtered ("\n");
1083 do_cleanups (old_chain);
1088 whatis_command (exp, from_tty)
1092 /* Most of the time users do not want to see all the fields
1093 in a structure. If they do they can use the "ptype" command.
1094 Hence the "-1" below. */
1095 whatis_exp (exp, -1);
1098 /* Simple subroutine for ptype_command. */
1102 struct expression *exp;
1104 if(exp->elts[0].opcode==OP_TYPE)
1105 return exp->elts[1].type;
1110 /* TYPENAME is either the name of a type, or an expression. */
1113 ptype_command (typename, from_tty)
1117 register struct type *type;
1118 struct expression *expr;
1119 register struct cleanup *old_chain;
1123 expr = parse_expression (typename);
1124 old_chain = make_cleanup (free_current_contents, &expr);
1125 type = ptype_eval (expr);
1129 printf_filtered ("type = ");
1130 type_print (type, "", stdout, 1);
1131 printf_filtered ("\n");
1132 do_cleanups (old_chain);
1136 do_cleanups (old_chain);
1137 whatis_exp (typename, 1);
1141 whatis_exp (typename, 1);
1144 /* Add an expression to the auto-display chain.
1145 Specify the expression. */
1148 display_command (exp, from_tty)
1152 struct format_data fmt;
1153 register struct expression *expr;
1154 register struct display *new;
1165 fmt = decode_format (&exp, 0, 0);
1166 if (fmt.size && fmt.format == 0)
1168 if (fmt.format == 'i' || fmt.format == 's')
1178 innermost_block = 0;
1179 expr = parse_expression (exp);
1181 new = (struct display *) xmalloc (sizeof (struct display));
1184 new->block = innermost_block;
1185 new->next = display_chain;
1186 new->number = ++display_number;
1188 new->status = enabled;
1189 display_chain = new;
1191 if (from_tty && target_has_execution)
1192 do_one_display (new);
1205 /* Clear out the display_chain.
1206 Done when new symtabs are loaded, since this invalidates
1207 the types stored in many expressions. */
1212 register struct display *d;
1214 while (d = display_chain)
1217 display_chain = d->next;
1222 /* Delete the auto-display number NUM. */
1225 delete_display (num)
1228 register struct display *d1, *d;
1231 error ("No display number %d.", num);
1233 if (display_chain->number == num)
1236 display_chain = d1->next;
1240 for (d = display_chain; ; d = d->next)
1243 error ("No display number %d.", num);
1244 if (d->next->number == num)
1254 /* Delete some values from the auto-display chain.
1255 Specify the element numbers. */
1258 undisplay_command (args, from_tty)
1262 register char *p = args;
1268 if (query ("Delete all auto-display expressions? "))
1277 while (*p1 >= '0' && *p1 <= '9') p1++;
1278 if (*p1 && *p1 != ' ' && *p1 != '\t')
1279 error ("Arguments must be display numbers.");
1283 delete_display (num);
1286 while (*p == ' ' || *p == '\t') p++;
1291 /* Display a single auto-display.
1292 Do nothing if the display cannot be printed in the current context,
1293 or if the display is disabled. */
1299 int within_current_scope;
1301 if (d->status == disabled)
1305 within_current_scope = contained_in (get_selected_block (), d->block);
1307 within_current_scope = 1;
1308 if (!within_current_scope)
1311 current_display_number = d->number;
1313 printf_filtered ("%d: ", d->number);
1318 printf_filtered ("x/");
1319 if (d->format.count != 1)
1320 printf_filtered ("%d", d->format.count);
1321 printf_filtered ("%c", d->format.format);
1322 if (d->format.format != 'i' && d->format.format != 's')
1323 printf_filtered ("%c", d->format.size);
1324 printf_filtered (" ");
1325 print_expression (d->exp, stdout);
1326 if (d->format.count != 1)
1327 printf_filtered ("\n");
1329 printf_filtered (" ");
1331 addr = value_as_pointer (evaluate_expression (d->exp));
1332 if (d->format.format == 'i')
1333 addr = ADDR_BITS_REMOVE (addr);
1335 do_examine (d->format, addr);
1339 if (d->format.format)
1340 printf_filtered ("/%c ", d->format.format);
1341 print_expression (d->exp, stdout);
1342 printf_filtered (" = ");
1343 print_formatted (evaluate_expression (d->exp),
1344 d->format.format, d->format.size);
1345 printf_filtered ("\n");
1349 current_display_number = -1;
1352 /* Display all of the values on the auto-display chain which can be
1353 evaluated in the current scope. */
1358 register struct display *d;
1360 for (d = display_chain; d; d = d->next)
1364 /* Delete the auto-display which we were in the process of displaying.
1365 This is done when there is an error or a signal. */
1368 disable_display (num)
1371 register struct display *d;
1373 for (d = display_chain; d; d = d->next)
1374 if (d->number == num)
1376 d->status = disabled;
1379 printf ("No display number %d.\n", num);
1383 disable_current_display ()
1385 if (current_display_number >= 0)
1387 disable_display (current_display_number);
1388 fprintf (stderr, "Disabling display %d to avoid infinite recursion.\n",
1389 current_display_number);
1391 current_display_number = -1;
1395 display_info (ignore, from_tty)
1399 register struct display *d;
1402 printf ("There are no auto-display expressions now.\n");
1404 printf_filtered ("Auto-display expressions now in effect:\n\
1405 Num Enb Expression\n");
1407 for (d = display_chain; d; d = d->next)
1409 printf_filtered ("%d: %c ", d->number, "ny"[(int)d->status]);
1411 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1413 else if (d->format.format)
1414 printf_filtered ("/%c ", d->format.format);
1415 print_expression (d->exp, stdout);
1416 if (d->block && !contained_in (get_selected_block (), d->block))
1417 printf_filtered (" (cannot be evaluated in the current context)");
1418 printf_filtered ("\n");
1424 enable_display (args, from_tty)
1428 register char *p = args;
1431 register struct display *d;
1435 for (d = display_chain; d; d = d->next)
1436 d->status = enabled;
1442 while (*p1 >= '0' && *p1 <= '9')
1444 if (*p1 && *p1 != ' ' && *p1 != '\t')
1445 error ("Arguments must be display numbers.");
1449 for (d = display_chain; d; d = d->next)
1450 if (d->number == num)
1452 d->status = enabled;
1455 printf ("No display number %d.\n", num);
1458 while (*p == ' ' || *p == '\t')
1465 disable_display_command (args, from_tty)
1469 register char *p = args;
1471 register struct display *d;
1475 for (d = display_chain; d; d = d->next)
1476 d->status = disabled;
1482 while (*p1 >= '0' && *p1 <= '9')
1484 if (*p1 && *p1 != ' ' && *p1 != '\t')
1485 error ("Arguments must be display numbers.");
1487 disable_display (atoi (p));
1490 while (*p == ' ' || *p == '\t')
1496 /* Print the value in stack frame FRAME of a variable
1497 specified by a struct symbol. */
1500 print_variable_value (var, frame, stream)
1505 value val = read_var_value (var, frame);
1506 value_print (val, stream, 0, Val_pretty_default);
1509 /* Print the arguments of a stack frame, given the function FUNC
1510 running in that frame (as a symbol), the info on the frame,
1511 and the number of args according to the stack frame (or -1 if unknown). */
1513 /* References here and elsewhere to "number of args according to the
1514 stack frame" appear in all cases to refer to "number of ints of args
1515 according to the stack frame". At least for VAX, i386, isi. */
1518 print_frame_args (func, fi, num, stream)
1519 struct symbol *func;
1520 struct frame_info *fi;
1528 register struct symbol *sym;
1530 /* Offset of next stack argument beyond the one we have seen that is
1531 at the highest offset.
1532 -1 if we haven't come to a stack argument yet. */
1533 long highest_offset = -1;
1535 /* Number of ints of arguments that we have printed so far. */
1536 int args_printed = 0;
1540 b = SYMBOL_BLOCK_VALUE (func);
1541 nsyms = BLOCK_NSYMS (b);
1544 for (i = 0; i < nsyms; i++)
1547 sym = BLOCK_SYM (b, i);
1549 /* Keep track of the highest stack argument offset seen, and
1550 skip over any kinds of symbols we don't care about. */
1552 switch (SYMBOL_CLASS (sym)) {
1556 long current_offset = SYMBOL_VALUE (sym);
1558 arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1560 /* Compute address of next argument by adding the size of
1561 this argument and rounding to an int boundary. */
1563 = ((current_offset + arg_size + sizeof (int) - 1)
1564 & ~(sizeof (int) - 1));
1566 /* If this is the highest offset seen yet, set highest_offset. */
1567 if (highest_offset == -1
1568 || (current_offset > highest_offset))
1569 highest_offset = current_offset;
1571 /* Add the number of ints we're about to print to args_printed. */
1572 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
1575 /* We care about types of symbols, but don't need to keep track of
1576 stack offsets in them. */
1581 /* Other types of symbols we just skip over. */
1586 /* We have to re-look-up the symbol because arguments often have
1587 two entries (one a parameter, one a register or local), and the one
1588 we want is the non-parm, which lookup_symbol will find for
1589 us. After this, sym could be any SYMBOL_CLASS... */
1590 #ifdef IBM6000_TARGET
1591 /* AIX/RS6000 implements a concept of traceback tables, in which case
1592 it creates nameless parameters. Looking for those parameter symbols
1593 will result in an error. */
1595 if ( *SYMBOL_NAME (sym))
1597 sym = lookup_symbol (SYMBOL_NAME (sym),
1598 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
1600 /* Print the current arg. */
1602 fprintf_filtered (stream, ", ");
1604 fprint_symbol (stream, SYMBOL_NAME (sym));
1605 fputs_filtered ("=", stream);
1607 /* Avoid value_print because it will deref ref parameters. We just
1608 want to print their addresses. Print ??? for args whose address
1609 we do not know. We pass 2 as "recurse" to val_print because our
1610 standard indentation here is 4 spaces, and val_print indents
1611 2 for each recurse. */
1612 val = read_var_value (sym, FRAME_INFO_ID (fi));
1614 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val),
1615 stream, 0, 0, 2, Val_no_prettyprint);
1617 fputs_filtered ("???", stream);
1621 /* Don't print nameless args in situations where we don't know
1622 enough about the stack to find them. */
1628 if (highest_offset == -1)
1629 start = FRAME_ARGS_SKIP;
1631 start = highest_offset;
1633 addr = FRAME_ARGS_ADDRESS (fi);
1635 print_frame_nameless_args (addr, start, num - args_printed,
1640 /* Print nameless args on STREAM.
1641 ARGSADDR is the address of the arglist, START is the offset
1642 of the first nameless arg, and NUM is the number of nameless args to
1643 print. FIRST is nonzero if this is the first argument (not just
1644 the first nameless arg). */
1646 print_frame_nameless_args (argsaddr, start, num, first, stream)
1654 for (i = 0; i < num; i++)
1658 fprintf_filtered (stream, ", ");
1659 #ifndef PRINT_TYPELESS_INTEGER
1660 fprintf_filtered (stream, "%d",
1661 read_memory_integer (argsaddr + start, sizeof (int)));
1663 PRINT_TYPELESS_INTEGER (stream, builtin_type_int,
1665 read_memory_integer (argsaddr + start,
1669 start += sizeof (int);
1675 printf_command (arg, from_tty)
1680 register char *s = arg;
1684 int allocated_args = 20;
1687 val_args = (value *) xmalloc (allocated_args * sizeof (value));
1690 error_no_arg ("format-control string and values to print");
1692 /* Skip white space before format string */
1693 while (*s == ' ' || *s == '\t') s++;
1695 /* A format string should follow, enveloped in double quotes */
1697 error ("Bad format string, missing '\"'.");
1699 /* Parse the format-control string and copy it into the string STRING,
1700 processing some kinds of escape sequence. */
1702 f = string = (char *) alloca (strlen (s) + 1);
1709 error ("Bad format string, non-terminated '\"'.");
1710 /* doesn't return */
1731 /* ??? TODO: handle other escape sequences */
1732 error ("Unrecognized \\ escape character in format string.");
1741 /* Skip over " and following space and comma. */
1744 while (*s == ' ' || *s == '\t') s++;
1746 if (*s != ',' && *s != 0)
1747 error ("Invalid argument syntax");
1750 while (*s == ' ' || *s == '\t') s++;
1753 /* Now scan the string for %-specs and see what kinds of args they want.
1754 argclass[I] classifies the %-specs so we can give vprintf something
1755 of the right size. */
1757 enum argclass {int_arg, string_arg, double_arg, long_long_arg};
1758 enum argclass *argclass;
1764 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1771 while (strchr ("0123456789.hlL-+ #", *f))
1773 if (*f == 'l' || *f == 'L')
1778 argclass[nargs_wanted++] = string_arg;
1779 else if (*f == 'e' || *f == 'f' || *f == 'g')
1780 argclass[nargs_wanted++] = double_arg;
1781 else if (lcount > 1)
1782 argclass[nargs_wanted++] = long_long_arg;
1784 argclass[nargs_wanted++] = int_arg;
1788 /* Now, parse all arguments and evaluate them.
1789 Store the VALUEs in VAL_ARGS. */
1794 if (nargs == allocated_args)
1795 val_args = (value *) xrealloc ((char *) val_args,
1796 (allocated_args *= 2)
1799 val_args[nargs] = parse_to_comma_and_eval (&s1);
1801 /* If format string wants a float, unchecked-convert the value to
1802 floating point of the same size */
1804 if (argclass[nargs] == double_arg)
1806 if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (float))
1807 VALUE_TYPE (val_args[nargs]) = builtin_type_float;
1808 if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (double))
1809 VALUE_TYPE (val_args[nargs]) = builtin_type_double;
1817 if (nargs != nargs_wanted)
1818 error ("Wrong number of arguments for specified format-string");
1820 /* Now lay out an argument-list containing the arguments
1821 as doubles, integers and C pointers. */
1823 arg_bytes = (char *) alloca (sizeof (double) * nargs);
1825 for (i = 0; i < nargs; i++)
1827 if (argclass[i] == string_arg)
1832 tem = value_as_pointer (val_args[i]);
1834 /* This is a %s argument. Find the length of the string. */
1839 read_memory (tem + j, &c, 1);
1844 /* Copy the string contents into a string inside GDB. */
1845 str = (char *) alloca (j + 1);
1846 read_memory (tem, str, j);
1849 /* Pass address of internal copy as the arg to vprintf. */
1850 *((int *) &arg_bytes[argindex]) = (int) str;
1851 argindex += sizeof (int);
1853 else if (VALUE_TYPE (val_args[i])->code == TYPE_CODE_FLT)
1855 *((double *) &arg_bytes[argindex]) = value_as_double (val_args[i]);
1856 argindex += sizeof (double);
1860 if (argclass[i] == long_long_arg)
1862 *(long long *) &arg_bytes[argindex] = value_as_long (val_args[i]);
1863 argindex += sizeof (long long);
1868 *((long *) &arg_bytes[argindex]) = value_as_long (val_args[i]);
1869 argindex += sizeof (long);
1874 /* There is not a standard way to make a va_list, so we need
1875 to do various things for different systems. */
1876 #if defined (__INT_VARARGS_H)
1881 list.__va_stk = (int *) arg_bytes;
1882 list.__va_reg = (int *) arg_bytes;
1883 vprintf (string, list);
1885 #else /* No __INT_VARARGS_H. */
1886 vprintf (string, arg_bytes);
1887 #endif /* No __INT_VARARGS_H. */
1890 /* Helper function for asdump_command. Finds the bounds of a function
1891 for a specified section of text. PC is an address within the
1892 function which you want bounds for; *LOW and *HIGH are set to the
1893 beginning (inclusive) and end (exclusive) of the function. This
1894 function returns 1 on success and 0 on failure. */
1897 containing_function_bounds (pc, low, high)
1898 CORE_ADDR pc, *low, *high;
1902 if (!find_pc_partial_function (pc, 0, low))
1908 if (!find_pc_partial_function (scan, 0, high))
1910 } while (*low == *high);
1915 /* Dump a specified section of assembly code. With no command line
1916 arguments, this command will dump the assembly code for the
1917 function surrounding the pc value in the selected frame. With one
1918 argument, it will dump the assembly code surrounding that pc value.
1919 Two arguments are interpeted as bounds within which to dump
1924 disassemble_command (arg, from_tty)
1928 CORE_ADDR low, high;
1934 if (!selected_frame)
1935 error ("No frame selected.\n");
1937 pc = get_frame_pc (selected_frame);
1938 if (!containing_function_bounds (pc, &low, &high))
1939 error ("No function contains pc specified by selected frame.\n");
1941 else if (!(space_index = (char *) strchr (arg, ' ')))
1944 pc = parse_and_eval_address (arg);
1945 if (!containing_function_bounds (pc, &low, &high))
1946 error ("No function contains specified pc.\n");
1950 /* Two arguments. */
1951 *space_index = '\0';
1952 low = parse_and_eval_address (arg);
1953 high = parse_and_eval_address (space_index + 1);
1956 printf_filtered ("Dump of assembler code ");
1960 find_pc_partial_function (pc, &name, 0);
1961 printf_filtered ("for function %s:\n", name);
1964 printf_filtered ("from %s ", local_hex_string(low));
1965 printf_filtered ("to %s:\n", local_hex_string(high));
1967 /* Dump the specified range. */
1968 for (pc = low; pc < high; )
1971 print_address (pc, stdout);
1972 printf_filtered (":\t");
1973 pc += print_insn (pc, stdout);
1974 printf_filtered ("\n");
1976 printf_filtered ("End of assembler dump.\n");
1982 _initialize_printcmd ()
1984 current_display_number = -1;
1986 add_info ("address", address_info,
1987 "Describe where variable VAR is stored.");
1989 add_com ("x", class_vars, x_command,
1990 "Examine memory: x/FMT ADDRESS.\n\
1991 ADDRESS is an expression for the memory address to examine.\n\
1992 FMT is a repeat count followed by a format letter and a size letter.\n\
1993 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1994 f(float), a(address), i(instruction), c(char) and s(string).\n\
1995 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1996 g is meaningful only with f, for type double.\n\
1997 The specified number of objects of the specified size are printed\n\
1998 according to the format.\n\n\
1999 Defaults for format and size letters are those previously used.\n\
2000 Default count is 1. Default address is following last thing printed\n\
2001 with this command or \"print\".");
2003 add_com ("disassemble", class_vars, disassemble_command,
2004 "Disassemble a specified section of memory.\n\
2005 Default is the function surrounding the pc of the selected frame.\n\
2006 With a single argument, the function surrounding that address is dumped.\n\
2007 Two arguments are taken as a range of memory to dump.");
2009 add_com ("ptype", class_vars, ptype_command,
2010 "Print definition of type TYPE.\n\
2011 Argument may be a type name defined by typedef, or \"struct STRUCTNAME\"\n\
2012 or \"union UNIONNAME\" or \"enum ENUMNAME\".\n\
2013 The selected stack frame's lexical context is used to look up the name.");
2015 add_com ("whatis", class_vars, whatis_command,
2016 "Print data type of expression EXP.");
2019 add_com ("whereis", class_vars, whereis_command,
2020 "Print line number and file of definition of variable.");
2023 add_info ("display", display_info,
2024 "Expressions to display when program stops, with code numbers.");
2026 add_cmd ("undisplay", class_vars, undisplay_command,
2027 "Cancel some expressions to be displayed when program stops.\n\
2028 Arguments are the code numbers of the expressions to stop displaying.\n\
2029 No argument means cancel all automatic-display expressions.\n\
2030 \"delete display\" has the same effect as this command.\n\
2031 Do \"info display\" to see current list of code numbers.",
2034 add_com ("display", class_vars, display_command,
2035 "Print value of expression EXP each time the program stops.\n\
2036 /FMT may be used before EXP as in the \"print\" command.\n\
2037 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2038 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2039 and examining is done as in the \"x\" command.\n\n\
2040 With no argument, display all currently requested auto-display expressions.\n\
2041 Use \"undisplay\" to cancel display requests previously made.");
2043 add_cmd ("display", class_vars, enable_display,
2044 "Enable some expressions to be displayed when program stops.\n\
2045 Arguments are the code numbers of the expressions to resume displaying.\n\
2046 No argument means enable all automatic-display expressions.\n\
2047 Do \"info display\" to see current list of code numbers.", &enablelist);
2049 add_cmd ("display", class_vars, disable_display_command,
2050 "Disable some expressions to be displayed when program stops.\n\
2051 Arguments are the code numbers of the expressions to stop displaying.\n\
2052 No argument means disable all automatic-display expressions.\n\
2053 Do \"info display\" to see current list of code numbers.", &disablelist);
2055 add_cmd ("display", class_vars, undisplay_command,
2056 "Cancel some expressions to be displayed when program stops.\n\
2057 Arguments are the code numbers of the expressions to stop displaying.\n\
2058 No argument means cancel all automatic-display expressions.\n\
2059 Do \"info display\" to see current list of code numbers.", &deletelist);
2061 add_com ("printf", class_vars, printf_command,
2062 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2063 This is useful for formatted output in user-defined commands.");
2064 add_com ("output", class_vars, output_command,
2065 "Like \"print\" but don't put in value history and don't print newline.\n\
2066 This is useful in user-defined commands.");
2068 add_prefix_cmd ("set", class_vars, set_command,
2069 "Perform an assignment VAR = EXP.\n\
2070 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
2071 (names starting with $), a register (a few standard names starting with $),\n\
2072 or an actual variable in the program being debugged. EXP is any expression.\n\
2073 Use \"set variable\" for variables with names identical to set subcommands.\n\
2074 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2075 You can see these environment settings with the \"show\" command.",
2076 &setlist, "set ", 1, &cmdlist);
2078 /* "call" is the same as "set", but handy for dbx users to call fns. */
2079 add_com ("call", class_vars, call_command,
2080 "Call a function in the inferior process.\n\
2081 The argument is the function name and arguments, in the notation of the\n\
2082 current working language. The result is printed and saved in the value\n\
2083 history, if it is not void.");
2085 add_cmd ("variable", class_vars, set_command,
2086 "Perform an assignment VAR = EXP.\n\
2087 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
2088 (names starting with $), a register (a few standard names starting with $),\n\
2089 or an actual variable in the program being debugged. EXP is any expression.\n\
2090 This may usually be abbreviated to simply \"set\".",
2093 add_com ("print", class_vars, print_command,
2094 concat ("Print value of expression EXP.\n\
2095 Variables accessible are those of the lexical environment of the selected\n\
2096 stack frame, plus all those whose scope is global or an entire file.\n\
2098 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2099 $$NUM refers to NUM'th value back from the last one.\n\
2100 Names starting with $ refer to registers (with the values they would have\n\
2101 if the program were to return to the stack frame now selected, restoring\n\
2102 all registers saved by frames farther in) or else to debugger\n\
2103 \"convenience\" variables (any such name not a known register).\n\
2104 Use assignment expressions to give values to convenience variables.\n",
2106 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2107 @ is a binary operator for treating consecutive data objects\n\
2108 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2109 element is FOO, whose second element is stored in the space following\n\
2110 where FOO is stored, etc. FOO must be an expression whose value\n\
2111 resides in memory.\n",
2113 EXP may be preceded with /FMT, where FMT is a format letter\n\
2114 but no count or size letter (see \"x\" command).", NULL));
2115 add_com_alias ("p", "print", class_vars, 1);
2117 add_com ("inspect", class_vars, inspect_command,
2118 "Same as \"print\" command, except that if you are running in the epoch\n\
2119 environment, the value is printed in its own window.");