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. */
28 #include "expression.h"
32 #include "breakpoint.h"
35 extern int asm_demangle; /* Whether to demangle syms in asm printouts */
36 extern int addressprint; /* Whether to print hex addresses in HLL " */
45 /* Last specified output format. */
47 static char last_format = 'x';
49 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
51 static char last_size = 'w';
53 /* Default address to examine next. */
55 static CORE_ADDR next_address;
57 /* Last address examined. */
59 static CORE_ADDR last_examine_address;
61 /* Contents of last address examined.
62 This is not valid past the end of the `x' command! */
64 static value last_examine_value;
66 /* Largest offset between a symbolic value and an address, that will be
67 printed as `0x1234 <symbol+offset>'. */
69 static unsigned int max_symbolic_offset = UINT_MAX;
71 /* Append the source filename and linenumber of the symbol when
72 printing a symbolic value as `<symbol at filename:linenum>' if set. */
73 static int print_symbol_filename = 0;
75 /* Number of auto-display expression currently being displayed.
76 So that we can disable it if we get an error or a signal within it.
77 -1 when not doing one. */
79 int current_display_number;
81 /* Flag to low-level print routines that this value is being printed
82 in an epoch window. We'd like to pass this as a parameter, but
83 every routine would need to take it. Perhaps we can encapsulate
84 this in the I/O stream once we have GNU stdio. */
90 /* Chain link to next auto-display item. */
92 /* Expression to be evaluated and displayed. */
93 struct expression *exp;
94 /* Item number of this auto-display item. */
96 /* Display format specified. */
97 struct format_data format;
98 /* Innermost block required by this expression when evaluated */
100 /* Status of this display (enabled or disabled) */
104 /* Chain of expressions whose values should be displayed
105 automatically each time the program stops. */
107 static struct display *display_chain;
109 static int display_number;
111 /* Prototypes for local functions */
114 delete_display PARAMS ((int));
117 enable_display PARAMS ((char *, int));
120 disable_display_command PARAMS ((char *, int));
123 disassemble_command PARAMS ((char *, int));
126 printf_command PARAMS ((char *, int));
129 print_frame_nameless_args PARAMS ((struct frame_info *, long, int, int,
133 display_info PARAMS ((char *, int));
136 do_one_display PARAMS ((struct display *));
139 undisplay_command PARAMS ((char *, int));
142 free_display PARAMS ((struct display *));
145 display_command PARAMS ((char *, int));
148 x_command PARAMS ((char *, int));
151 address_info PARAMS ((char *, int));
154 set_command PARAMS ((char *, int));
157 output_command PARAMS ((char *, int));
160 call_command PARAMS ((char *, int));
163 inspect_command PARAMS ((char *, int));
166 print_command PARAMS ((char *, int));
169 print_command_1 PARAMS ((char *, int, int));
172 validate_format PARAMS ((struct format_data, char *));
175 do_examine PARAMS ((struct format_data, CORE_ADDR));
178 print_formatted PARAMS ((value, int, int));
180 static struct format_data
181 decode_format PARAMS ((char **, int, int));
184 /* Decode a format specification. *STRING_PTR should point to it.
185 OFORMAT and OSIZE are used as defaults for the format and size
186 if none are given in the format specification.
187 If OSIZE is zero, then the size field of the returned value
188 should be set only if a size is explicitly specified by the
190 The structure returned describes all the data
191 found in the specification. In addition, *STRING_PTR is advanced
192 past the specification and past all whitespace following it. */
194 static struct format_data
195 decode_format (string_ptr, oformat, osize)
200 struct format_data val;
201 register char *p = *string_ptr;
207 if (*p >= '0' && *p <= '9')
208 val.count = atoi (p);
209 while (*p >= '0' && *p <= '9') p++;
211 /* Now process size or format letters that follow. */
215 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
217 #ifdef CC_HAS_LONG_LONG
224 else if (*p >= 'a' && *p <= 'z')
230 #ifndef CC_HAS_LONG_LONG
231 /* Make sure 'g' size is not used on integer types.
232 Well, actually, we can handle hex. */
233 if (val.size == 'g' && val.format != 'f' && val.format != 'x')
237 while (*p == ' ' || *p == '\t') p++;
240 /* Set defaults for format and size if not specified. */
241 if (val.format == '?')
245 /* Neither has been specified. */
246 val.format = oformat;
250 /* If a size is specified, any format makes a reasonable
251 default except 'i'. */
252 val.format = oformat == 'i' ? 'x' : oformat;
254 else if (val.size == '?')
259 /* Addresses must be words. */
260 val.size = osize ? 'w' : osize;
263 /* Floating point has to be word or giantword. */
264 if (osize == 'w' || osize == 'g')
267 /* Default it to giantword if the last used size is not
269 val.size = osize ? 'g' : osize;
272 /* Characters default to one byte. */
273 val.size = osize ? 'b' : osize;
276 /* The default is the size most recently specified. */
283 /* Print value VAL on stdout according to FORMAT, a letter or 0.
284 Do not end with a newline.
285 0 means print VAL according to its own type.
286 SIZE is the letter for the size of datum being printed.
287 This is used to pad hex numbers so they line up. */
290 print_formatted (val, format, size)
295 int len = TYPE_LENGTH (VALUE_TYPE (val));
297 if (VALUE_LVAL (val) == lval_memory)
298 next_address = VALUE_ADDRESS (val) + len;
303 next_address = VALUE_ADDRESS (val)
304 + value_print (value_addr (val), stdout, format, Val_pretty_default);
308 /* The old comment says
309 "Force output out, print_insn not using _filtered".
310 I'm not completely sure what that means, I suspect most print_insn
311 now do use _filtered, so I guess it's obsolete. */
312 /* We often wrap here if there are long symbolic names. */
314 next_address = VALUE_ADDRESS (val)
315 + print_insn (VALUE_ADDRESS (val), stdout);
320 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_ARRAY
321 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_STRING
322 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_STRUCT
323 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_UNION
324 || VALUE_REPEATED (val))
325 value_print (val, stdout, format, Val_pretty_default);
327 print_scalar_formatted (VALUE_CONTENTS (val), VALUE_TYPE (val),
328 format, size, stdout);
332 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
333 according to letters FORMAT and SIZE on STREAM.
334 FORMAT may not be zero. Formats s and i are not supported at this level.
336 This is how the elements of an array or structure are printed
340 print_scalar_formatted (valaddr, type, format, size, stream)
348 int len = TYPE_LENGTH (type);
350 if (len > sizeof (LONGEST)
358 /* We can't print it normally, but we can print it in hex.
359 Printing it in the wrong radix is more useful than saying
360 "use /x, you dummy". */
361 /* FIXME: we could also do octal or binary if that was the
363 /* FIXME: we should be using the size field to give us a minimum
364 field width to print. */
365 val_print_type_code_int (type, valaddr, stream);
369 val_long = unpack_long (type, valaddr);
371 /* If value is unsigned, truncate it in case negative. */
374 if (len == sizeof (char))
375 val_long &= (1 << 8 * sizeof(char)) - 1;
376 else if (len == sizeof (short))
377 val_long &= (1 << 8 * sizeof(short)) - 1;
378 else if (len == sizeof (long))
379 val_long &= (unsigned long) - 1;
387 /* no size specified, like in print. Print varying # of digits. */
388 print_longest (stream, 'x', 1, val_long);
397 print_longest (stream, size, 1, val_long);
400 error ("Undefined output size \"%c\".", size);
405 print_longest (stream, 'd', 1, val_long);
409 print_longest (stream, 'u', 0, val_long);
414 print_longest (stream, 'o', 1, val_long);
416 fprintf_filtered (stream, "0");
420 print_address (unpack_pointer (type, valaddr), stream);
424 value_print (value_from_longest (builtin_type_char, val_long), stream, 0,
429 if (len == sizeof (float))
430 type = builtin_type_float;
431 else if (len == sizeof (double))
432 type = builtin_type_double;
433 print_floating (valaddr, type, stream);
440 /* Binary; 't' stands for "two". */
442 char bits[8*(sizeof val_long) + 1];
447 width = 8*(sizeof val_long);
464 error ("Undefined output size \"%c\".", size);
470 bits[width] = (val_long & 1) ? '1' : '0';
475 while (*cp && *cp == '0')
480 fprintf_filtered (stream, local_binary_format_prefix());
481 fprintf_filtered (stream, cp);
482 fprintf_filtered (stream, local_binary_format_suffix());
487 error ("Undefined output format \"%c\".", format);
491 /* Specify default address for `x' command.
492 `info lines' uses this. */
495 set_next_address (addr)
500 /* Make address available to the user as $_. */
501 set_internalvar (lookup_internalvar ("_"),
502 value_from_longest (lookup_pointer_type (builtin_type_void),
506 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
507 after LEADIN. Print nothing if no symbolic name is found nearby.
508 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
509 or to interpret it as a possible C++ name and convert it back to source
510 form. However note that DO_DEMANGLE can be overridden by the specific
511 settings of the demangle and asm_demangle variables. */
514 print_address_symbolic (addr, stream, do_demangle, leadin)
520 CORE_ADDR name_location;
521 register struct symbol *symbol;
524 /* First try to find the address in the symbol tables to find
525 static functions. If that doesn't succeed we try the minimal symbol
526 vector for symbols in non-text space.
527 FIXME: Should find a way to get at the static non-text symbols too. */
529 symbol = find_pc_function (addr);
532 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
534 name = SYMBOL_SOURCE_NAME (symbol);
536 name = SYMBOL_LINKAGE_NAME (symbol);
540 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (addr);
542 /* If nothing comes out, don't print anything symbolic. */
545 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
547 name = SYMBOL_SOURCE_NAME (msymbol);
549 name = SYMBOL_LINKAGE_NAME (msymbol);
552 /* If the nearest symbol is too far away, don't print anything symbolic. */
554 /* For when CORE_ADDR is larger than unsigned int, we do math in
555 CORE_ADDR. But when we detect unsigned wraparound in the
556 CORE_ADDR math, we ignore this test and print the offset,
557 because addr+max_symbolic_offset has wrapped through the end
558 of the address space back to the beginning, giving bogus comparison. */
559 if (addr > name_location + max_symbolic_offset
560 && name_location + max_symbolic_offset > name_location)
563 fputs_filtered (leadin, stream);
564 fputs_filtered ("<", stream);
565 fputs_filtered (name, stream);
566 if (addr != name_location)
567 fprintf_filtered (stream, "+%u", (unsigned int)(addr - name_location));
569 /* Append source filename and line number if desired. */
570 if (symbol && print_symbol_filename)
572 struct symtab_and_line sal;
574 sal = find_pc_line (addr, 0);
576 fprintf_filtered (stream, " at %s:%d", sal.symtab->filename, sal.line);
578 fputs_filtered (">", stream);
581 /* Print address ADDR symbolically on STREAM.
582 First print it as a number. Then perhaps print
583 <SYMBOL + OFFSET> after the number. */
586 print_address (addr, stream)
590 #ifdef ADDR_BITS_REMOVE
591 fprintf_filtered (stream, local_hex_format(), ADDR_BITS_REMOVE(addr));
593 fprintf_filtered (stream, local_hex_format(), addr);
595 print_address_symbolic (addr, stream, asm_demangle, " ");
598 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
599 controls whether to print the symbolic name "raw" or demangled.
600 Global setting "addressprint" controls whether to print hex address
604 print_address_demangle (addr, stream, do_demangle)
610 fprintf_filtered (stream, "0");
611 } else if (addressprint) {
612 fprintf_filtered (stream, local_hex_format(), addr);
613 print_address_symbolic (addr, stream, do_demangle, " ");
615 print_address_symbolic (addr, stream, do_demangle, "");
620 /* Examine data at address ADDR in format FMT.
621 Fetch it from memory and print on stdout. */
624 do_examine (fmt, addr)
625 struct format_data fmt;
628 register char format = 0;
630 register int count = 1;
631 struct type *val_type;
633 register int maxelts;
640 /* String or instruction format implies fetch single bytes
641 regardless of the specified size. */
642 if (format == 's' || format == 'i')
646 val_type = builtin_type_char;
647 else if (size == 'h')
648 val_type = builtin_type_short;
649 else if (size == 'w')
650 val_type = builtin_type_long;
651 else if (size == 'g')
652 #ifndef CC_HAS_LONG_LONG
653 val_type = builtin_type_double;
655 val_type = builtin_type_long_long;
663 if (format == 's' || format == 'i')
666 /* Print as many objects as specified in COUNT, at most maxelts per line,
667 with the address of the next one at the start of each line. */
671 print_address (next_address, stdout);
672 printf_filtered (":");
677 printf_filtered ("\t");
678 /* Note that print_formatted sets next_address for the next
680 last_examine_address = next_address;
681 last_examine_value = value_at (val_type, next_address);
682 print_formatted (last_examine_value, format, size);
684 printf_filtered ("\n");
690 validate_format (fmt, cmdname)
691 struct format_data fmt;
695 error ("Size letters are meaningless in \"%s\" command.", cmdname);
697 error ("Item count other than 1 is meaningless in \"%s\" command.",
699 if (fmt.format == 'i' || fmt.format == 's')
700 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
701 fmt.format, cmdname);
704 /* Evaluate string EXP as an expression in the current language and
705 print the resulting value. EXP may contain a format specifier as the
706 first argument ("/x myvar" for example, to print myvar in hex).
710 print_command_1 (exp, inspect, voidprint)
715 struct expression *expr;
716 register struct cleanup *old_chain = 0;
717 register char format = 0;
719 struct format_data fmt;
722 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
723 inspect_it = inspect;
725 if (exp && *exp == '/')
728 fmt = decode_format (&exp, last_format, 0);
729 validate_format (fmt, "print");
730 last_format = format = fmt.format;
741 extern int objectprint;
743 expr = parse_expression (exp);
744 old_chain = make_cleanup (free_current_contents, &expr);
746 val = evaluate_expression (expr);
748 /* C++: figure out what type we actually want to print it as. */
749 type = VALUE_TYPE (val);
752 && ( TYPE_CODE (type) == TYPE_CODE_PTR
753 || TYPE_CODE (type) == TYPE_CODE_REF)
754 && ( TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT
755 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION))
759 v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
763 type = VALUE_TYPE (val);
768 val = access_value_history (0);
770 if (voidprint || (val && VALUE_TYPE (val) &&
771 TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
773 int histindex = record_latest_value (val);
776 printf ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
778 if (histindex >= 0) printf_filtered ("$%d = ", histindex);
780 print_formatted (val, format, fmt.size);
781 printf_filtered ("\n");
787 do_cleanups (old_chain);
788 inspect_it = 0; /* Reset print routines to normal */
793 print_command (exp, from_tty)
797 print_command_1 (exp, 0, 1);
800 /* Same as print, except in epoch, it gets its own window */
803 inspect_command (exp, from_tty)
807 extern int epoch_interface;
809 print_command_1 (exp, epoch_interface, 1);
812 /* Same as print, except it doesn't print void results. */
815 call_command (exp, from_tty)
819 print_command_1 (exp, 0, 0);
824 output_command (exp, from_tty)
828 struct expression *expr;
829 register struct cleanup *old_chain;
830 register char format = 0;
832 struct format_data fmt;
834 if (exp && *exp == '/')
837 fmt = decode_format (&exp, 0, 0);
838 validate_format (fmt, "output");
842 expr = parse_expression (exp);
843 old_chain = make_cleanup (free_current_contents, &expr);
845 val = evaluate_expression (expr);
847 print_formatted (val, format, fmt.size);
849 do_cleanups (old_chain);
854 set_command (exp, from_tty)
858 struct expression *expr = parse_expression (exp);
859 register struct cleanup *old_chain
860 = make_cleanup (free_current_contents, &expr);
861 evaluate_expression (expr);
862 do_cleanups (old_chain);
867 address_info (exp, from_tty)
871 register struct symbol *sym;
872 register struct minimal_symbol *msymbol;
874 register long basereg;
875 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
876 if exp is a field of `this'. */
879 error ("Argument required.");
881 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
882 &is_a_field_of_this, (struct symtab **)NULL);
885 if (is_a_field_of_this)
887 printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp);
891 msymbol = lookup_minimal_symbol (exp, (struct objfile *) NULL);
894 printf ("Symbol \"%s\" is at %s in a file compiled without debugging.\n",
895 exp, local_hex_string(SYMBOL_VALUE_ADDRESS (msymbol)));
897 error ("No symbol \"%s\" in current context.", exp);
901 printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym));
902 val = SYMBOL_VALUE (sym);
903 basereg = SYMBOL_BASEREG (sym);
905 switch (SYMBOL_CLASS (sym))
908 case LOC_CONST_BYTES:
913 printf ("a label at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
917 printf ("a variable in register %s", reg_names[val]);
921 printf ("static storage at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
925 printf ("an argument in register %s", reg_names[val]);
928 case LOC_REGPARM_ADDR:
929 printf ("address of an argument in register %s", reg_names[val]);
933 if (SYMBOL_BASEREG_VALID (sym))
935 printf ("an argument at offset %ld from register %s",
936 val, reg_names[basereg]);
940 printf ("an argument at offset %ld", val);
945 if (SYMBOL_BASEREG_VALID (sym))
947 printf ("an argument at offset %ld from register %s",
948 val, reg_names[basereg]);
952 printf ("an argument at frame offset %ld", val);
957 if (SYMBOL_BASEREG_VALID (sym))
959 printf ("a local variable at offset %ld from register %s",
960 val, reg_names[basereg]);
964 printf ("a local variable at frame offset %ld", val);
969 printf ("a reference argument at offset %ld", val);
973 printf ("a typedef");
977 printf ("a function at address %s",
978 local_hex_string(BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
981 case LOC_OPTIMIZED_OUT:
982 printf_filtered ("optimized out");
986 printf ("of unknown (botched) type");
993 x_command (exp, from_tty)
997 struct expression *expr;
998 struct format_data fmt;
999 struct cleanup *old_chain;
1002 fmt.format = last_format;
1003 fmt.size = last_size;
1006 if (exp && *exp == '/')
1009 fmt = decode_format (&exp, last_format, last_size);
1012 /* If we have an expression, evaluate it and use it as the address. */
1014 if (exp != 0 && *exp != 0)
1016 expr = parse_expression (exp);
1017 /* Cause expression not to be there any more
1018 if this command is repeated with Newline.
1019 But don't clobber a user-defined command's definition. */
1022 old_chain = make_cleanup (free_current_contents, &expr);
1023 val = evaluate_expression (expr);
1024 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
1025 val = value_ind (val);
1026 /* In rvalue contexts, such as this, functions are coerced into
1027 pointers to functions. This makes "x/i main" work. */
1028 if (/* last_format == 'i'
1029 && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
1030 && VALUE_LVAL (val) == lval_memory)
1031 next_address = VALUE_ADDRESS (val);
1033 next_address = value_as_pointer (val);
1034 do_cleanups (old_chain);
1037 do_examine (fmt, next_address);
1039 /* If the examine succeeds, we remember its size and format for next time. */
1040 last_size = fmt.size;
1041 last_format = fmt.format;
1043 /* Set a couple of internal variables if appropriate. */
1044 if (last_examine_value)
1046 /* Make last address examined available to the user as $_. Use
1047 the correct pointer type. */
1048 set_internalvar (lookup_internalvar ("_"),
1049 value_from_longest (
1050 lookup_pointer_type (VALUE_TYPE (last_examine_value)),
1051 (LONGEST) last_examine_address));
1053 /* Make contents of last address examined available to the user as $__.*/
1054 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1059 /* Add an expression to the auto-display chain.
1060 Specify the expression. */
1063 display_command (exp, from_tty)
1067 struct format_data fmt;
1068 register struct expression *expr;
1069 register struct display *new;
1080 fmt = decode_format (&exp, 0, 0);
1081 if (fmt.size && fmt.format == 0)
1083 if (fmt.format == 'i' || fmt.format == 's')
1093 innermost_block = 0;
1094 expr = parse_expression (exp);
1096 new = (struct display *) xmalloc (sizeof (struct display));
1099 new->block = innermost_block;
1100 new->next = display_chain;
1101 new->number = ++display_number;
1103 new->status = enabled;
1104 display_chain = new;
1106 if (from_tty && target_has_execution)
1107 do_one_display (new);
1120 /* Clear out the display_chain.
1121 Done when new symtabs are loaded, since this invalidates
1122 the types stored in many expressions. */
1127 register struct display *d;
1129 while ((d = display_chain) != NULL)
1132 display_chain = d->next;
1137 /* Delete the auto-display number NUM. */
1140 delete_display (num)
1143 register struct display *d1, *d;
1146 error ("No display number %d.", num);
1148 if (display_chain->number == num)
1151 display_chain = d1->next;
1155 for (d = display_chain; ; d = d->next)
1158 error ("No display number %d.", num);
1159 if (d->next->number == num)
1169 /* Delete some values from the auto-display chain.
1170 Specify the element numbers. */
1173 undisplay_command (args, from_tty)
1177 register char *p = args;
1183 if (query ("Delete all auto-display expressions? "))
1192 while (*p1 >= '0' && *p1 <= '9') p1++;
1193 if (*p1 && *p1 != ' ' && *p1 != '\t')
1194 error ("Arguments must be display numbers.");
1198 delete_display (num);
1201 while (*p == ' ' || *p == '\t') p++;
1206 /* Display a single auto-display.
1207 Do nothing if the display cannot be printed in the current context,
1208 or if the display is disabled. */
1214 int within_current_scope;
1216 if (d->status == disabled)
1220 within_current_scope = contained_in (get_selected_block (), d->block);
1222 within_current_scope = 1;
1223 if (!within_current_scope)
1226 current_display_number = d->number;
1228 printf_filtered ("%d: ", d->number);
1233 printf_filtered ("x/");
1234 if (d->format.count != 1)
1235 printf_filtered ("%d", d->format.count);
1236 printf_filtered ("%c", d->format.format);
1237 if (d->format.format != 'i' && d->format.format != 's')
1238 printf_filtered ("%c", d->format.size);
1239 printf_filtered (" ");
1240 print_expression (d->exp, stdout);
1241 if (d->format.count != 1)
1242 printf_filtered ("\n");
1244 printf_filtered (" ");
1246 addr = value_as_pointer (evaluate_expression (d->exp));
1247 if (d->format.format == 'i')
1248 addr = ADDR_BITS_REMOVE (addr);
1250 do_examine (d->format, addr);
1254 if (d->format.format)
1255 printf_filtered ("/%c ", d->format.format);
1256 print_expression (d->exp, stdout);
1257 printf_filtered (" = ");
1258 print_formatted (evaluate_expression (d->exp),
1259 d->format.format, d->format.size);
1260 printf_filtered ("\n");
1264 current_display_number = -1;
1267 /* Display all of the values on the auto-display chain which can be
1268 evaluated in the current scope. */
1273 register struct display *d;
1275 for (d = display_chain; d; d = d->next)
1279 /* Delete the auto-display which we were in the process of displaying.
1280 This is done when there is an error or a signal. */
1283 disable_display (num)
1286 register struct display *d;
1288 for (d = display_chain; d; d = d->next)
1289 if (d->number == num)
1291 d->status = disabled;
1294 printf ("No display number %d.\n", num);
1298 disable_current_display ()
1300 if (current_display_number >= 0)
1302 disable_display (current_display_number);
1303 fprintf (stderr, "Disabling display %d to avoid infinite recursion.\n",
1304 current_display_number);
1306 current_display_number = -1;
1310 display_info (ignore, from_tty)
1314 register struct display *d;
1317 printf ("There are no auto-display expressions now.\n");
1319 printf_filtered ("Auto-display expressions now in effect:\n\
1320 Num Enb Expression\n");
1322 for (d = display_chain; d; d = d->next)
1324 printf_filtered ("%d: %c ", d->number, "ny"[(int)d->status]);
1326 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1328 else if (d->format.format)
1329 printf_filtered ("/%c ", d->format.format);
1330 print_expression (d->exp, stdout);
1331 if (d->block && !contained_in (get_selected_block (), d->block))
1332 printf_filtered (" (cannot be evaluated in the current context)");
1333 printf_filtered ("\n");
1339 enable_display (args, from_tty)
1343 register char *p = args;
1346 register struct display *d;
1350 for (d = display_chain; d; d = d->next)
1351 d->status = enabled;
1357 while (*p1 >= '0' && *p1 <= '9')
1359 if (*p1 && *p1 != ' ' && *p1 != '\t')
1360 error ("Arguments must be display numbers.");
1364 for (d = display_chain; d; d = d->next)
1365 if (d->number == num)
1367 d->status = enabled;
1370 printf ("No display number %d.\n", num);
1373 while (*p == ' ' || *p == '\t')
1380 disable_display_command (args, from_tty)
1384 register char *p = args;
1386 register struct display *d;
1390 for (d = display_chain; d; d = d->next)
1391 d->status = disabled;
1397 while (*p1 >= '0' && *p1 <= '9')
1399 if (*p1 && *p1 != ' ' && *p1 != '\t')
1400 error ("Arguments must be display numbers.");
1402 disable_display (atoi (p));
1405 while (*p == ' ' || *p == '\t')
1411 /* Print the value in stack frame FRAME of a variable
1412 specified by a struct symbol. */
1415 print_variable_value (var, frame, stream)
1420 value val = read_var_value (var, frame);
1421 value_print (val, stream, 0, Val_pretty_default);
1424 /* Print the arguments of a stack frame, given the function FUNC
1425 running in that frame (as a symbol), the info on the frame,
1426 and the number of args according to the stack frame (or -1 if unknown). */
1428 /* References here and elsewhere to "number of args according to the
1429 stack frame" appear in all cases to refer to "number of ints of args
1430 according to the stack frame". At least for VAX, i386, isi. */
1433 print_frame_args (func, fi, num, stream)
1434 struct symbol *func;
1435 struct frame_info *fi;
1443 register struct symbol *sym;
1445 /* Offset of next stack argument beyond the one we have seen that is
1446 at the highest offset.
1447 -1 if we haven't come to a stack argument yet. */
1448 long highest_offset = -1;
1450 /* Number of ints of arguments that we have printed so far. */
1451 int args_printed = 0;
1455 b = SYMBOL_BLOCK_VALUE (func);
1456 nsyms = BLOCK_NSYMS (b);
1459 for (i = 0; i < nsyms; i++)
1462 sym = BLOCK_SYM (b, i);
1464 /* Keep track of the highest stack argument offset seen, and
1465 skip over any kinds of symbols we don't care about. */
1467 switch (SYMBOL_CLASS (sym)) {
1471 long current_offset = SYMBOL_VALUE (sym);
1473 arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1475 /* Compute address of next argument by adding the size of
1476 this argument and rounding to an int boundary. */
1478 = ((current_offset + arg_size + sizeof (int) - 1)
1479 & ~(sizeof (int) - 1));
1481 /* If this is the highest offset seen yet, set highest_offset. */
1482 if (highest_offset == -1
1483 || (current_offset > highest_offset))
1484 highest_offset = current_offset;
1486 /* Add the number of ints we're about to print to args_printed. */
1487 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
1490 /* We care about types of symbols, but don't need to keep track of
1491 stack offsets in them. */
1493 case LOC_REGPARM_ADDR:
1497 /* Other types of symbols we just skip over. */
1502 /* We have to look up the symbol because arguments can have
1503 two entries (one a parameter, one a local) and the one we
1504 want is the local, which lookup_symbol will find for us.
1505 This includes gcc1 (not gcc2) on the sparc when passing a
1506 small structure and gcc2 when the argument type is float
1507 and it is passed as a double and converted to float by
1508 the prologue (in the latter case the type of the LOC_ARG
1509 symbol is double and the type of the LOC_LOCAL symbol is
1510 float). There are also LOC_ARG/LOC_REGISTER pairs which
1511 are not combined in symbol-reading. */
1512 /* But if the parameter name is null, don't try it.
1513 Null parameter names occur on the RS/6000, for traceback tables.
1514 FIXME, should we even print them? */
1516 if (*SYMBOL_NAME (sym))
1519 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
1521 /* Print the current arg. */
1523 fprintf_filtered (stream, ", ");
1525 fprintf_symbol_filtered (stream, SYMBOL_SOURCE_NAME (sym),
1526 SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
1527 fputs_filtered ("=", stream);
1529 /* Avoid value_print because it will deref ref parameters. We just
1530 want to print their addresses. Print ??? for args whose address
1531 we do not know. We pass 2 as "recurse" to val_print because our
1532 standard indentation here is 4 spaces, and val_print indents
1533 2 for each recurse. */
1534 val = read_var_value (sym, FRAME_INFO_ID (fi));
1536 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val),
1537 stream, 0, 0, 2, Val_no_prettyprint);
1539 fputs_filtered ("???", stream);
1543 /* Don't print nameless args in situations where we don't know
1544 enough about the stack to find them. */
1549 if (highest_offset == -1)
1550 start = FRAME_ARGS_SKIP;
1552 start = highest_offset;
1554 print_frame_nameless_args (fi, start, num - args_printed,
1559 /* Print nameless args on STREAM.
1560 FI is the frameinfo for this frame, START is the offset
1561 of the first nameless arg, and NUM is the number of nameless args to
1562 print. FIRST is nonzero if this is the first argument (not just
1563 the first nameless arg). */
1565 print_frame_nameless_args (fi, start, num, first, stream)
1566 struct frame_info *fi;
1576 for (i = 0; i < num; i++)
1579 #ifdef NAMELESS_ARG_VALUE
1580 NAMELESS_ARG_VALUE (fi, start, &arg_value);
1582 argsaddr = FRAME_ARGS_ADDRESS (fi);
1586 arg_value = read_memory_integer (argsaddr + start, sizeof (int));
1590 fprintf_filtered (stream, ", ");
1592 #ifdef PRINT_NAMELESS_INTEGER
1593 PRINT_NAMELESS_INTEGER (stream, arg_value);
1595 #ifdef PRINT_TYPELESS_INTEGER
1596 PRINT_TYPELESS_INTEGER (stream, builtin_type_int, (LONGEST) arg_value);
1598 fprintf_filtered (stream, "%d", arg_value);
1599 #endif /* PRINT_TYPELESS_INTEGER */
1600 #endif /* PRINT_NAMELESS_INTEGER */
1602 start += sizeof (int);
1606 /* Make makeva* work on an __INT_VARARGS_H machine. */
1608 #if defined (__INT_VARARGS_H)
1609 /* This is used on an 88k. Not sure whether it is used by anything else. */
1610 #define MAKEVA_END(list) \
1612 retval.__va_arg = 0; \
1613 retval.__va_stk = (int *) (list)->arg_bytes; \
1614 retval.__va_reg = (int *) (list)->arg_bytes; \
1618 /* This is an interface which allows to us make a va_list. */
1621 unsigned int max_arg_size;
1623 /* Current position in bytes. */
1624 unsigned int argindex;
1629 /* Tell the caller how many bytes to allocate for a makeva_list with NARGS
1630 arguments and whose largest argument is MAX_ARG_SIZE bytes. This
1631 way the caller can use alloca, malloc, or some other allocator. */
1633 makeva_size (nargs, max_arg_size)
1635 unsigned int max_arg_size;
1637 return sizeof (makeva_list) + nargs * max_arg_size;
1640 /* Start working on LIST with NARGS arguments and whose largest
1641 argument is MAX_ARG_SIZE bytes. */
1643 makeva_start (list, nargs, max_arg_size)
1646 unsigned int max_arg_size;
1648 list->nargs = nargs;
1649 list->max_arg_size = max_arg_size;
1650 #if defined (MAKEVA_START)
1651 MAKEVA_START (list);
1657 /* Add ARG to LIST. */
1659 makeva_arg (list, argaddr, argsize)
1662 unsigned int argsize;
1664 #if defined (MAKEVA_ARG)
1665 MAKEVA_ARG (list, argaddr, argsize);
1667 memcpy (&list->arg_bytes[list->argindex], argaddr, argsize);
1668 list->argindex += argsize;
1672 /* From LIST, for which makeva_arg has been called for each arg,
1673 return a va_list containing the args. */
1678 #if defined (MAKEVA_END)
1681 /* This works if a va_list is just a pointer to the arguments. */
1682 return (va_list) list->arg_bytes;
1688 printf_command (arg, from_tty)
1693 register char *s = arg;
1697 int allocated_args = 20;
1698 va_list args_to_vprintf;
1700 val_args = (value *) xmalloc (allocated_args * sizeof (value));
1703 error_no_arg ("format-control string and values to print");
1705 /* Skip white space before format string */
1706 while (*s == ' ' || *s == '\t') s++;
1708 /* A format string should follow, enveloped in double quotes */
1710 error ("Bad format string, missing '\"'.");
1712 /* Parse the format-control string and copy it into the string STRING,
1713 processing some kinds of escape sequence. */
1715 f = string = (char *) alloca (strlen (s) + 1);
1722 error ("Bad format string, non-terminated '\"'.");
1723 /* doesn't return */
1744 /* ??? TODO: handle other escape sequences */
1745 error ("Unrecognized \\ escape character in format string.");
1754 /* Skip over " and following space and comma. */
1757 while (*s == ' ' || *s == '\t') s++;
1759 if (*s != ',' && *s != 0)
1760 error ("Invalid argument syntax");
1763 while (*s == ' ' || *s == '\t') s++;
1766 /* Now scan the string for %-specs and see what kinds of args they want.
1767 argclass[I] classifies the %-specs so we can give vprintf something
1768 of the right size. */
1770 enum argclass {int_arg, string_arg, double_arg, long_long_arg};
1771 enum argclass *argclass;
1775 makeva_list *args_makeva;
1777 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1784 while (strchr ("0123456789.hlL-+ #", *f))
1786 if (*f == 'l' || *f == 'L')
1791 argclass[nargs_wanted++] = string_arg;
1792 else if (*f == 'e' || *f == 'f' || *f == 'g')
1793 argclass[nargs_wanted++] = double_arg;
1794 else if (lcount > 1)
1795 argclass[nargs_wanted++] = long_long_arg;
1797 argclass[nargs_wanted++] = int_arg;
1801 /* Now, parse all arguments and evaluate them.
1802 Store the VALUEs in VAL_ARGS. */
1807 if (nargs == allocated_args)
1808 val_args = (value *) xrealloc ((char *) val_args,
1809 (allocated_args *= 2)
1812 val_args[nargs] = parse_to_comma_and_eval (&s1);
1814 /* If format string wants a float, unchecked-convert the value to
1815 floating point of the same size */
1817 if (argclass[nargs] == double_arg)
1819 if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (float))
1820 VALUE_TYPE (val_args[nargs]) = builtin_type_float;
1821 if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (double))
1822 VALUE_TYPE (val_args[nargs]) = builtin_type_double;
1830 if (nargs != nargs_wanted)
1831 error ("Wrong number of arguments for specified format-string");
1833 /* Now lay out an argument-list containing the arguments
1834 as doubles, integers and C pointers. */
1836 args_makeva = (makeva_list *)
1837 alloca (makeva_size (nargs, sizeof (double)));
1838 makeva_start (args_makeva, nargs, sizeof (double));
1839 for (i = 0; i < nargs; i++)
1841 if (argclass[i] == string_arg)
1846 tem = value_as_pointer (val_args[i]);
1848 /* This is a %s argument. Find the length of the string. */
1853 read_memory (tem + j, &c, 1);
1858 /* Copy the string contents into a string inside GDB. */
1859 str = (char *) alloca (j + 1);
1860 read_memory (tem, str, j);
1863 /* Pass address of internal copy as the arg to vprintf. */
1864 makeva_arg (args_makeva, &str, sizeof (str));
1866 else if (VALUE_TYPE (val_args[i])->code == TYPE_CODE_FLT)
1868 double val = value_as_double (val_args[i]);
1869 makeva_arg (args_makeva, &val, sizeof (val));
1872 #ifdef CC_HAS_LONG_LONG
1873 if (argclass[i] == long_long_arg)
1875 long long val = value_as_long (val_args[i]);
1876 makeva_arg (args_makeva, &val, sizeof (val));
1881 long val = value_as_long (val_args[i]);
1882 makeva_arg (args_makeva, &val, sizeof (val));
1885 args_to_vprintf = makeva_end (args_makeva);
1888 /* FIXME: We should be using vprintf_filtered, but as long as it has an
1889 arbitrary limit that is unacceptable. Correct fix is for vprintf_filtered
1890 to scan down the format string so it knows how big a buffer it needs.
1892 But for now, just force out any pending output, so at least the output
1893 appears in the correct order. */
1894 wrap_here ((char *)NULL);
1895 vprintf (string, args_to_vprintf);
1898 /* Dump a specified section of assembly code. With no command line
1899 arguments, this command will dump the assembly code for the
1900 function surrounding the pc value in the selected frame. With one
1901 argument, it will dump the assembly code surrounding that pc value.
1902 Two arguments are interpeted as bounds within which to dump
1907 disassemble_command (arg, from_tty)
1911 CORE_ADDR low, high;
1919 if (!selected_frame)
1920 error ("No frame selected.\n");
1922 pc = get_frame_pc (selected_frame);
1923 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
1924 error ("No function contains program counter for selected frame.\n");
1926 else if (!(space_index = (char *) strchr (arg, ' ')))
1929 pc = parse_and_eval_address (arg);
1930 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
1931 error ("No function contains specified address.\n");
1935 /* Two arguments. */
1936 *space_index = '\0';
1937 low = parse_and_eval_address (arg);
1938 high = parse_and_eval_address (space_index + 1);
1941 printf_filtered ("Dump of assembler code ");
1944 printf_filtered ("for function %s:\n", name);
1948 printf_filtered ("from %s ", local_hex_string(low));
1949 printf_filtered ("to %s:\n", local_hex_string(high));
1952 /* Dump the specified range. */
1953 for (pc = low; pc < high; )
1956 print_address (pc, stdout);
1957 printf_filtered (":\t");
1958 pc += print_insn (pc, stdout);
1959 printf_filtered ("\n");
1961 printf_filtered ("End of assembler dump.\n");
1967 _initialize_printcmd ()
1969 current_display_number = -1;
1971 add_info ("address", address_info,
1972 "Describe where variable VAR is stored.");
1974 add_com ("x", class_vars, x_command,
1975 "Examine memory: x/FMT ADDRESS.\n\
1976 ADDRESS is an expression for the memory address to examine.\n\
1977 FMT is a repeat count followed by a format letter and a size letter.\n\
1978 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1979 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
1980 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1981 The specified number of objects of the specified size are printed\n\
1982 according to the format.\n\n\
1983 Defaults for format and size letters are those previously used.\n\
1984 Default count is 1. Default address is following last thing printed\n\
1985 with this command or \"print\".");
1987 add_com ("disassemble", class_vars, disassemble_command,
1988 "Disassemble a specified section of memory.\n\
1989 Default is the function surrounding the pc of the selected frame.\n\
1990 With a single argument, the function surrounding that address is dumped.\n\
1991 Two arguments are taken as a range of memory to dump.");
1994 add_com ("whereis", class_vars, whereis_command,
1995 "Print line number and file of definition of variable.");
1998 add_info ("display", display_info,
1999 "Expressions to display when program stops, with code numbers.");
2001 add_cmd ("undisplay", class_vars, undisplay_command,
2002 "Cancel some expressions to be displayed when program stops.\n\
2003 Arguments are the code numbers of the expressions to stop displaying.\n\
2004 No argument means cancel all automatic-display expressions.\n\
2005 \"delete display\" has the same effect as this command.\n\
2006 Do \"info display\" to see current list of code numbers.",
2009 add_com ("display", class_vars, display_command,
2010 "Print value of expression EXP each time the program stops.\n\
2011 /FMT may be used before EXP as in the \"print\" command.\n\
2012 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2013 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2014 and examining is done as in the \"x\" command.\n\n\
2015 With no argument, display all currently requested auto-display expressions.\n\
2016 Use \"undisplay\" to cancel display requests previously made.");
2018 add_cmd ("display", class_vars, enable_display,
2019 "Enable some expressions to be displayed when program stops.\n\
2020 Arguments are the code numbers of the expressions to resume displaying.\n\
2021 No argument means enable all automatic-display expressions.\n\
2022 Do \"info display\" to see current list of code numbers.", &enablelist);
2024 add_cmd ("display", class_vars, disable_display_command,
2025 "Disable some expressions to be displayed when program stops.\n\
2026 Arguments are the code numbers of the expressions to stop displaying.\n\
2027 No argument means disable all automatic-display expressions.\n\
2028 Do \"info display\" to see current list of code numbers.", &disablelist);
2030 add_cmd ("display", class_vars, undisplay_command,
2031 "Cancel some expressions to be displayed when program stops.\n\
2032 Arguments are the code numbers of the expressions to stop displaying.\n\
2033 No argument means cancel all automatic-display expressions.\n\
2034 Do \"info display\" to see current list of code numbers.", &deletelist);
2036 add_com ("printf", class_vars, printf_command,
2037 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2038 This is useful for formatted output in user-defined commands.");
2039 add_com ("output", class_vars, output_command,
2040 "Like \"print\" but don't put in value history and don't print newline.\n\
2041 This is useful in user-defined commands.");
2043 add_prefix_cmd ("set", class_vars, set_command,
2044 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2045 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2046 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2047 with $), a register (a few standard names starting with $), or an actual\n\
2048 variable in the program being debugged. EXP is any valid expression.\n\
2049 Use \"set variable\" for variables with names identical to set subcommands.\n\
2050 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2051 You can see these environment settings with the \"show\" command.",
2052 &setlist, "set ", 1, &cmdlist);
2054 /* "call" is the same as "set", but handy for dbx users to call fns. */
2055 add_com ("call", class_vars, call_command,
2056 "Call a function in the program.\n\
2057 The argument is the function name and arguments, in the notation of the\n\
2058 current working language. The result is printed and saved in the value\n\
2059 history, if it is not void.");
2061 add_cmd ("variable", class_vars, set_command,
2062 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2063 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2064 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2065 with $), a register (a few standard names starting with $), or an actual\n\
2066 variable in the program being debugged. EXP is any valid expression.\n\
2067 This may usually be abbreviated to simply \"set\".",
2070 add_com ("print", class_vars, print_command,
2071 concat ("Print value of expression EXP.\n\
2072 Variables accessible are those of the lexical environment of the selected\n\
2073 stack frame, plus all those whose scope is global or an entire file.\n\
2075 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2076 $$NUM refers to NUM'th value back from the last one.\n\
2077 Names starting with $ refer to registers (with the values they would have\n\
2078 if the program were to return to the stack frame now selected, restoring\n\
2079 all registers saved by frames farther in) or else to debugger\n\
2080 \"convenience\" variables (any such name not a known register).\n\
2081 Use assignment expressions to give values to convenience variables.\n",
2083 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2084 @ is a binary operator for treating consecutive data objects\n\
2085 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2086 element is FOO, whose second element is stored in the space following\n\
2087 where FOO is stored, etc. FOO must be an expression whose value\n\
2088 resides in memory.\n",
2090 EXP may be preceded with /FMT, where FMT is a format letter\n\
2091 but no count or size letter (see \"x\" command).", NULL));
2092 add_com_alias ("p", "print", class_vars, 1);
2094 add_com ("inspect", class_vars, inspect_command,
2095 "Same as \"print\" command, except that if you are running in the epoch\n\
2096 environment, the value is printed in its own window.");
2099 add_set_cmd ("max-symbolic-offset", no_class, var_uinteger,
2100 (char *)&max_symbolic_offset,
2101 "Set the largest offset that will be printed in <symbol+1234> form.",
2105 add_set_cmd ("symbol-filename", no_class, var_boolean,
2106 (char *)&print_symbol_filename,
2107 "Set printing of source filename and line number with <symbol>.",