1 /* Print values for GNU debugger GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
28 #include "expression.h"
32 #include "breakpoint.h"
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 *));
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 ((void));
128 do_one_display
PARAMS ((struct display
*));
131 undisplay_command
PARAMS ((char *));
134 free_display
PARAMS ((struct display
*));
137 display_command
PARAMS ((char *, int));
140 ptype_command
PARAMS ((char *, int));
143 ptype_eval
PARAMS ((struct expression
*));
146 whatis_command
PARAMS ((char *, int));
149 whatis_exp
PARAMS ((char *, int));
152 x_command
PARAMS ((char *, int));
155 address_info
PARAMS ((char *, int));
158 set_command
PARAMS ((char *, int));
161 output_command
PARAMS ((char *, int));
164 call_command
PARAMS ((char *, int));
167 inspect_command
PARAMS ((char *, int));
170 print_command
PARAMS ((char *, int));
173 print_command_1
PARAMS ((char *, int, int));
176 validate_format
PARAMS ((struct format_data
, char *));
179 do_examine
PARAMS ((struct format_data
, CORE_ADDR
));
182 print_formatted
PARAMS ((value
, int, int));
184 static struct format_data
185 decode_format
PARAMS ((char **, int, int));
188 /* Decode a format specification. *STRING_PTR should point to it.
189 OFORMAT and OSIZE are used as defaults for the format and size
190 if none are given in the format specification.
191 If OSIZE is zero, then the size field of the returned value
192 should be set only if a size is explicitly specified by the
194 The structure returned describes all the data
195 found in the specification. In addition, *STRING_PTR is advanced
196 past the specification and past all whitespace following it. */
198 static struct format_data
199 decode_format (string_ptr
, oformat
, osize
)
204 struct format_data val
;
205 register char *p
= *string_ptr
;
211 if (*p
>= '0' && *p
<= '9')
212 val
.count
= atoi (p
);
213 while (*p
>= '0' && *p
<= '9') p
++;
215 /* Now process size or format letters that follow. */
219 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
228 else if (*p
>= 'a' && *p
<= 'z')
235 /* Make sure 'g' size is not used on integer types.
236 Well, actually, we can handle hex. */
237 if (val
.size
== 'g' && val
.format
!= 'f' && val
.format
!= 'x')
241 while (*p
== ' ' || *p
== '\t') p
++;
244 /* Set defaults for format and size if not specified. */
245 if (val
.format
== '?')
249 /* Neither has been specified. */
250 val
.format
= oformat
;
254 /* If a size is specified, any format makes a reasonable
255 default except 'i'. */
256 val
.format
= oformat
== 'i' ? 'x' : oformat
;
258 else if (val
.size
== '?')
263 /* Addresses must be words. */
264 val
.size
= osize
? 'w' : osize
;
267 /* Floating point has to be word or giantword. */
268 if (osize
== 'w' || osize
== 'g')
271 /* Default it to giantword if the last used size is not
273 val
.size
= osize
? 'g' : osize
;
276 /* Characters default to one byte. */
277 val
.size
= osize
? 'b' : osize
;
280 /* The default is the size most recently specified. */
287 /* Print value VAL on stdout according to FORMAT, a letter or 0.
288 Do not end with a newline.
289 0 means print VAL according to its own type.
290 SIZE is the letter for the size of datum being printed.
291 This is used to pad hex numbers so they line up. */
294 print_formatted (val
, format
, size
)
299 int len
= TYPE_LENGTH (VALUE_TYPE (val
));
301 if (VALUE_LVAL (val
) == lval_memory
)
302 next_address
= VALUE_ADDRESS (val
) + len
;
307 next_address
= VALUE_ADDRESS (val
)
308 + value_print (value_addr (val
), stdout
, format
, Val_pretty_default
);
312 wrap_here (""); /* Force output out, print_insn not using _filtered */
313 next_address
= VALUE_ADDRESS (val
)
314 + print_insn (VALUE_ADDRESS (val
), stdout
);
319 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_ARRAY
320 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_STRUCT
321 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_UNION
322 || VALUE_REPEATED (val
))
323 value_print (val
, stdout
, format
, Val_pretty_default
);
325 print_scalar_formatted (VALUE_CONTENTS (val
), VALUE_TYPE (val
),
326 format
, size
, stdout
);
330 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
331 according to letters FORMAT and SIZE on STREAM.
332 FORMAT may not be zero. Formats s and i are not supported at this level.
334 This is how the elements of an array or structure are printed
338 print_scalar_formatted (valaddr
, type
, format
, size
, stream
)
346 int len
= TYPE_LENGTH (type
);
348 if (size
== 'g' && sizeof (LONGEST
) < 8
351 /* ok, we're going to have to get fancy here. Assumption: a
352 long is four bytes. FIXME. */
353 unsigned long v1
, v2
;
355 v1
= unpack_long (builtin_type_long
, valaddr
);
356 v2
= unpack_long (builtin_type_long
, valaddr
+ 4);
358 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
359 /* Swap the two for printing */
372 fprintf_filtered (stream
, local_hex_format_custom("08x%08"), v1
, v2
);
375 error ("Output size \"g\" unimplemented for format \"%c\".",
381 val_long
= unpack_long (type
, valaddr
);
383 /* If value is unsigned, truncate it in case negative. */
386 if (len
== sizeof (char))
387 val_long
&= (1 << 8 * sizeof(char)) - 1;
388 else if (len
== sizeof (short))
389 val_long
&= (1 << 8 * sizeof(short)) - 1;
390 else if (len
== sizeof (long))
391 val_long
&= (unsigned long) - 1;
399 /* no size specified, like in print. Print varying # of digits. */
400 #if defined (LONG_LONG)
401 fprintf_filtered (stream
, local_hex_format_custom("ll"), val_long
);
402 #else /* not LONG_LONG. */
403 fprintf_filtered (stream
, local_hex_format_custom("l"), val_long
);
404 #endif /* not LONG_LONG. */
407 #if defined (LONG_LONG)
411 fprintf_filtered (stream
, local_hex_format_custom("02ll"), val_long
);
414 fprintf_filtered (stream
, local_hex_format_custom("04ll"), val_long
);
417 fprintf_filtered (stream
, local_hex_format_custom("08ll"), val_long
);
420 fprintf_filtered (stream
, local_hex_format_custom("016ll"), val_long
);
423 error ("Undefined output size \"%c\".", size
);
425 #else /* not LONG_LONG. */
429 fprintf_filtered (stream
, local_hex_format_custom("02"), val_long
);
432 fprintf_filtered (stream
, local_hex_format_custom("04"), val_long
);
435 fprintf_filtered (stream
, local_hex_format_custom("08"), val_long
);
438 fprintf_filtered (stream
, local_hex_format_custom("016"), val_long
);
441 error ("Undefined output size \"%c\".", size
);
443 #endif /* not LONG_LONG */
448 fprintf_filtered (stream
, "%lld", val_long
);
450 fprintf_filtered (stream
, "%d", val_long
);
456 fprintf_filtered (stream
, "%llu", val_long
);
458 fprintf_filtered (stream
, "%u", val_long
);
465 fprintf_filtered (stream
, local_octal_format_custom("ll"), val_long
);
467 fprintf_filtered (stream
, local_octal_format(), val_long
);
470 fprintf_filtered (stream
, "0");
474 print_address (unpack_pointer (type
, valaddr
), stream
);
478 value_print (value_from_longest (builtin_type_char
, val_long
), stream
, 0,
483 if (len
== sizeof (float))
484 type
= builtin_type_float
;
485 else if (len
== sizeof (double))
486 type
= builtin_type_double
;
487 print_floating (valaddr
, type
, stream
);
494 /* Binary; 't' stands for "two". */
496 char bits
[8*(sizeof val_long
) + 1];
501 width
= 8*(sizeof val_long
);
518 error ("Undefined output size \"%c\".", size
);
524 bits
[width
] = (val_long
& 1) ? '1' : '0';
529 while (*cp
&& *cp
== '0')
534 fprintf_filtered (stream
, cp
);
539 error ("Undefined output format \"%c\".", format
);
543 /* Specify default address for `x' command.
544 `info lines' uses this. */
547 set_next_address (addr
)
552 /* Make address available to the user as $_. */
553 set_internalvar (lookup_internalvar ("_"),
554 value_from_longest (lookup_pointer_type (builtin_type_void
),
558 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
559 after LEADIN. Print nothing if no symbolic name is found nearby.
560 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
561 or to interpret it as a possible C++ name and convert it back to source
565 print_address_symbolic (addr
, stream
, do_demangle
, leadin
)
572 register struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (addr
);
574 /* If nothing comes out, don't print anything symbolic. */
579 fputs_filtered (leadin
, stream
);
580 fputs_filtered ("<", stream
);
582 fputs_demangled (msymbol
-> name
, stream
, 1);
584 fputs_filtered (msymbol
-> name
, stream
);
585 name_location
= msymbol
-> address
;
586 if (addr
- name_location
)
587 fprintf_filtered (stream
, "+%d>", addr
- name_location
);
589 fputs_filtered (">", stream
);
592 /* Print address ADDR symbolically on STREAM.
593 First print it as a number. Then perhaps print
594 <SYMBOL + OFFSET> after the number. */
597 print_address (addr
, stream
)
601 #ifdef ADDR_BITS_REMOVE
602 fprintf_filtered (stream
, local_hex_format(), ADDR_BITS_REMOVE(addr
));
604 fprintf_filtered (stream
, local_hex_format(), addr
);
606 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
609 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
610 controls whether to print the symbolic name "raw" or demangled.
611 Global setting "addressprint" controls whether to print hex address
615 print_address_demangle (addr
, stream
, do_demangle
)
621 fprintf_filtered (stream
, "0");
622 } else if (addressprint
) {
623 fprintf_filtered (stream
, local_hex_format(), addr
);
624 print_address_symbolic (addr
, stream
, do_demangle
, " ");
626 print_address_symbolic (addr
, stream
, do_demangle
, "");
631 /* Examine data at address ADDR in format FMT.
632 Fetch it from memory and print on stdout. */
635 do_examine (fmt
, addr
)
636 struct format_data fmt
;
639 register char format
= 0;
641 register int count
= 1;
642 struct type
*val_type
;
644 register int maxelts
;
651 /* String or instruction format implies fetch single bytes
652 regardless of the specified size. */
653 if (format
== 's' || format
== 'i')
657 val_type
= builtin_type_char
;
658 else if (size
== 'h')
659 val_type
= builtin_type_short
;
660 else if (size
== 'w')
661 val_type
= builtin_type_long
;
662 else if (size
== 'g')
664 val_type
= builtin_type_double
;
666 val_type
= builtin_type_long_long
;
674 if (format
== 's' || format
== 'i')
677 /* Print as many objects as specified in COUNT, at most maxelts per line,
678 with the address of the next one at the start of each line. */
682 print_address (next_address
, stdout
);
683 printf_filtered (":");
688 printf_filtered ("\t");
689 /* Note that print_formatted sets next_address for the next
691 last_examine_address
= next_address
;
692 last_examine_value
= value_at (val_type
, next_address
);
693 print_formatted (last_examine_value
, format
, size
);
695 printf_filtered ("\n");
701 validate_format (fmt
, cmdname
)
702 struct format_data fmt
;
706 error ("Size letters are meaningless in \"%s\" command.", cmdname
);
708 error ("Item count other than 1 is meaningless in \"%s\" command.",
710 if (fmt
.format
== 'i' || fmt
.format
== 's')
711 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
712 fmt
.format
, cmdname
);
716 print_command_1 (exp
, inspect
, voidprint
)
721 struct expression
*expr
;
722 register struct cleanup
*old_chain
= 0;
723 register char format
= 0;
725 struct format_data fmt
;
728 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
729 inspect_it
= inspect
;
731 if (exp
&& *exp
== '/')
734 fmt
= decode_format (&exp
, last_format
, 0);
735 validate_format (fmt
, "print");
736 last_format
= format
= fmt
.format
;
747 extern int objectprint
;
749 expr
= parse_expression (exp
);
750 old_chain
= make_cleanup (free_current_contents
, &expr
);
752 val
= evaluate_expression (expr
);
754 /* C++: figure out what type we actually want to print it as. */
755 type
= VALUE_TYPE (val
);
758 && ( TYPE_CODE (type
) == TYPE_CODE_PTR
759 || TYPE_CODE (type
) == TYPE_CODE_REF
)
760 && ( TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
761 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_UNION
))
765 v
= value_from_vtable_info (val
, TYPE_TARGET_TYPE (type
));
769 type
= VALUE_TYPE (val
);
774 val
= access_value_history (0);
776 if (voidprint
|| (val
&& VALUE_TYPE (val
) &&
777 TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_VOID
))
779 int histindex
= record_latest_value (val
);
782 printf ("\031(gdb-makebuffer \"%s\" %d '(\"", exp
, histindex
);
784 if (histindex
>= 0) printf_filtered ("$%d = ", histindex
);
786 print_formatted (val
, format
, fmt
.size
);
787 printf_filtered ("\n");
793 do_cleanups (old_chain
);
794 inspect_it
= 0; /* Reset print routines to normal */
799 print_command (exp
, from_tty
)
803 print_command_1 (exp
, 0, 1);
806 /* Same as print, except in epoch, it gets its own window */
809 inspect_command (exp
, from_tty
)
813 extern int epoch_interface
;
815 print_command_1 (exp
, epoch_interface
, 1);
818 /* Same as print, except it doesn't print void results. */
821 call_command (exp
, from_tty
)
825 print_command_1 (exp
, 0, 0);
830 output_command (exp
, from_tty
)
834 struct expression
*expr
;
835 register struct cleanup
*old_chain
;
836 register char format
= 0;
838 struct format_data fmt
;
840 if (exp
&& *exp
== '/')
843 fmt
= decode_format (&exp
, 0, 0);
844 validate_format (fmt
, "print");
848 expr
= parse_expression (exp
);
849 old_chain
= make_cleanup (free_current_contents
, &expr
);
851 val
= evaluate_expression (expr
);
853 print_formatted (val
, format
, fmt
.size
);
855 do_cleanups (old_chain
);
860 set_command (exp
, from_tty
)
864 struct expression
*expr
= parse_expression (exp
);
865 register struct cleanup
*old_chain
866 = make_cleanup (free_current_contents
, &expr
);
867 evaluate_expression (expr
);
868 do_cleanups (old_chain
);
873 address_info (exp
, from_tty
)
877 register struct symbol
*sym
;
878 register struct minimal_symbol
*msymbol
;
880 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
881 if exp is a field of `this'. */
884 error ("Argument required.");
886 sym
= lookup_symbol (exp
, get_selected_block (), VAR_NAMESPACE
,
887 &is_a_field_of_this
, (struct symtab
**)NULL
);
890 if (is_a_field_of_this
)
892 printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp
);
896 msymbol
= lookup_minimal_symbol (exp
, (struct objfile
*) NULL
);
899 printf ("Symbol \"%s\" is at %s in a file compiled without debugging.\n",
900 exp
, local_hex_string(msymbol
-> address
));
902 error ("No symbol \"%s\" in current context.", exp
);
906 printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym
));
907 val
= SYMBOL_VALUE (sym
);
909 switch (SYMBOL_CLASS (sym
))
912 case LOC_CONST_BYTES
:
917 printf ("a label at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym
)));
921 printf ("a variable in register %s", reg_names
[val
]);
925 printf ("static storage at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym
)));
929 printf ("an argument in register %s", reg_names
[val
]);
933 printf ("an argument at offset %ld", val
);
937 printf ("an argument at frame offset %ld", val
);
941 printf ("a local variable at frame offset %ld", val
);
945 printf ("a reference argument at offset %ld", val
);
949 printf ("a typedef");
953 printf ("a function at address %s",
954 local_hex_string(BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
958 printf ("of unknown (botched) type");
965 x_command (exp
, from_tty
)
969 struct expression
*expr
;
970 struct format_data fmt
;
971 struct cleanup
*old_chain
;
974 fmt
.format
= last_format
;
975 fmt
.size
= last_size
;
978 if (exp
&& *exp
== '/')
981 fmt
= decode_format (&exp
, last_format
, last_size
);
982 last_size
= fmt
.size
;
983 last_format
= fmt
.format
;
986 /* If we have an expression, evaluate it and use it as the address. */
988 if (exp
!= 0 && *exp
!= 0)
990 expr
= parse_expression (exp
);
991 /* Cause expression not to be there any more
992 if this command is repeated with Newline.
993 But don't clobber a user-defined command's definition. */
996 old_chain
= make_cleanup (free_current_contents
, &expr
);
997 val
= evaluate_expression (expr
);
998 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_REF
)
999 val
= value_ind (val
);
1000 /* In rvalue contexts, such as this, functions are coerced into
1001 pointers to functions. This makes "x/i main" work. */
1002 if (/* last_format == 'i'
1003 && */ TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FUNC
1004 && VALUE_LVAL (val
) == lval_memory
)
1005 next_address
= VALUE_ADDRESS (val
);
1007 next_address
= value_as_pointer (val
);
1008 do_cleanups (old_chain
);
1011 do_examine (fmt
, next_address
);
1013 /* Set a couple of internal variables if appropriate. */
1014 if (last_examine_value
)
1016 /* Make last address examined available to the user as $_. Use
1017 the correct pointer type. */
1018 set_internalvar (lookup_internalvar ("_"),
1019 value_from_longest (
1020 lookup_pointer_type (VALUE_TYPE (last_examine_value
)),
1021 (LONGEST
) last_examine_address
));
1023 /* Make contents of last address examined available to the user as $__.*/
1024 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1028 /* Commands for printing types of things. */
1030 /* Print type of EXP, or last thing in value history if EXP == NULL.
1031 show is passed to type_print. */
1033 whatis_exp (exp
, show
)
1037 struct expression
*expr
;
1039 register struct cleanup
*old_chain
;
1043 expr
= parse_expression (exp
);
1044 old_chain
= make_cleanup (free_current_contents
, &expr
);
1045 val
= evaluate_type (expr
);
1048 val
= access_value_history (0);
1050 printf_filtered ("type = ");
1051 type_print (VALUE_TYPE (val
), "", stdout
, show
);
1052 printf_filtered ("\n");
1055 do_cleanups (old_chain
);
1060 whatis_command (exp
, from_tty
)
1064 /* Most of the time users do not want to see all the fields
1065 in a structure. If they do they can use the "ptype" command.
1066 Hence the "-1" below. */
1067 whatis_exp (exp
, -1);
1070 /* Simple subroutine for ptype_command. */
1074 struct expression
*exp
;
1076 if(exp
->elts
[0].opcode
==OP_TYPE
)
1077 return exp
->elts
[1].type
;
1082 /* TYPENAME is either the name of a type, or an expression. */
1085 ptype_command (typename
, from_tty
)
1089 register struct type
*type
;
1090 struct expression
*expr
;
1091 register struct cleanup
*old_chain
;
1095 expr
= parse_expression (typename
);
1096 old_chain
= make_cleanup (free_current_contents
, &expr
);
1097 type
= ptype_eval (expr
);
1101 printf_filtered ("type = ");
1102 type_print (type
, "", stdout
, 1);
1103 printf_filtered ("\n");
1104 do_cleanups (old_chain
);
1108 do_cleanups (old_chain
);
1109 whatis_exp (typename
, 1);
1113 whatis_exp (typename
, 1);
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
)
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
)
1233 register char *p
= args
;
1239 if (query ("Delete all auto-display expressions? "))
1248 while (*p1
>= '0' && *p1
<= '9') p1
++;
1249 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1250 error ("Arguments must be display numbers.");
1254 delete_display (num
);
1257 while (*p
== ' ' || *p
== '\t') p
++;
1262 /* Display a single auto-display.
1263 Do nothing if the display cannot be printed in the current context,
1264 or if the display is disabled. */
1270 int within_current_scope
;
1272 if (d
->status
== disabled
)
1276 within_current_scope
= contained_in (get_selected_block (), d
->block
);
1278 within_current_scope
= 1;
1279 if (!within_current_scope
)
1282 current_display_number
= d
->number
;
1284 printf_filtered ("%d: ", d
->number
);
1289 printf_filtered ("x/");
1290 if (d
->format
.count
!= 1)
1291 printf_filtered ("%d", d
->format
.count
);
1292 printf_filtered ("%c", d
->format
.format
);
1293 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1294 printf_filtered ("%c", d
->format
.size
);
1295 printf_filtered (" ");
1296 print_expression (d
->exp
, stdout
);
1297 if (d
->format
.count
!= 1)
1298 printf_filtered ("\n");
1300 printf_filtered (" ");
1302 addr
= value_as_pointer (evaluate_expression (d
->exp
));
1303 if (d
->format
.format
== 'i')
1304 addr
= ADDR_BITS_REMOVE (addr
);
1306 do_examine (d
->format
, addr
);
1310 if (d
->format
.format
)
1311 printf_filtered ("/%c ", d
->format
.format
);
1312 print_expression (d
->exp
, stdout
);
1313 printf_filtered (" = ");
1314 print_formatted (evaluate_expression (d
->exp
),
1315 d
->format
.format
, d
->format
.size
);
1316 printf_filtered ("\n");
1320 current_display_number
= -1;
1323 /* Display all of the values on the auto-display chain which can be
1324 evaluated in the current scope. */
1329 register struct display
*d
;
1331 for (d
= display_chain
; d
; d
= d
->next
)
1335 /* Delete the auto-display which we were in the process of displaying.
1336 This is done when there is an error or a signal. */
1339 disable_display (num
)
1342 register struct display
*d
;
1344 for (d
= display_chain
; d
; d
= d
->next
)
1345 if (d
->number
== num
)
1347 d
->status
= disabled
;
1350 printf ("No display number %d.\n", num
);
1354 disable_current_display ()
1356 if (current_display_number
>= 0)
1358 disable_display (current_display_number
);
1359 fprintf (stderr
, "Disabling display %d to avoid infinite recursion.\n",
1360 current_display_number
);
1362 current_display_number
= -1;
1368 register struct display
*d
;
1371 printf ("There are no auto-display expressions now.\n");
1373 printf_filtered ("Auto-display expressions now in effect:\n\
1374 Num Enb Expression\n");
1376 for (d
= display_chain
; d
; d
= d
->next
)
1378 printf_filtered ("%d: %c ", d
->number
, "ny"[(int)d
->status
]);
1380 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1382 else if (d
->format
.format
)
1383 printf_filtered ("/%c ", d
->format
.format
);
1384 print_expression (d
->exp
, stdout
);
1385 if (d
->block
&& !contained_in (get_selected_block (), d
->block
))
1386 printf_filtered (" (cannot be evaluated in the current context)");
1387 printf_filtered ("\n");
1393 enable_display (args
)
1396 register char *p
= args
;
1399 register struct display
*d
;
1403 for (d
= display_chain
; d
; d
= d
->next
)
1404 d
->status
= enabled
;
1410 while (*p1
>= '0' && *p1
<= '9')
1412 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1413 error ("Arguments must be display numbers.");
1417 for (d
= display_chain
; d
; d
= d
->next
)
1418 if (d
->number
== num
)
1420 d
->status
= enabled
;
1423 printf ("No display number %d.\n", num
);
1426 while (*p
== ' ' || *p
== '\t')
1433 disable_display_command (args
, from_tty
)
1437 register char *p
= args
;
1439 register struct display
*d
;
1443 for (d
= display_chain
; d
; d
= d
->next
)
1444 d
->status
= disabled
;
1450 while (*p1
>= '0' && *p1
<= '9')
1452 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1453 error ("Arguments must be display numbers.");
1455 disable_display (atoi (p
));
1458 while (*p
== ' ' || *p
== '\t')
1464 /* Print the value in stack frame FRAME of a variable
1465 specified by a struct symbol. */
1468 print_variable_value (var
, frame
, stream
)
1473 value val
= read_var_value (var
, frame
);
1474 value_print (val
, stream
, 0, Val_pretty_default
);
1477 /* Print the arguments of a stack frame, given the function FUNC
1478 running in that frame (as a symbol), the info on the frame,
1479 and the number of args according to the stack frame (or -1 if unknown). */
1481 /* References here and elsewhere to "number of args according to the
1482 stack frame" appear in all cases to refer to "number of ints of args
1483 according to the stack frame". At least for VAX, i386, isi. */
1486 print_frame_args (func
, fi
, num
, stream
)
1487 struct symbol
*func
;
1488 struct frame_info
*fi
;
1496 register struct symbol
*sym
;
1498 /* Offset of next stack argument beyond the one we have seen that is
1499 at the highest offset.
1500 -1 if we haven't come to a stack argument yet. */
1501 long highest_offset
= -1;
1503 /* Number of ints of arguments that we have printed so far. */
1504 int args_printed
= 0;
1508 b
= SYMBOL_BLOCK_VALUE (func
);
1509 nsyms
= BLOCK_NSYMS (b
);
1512 for (i
= 0; i
< nsyms
; i
++)
1515 sym
= BLOCK_SYM (b
, i
);
1517 /* Keep track of the highest stack argument offset seen, and
1518 skip over any kinds of symbols we don't care about. */
1520 switch (SYMBOL_CLASS (sym
)) {
1524 long current_offset
= SYMBOL_VALUE (sym
);
1526 arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
1528 /* Compute address of next argument by adding the size of
1529 this argument and rounding to an int boundary. */
1531 = ((current_offset
+ arg_size
+ sizeof (int) - 1)
1532 & ~(sizeof (int) - 1));
1534 /* If this is the highest offset seen yet, set highest_offset. */
1535 if (highest_offset
== -1
1536 || (current_offset
> highest_offset
))
1537 highest_offset
= current_offset
;
1539 /* Add the number of ints we're about to print to args_printed. */
1540 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
1543 /* We care about types of symbols, but don't need to keep track of
1544 stack offsets in them. */
1549 /* Other types of symbols we just skip over. */
1554 /* We have to re-look-up the symbol because arguments often have
1555 two entries (one a parameter, one a register or local), and the one
1556 we want is the non-parm, which lookup_symbol will find for
1557 us. After this, sym could be any SYMBOL_CLASS... */
1559 /* AIX/RS6000 implements a concept of traceback tables, in which case
1560 it creates nameless parameters. Looking for those parameter symbols
1561 will result in an error. */
1563 if ( *SYMBOL_NAME (sym
))
1565 sym
= lookup_symbol (SYMBOL_NAME (sym
),
1566 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
1568 /* Print the current arg. */
1570 fprintf_filtered (stream
, ", ");
1572 fprint_symbol (stream
, SYMBOL_NAME (sym
));
1573 fputs_filtered ("=", stream
);
1575 /* Avoid value_print because it will deref ref parameters. We just
1576 want to print their addresses. Print ??? for args whose address
1577 we do not know. We pass 2 as "recurse" to val_print because our
1578 standard indentation here is 4 spaces, and val_print indents
1579 2 for each recurse. */
1580 val
= read_var_value (sym
, FRAME_INFO_ID (fi
));
1582 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), VALUE_ADDRESS (val
),
1583 stream
, 0, 0, 2, Val_no_prettyprint
);
1585 fputs_filtered ("???", stream
);
1589 /* Don't print nameless args in situations where we don't know
1590 enough about the stack to find them. */
1596 if (highest_offset
== -1)
1597 start
= FRAME_ARGS_SKIP
;
1599 start
= highest_offset
;
1601 addr
= FRAME_ARGS_ADDRESS (fi
);
1603 print_frame_nameless_args (addr
, start
, num
- args_printed
,
1608 /* Print nameless args on STREAM.
1609 ARGSADDR is the address of the arglist, START is the offset
1610 of the first nameless arg, and NUM is the number of nameless args to
1611 print. FIRST is nonzero if this is the first argument (not just
1612 the first nameless arg). */
1614 print_frame_nameless_args (argsaddr
, start
, num
, first
, stream
)
1622 for (i
= 0; i
< num
; i
++)
1626 fprintf_filtered (stream
, ", ");
1627 #ifndef PRINT_TYPELESS_INTEGER
1628 fprintf_filtered (stream
, "%d",
1629 read_memory_integer (argsaddr
+ start
, sizeof (int)));
1631 PRINT_TYPELESS_INTEGER (stream
, builtin_type_int
,
1633 read_memory_integer (argsaddr
+ start
,
1637 start
+= sizeof (int);
1643 printf_command (arg
, from_tty
)
1648 register char *s
= arg
;
1652 int allocated_args
= 20;
1655 val_args
= (value
*) xmalloc (allocated_args
* sizeof (value
));
1658 error_no_arg ("format-control string and values to print");
1660 /* Skip white space before format string */
1661 while (*s
== ' ' || *s
== '\t') s
++;
1663 /* A format string should follow, enveloped in double quotes */
1665 error ("Bad format string, missing '\"'.");
1667 /* Parse the format-control string and copy it into the string STRING,
1668 processing some kinds of escape sequence. */
1670 f
= string
= (char *) alloca (strlen (s
) + 1);
1677 error ("Bad format string, non-terminated '\"'.");
1678 /* doesn't return */
1699 /* ??? TODO: handle other escape sequences */
1700 error ("Unrecognized \\ escape character in format string.");
1709 /* Skip over " and following space and comma. */
1712 while (*s
== ' ' || *s
== '\t') s
++;
1714 if (*s
!= ',' && *s
!= 0)
1715 error ("Invalid argument syntax");
1718 while (*s
== ' ' || *s
== '\t') s
++;
1721 /* Now scan the string for %-specs and see what kinds of args they want.
1722 argclass[I] classifies the %-specs so we can give vprintf something
1723 of the right size. */
1725 enum argclass
{int_arg
, string_arg
, double_arg
, long_long_arg
};
1726 enum argclass
*argclass
;
1732 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1739 while (strchr ("0123456789.hlL-+ #", *f
))
1741 if (*f
== 'l' || *f
== 'L')
1746 argclass
[nargs_wanted
++] = string_arg
;
1747 else if (*f
== 'e' || *f
== 'f' || *f
== 'g')
1748 argclass
[nargs_wanted
++] = double_arg
;
1749 else if (lcount
> 1)
1750 argclass
[nargs_wanted
++] = long_long_arg
;
1752 argclass
[nargs_wanted
++] = int_arg
;
1756 /* Now, parse all arguments and evaluate them.
1757 Store the VALUEs in VAL_ARGS. */
1762 if (nargs
== allocated_args
)
1763 val_args
= (value
*) xrealloc ((char *) val_args
,
1764 (allocated_args
*= 2)
1767 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
1769 /* If format string wants a float, unchecked-convert the value to
1770 floating point of the same size */
1772 if (argclass
[nargs
] == double_arg
)
1774 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (float))
1775 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
1776 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (double))
1777 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
1785 if (nargs
!= nargs_wanted
)
1786 error ("Wrong number of arguments for specified format-string");
1788 /* Now lay out an argument-list containing the arguments
1789 as doubles, integers and C pointers. */
1791 arg_bytes
= (char *) alloca (sizeof (double) * nargs
);
1793 for (i
= 0; i
< nargs
; i
++)
1795 if (argclass
[i
] == string_arg
)
1800 tem
= value_as_pointer (val_args
[i
]);
1802 /* This is a %s argument. Find the length of the string. */
1807 read_memory (tem
+ j
, &c
, 1);
1812 /* Copy the string contents into a string inside GDB. */
1813 str
= (char *) alloca (j
+ 1);
1814 read_memory (tem
, str
, j
);
1817 /* Pass address of internal copy as the arg to vprintf. */
1818 *((int *) &arg_bytes
[argindex
]) = (int) str
;
1819 argindex
+= sizeof (int);
1821 else if (VALUE_TYPE (val_args
[i
])->code
== TYPE_CODE_FLT
)
1823 *((double *) &arg_bytes
[argindex
]) = value_as_double (val_args
[i
]);
1824 argindex
+= sizeof (double);
1828 if (argclass
[i
] == long_long_arg
)
1830 *(long long *) &arg_bytes
[argindex
] = value_as_long (val_args
[i
]);
1831 argindex
+= sizeof (long long);
1836 *((long *) &arg_bytes
[argindex
]) = value_as_long (val_args
[i
]);
1837 argindex
+= sizeof (long);
1842 /* There is not a standard way to make a va_list, so we need
1843 to do various things for different systems. */
1844 #if defined (__INT_VARARGS_H)
1849 list
.__va_stk
= (int *) arg_bytes
;
1850 list
.__va_reg
= (int *) arg_bytes
;
1851 vprintf (string
, list
);
1853 #else /* No __INT_VARARGS_H. */
1854 vprintf (string
, arg_bytes
);
1855 #endif /* No __INT_VARARGS_H. */
1858 /* Helper function for asdump_command. Finds the bounds of a function
1859 for a specified section of text. PC is an address within the
1860 function which you want bounds for; *LOW and *HIGH are set to the
1861 beginning (inclusive) and end (exclusive) of the function. This
1862 function returns 1 on success and 0 on failure. */
1865 containing_function_bounds (pc
, low
, high
)
1866 CORE_ADDR pc
, *low
, *high
;
1870 if (!find_pc_partial_function (pc
, 0, low
))
1876 if (!find_pc_partial_function (scan
, 0, high
))
1878 } while (*low
== *high
);
1883 /* Dump a specified section of assembly code. With no command line
1884 arguments, this command will dump the assembly code for the
1885 function surrounding the pc value in the selected frame. With one
1886 argument, it will dump the assembly code surrounding that pc value.
1887 Two arguments are interpeted as bounds within which to dump
1892 disassemble_command (arg
, from_tty
)
1896 CORE_ADDR low
, high
;
1902 if (!selected_frame
)
1903 error ("No frame selected.\n");
1905 pc
= get_frame_pc (selected_frame
);
1906 if (!containing_function_bounds (pc
, &low
, &high
))
1907 error ("No function contains pc specified by selected frame.\n");
1909 else if (!(space_index
= (char *) strchr (arg
, ' ')))
1912 pc
= parse_and_eval_address (arg
);
1913 if (!containing_function_bounds (pc
, &low
, &high
))
1914 error ("No function contains specified pc.\n");
1918 /* Two arguments. */
1919 *space_index
= '\0';
1920 low
= parse_and_eval_address (arg
);
1921 high
= parse_and_eval_address (space_index
+ 1);
1924 printf_filtered ("Dump of assembler code ");
1928 find_pc_partial_function (pc
, &name
, 0);
1929 printf_filtered ("for function %s:\n", name
);
1932 printf_filtered ("from %s ", local_hex_string(low
));
1933 printf_filtered ("to %s:\n", local_hex_string(high
));
1935 /* Dump the specified range. */
1936 for (pc
= low
; pc
< high
; )
1939 print_address (pc
, stdout
);
1940 printf_filtered (":\t");
1941 pc
+= print_insn (pc
, stdout
);
1942 printf_filtered ("\n");
1944 printf_filtered ("End of assembler dump.\n");
1950 _initialize_printcmd ()
1952 current_display_number
= -1;
1954 add_info ("address", address_info
,
1955 "Describe where variable VAR is stored.");
1957 add_com ("x", class_vars
, x_command
,
1958 "Examine memory: x/FMT ADDRESS.\n\
1959 ADDRESS is an expression for the memory address to examine.\n\
1960 FMT is a repeat count followed by a format letter and a size letter.\n\
1961 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1962 f(float), a(address), i(instruction), c(char) and s(string).\n\
1963 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1964 g is meaningful only with f, for type double.\n\
1965 The specified number of objects of the specified size are printed\n\
1966 according to the format.\n\n\
1967 Defaults for format and size letters are those previously used.\n\
1968 Default count is 1. Default address is following last thing printed\n\
1969 with this command or \"print\".");
1971 add_com ("disassemble", class_vars
, disassemble_command
,
1972 "Disassemble a specified section of memory.\n\
1973 Default is the function surrounding the pc of the selected frame.\n\
1974 With a single argument, the function surrounding that address is dumped.\n\
1975 Two arguments are taken as a range of memory to dump.");
1977 add_com ("ptype", class_vars
, ptype_command
,
1978 "Print definition of type TYPE.\n\
1979 Argument may be a type name defined by typedef, or \"struct STRUCTNAME\"\n\
1980 or \"union UNIONNAME\" or \"enum ENUMNAME\".\n\
1981 The selected stack frame's lexical context is used to look up the name.");
1983 add_com ("whatis", class_vars
, whatis_command
,
1984 "Print data type of expression EXP.");
1987 add_com ("whereis", class_vars
, whereis_command
,
1988 "Print line number and file of definition of variable.");
1991 add_info ("display", display_info
,
1992 "Expressions to display when program stops, with code numbers.");
1994 add_cmd ("undisplay", class_vars
, undisplay_command
,
1995 "Cancel some expressions to be displayed when program stops.\n\
1996 Arguments are the code numbers of the expressions to stop displaying.\n\
1997 No argument means cancel all automatic-display expressions.\n\
1998 \"delete display\" has the same effect as this command.\n\
1999 Do \"info display\" to see current list of code numbers.",
2002 add_com ("display", class_vars
, display_command
,
2003 "Print value of expression EXP each time the program stops.\n\
2004 /FMT may be used before EXP as in the \"print\" command.\n\
2005 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2006 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2007 and examining is done as in the \"x\" command.\n\n\
2008 With no argument, display all currently requested auto-display expressions.\n\
2009 Use \"undisplay\" to cancel display requests previously made.");
2011 add_cmd ("display", class_vars
, enable_display
,
2012 "Enable some expressions to be displayed when program stops.\n\
2013 Arguments are the code numbers of the expressions to resume displaying.\n\
2014 No argument means enable all automatic-display expressions.\n\
2015 Do \"info display\" to see current list of code numbers.", &enablelist
);
2017 add_cmd ("display", class_vars
, disable_display_command
,
2018 "Disable some expressions to be displayed when program stops.\n\
2019 Arguments are the code numbers of the expressions to stop displaying.\n\
2020 No argument means disable all automatic-display expressions.\n\
2021 Do \"info display\" to see current list of code numbers.", &disablelist
);
2023 add_cmd ("display", class_vars
, undisplay_command
,
2024 "Cancel some expressions to be displayed when program stops.\n\
2025 Arguments are the code numbers of the expressions to stop displaying.\n\
2026 No argument means cancel all automatic-display expressions.\n\
2027 Do \"info display\" to see current list of code numbers.", &deletelist
);
2029 add_com ("printf", class_vars
, printf_command
,
2030 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2031 This is useful for formatted output in user-defined commands.");
2032 add_com ("output", class_vars
, output_command
,
2033 "Like \"print\" but don't put in value history and don't print newline.\n\
2034 This is useful in user-defined commands.");
2036 add_prefix_cmd ("set", class_vars
, set_command
,
2037 "Perform an assignment VAR = EXP.\n\
2038 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
2039 (names starting with $), a register (a few standard names starting with $),\n\
2040 or an actual variable in the program being debugged. EXP is any expression.\n\
2041 Use \"set variable\" for variables with names identical to set subcommands.\n\
2042 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2043 You can see these environment settings with the \"show\" command.",
2044 &setlist
, "set ", 1, &cmdlist
);
2046 /* "call" is the same as "set", but handy for dbx users to call fns. */
2047 add_com ("call", class_vars
, call_command
,
2048 "Call a function in the inferior process.\n\
2049 The argument is the function name and arguments, in the notation of the\n\
2050 current working language. The result is printed and saved in the value\n\
2051 history, if it is not void.");
2053 add_cmd ("variable", class_vars
, set_command
,
2054 "Perform an assignment VAR = EXP.\n\
2055 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
2056 (names starting with $), a register (a few standard names starting with $),\n\
2057 or an actual variable in the program being debugged. EXP is any expression.\n\
2058 This may usually be abbreviated to simply \"set\".",
2061 add_com ("print", class_vars
, print_command
,
2062 concat ("Print value of expression EXP.\n\
2063 Variables accessible are those of the lexical environment of the selected\n\
2064 stack frame, plus all those whose scope is global or an entire file.\n\
2066 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2067 $$NUM refers to NUM'th value back from the last one.\n\
2068 Names starting with $ refer to registers (with the values they would have\n\
2069 if the program were to return to the stack frame now selected, restoring\n\
2070 all registers saved by frames farther in) or else to debugger\n\
2071 \"convenience\" variables (any such name not a known register).\n\
2072 Use assignment expressions to give values to convenience variables.\n",
2074 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2075 @ is a binary operator for treating consecutive data objects\n\
2076 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2077 element is FOO, whose second element is stored in the space following\n\
2078 where FOO is stored, etc. FOO must be an expression whose value\n\
2079 resides in memory.\n",
2081 EXP may be preceded with /FMT, where FMT is a format letter\n\
2082 but no count or size letter (see \"x\" command).", NULL
));
2083 add_com_alias ("p", "print", class_vars
, 1);
2085 add_com ("inspect", class_vars
, inspect_command
,
2086 "Same as \"print\" command, except that if you are running in the epoch\n\
2087 environment, the value is printed in its own window.");