1 /* Print values for GNU debugger GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1993, 1994, 1995
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
28 #include "expression.h"
32 #include "breakpoint.h"
37 extern int asm_demangle; /* Whether to demangle syms in asm printouts */
38 extern int addressprint; /* Whether to print hex addresses in HLL " */
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_ptr last_examine_value;
68 /* Largest offset between a symbolic value and an address, that will be
69 printed as `0x1234 <symbol+offset>'. */
71 static unsigned int max_symbolic_offset = UINT_MAX;
73 /* Append the source filename and linenumber of the symbol when
74 printing a symbolic value as `<symbol at filename:linenum>' if set. */
75 static int print_symbol_filename = 0;
77 /* Number of auto-display expression currently being displayed.
78 So that we can disable it if we get an error or a signal within it.
79 -1 when not doing one. */
81 int current_display_number;
83 /* Flag to low-level print routines that this value is being printed
84 in an epoch window. We'd like to pass this as a parameter, but
85 every routine would need to take it. Perhaps we can encapsulate
86 this in the I/O stream once we have GNU stdio. */
92 /* Chain link to next auto-display item. */
94 /* Expression to be evaluated and displayed. */
95 struct expression *exp;
96 /* Item number of this auto-display item. */
98 /* Display format specified. */
99 struct format_data format;
100 /* Innermost block required by this expression when evaluated */
102 /* Status of this display (enabled or disabled) */
106 /* Chain of expressions whose values should be displayed
107 automatically each time the program stops. */
109 static struct display *display_chain;
111 static int display_number;
113 /* Pointer to the target-dependent disassembly function. */
115 int (*tm_print_insn) PARAMS ((bfd_vma, disassemble_info *));
117 /* Prototypes for local functions. */
119 static void delete_display PARAMS ((int));
121 static void enable_display PARAMS ((char *, int));
123 static void disable_display_command PARAMS ((char *, int));
125 static void disassemble_command PARAMS ((char *, int));
127 static void printf_command PARAMS ((char *, int));
129 static void print_frame_nameless_args PARAMS ((struct frame_info *, long,
130 int, int, GDB_FILE *));
132 static void display_info PARAMS ((char *, int));
134 static void do_one_display PARAMS ((struct display *));
136 static void undisplay_command PARAMS ((char *, int));
138 static void free_display PARAMS ((struct display *));
140 static void display_command PARAMS ((char *, int));
142 static void x_command PARAMS ((char *, int));
144 static void address_info PARAMS ((char *, int));
146 static void set_command PARAMS ((char *, int));
148 static void output_command PARAMS ((char *, int));
150 static void call_command PARAMS ((char *, int));
152 static void inspect_command PARAMS ((char *, int));
154 static void print_command PARAMS ((char *, int));
156 static void print_command_1 PARAMS ((char *, int, int));
158 static void validate_format PARAMS ((struct format_data, char *));
160 static void do_examine PARAMS ((struct format_data, CORE_ADDR));
162 static void print_formatted PARAMS ((value_ptr, int, int));
164 static struct format_data decode_format PARAMS ((char **, int, int));
166 static int print_insn PARAMS ((CORE_ADDR, GDB_FILE *));
169 /* Decode a format specification. *STRING_PTR should point to it.
170 OFORMAT and OSIZE are used as defaults for the format and size
171 if none are given in the format specification.
172 If OSIZE is zero, then the size field of the returned value
173 should be set only if a size is explicitly specified by the
175 The structure returned describes all the data
176 found in the specification. In addition, *STRING_PTR is advanced
177 past the specification and past all whitespace following it. */
179 static struct format_data
180 decode_format (string_ptr, oformat, osize)
185 struct format_data val;
186 register char *p = *string_ptr;
192 if (*p >= '0' && *p <= '9')
193 val.count = atoi (p);
194 while (*p >= '0' && *p <= '9') p++;
196 /* Now process size or format letters that follow. */
200 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
202 else if (*p >= 'a' && *p <= 'z')
208 while (*p == ' ' || *p == '\t') p++;
211 /* Set defaults for format and size if not specified. */
212 if (val.format == '?')
216 /* Neither has been specified. */
217 val.format = oformat;
221 /* If a size is specified, any format makes a reasonable
222 default except 'i'. */
223 val.format = oformat == 'i' ? 'x' : oformat;
225 else if (val.size == '?')
230 /* Pick the appropriate size for an address. */
231 if (TARGET_PTR_BIT == 64)
232 val.size = osize ? 'g' : osize;
233 else if (TARGET_PTR_BIT == 32)
234 val.size = osize ? 'w' : osize;
235 else if (TARGET_PTR_BIT == 16)
236 val.size = osize ? 'h' : osize;
238 /* Bad value for TARGET_PTR_BIT */
242 /* Floating point has to be word or giantword. */
243 if (osize == 'w' || osize == 'g')
246 /* Default it to giantword if the last used size is not
248 val.size = osize ? 'g' : osize;
251 /* Characters default to one byte. */
252 val.size = osize ? 'b' : osize;
255 /* The default is the size most recently specified. */
262 /* Print value VAL on gdb_stdout according to FORMAT, a letter or 0.
263 Do not end with a newline.
264 0 means print VAL according to its own type.
265 SIZE is the letter for the size of datum being printed.
266 This is used to pad hex numbers so they line up. */
269 print_formatted (val, format, size)
270 register value_ptr val;
274 struct type *type = check_typedef (VALUE_TYPE (val));
275 int len = TYPE_LENGTH (type);
277 if (VALUE_LVAL (val) == lval_memory)
278 next_address = VALUE_ADDRESS (val) + len;
283 next_address = VALUE_ADDRESS (val)
284 + val_print_string (VALUE_ADDRESS (val), 0, gdb_stdout);
288 /* The old comment says
289 "Force output out, print_insn not using _filtered".
290 I'm not completely sure what that means, I suspect most print_insn
291 now do use _filtered, so I guess it's obsolete. */
292 /* We often wrap here if there are long symbolic names. */
294 next_address = VALUE_ADDRESS (val)
295 + print_insn (VALUE_ADDRESS (val), gdb_stdout);
300 || TYPE_CODE (type) == TYPE_CODE_ARRAY
301 || TYPE_CODE (type) == TYPE_CODE_STRING
302 || TYPE_CODE (type) == TYPE_CODE_STRUCT
303 || TYPE_CODE (type) == TYPE_CODE_UNION)
304 value_print (val, gdb_stdout, format, Val_pretty_default);
306 print_scalar_formatted (VALUE_CONTENTS (val), type,
307 format, size, gdb_stdout);
311 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
312 according to letters FORMAT and SIZE on STREAM.
313 FORMAT may not be zero. Formats s and i are not supported at this level.
315 This is how the elements of an array or structure are printed
319 print_scalar_formatted (valaddr, type, format, size, stream)
327 unsigned int len = TYPE_LENGTH (type);
329 if (len > sizeof (LONGEST)
337 if (! TYPE_UNSIGNED (type)
338 || ! extract_long_unsigned_integer (valaddr, len, &val_long))
340 /* We can't print it normally, but we can print it in hex.
341 Printing it in the wrong radix is more useful than saying
342 "use /x, you dummy". */
343 /* FIXME: we could also do octal or binary if that was the
345 /* FIXME: we should be using the size field to give us a
346 minimum field width to print. */
347 val_print_type_code_int (type, valaddr, stream);
351 /* If we get here, extract_long_unsigned_integer set val_long. */
353 else if (format != 'f')
354 val_long = unpack_long (type, valaddr);
356 /* If we are printing it as unsigned, truncate it in case it is actually
357 a negative signed value (e.g. "print/u (short)-1" should print 65535
358 (if shorts are 16 bits) instead of 4294967295). */
361 if (len < sizeof (LONGEST))
362 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
370 /* no size specified, like in print. Print varying # of digits. */
371 print_longest (stream, 'x', 1, val_long);
380 print_longest (stream, size, 1, val_long);
383 error ("Undefined output size \"%c\".", size);
388 print_longest (stream, 'd', 1, val_long);
392 print_longest (stream, 'u', 0, val_long);
397 print_longest (stream, 'o', 1, val_long);
399 fprintf_filtered (stream, "0");
403 print_address (unpack_pointer (type, valaddr), stream);
407 value_print (value_from_longest (builtin_type_char, val_long), stream, 0,
412 if (len == sizeof (float))
413 type = builtin_type_float;
414 else if (len == sizeof (double))
415 type = builtin_type_double;
416 print_floating (valaddr, type, stream);
423 /* Binary; 't' stands for "two". */
425 char bits[8*(sizeof val_long) + 1];
430 width = 8*(sizeof val_long);
447 error ("Undefined output size \"%c\".", size);
453 bits[width] = (val_long & 1) ? '1' : '0';
458 while (*cp && *cp == '0')
463 fprintf_filtered (stream, local_binary_format_prefix());
464 fprintf_filtered (stream, cp);
465 fprintf_filtered (stream, local_binary_format_suffix());
470 error ("Undefined output format \"%c\".", format);
474 /* Specify default address for `x' command.
475 `info lines' uses this. */
478 set_next_address (addr)
483 /* Make address available to the user as $_. */
484 set_internalvar (lookup_internalvar ("_"),
485 value_from_longest (lookup_pointer_type (builtin_type_void),
489 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
490 after LEADIN. Print nothing if no symbolic name is found nearby.
491 Optionally also print source file and line number, if available.
492 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
493 or to interpret it as a possible C++ name and convert it back to source
494 form. However note that DO_DEMANGLE can be overridden by the specific
495 settings of the demangle and asm_demangle variables. */
498 print_address_symbolic (addr, stream, do_demangle, leadin)
504 struct minimal_symbol *msymbol;
505 struct symbol *symbol;
506 struct symtab *symtab = 0;
507 CORE_ADDR name_location = 0;
510 /* First try to find the address in the symbol table, then
511 in the minsyms. Take the closest one. */
513 /* This is defective in the sense that it only finds text symbols. So
514 really this is kind of pointless--we should make sure that the
515 minimal symbols have everything we need (by changing that we could
516 save some memory, but for many debug format--ELF/DWARF or
517 anything/stabs--it would be inconvenient to eliminate those minimal
519 symbol = find_pc_function (addr);
521 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
526 name = SYMBOL_SOURCE_NAME (symbol);
528 name = SYMBOL_LINKAGE_NAME (symbol);
531 msymbol = lookup_minimal_symbol_by_pc (addr);
534 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
536 /* The msymbol is closer to the address than the symbol;
537 use the msymbol instead. */
540 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
542 name = SYMBOL_SOURCE_NAME (msymbol);
544 name = SYMBOL_LINKAGE_NAME (msymbol);
547 if (symbol == NULL && msymbol == NULL)
550 /* If the nearest symbol is too far away, don't print anything symbolic. */
552 /* For when CORE_ADDR is larger than unsigned int, we do math in
553 CORE_ADDR. But when we detect unsigned wraparound in the
554 CORE_ADDR math, we ignore this test and print the offset,
555 because addr+max_symbolic_offset has wrapped through the end
556 of the address space back to the beginning, giving bogus comparison. */
557 if (addr > name_location + max_symbolic_offset
558 && name_location + max_symbolic_offset > name_location)
561 fputs_filtered (leadin, stream);
562 fputs_filtered ("<", stream);
563 fputs_filtered (name, stream);
564 if (addr != name_location)
565 fprintf_filtered (stream, "+%u", (unsigned int)(addr - name_location));
567 /* Append source filename and line number if desired. Give specific
568 line # of this addr, if we have it; else line # of the nearest symbol. */
569 if (print_symbol_filename)
571 struct symtab_and_line sal;
573 sal = find_pc_line (addr, 0);
575 fprintf_filtered (stream, " at %s:%d", sal.symtab->filename, sal.line);
576 else if (symtab && symbol && symbol->line)
577 fprintf_filtered (stream, " at %s:%d", symtab->filename, symbol->line);
579 fprintf_filtered (stream, " in %s", symtab->filename);
581 fputs_filtered (">", stream);
584 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
587 print_address_numeric (addr, use_local, stream)
592 /* This assumes a CORE_ADDR can fit in a LONGEST. Probably a safe
594 print_longest (stream, 'x', use_local, (unsigned LONGEST) addr);
597 /* Print address ADDR symbolically on STREAM.
598 First print it as a number. Then perhaps print
599 <SYMBOL + OFFSET> after the number. */
602 print_address (addr, stream)
606 print_address_numeric (addr, 1, stream);
607 print_address_symbolic (addr, stream, asm_demangle, " ");
610 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
611 controls whether to print the symbolic name "raw" or demangled.
612 Global setting "addressprint" controls whether to print hex address
616 print_address_demangle (addr, stream, do_demangle)
623 fprintf_filtered (stream, "0");
625 else if (addressprint)
627 print_address_numeric (addr, 1, stream);
628 print_address_symbolic (addr, stream, do_demangle, " ");
632 print_address_symbolic (addr, stream, do_demangle, "");
637 /* These are the types that $__ will get after an examine command of one
640 static struct type *examine_b_type;
641 static struct type *examine_h_type;
642 static struct type *examine_w_type;
643 static struct type *examine_g_type;
645 /* Examine data at address ADDR in format FMT.
646 Fetch it from memory and print on gdb_stdout. */
649 do_examine (fmt, addr)
650 struct format_data fmt;
653 register char format = 0;
655 register int count = 1;
656 struct type *val_type = NULL;
658 register int maxelts;
665 /* String or instruction format implies fetch single bytes
666 regardless of the specified size. */
667 if (format == 's' || format == 'i')
671 val_type = examine_b_type;
672 else if (size == 'h')
673 val_type = examine_h_type;
674 else if (size == 'w')
675 val_type = examine_w_type;
676 else if (size == 'g')
677 val_type = examine_g_type;
684 if (format == 's' || format == 'i')
687 /* Print as many objects as specified in COUNT, at most maxelts per line,
688 with the address of the next one at the start of each line. */
693 print_address (next_address, gdb_stdout);
694 printf_filtered (":");
699 printf_filtered ("\t");
700 /* Note that print_formatted sets next_address for the next
702 last_examine_address = next_address;
703 last_examine_value = value_at (val_type, next_address);
704 print_formatted (last_examine_value, format, size);
706 printf_filtered ("\n");
707 gdb_flush (gdb_stdout);
712 validate_format (fmt, cmdname)
713 struct format_data fmt;
717 error ("Size letters are meaningless in \"%s\" command.", cmdname);
719 error ("Item count other than 1 is meaningless in \"%s\" command.",
721 if (fmt.format == 'i' || fmt.format == 's')
722 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
723 fmt.format, cmdname);
726 /* Evaluate string EXP as an expression in the current language and
727 print the resulting value. EXP may contain a format specifier as the
728 first argument ("/x myvar" for example, to print myvar in hex).
732 print_command_1 (exp, inspect, voidprint)
737 struct expression *expr;
738 register struct cleanup *old_chain = 0;
739 register char format = 0;
740 register value_ptr val;
741 struct format_data fmt;
744 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
745 inspect_it = inspect;
747 if (exp && *exp == '/')
750 fmt = decode_format (&exp, last_format, 0);
751 validate_format (fmt, "print");
752 last_format = format = fmt.format;
763 extern int objectprint;
765 expr = parse_expression (exp);
766 old_chain = make_cleanup (free_current_contents, &expr);
768 val = evaluate_expression (expr);
770 /* C++: figure out what type we actually want to print it as. */
771 type = VALUE_TYPE (val);
774 && ( TYPE_CODE (type) == TYPE_CODE_PTR
775 || TYPE_CODE (type) == TYPE_CODE_REF)
776 && ( TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT
777 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION))
781 v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
785 type = VALUE_TYPE (val);
790 val = access_value_history (0);
792 if (voidprint || (val && VALUE_TYPE (val) &&
793 TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
795 int histindex = record_latest_value (val);
798 annotate_value_history_begin (histindex, VALUE_TYPE (val));
800 annotate_value_begin (VALUE_TYPE (val));
803 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
805 if (histindex >= 0) printf_filtered ("$%d = ", histindex);
808 annotate_value_history_value ();
810 print_formatted (val, format, fmt.size);
811 printf_filtered ("\n");
814 annotate_value_history_end ();
816 annotate_value_end ();
819 printf_unfiltered("\") )\030");
823 do_cleanups (old_chain);
824 inspect_it = 0; /* Reset print routines to normal */
829 print_command (exp, from_tty)
833 print_command_1 (exp, 0, 1);
836 /* Same as print, except in epoch, it gets its own window */
839 inspect_command (exp, from_tty)
843 extern int epoch_interface;
845 print_command_1 (exp, epoch_interface, 1);
848 /* Same as print, except it doesn't print void results. */
851 call_command (exp, from_tty)
855 print_command_1 (exp, 0, 0);
860 output_command (exp, from_tty)
864 struct expression *expr;
865 register struct cleanup *old_chain;
866 register char format = 0;
867 register value_ptr val;
868 struct format_data fmt;
870 if (exp && *exp == '/')
873 fmt = decode_format (&exp, 0, 0);
874 validate_format (fmt, "output");
878 expr = parse_expression (exp);
879 old_chain = make_cleanup (free_current_contents, &expr);
881 val = evaluate_expression (expr);
883 annotate_value_begin (VALUE_TYPE (val));
885 print_formatted (val, format, fmt.size);
887 annotate_value_end ();
889 do_cleanups (old_chain);
894 set_command (exp, from_tty)
898 struct expression *expr = parse_expression (exp);
899 register struct cleanup *old_chain
900 = make_cleanup (free_current_contents, &expr);
901 evaluate_expression (expr);
902 do_cleanups (old_chain);
907 address_info (exp, from_tty)
911 register struct symbol *sym;
912 register struct minimal_symbol *msymbol;
914 register long basereg;
915 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
916 if exp is a field of `this'. */
919 error ("Argument required.");
921 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
922 &is_a_field_of_this, (struct symtab **)NULL);
925 if (is_a_field_of_this)
927 printf_filtered ("Symbol \"");
928 fprintf_symbol_filtered (gdb_stdout, exp,
929 current_language->la_language, DMGL_ANSI);
930 printf_filtered ("\" is a field of the local class variable `this'\n");
934 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
938 printf_filtered ("Symbol \"");
939 fprintf_symbol_filtered (gdb_stdout, exp,
940 current_language->la_language, DMGL_ANSI);
941 printf_filtered ("\" is at ");
942 print_address_numeric (SYMBOL_VALUE_ADDRESS (msymbol), 1,
944 printf_filtered (" in a file compiled without debugging.\n");
947 error ("No symbol \"%s\" in current context.", exp);
951 printf_filtered ("Symbol \"");
952 fprintf_symbol_filtered (gdb_stdout, SYMBOL_NAME (sym),
953 current_language->la_language, DMGL_ANSI);
954 printf_filtered ("\" is ");
955 val = SYMBOL_VALUE (sym);
956 basereg = SYMBOL_BASEREG (sym);
958 switch (SYMBOL_CLASS (sym))
961 case LOC_CONST_BYTES:
962 printf_filtered ("constant");
966 printf_filtered ("a label at address ");
967 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym), 1, gdb_stdout);
971 printf_filtered ("a variable in register %s", reg_names[val]);
975 printf_filtered ("static storage at address ");
976 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym), 1, gdb_stdout);
980 printf_filtered ("an argument in register %s", reg_names[val]);
983 case LOC_REGPARM_ADDR:
984 printf_filtered ("address of an argument in register %s", reg_names[val]);
988 printf_filtered ("an argument at offset %ld", val);
992 printf_filtered ("an argument at frame offset %ld", val);
996 printf_filtered ("a local variable at frame offset %ld", val);
1000 printf_filtered ("a reference argument at offset %ld", val);
1004 printf_filtered ("a variable at offset %ld from register %s",
1005 val, reg_names[basereg]);
1008 case LOC_BASEREG_ARG:
1009 printf_filtered ("an argument at offset %ld from register %s",
1010 val, reg_names[basereg]);
1014 printf_filtered ("a typedef");
1018 printf_filtered ("a function at address ");
1019 print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)), 1,
1023 case LOC_UNRESOLVED:
1025 struct minimal_symbol *msym;
1027 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, NULL);
1029 printf_filtered ("unresolved");
1032 printf_filtered ("static storage at address ");
1033 print_address_numeric (SYMBOL_VALUE_ADDRESS (msym), 1, gdb_stdout);
1038 case LOC_OPTIMIZED_OUT:
1039 printf_filtered ("optimized out");
1043 printf_filtered ("of unknown (botched) type");
1046 printf_filtered (".\n");
1050 x_command (exp, from_tty)
1054 struct expression *expr;
1055 struct format_data fmt;
1056 struct cleanup *old_chain;
1059 fmt.format = last_format;
1060 fmt.size = last_size;
1063 if (exp && *exp == '/')
1066 fmt = decode_format (&exp, last_format, last_size);
1069 /* If we have an expression, evaluate it and use it as the address. */
1071 if (exp != 0 && *exp != 0)
1073 expr = parse_expression (exp);
1074 /* Cause expression not to be there any more
1075 if this command is repeated with Newline.
1076 But don't clobber a user-defined command's definition. */
1079 old_chain = make_cleanup (free_current_contents, &expr);
1080 val = evaluate_expression (expr);
1081 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
1082 val = value_ind (val);
1083 /* In rvalue contexts, such as this, functions are coerced into
1084 pointers to functions. This makes "x/i main" work. */
1085 if (/* last_format == 'i'
1086 && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
1087 && VALUE_LVAL (val) == lval_memory)
1088 next_address = VALUE_ADDRESS (val);
1090 next_address = value_as_pointer (val);
1091 do_cleanups (old_chain);
1094 do_examine (fmt, next_address);
1096 /* If the examine succeeds, we remember its size and format for next time. */
1097 last_size = fmt.size;
1098 last_format = fmt.format;
1100 /* Set a couple of internal variables if appropriate. */
1101 if (last_examine_value)
1103 /* Make last address examined available to the user as $_. Use
1104 the correct pointer type. */
1105 set_internalvar (lookup_internalvar ("_"),
1106 value_from_longest (
1107 lookup_pointer_type (VALUE_TYPE (last_examine_value)),
1108 (LONGEST) last_examine_address));
1110 /* Make contents of last address examined available to the user as $__.*/
1111 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1116 /* Add an expression to the auto-display chain.
1117 Specify the expression. */
1120 display_command (exp, from_tty)
1124 struct format_data fmt;
1125 register struct expression *expr;
1126 register struct display *new;
1137 fmt = decode_format (&exp, 0, 0);
1138 if (fmt.size && fmt.format == 0)
1140 if (fmt.format == 'i' || fmt.format == 's')
1150 innermost_block = 0;
1151 expr = parse_expression (exp);
1153 new = (struct display *) xmalloc (sizeof (struct display));
1156 new->block = innermost_block;
1157 new->next = display_chain;
1158 new->number = ++display_number;
1160 new->status = enabled;
1161 display_chain = new;
1163 if (from_tty && target_has_execution)
1164 do_one_display (new);
1177 /* Clear out the display_chain.
1178 Done when new symtabs are loaded, since this invalidates
1179 the types stored in many expressions. */
1184 register struct display *d;
1186 while ((d = display_chain) != NULL)
1189 display_chain = d->next;
1194 /* Delete the auto-display number NUM. */
1197 delete_display (num)
1200 register struct display *d1, *d;
1203 error ("No display number %d.", num);
1205 if (display_chain->number == num)
1208 display_chain = d1->next;
1212 for (d = display_chain; ; d = d->next)
1215 error ("No display number %d.", num);
1216 if (d->next->number == num)
1226 /* Delete some values from the auto-display chain.
1227 Specify the element numbers. */
1230 undisplay_command (args, from_tty)
1234 register char *p = args;
1240 if (query ("Delete all auto-display expressions? "))
1249 while (*p1 >= '0' && *p1 <= '9') p1++;
1250 if (*p1 && *p1 != ' ' && *p1 != '\t')
1251 error ("Arguments must be display numbers.");
1255 delete_display (num);
1258 while (*p == ' ' || *p == '\t') p++;
1263 /* Display a single auto-display.
1264 Do nothing if the display cannot be printed in the current context,
1265 or if the display is disabled. */
1271 int within_current_scope;
1273 if (d->status == disabled)
1277 within_current_scope = contained_in (get_selected_block (), d->block);
1279 within_current_scope = 1;
1280 if (!within_current_scope)
1283 current_display_number = d->number;
1285 annotate_display_begin ();
1286 printf_filtered ("%d", d->number);
1287 annotate_display_number_end ();
1288 printf_filtered (": ");
1293 annotate_display_format ();
1295 printf_filtered ("x/");
1296 if (d->format.count != 1)
1297 printf_filtered ("%d", d->format.count);
1298 printf_filtered ("%c", d->format.format);
1299 if (d->format.format != 'i' && d->format.format != 's')
1300 printf_filtered ("%c", d->format.size);
1301 printf_filtered (" ");
1303 annotate_display_expression ();
1305 print_expression (d->exp, gdb_stdout);
1306 annotate_display_expression_end ();
1308 if (d->format.count != 1)
1309 printf_filtered ("\n");
1311 printf_filtered (" ");
1313 addr = value_as_pointer (evaluate_expression (d->exp));
1314 if (d->format.format == 'i')
1315 addr = ADDR_BITS_REMOVE (addr);
1317 annotate_display_value ();
1319 do_examine (d->format, addr);
1323 annotate_display_format ();
1325 if (d->format.format)
1326 printf_filtered ("/%c ", d->format.format);
1328 annotate_display_expression ();
1330 print_expression (d->exp, gdb_stdout);
1331 annotate_display_expression_end ();
1333 printf_filtered (" = ");
1335 annotate_display_expression ();
1337 print_formatted (evaluate_expression (d->exp),
1338 d->format.format, d->format.size);
1339 printf_filtered ("\n");
1342 annotate_display_end ();
1344 gdb_flush (gdb_stdout);
1345 current_display_number = -1;
1348 /* Display all of the values on the auto-display chain which can be
1349 evaluated in the current scope. */
1354 register struct display *d;
1356 for (d = display_chain; d; d = d->next)
1360 /* Delete the auto-display which we were in the process of displaying.
1361 This is done when there is an error or a signal. */
1364 disable_display (num)
1367 register struct display *d;
1369 for (d = display_chain; d; d = d->next)
1370 if (d->number == num)
1372 d->status = disabled;
1375 printf_unfiltered ("No display number %d.\n", num);
1379 disable_current_display ()
1381 if (current_display_number >= 0)
1383 disable_display (current_display_number);
1384 fprintf_unfiltered (gdb_stderr, "Disabling display %d to avoid infinite recursion.\n",
1385 current_display_number);
1387 current_display_number = -1;
1391 display_info (ignore, from_tty)
1395 register struct display *d;
1398 printf_unfiltered ("There are no auto-display expressions now.\n");
1400 printf_filtered ("Auto-display expressions now in effect:\n\
1401 Num Enb Expression\n");
1403 for (d = display_chain; d; d = d->next)
1405 printf_filtered ("%d: %c ", d->number, "ny"[(int)d->status]);
1407 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1409 else if (d->format.format)
1410 printf_filtered ("/%c ", d->format.format);
1411 print_expression (d->exp, gdb_stdout);
1412 if (d->block && !contained_in (get_selected_block (), d->block))
1413 printf_filtered (" (cannot be evaluated in the current context)");
1414 printf_filtered ("\n");
1415 gdb_flush (gdb_stdout);
1420 enable_display (args, from_tty)
1424 register char *p = args;
1427 register struct display *d;
1431 for (d = display_chain; d; d = d->next)
1432 d->status = enabled;
1438 while (*p1 >= '0' && *p1 <= '9')
1440 if (*p1 && *p1 != ' ' && *p1 != '\t')
1441 error ("Arguments must be display numbers.");
1445 for (d = display_chain; d; d = d->next)
1446 if (d->number == num)
1448 d->status = enabled;
1451 printf_unfiltered ("No display number %d.\n", num);
1454 while (*p == ' ' || *p == '\t')
1461 disable_display_command (args, from_tty)
1465 register char *p = args;
1467 register struct display *d;
1471 for (d = display_chain; d; d = d->next)
1472 d->status = disabled;
1478 while (*p1 >= '0' && *p1 <= '9')
1480 if (*p1 && *p1 != ' ' && *p1 != '\t')
1481 error ("Arguments must be display numbers.");
1483 disable_display (atoi (p));
1486 while (*p == ' ' || *p == '\t')
1492 /* Print the value in stack frame FRAME of a variable
1493 specified by a struct symbol. */
1496 print_variable_value (var, frame, stream)
1498 struct frame_info *frame;
1501 value_ptr val = read_var_value (var, frame);
1503 value_print (val, stream, 0, Val_pretty_default);
1506 /* Print the arguments of a stack frame, given the function FUNC
1507 running in that frame (as a symbol), the info on the frame,
1508 and the number of args according to the stack frame (or -1 if unknown). */
1510 /* References here and elsewhere to "number of args according to the
1511 stack frame" appear in all cases to refer to "number of ints of args
1512 according to the stack frame". At least for VAX, i386, isi. */
1515 print_frame_args (func, fi, num, stream)
1516 struct symbol *func;
1517 struct frame_info *fi;
1521 struct block *b = NULL;
1525 register struct symbol *sym;
1526 register value_ptr val;
1527 /* Offset of next stack argument beyond the one we have seen that is
1528 at the highest offset.
1529 -1 if we haven't come to a stack argument yet. */
1530 long highest_offset = -1;
1532 /* Number of ints of arguments that we have printed so far. */
1533 int args_printed = 0;
1537 b = SYMBOL_BLOCK_VALUE (func);
1538 nsyms = BLOCK_NSYMS (b);
1541 for (i = 0; i < nsyms; i++)
1544 sym = BLOCK_SYM (b, i);
1546 /* Keep track of the highest stack argument offset seen, and
1547 skip over any kinds of symbols we don't care about. */
1549 switch (SYMBOL_CLASS (sym)) {
1553 long current_offset = SYMBOL_VALUE (sym);
1554 arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1556 /* Compute address of next argument by adding the size of
1557 this argument and rounding to an int boundary. */
1559 = ((current_offset + arg_size + sizeof (int) - 1)
1560 & ~(sizeof (int) - 1));
1562 /* If this is the highest offset seen yet, set highest_offset. */
1563 if (highest_offset == -1
1564 || (current_offset > highest_offset))
1565 highest_offset = current_offset;
1567 /* Add the number of ints we're about to print to args_printed. */
1568 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
1571 /* We care about types of symbols, but don't need to keep track of
1572 stack offsets in them. */
1574 case LOC_REGPARM_ADDR:
1576 case LOC_BASEREG_ARG:
1579 /* Other types of symbols we just skip over. */
1584 /* We have to look up the symbol because arguments can have
1585 two entries (one a parameter, one a local) and the one we
1586 want is the local, which lookup_symbol will find for us.
1587 This includes gcc1 (not gcc2) on the sparc when passing a
1588 small structure and gcc2 when the argument type is float
1589 and it is passed as a double and converted to float by
1590 the prologue (in the latter case the type of the LOC_ARG
1591 symbol is double and the type of the LOC_LOCAL symbol is
1593 /* But if the parameter name is null, don't try it.
1594 Null parameter names occur on the RS/6000, for traceback tables.
1595 FIXME, should we even print them? */
1597 if (*SYMBOL_NAME (sym))
1599 struct symbol *nsym;
1600 nsym = lookup_symbol
1602 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
1603 if (SYMBOL_CLASS (nsym) == LOC_REGISTER)
1605 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
1606 it was passed on the stack and loaded into a register,
1607 or passed in a register and stored in a stack slot.
1608 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
1610 Reasons for using the LOC_ARG:
1611 (1) because find_saved_registers may be slow for remote
1613 (2) because registers are often re-used and stack slots
1614 rarely (never?) are. Therefore using the stack slot is
1615 much less likely to print garbage.
1617 Reasons why we might want to use the LOC_REGISTER:
1618 (1) So that the backtrace prints the same value as
1619 "print foo". I see no compelling reason why this needs
1620 to be the case; having the backtrace print the value which
1621 was passed in, and "print foo" print the value as modified
1622 within the called function, makes perfect sense to me.
1624 Additional note: It might be nice if "info args" displayed
1626 One more note: There is a case with sparc structure passing
1627 where we need to use the LOC_REGISTER, but this is dealt with
1628 by creating a single LOC_REGPARM in symbol reading. */
1630 /* Leave sym (the LOC_ARG) alone. */
1637 /* Print the current arg. */
1639 fprintf_filtered (stream, ", ");
1642 annotate_arg_begin ();
1644 fprintf_symbol_filtered (stream, SYMBOL_SOURCE_NAME (sym),
1645 SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
1646 annotate_arg_name_end ();
1647 fputs_filtered ("=", stream);
1649 /* Avoid value_print because it will deref ref parameters. We just
1650 want to print their addresses. Print ??? for args whose address
1651 we do not know. We pass 2 as "recurse" to val_print because our
1652 standard indentation here is 4 spaces, and val_print indents
1653 2 for each recurse. */
1654 val = read_var_value (sym, fi);
1656 annotate_arg_value (val == NULL ? NULL : VALUE_TYPE (val));
1659 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val),
1660 stream, 0, 0, 2, Val_no_prettyprint);
1662 fputs_filtered ("???", stream);
1664 annotate_arg_end ();
1669 /* Don't print nameless args in situations where we don't know
1670 enough about the stack to find them. */
1675 if (highest_offset == -1)
1676 start = FRAME_ARGS_SKIP;
1678 start = highest_offset;
1680 print_frame_nameless_args (fi, start, num - args_printed,
1685 /* Print nameless args on STREAM.
1686 FI is the frameinfo for this frame, START is the offset
1687 of the first nameless arg, and NUM is the number of nameless args to
1688 print. FIRST is nonzero if this is the first argument (not just
1689 the first nameless arg). */
1692 print_frame_nameless_args (fi, start, num, first, stream)
1693 struct frame_info *fi;
1703 for (i = 0; i < num; i++)
1706 #ifdef NAMELESS_ARG_VALUE
1707 NAMELESS_ARG_VALUE (fi, start, &arg_value);
1709 argsaddr = FRAME_ARGS_ADDRESS (fi);
1713 arg_value = read_memory_integer (argsaddr + start, sizeof (int));
1717 fprintf_filtered (stream, ", ");
1719 #ifdef PRINT_NAMELESS_INTEGER
1720 PRINT_NAMELESS_INTEGER (stream, arg_value);
1722 #ifdef PRINT_TYPELESS_INTEGER
1723 PRINT_TYPELESS_INTEGER (stream, builtin_type_int, (LONGEST) arg_value);
1725 fprintf_filtered (stream, "%ld", arg_value);
1726 #endif /* PRINT_TYPELESS_INTEGER */
1727 #endif /* PRINT_NAMELESS_INTEGER */
1729 start += sizeof (int);
1735 printf_command (arg, from_tty)
1740 register char *s = arg;
1742 value_ptr *val_args;
1744 char *current_substring;
1746 int allocated_args = 20;
1747 struct cleanup *old_cleanups;
1749 val_args = (value_ptr *) xmalloc (allocated_args * sizeof (value_ptr));
1750 old_cleanups = make_cleanup (free_current_contents, &val_args);
1753 error_no_arg ("format-control string and values to print");
1755 /* Skip white space before format string */
1756 while (*s == ' ' || *s == '\t') s++;
1758 /* A format string should follow, enveloped in double quotes */
1760 error ("Bad format string, missing '\"'.");
1762 /* Parse the format-control string and copy it into the string STRING,
1763 processing some kinds of escape sequence. */
1765 f = string = (char *) alloca (strlen (s) + 1);
1773 error ("Bad format string, non-terminated '\"'.");
1785 *f++ = '\007'; /* Bell */
1810 /* ??? TODO: handle other escape sequences */
1811 error ("Unrecognized escape character \\%c in format string.",
1821 /* Skip over " and following space and comma. */
1824 while (*s == ' ' || *s == '\t') s++;
1826 if (*s != ',' && *s != 0)
1827 error ("Invalid argument syntax");
1830 while (*s == ' ' || *s == '\t') s++;
1832 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1833 substrings = alloca (strlen (string) * 2);
1834 current_substring = substrings;
1837 /* Now scan the string for %-specs and see what kinds of args they want.
1838 argclass[I] classifies the %-specs so we can give printf_filtered
1839 something of the right size. */
1841 enum argclass {no_arg, int_arg, string_arg, double_arg, long_long_arg};
1842 enum argclass *argclass;
1843 enum argclass this_argclass;
1849 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1857 while (strchr ("0123456789.hlL-+ #", *f))
1859 if (*f == 'l' || *f == 'L')
1866 this_argclass = string_arg;
1872 this_argclass = double_arg;
1876 error ("`*' not supported for precision or width in printf");
1879 error ("Format specifier `n' not supported in printf");
1882 this_argclass = no_arg;
1887 this_argclass = long_long_arg;
1889 this_argclass = int_arg;
1893 if (this_argclass != no_arg)
1895 strncpy (current_substring, last_arg, f - last_arg);
1896 current_substring += f - last_arg;
1897 *current_substring++ = '\0';
1899 argclass[nargs_wanted++] = this_argclass;
1903 /* Now, parse all arguments and evaluate them.
1904 Store the VALUEs in VAL_ARGS. */
1909 if (nargs == allocated_args)
1910 val_args = (value_ptr *) xrealloc ((char *) val_args,
1911 (allocated_args *= 2)
1912 * sizeof (value_ptr));
1914 val_args[nargs] = parse_to_comma_and_eval (&s1);
1916 /* If format string wants a float, unchecked-convert the value to
1917 floating point of the same size */
1919 if (argclass[nargs] == double_arg)
1921 struct type *type = VALUE_TYPE (val_args[nargs]);
1922 if (TYPE_LENGTH (type) == sizeof (float))
1923 VALUE_TYPE (val_args[nargs]) = builtin_type_float;
1924 if (TYPE_LENGTH (type) == sizeof (double))
1925 VALUE_TYPE (val_args[nargs]) = builtin_type_double;
1933 if (nargs != nargs_wanted)
1934 error ("Wrong number of arguments for specified format-string");
1936 /* Now actually print them. */
1937 current_substring = substrings;
1938 for (i = 0; i < nargs; i++)
1940 switch (argclass[i])
1947 tem = value_as_pointer (val_args[i]);
1949 /* This is a %s argument. Find the length of the string. */
1954 read_memory (tem + j, &c, 1);
1959 /* Copy the string contents into a string inside GDB. */
1960 str = (char *) alloca (j + 1);
1961 read_memory (tem, str, j);
1964 printf_filtered (current_substring, str);
1969 double val = value_as_double (val_args[i]);
1970 printf_filtered (current_substring, val);
1974 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
1976 long long val = value_as_long (val_args[i]);
1977 printf_filtered (current_substring, val);
1981 error ("long long not supported in printf");
1985 /* FIXME: there should be separate int_arg and long_arg. */
1986 long val = value_as_long (val_args[i]);
1987 printf_filtered (current_substring, val);
1991 error ("internal error in printf_command");
1993 /* Skip to the next substring. */
1994 current_substring += strlen (current_substring) + 1;
1996 /* Print the portion of the format string after the last argument. */
1997 printf_filtered (last_arg);
1999 do_cleanups (old_cleanups);
2002 /* Dump a specified section of assembly code. With no command line
2003 arguments, this command will dump the assembly code for the
2004 function surrounding the pc value in the selected frame. With one
2005 argument, it will dump the assembly code surrounding that pc value.
2006 Two arguments are interpeted as bounds within which to dump
2011 disassemble_command (arg, from_tty)
2015 CORE_ADDR low, high;
2023 if (!selected_frame)
2024 error ("No frame selected.\n");
2026 pc = get_frame_pc (selected_frame);
2027 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
2028 error ("No function contains program counter for selected frame.\n");
2030 else if (!(space_index = (char *) strchr (arg, ' ')))
2033 pc = parse_and_eval_address (arg);
2034 if (find_pc_partial_function (pc, &name, &low, &high) == 0)
2035 error ("No function contains specified address.\n");
2039 /* Two arguments. */
2040 *space_index = '\0';
2041 low = parse_and_eval_address (arg);
2042 high = parse_and_eval_address (space_index + 1);
2045 printf_filtered ("Dump of assembler code ");
2048 printf_filtered ("for function %s:\n", name);
2052 printf_filtered ("from ");
2053 print_address_numeric (low, 1, gdb_stdout);
2054 printf_filtered (" to ");
2055 print_address_numeric (high, 1, gdb_stdout);
2056 printf_filtered (":\n");
2059 /* Dump the specified range. */
2060 for (pc = low; pc < high; )
2063 print_address (pc, gdb_stdout);
2064 printf_filtered (":\t");
2065 /* We often wrap here if there are long symbolic names. */
2067 pc += print_insn (pc, gdb_stdout);
2068 printf_filtered ("\n");
2070 printf_filtered ("End of assembler dump.\n");
2071 gdb_flush (gdb_stdout);
2074 /* Print the instruction at address MEMADDR in debugged memory,
2075 on STREAM. Returns length of the instruction, in bytes. */
2078 print_insn (memaddr, stream)
2082 disassemble_info info;
2084 INIT_DISASSEMBLE_INFO (info, stream, (fprintf_ftype)fprintf_filtered);
2085 info.read_memory_func = dis_asm_read_memory;
2086 info.memory_error_func = dis_asm_memory_error;
2087 info.print_address_func = dis_asm_print_address;
2089 /* If there's no disassembler, something is very wrong. */
2090 if (tm_print_insn == NULL)
2093 return (*tm_print_insn) (memaddr, &info);
2098 _initialize_printcmd ()
2100 current_display_number = -1;
2102 add_info ("address", address_info,
2103 "Describe where variable VAR is stored.");
2105 add_com ("x", class_vars, x_command,
2106 concat ("Examine memory: x/FMT ADDRESS.\n\
2107 ADDRESS is an expression for the memory address to examine.\n\
2108 FMT is a repeat count followed by a format letter and a size letter.\n\
2109 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2110 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n",
2111 "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2112 The specified number of objects of the specified size are printed\n\
2113 according to the format.\n\n\
2114 Defaults for format and size letters are those previously used.\n\
2115 Default count is 1. Default address is following last thing printed\n\
2116 with this command or \"print\".", NULL));
2118 add_com ("disassemble", class_vars, disassemble_command,
2119 "Disassemble a specified section of memory.\n\
2120 Default is the function surrounding the pc of the selected frame.\n\
2121 With a single argument, the function surrounding that address is dumped.\n\
2122 Two arguments are taken as a range of memory to dump.");
2125 add_com ("whereis", class_vars, whereis_command,
2126 "Print line number and file of definition of variable.");
2129 add_info ("display", display_info,
2130 "Expressions to display when program stops, with code numbers.");
2132 add_cmd ("undisplay", class_vars, undisplay_command,
2133 "Cancel some expressions to be displayed when program stops.\n\
2134 Arguments are the code numbers of the expressions to stop displaying.\n\
2135 No argument means cancel all automatic-display expressions.\n\
2136 \"delete display\" has the same effect as this command.\n\
2137 Do \"info display\" to see current list of code numbers.",
2140 add_com ("display", class_vars, display_command,
2141 "Print value of expression EXP each time the program stops.\n\
2142 /FMT may be used before EXP as in the \"print\" command.\n\
2143 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2144 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2145 and examining is done as in the \"x\" command.\n\n\
2146 With no argument, display all currently requested auto-display expressions.\n\
2147 Use \"undisplay\" to cancel display requests previously made."
2150 add_cmd ("display", class_vars, enable_display,
2151 "Enable some expressions to be displayed when program stops.\n\
2152 Arguments are the code numbers of the expressions to resume displaying.\n\
2153 No argument means enable all automatic-display expressions.\n\
2154 Do \"info display\" to see current list of code numbers.", &enablelist);
2156 add_cmd ("display", class_vars, disable_display_command,
2157 "Disable some expressions to be displayed when program stops.\n\
2158 Arguments are the code numbers of the expressions to stop displaying.\n\
2159 No argument means disable all automatic-display expressions.\n\
2160 Do \"info display\" to see current list of code numbers.", &disablelist);
2162 add_cmd ("display", class_vars, undisplay_command,
2163 "Cancel some expressions to be displayed when program stops.\n\
2164 Arguments are the code numbers of the expressions to stop displaying.\n\
2165 No argument means cancel all automatic-display expressions.\n\
2166 Do \"info display\" to see current list of code numbers.", &deletelist);
2168 add_com ("printf", class_vars, printf_command,
2169 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2170 This is useful for formatted output in user-defined commands.");
2172 add_com ("output", class_vars, output_command,
2173 "Like \"print\" but don't put in value history and don't print newline.\n\
2174 This is useful in user-defined commands.");
2176 add_prefix_cmd ("set", class_vars, set_command,
2177 concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2178 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2179 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2180 with $), a register (a few standard names starting with $), or an actual\n\
2181 variable in the program being debugged. EXP is any valid expression.\n",
2182 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2183 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2184 You can see these environment settings with the \"show\" command.", NULL),
2185 &setlist, "set ", 1, &cmdlist);
2187 /* "call" is the same as "set", but handy for dbx users to call fns. */
2188 add_com ("call", class_vars, call_command,
2189 "Call a function in the program.\n\
2190 The argument is the function name and arguments, in the notation of the\n\
2191 current working language. The result is printed and saved in the value\n\
2192 history, if it is not void.");
2194 add_cmd ("variable", class_vars, set_command,
2195 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2196 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2197 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2198 with $), a register (a few standard names starting with $), or an actual\n\
2199 variable in the program being debugged. EXP is any valid expression.\n\
2200 This may usually be abbreviated to simply \"set\".",
2203 add_com ("print", class_vars, print_command,
2204 concat ("Print value of expression EXP.\n\
2205 Variables accessible are those of the lexical environment of the selected\n\
2206 stack frame, plus all those whose scope is global or an entire file.\n\
2208 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2209 $$NUM refers to NUM'th value back from the last one.\n\
2210 Names starting with $ refer to registers (with the values they would have\n",
2211 "if the program were to return to the stack frame now selected, restoring\n\
2212 all registers saved by frames farther in) or else to debugger\n\
2213 \"convenience\" variables (any such name not a known register).\n\
2214 Use assignment expressions to give values to convenience variables.\n",
2216 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2217 @ is a binary operator for treating consecutive data objects\n\
2218 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2219 element is FOO, whose second element is stored in the space following\n\
2220 where FOO is stored, etc. FOO must be an expression whose value\n\
2221 resides in memory.\n",
2223 EXP may be preceded with /FMT, where FMT is a format letter\n\
2224 but no count or size letter (see \"x\" command).", NULL));
2225 add_com_alias ("p", "print", class_vars, 1);
2227 add_com ("inspect", class_vars, inspect_command,
2228 "Same as \"print\" command, except that if you are running in the epoch\n\
2229 environment, the value is printed in its own window.");
2232 add_set_cmd ("max-symbolic-offset", no_class, var_uinteger,
2233 (char *)&max_symbolic_offset,
2234 "Set the largest offset that will be printed in <symbol+1234> form.",
2238 add_set_cmd ("symbol-filename", no_class, var_boolean,
2239 (char *)&print_symbol_filename,
2240 "Set printing of source filename and line number with <symbol>.",
2244 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2245 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2246 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2247 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);