1 /* Print values for GNU debugger GDB.
2 Copyright (C) 1986-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"
32 extern int asm_demangle; /* Whether to demangle syms in asm printouts */
33 extern int addressprint; /* Whether to print hex addresses in HLL " */
35 extern struct block *get_current_block ();
37 static void print_frame_nameless_args ();
46 /* Last specified output format. */
48 static char last_format = 'x';
50 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
52 static char last_size = 'w';
54 /* Default address to examine next. */
56 static CORE_ADDR next_address;
58 /* Last address examined. */
60 static CORE_ADDR last_examine_address;
62 /* Contents of last address examined.
63 This is not valid past the end of the `x' command! */
65 static value last_examine_value;
67 /* Number of auto-display expression currently being displayed.
68 So that we can deleted it if we get an error or a signal within it.
69 -1 when not doing one. */
71 int current_display_number;
73 /* Flag to low-level print routines that this value is being printed
74 in an epoch window. We'd like to pass this as a parameter, but
75 every routine would need to take it. Perhaps we can encapsulate
76 this in the I/O stream once we have GNU stdio. */
80 static void do_one_display ();
83 void print_scalar_formatted ();
86 /* Decode a format specification. *STRING_PTR should point to it.
87 OFORMAT and OSIZE are used as defaults for the format and size
88 if none are given in the format specification.
89 If OSIZE is zero, then the size field of the returned value
90 should be set only if a size is explicitly specified by the
92 The structure returned describes all the data
93 found in the specification. In addition, *STRING_PTR is advanced
94 past the specification and past all whitespace following it. */
97 decode_format (string_ptr, oformat, osize)
102 struct format_data val;
103 register char *p = *string_ptr;
109 if (*p >= '0' && *p <= '9')
110 val.count = atoi (p);
111 while (*p >= '0' && *p <= '9') p++;
113 /* Now process size or format letters that follow. */
117 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
126 else if (*p >= 'a' && *p <= 'z')
133 /* Make sure 'g' size is not used on integer types.
134 Well, actually, we can handle hex. */
135 if (val.size == 'g' && val.format != 'f' && val.format != 'x')
139 while (*p == ' ' || *p == '\t') p++;
142 /* Set defaults for format and size if not specified. */
143 if (val.format == '?')
147 /* Neither has been specified. */
148 val.format = oformat;
152 /* If a size is specified, any format makes a reasonable
153 default except 'i'. */
154 val.format = oformat == 'i' ? 'x' : oformat;
156 else if (val.size == '?')
161 /* Addresses must be words. */
162 val.size = osize ? 'w' : osize;
165 /* Floating point has to be word or giantword. */
166 if (osize == 'w' || osize == 'g')
169 /* Default it to giantword if the last used size is not
171 val.size = osize ? 'g' : osize;
174 /* Characters default to one byte. */
175 val.size = osize ? 'b' : osize;
178 /* The default is the size most recently specified. */
185 /* Print value VAL on stdout according to FORMAT, a letter or 0.
186 Do not end with a newline.
187 0 means print VAL according to its own type.
188 SIZE is the letter for the size of datum being printed.
189 This is used to pad hex numbers so they line up. */
192 print_formatted (val, format, size)
194 register char format;
197 int len = TYPE_LENGTH (VALUE_TYPE (val));
199 if (VALUE_LVAL (val) == lval_memory)
200 next_address = VALUE_ADDRESS (val) + len;
205 next_address = VALUE_ADDRESS (val)
206 + value_print (value_addr (val), stdout, format, Val_pretty_default);
210 next_address = VALUE_ADDRESS (val)
211 + print_insn (VALUE_ADDRESS (val), stdout);
216 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_ARRAY
217 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_STRUCT
218 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_UNION
219 || VALUE_REPEATED (val))
220 value_print (val, stdout, format, Val_pretty_default);
222 print_scalar_formatted (VALUE_CONTENTS (val), VALUE_TYPE (val),
223 format, size, stdout);
227 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
228 according to letters FORMAT and SIZE on STREAM.
229 FORMAT may not be zero. Formats s and i are not supported at this level.
231 This is how the elements of an array or structure are printed
235 print_scalar_formatted (valaddr, type, format, size, stream)
243 int len = TYPE_LENGTH (type);
245 if (size == 'g' && sizeof (LONGEST) < 8
248 /* ok, we're going to have to get fancy here. Assumption: a
249 long is four bytes. FIXME. */
250 unsigned long v1, v2, tmp;
252 v1 = unpack_long (builtin_type_long, valaddr);
253 v2 = unpack_long (builtin_type_long, valaddr + 4);
255 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
256 /* Swap the two for printing */
265 fprintf_filtered (stream, "0x%08x%08x", v1, v2);
268 error ("Output size \"g\" unimplemented for format \"%c\".",
274 val_long = unpack_long (type, valaddr);
276 /* If value is unsigned, truncate it in case negative. */
279 if (len == sizeof (char))
280 val_long &= (1 << 8 * sizeof(char)) - 1;
281 else if (len == sizeof (short))
282 val_long &= (1 << 8 * sizeof(short)) - 1;
283 else if (len == sizeof (long))
284 val_long &= (unsigned long) - 1;
292 /* no size specified, like in print. Print varying # of digits. */
293 #if defined (LONG_LONG)
294 fprintf_filtered (stream, "0x%llx", val_long);
295 #else /* not LONG_LONG. */
296 fprintf_filtered (stream, "0x%lx", val_long);
297 #endif /* not LONG_LONG. */
300 #if defined (LONG_LONG)
304 fprintf_filtered (stream, "0x%02llx", val_long);
307 fprintf_filtered (stream, "0x%04llx", val_long);
310 fprintf_filtered (stream, "0x%08llx", val_long);
313 fprintf_filtered (stream, "0x%016llx", val_long);
316 error ("Undefined output size \"%c\".", size);
318 #else /* not LONG_LONG. */
322 fprintf_filtered (stream, "0x%02x", val_long);
325 fprintf_filtered (stream, "0x%04x", val_long);
328 fprintf_filtered (stream, "0x%08x", val_long);
331 fprintf_filtered (stream, "0x%016x", val_long);
334 error ("Undefined output size \"%c\".", size);
336 #endif /* not LONG_LONG */
341 fprintf_filtered (stream, "%lld", val_long);
343 fprintf_filtered (stream, "%d", val_long);
349 fprintf_filtered (stream, "%llu", val_long);
351 fprintf_filtered (stream, "%u", val_long);
358 fprintf_filtered (stream, "0%llo", val_long);
360 fprintf_filtered (stream, "0%o", val_long);
363 fprintf_filtered (stream, "0");
367 print_address (unpack_pointer (type, valaddr), stream);
371 value_print (value_from_long (builtin_type_char, val_long), stream, 0,
376 if (len == sizeof (float))
377 type = builtin_type_float;
378 else if (len == sizeof (double))
379 type = builtin_type_double;
380 print_floating (valaddr, type, stream);
387 /* Binary; 't' stands for "two". */
389 char bits[8*(sizeof val_long) + 1];
394 width = 8*(sizeof val_long);
411 error ("Undefined output size \"%c\".", size);
417 bits[width] = (val_long & 1) ? '1' : '0';
422 while (*cp && *cp == '0')
427 fprintf_filtered (stream, cp);
432 error ("Undefined output format \"%c\".", format);
436 /* Specify default address for `x' command.
437 `info lines' uses this. */
440 set_next_address (addr)
445 /* Make address available to the user as $_. */
446 set_internalvar (lookup_internalvar ("_"),
447 value_from_long (builtin_type_int, (LONGEST) addr));
450 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
451 after LEADIN. Print nothing if no symbolic name is found nearby.
452 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
453 or to interpret it as a possible C++ name and convert it back to source
457 print_address_symbolic (addr, stream, do_demangle, leadin)
464 register int i = find_pc_misc_function (addr);
466 /* If nothing comes out, don't print anything symbolic. */
471 fputs_filtered (leadin, stream);
472 fputs_filtered ("<", stream);
474 fputs_demangled (misc_function_vector[i].name, stream, 1);
476 fputs_filtered (misc_function_vector[i].name, stream);
477 name_location = misc_function_vector[i].address;
478 if (addr - name_location)
479 fprintf_filtered (stream, "+%d>", addr - name_location);
481 fputs_filtered (">", stream);
484 /* Print address ADDR symbolically on STREAM.
485 First print it as a number. Then perhaps print
486 <SYMBOL + OFFSET> after the number. */
489 print_address (addr, stream)
493 fprintf_filtered (stream, "0x%x", addr);
494 print_address_symbolic (addr, stream, asm_demangle, " ");
497 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
498 controls whether to print the symbolic name "raw" or demangled.
499 Global setting "addressprint" controls whether to print hex address
503 print_address_demangle (addr, stream, do_demangle)
509 fprintf_filtered (stream, "0");
510 } else if (addressprint) {
511 fprintf_filtered (stream, "0x%x", addr);
512 print_address_symbolic (addr, stream, do_demangle, " ");
514 print_address_symbolic (addr, stream, do_demangle, "");
519 /* Examine data at address ADDR in format FMT.
520 Fetch it from memory and print on stdout. */
523 do_examine (fmt, addr)
524 struct format_data fmt;
527 register char format = 0;
529 register int count = 1;
530 struct type *val_type;
532 register int maxelts;
539 /* String or instruction format implies fetch single bytes
540 regardless of the specified size. */
541 if (format == 's' || format == 'i')
545 val_type = builtin_type_char;
546 else if (size == 'h')
547 val_type = builtin_type_short;
548 else if (size == 'w')
549 val_type = builtin_type_long;
550 else if (size == 'g')
552 val_type = builtin_type_double;
554 val_type = builtin_type_long_long;
562 if (format == 's' || format == 'i')
565 /* Print as many objects as specified in COUNT, at most maxelts per line,
566 with the address of the next one at the start of each line. */
570 print_address (next_address, stdout);
571 printf_filtered (":");
576 printf_filtered ("\t");
577 /* Note that print_formatted sets next_address for the next
579 last_examine_address = next_address;
580 last_examine_value = value_at (val_type, next_address);
581 print_formatted (last_examine_value, format, size);
583 printf_filtered ("\n");
589 validate_format (fmt, cmdname)
590 struct format_data fmt;
594 error ("Size letters are meaningless in \"%s\" command.", cmdname);
596 error ("Item count other than 1 is meaningless in \"%s\" command.",
598 if (fmt.format == 'i' || fmt.format == 's')
599 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
600 fmt.format, cmdname);
604 print_command_1 (exp, inspect, voidprint)
609 struct expression *expr;
610 register struct cleanup *old_chain = 0;
611 register char format = 0;
613 struct format_data fmt;
616 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
617 inspect_it = inspect;
619 if (exp && *exp == '/')
622 fmt = decode_format (&exp, last_format, 0);
623 validate_format (fmt, "print");
624 last_format = format = fmt.format;
635 extern int objectprint;
637 expr = parse_c_expression (exp);
638 old_chain = make_cleanup (free_current_contents, &expr);
640 val = evaluate_expression (expr);
642 /* C++: figure out what type we actually want to print it as. */
643 type = VALUE_TYPE (val);
646 && (TYPE_CODE (type) == TYPE_CODE_PTR
647 || TYPE_CODE (type) == TYPE_CODE_REF)
648 && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT)
652 v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
656 type = VALUE_TYPE (val);
661 val = access_value_history (0);
663 if (voidprint || (val && VALUE_TYPE (val) &&
664 TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
666 int histindex = record_latest_value (val);
669 printf ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
671 if (histindex >= 0) printf_filtered ("$%d = ", histindex);
673 print_formatted (val, format, fmt.size);
674 printf_filtered ("\n");
680 do_cleanups (old_chain);
681 inspect_it = 0; /* Reset print routines to normal */
686 print_command (exp, from_tty)
690 print_command_1 (exp, 0, 1);
693 /* Same as print, except in epoch, it gets its own window */
696 inspect_command (exp, from_tty)
700 extern int epoch_interface;
702 print_command_1 (exp, epoch_interface, 1);
705 /* Same as print, except it doesn't print void results. */
708 call_command (exp, from_tty)
712 print_command_1 (exp, 0, 0);
717 output_command (exp, from_tty)
721 struct expression *expr;
722 register struct cleanup *old_chain;
723 register char format = 0;
725 struct format_data fmt;
727 if (exp && *exp == '/')
730 fmt = decode_format (&exp, 0, 0);
731 validate_format (fmt, "print");
735 expr = parse_c_expression (exp);
736 old_chain = make_cleanup (free_current_contents, &expr);
738 val = evaluate_expression (expr);
740 print_formatted (val, format, fmt.size);
742 do_cleanups (old_chain);
747 set_command (exp, from_tty)
751 struct expression *expr = parse_c_expression (exp);
752 register struct cleanup *old_chain
753 = make_cleanup (free_current_contents, &expr);
754 evaluate_expression (expr);
755 do_cleanups (old_chain);
760 address_info (exp, from_tty)
764 register struct symbol *sym;
766 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
767 if exp is a field of `this'. */
770 error ("Argument required.");
772 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
773 &is_a_field_of_this, (struct symtab **)NULL);
778 if (is_a_field_of_this)
780 printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp);
784 for (i = 0; i < misc_function_count; i++)
785 if (!strcmp (misc_function_vector[i].name, exp))
788 if (i < misc_function_count)
789 printf ("Symbol \"%s\" is at 0x%x in a file compiled without -g.\n",
790 exp, misc_function_vector[i].address);
792 error ("No symbol \"%s\" in current context.", exp);
796 printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym));
797 val = SYMBOL_VALUE (sym);
799 switch (SYMBOL_CLASS (sym))
802 case LOC_CONST_BYTES:
807 printf ("a label at address 0x%x", SYMBOL_VALUE_ADDRESS (sym));
811 printf ("a variable in register %s", reg_names[val]);
815 printf ("static at address 0x%x", SYMBOL_VALUE_ADDRESS (sym));
819 printf ("an argument in register %s", reg_names[val]);
823 printf ("an argument at offset %ld", val);
827 printf ("an argument at frame offset %ld", val);
831 printf ("a local variable at frame offset %ld", val);
835 printf ("a reference argument at offset %ld", val);
839 printf ("a typedef");
843 printf ("a function at address 0x%x",
844 BLOCK_START (SYMBOL_BLOCK_VALUE (sym)));
848 printf ("an external symbol at address 0x%x",
849 SYMBOL_VALUE_ADDRESS (sym));
853 printf ("of unknown (botched) type");
860 x_command (exp, from_tty)
864 struct expression *expr;
865 struct format_data fmt;
866 struct cleanup *old_chain;
869 fmt.format = last_format;
870 fmt.size = last_size;
873 if (exp && *exp == '/')
876 fmt = decode_format (&exp, last_format, last_size);
877 last_size = fmt.size;
878 last_format = fmt.format;
881 /* If we have an expression, evaluate it and use it as the address. */
883 if (exp != 0 && *exp != 0)
885 expr = parse_c_expression (exp);
886 /* Cause expression not to be there any more
887 if this command is repeated with Newline.
888 But don't clobber a user-defined command's definition. */
891 old_chain = make_cleanup (free_current_contents, &expr);
892 val = evaluate_expression (expr);
893 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
894 val = value_ind (val);
895 /* In rvalue contexts, such as this, functions are coerced into
896 pointers to functions. This makes "x/i main" work. */
897 if (/* last_format == 'i'
898 && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
899 && VALUE_LVAL (val) == lval_memory)
900 next_address = VALUE_ADDRESS (val);
902 next_address = value_as_pointer (val);
903 do_cleanups (old_chain);
906 do_examine (fmt, next_address);
908 /* Set a couple of internal variables if appropriate. */
909 if (last_examine_value)
911 /* Make last address examined available to the user as $_. */
912 set_internalvar (lookup_internalvar ("_"),
913 value_from_long (builtin_type_int,
914 (LONGEST) last_examine_address));
916 /* Make contents of last address examined available to the user as $__.*/
917 set_internalvar (lookup_internalvar ("__"), last_examine_value);
921 /* Commands for printing types of things. */
923 /* Print type of EXP, or last thing in value history if EXP == NULL.
924 show is passed to type_print. */
926 whatis_exp (exp, show)
930 struct expression *expr;
932 register struct cleanup *old_chain;
936 expr = parse_c_expression (exp);
937 old_chain = make_cleanup (free_current_contents, &expr);
938 val = evaluate_type (expr);
941 val = access_value_history (0);
943 printf_filtered ("type = ");
944 type_print (VALUE_TYPE (val), "", stdout, show);
945 printf_filtered ("\n");
948 do_cleanups (old_chain);
953 whatis_command (exp, from_tty)
957 /* Most of the time users do not want to see all the fields
958 in a structure. If they do they can use the "ptype" command.
959 Hence the "-1" below. */
960 whatis_exp (exp, -1);
963 /* TYPENAME is either the name of a type, or an expression. */
966 ptype_command (typename, from_tty)
970 register char *p = typename;
972 register struct block *b
973 = target_has_stack ? get_current_block () : 0;
974 register struct type *type;
978 whatis_exp (typename, 1);
982 while (*p && *p != ' ' && *p != '\t') p++;
984 while (*p == ' ' || *p == '\t') p++;
986 if (len == 6 && !strncmp (typename, "struct", 6))
987 type = lookup_struct (p, b);
988 else if (len == 5 && !strncmp (typename, "union", 5))
989 type = lookup_union (p, b);
990 else if (len == 4 && !strncmp (typename, "enum", 4))
991 type = lookup_enum (p, b);
994 type = lookup_typename (typename, b, 1);
997 register struct symbol *sym
998 = lookup_symbol (typename, b, STRUCT_NAMESPACE, 0,
999 (struct symtab **)NULL);
1002 /* It's not the name of a type, either VAR_NAMESPACE
1003 or STRUCT_NAMESPACE, so it must be an expression. */
1004 whatis_exp (typename, 1);
1007 printf_filtered ("No type named %s, ", typename);
1009 printf_filtered ("but there is ");
1010 switch (TYPE_CODE (SYMBOL_TYPE (sym)))
1012 case TYPE_CODE_STRUCT:
1013 printf_filtered ("a struct");
1016 case TYPE_CODE_UNION:
1017 printf_filtered ("a union");
1020 case TYPE_CODE_ENUM:
1021 printf_filtered ("an enum");
1025 printf_filtered ("(Internal error in gdb)");
1028 printf_filtered (" %s. ", typename);
1030 printf_filtered ("(Type \"help ptype\".)\n");
1031 type = SYMBOL_TYPE (sym);
1035 type_print (type, "", stdout, 1);
1036 printf_filtered ("\n");
1040 /* This is not necessary. Instead, decode_line_1 takes any variable,
1041 so "info line foo" is a close equivalent to "whereis foo". */
1043 whereis_command (var, from_tty)
1051 error_no_arg ("Variable name.");
1053 sym = lookup_symbol (var, get_selected_block (), VAR_NAMESPACE,
1056 if (sym != NULL && s != NULL)
1057 printf_filtered ("Symbol \"%s\" is at line %d of file %s\n",
1058 var, sym->line, s->filename);
1061 if (lookup_misc_func (var) >= 0)
1062 printf_filtered ("Symbol \"%s\" is in a file compiled without -g.",
1065 error ("No symbol \"%s\" in current context.", var);
1070 enum display_status {disabled, enabled};
1074 /* Chain link to next auto-display item. */
1075 struct display *next;
1076 /* Expression to be evaluated and displayed. */
1077 struct expression *exp;
1078 /* Item number of this auto-display item. */
1080 /* Display format specified. */
1081 struct format_data format;
1082 /* Innermost block required by this expression when evaluated */
1083 struct block *block;
1084 /* Status of this display (enabled or disabled) */
1085 enum display_status status;
1088 /* Chain of expressions whose values should be displayed
1089 automatically each time the program stops. */
1091 static struct display *display_chain;
1093 static int display_number;
1095 /* Add an expression to the auto-display chain.
1096 Specify the expression. */
1099 display_command (exp, from_tty)
1103 struct format_data fmt;
1104 register struct expression *expr;
1105 register struct display *new;
1116 fmt = decode_format (&exp, 0, 0);
1117 if (fmt.size && fmt.format == 0)
1119 if (fmt.format == 'i' || fmt.format == 's')
1129 innermost_block = 0;
1130 expr = parse_c_expression (exp);
1132 new = (struct display *) xmalloc (sizeof (struct display));
1135 new->block = innermost_block;
1136 new->next = display_chain;
1137 new->number = ++display_number;
1139 new->status = enabled;
1140 display_chain = new;
1142 if (from_tty && target_has_execution)
1143 do_one_display (new);
1156 /* Clear out the display_chain.
1157 Done when new symtabs are loaded, since this invalidates
1158 the types stored in many expressions. */
1163 register struct display *d;
1165 while (d = display_chain)
1168 display_chain = d->next;
1173 /* Delete the auto-display number NUM. */
1176 delete_display (num)
1179 register struct display *d1, *d;
1182 error ("No display number %d.", num);
1184 if (display_chain->number == num)
1187 display_chain = d1->next;
1191 for (d = display_chain; ; d = d->next)
1194 error ("No display number %d.", num);
1195 if (d->next->number == num)
1205 /* Delete some values from the auto-display chain.
1206 Specify the element numbers. */
1209 undisplay_command (args)
1212 register char *p = args;
1218 if (query ("Delete all auto-display expressions? "))
1227 while (*p1 >= '0' && *p1 <= '9') p1++;
1228 if (*p1 && *p1 != ' ' && *p1 != '\t')
1229 error ("Arguments must be display numbers.");
1233 delete_display (num);
1236 while (*p == ' ' || *p == '\t') p++;
1241 /* Display a single auto-display.
1242 Do nothing if the display cannot be printed in the current context,
1243 or if the display is disabled. */
1249 int within_current_scope;
1251 if (d->status == disabled)
1255 within_current_scope = contained_in (get_selected_block (), d->block);
1257 within_current_scope = 1;
1258 if (!within_current_scope)
1261 current_display_number = d->number;
1263 printf_filtered ("%d: ", d->number);
1268 printf_filtered ("x/");
1269 if (d->format.count != 1)
1270 printf_filtered ("%d", d->format.count);
1271 printf_filtered ("%c", d->format.format);
1272 if (d->format.format != 'i' && d->format.format != 's')
1273 printf_filtered ("%c", d->format.size);
1274 printf_filtered (" ");
1275 print_expression (d->exp, stdout);
1276 if (d->format.count != 1)
1277 printf_filtered ("\n");
1279 printf_filtered (" ");
1281 addr = value_as_pointer (evaluate_expression (d->exp));
1282 if (d->format.format == 'i')
1283 addr = ADDR_BITS_REMOVE (addr);
1285 do_examine (d->format, addr);
1289 if (d->format.format)
1290 printf_filtered ("/%c ", d->format.format);
1291 print_expression (d->exp, stdout);
1292 printf_filtered (" = ");
1293 print_formatted (evaluate_expression (d->exp),
1294 d->format.format, d->format.size);
1295 printf_filtered ("\n");
1299 current_display_number = -1;
1302 /* Display all of the values on the auto-display chain which can be
1303 evaluated in the current scope. */
1308 register struct display *d;
1310 for (d = display_chain; d; d = d->next)
1314 /* Delete the auto-display which we were in the process of displaying.
1315 This is done when there is an error or a signal. */
1318 disable_display (num)
1321 register struct display *d;
1323 for (d = display_chain; d; d = d->next)
1324 if (d->number == num)
1326 d->status = disabled;
1329 printf ("No display number %d.\n", num);
1333 disable_current_display ()
1335 if (current_display_number >= 0)
1337 disable_display (current_display_number);
1338 fprintf (stderr, "Disabling display %d to avoid infinite recursion.\n",
1339 current_display_number);
1341 current_display_number = -1;
1347 register struct display *d;
1350 printf ("There are no auto-display expressions now.\n");
1352 printf_filtered ("Auto-display expressions now in effect:\n\
1353 Num Enb Expression\n");
1355 for (d = display_chain; d; d = d->next)
1357 printf_filtered ("%d: %c ", d->number, "ny"[(int)d->status]);
1359 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1361 else if (d->format.format)
1362 printf_filtered ("/%c ", d->format.format);
1363 print_expression (d->exp, stdout);
1364 if (d->block && !contained_in (get_selected_block (), d->block))
1365 printf_filtered (" (cannot be evaluated in the current context)");
1366 printf_filtered ("\n");
1372 enable_display (args)
1375 register char *p = args;
1378 register struct display *d;
1382 for (d = display_chain; d; d = d->next)
1383 d->status = enabled;
1389 while (*p1 >= '0' && *p1 <= '9')
1391 if (*p1 && *p1 != ' ' && *p1 != '\t')
1392 error ("Arguments must be display numbers.");
1396 for (d = display_chain; d; d = d->next)
1397 if (d->number == num)
1399 d->status = enabled;
1402 printf ("No display number %d.\n", num);
1405 while (*p == ' ' || *p == '\t')
1412 disable_display_command (args, from_tty)
1416 register char *p = args;
1418 register struct display *d;
1422 for (d = display_chain; d; d = d->next)
1423 d->status = disabled;
1429 while (*p1 >= '0' && *p1 <= '9')
1431 if (*p1 && *p1 != ' ' && *p1 != '\t')
1432 error ("Arguments must be display numbers.");
1434 disable_display (atoi (p));
1437 while (*p == ' ' || *p == '\t')
1443 /* Print the value in stack frame FRAME of a variable
1444 specified by a struct symbol. */
1447 print_variable_value (var, frame, stream)
1452 value val = read_var_value (var, frame);
1453 value_print (val, stream, 0, Val_pretty_default);
1456 /* Print the arguments of a stack frame, given the function FUNC
1457 running in that frame (as a symbol), the info on the frame,
1458 and the number of args according to the stack frame (or -1 if unknown). */
1460 /* References here and elsewhere to "number of args according to the
1461 stack frame" appear in all cases to refer to "number of ints of args
1462 according to the stack frame". At least for VAX, i386, isi. */
1465 print_frame_args (func, fi, num, stream)
1466 struct symbol *func;
1467 struct frame_info *fi;
1475 register struct symbol *sym;
1477 /* Offset of next stack argument beyond the one we have seen that is
1478 at the highest offset.
1479 -1 if we haven't come to a stack argument yet. */
1480 long highest_offset = -1;
1482 /* Number of ints of arguments that we have printed so far. */
1483 int args_printed = 0;
1487 b = SYMBOL_BLOCK_VALUE (func);
1488 nsyms = BLOCK_NSYMS (b);
1491 for (i = 0; i < nsyms; i++)
1494 sym = BLOCK_SYM (b, i);
1496 if (SYMBOL_CLASS (sym) != LOC_REGPARM
1497 && SYMBOL_CLASS (sym) != LOC_ARG
1498 && SYMBOL_CLASS (sym) != LOC_LOCAL_ARG
1499 && SYMBOL_CLASS (sym) != LOC_REF_ARG)
1502 /* We have to re-look-up the symbol because arguments often have
1503 two entries (one a parameter, one a register or local), and the one
1504 we want is the non-parm, which lookup_symbol will find for
1505 us. After this, sym could be any SYMBOL_CLASS... */
1506 sym = lookup_symbol (SYMBOL_NAME (sym),
1507 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
1509 switch (SYMBOL_CLASS (sym)) {
1511 /* Keep track of the highest stack argument offset seen */
1515 long current_offset = SYMBOL_VALUE (sym);
1517 arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1519 /* Compute address of next argument by adding the size of
1520 this argument and rounding to an int boundary. */
1522 = ((current_offset + arg_size + sizeof (int) - 1)
1523 & ~(sizeof (int) - 1));
1525 /* If this is the highest offset seen yet, set highest_offset. */
1526 if (highest_offset == -1
1527 || (current_offset > highest_offset))
1528 highest_offset = current_offset;
1530 /* Add the number of ints we're about to print to args_printed. */
1531 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
1534 /* Other types of symbols don't need to be kept track of. */
1539 /* Print the current arg. */
1541 fprintf_filtered (stream, ", ");
1543 fprint_symbol (stream, SYMBOL_NAME (sym));
1544 fputs_filtered ("=", stream);
1546 /* Avoid value_print because it will deref ref parameters. We just
1547 want to print their addresses. Print ??? for args whose address
1548 we do not know. We pass 2 as "recurse" to val_print because our
1549 standard indentation here is 4 spaces, and val_print indents
1550 2 for each recurse. */
1551 val = read_var_value (sym, FRAME_INFO_ID (fi));
1553 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val),
1554 stream, 0, 0, 2, Val_no_prettyprint);
1556 fputs_filtered ("???", stream);
1560 /* Don't print nameless args in situations where we don't know
1561 enough about the stack to find them. */
1567 if (highest_offset == -1)
1568 start = FRAME_ARGS_SKIP;
1570 start = highest_offset;
1572 addr = FRAME_ARGS_ADDRESS (fi);
1574 print_frame_nameless_args (addr, start, num - args_printed,
1579 /* Print nameless args on STREAM.
1580 ARGSADDR is the address of the arglist, START is the offset
1581 of the first nameless arg, and NUM is the number of nameless args to
1582 print. FIRST is nonzero if this is the first argument (not just
1583 the first nameless arg). */
1585 print_frame_nameless_args (argsaddr, start, num, first, stream)
1593 for (i = 0; i < num; i++)
1597 fprintf_filtered (stream, ", ");
1598 #ifndef PRINT_TYPELESS_INTEGER
1599 fprintf_filtered (stream, "%d",
1600 read_memory_integer (argsaddr + start, sizeof (int)));
1602 PRINT_TYPELESS_INTEGER (stream, builtin_type_int,
1604 read_memory_integer (argsaddr + start,
1608 start += sizeof (int);
1614 printf_command (arg, from_tty)
1619 register char *s = arg;
1623 int allocated_args = 20;
1626 val_args = (value *) xmalloc (allocated_args * sizeof (value));
1629 error_no_arg ("format-control string and values to print");
1631 /* Skip white space before format string */
1632 while (*s == ' ' || *s == '\t') s++;
1634 /* A format string should follow, enveloped in double quotes */
1636 error ("Bad format string, missing '\"'.");
1638 /* Parse the format-control string and copy it into the string STRING,
1639 processing some kinds of escape sequence. */
1641 f = string = (char *) alloca (strlen (s) + 1);
1648 error ("Bad format string, non-terminated '\"'.");
1649 /* doesn't return */
1670 /* ??? TODO: handle other escape sequences */
1671 error ("Unrecognized \\ escape character in format string.");
1680 /* Skip over " and following space and comma. */
1683 while (*s == ' ' || *s == '\t') s++;
1685 if (*s != ',' && *s != 0)
1686 error ("Invalid argument syntax");
1689 while (*s == ' ' || *s == '\t') s++;
1692 /* Now scan the string for %-specs and see what kinds of args they want.
1693 argclass[I] classifies the %-specs so we can give vprintf something
1694 of the right size. */
1696 enum argclass {int_arg, string_arg, double_arg, long_long_arg};
1697 enum argclass *argclass;
1703 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1710 while (strchr ("0123456789.hlL-+ #", *f))
1712 if (*f == 'l' || *f == 'L')
1717 argclass[nargs_wanted++] = string_arg;
1718 else if (*f == 'e' || *f == 'f' || *f == 'g')
1719 argclass[nargs_wanted++] = double_arg;
1720 else if (lcount > 1)
1721 argclass[nargs_wanted++] = long_long_arg;
1723 argclass[nargs_wanted++] = int_arg;
1727 /* Now, parse all arguments and evaluate them.
1728 Store the VALUEs in VAL_ARGS. */
1733 if (nargs == allocated_args)
1734 val_args = (value *) xrealloc (val_args,
1735 (allocated_args *= 2)
1738 val_args[nargs] = parse_to_comma_and_eval (&s1);
1740 /* If format string wants a float, unchecked-convert the value to
1741 floating point of the same size */
1743 if (argclass[nargs] == double_arg)
1745 if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (float))
1746 VALUE_TYPE (val_args[nargs]) = builtin_type_float;
1747 if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (double))
1748 VALUE_TYPE (val_args[nargs]) = builtin_type_double;
1756 if (nargs != nargs_wanted)
1757 error ("Wrong number of arguments for specified format-string");
1759 /* Now lay out an argument-list containing the arguments
1760 as doubles, integers and C pointers. */
1762 arg_bytes = (char *) alloca (sizeof (double) * nargs);
1764 for (i = 0; i < nargs; i++)
1766 if (argclass[i] == string_arg)
1771 tem = value_as_pointer (val_args[i]);
1773 /* This is a %s argument. Find the length of the string. */
1778 read_memory (tem + j, &c, 1);
1783 /* Copy the string contents into a string inside GDB. */
1784 str = (char *) alloca (j + 1);
1785 read_memory (tem, str, j);
1788 /* Pass address of internal copy as the arg to vprintf. */
1789 *((int *) &arg_bytes[argindex]) = (int) str;
1790 argindex += sizeof (int);
1792 else if (VALUE_TYPE (val_args[i])->code == TYPE_CODE_FLT)
1794 *((double *) &arg_bytes[argindex]) = value_as_double (val_args[i]);
1795 argindex += sizeof (double);
1799 if (argclass[i] == long_long_arg)
1801 *(long long *) &arg_bytes[argindex] = value_as_long (val_args[i]);
1802 argindex += sizeof (long long);
1807 *((long *) &arg_bytes[argindex]) = value_as_long (val_args[i]);
1808 argindex += sizeof (long);
1813 /* There is not a standard way to make a va_list, so we need
1814 to do various things for different systems. */
1815 #if defined (__INT_VARARGS_H)
1820 list.__va_stk = (int *) arg_bytes;
1821 list.__va_reg = (int *) arg_bytes;
1822 vprintf (string, list);
1824 #else /* No __INT_VARARGS_H. */
1825 vprintf (string, arg_bytes);
1826 #endif /* No __INT_VARARGS_H. */
1829 /* Helper function for asdump_command. Finds the bounds of a function
1830 for a specified section of text. PC is an address within the
1831 function which you want bounds for; *LOW and *HIGH are set to the
1832 beginning (inclusive) and end (exclusive) of the function. This
1833 function returns 1 on success and 0 on failure. */
1836 containing_function_bounds (pc, low, high)
1837 CORE_ADDR pc, *low, *high;
1841 if (!find_pc_partial_function (pc, 0, low))
1847 if (!find_pc_partial_function (scan, 0, high))
1849 } while (*low == *high);
1854 /* Dump a specified section of assembly code. With no command line
1855 arguments, this command will dump the assembly code for the
1856 function surrounding the pc value in the selected frame. With one
1857 argument, it will dump the assembly code surrounding that pc value.
1858 Two arguments are interpeted as bounds within which to dump
1863 disassemble_command (arg, from_tty)
1867 CORE_ADDR low, high;
1873 if (!selected_frame)
1874 error ("No frame selected.\n");
1876 pc = get_frame_pc (selected_frame);
1877 if (!containing_function_bounds (pc, &low, &high))
1878 error ("No function contains pc specified by selected frame.\n");
1880 else if (!(space_index = (char *) strchr (arg, ' ')))
1883 pc = parse_and_eval_address (arg);
1884 if (!containing_function_bounds (pc, &low, &high))
1885 error ("No function contains specified pc.\n");
1889 /* Two arguments. */
1890 *space_index = '\0';
1891 low = parse_and_eval_address (arg);
1892 high = parse_and_eval_address (space_index + 1);
1895 printf_filtered ("Dump of assembler code ");
1899 find_pc_partial_function (pc, &name, 0);
1900 printf_filtered ("for function %s:\n", name);
1903 printf_filtered ("from 0x%x to 0x%x:\n", low, high);
1905 /* Dump the specified range. */
1906 for (pc = low; pc < high; )
1909 print_address (pc, stdout);
1910 printf_filtered (":\t");
1911 pc += print_insn (pc, stdout);
1912 printf_filtered ("\n");
1914 printf_filtered ("End of assembler dump.\n");
1920 _initialize_printcmd ()
1922 current_display_number = -1;
1924 add_info ("address", address_info,
1925 "Describe where variable VAR is stored.");
1927 add_com ("x", class_vars, x_command,
1928 "Examine memory: x/FMT ADDRESS.\n\
1929 ADDRESS is an expression for the memory address to examine.\n\
1930 FMT is a repeat count followed by a format letter and a size letter.\n\
1931 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1932 f(float), a(address), i(instruction), c(char) and s(string).\n\
1933 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1934 g is meaningful only with f, for type double.\n\
1935 The specified number of objects of the specified size are printed\n\
1936 according to the format.\n\n\
1937 Defaults for format and size letters are those previously used.\n\
1938 Default count is 1. Default address is following last thing printed\n\
1939 with this command or \"print\".");
1941 add_com ("disassemble", class_vars, disassemble_command,
1942 "Disassemble a specified section of memory.\n\
1943 Default is the function surrounding the pc of the selected frame.\n\
1944 With a single argument, the function surrounding that address is dumped.\n\
1945 Two arguments are taken as a range of memory to dump.");
1947 add_com ("ptype", class_vars, ptype_command,
1948 "Print definition of type TYPE.\n\
1949 Argument may be a type name defined by typedef, or \"struct STRUCTNAME\"\n\
1950 or \"union UNIONNAME\" or \"enum ENUMNAME\".\n\
1951 The selected stack frame's lexical context is used to look up the name.");
1953 add_com ("whatis", class_vars, whatis_command,
1954 "Print data type of expression EXP.");
1957 add_com ("whereis", class_vars, whereis_command,
1958 "Print line number and file of definition of variable.");
1961 add_info ("display", display_info,
1962 "Expressions to display when program stops, with code numbers.");
1964 add_cmd ("undisplay", class_vars, undisplay_command,
1965 "Cancel some expressions to be displayed when program stops.\n\
1966 Arguments are the code numbers of the expressions to stop displaying.\n\
1967 No argument means cancel all automatic-display expressions.\n\
1968 \"delete display\" has the same effect as this command.\n\
1969 Do \"info display\" to see current list of code numbers.",
1972 add_com ("display", class_vars, display_command,
1973 "Print value of expression EXP each time the program stops.\n\
1974 /FMT may be used before EXP as in the \"print\" command.\n\
1975 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
1976 as in the \"x\" command, and then EXP is used to get the address to examine\n\
1977 and examining is done as in the \"x\" command.\n\n\
1978 With no argument, display all currently requested auto-display expressions.\n\
1979 Use \"undisplay\" to cancel display requests previously made.");
1981 add_cmd ("display", class_vars, enable_display,
1982 "Enable some expressions to be displayed when program stops.\n\
1983 Arguments are the code numbers of the expressions to resume displaying.\n\
1984 No argument means enable all automatic-display expressions.\n\
1985 Do \"info display\" to see current list of code numbers.", &enablelist);
1987 add_cmd ("display", class_vars, disable_display_command,
1988 "Disable some expressions to be displayed when program stops.\n\
1989 Arguments are the code numbers of the expressions to stop displaying.\n\
1990 No argument means disable all automatic-display expressions.\n\
1991 Do \"info display\" to see current list of code numbers.", &disablelist);
1993 add_cmd ("display", class_vars, undisplay_command,
1994 "Cancel some expressions to be displayed when program stops.\n\
1995 Arguments are the code numbers of the expressions to stop displaying.\n\
1996 No argument means cancel all automatic-display expressions.\n\
1997 Do \"info display\" to see current list of code numbers.", &deletelist);
1999 add_com ("printf", class_vars, printf_command,
2000 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2001 This is useful for formatted output in user-defined commands.");
2002 add_com ("output", class_vars, output_command,
2003 "Like \"print\" but don't put in value history and don't print newline.\n\
2004 This is useful in user-defined commands.");
2006 add_prefix_cmd ("set", class_vars, set_command,
2007 "Perform an assignment VAR = EXP.\n\
2008 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
2009 (names starting with $), a register (a few standard names starting with $),\n\
2010 or an actual variable in the program being debugged. EXP is any expression.\n\
2011 Use \"set variable\" for variables with names identical to set subcommands.\n\
2012 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2013 You can see these environment settings with the \"show\" command.",
2014 &setlist, "set ", 1, &cmdlist);
2016 /* "call" is the same as "set", but handy for dbx users to call fns. */
2017 add_com ("call", class_vars, call_command,
2018 "Call a function in the inferior process.\n\
2019 The argument is the function name and arguments, in standard C notation.\n\
2020 The result is printed and saved in the value history, if it is not void.");
2022 add_cmd ("variable", class_vars, set_command,
2023 "Perform an assignment VAR = EXP.\n\
2024 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
2025 (names starting with $), a register (a few standard names starting with $),\n\
2026 or an actual variable in the program being debugged. EXP is any expression.\n\
2027 This may usually be abbreviated to simply \"set\".",
2030 add_com ("print", class_vars, print_command,
2031 concat ("Print value of expression EXP.\n\
2032 Variables accessible are those of the lexical environment of the selected\n\
2033 stack frame, plus all those whose scope is global or an entire file.\n\
2035 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2036 $$NUM refers to NUM'th value back from the last one.\n\
2037 Names starting with $ refer to registers (with the values they would have\n\
2038 if the program were to return to the stack frame now selected, restoring\n\
2039 all registers saved by frames farther in) or else to debugger\n\
2040 \"convenience\" variables (any such name not a known register).\n\
2041 Use assignment expressions to give values to convenience variables.\n",
2043 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2044 @ is a binary operator for treating consecutive data objects\n\
2045 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2046 element is FOO, whose second element is stored in the space following\n\
2047 where FOO is stored, etc. FOO must be an expression whose value\n\
2048 resides in memory.\n",
2050 EXP may be preceded with /FMT, where FMT is a format letter\n\
2051 but no count or size letter (see \"x\" command)."));
2052 add_com_alias ("p", "print", class_vars, 1);
2054 add_com ("inspect", class_vars, inspect_command,
2055 "Same as \"print\" command, except that if you are running in the epoch\n\
2056 environment, the value is printed in its own window.");