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"
33 extern int asm_demangle
; /* Whether to demangle syms in asm printouts */
34 extern int addressprint
; /* Whether to print hex addresses in HLL " */
43 /* Last specified output format. */
45 static char last_format
= 'x';
47 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
49 static char last_size
= 'w';
51 /* Default address to examine next. */
53 static CORE_ADDR next_address
;
55 /* Last address examined. */
57 static CORE_ADDR last_examine_address
;
59 /* Contents of last address examined.
60 This is not valid past the end of the `x' command! */
62 static value last_examine_value
;
64 /* Number of auto-display expression currently being displayed.
65 So that we can deleted it if we get an error or a signal within it.
66 -1 when not doing one. */
68 int current_display_number
;
70 /* Flag to low-level print routines that this value is being printed
71 in an epoch window. We'd like to pass this as a parameter, but
72 every routine would need to take it. Perhaps we can encapsulate
73 this in the I/O stream once we have GNU stdio. */
79 /* Chain link to next auto-display item. */
81 /* Expression to be evaluated and displayed. */
82 struct expression
*exp
;
83 /* Item number of this auto-display item. */
85 /* Display format specified. */
86 struct format_data format
;
87 /* Innermost block required by this expression when evaluated */
89 /* Status of this display (enabled or disabled) */
93 /* Chain of expressions whose values should be displayed
94 automatically each time the program stops. */
96 static struct display
*display_chain
;
98 static int display_number
;
100 /* Prototypes for local functions */
103 delete_display
PARAMS ((int));
106 enable_display
PARAMS ((char *));
109 disable_display_command
PARAMS ((char *, int));
112 disassemble_command
PARAMS ((char *, int));
115 containing_function_bounds
PARAMS ((CORE_ADDR
, CORE_ADDR
*, CORE_ADDR
*));
118 printf_command
PARAMS ((char *, int));
121 print_frame_nameless_args
PARAMS ((CORE_ADDR
, long, int, int, FILE *));
124 display_info
PARAMS ((void));
127 do_one_display
PARAMS ((struct display
*));
130 undisplay_command
PARAMS ((char *));
133 free_display
PARAMS ((struct display
*));
136 display_command
PARAMS ((char *, int));
139 ptype_command
PARAMS ((char *, int));
142 ptype_eval
PARAMS ((struct expression
*));
145 whatis_command
PARAMS ((char *, int));
148 whatis_exp
PARAMS ((char *, int));
151 x_command
PARAMS ((char *, int));
154 address_info
PARAMS ((char *, int));
157 set_command
PARAMS ((char *, int));
160 output_command
PARAMS ((char *, int));
163 call_command
PARAMS ((char *, int));
166 inspect_command
PARAMS ((char *, int));
169 print_command
PARAMS ((char *, int));
172 print_command_1
PARAMS ((char *, int, int));
175 validate_format
PARAMS ((struct format_data
, char *));
178 do_examine
PARAMS ((struct format_data
, CORE_ADDR
));
181 print_formatted
PARAMS ((value
, int, int));
183 static struct format_data
184 decode_format
PARAMS ((char **, int, int));
187 /* Decode a format specification. *STRING_PTR should point to it.
188 OFORMAT and OSIZE are used as defaults for the format and size
189 if none are given in the format specification.
190 If OSIZE is zero, then the size field of the returned value
191 should be set only if a size is explicitly specified by the
193 The structure returned describes all the data
194 found in the specification. In addition, *STRING_PTR is advanced
195 past the specification and past all whitespace following it. */
197 static struct format_data
198 decode_format (string_ptr
, oformat
, osize
)
203 struct format_data val
;
204 register char *p
= *string_ptr
;
210 if (*p
>= '0' && *p
<= '9')
211 val
.count
= atoi (p
);
212 while (*p
>= '0' && *p
<= '9') p
++;
214 /* Now process size or format letters that follow. */
218 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
227 else if (*p
>= 'a' && *p
<= 'z')
234 /* Make sure 'g' size is not used on integer types.
235 Well, actually, we can handle hex. */
236 if (val
.size
== 'g' && val
.format
!= 'f' && val
.format
!= 'x')
240 while (*p
== ' ' || *p
== '\t') p
++;
243 /* Set defaults for format and size if not specified. */
244 if (val
.format
== '?')
248 /* Neither has been specified. */
249 val
.format
= oformat
;
253 /* If a size is specified, any format makes a reasonable
254 default except 'i'. */
255 val
.format
= oformat
== 'i' ? 'x' : oformat
;
257 else if (val
.size
== '?')
262 /* Addresses must be words. */
263 val
.size
= osize
? 'w' : osize
;
266 /* Floating point has to be word or giantword. */
267 if (osize
== 'w' || osize
== 'g')
270 /* Default it to giantword if the last used size is not
272 val
.size
= osize
? 'g' : osize
;
275 /* Characters default to one byte. */
276 val
.size
= osize
? 'b' : osize
;
279 /* The default is the size most recently specified. */
286 /* Print value VAL on stdout according to FORMAT, a letter or 0.
287 Do not end with a newline.
288 0 means print VAL according to its own type.
289 SIZE is the letter for the size of datum being printed.
290 This is used to pad hex numbers so they line up. */
293 print_formatted (val
, format
, size
)
298 int len
= TYPE_LENGTH (VALUE_TYPE (val
));
300 if (VALUE_LVAL (val
) == lval_memory
)
301 next_address
= VALUE_ADDRESS (val
) + len
;
306 next_address
= VALUE_ADDRESS (val
)
307 + value_print (value_addr (val
), stdout
, format
, Val_pretty_default
);
311 wrap_here (""); /* Force output out, print_insn not using _filtered */
312 next_address
= VALUE_ADDRESS (val
)
313 + print_insn (VALUE_ADDRESS (val
), stdout
);
318 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_ARRAY
319 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_STRUCT
320 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_UNION
321 || VALUE_REPEATED (val
))
322 value_print (val
, stdout
, format
, Val_pretty_default
);
324 print_scalar_formatted (VALUE_CONTENTS (val
), VALUE_TYPE (val
),
325 format
, size
, stdout
);
329 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
330 according to letters FORMAT and SIZE on STREAM.
331 FORMAT may not be zero. Formats s and i are not supported at this level.
333 This is how the elements of an array or structure are printed
337 print_scalar_formatted (valaddr
, type
, format
, size
, stream
)
345 int len
= TYPE_LENGTH (type
);
347 if (size
== 'g' && sizeof (LONGEST
) < 8
350 /* ok, we're going to have to get fancy here. Assumption: a
351 long is four bytes. FIXME. */
352 unsigned long v1
, v2
;
354 v1
= unpack_long (builtin_type_long
, valaddr
);
355 v2
= unpack_long (builtin_type_long
, valaddr
+ 4);
357 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
358 /* Swap the two for printing */
371 fprintf_filtered (stream
, local_hex_format_custom("08x%08"), v1
, v2
);
374 error ("Output size \"g\" unimplemented for format \"%c\".",
380 val_long
= unpack_long (type
, valaddr
);
382 /* If value is unsigned, truncate it in case negative. */
385 if (len
== sizeof (char))
386 val_long
&= (1 << 8 * sizeof(char)) - 1;
387 else if (len
== sizeof (short))
388 val_long
&= (1 << 8 * sizeof(short)) - 1;
389 else if (len
== sizeof (long))
390 val_long
&= (unsigned long) - 1;
398 /* no size specified, like in print. Print varying # of digits. */
399 #if defined (LONG_LONG)
400 fprintf_filtered (stream
, local_hex_format_custom("ll"), val_long
);
401 #else /* not LONG_LONG. */
402 fprintf_filtered (stream
, local_hex_format_custom("l"), val_long
);
403 #endif /* not LONG_LONG. */
406 #if defined (LONG_LONG)
410 fprintf_filtered (stream
, local_hex_format_custom("02ll"), val_long
);
413 fprintf_filtered (stream
, local_hex_format_custom("04ll"), val_long
);
416 fprintf_filtered (stream
, local_hex_format_custom("08ll"), val_long
);
419 fprintf_filtered (stream
, local_hex_format_custom("016ll"), val_long
);
422 error ("Undefined output size \"%c\".", size
);
424 #else /* not LONG_LONG. */
428 fprintf_filtered (stream
, local_hex_format_custom("02"), val_long
);
431 fprintf_filtered (stream
, local_hex_format_custom("04"), val_long
);
434 fprintf_filtered (stream
, local_hex_format_custom("08"), val_long
);
437 fprintf_filtered (stream
, local_hex_format_custom("016"), val_long
);
440 error ("Undefined output size \"%c\".", size
);
442 #endif /* not LONG_LONG */
447 fprintf_filtered (stream
, "%lld", val_long
);
449 fprintf_filtered (stream
, "%d", val_long
);
455 fprintf_filtered (stream
, "%llu", val_long
);
457 fprintf_filtered (stream
, "%u", val_long
);
464 fprintf_filtered (stream
, local_octal_format_custom("ll"), val_long
);
466 fprintf_filtered (stream
, local_octal_format(), val_long
);
469 fprintf_filtered (stream
, "0");
473 print_address (unpack_pointer (type
, valaddr
), stream
);
477 value_print (value_from_longest (builtin_type_char
, val_long
), stream
, 0,
482 if (len
== sizeof (float))
483 type
= builtin_type_float
;
484 else if (len
== sizeof (double))
485 type
= builtin_type_double
;
486 print_floating (valaddr
, type
, stream
);
493 /* Binary; 't' stands for "two". */
495 char bits
[8*(sizeof val_long
) + 1];
500 width
= 8*(sizeof val_long
);
517 error ("Undefined output size \"%c\".", size
);
523 bits
[width
] = (val_long
& 1) ? '1' : '0';
528 while (*cp
&& *cp
== '0')
533 fprintf_filtered (stream
, cp
);
538 error ("Undefined output format \"%c\".", format
);
542 /* Specify default address for `x' command.
543 `info lines' uses this. */
546 set_next_address (addr
)
551 /* Make address available to the user as $_. */
552 set_internalvar (lookup_internalvar ("_"),
553 value_from_longest (lookup_pointer_type (builtin_type_void
),
557 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
558 after LEADIN. Print nothing if no symbolic name is found nearby.
559 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
560 or to interpret it as a possible C++ name and convert it back to source
564 print_address_symbolic (addr
, stream
, do_demangle
, leadin
)
571 register struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (addr
);
573 /* If nothing comes out, don't print anything symbolic. */
578 fputs_filtered (leadin
, stream
);
579 fputs_filtered ("<", stream
);
581 fputs_demangled (msymbol
-> name
, stream
, 1);
583 fputs_filtered (msymbol
-> name
, stream
);
584 name_location
= msymbol
-> address
;
585 if (addr
- name_location
)
586 fprintf_filtered (stream
, "+%d>", addr
- name_location
);
588 fputs_filtered (">", stream
);
591 /* Print address ADDR symbolically on STREAM.
592 First print it as a number. Then perhaps print
593 <SYMBOL + OFFSET> after the number. */
596 print_address (addr
, stream
)
600 #ifdef ADDR_BITS_REMOVE
601 fprintf_filtered (stream
, local_hex_format(), ADDR_BITS_REMOVE(addr
));
603 fprintf_filtered (stream
, local_hex_format(), addr
);
605 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
608 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
609 controls whether to print the symbolic name "raw" or demangled.
610 Global setting "addressprint" controls whether to print hex address
614 print_address_demangle (addr
, stream
, do_demangle
)
620 fprintf_filtered (stream
, "0");
621 } else if (addressprint
) {
622 fprintf_filtered (stream
, local_hex_format(), addr
);
623 print_address_symbolic (addr
, stream
, do_demangle
, " ");
625 print_address_symbolic (addr
, stream
, do_demangle
, "");
630 /* Examine data at address ADDR in format FMT.
631 Fetch it from memory and print on stdout. */
634 do_examine (fmt
, addr
)
635 struct format_data fmt
;
638 register char format
= 0;
640 register int count
= 1;
641 struct type
*val_type
;
643 register int maxelts
;
650 /* String or instruction format implies fetch single bytes
651 regardless of the specified size. */
652 if (format
== 's' || format
== 'i')
656 val_type
= builtin_type_char
;
657 else if (size
== 'h')
658 val_type
= builtin_type_short
;
659 else if (size
== 'w')
660 val_type
= builtin_type_long
;
661 else if (size
== 'g')
663 val_type
= builtin_type_double
;
665 val_type
= builtin_type_long_long
;
673 if (format
== 's' || format
== 'i')
676 /* Print as many objects as specified in COUNT, at most maxelts per line,
677 with the address of the next one at the start of each line. */
681 print_address (next_address
, stdout
);
682 printf_filtered (":");
687 printf_filtered ("\t");
688 /* Note that print_formatted sets next_address for the next
690 last_examine_address
= next_address
;
691 last_examine_value
= value_at (val_type
, next_address
);
692 print_formatted (last_examine_value
, format
, size
);
694 printf_filtered ("\n");
700 validate_format (fmt
, cmdname
)
701 struct format_data fmt
;
705 error ("Size letters are meaningless in \"%s\" command.", cmdname
);
707 error ("Item count other than 1 is meaningless in \"%s\" command.",
709 if (fmt
.format
== 'i' || fmt
.format
== 's')
710 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
711 fmt
.format
, cmdname
);
715 print_command_1 (exp
, inspect
, voidprint
)
720 struct expression
*expr
;
721 register struct cleanup
*old_chain
= 0;
722 register char format
= 0;
724 struct format_data fmt
;
727 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
728 inspect_it
= inspect
;
730 if (exp
&& *exp
== '/')
733 fmt
= decode_format (&exp
, last_format
, 0);
734 validate_format (fmt
, "print");
735 last_format
= format
= fmt
.format
;
746 extern int objectprint
;
748 expr
= parse_expression (exp
);
749 old_chain
= make_cleanup (free_current_contents
, &expr
);
751 val
= evaluate_expression (expr
);
753 /* C++: figure out what type we actually want to print it as. */
754 type
= VALUE_TYPE (val
);
757 && ( TYPE_CODE (type
) == TYPE_CODE_PTR
758 || TYPE_CODE (type
) == TYPE_CODE_REF
)
759 && ( TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
760 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_UNION
))
764 v
= value_from_vtable_info (val
, TYPE_TARGET_TYPE (type
));
768 type
= VALUE_TYPE (val
);
773 val
= access_value_history (0);
775 if (voidprint
|| (val
&& VALUE_TYPE (val
) &&
776 TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_VOID
))
778 int histindex
= record_latest_value (val
);
781 printf ("\031(gdb-makebuffer \"%s\" %d '(\"", exp
, histindex
);
783 if (histindex
>= 0) printf_filtered ("$%d = ", histindex
);
785 print_formatted (val
, format
, fmt
.size
);
786 printf_filtered ("\n");
792 do_cleanups (old_chain
);
793 inspect_it
= 0; /* Reset print routines to normal */
798 print_command (exp
, from_tty
)
802 print_command_1 (exp
, 0, 1);
805 /* Same as print, except in epoch, it gets its own window */
808 inspect_command (exp
, from_tty
)
812 extern int epoch_interface
;
814 print_command_1 (exp
, epoch_interface
, 1);
817 /* Same as print, except it doesn't print void results. */
820 call_command (exp
, from_tty
)
824 print_command_1 (exp
, 0, 0);
829 output_command (exp
, from_tty
)
833 struct expression
*expr
;
834 register struct cleanup
*old_chain
;
835 register char format
= 0;
837 struct format_data fmt
;
839 if (exp
&& *exp
== '/')
842 fmt
= decode_format (&exp
, 0, 0);
843 validate_format (fmt
, "print");
847 expr
= parse_expression (exp
);
848 old_chain
= make_cleanup (free_current_contents
, &expr
);
850 val
= evaluate_expression (expr
);
852 print_formatted (val
, format
, fmt
.size
);
854 do_cleanups (old_chain
);
859 set_command (exp
, from_tty
)
863 struct expression
*expr
= parse_expression (exp
);
864 register struct cleanup
*old_chain
865 = make_cleanup (free_current_contents
, &expr
);
866 evaluate_expression (expr
);
867 do_cleanups (old_chain
);
872 address_info (exp
, from_tty
)
876 register struct symbol
*sym
;
877 register struct minimal_symbol
*msymbol
;
879 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
880 if exp is a field of `this'. */
883 error ("Argument required.");
885 sym
= lookup_symbol (exp
, get_selected_block (), VAR_NAMESPACE
,
886 &is_a_field_of_this
, (struct symtab
**)NULL
);
889 if (is_a_field_of_this
)
891 printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp
);
895 msymbol
= lookup_minimal_symbol (exp
, (struct objfile
*) NULL
);
898 printf ("Symbol \"%s\" is at %s in a file compiled without debugging.\n",
899 exp
, local_hex_string(msymbol
-> address
));
901 error ("No symbol \"%s\" in current context.", exp
);
905 printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym
));
906 val
= SYMBOL_VALUE (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 printf ("an argument at offset %ld", val
);
936 printf ("an argument at frame offset %ld", val
);
940 printf ("a local variable at frame offset %ld", val
);
944 printf ("a reference argument at offset %ld", val
);
948 printf ("a typedef");
952 printf ("a function at address %s",
953 local_hex_string(BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
957 printf ("of unknown (botched) type");
964 x_command (exp
, from_tty
)
968 struct expression
*expr
;
969 struct format_data fmt
;
970 struct cleanup
*old_chain
;
973 fmt
.format
= last_format
;
974 fmt
.size
= last_size
;
977 if (exp
&& *exp
== '/')
980 fmt
= decode_format (&exp
, last_format
, last_size
);
981 last_size
= fmt
.size
;
982 last_format
= fmt
.format
;
985 /* If we have an expression, evaluate it and use it as the address. */
987 if (exp
!= 0 && *exp
!= 0)
989 expr
= parse_expression (exp
);
990 /* Cause expression not to be there any more
991 if this command is repeated with Newline.
992 But don't clobber a user-defined command's definition. */
995 old_chain
= make_cleanup (free_current_contents
, &expr
);
996 val
= evaluate_expression (expr
);
997 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_REF
)
998 val
= value_ind (val
);
999 /* In rvalue contexts, such as this, functions are coerced into
1000 pointers to functions. This makes "x/i main" work. */
1001 if (/* last_format == 'i'
1002 && */ TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FUNC
1003 && VALUE_LVAL (val
) == lval_memory
)
1004 next_address
= VALUE_ADDRESS (val
);
1006 next_address
= value_as_pointer (val
);
1007 do_cleanups (old_chain
);
1010 do_examine (fmt
, next_address
);
1012 /* Set a couple of internal variables if appropriate. */
1013 if (last_examine_value
)
1015 /* Make last address examined available to the user as $_. Use
1016 the correct pointer type. */
1017 set_internalvar (lookup_internalvar ("_"),
1018 value_from_longest (
1019 lookup_pointer_type (VALUE_TYPE (last_examine_value
)),
1020 (LONGEST
) last_examine_address
));
1022 /* Make contents of last address examined available to the user as $__.*/
1023 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1027 /* Commands for printing types of things. */
1029 /* Print type of EXP, or last thing in value history if EXP == NULL.
1030 show is passed to type_print. */
1032 whatis_exp (exp
, show
)
1036 struct expression
*expr
;
1038 register struct cleanup
*old_chain
;
1042 expr
= parse_expression (exp
);
1043 old_chain
= make_cleanup (free_current_contents
, &expr
);
1044 val
= evaluate_type (expr
);
1047 val
= access_value_history (0);
1049 printf_filtered ("type = ");
1050 type_print (VALUE_TYPE (val
), "", stdout
, show
);
1051 printf_filtered ("\n");
1054 do_cleanups (old_chain
);
1059 whatis_command (exp
, from_tty
)
1063 /* Most of the time users do not want to see all the fields
1064 in a structure. If they do they can use the "ptype" command.
1065 Hence the "-1" below. */
1066 whatis_exp (exp
, -1);
1069 /* Simple subroutine for ptype_command. */
1073 struct expression
*exp
;
1075 if(exp
->elts
[0].opcode
==OP_TYPE
)
1076 return exp
->elts
[1].type
;
1081 /* TYPENAME is either the name of a type, or an expression. */
1084 ptype_command (typename
, from_tty
)
1088 register struct type
*type
;
1089 struct expression
*expr
;
1090 register struct cleanup
*old_chain
;
1094 expr
= parse_expression (typename
);
1095 old_chain
= make_cleanup (free_current_contents
, &expr
);
1096 type
= ptype_eval (expr
);
1100 printf_filtered ("type = ");
1101 type_print (type
, "", stdout
, 1);
1102 printf_filtered ("\n");
1103 do_cleanups (old_chain
);
1107 do_cleanups (old_chain
);
1108 whatis_exp (typename
, 1);
1112 whatis_exp (typename
, 1);
1115 /* Add an expression to the auto-display chain.
1116 Specify the expression. */
1119 display_command (exp
, from_tty
)
1123 struct format_data fmt
;
1124 register struct expression
*expr
;
1125 register struct display
*new;
1136 fmt
= decode_format (&exp
, 0, 0);
1137 if (fmt
.size
&& fmt
.format
== 0)
1139 if (fmt
.format
== 'i' || fmt
.format
== 's')
1149 innermost_block
= 0;
1150 expr
= parse_expression (exp
);
1152 new = (struct display
*) xmalloc (sizeof (struct display
));
1155 new->block
= innermost_block
;
1156 new->next
= display_chain
;
1157 new->number
= ++display_number
;
1159 new->status
= enabled
;
1160 display_chain
= new;
1162 if (from_tty
&& target_has_execution
)
1163 do_one_display (new);
1176 /* Clear out the display_chain.
1177 Done when new symtabs are loaded, since this invalidates
1178 the types stored in many expressions. */
1183 register struct display
*d
;
1185 while (d
= display_chain
)
1188 display_chain
= d
->next
;
1193 /* Delete the auto-display number NUM. */
1196 delete_display (num
)
1199 register struct display
*d1
, *d
;
1202 error ("No display number %d.", num
);
1204 if (display_chain
->number
== num
)
1207 display_chain
= d1
->next
;
1211 for (d
= display_chain
; ; d
= d
->next
)
1214 error ("No display number %d.", num
);
1215 if (d
->next
->number
== num
)
1225 /* Delete some values from the auto-display chain.
1226 Specify the element numbers. */
1229 undisplay_command (args
)
1232 register char *p
= args
;
1238 if (query ("Delete all auto-display expressions? "))
1247 while (*p1
>= '0' && *p1
<= '9') p1
++;
1248 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1249 error ("Arguments must be display numbers.");
1253 delete_display (num
);
1256 while (*p
== ' ' || *p
== '\t') p
++;
1261 /* Display a single auto-display.
1262 Do nothing if the display cannot be printed in the current context,
1263 or if the display is disabled. */
1269 int within_current_scope
;
1271 if (d
->status
== disabled
)
1275 within_current_scope
= contained_in (get_selected_block (), d
->block
);
1277 within_current_scope
= 1;
1278 if (!within_current_scope
)
1281 current_display_number
= d
->number
;
1283 printf_filtered ("%d: ", d
->number
);
1288 printf_filtered ("x/");
1289 if (d
->format
.count
!= 1)
1290 printf_filtered ("%d", d
->format
.count
);
1291 printf_filtered ("%c", d
->format
.format
);
1292 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1293 printf_filtered ("%c", d
->format
.size
);
1294 printf_filtered (" ");
1295 print_expression (d
->exp
, stdout
);
1296 if (d
->format
.count
!= 1)
1297 printf_filtered ("\n");
1299 printf_filtered (" ");
1301 addr
= value_as_pointer (evaluate_expression (d
->exp
));
1302 if (d
->format
.format
== 'i')
1303 addr
= ADDR_BITS_REMOVE (addr
);
1305 do_examine (d
->format
, addr
);
1309 if (d
->format
.format
)
1310 printf_filtered ("/%c ", d
->format
.format
);
1311 print_expression (d
->exp
, stdout
);
1312 printf_filtered (" = ");
1313 print_formatted (evaluate_expression (d
->exp
),
1314 d
->format
.format
, d
->format
.size
);
1315 printf_filtered ("\n");
1319 current_display_number
= -1;
1322 /* Display all of the values on the auto-display chain which can be
1323 evaluated in the current scope. */
1328 register struct display
*d
;
1330 for (d
= display_chain
; d
; d
= d
->next
)
1334 /* Delete the auto-display which we were in the process of displaying.
1335 This is done when there is an error or a signal. */
1338 disable_display (num
)
1341 register struct display
*d
;
1343 for (d
= display_chain
; d
; d
= d
->next
)
1344 if (d
->number
== num
)
1346 d
->status
= disabled
;
1349 printf ("No display number %d.\n", num
);
1353 disable_current_display ()
1355 if (current_display_number
>= 0)
1357 disable_display (current_display_number
);
1358 fprintf (stderr
, "Disabling display %d to avoid infinite recursion.\n",
1359 current_display_number
);
1361 current_display_number
= -1;
1367 register struct display
*d
;
1370 printf ("There are no auto-display expressions now.\n");
1372 printf_filtered ("Auto-display expressions now in effect:\n\
1373 Num Enb Expression\n");
1375 for (d
= display_chain
; d
; d
= d
->next
)
1377 printf_filtered ("%d: %c ", d
->number
, "ny"[(int)d
->status
]);
1379 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1381 else if (d
->format
.format
)
1382 printf_filtered ("/%c ", d
->format
.format
);
1383 print_expression (d
->exp
, stdout
);
1384 if (d
->block
&& !contained_in (get_selected_block (), d
->block
))
1385 printf_filtered (" (cannot be evaluated in the current context)");
1386 printf_filtered ("\n");
1392 enable_display (args
)
1395 register char *p
= args
;
1398 register struct display
*d
;
1402 for (d
= display_chain
; d
; d
= d
->next
)
1403 d
->status
= enabled
;
1409 while (*p1
>= '0' && *p1
<= '9')
1411 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1412 error ("Arguments must be display numbers.");
1416 for (d
= display_chain
; d
; d
= d
->next
)
1417 if (d
->number
== num
)
1419 d
->status
= enabled
;
1422 printf ("No display number %d.\n", num
);
1425 while (*p
== ' ' || *p
== '\t')
1432 disable_display_command (args
, from_tty
)
1436 register char *p
= args
;
1438 register struct display
*d
;
1442 for (d
= display_chain
; d
; d
= d
->next
)
1443 d
->status
= disabled
;
1449 while (*p1
>= '0' && *p1
<= '9')
1451 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1452 error ("Arguments must be display numbers.");
1454 disable_display (atoi (p
));
1457 while (*p
== ' ' || *p
== '\t')
1463 /* Print the value in stack frame FRAME of a variable
1464 specified by a struct symbol. */
1467 print_variable_value (var
, frame
, stream
)
1472 value val
= read_var_value (var
, frame
);
1473 value_print (val
, stream
, 0, Val_pretty_default
);
1476 /* Print the arguments of a stack frame, given the function FUNC
1477 running in that frame (as a symbol), the info on the frame,
1478 and the number of args according to the stack frame (or -1 if unknown). */
1480 /* References here and elsewhere to "number of args according to the
1481 stack frame" appear in all cases to refer to "number of ints of args
1482 according to the stack frame". At least for VAX, i386, isi. */
1485 print_frame_args (func
, fi
, num
, stream
)
1486 struct symbol
*func
;
1487 struct frame_info
*fi
;
1495 register struct symbol
*sym
;
1497 /* Offset of next stack argument beyond the one we have seen that is
1498 at the highest offset.
1499 -1 if we haven't come to a stack argument yet. */
1500 long highest_offset
= -1;
1502 /* Number of ints of arguments that we have printed so far. */
1503 int args_printed
= 0;
1507 b
= SYMBOL_BLOCK_VALUE (func
);
1508 nsyms
= BLOCK_NSYMS (b
);
1511 for (i
= 0; i
< nsyms
; i
++)
1514 sym
= BLOCK_SYM (b
, i
);
1516 /* Keep track of the highest stack argument offset seen, and
1517 skip over any kinds of symbols we don't care about. */
1519 switch (SYMBOL_CLASS (sym
)) {
1523 long current_offset
= SYMBOL_VALUE (sym
);
1525 arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
1527 /* Compute address of next argument by adding the size of
1528 this argument and rounding to an int boundary. */
1530 = ((current_offset
+ arg_size
+ sizeof (int) - 1)
1531 & ~(sizeof (int) - 1));
1533 /* If this is the highest offset seen yet, set highest_offset. */
1534 if (highest_offset
== -1
1535 || (current_offset
> highest_offset
))
1536 highest_offset
= current_offset
;
1538 /* Add the number of ints we're about to print to args_printed. */
1539 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
1542 /* We care about types of symbols, but don't need to keep track of
1543 stack offsets in them. */
1548 /* Other types of symbols we just skip over. */
1553 /* We have to re-look-up the symbol because arguments often have
1554 two entries (one a parameter, one a register or local), and the one
1555 we want is the non-parm, which lookup_symbol will find for
1556 us. After this, sym could be any SYMBOL_CLASS... */
1557 #ifdef IBM6000_TARGET
1558 /* AIX/RS6000 implements a concept of traceback tables, in which case
1559 it creates nameless parameters. Looking for those parameter symbols
1560 will result in an error. */
1562 if ( *SYMBOL_NAME (sym
))
1564 sym
= lookup_symbol (SYMBOL_NAME (sym
),
1565 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
1567 /* Print the current arg. */
1569 fprintf_filtered (stream
, ", ");
1571 fprint_symbol (stream
, SYMBOL_NAME (sym
));
1572 fputs_filtered ("=", stream
);
1574 /* Avoid value_print because it will deref ref parameters. We just
1575 want to print their addresses. Print ??? for args whose address
1576 we do not know. We pass 2 as "recurse" to val_print because our
1577 standard indentation here is 4 spaces, and val_print indents
1578 2 for each recurse. */
1579 val
= read_var_value (sym
, FRAME_INFO_ID (fi
));
1581 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), VALUE_ADDRESS (val
),
1582 stream
, 0, 0, 2, Val_no_prettyprint
);
1584 fputs_filtered ("???", stream
);
1588 /* Don't print nameless args in situations where we don't know
1589 enough about the stack to find them. */
1595 if (highest_offset
== -1)
1596 start
= FRAME_ARGS_SKIP
;
1598 start
= highest_offset
;
1600 addr
= FRAME_ARGS_ADDRESS (fi
);
1602 print_frame_nameless_args (addr
, start
, num
- args_printed
,
1607 /* Print nameless args on STREAM.
1608 ARGSADDR is the address of the arglist, START is the offset
1609 of the first nameless arg, and NUM is the number of nameless args to
1610 print. FIRST is nonzero if this is the first argument (not just
1611 the first nameless arg). */
1613 print_frame_nameless_args (argsaddr
, start
, num
, first
, stream
)
1621 for (i
= 0; i
< num
; i
++)
1625 fprintf_filtered (stream
, ", ");
1626 #ifndef PRINT_TYPELESS_INTEGER
1627 fprintf_filtered (stream
, "%d",
1628 read_memory_integer (argsaddr
+ start
, sizeof (int)));
1630 PRINT_TYPELESS_INTEGER (stream
, builtin_type_int
,
1632 read_memory_integer (argsaddr
+ start
,
1636 start
+= sizeof (int);
1642 printf_command (arg
, from_tty
)
1647 register char *s
= arg
;
1651 int allocated_args
= 20;
1654 val_args
= (value
*) xmalloc (allocated_args
* sizeof (value
));
1657 error_no_arg ("format-control string and values to print");
1659 /* Skip white space before format string */
1660 while (*s
== ' ' || *s
== '\t') s
++;
1662 /* A format string should follow, enveloped in double quotes */
1664 error ("Bad format string, missing '\"'.");
1666 /* Parse the format-control string and copy it into the string STRING,
1667 processing some kinds of escape sequence. */
1669 f
= string
= (char *) alloca (strlen (s
) + 1);
1676 error ("Bad format string, non-terminated '\"'.");
1677 /* doesn't return */
1698 /* ??? TODO: handle other escape sequences */
1699 error ("Unrecognized \\ escape character in format string.");
1708 /* Skip over " and following space and comma. */
1711 while (*s
== ' ' || *s
== '\t') s
++;
1713 if (*s
!= ',' && *s
!= 0)
1714 error ("Invalid argument syntax");
1717 while (*s
== ' ' || *s
== '\t') s
++;
1720 /* Now scan the string for %-specs and see what kinds of args they want.
1721 argclass[I] classifies the %-specs so we can give vprintf something
1722 of the right size. */
1724 enum argclass
{int_arg
, string_arg
, double_arg
, long_long_arg
};
1725 enum argclass
*argclass
;
1731 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1738 while (strchr ("0123456789.hlL-+ #", *f
))
1740 if (*f
== 'l' || *f
== 'L')
1745 argclass
[nargs_wanted
++] = string_arg
;
1746 else if (*f
== 'e' || *f
== 'f' || *f
== 'g')
1747 argclass
[nargs_wanted
++] = double_arg
;
1748 else if (lcount
> 1)
1749 argclass
[nargs_wanted
++] = long_long_arg
;
1751 argclass
[nargs_wanted
++] = int_arg
;
1755 /* Now, parse all arguments and evaluate them.
1756 Store the VALUEs in VAL_ARGS. */
1761 if (nargs
== allocated_args
)
1762 val_args
= (value
*) xrealloc ((char *) val_args
,
1763 (allocated_args
*= 2)
1766 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
1768 /* If format string wants a float, unchecked-convert the value to
1769 floating point of the same size */
1771 if (argclass
[nargs
] == double_arg
)
1773 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (float))
1774 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
1775 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (double))
1776 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
1784 if (nargs
!= nargs_wanted
)
1785 error ("Wrong number of arguments for specified format-string");
1787 /* Now lay out an argument-list containing the arguments
1788 as doubles, integers and C pointers. */
1790 arg_bytes
= (char *) alloca (sizeof (double) * nargs
);
1792 for (i
= 0; i
< nargs
; i
++)
1794 if (argclass
[i
] == string_arg
)
1799 tem
= value_as_pointer (val_args
[i
]);
1801 /* This is a %s argument. Find the length of the string. */
1806 read_memory (tem
+ j
, &c
, 1);
1811 /* Copy the string contents into a string inside GDB. */
1812 str
= (char *) alloca (j
+ 1);
1813 read_memory (tem
, str
, j
);
1816 /* Pass address of internal copy as the arg to vprintf. */
1817 *((int *) &arg_bytes
[argindex
]) = (int) str
;
1818 argindex
+= sizeof (int);
1820 else if (VALUE_TYPE (val_args
[i
])->code
== TYPE_CODE_FLT
)
1822 *((double *) &arg_bytes
[argindex
]) = value_as_double (val_args
[i
]);
1823 argindex
+= sizeof (double);
1827 if (argclass
[i
] == long_long_arg
)
1829 *(long long *) &arg_bytes
[argindex
] = value_as_long (val_args
[i
]);
1830 argindex
+= sizeof (long long);
1835 *((long *) &arg_bytes
[argindex
]) = value_as_long (val_args
[i
]);
1836 argindex
+= sizeof (long);
1841 /* There is not a standard way to make a va_list, so we need
1842 to do various things for different systems. */
1843 #if defined (__INT_VARARGS_H)
1848 list
.__va_stk
= (int *) arg_bytes
;
1849 list
.__va_reg
= (int *) arg_bytes
;
1850 vprintf (string
, list
);
1852 #else /* No __INT_VARARGS_H. */
1853 vprintf (string
, arg_bytes
);
1854 #endif /* No __INT_VARARGS_H. */
1857 /* Helper function for asdump_command. Finds the bounds of a function
1858 for a specified section of text. PC is an address within the
1859 function which you want bounds for; *LOW and *HIGH are set to the
1860 beginning (inclusive) and end (exclusive) of the function. This
1861 function returns 1 on success and 0 on failure. */
1864 containing_function_bounds (pc
, low
, high
)
1865 CORE_ADDR pc
, *low
, *high
;
1869 if (!find_pc_partial_function (pc
, 0, low
))
1875 if (!find_pc_partial_function (scan
, 0, high
))
1877 } while (*low
== *high
);
1882 /* Dump a specified section of assembly code. With no command line
1883 arguments, this command will dump the assembly code for the
1884 function surrounding the pc value in the selected frame. With one
1885 argument, it will dump the assembly code surrounding that pc value.
1886 Two arguments are interpeted as bounds within which to dump
1891 disassemble_command (arg
, from_tty
)
1895 CORE_ADDR low
, high
;
1901 if (!selected_frame
)
1902 error ("No frame selected.\n");
1904 pc
= get_frame_pc (selected_frame
);
1905 if (!containing_function_bounds (pc
, &low
, &high
))
1906 error ("No function contains pc specified by selected frame.\n");
1908 else if (!(space_index
= (char *) strchr (arg
, ' ')))
1911 pc
= parse_and_eval_address (arg
);
1912 if (!containing_function_bounds (pc
, &low
, &high
))
1913 error ("No function contains specified pc.\n");
1917 /* Two arguments. */
1918 *space_index
= '\0';
1919 low
= parse_and_eval_address (arg
);
1920 high
= parse_and_eval_address (space_index
+ 1);
1923 printf_filtered ("Dump of assembler code ");
1927 find_pc_partial_function (pc
, &name
, 0);
1928 printf_filtered ("for function %s:\n", name
);
1931 printf_filtered ("from %s ", local_hex_string(low
));
1932 printf_filtered ("to %s:\n", local_hex_string(high
));
1934 /* Dump the specified range. */
1935 for (pc
= low
; pc
< high
; )
1938 print_address (pc
, stdout
);
1939 printf_filtered (":\t");
1940 pc
+= print_insn (pc
, stdout
);
1941 printf_filtered ("\n");
1943 printf_filtered ("End of assembler dump.\n");
1949 _initialize_printcmd ()
1951 current_display_number
= -1;
1953 add_info ("address", address_info
,
1954 "Describe where variable VAR is stored.");
1956 add_com ("x", class_vars
, x_command
,
1957 "Examine memory: x/FMT ADDRESS.\n\
1958 ADDRESS is an expression for the memory address to examine.\n\
1959 FMT is a repeat count followed by a format letter and a size letter.\n\
1960 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1961 f(float), a(address), i(instruction), c(char) and s(string).\n\
1962 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1963 g is meaningful only with f, for type double.\n\
1964 The specified number of objects of the specified size are printed\n\
1965 according to the format.\n\n\
1966 Defaults for format and size letters are those previously used.\n\
1967 Default count is 1. Default address is following last thing printed\n\
1968 with this command or \"print\".");
1970 add_com ("disassemble", class_vars
, disassemble_command
,
1971 "Disassemble a specified section of memory.\n\
1972 Default is the function surrounding the pc of the selected frame.\n\
1973 With a single argument, the function surrounding that address is dumped.\n\
1974 Two arguments are taken as a range of memory to dump.");
1976 add_com ("ptype", class_vars
, ptype_command
,
1977 "Print definition of type TYPE.\n\
1978 Argument may be a type name defined by typedef, or \"struct STRUCTNAME\"\n\
1979 or \"union UNIONNAME\" or \"enum ENUMNAME\".\n\
1980 The selected stack frame's lexical context is used to look up the name.");
1982 add_com ("whatis", class_vars
, whatis_command
,
1983 "Print data type of expression EXP.");
1986 add_com ("whereis", class_vars
, whereis_command
,
1987 "Print line number and file of definition of variable.");
1990 add_info ("display", display_info
,
1991 "Expressions to display when program stops, with code numbers.");
1993 add_cmd ("undisplay", class_vars
, undisplay_command
,
1994 "Cancel some expressions to be displayed when program stops.\n\
1995 Arguments are the code numbers of the expressions to stop displaying.\n\
1996 No argument means cancel all automatic-display expressions.\n\
1997 \"delete display\" has the same effect as this command.\n\
1998 Do \"info display\" to see current list of code numbers.",
2001 add_com ("display", class_vars
, display_command
,
2002 "Print value of expression EXP each time the program stops.\n\
2003 /FMT may be used before EXP as in the \"print\" command.\n\
2004 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2005 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2006 and examining is done as in the \"x\" command.\n\n\
2007 With no argument, display all currently requested auto-display expressions.\n\
2008 Use \"undisplay\" to cancel display requests previously made.");
2010 add_cmd ("display", class_vars
, enable_display
,
2011 "Enable some expressions to be displayed when program stops.\n\
2012 Arguments are the code numbers of the expressions to resume displaying.\n\
2013 No argument means enable all automatic-display expressions.\n\
2014 Do \"info display\" to see current list of code numbers.", &enablelist
);
2016 add_cmd ("display", class_vars
, disable_display_command
,
2017 "Disable some expressions to be displayed when program stops.\n\
2018 Arguments are the code numbers of the expressions to stop displaying.\n\
2019 No argument means disable all automatic-display expressions.\n\
2020 Do \"info display\" to see current list of code numbers.", &disablelist
);
2022 add_cmd ("display", class_vars
, undisplay_command
,
2023 "Cancel some expressions to be displayed when program stops.\n\
2024 Arguments are the code numbers of the expressions to stop displaying.\n\
2025 No argument means cancel all automatic-display expressions.\n\
2026 Do \"info display\" to see current list of code numbers.", &deletelist
);
2028 add_com ("printf", class_vars
, printf_command
,
2029 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2030 This is useful for formatted output in user-defined commands.");
2031 add_com ("output", class_vars
, output_command
,
2032 "Like \"print\" but don't put in value history and don't print newline.\n\
2033 This is useful in user-defined commands.");
2035 add_prefix_cmd ("set", class_vars
, set_command
,
2036 "Perform an assignment VAR = EXP.\n\
2037 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
2038 (names starting with $), a register (a few standard names starting with $),\n\
2039 or an actual variable in the program being debugged. EXP is any expression.\n\
2040 Use \"set variable\" for variables with names identical to set subcommands.\n\
2041 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2042 You can see these environment settings with the \"show\" command.",
2043 &setlist
, "set ", 1, &cmdlist
);
2045 /* "call" is the same as "set", but handy for dbx users to call fns. */
2046 add_com ("call", class_vars
, call_command
,
2047 "Call a function in the inferior process.\n\
2048 The argument is the function name and arguments, in the notation of the\n\
2049 current working language. The result is printed and saved in the value\n\
2050 history, if it is not void.");
2052 add_cmd ("variable", class_vars
, set_command
,
2053 "Perform an assignment VAR = EXP.\n\
2054 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
2055 (names starting with $), a register (a few standard names starting with $),\n\
2056 or an actual variable in the program being debugged. EXP is any expression.\n\
2057 This may usually be abbreviated to simply \"set\".",
2060 add_com ("print", class_vars
, print_command
,
2061 concat ("Print value of expression EXP.\n\
2062 Variables accessible are those of the lexical environment of the selected\n\
2063 stack frame, plus all those whose scope is global or an entire file.\n\
2065 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2066 $$NUM refers to NUM'th value back from the last one.\n\
2067 Names starting with $ refer to registers (with the values they would have\n\
2068 if the program were to return to the stack frame now selected, restoring\n\
2069 all registers saved by frames farther in) or else to debugger\n\
2070 \"convenience\" variables (any such name not a known register).\n\
2071 Use assignment expressions to give values to convenience variables.\n",
2073 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2074 @ is a binary operator for treating consecutive data objects\n\
2075 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2076 element is FOO, whose second element is stored in the space following\n\
2077 where FOO is stored, etc. FOO must be an expression whose value\n\
2078 resides in memory.\n",
2080 EXP may be preceded with /FMT, where FMT is a format letter\n\
2081 but no count or size letter (see \"x\" command).", NULL
));
2082 add_com_alias ("p", "print", class_vars
, 1);
2084 add_com ("inspect", class_vars
, inspect_command
,
2085 "Same as \"print\" command, except that if you are running in the epoch\n\
2086 environment, the value is printed in its own window.");