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. */
28 #include "expression.h"
33 extern int asm_demangle; /* Whether to demangle syms in asm printouts */
34 extern int addressprint; /* Whether to print hex addresses in HLL " */
36 extern struct block *get_current_block ();
38 static void print_frame_nameless_args ();
47 /* Last specified output format. */
49 static char last_format = 'x';
51 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
53 static char last_size = 'w';
55 /* Default address to examine next. */
57 static CORE_ADDR next_address;
59 /* Last address examined. */
61 static CORE_ADDR last_examine_address;
63 /* Contents of last address examined.
64 This is not valid past the end of the `x' command! */
66 static value last_examine_value;
68 /* Number of auto-display expression currently being displayed.
69 So that we can deleted it if we get an error or a signal within it.
70 -1 when not doing one. */
72 int current_display_number;
74 /* Flag to low-level print routines that this value is being printed
75 in an epoch window. We'd like to pass this as a parameter, but
76 every routine would need to take it. Perhaps we can encapsulate
77 this in the I/O stream once we have GNU stdio. */
81 static void do_one_display ();
84 void print_scalar_formatted ();
87 /* Decode a format specification. *STRING_PTR should point to it.
88 OFORMAT and OSIZE are used as defaults for the format and size
89 if none are given in the format specification.
90 If OSIZE is zero, then the size field of the returned value
91 should be set only if a size is explicitly specified by the
93 The structure returned describes all the data
94 found in the specification. In addition, *STRING_PTR is advanced
95 past the specification and past all whitespace following it. */
98 decode_format (string_ptr, oformat, osize)
103 struct format_data val;
104 register char *p = *string_ptr;
110 if (*p >= '0' && *p <= '9')
111 val.count = atoi (p);
112 while (*p >= '0' && *p <= '9') p++;
114 /* Now process size or format letters that follow. */
118 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
127 else if (*p >= 'a' && *p <= 'z')
134 /* Make sure 'g' size is not used on integer types.
135 Well, actually, we can handle hex. */
136 if (val.size == 'g' && val.format != 'f' && val.format != 'x')
140 while (*p == ' ' || *p == '\t') p++;
143 /* Set defaults for format and size if not specified. */
144 if (val.format == '?')
148 /* Neither has been specified. */
149 val.format = oformat;
153 /* If a size is specified, any format makes a reasonable
154 default except 'i'. */
155 val.format = oformat == 'i' ? 'x' : oformat;
157 else if (val.size == '?')
162 /* Addresses must be words. */
163 val.size = osize ? 'w' : osize;
166 /* Floating point has to be word or giantword. */
167 if (osize == 'w' || osize == 'g')
170 /* Default it to giantword if the last used size is not
172 val.size = osize ? 'g' : osize;
175 /* Characters default to one byte. */
176 val.size = osize ? 'b' : osize;
179 /* The default is the size most recently specified. */
186 /* Print value VAL on stdout according to FORMAT, a letter or 0.
187 Do not end with a newline.
188 0 means print VAL according to its own type.
189 SIZE is the letter for the size of datum being printed.
190 This is used to pad hex numbers so they line up. */
193 print_formatted (val, format, size)
195 register char format;
198 int len = TYPE_LENGTH (VALUE_TYPE (val));
200 if (VALUE_LVAL (val) == lval_memory)
201 next_address = VALUE_ADDRESS (val) + len;
206 next_address = VALUE_ADDRESS (val)
207 + value_print (value_addr (val), stdout, format, Val_pretty_default);
211 wrap_here (""); /* Force output out, print_insn not using _filtered */
212 next_address = VALUE_ADDRESS (val)
213 + print_insn (VALUE_ADDRESS (val), stdout);
218 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_ARRAY
219 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_STRUCT
220 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_UNION
221 || VALUE_REPEATED (val))
222 value_print (val, stdout, format, Val_pretty_default);
224 print_scalar_formatted (VALUE_CONTENTS (val), VALUE_TYPE (val),
225 format, size, stdout);
229 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
230 according to letters FORMAT and SIZE on STREAM.
231 FORMAT may not be zero. Formats s and i are not supported at this level.
233 This is how the elements of an array or structure are printed
237 print_scalar_formatted (valaddr, type, format, size, stream)
245 int len = TYPE_LENGTH (type);
247 if (size == 'g' && sizeof (LONGEST) < 8
250 /* ok, we're going to have to get fancy here. Assumption: a
251 long is four bytes. FIXME. */
252 unsigned long v1, v2;
254 v1 = unpack_long (builtin_type_long, valaddr);
255 v2 = unpack_long (builtin_type_long, valaddr + 4);
257 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
258 /* Swap the two for printing */
271 fprintf_filtered (stream, local_hex_format_custom("08x%08"), v1, v2);
274 error ("Output size \"g\" unimplemented for format \"%c\".",
280 val_long = unpack_long (type, valaddr);
282 /* If value is unsigned, truncate it in case negative. */
285 if (len == sizeof (char))
286 val_long &= (1 << 8 * sizeof(char)) - 1;
287 else if (len == sizeof (short))
288 val_long &= (1 << 8 * sizeof(short)) - 1;
289 else if (len == sizeof (long))
290 val_long &= (unsigned long) - 1;
298 /* no size specified, like in print. Print varying # of digits. */
299 #if defined (LONG_LONG)
300 fprintf_filtered (stream, local_hex_format_custom("ll"), val_long);
301 #else /* not LONG_LONG. */
302 fprintf_filtered (stream, local_hex_format_custom("l"), val_long);
303 #endif /* not LONG_LONG. */
306 #if defined (LONG_LONG)
310 fprintf_filtered (stream, local_hex_format_custom("02ll"), val_long);
313 fprintf_filtered (stream, local_hex_format_custom("04ll"), val_long);
316 fprintf_filtered (stream, local_hex_format_custom("08ll"), val_long);
319 fprintf_filtered (stream, local_hex_format_custom("016ll"), val_long);
322 error ("Undefined output size \"%c\".", size);
324 #else /* not LONG_LONG. */
328 fprintf_filtered (stream, local_hex_format_custom("02"), val_long);
331 fprintf_filtered (stream, local_hex_format_custom("04"), val_long);
334 fprintf_filtered (stream, local_hex_format_custom("08"), val_long);
337 fprintf_filtered (stream, local_hex_format_custom("016"), val_long);
340 error ("Undefined output size \"%c\".", size);
342 #endif /* not LONG_LONG */
347 fprintf_filtered (stream, "%lld", val_long);
349 fprintf_filtered (stream, "%d", val_long);
355 fprintf_filtered (stream, "%llu", val_long);
357 fprintf_filtered (stream, "%u", val_long);
364 fprintf_filtered (stream, local_octal_format_custom("ll"), val_long);
366 fprintf_filtered (stream, local_octal_format(), val_long);
369 fprintf_filtered (stream, "0");
373 print_address (unpack_pointer (type, valaddr), stream);
377 value_print (value_from_longest (builtin_type_char, val_long), stream, 0,
382 if (len == sizeof (float))
383 type = builtin_type_float;
384 else if (len == sizeof (double))
385 type = builtin_type_double;
386 print_floating (valaddr, type, stream);
393 /* Binary; 't' stands for "two". */
395 char bits[8*(sizeof val_long) + 1];
400 width = 8*(sizeof val_long);
417 error ("Undefined output size \"%c\".", size);
423 bits[width] = (val_long & 1) ? '1' : '0';
428 while (*cp && *cp == '0')
433 fprintf_filtered (stream, cp);
438 error ("Undefined output format \"%c\".", format);
442 /* Specify default address for `x' command.
443 `info lines' uses this. */
446 set_next_address (addr)
451 /* Make address available to the user as $_. */
452 set_internalvar (lookup_internalvar ("_"),
453 value_from_longest (lookup_pointer_type (builtin_type_void),
457 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
458 after LEADIN. Print nothing if no symbolic name is found nearby.
459 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
460 or to interpret it as a possible C++ name and convert it back to source
464 print_address_symbolic (addr, stream, do_demangle, leadin)
471 register int i = find_pc_misc_function (addr);
473 /* If nothing comes out, don't print anything symbolic. */
478 fputs_filtered (leadin, stream);
479 fputs_filtered ("<", stream);
481 fputs_demangled (misc_function_vector[i].name, stream, 1);
483 fputs_filtered (misc_function_vector[i].name, stream);
484 name_location = misc_function_vector[i].address;
485 if (addr - name_location)
486 fprintf_filtered (stream, "+%d>", addr - name_location);
488 fputs_filtered (">", stream);
491 /* Print address ADDR symbolically on STREAM.
492 First print it as a number. Then perhaps print
493 <SYMBOL + OFFSET> after the number. */
496 print_address (addr, stream)
500 fprintf_filtered (stream, local_hex_format(), addr);
501 print_address_symbolic (addr, stream, asm_demangle, " ");
504 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
505 controls whether to print the symbolic name "raw" or demangled.
506 Global setting "addressprint" controls whether to print hex address
510 print_address_demangle (addr, stream, do_demangle)
516 fprintf_filtered (stream, "0");
517 } else if (addressprint) {
518 fprintf_filtered (stream, local_hex_format(), addr);
519 print_address_symbolic (addr, stream, do_demangle, " ");
521 print_address_symbolic (addr, stream, do_demangle, "");
526 /* Examine data at address ADDR in format FMT.
527 Fetch it from memory and print on stdout. */
530 do_examine (fmt, addr)
531 struct format_data fmt;
534 register char format = 0;
536 register int count = 1;
537 struct type *val_type;
539 register int maxelts;
546 /* String or instruction format implies fetch single bytes
547 regardless of the specified size. */
548 if (format == 's' || format == 'i')
552 val_type = builtin_type_char;
553 else if (size == 'h')
554 val_type = builtin_type_short;
555 else if (size == 'w')
556 val_type = builtin_type_long;
557 else if (size == 'g')
559 val_type = builtin_type_double;
561 val_type = builtin_type_long_long;
569 if (format == 's' || format == 'i')
572 /* Print as many objects as specified in COUNT, at most maxelts per line,
573 with the address of the next one at the start of each line. */
577 print_address (next_address, stdout);
578 printf_filtered (":");
583 printf_filtered ("\t");
584 /* Note that print_formatted sets next_address for the next
586 last_examine_address = next_address;
587 last_examine_value = value_at (val_type, next_address);
588 print_formatted (last_examine_value, format, size);
590 printf_filtered ("\n");
596 validate_format (fmt, cmdname)
597 struct format_data fmt;
601 error ("Size letters are meaningless in \"%s\" command.", cmdname);
603 error ("Item count other than 1 is meaningless in \"%s\" command.",
605 if (fmt.format == 'i' || fmt.format == 's')
606 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
607 fmt.format, cmdname);
611 print_command_1 (exp, inspect, voidprint)
616 struct expression *expr;
617 register struct cleanup *old_chain = 0;
618 register char format = 0;
620 struct format_data fmt;
623 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
624 inspect_it = inspect;
626 if (exp && *exp == '/')
629 fmt = decode_format (&exp, last_format, 0);
630 validate_format (fmt, "print");
631 last_format = format = fmt.format;
642 extern int objectprint;
644 expr = parse_expression (exp);
645 old_chain = make_cleanup (free_current_contents, &expr);
647 val = evaluate_expression (expr);
649 /* C++: figure out what type we actually want to print it as. */
650 type = VALUE_TYPE (val);
653 && (TYPE_CODE (type) == TYPE_CODE_PTR
654 || TYPE_CODE (type) == TYPE_CODE_REF)
655 && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT)
659 v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
663 type = VALUE_TYPE (val);
668 val = access_value_history (0);
670 if (voidprint || (val && VALUE_TYPE (val) &&
671 TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
673 int histindex = record_latest_value (val);
676 printf ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
678 if (histindex >= 0) printf_filtered ("$%d = ", histindex);
680 print_formatted (val, format, fmt.size);
681 printf_filtered ("\n");
687 do_cleanups (old_chain);
688 inspect_it = 0; /* Reset print routines to normal */
693 print_command (exp, from_tty)
697 print_command_1 (exp, 0, 1);
700 /* Same as print, except in epoch, it gets its own window */
703 inspect_command (exp, from_tty)
707 extern int epoch_interface;
709 print_command_1 (exp, epoch_interface, 1);
712 /* Same as print, except it doesn't print void results. */
715 call_command (exp, from_tty)
719 print_command_1 (exp, 0, 0);
724 output_command (exp, from_tty)
728 struct expression *expr;
729 register struct cleanup *old_chain;
730 register char format = 0;
732 struct format_data fmt;
734 if (exp && *exp == '/')
737 fmt = decode_format (&exp, 0, 0);
738 validate_format (fmt, "print");
742 expr = parse_expression (exp);
743 old_chain = make_cleanup (free_current_contents, &expr);
745 val = evaluate_expression (expr);
747 print_formatted (val, format, fmt.size);
749 do_cleanups (old_chain);
754 set_command (exp, from_tty)
758 struct expression *expr = parse_expression (exp);
759 register struct cleanup *old_chain
760 = make_cleanup (free_current_contents, &expr);
761 evaluate_expression (expr);
762 do_cleanups (old_chain);
767 address_info (exp, from_tty)
771 register struct symbol *sym;
773 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
774 if exp is a field of `this'. */
777 error ("Argument required.");
779 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
780 &is_a_field_of_this, (struct symtab **)NULL);
785 if (is_a_field_of_this)
787 printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp);
791 for (i = 0; i < misc_function_count; i++)
792 if (!strcmp (misc_function_vector[i].name, exp))
795 if (i < misc_function_count)
796 printf ("Symbol \"%s\" is at %s in a file compiled without debugging.\n",
797 exp, local_hex_string(misc_function_vector[i].address));
799 error ("No symbol \"%s\" in current context.", exp);
803 printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym));
804 val = SYMBOL_VALUE (sym);
806 switch (SYMBOL_CLASS (sym))
809 case LOC_CONST_BYTES:
814 printf ("a label at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
818 printf ("a variable in register %s", reg_names[val]);
822 printf ("static storage at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
826 printf ("an argument in register %s", reg_names[val]);
830 printf ("an argument at offset %ld", val);
834 printf ("an argument at frame offset %ld", val);
838 printf ("a local variable at frame offset %ld", val);
842 printf ("a reference argument at offset %ld", val);
846 printf ("a typedef");
850 printf ("a function at address %s",
851 local_hex_string(BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
855 printf ("of unknown (botched) type");
862 x_command (exp, from_tty)
866 struct expression *expr;
867 struct format_data fmt;
868 struct cleanup *old_chain;
871 fmt.format = last_format;
872 fmt.size = last_size;
875 if (exp && *exp == '/')
878 fmt = decode_format (&exp, last_format, last_size);
879 last_size = fmt.size;
880 last_format = fmt.format;
883 /* If we have an expression, evaluate it and use it as the address. */
885 if (exp != 0 && *exp != 0)
887 expr = parse_expression (exp);
888 /* Cause expression not to be there any more
889 if this command is repeated with Newline.
890 But don't clobber a user-defined command's definition. */
893 old_chain = make_cleanup (free_current_contents, &expr);
894 val = evaluate_expression (expr);
895 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
896 val = value_ind (val);
897 /* In rvalue contexts, such as this, functions are coerced into
898 pointers to functions. This makes "x/i main" work. */
899 if (/* last_format == 'i'
900 && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
901 && VALUE_LVAL (val) == lval_memory)
902 next_address = VALUE_ADDRESS (val);
904 next_address = value_as_pointer (val);
905 do_cleanups (old_chain);
908 do_examine (fmt, next_address);
910 /* Set a couple of internal variables if appropriate. */
911 if (last_examine_value)
913 /* Make last address examined available to the user as $_. Use
914 the correct pointer type. */
915 set_internalvar (lookup_internalvar ("_"),
917 lookup_pointer_type (VALUE_TYPE (last_examine_value)),
918 (LONGEST) last_examine_address));
920 /* Make contents of last address examined available to the user as $__.*/
921 set_internalvar (lookup_internalvar ("__"), last_examine_value);
925 /* Commands for printing types of things. */
927 /* Print type of EXP, or last thing in value history if EXP == NULL.
928 show is passed to type_print. */
930 whatis_exp (exp, show)
934 struct expression *expr;
936 register struct cleanup *old_chain;
940 expr = parse_expression (exp);
941 old_chain = make_cleanup (free_current_contents, &expr);
942 val = evaluate_type (expr);
945 val = access_value_history (0);
947 printf_filtered ("type = ");
948 type_print (VALUE_TYPE (val), "", stdout, show);
949 printf_filtered ("\n");
952 do_cleanups (old_chain);
957 whatis_command (exp, from_tty)
961 /* Most of the time users do not want to see all the fields
962 in a structure. If they do they can use the "ptype" command.
963 Hence the "-1" below. */
964 whatis_exp (exp, -1);
967 /* Simple subroutine for ptype_command. */
971 struct expression *exp;
973 if(exp->elts[0].opcode==OP_TYPE)
974 return exp->elts[1].type;
979 /* TYPENAME is either the name of a type, or an expression. */
982 ptype_command (typename, from_tty)
986 register struct type *type;
987 struct expression *expr;
988 register struct cleanup *old_chain;
992 expr = parse_expression (typename);
993 old_chain = make_cleanup (free_current_contents, &expr);
994 type = ptype_eval (expr);
998 printf_filtered ("type = ");
999 type_print (type, "", stdout, 1);
1000 printf_filtered ("\n");
1001 do_cleanups (old_chain);
1005 do_cleanups (old_chain);
1006 whatis_exp (typename, 1);
1010 whatis_exp (typename, 1);
1013 enum display_status {disabled, enabled};
1017 /* Chain link to next auto-display item. */
1018 struct display *next;
1019 /* Expression to be evaluated and displayed. */
1020 struct expression *exp;
1021 /* Item number of this auto-display item. */
1023 /* Display format specified. */
1024 struct format_data format;
1025 /* Innermost block required by this expression when evaluated */
1026 struct block *block;
1027 /* Status of this display (enabled or disabled) */
1028 enum display_status status;
1031 /* Chain of expressions whose values should be displayed
1032 automatically each time the program stops. */
1034 static struct display *display_chain;
1036 static int display_number;
1038 /* Add an expression to the auto-display chain.
1039 Specify the expression. */
1042 display_command (exp, from_tty)
1046 struct format_data fmt;
1047 register struct expression *expr;
1048 register struct display *new;
1059 fmt = decode_format (&exp, 0, 0);
1060 if (fmt.size && fmt.format == 0)
1062 if (fmt.format == 'i' || fmt.format == 's')
1072 innermost_block = 0;
1073 expr = parse_expression (exp);
1075 new = (struct display *) xmalloc (sizeof (struct display));
1078 new->block = innermost_block;
1079 new->next = display_chain;
1080 new->number = ++display_number;
1082 new->status = enabled;
1083 display_chain = new;
1085 if (from_tty && target_has_execution)
1086 do_one_display (new);
1099 /* Clear out the display_chain.
1100 Done when new symtabs are loaded, since this invalidates
1101 the types stored in many expressions. */
1106 register struct display *d;
1108 while (d = display_chain)
1111 display_chain = d->next;
1116 /* Delete the auto-display number NUM. */
1119 delete_display (num)
1122 register struct display *d1, *d;
1125 error ("No display number %d.", num);
1127 if (display_chain->number == num)
1130 display_chain = d1->next;
1134 for (d = display_chain; ; d = d->next)
1137 error ("No display number %d.", num);
1138 if (d->next->number == num)
1148 /* Delete some values from the auto-display chain.
1149 Specify the element numbers. */
1152 undisplay_command (args)
1155 register char *p = args;
1161 if (query ("Delete all auto-display expressions? "))
1170 while (*p1 >= '0' && *p1 <= '9') p1++;
1171 if (*p1 && *p1 != ' ' && *p1 != '\t')
1172 error ("Arguments must be display numbers.");
1176 delete_display (num);
1179 while (*p == ' ' || *p == '\t') p++;
1184 /* Display a single auto-display.
1185 Do nothing if the display cannot be printed in the current context,
1186 or if the display is disabled. */
1192 int within_current_scope;
1194 if (d->status == disabled)
1198 within_current_scope = contained_in (get_selected_block (), d->block);
1200 within_current_scope = 1;
1201 if (!within_current_scope)
1204 current_display_number = d->number;
1206 printf_filtered ("%d: ", d->number);
1211 printf_filtered ("x/");
1212 if (d->format.count != 1)
1213 printf_filtered ("%d", d->format.count);
1214 printf_filtered ("%c", d->format.format);
1215 if (d->format.format != 'i' && d->format.format != 's')
1216 printf_filtered ("%c", d->format.size);
1217 printf_filtered (" ");
1218 print_expression (d->exp, stdout);
1219 if (d->format.count != 1)
1220 printf_filtered ("\n");
1222 printf_filtered (" ");
1224 addr = value_as_pointer (evaluate_expression (d->exp));
1225 if (d->format.format == 'i')
1226 addr = ADDR_BITS_REMOVE (addr);
1228 do_examine (d->format, addr);
1232 if (d->format.format)
1233 printf_filtered ("/%c ", d->format.format);
1234 print_expression (d->exp, stdout);
1235 printf_filtered (" = ");
1236 print_formatted (evaluate_expression (d->exp),
1237 d->format.format, d->format.size);
1238 printf_filtered ("\n");
1242 current_display_number = -1;
1245 /* Display all of the values on the auto-display chain which can be
1246 evaluated in the current scope. */
1251 register struct display *d;
1253 for (d = display_chain; d; d = d->next)
1257 /* Delete the auto-display which we were in the process of displaying.
1258 This is done when there is an error or a signal. */
1261 disable_display (num)
1264 register struct display *d;
1266 for (d = display_chain; d; d = d->next)
1267 if (d->number == num)
1269 d->status = disabled;
1272 printf ("No display number %d.\n", num);
1276 disable_current_display ()
1278 if (current_display_number >= 0)
1280 disable_display (current_display_number);
1281 fprintf (stderr, "Disabling display %d to avoid infinite recursion.\n",
1282 current_display_number);
1284 current_display_number = -1;
1290 register struct display *d;
1293 printf ("There are no auto-display expressions now.\n");
1295 printf_filtered ("Auto-display expressions now in effect:\n\
1296 Num Enb Expression\n");
1298 for (d = display_chain; d; d = d->next)
1300 printf_filtered ("%d: %c ", d->number, "ny"[(int)d->status]);
1302 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1304 else if (d->format.format)
1305 printf_filtered ("/%c ", d->format.format);
1306 print_expression (d->exp, stdout);
1307 if (d->block && !contained_in (get_selected_block (), d->block))
1308 printf_filtered (" (cannot be evaluated in the current context)");
1309 printf_filtered ("\n");
1315 enable_display (args)
1318 register char *p = args;
1321 register struct display *d;
1325 for (d = display_chain; d; d = d->next)
1326 d->status = enabled;
1332 while (*p1 >= '0' && *p1 <= '9')
1334 if (*p1 && *p1 != ' ' && *p1 != '\t')
1335 error ("Arguments must be display numbers.");
1339 for (d = display_chain; d; d = d->next)
1340 if (d->number == num)
1342 d->status = enabled;
1345 printf ("No display number %d.\n", num);
1348 while (*p == ' ' || *p == '\t')
1355 disable_display_command (args, from_tty)
1359 register char *p = args;
1361 register struct display *d;
1365 for (d = display_chain; d; d = d->next)
1366 d->status = disabled;
1372 while (*p1 >= '0' && *p1 <= '9')
1374 if (*p1 && *p1 != ' ' && *p1 != '\t')
1375 error ("Arguments must be display numbers.");
1377 disable_display (atoi (p));
1380 while (*p == ' ' || *p == '\t')
1386 /* Print the value in stack frame FRAME of a variable
1387 specified by a struct symbol. */
1390 print_variable_value (var, frame, stream)
1395 value val = read_var_value (var, frame);
1396 value_print (val, stream, 0, Val_pretty_default);
1399 /* Print the arguments of a stack frame, given the function FUNC
1400 running in that frame (as a symbol), the info on the frame,
1401 and the number of args according to the stack frame (or -1 if unknown). */
1403 /* References here and elsewhere to "number of args according to the
1404 stack frame" appear in all cases to refer to "number of ints of args
1405 according to the stack frame". At least for VAX, i386, isi. */
1408 print_frame_args (func, fi, num, stream)
1409 struct symbol *func;
1410 struct frame_info *fi;
1418 register struct symbol *sym;
1420 /* Offset of next stack argument beyond the one we have seen that is
1421 at the highest offset.
1422 -1 if we haven't come to a stack argument yet. */
1423 long highest_offset = -1;
1425 /* Number of ints of arguments that we have printed so far. */
1426 int args_printed = 0;
1430 b = SYMBOL_BLOCK_VALUE (func);
1431 nsyms = BLOCK_NSYMS (b);
1434 for (i = 0; i < nsyms; i++)
1437 sym = BLOCK_SYM (b, i);
1439 /* Keep track of the highest stack argument offset seen, and
1440 skip over any kinds of symbols we don't care about. */
1442 switch (SYMBOL_CLASS (sym)) {
1446 long current_offset = SYMBOL_VALUE (sym);
1448 arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1450 /* Compute address of next argument by adding the size of
1451 this argument and rounding to an int boundary. */
1453 = ((current_offset + arg_size + sizeof (int) - 1)
1454 & ~(sizeof (int) - 1));
1456 /* If this is the highest offset seen yet, set highest_offset. */
1457 if (highest_offset == -1
1458 || (current_offset > highest_offset))
1459 highest_offset = current_offset;
1461 /* Add the number of ints we're about to print to args_printed. */
1462 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
1465 /* We care about types of symbols, but don't need to keep track of
1466 stack offsets in them. */
1471 /* Other types of symbols we just skip over. */
1476 /* We have to re-look-up the symbol because arguments often have
1477 two entries (one a parameter, one a register or local), and the one
1478 we want is the non-parm, which lookup_symbol will find for
1479 us. After this, sym could be any SYMBOL_CLASS... */
1480 sym = lookup_symbol (SYMBOL_NAME (sym),
1481 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
1483 /* Print the current arg. */
1485 fprintf_filtered (stream, ", ");
1487 fprint_symbol (stream, SYMBOL_NAME (sym));
1488 fputs_filtered ("=", stream);
1490 /* Avoid value_print because it will deref ref parameters. We just
1491 want to print their addresses. Print ??? for args whose address
1492 we do not know. We pass 2 as "recurse" to val_print because our
1493 standard indentation here is 4 spaces, and val_print indents
1494 2 for each recurse. */
1495 val = read_var_value (sym, FRAME_INFO_ID (fi));
1497 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val),
1498 stream, 0, 0, 2, Val_no_prettyprint);
1500 fputs_filtered ("???", stream);
1504 /* Don't print nameless args in situations where we don't know
1505 enough about the stack to find them. */
1511 if (highest_offset == -1)
1512 start = FRAME_ARGS_SKIP;
1514 start = highest_offset;
1516 addr = FRAME_ARGS_ADDRESS (fi);
1518 print_frame_nameless_args (addr, start, num - args_printed,
1523 /* Print nameless args on STREAM.
1524 ARGSADDR is the address of the arglist, START is the offset
1525 of the first nameless arg, and NUM is the number of nameless args to
1526 print. FIRST is nonzero if this is the first argument (not just
1527 the first nameless arg). */
1529 print_frame_nameless_args (argsaddr, start, num, first, stream)
1537 for (i = 0; i < num; i++)
1541 fprintf_filtered (stream, ", ");
1542 #ifndef PRINT_TYPELESS_INTEGER
1543 fprintf_filtered (stream, "%d",
1544 read_memory_integer (argsaddr + start, sizeof (int)));
1546 PRINT_TYPELESS_INTEGER (stream, builtin_type_int,
1548 read_memory_integer (argsaddr + start,
1552 start += sizeof (int);
1558 printf_command (arg, from_tty)
1563 register char *s = arg;
1567 int allocated_args = 20;
1570 val_args = (value *) xmalloc (allocated_args * sizeof (value));
1573 error_no_arg ("format-control string and values to print");
1575 /* Skip white space before format string */
1576 while (*s == ' ' || *s == '\t') s++;
1578 /* A format string should follow, enveloped in double quotes */
1580 error ("Bad format string, missing '\"'.");
1582 /* Parse the format-control string and copy it into the string STRING,
1583 processing some kinds of escape sequence. */
1585 f = string = (char *) alloca (strlen (s) + 1);
1592 error ("Bad format string, non-terminated '\"'.");
1593 /* doesn't return */
1614 /* ??? TODO: handle other escape sequences */
1615 error ("Unrecognized \\ escape character in format string.");
1624 /* Skip over " and following space and comma. */
1627 while (*s == ' ' || *s == '\t') s++;
1629 if (*s != ',' && *s != 0)
1630 error ("Invalid argument syntax");
1633 while (*s == ' ' || *s == '\t') s++;
1636 /* Now scan the string for %-specs and see what kinds of args they want.
1637 argclass[I] classifies the %-specs so we can give vprintf something
1638 of the right size. */
1640 enum argclass {int_arg, string_arg, double_arg, long_long_arg};
1641 enum argclass *argclass;
1647 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1654 while (strchr ("0123456789.hlL-+ #", *f))
1656 if (*f == 'l' || *f == 'L')
1661 argclass[nargs_wanted++] = string_arg;
1662 else if (*f == 'e' || *f == 'f' || *f == 'g')
1663 argclass[nargs_wanted++] = double_arg;
1664 else if (lcount > 1)
1665 argclass[nargs_wanted++] = long_long_arg;
1667 argclass[nargs_wanted++] = int_arg;
1671 /* Now, parse all arguments and evaluate them.
1672 Store the VALUEs in VAL_ARGS. */
1677 if (nargs == allocated_args)
1678 val_args = (value *) xrealloc (val_args,
1679 (allocated_args *= 2)
1682 val_args[nargs] = parse_to_comma_and_eval (&s1);
1684 /* If format string wants a float, unchecked-convert the value to
1685 floating point of the same size */
1687 if (argclass[nargs] == double_arg)
1689 if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (float))
1690 VALUE_TYPE (val_args[nargs]) = builtin_type_float;
1691 if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (double))
1692 VALUE_TYPE (val_args[nargs]) = builtin_type_double;
1700 if (nargs != nargs_wanted)
1701 error ("Wrong number of arguments for specified format-string");
1703 /* Now lay out an argument-list containing the arguments
1704 as doubles, integers and C pointers. */
1706 arg_bytes = (char *) alloca (sizeof (double) * nargs);
1708 for (i = 0; i < nargs; i++)
1710 if (argclass[i] == string_arg)
1715 tem = value_as_pointer (val_args[i]);
1717 /* This is a %s argument. Find the length of the string. */
1722 read_memory (tem + j, &c, 1);
1727 /* Copy the string contents into a string inside GDB. */
1728 str = (char *) alloca (j + 1);
1729 read_memory (tem, str, j);
1732 /* Pass address of internal copy as the arg to vprintf. */
1733 *((int *) &arg_bytes[argindex]) = (int) str;
1734 argindex += sizeof (int);
1736 else if (VALUE_TYPE (val_args[i])->code == TYPE_CODE_FLT)
1738 *((double *) &arg_bytes[argindex]) = value_as_double (val_args[i]);
1739 argindex += sizeof (double);
1743 if (argclass[i] == long_long_arg)
1745 *(long long *) &arg_bytes[argindex] = value_as_long (val_args[i]);
1746 argindex += sizeof (long long);
1751 *((long *) &arg_bytes[argindex]) = value_as_long (val_args[i]);
1752 argindex += sizeof (long);
1757 /* There is not a standard way to make a va_list, so we need
1758 to do various things for different systems. */
1759 #if defined (__INT_VARARGS_H)
1764 list.__va_stk = (int *) arg_bytes;
1765 list.__va_reg = (int *) arg_bytes;
1766 vprintf (string, list);
1768 #else /* No __INT_VARARGS_H. */
1769 vprintf (string, arg_bytes);
1770 #endif /* No __INT_VARARGS_H. */
1773 /* Helper function for asdump_command. Finds the bounds of a function
1774 for a specified section of text. PC is an address within the
1775 function which you want bounds for; *LOW and *HIGH are set to the
1776 beginning (inclusive) and end (exclusive) of the function. This
1777 function returns 1 on success and 0 on failure. */
1780 containing_function_bounds (pc, low, high)
1781 CORE_ADDR pc, *low, *high;
1785 if (!find_pc_partial_function (pc, 0, low))
1791 if (!find_pc_partial_function (scan, 0, high))
1793 } while (*low == *high);
1798 /* Dump a specified section of assembly code. With no command line
1799 arguments, this command will dump the assembly code for the
1800 function surrounding the pc value in the selected frame. With one
1801 argument, it will dump the assembly code surrounding that pc value.
1802 Two arguments are interpeted as bounds within which to dump
1807 disassemble_command (arg, from_tty)
1811 CORE_ADDR low, high;
1817 if (!selected_frame)
1818 error ("No frame selected.\n");
1820 pc = get_frame_pc (selected_frame);
1821 if (!containing_function_bounds (pc, &low, &high))
1822 error ("No function contains pc specified by selected frame.\n");
1824 else if (!(space_index = (char *) strchr (arg, ' ')))
1827 pc = parse_and_eval_address (arg);
1828 if (!containing_function_bounds (pc, &low, &high))
1829 error ("No function contains specified pc.\n");
1833 /* Two arguments. */
1834 *space_index = '\0';
1835 low = parse_and_eval_address (arg);
1836 high = parse_and_eval_address (space_index + 1);
1839 printf_filtered ("Dump of assembler code ");
1843 find_pc_partial_function (pc, &name, 0);
1844 printf_filtered ("for function %s:\n", name);
1847 printf_filtered ("from %s ", local_hex_string(low));
1848 printf_filtered ("to %s:\n", local_hex_string(high));
1850 /* Dump the specified range. */
1851 for (pc = low; pc < high; )
1854 print_address (pc, stdout);
1855 printf_filtered (":\t");
1856 pc += print_insn (pc, stdout);
1857 printf_filtered ("\n");
1859 printf_filtered ("End of assembler dump.\n");
1865 _initialize_printcmd ()
1867 current_display_number = -1;
1869 add_info ("address", address_info,
1870 "Describe where variable VAR is stored.");
1872 add_com ("x", class_vars, x_command,
1873 "Examine memory: x/FMT ADDRESS.\n\
1874 ADDRESS is an expression for the memory address to examine.\n\
1875 FMT is a repeat count followed by a format letter and a size letter.\n\
1876 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1877 f(float), a(address), i(instruction), c(char) and s(string).\n\
1878 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1879 g is meaningful only with f, for type double.\n\
1880 The specified number of objects of the specified size are printed\n\
1881 according to the format.\n\n\
1882 Defaults for format and size letters are those previously used.\n\
1883 Default count is 1. Default address is following last thing printed\n\
1884 with this command or \"print\".");
1886 add_com ("disassemble", class_vars, disassemble_command,
1887 "Disassemble a specified section of memory.\n\
1888 Default is the function surrounding the pc of the selected frame.\n\
1889 With a single argument, the function surrounding that address is dumped.\n\
1890 Two arguments are taken as a range of memory to dump.");
1892 add_com ("ptype", class_vars, ptype_command,
1893 "Print definition of type TYPE.\n\
1894 Argument may be a type name defined by typedef, or \"struct STRUCTNAME\"\n\
1895 or \"union UNIONNAME\" or \"enum ENUMNAME\".\n\
1896 The selected stack frame's lexical context is used to look up the name.");
1898 add_com ("whatis", class_vars, whatis_command,
1899 "Print data type of expression EXP.");
1902 add_com ("whereis", class_vars, whereis_command,
1903 "Print line number and file of definition of variable.");
1906 add_info ("display", display_info,
1907 "Expressions to display when program stops, with code numbers.");
1909 add_cmd ("undisplay", class_vars, undisplay_command,
1910 "Cancel some expressions to be displayed when program stops.\n\
1911 Arguments are the code numbers of the expressions to stop displaying.\n\
1912 No argument means cancel all automatic-display expressions.\n\
1913 \"delete display\" has the same effect as this command.\n\
1914 Do \"info display\" to see current list of code numbers.",
1917 add_com ("display", class_vars, display_command,
1918 "Print value of expression EXP each time the program stops.\n\
1919 /FMT may be used before EXP as in the \"print\" command.\n\
1920 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
1921 as in the \"x\" command, and then EXP is used to get the address to examine\n\
1922 and examining is done as in the \"x\" command.\n\n\
1923 With no argument, display all currently requested auto-display expressions.\n\
1924 Use \"undisplay\" to cancel display requests previously made.");
1926 add_cmd ("display", class_vars, enable_display,
1927 "Enable some expressions to be displayed when program stops.\n\
1928 Arguments are the code numbers of the expressions to resume displaying.\n\
1929 No argument means enable all automatic-display expressions.\n\
1930 Do \"info display\" to see current list of code numbers.", &enablelist);
1932 add_cmd ("display", class_vars, disable_display_command,
1933 "Disable some expressions to be displayed when program stops.\n\
1934 Arguments are the code numbers of the expressions to stop displaying.\n\
1935 No argument means disable all automatic-display expressions.\n\
1936 Do \"info display\" to see current list of code numbers.", &disablelist);
1938 add_cmd ("display", class_vars, undisplay_command,
1939 "Cancel some expressions to be displayed when program stops.\n\
1940 Arguments are the code numbers of the expressions to stop displaying.\n\
1941 No argument means cancel all automatic-display expressions.\n\
1942 Do \"info display\" to see current list of code numbers.", &deletelist);
1944 add_com ("printf", class_vars, printf_command,
1945 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
1946 This is useful for formatted output in user-defined commands.");
1947 add_com ("output", class_vars, output_command,
1948 "Like \"print\" but don't put in value history and don't print newline.\n\
1949 This is useful in user-defined commands.");
1951 add_prefix_cmd ("set", class_vars, set_command,
1952 "Perform an assignment VAR = EXP.\n\
1953 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
1954 (names starting with $), a register (a few standard names starting with $),\n\
1955 or an actual variable in the program being debugged. EXP is any expression.\n\
1956 Use \"set variable\" for variables with names identical to set subcommands.\n\
1957 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
1958 You can see these environment settings with the \"show\" command.",
1959 &setlist, "set ", 1, &cmdlist);
1961 /* "call" is the same as "set", but handy for dbx users to call fns. */
1962 add_com ("call", class_vars, call_command,
1963 "Call a function in the inferior process.\n\
1964 The argument is the function name and arguments, in the notation of the\n\
1965 current working language. The result is printed and saved in the value\n\
1966 history, if it is not void.");
1968 add_cmd ("variable", class_vars, set_command,
1969 "Perform an assignment VAR = EXP.\n\
1970 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
1971 (names starting with $), a register (a few standard names starting with $),\n\
1972 or an actual variable in the program being debugged. EXP is any expression.\n\
1973 This may usually be abbreviated to simply \"set\".",
1976 add_com ("print", class_vars, print_command,
1977 concat ("Print value of expression EXP.\n\
1978 Variables accessible are those of the lexical environment of the selected\n\
1979 stack frame, plus all those whose scope is global or an entire file.\n\
1981 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
1982 $$NUM refers to NUM'th value back from the last one.\n\
1983 Names starting with $ refer to registers (with the values they would have\n\
1984 if the program were to return to the stack frame now selected, restoring\n\
1985 all registers saved by frames farther in) or else to debugger\n\
1986 \"convenience\" variables (any such name not a known register).\n\
1987 Use assignment expressions to give values to convenience variables.\n",
1989 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
1990 @ is a binary operator for treating consecutive data objects\n\
1991 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
1992 element is FOO, whose second element is stored in the space following\n\
1993 where FOO is stored, etc. FOO must be an expression whose value\n\
1994 resides in memory.\n",
1996 EXP may be preceded with /FMT, where FMT is a format letter\n\
1997 but no count or size letter (see \"x\" command)."));
1998 add_com_alias ("p", "print", class_vars, 1);
2000 add_com ("inspect", class_vars, inspect_command,
2001 "Same as \"print\" command, except that if you are running in the epoch\n\
2002 environment, the value is printed in its own window.");