1 /* Print values for GNU debugger GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "expression.h"
31 #include "breakpoint.h"
34 extern int asm_demangle
; /* Whether to demangle syms in asm printouts */
35 extern int addressprint
; /* Whether to print hex addresses in HLL " */
44 /* Last specified output format. */
46 static char last_format
= 'x';
48 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
50 static char last_size
= 'w';
52 /* Default address to examine next. */
54 static CORE_ADDR next_address
;
56 /* Last address examined. */
58 static CORE_ADDR last_examine_address
;
60 /* Contents of last address examined.
61 This is not valid past the end of the `x' command! */
63 static value last_examine_value
;
65 /* Number of auto-display expression currently being displayed.
66 So that we can deleted it if we get an error or a signal within it.
67 -1 when not doing one. */
69 int current_display_number
;
71 /* Flag to low-level print routines that this value is being printed
72 in an epoch window. We'd like to pass this as a parameter, but
73 every routine would need to take it. Perhaps we can encapsulate
74 this in the I/O stream once we have GNU stdio. */
80 /* Chain link to next auto-display item. */
82 /* Expression to be evaluated and displayed. */
83 struct expression
*exp
;
84 /* Item number of this auto-display item. */
86 /* Display format specified. */
87 struct format_data format
;
88 /* Innermost block required by this expression when evaluated */
90 /* Status of this display (enabled or disabled) */
94 /* Chain of expressions whose values should be displayed
95 automatically each time the program stops. */
97 static struct display
*display_chain
;
99 static int display_number
;
101 /* Prototypes for local functions */
104 delete_display
PARAMS ((int));
107 enable_display
PARAMS ((char *, int));
110 disable_display_command
PARAMS ((char *, int));
113 disassemble_command
PARAMS ((char *, int));
116 containing_function_bounds
PARAMS ((CORE_ADDR
, CORE_ADDR
*, CORE_ADDR
*));
119 printf_command
PARAMS ((char *, int));
122 print_frame_nameless_args
PARAMS ((CORE_ADDR
, long, int, int, FILE *));
125 display_info
PARAMS ((char *, int));
128 do_one_display
PARAMS ((struct display
*));
131 undisplay_command
PARAMS ((char *, int));
134 free_display
PARAMS ((struct display
*));
137 display_command
PARAMS ((char *, int));
140 x_command
PARAMS ((char *, int));
143 address_info
PARAMS ((char *, int));
146 set_command
PARAMS ((char *, int));
149 output_command
PARAMS ((char *, int));
152 call_command
PARAMS ((char *, int));
155 inspect_command
PARAMS ((char *, int));
158 print_command
PARAMS ((char *, int));
161 print_command_1
PARAMS ((char *, int, int));
164 validate_format
PARAMS ((struct format_data
, char *));
167 do_examine
PARAMS ((struct format_data
, CORE_ADDR
));
170 print_formatted
PARAMS ((value
, int, int));
172 static struct format_data
173 decode_format
PARAMS ((char **, int, int));
176 /* Decode a format specification. *STRING_PTR should point to it.
177 OFORMAT and OSIZE are used as defaults for the format and size
178 if none are given in the format specification.
179 If OSIZE is zero, then the size field of the returned value
180 should be set only if a size is explicitly specified by the
182 The structure returned describes all the data
183 found in the specification. In addition, *STRING_PTR is advanced
184 past the specification and past all whitespace following it. */
186 static struct format_data
187 decode_format (string_ptr
, oformat
, osize
)
192 struct format_data val
;
193 register char *p
= *string_ptr
;
199 if (*p
>= '0' && *p
<= '9')
200 val
.count
= atoi (p
);
201 while (*p
>= '0' && *p
<= '9') p
++;
203 /* Now process size or format letters that follow. */
207 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
216 else if (*p
>= 'a' && *p
<= 'z')
223 /* Make sure 'g' size is not used on integer types.
224 Well, actually, we can handle hex. */
225 if (val
.size
== 'g' && val
.format
!= 'f' && val
.format
!= 'x')
229 while (*p
== ' ' || *p
== '\t') p
++;
232 /* Set defaults for format and size if not specified. */
233 if (val
.format
== '?')
237 /* Neither has been specified. */
238 val
.format
= oformat
;
242 /* If a size is specified, any format makes a reasonable
243 default except 'i'. */
244 val
.format
= oformat
== 'i' ? 'x' : oformat
;
246 else if (val
.size
== '?')
251 /* Addresses must be words. */
252 val
.size
= osize
? 'w' : osize
;
255 /* Floating point has to be word or giantword. */
256 if (osize
== 'w' || osize
== 'g')
259 /* Default it to giantword if the last used size is not
261 val
.size
= osize
? 'g' : osize
;
264 /* Characters default to one byte. */
265 val
.size
= osize
? 'b' : osize
;
268 /* The default is the size most recently specified. */
275 /* Print value VAL on stdout according to FORMAT, a letter or 0.
276 Do not end with a newline.
277 0 means print VAL according to its own type.
278 SIZE is the letter for the size of datum being printed.
279 This is used to pad hex numbers so they line up. */
282 print_formatted (val
, format
, size
)
287 int len
= TYPE_LENGTH (VALUE_TYPE (val
));
289 if (VALUE_LVAL (val
) == lval_memory
)
290 next_address
= VALUE_ADDRESS (val
) + len
;
295 next_address
= VALUE_ADDRESS (val
)
296 + value_print (value_addr (val
), stdout
, format
, Val_pretty_default
);
300 wrap_here (""); /* Force output out, print_insn not using _filtered */
301 next_address
= VALUE_ADDRESS (val
)
302 + print_insn (VALUE_ADDRESS (val
), stdout
);
307 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_ARRAY
308 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_STRING
309 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_STRUCT
310 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_UNION
311 || VALUE_REPEATED (val
))
312 value_print (val
, stdout
, format
, Val_pretty_default
);
314 print_scalar_formatted (VALUE_CONTENTS (val
), VALUE_TYPE (val
),
315 format
, size
, stdout
);
319 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
320 according to letters FORMAT and SIZE on STREAM.
321 FORMAT may not be zero. Formats s and i are not supported at this level.
323 This is how the elements of an array or structure are printed
327 print_scalar_formatted (valaddr
, type
, format
, size
, stream
)
335 int len
= TYPE_LENGTH (type
);
337 if (size
== 'g' && sizeof (LONGEST
) < 8
340 /* ok, we're going to have to get fancy here. Assumption: a
341 long is four bytes. FIXME. */
342 unsigned long v1
, v2
;
344 v1
= unpack_long (builtin_type_long
, valaddr
);
345 v2
= unpack_long (builtin_type_long
, valaddr
+ 4);
347 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
348 /* Swap the two for printing */
361 fprintf_filtered (stream
, local_hex_format_custom("08x%08"), v1
, v2
);
364 error ("Output size \"g\" unimplemented for format \"%c\".",
370 val_long
= unpack_long (type
, valaddr
);
372 /* If value is unsigned, truncate it in case negative. */
375 if (len
== sizeof (char))
376 val_long
&= (1 << 8 * sizeof(char)) - 1;
377 else if (len
== sizeof (short))
378 val_long
&= (1 << 8 * sizeof(short)) - 1;
379 else if (len
== sizeof (long))
380 val_long
&= (unsigned long) - 1;
388 /* no size specified, like in print. Print varying # of digits. */
389 #if defined (LONG_LONG)
390 fprintf_filtered (stream
, local_hex_format_custom("ll"), val_long
);
391 #else /* not LONG_LONG. */
392 fprintf_filtered (stream
, local_hex_format_custom("l"), val_long
);
393 #endif /* not LONG_LONG. */
396 #if defined (LONG_LONG)
400 fprintf_filtered (stream
, local_hex_format_custom("02ll"), val_long
);
403 fprintf_filtered (stream
, local_hex_format_custom("04ll"), val_long
);
406 fprintf_filtered (stream
, local_hex_format_custom("08ll"), val_long
);
409 fprintf_filtered (stream
, local_hex_format_custom("016ll"), val_long
);
412 error ("Undefined output size \"%c\".", size
);
414 #else /* not LONG_LONG. */
418 fprintf_filtered (stream
, local_hex_format_custom("02"), val_long
);
421 fprintf_filtered (stream
, local_hex_format_custom("04"), val_long
);
424 fprintf_filtered (stream
, local_hex_format_custom("08"), val_long
);
427 fprintf_filtered (stream
, local_hex_format_custom("016"), val_long
);
430 error ("Undefined output size \"%c\".", size
);
432 #endif /* not LONG_LONG */
437 fprintf_filtered (stream
, local_decimal_format_custom("ll"), val_long
);
439 fprintf_filtered (stream
, local_decimal_format(), val_long
);
445 fprintf_filtered (stream
, "%llu", val_long
);
447 fprintf_filtered (stream
, "%u", val_long
);
454 fprintf_filtered (stream
, local_octal_format_custom("ll"), val_long
);
456 fprintf_filtered (stream
, local_octal_format(), val_long
);
459 fprintf_filtered (stream
, "0");
463 print_address (unpack_pointer (type
, valaddr
), stream
);
467 value_print (value_from_longest (builtin_type_char
, val_long
), stream
, 0,
472 if (len
== sizeof (float))
473 type
= builtin_type_float
;
474 else if (len
== sizeof (double))
475 type
= builtin_type_double
;
476 print_floating (valaddr
, type
, stream
);
483 /* Binary; 't' stands for "two". */
485 char bits
[8*(sizeof val_long
) + 1];
490 width
= 8*(sizeof val_long
);
507 error ("Undefined output size \"%c\".", size
);
513 bits
[width
] = (val_long
& 1) ? '1' : '0';
518 while (*cp
&& *cp
== '0')
523 fprintf_filtered (stream
, local_binary_format_prefix());
524 fprintf_filtered (stream
, cp
);
525 fprintf_filtered (stream
, local_binary_format_suffix());
530 error ("Undefined output format \"%c\".", format
);
534 /* Specify default address for `x' command.
535 `info lines' uses this. */
538 set_next_address (addr
)
543 /* Make address available to the user as $_. */
544 set_internalvar (lookup_internalvar ("_"),
545 value_from_longest (lookup_pointer_type (builtin_type_void
),
549 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
550 after LEADIN. Print nothing if no symbolic name is found nearby.
551 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
552 or to interpret it as a possible C++ name and convert it back to source
553 form. However note that DO_DEMANGLE can be overridden by the specific
554 settings of the demangle and asm_demangle variables. */
557 print_address_symbolic (addr
, stream
, do_demangle
, leadin
)
564 register struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (addr
);
566 /* If nothing comes out, don't print anything symbolic. */
571 fputs_filtered (leadin
, stream
);
572 fputs_filtered ("<", stream
);
574 fputs_filtered (SYMBOL_SOURCE_NAME (msymbol
), stream
);
576 fputs_filtered (SYMBOL_LINKAGE_NAME (msymbol
), stream
);
577 name_location
= SYMBOL_VALUE_ADDRESS (msymbol
);
578 if (addr
- name_location
)
579 fprintf_filtered (stream
, "+%d>", addr
- name_location
);
581 fputs_filtered (">", stream
);
584 /* Print address ADDR symbolically on STREAM.
585 First print it as a number. Then perhaps print
586 <SYMBOL + OFFSET> after the number. */
589 print_address (addr
, stream
)
593 #ifdef ADDR_BITS_REMOVE
594 fprintf_filtered (stream
, local_hex_format(), ADDR_BITS_REMOVE(addr
));
596 fprintf_filtered (stream
, local_hex_format(), addr
);
598 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
601 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
602 controls whether to print the symbolic name "raw" or demangled.
603 Global setting "addressprint" controls whether to print hex address
607 print_address_demangle (addr
, stream
, do_demangle
)
613 fprintf_filtered (stream
, "0");
614 } else if (addressprint
) {
615 fprintf_filtered (stream
, local_hex_format(), addr
);
616 print_address_symbolic (addr
, stream
, do_demangle
, " ");
618 print_address_symbolic (addr
, stream
, do_demangle
, "");
623 /* Examine data at address ADDR in format FMT.
624 Fetch it from memory and print on stdout. */
627 do_examine (fmt
, addr
)
628 struct format_data fmt
;
631 register char format
= 0;
633 register int count
= 1;
634 struct type
*val_type
;
636 register int maxelts
;
643 /* String or instruction format implies fetch single bytes
644 regardless of the specified size. */
645 if (format
== 's' || format
== 'i')
649 val_type
= builtin_type_char
;
650 else if (size
== 'h')
651 val_type
= builtin_type_short
;
652 else if (size
== 'w')
653 val_type
= builtin_type_long
;
654 else if (size
== 'g')
656 val_type
= builtin_type_double
;
658 val_type
= builtin_type_long_long
;
666 if (format
== 's' || format
== 'i')
669 /* Print as many objects as specified in COUNT, at most maxelts per line,
670 with the address of the next one at the start of each line. */
674 print_address (next_address
, stdout
);
675 printf_filtered (":");
680 printf_filtered ("\t");
681 /* Note that print_formatted sets next_address for the next
683 last_examine_address
= next_address
;
684 last_examine_value
= value_at (val_type
, next_address
);
685 print_formatted (last_examine_value
, format
, size
);
687 printf_filtered ("\n");
693 validate_format (fmt
, cmdname
)
694 struct format_data fmt
;
698 error ("Size letters are meaningless in \"%s\" command.", cmdname
);
700 error ("Item count other than 1 is meaningless in \"%s\" command.",
702 if (fmt
.format
== 'i' || fmt
.format
== 's')
703 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
704 fmt
.format
, cmdname
);
707 /* Evaluate string EXP as an expression in the current language and
708 print the resulting value. EXP may contain a format specifier as the
709 first argument ("/x myvar" for example, to print myvar in hex).
713 print_command_1 (exp
, inspect
, voidprint
)
718 struct expression
*expr
;
719 register struct cleanup
*old_chain
= 0;
720 register char format
= 0;
722 struct format_data fmt
;
725 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
726 inspect_it
= inspect
;
728 if (exp
&& *exp
== '/')
731 fmt
= decode_format (&exp
, last_format
, 0);
732 validate_format (fmt
, "print");
733 last_format
= format
= fmt
.format
;
744 extern int objectprint
;
746 expr
= parse_expression (exp
);
747 old_chain
= make_cleanup (free_current_contents
, &expr
);
749 val
= evaluate_expression (expr
);
751 /* C++: figure out what type we actually want to print it as. */
752 type
= VALUE_TYPE (val
);
755 && ( TYPE_CODE (type
) == TYPE_CODE_PTR
756 || TYPE_CODE (type
) == TYPE_CODE_REF
)
757 && ( TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
758 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_UNION
))
762 v
= value_from_vtable_info (val
, TYPE_TARGET_TYPE (type
));
766 type
= VALUE_TYPE (val
);
771 val
= access_value_history (0);
773 if (voidprint
|| (val
&& VALUE_TYPE (val
) &&
774 TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_VOID
))
776 int histindex
= record_latest_value (val
);
779 printf ("\031(gdb-makebuffer \"%s\" %d '(\"", exp
, histindex
);
781 if (histindex
>= 0) printf_filtered ("$%d = ", histindex
);
783 print_formatted (val
, format
, fmt
.size
);
784 printf_filtered ("\n");
790 do_cleanups (old_chain
);
791 inspect_it
= 0; /* Reset print routines to normal */
796 print_command (exp
, from_tty
)
800 print_command_1 (exp
, 0, 1);
803 /* Same as print, except in epoch, it gets its own window */
806 inspect_command (exp
, from_tty
)
810 extern int epoch_interface
;
812 print_command_1 (exp
, epoch_interface
, 1);
815 /* Same as print, except it doesn't print void results. */
818 call_command (exp
, from_tty
)
822 print_command_1 (exp
, 0, 0);
827 output_command (exp
, from_tty
)
831 struct expression
*expr
;
832 register struct cleanup
*old_chain
;
833 register char format
= 0;
835 struct format_data fmt
;
837 if (exp
&& *exp
== '/')
840 fmt
= decode_format (&exp
, 0, 0);
841 validate_format (fmt
, "output");
845 expr
= parse_expression (exp
);
846 old_chain
= make_cleanup (free_current_contents
, &expr
);
848 val
= evaluate_expression (expr
);
850 print_formatted (val
, format
, fmt
.size
);
852 do_cleanups (old_chain
);
857 set_command (exp
, from_tty
)
861 struct expression
*expr
= parse_expression (exp
);
862 register struct cleanup
*old_chain
863 = make_cleanup (free_current_contents
, &expr
);
864 evaluate_expression (expr
);
865 do_cleanups (old_chain
);
870 address_info (exp
, from_tty
)
874 register struct symbol
*sym
;
875 register struct minimal_symbol
*msymbol
;
877 register long basereg
;
878 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
879 if exp is a field of `this'. */
882 error ("Argument required.");
884 sym
= lookup_symbol (exp
, get_selected_block (), VAR_NAMESPACE
,
885 &is_a_field_of_this
, (struct symtab
**)NULL
);
888 if (is_a_field_of_this
)
890 printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp
);
894 msymbol
= lookup_minimal_symbol (exp
, (struct objfile
*) NULL
);
897 printf ("Symbol \"%s\" is at %s in a file compiled without debugging.\n",
898 exp
, local_hex_string(SYMBOL_VALUE_ADDRESS (msymbol
)));
900 error ("No symbol \"%s\" in current context.", exp
);
904 printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym
));
905 val
= SYMBOL_VALUE (sym
);
906 basereg
= SYMBOL_BASEREG (sym
);
908 switch (SYMBOL_CLASS (sym
))
911 case LOC_CONST_BYTES
:
916 printf ("a label at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym
)));
920 printf ("a variable in register %s", reg_names
[val
]);
924 printf ("static storage at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym
)));
928 printf ("an argument in register %s", reg_names
[val
]);
932 if (SYMBOL_BASEREG_VALID (sym
))
934 printf ("an argument at offset %ld from register %s",
935 val
, reg_names
[basereg
]);
939 printf ("an argument at offset %ld", val
);
944 if (SYMBOL_BASEREG_VALID (sym
))
946 printf ("an argument at offset %ld from register %s",
947 val
, reg_names
[basereg
]);
951 printf ("an argument at frame offset %ld", val
);
956 if (SYMBOL_BASEREG_VALID (sym
))
958 printf ("a local variable at offset %ld from register %s",
959 val
, reg_names
[basereg
]);
963 printf ("a local variable at frame offset %ld", val
);
968 printf ("a reference argument at offset %ld", val
);
972 printf ("a typedef");
976 printf ("a function at address %s",
977 local_hex_string(BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
981 printf ("of unknown (botched) type");
988 x_command (exp
, from_tty
)
992 struct expression
*expr
;
993 struct format_data fmt
;
994 struct cleanup
*old_chain
;
997 fmt
.format
= last_format
;
998 fmt
.size
= last_size
;
1001 if (exp
&& *exp
== '/')
1004 fmt
= decode_format (&exp
, last_format
, last_size
);
1007 /* If we have an expression, evaluate it and use it as the address. */
1009 if (exp
!= 0 && *exp
!= 0)
1011 expr
= parse_expression (exp
);
1012 /* Cause expression not to be there any more
1013 if this command is repeated with Newline.
1014 But don't clobber a user-defined command's definition. */
1017 old_chain
= make_cleanup (free_current_contents
, &expr
);
1018 val
= evaluate_expression (expr
);
1019 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_REF
)
1020 val
= value_ind (val
);
1021 /* In rvalue contexts, such as this, functions are coerced into
1022 pointers to functions. This makes "x/i main" work. */
1023 if (/* last_format == 'i'
1024 && */ TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FUNC
1025 && VALUE_LVAL (val
) == lval_memory
)
1026 next_address
= VALUE_ADDRESS (val
);
1028 next_address
= value_as_pointer (val
);
1029 do_cleanups (old_chain
);
1032 do_examine (fmt
, next_address
);
1034 /* If the examine succeeds, we remember its size and format for next time. */
1035 last_size
= fmt
.size
;
1036 last_format
= fmt
.format
;
1038 /* Set a couple of internal variables if appropriate. */
1039 if (last_examine_value
)
1041 /* Make last address examined available to the user as $_. Use
1042 the correct pointer type. */
1043 set_internalvar (lookup_internalvar ("_"),
1044 value_from_longest (
1045 lookup_pointer_type (VALUE_TYPE (last_examine_value
)),
1046 (LONGEST
) last_examine_address
));
1048 /* Make contents of last address examined available to the user as $__.*/
1049 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1054 /* Add an expression to the auto-display chain.
1055 Specify the expression. */
1058 display_command (exp
, from_tty
)
1062 struct format_data fmt
;
1063 register struct expression
*expr
;
1064 register struct display
*new;
1075 fmt
= decode_format (&exp
, 0, 0);
1076 if (fmt
.size
&& fmt
.format
== 0)
1078 if (fmt
.format
== 'i' || fmt
.format
== 's')
1088 innermost_block
= 0;
1089 expr
= parse_expression (exp
);
1091 new = (struct display
*) xmalloc (sizeof (struct display
));
1094 new->block
= innermost_block
;
1095 new->next
= display_chain
;
1096 new->number
= ++display_number
;
1098 new->status
= enabled
;
1099 display_chain
= new;
1101 if (from_tty
&& target_has_execution
)
1102 do_one_display (new);
1115 /* Clear out the display_chain.
1116 Done when new symtabs are loaded, since this invalidates
1117 the types stored in many expressions. */
1122 register struct display
*d
;
1124 while ((d
= display_chain
) != NULL
)
1127 display_chain
= d
->next
;
1132 /* Delete the auto-display number NUM. */
1135 delete_display (num
)
1138 register struct display
*d1
, *d
;
1141 error ("No display number %d.", num
);
1143 if (display_chain
->number
== num
)
1146 display_chain
= d1
->next
;
1150 for (d
= display_chain
; ; d
= d
->next
)
1153 error ("No display number %d.", num
);
1154 if (d
->next
->number
== num
)
1164 /* Delete some values from the auto-display chain.
1165 Specify the element numbers. */
1168 undisplay_command (args
, from_tty
)
1172 register char *p
= args
;
1178 if (query ("Delete all auto-display expressions? "))
1187 while (*p1
>= '0' && *p1
<= '9') p1
++;
1188 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1189 error ("Arguments must be display numbers.");
1193 delete_display (num
);
1196 while (*p
== ' ' || *p
== '\t') p
++;
1201 /* Display a single auto-display.
1202 Do nothing if the display cannot be printed in the current context,
1203 or if the display is disabled. */
1209 int within_current_scope
;
1211 if (d
->status
== disabled
)
1215 within_current_scope
= contained_in (get_selected_block (), d
->block
);
1217 within_current_scope
= 1;
1218 if (!within_current_scope
)
1221 current_display_number
= d
->number
;
1223 printf_filtered ("%d: ", d
->number
);
1228 printf_filtered ("x/");
1229 if (d
->format
.count
!= 1)
1230 printf_filtered ("%d", d
->format
.count
);
1231 printf_filtered ("%c", d
->format
.format
);
1232 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1233 printf_filtered ("%c", d
->format
.size
);
1234 printf_filtered (" ");
1235 print_expression (d
->exp
, stdout
);
1236 if (d
->format
.count
!= 1)
1237 printf_filtered ("\n");
1239 printf_filtered (" ");
1241 addr
= value_as_pointer (evaluate_expression (d
->exp
));
1242 if (d
->format
.format
== 'i')
1243 addr
= ADDR_BITS_REMOVE (addr
);
1245 do_examine (d
->format
, addr
);
1249 if (d
->format
.format
)
1250 printf_filtered ("/%c ", d
->format
.format
);
1251 print_expression (d
->exp
, stdout
);
1252 printf_filtered (" = ");
1253 print_formatted (evaluate_expression (d
->exp
),
1254 d
->format
.format
, d
->format
.size
);
1255 printf_filtered ("\n");
1259 current_display_number
= -1;
1262 /* Display all of the values on the auto-display chain which can be
1263 evaluated in the current scope. */
1268 register struct display
*d
;
1270 for (d
= display_chain
; d
; d
= d
->next
)
1274 /* Delete the auto-display which we were in the process of displaying.
1275 This is done when there is an error or a signal. */
1278 disable_display (num
)
1281 register struct display
*d
;
1283 for (d
= display_chain
; d
; d
= d
->next
)
1284 if (d
->number
== num
)
1286 d
->status
= disabled
;
1289 printf ("No display number %d.\n", num
);
1293 disable_current_display ()
1295 if (current_display_number
>= 0)
1297 disable_display (current_display_number
);
1298 fprintf (stderr
, "Disabling display %d to avoid infinite recursion.\n",
1299 current_display_number
);
1301 current_display_number
= -1;
1305 display_info (ignore
, from_tty
)
1309 register struct display
*d
;
1312 printf ("There are no auto-display expressions now.\n");
1314 printf_filtered ("Auto-display expressions now in effect:\n\
1315 Num Enb Expression\n");
1317 for (d
= display_chain
; d
; d
= d
->next
)
1319 printf_filtered ("%d: %c ", d
->number
, "ny"[(int)d
->status
]);
1321 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1323 else if (d
->format
.format
)
1324 printf_filtered ("/%c ", d
->format
.format
);
1325 print_expression (d
->exp
, stdout
);
1326 if (d
->block
&& !contained_in (get_selected_block (), d
->block
))
1327 printf_filtered (" (cannot be evaluated in the current context)");
1328 printf_filtered ("\n");
1334 enable_display (args
, from_tty
)
1338 register char *p
= args
;
1341 register struct display
*d
;
1345 for (d
= display_chain
; d
; d
= d
->next
)
1346 d
->status
= enabled
;
1352 while (*p1
>= '0' && *p1
<= '9')
1354 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1355 error ("Arguments must be display numbers.");
1359 for (d
= display_chain
; d
; d
= d
->next
)
1360 if (d
->number
== num
)
1362 d
->status
= enabled
;
1365 printf ("No display number %d.\n", num
);
1368 while (*p
== ' ' || *p
== '\t')
1375 disable_display_command (args
, from_tty
)
1379 register char *p
= args
;
1381 register struct display
*d
;
1385 for (d
= display_chain
; d
; d
= d
->next
)
1386 d
->status
= disabled
;
1392 while (*p1
>= '0' && *p1
<= '9')
1394 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1395 error ("Arguments must be display numbers.");
1397 disable_display (atoi (p
));
1400 while (*p
== ' ' || *p
== '\t')
1406 /* Print the value in stack frame FRAME of a variable
1407 specified by a struct symbol. */
1410 print_variable_value (var
, frame
, stream
)
1415 value val
= read_var_value (var
, frame
);
1416 value_print (val
, stream
, 0, Val_pretty_default
);
1419 /* Print the arguments of a stack frame, given the function FUNC
1420 running in that frame (as a symbol), the info on the frame,
1421 and the number of args according to the stack frame (or -1 if unknown). */
1423 /* References here and elsewhere to "number of args according to the
1424 stack frame" appear in all cases to refer to "number of ints of args
1425 according to the stack frame". At least for VAX, i386, isi. */
1428 print_frame_args (func
, fi
, num
, stream
)
1429 struct symbol
*func
;
1430 struct frame_info
*fi
;
1438 register struct symbol
*sym
;
1440 /* Offset of next stack argument beyond the one we have seen that is
1441 at the highest offset.
1442 -1 if we haven't come to a stack argument yet. */
1443 long highest_offset
= -1;
1445 /* Number of ints of arguments that we have printed so far. */
1446 int args_printed
= 0;
1450 b
= SYMBOL_BLOCK_VALUE (func
);
1451 nsyms
= BLOCK_NSYMS (b
);
1454 for (i
= 0; i
< nsyms
; i
++)
1457 sym
= BLOCK_SYM (b
, i
);
1459 /* Keep track of the highest stack argument offset seen, and
1460 skip over any kinds of symbols we don't care about. */
1462 switch (SYMBOL_CLASS (sym
)) {
1466 long current_offset
= SYMBOL_VALUE (sym
);
1468 arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
1470 /* Compute address of next argument by adding the size of
1471 this argument and rounding to an int boundary. */
1473 = ((current_offset
+ arg_size
+ sizeof (int) - 1)
1474 & ~(sizeof (int) - 1));
1476 /* If this is the highest offset seen yet, set highest_offset. */
1477 if (highest_offset
== -1
1478 || (current_offset
> highest_offset
))
1479 highest_offset
= current_offset
;
1481 /* Add the number of ints we're about to print to args_printed. */
1482 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
1485 /* We care about types of symbols, but don't need to keep track of
1486 stack offsets in them. */
1491 /* Other types of symbols we just skip over. */
1496 /* If the symbol name is non-null,
1497 we have to re-look-up the symbol because arguments often have
1498 two entries (one a parameter, one a register or local), and the one
1499 we want is the non-parm, which lookup_symbol will find for
1500 us. After this, sym could be any SYMBOL_CLASS...
1502 Null parameter names occur on the RS/6000, for traceback tables.
1503 FIXME, should we even print them? */
1505 if (*SYMBOL_NAME (sym
))
1506 sym
= lookup_symbol (SYMBOL_NAME (sym
),
1507 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
1509 /* Print the current arg. */
1511 fprintf_filtered (stream
, ", ");
1513 fprint_symbol (stream
, SYMBOL_SOURCE_NAME (sym
));
1514 fputs_filtered ("=", stream
);
1516 /* Avoid value_print because it will deref ref parameters. We just
1517 want to print their addresses. Print ??? for args whose address
1518 we do not know. We pass 2 as "recurse" to val_print because our
1519 standard indentation here is 4 spaces, and val_print indents
1520 2 for each recurse. */
1521 val
= read_var_value (sym
, FRAME_INFO_ID (fi
));
1523 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), VALUE_ADDRESS (val
),
1524 stream
, 0, 0, 2, Val_no_prettyprint
);
1526 fputs_filtered ("???", stream
);
1530 /* Don't print nameless args in situations where we don't know
1531 enough about the stack to find them. */
1536 if (highest_offset
== -1)
1537 start
= FRAME_ARGS_SKIP
;
1539 start
= highest_offset
;
1541 print_frame_nameless_args (fi
, start
, num
- args_printed
,
1546 /* Print nameless args on STREAM.
1547 FI is the frameinfo for this frame, START is the offset
1548 of the first nameless arg, and NUM is the number of nameless args to
1549 print. FIRST is nonzero if this is the first argument (not just
1550 the first nameless arg). */
1552 print_frame_nameless_args (fi
, start
, num
, first
, stream
)
1553 struct frame_info
*fi
;
1563 for (i
= 0; i
< num
; i
++)
1566 #ifdef NAMELESS_ARG_VALUE
1567 NAMELESS_ARG_VALUE (fi
, start
, &arg_value
);
1569 argsaddr
= FRAME_ARGS_ADDRESS (fi
);
1573 arg_value
= read_memory_integer (argsaddr
+ start
, sizeof (int));
1577 fprintf_filtered (stream
, ", ");
1579 #ifdef PRINT_NAMELESS_INTEGER
1580 PRINT_NAMELESS_INTEGER (stream
, arg_value
);
1582 #ifdef PRINT_TYPELESS_INTEGER
1583 PRINT_TYPELESS_INTEGER (stream
, builtin_type_int
, (LONGEST
) arg_value
);
1585 fprintf_filtered (stream
, "%d", arg_value
);
1586 #endif /* PRINT_TYPELESS_INTEGER */
1587 #endif /* PRINT_NAMELESS_INTEGER */
1589 start
+= sizeof (int);
1595 printf_command (arg
, from_tty
)
1600 register char *s
= arg
;
1604 int allocated_args
= 20;
1607 val_args
= (value
*) xmalloc (allocated_args
* sizeof (value
));
1610 error_no_arg ("format-control string and values to print");
1612 /* Skip white space before format string */
1613 while (*s
== ' ' || *s
== '\t') s
++;
1615 /* A format string should follow, enveloped in double quotes */
1617 error ("Bad format string, missing '\"'.");
1619 /* Parse the format-control string and copy it into the string STRING,
1620 processing some kinds of escape sequence. */
1622 f
= string
= (char *) alloca (strlen (s
) + 1);
1629 error ("Bad format string, non-terminated '\"'.");
1630 /* doesn't return */
1651 /* ??? TODO: handle other escape sequences */
1652 error ("Unrecognized \\ escape character in format string.");
1661 /* Skip over " and following space and comma. */
1664 while (*s
== ' ' || *s
== '\t') s
++;
1666 if (*s
!= ',' && *s
!= 0)
1667 error ("Invalid argument syntax");
1670 while (*s
== ' ' || *s
== '\t') s
++;
1673 /* Now scan the string for %-specs and see what kinds of args they want.
1674 argclass[I] classifies the %-specs so we can give vprintf something
1675 of the right size. */
1677 enum argclass
{int_arg
, string_arg
, double_arg
, long_long_arg
};
1678 enum argclass
*argclass
;
1684 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1691 while (strchr ("0123456789.hlL-+ #", *f
))
1693 if (*f
== 'l' || *f
== 'L')
1698 argclass
[nargs_wanted
++] = string_arg
;
1699 else if (*f
== 'e' || *f
== 'f' || *f
== 'g')
1700 argclass
[nargs_wanted
++] = double_arg
;
1701 else if (lcount
> 1)
1702 argclass
[nargs_wanted
++] = long_long_arg
;
1704 argclass
[nargs_wanted
++] = int_arg
;
1708 /* Now, parse all arguments and evaluate them.
1709 Store the VALUEs in VAL_ARGS. */
1714 if (nargs
== allocated_args
)
1715 val_args
= (value
*) xrealloc ((char *) val_args
,
1716 (allocated_args
*= 2)
1719 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
1721 /* If format string wants a float, unchecked-convert the value to
1722 floating point of the same size */
1724 if (argclass
[nargs
] == double_arg
)
1726 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (float))
1727 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
1728 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (double))
1729 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
1737 if (nargs
!= nargs_wanted
)
1738 error ("Wrong number of arguments for specified format-string");
1740 /* Now lay out an argument-list containing the arguments
1741 as doubles, integers and C pointers. */
1743 arg_bytes
= (char *) alloca (sizeof (double) * nargs
);
1745 for (i
= 0; i
< nargs
; i
++)
1747 if (argclass
[i
] == string_arg
)
1752 tem
= value_as_pointer (val_args
[i
]);
1754 /* This is a %s argument. Find the length of the string. */
1759 read_memory (tem
+ j
, &c
, 1);
1764 /* Copy the string contents into a string inside GDB. */
1765 str
= (char *) alloca (j
+ 1);
1766 read_memory (tem
, str
, j
);
1769 /* Pass address of internal copy as the arg to vprintf. */
1770 *((int *) &arg_bytes
[argindex
]) = (int) str
;
1771 argindex
+= sizeof (int);
1773 else if (VALUE_TYPE (val_args
[i
])->code
== TYPE_CODE_FLT
)
1775 *((double *) &arg_bytes
[argindex
]) = value_as_double (val_args
[i
]);
1776 argindex
+= sizeof (double);
1780 if (argclass
[i
] == long_long_arg
)
1782 *(long long *) &arg_bytes
[argindex
] = value_as_long (val_args
[i
]);
1783 argindex
+= sizeof (long long);
1788 *((long *) &arg_bytes
[argindex
]) = value_as_long (val_args
[i
]);
1789 argindex
+= sizeof (long);
1794 /* There is not a standard way to make a va_list, so we need
1795 to do various things for different systems. */
1796 #if defined (__INT_VARARGS_H)
1801 list
.__va_stk
= (int *) arg_bytes
;
1802 list
.__va_reg
= (int *) arg_bytes
;
1803 vprintf (string
, list
);
1805 #else /* No __INT_VARARGS_H. */
1806 vprintf (string
, arg_bytes
);
1807 #endif /* No __INT_VARARGS_H. */
1810 /* Helper function for asdump_command. Finds the bounds of a function
1811 for a specified section of text. PC is an address within the
1812 function which you want bounds for; *LOW and *HIGH are set to the
1813 beginning (inclusive) and end (exclusive) of the function. This
1814 function returns 1 on success and 0 on failure. */
1817 containing_function_bounds (pc
, low
, high
)
1818 CORE_ADDR pc
, *low
, *high
;
1822 if (!find_pc_partial_function (pc
, 0, low
))
1828 if (!find_pc_partial_function (scan
, 0, high
))
1830 } while (*low
== *high
);
1835 /* Dump a specified section of assembly code. With no command line
1836 arguments, this command will dump the assembly code for the
1837 function surrounding the pc value in the selected frame. With one
1838 argument, it will dump the assembly code surrounding that pc value.
1839 Two arguments are interpeted as bounds within which to dump
1844 disassemble_command (arg
, from_tty
)
1848 CORE_ADDR low
, high
;
1854 if (!selected_frame
)
1855 error ("No frame selected.\n");
1857 pc
= get_frame_pc (selected_frame
);
1858 if (!containing_function_bounds (pc
, &low
, &high
))
1859 error ("No function contains pc specified by selected frame.\n");
1861 else if (!(space_index
= (char *) strchr (arg
, ' ')))
1864 pc
= parse_and_eval_address (arg
);
1865 if (!containing_function_bounds (pc
, &low
, &high
))
1866 error ("No function contains specified pc.\n");
1870 /* Two arguments. */
1871 *space_index
= '\0';
1872 low
= parse_and_eval_address (arg
);
1873 high
= parse_and_eval_address (space_index
+ 1);
1876 printf_filtered ("Dump of assembler code ");
1880 find_pc_partial_function (pc
, &name
, 0);
1881 printf_filtered ("for function %s:\n", name
);
1884 printf_filtered ("from %s ", local_hex_string(low
));
1885 printf_filtered ("to %s:\n", local_hex_string(high
));
1887 /* Dump the specified range. */
1888 for (pc
= low
; pc
< high
; )
1891 print_address (pc
, stdout
);
1892 printf_filtered (":\t");
1893 pc
+= print_insn (pc
, stdout
);
1894 printf_filtered ("\n");
1896 printf_filtered ("End of assembler dump.\n");
1902 _initialize_printcmd ()
1904 current_display_number
= -1;
1906 add_info ("address", address_info
,
1907 "Describe where variable VAR is stored.");
1909 add_com ("x", class_vars
, x_command
,
1910 "Examine memory: x/FMT ADDRESS.\n\
1911 ADDRESS is an expression for the memory address to examine.\n\
1912 FMT is a repeat count followed by a format letter and a size letter.\n\
1913 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1914 f(float), a(address), i(instruction), c(char) and s(string).\n\
1915 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1916 g is meaningful only with f, for type double.\n\
1917 The specified number of objects of the specified size are printed\n\
1918 according to the format.\n\n\
1919 Defaults for format and size letters are those previously used.\n\
1920 Default count is 1. Default address is following last thing printed\n\
1921 with this command or \"print\".");
1923 add_com ("disassemble", class_vars
, disassemble_command
,
1924 "Disassemble a specified section of memory.\n\
1925 Default is the function surrounding the pc of the selected frame.\n\
1926 With a single argument, the function surrounding that address is dumped.\n\
1927 Two arguments are taken as a range of memory to dump.");
1930 add_com ("whereis", class_vars
, whereis_command
,
1931 "Print line number and file of definition of variable.");
1934 add_info ("display", display_info
,
1935 "Expressions to display when program stops, with code numbers.");
1937 add_cmd ("undisplay", class_vars
, undisplay_command
,
1938 "Cancel some expressions to be displayed when program stops.\n\
1939 Arguments are the code numbers of the expressions to stop displaying.\n\
1940 No argument means cancel all automatic-display expressions.\n\
1941 \"delete display\" has the same effect as this command.\n\
1942 Do \"info display\" to see current list of code numbers.",
1945 add_com ("display", class_vars
, display_command
,
1946 "Print value of expression EXP each time the program stops.\n\
1947 /FMT may be used before EXP as in the \"print\" command.\n\
1948 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
1949 as in the \"x\" command, and then EXP is used to get the address to examine\n\
1950 and examining is done as in the \"x\" command.\n\n\
1951 With no argument, display all currently requested auto-display expressions.\n\
1952 Use \"undisplay\" to cancel display requests previously made.");
1954 add_cmd ("display", class_vars
, enable_display
,
1955 "Enable some expressions to be displayed when program stops.\n\
1956 Arguments are the code numbers of the expressions to resume displaying.\n\
1957 No argument means enable all automatic-display expressions.\n\
1958 Do \"info display\" to see current list of code numbers.", &enablelist
);
1960 add_cmd ("display", class_vars
, disable_display_command
,
1961 "Disable some expressions to be displayed when program stops.\n\
1962 Arguments are the code numbers of the expressions to stop displaying.\n\
1963 No argument means disable all automatic-display expressions.\n\
1964 Do \"info display\" to see current list of code numbers.", &disablelist
);
1966 add_cmd ("display", class_vars
, undisplay_command
,
1967 "Cancel some expressions to be displayed when program stops.\n\
1968 Arguments are the code numbers of the expressions to stop displaying.\n\
1969 No argument means cancel all automatic-display expressions.\n\
1970 Do \"info display\" to see current list of code numbers.", &deletelist
);
1972 add_com ("printf", class_vars
, printf_command
,
1973 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
1974 This is useful for formatted output in user-defined commands.");
1975 add_com ("output", class_vars
, output_command
,
1976 "Like \"print\" but don't put in value history and don't print newline.\n\
1977 This is useful in user-defined commands.");
1979 add_prefix_cmd ("set", class_vars
, set_command
,
1980 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
1981 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
1982 example). VAR may be a debugger \"convenience\" variable (names starting\n\
1983 with $), a register (a few standard names starting with $), or an actual\n\
1984 variable in the program being debugged. EXP is any valid expression.\n\
1985 Use \"set variable\" for variables with names identical to set subcommands.\n\
1986 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
1987 You can see these environment settings with the \"show\" command.",
1988 &setlist
, "set ", 1, &cmdlist
);
1990 /* "call" is the same as "set", but handy for dbx users to call fns. */
1991 add_com ("call", class_vars
, call_command
,
1992 "Call a function in the inferior process.\n\
1993 The argument is the function name and arguments, in the notation of the\n\
1994 current working language. The result is printed and saved in the value\n\
1995 history, if it is not void.");
1997 add_cmd ("variable", class_vars
, set_command
,
1998 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
1999 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2000 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2001 with $), a register (a few standard names starting with $), or an actual\n\
2002 variable in the program being debugged. EXP is any valid expression.\n\
2003 This may usually be abbreviated to simply \"set\".",
2006 add_com ("print", class_vars
, print_command
,
2007 concat ("Print value of expression EXP.\n\
2008 Variables accessible are those of the lexical environment of the selected\n\
2009 stack frame, plus all those whose scope is global or an entire file.\n\
2011 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2012 $$NUM refers to NUM'th value back from the last one.\n\
2013 Names starting with $ refer to registers (with the values they would have\n\
2014 if the program were to return to the stack frame now selected, restoring\n\
2015 all registers saved by frames farther in) or else to debugger\n\
2016 \"convenience\" variables (any such name not a known register).\n\
2017 Use assignment expressions to give values to convenience variables.\n",
2019 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2020 @ is a binary operator for treating consecutive data objects\n\
2021 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2022 element is FOO, whose second element is stored in the space following\n\
2023 where FOO is stored, etc. FOO must be an expression whose value\n\
2024 resides in memory.\n",
2026 EXP may be preceded with /FMT, where FMT is a format letter\n\
2027 but no count or size letter (see \"x\" command).", NULL
));
2028 add_com_alias ("p", "print", class_vars
, 1);
2030 add_com ("inspect", class_vars
, inspect_command
,
2031 "Same as \"print\" command, except that if you are running in the epoch\n\
2032 environment, the value is printed in its own window.");