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. */
78 enum display_status
{disabled
, enabled
};
82 /* Chain link to next auto-display item. */
84 /* Expression to be evaluated and displayed. */
85 struct expression
*exp
;
86 /* Item number of this auto-display item. */
88 /* Display format specified. */
89 struct format_data format
;
90 /* Innermost block required by this expression when evaluated */
92 /* Status of this display (enabled or disabled) */
93 enum display_status status
;
96 /* Chain of expressions whose values should be displayed
97 automatically each time the program stops. */
99 static struct display
*display_chain
;
101 static int display_number
;
103 /* Prototypes for local functions */
106 delete_display
PARAMS ((int));
109 enable_display
PARAMS ((char *));
112 disable_display_command
PARAMS ((char *, int));
115 disassemble_command
PARAMS ((char *, int));
118 containing_function_bounds
PARAMS ((CORE_ADDR
, CORE_ADDR
*, CORE_ADDR
*));
121 printf_command
PARAMS ((char *, int));
124 print_frame_nameless_args
PARAMS ((CORE_ADDR
, long, int, int, FILE *));
127 display_info
PARAMS ((void));
130 do_one_display
PARAMS ((struct display
*));
133 undisplay_command
PARAMS ((char *));
136 free_display
PARAMS ((struct display
*));
139 display_command
PARAMS ((char *, int));
142 ptype_command
PARAMS ((char *, int));
145 ptype_eval
PARAMS ((struct expression
*));
148 whatis_command
PARAMS ((char *, int));
151 whatis_exp
PARAMS ((char *, int));
154 x_command
PARAMS ((char *, int));
157 address_info
PARAMS ((char *, int));
160 set_command
PARAMS ((char *, int));
163 output_command
PARAMS ((char *, int));
166 call_command
PARAMS ((char *, int));
169 inspect_command
PARAMS ((char *, int));
172 print_command
PARAMS ((char *, int));
175 print_command_1
PARAMS ((char *, int, int));
178 validate_format
PARAMS ((struct format_data
, char *));
181 do_examine
PARAMS ((struct format_data
, CORE_ADDR
));
184 print_formatted
PARAMS ((value
, int, int));
186 static struct format_data
187 decode_format
PARAMS ((char **, int, int));
190 /* Decode a format specification. *STRING_PTR should point to it.
191 OFORMAT and OSIZE are used as defaults for the format and size
192 if none are given in the format specification.
193 If OSIZE is zero, then the size field of the returned value
194 should be set only if a size is explicitly specified by the
196 The structure returned describes all the data
197 found in the specification. In addition, *STRING_PTR is advanced
198 past the specification and past all whitespace following it. */
200 static struct format_data
201 decode_format (string_ptr
, oformat
, osize
)
206 struct format_data val
;
207 register char *p
= *string_ptr
;
213 if (*p
>= '0' && *p
<= '9')
214 val
.count
= atoi (p
);
215 while (*p
>= '0' && *p
<= '9') p
++;
217 /* Now process size or format letters that follow. */
221 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
230 else if (*p
>= 'a' && *p
<= 'z')
237 /* Make sure 'g' size is not used on integer types.
238 Well, actually, we can handle hex. */
239 if (val
.size
== 'g' && val
.format
!= 'f' && val
.format
!= 'x')
243 while (*p
== ' ' || *p
== '\t') p
++;
246 /* Set defaults for format and size if not specified. */
247 if (val
.format
== '?')
251 /* Neither has been specified. */
252 val
.format
= oformat
;
256 /* If a size is specified, any format makes a reasonable
257 default except 'i'. */
258 val
.format
= oformat
== 'i' ? 'x' : oformat
;
260 else if (val
.size
== '?')
265 /* Addresses must be words. */
266 val
.size
= osize
? 'w' : osize
;
269 /* Floating point has to be word or giantword. */
270 if (osize
== 'w' || osize
== 'g')
273 /* Default it to giantword if the last used size is not
275 val
.size
= osize
? 'g' : osize
;
278 /* Characters default to one byte. */
279 val
.size
= osize
? 'b' : osize
;
282 /* The default is the size most recently specified. */
289 /* Print value VAL on stdout according to FORMAT, a letter or 0.
290 Do not end with a newline.
291 0 means print VAL according to its own type.
292 SIZE is the letter for the size of datum being printed.
293 This is used to pad hex numbers so they line up. */
296 print_formatted (val
, format
, size
)
301 int len
= TYPE_LENGTH (VALUE_TYPE (val
));
303 if (VALUE_LVAL (val
) == lval_memory
)
304 next_address
= VALUE_ADDRESS (val
) + len
;
309 next_address
= VALUE_ADDRESS (val
)
310 + value_print (value_addr (val
), stdout
, format
, Val_pretty_default
);
314 wrap_here (""); /* Force output out, print_insn not using _filtered */
315 next_address
= VALUE_ADDRESS (val
)
316 + print_insn (VALUE_ADDRESS (val
), stdout
);
321 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_ARRAY
322 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_STRUCT
323 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_UNION
324 || VALUE_REPEATED (val
))
325 value_print (val
, stdout
, format
, Val_pretty_default
);
327 print_scalar_formatted (VALUE_CONTENTS (val
), VALUE_TYPE (val
),
328 format
, size
, stdout
);
332 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
333 according to letters FORMAT and SIZE on STREAM.
334 FORMAT may not be zero. Formats s and i are not supported at this level.
336 This is how the elements of an array or structure are printed
340 print_scalar_formatted (valaddr
, type
, format
, size
, stream
)
348 int len
= TYPE_LENGTH (type
);
350 if (size
== 'g' && sizeof (LONGEST
) < 8
353 /* ok, we're going to have to get fancy here. Assumption: a
354 long is four bytes. FIXME. */
355 unsigned long v1
, v2
;
357 v1
= unpack_long (builtin_type_long
, valaddr
);
358 v2
= unpack_long (builtin_type_long
, valaddr
+ 4);
360 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
361 /* Swap the two for printing */
374 fprintf_filtered (stream
, local_hex_format_custom("08x%08"), v1
, v2
);
377 error ("Output size \"g\" unimplemented for format \"%c\".",
383 val_long
= unpack_long (type
, valaddr
);
385 /* If value is unsigned, truncate it in case negative. */
388 if (len
== sizeof (char))
389 val_long
&= (1 << 8 * sizeof(char)) - 1;
390 else if (len
== sizeof (short))
391 val_long
&= (1 << 8 * sizeof(short)) - 1;
392 else if (len
== sizeof (long))
393 val_long
&= (unsigned long) - 1;
401 /* no size specified, like in print. Print varying # of digits. */
402 #if defined (LONG_LONG)
403 fprintf_filtered (stream
, local_hex_format_custom("ll"), val_long
);
404 #else /* not LONG_LONG. */
405 fprintf_filtered (stream
, local_hex_format_custom("l"), val_long
);
406 #endif /* not LONG_LONG. */
409 #if defined (LONG_LONG)
413 fprintf_filtered (stream
, local_hex_format_custom("02ll"), val_long
);
416 fprintf_filtered (stream
, local_hex_format_custom("04ll"), val_long
);
419 fprintf_filtered (stream
, local_hex_format_custom("08ll"), val_long
);
422 fprintf_filtered (stream
, local_hex_format_custom("016ll"), val_long
);
425 error ("Undefined output size \"%c\".", size
);
427 #else /* not LONG_LONG. */
431 fprintf_filtered (stream
, local_hex_format_custom("02"), val_long
);
434 fprintf_filtered (stream
, local_hex_format_custom("04"), val_long
);
437 fprintf_filtered (stream
, local_hex_format_custom("08"), val_long
);
440 fprintf_filtered (stream
, local_hex_format_custom("016"), val_long
);
443 error ("Undefined output size \"%c\".", size
);
445 #endif /* not LONG_LONG */
450 fprintf_filtered (stream
, "%lld", val_long
);
452 fprintf_filtered (stream
, "%d", val_long
);
458 fprintf_filtered (stream
, "%llu", val_long
);
460 fprintf_filtered (stream
, "%u", val_long
);
467 fprintf_filtered (stream
, local_octal_format_custom("ll"), val_long
);
469 fprintf_filtered (stream
, local_octal_format(), val_long
);
472 fprintf_filtered (stream
, "0");
476 print_address (unpack_pointer (type
, valaddr
), stream
);
480 value_print (value_from_longest (builtin_type_char
, val_long
), stream
, 0,
485 if (len
== sizeof (float))
486 type
= builtin_type_float
;
487 else if (len
== sizeof (double))
488 type
= builtin_type_double
;
489 print_floating (valaddr
, type
, stream
);
496 /* Binary; 't' stands for "two". */
498 char bits
[8*(sizeof val_long
) + 1];
503 width
= 8*(sizeof val_long
);
520 error ("Undefined output size \"%c\".", size
);
526 bits
[width
] = (val_long
& 1) ? '1' : '0';
531 while (*cp
&& *cp
== '0')
536 fprintf_filtered (stream
, cp
);
541 error ("Undefined output format \"%c\".", format
);
545 /* Specify default address for `x' command.
546 `info lines' uses this. */
549 set_next_address (addr
)
554 /* Make address available to the user as $_. */
555 set_internalvar (lookup_internalvar ("_"),
556 value_from_longest (lookup_pointer_type (builtin_type_void
),
560 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
561 after LEADIN. Print nothing if no symbolic name is found nearby.
562 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
563 or to interpret it as a possible C++ name and convert it back to source
567 print_address_symbolic (addr
, stream
, do_demangle
, leadin
)
574 register struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (addr
);
576 /* If nothing comes out, don't print anything symbolic. */
581 fputs_filtered (leadin
, stream
);
582 fputs_filtered ("<", stream
);
584 fputs_demangled (msymbol
-> name
, stream
, 1);
586 fputs_filtered (msymbol
-> name
, stream
);
587 name_location
= msymbol
-> address
;
588 if (addr
- name_location
)
589 fprintf_filtered (stream
, "+%d>", addr
- name_location
);
591 fputs_filtered (">", stream
);
594 /* Print address ADDR symbolically on STREAM.
595 First print it as a number. Then perhaps print
596 <SYMBOL + OFFSET> after the number. */
599 print_address (addr
, stream
)
603 fprintf_filtered (stream
, local_hex_format(), addr
);
604 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
607 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
608 controls whether to print the symbolic name "raw" or demangled.
609 Global setting "addressprint" controls whether to print hex address
613 print_address_demangle (addr
, stream
, do_demangle
)
619 fprintf_filtered (stream
, "0");
620 } else if (addressprint
) {
621 fprintf_filtered (stream
, local_hex_format(), addr
);
622 print_address_symbolic (addr
, stream
, do_demangle
, " ");
624 print_address_symbolic (addr
, stream
, do_demangle
, "");
629 /* Examine data at address ADDR in format FMT.
630 Fetch it from memory and print on stdout. */
633 do_examine (fmt
, addr
)
634 struct format_data fmt
;
637 register char format
= 0;
639 register int count
= 1;
640 struct type
*val_type
;
642 register int maxelts
;
649 /* String or instruction format implies fetch single bytes
650 regardless of the specified size. */
651 if (format
== 's' || format
== 'i')
655 val_type
= builtin_type_char
;
656 else if (size
== 'h')
657 val_type
= builtin_type_short
;
658 else if (size
== 'w')
659 val_type
= builtin_type_long
;
660 else if (size
== 'g')
662 val_type
= builtin_type_double
;
664 val_type
= builtin_type_long_long
;
672 if (format
== 's' || format
== 'i')
675 /* Print as many objects as specified in COUNT, at most maxelts per line,
676 with the address of the next one at the start of each line. */
680 print_address (next_address
, stdout
);
681 printf_filtered (":");
686 printf_filtered ("\t");
687 /* Note that print_formatted sets next_address for the next
689 last_examine_address
= next_address
;
690 last_examine_value
= value_at (val_type
, next_address
);
691 print_formatted (last_examine_value
, format
, size
);
693 printf_filtered ("\n");
699 validate_format (fmt
, cmdname
)
700 struct format_data fmt
;
704 error ("Size letters are meaningless in \"%s\" command.", cmdname
);
706 error ("Item count other than 1 is meaningless in \"%s\" command.",
708 if (fmt
.format
== 'i' || fmt
.format
== 's')
709 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
710 fmt
.format
, cmdname
);
714 print_command_1 (exp
, inspect
, voidprint
)
719 struct expression
*expr
;
720 register struct cleanup
*old_chain
= 0;
721 register char format
= 0;
723 struct format_data fmt
;
726 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
727 inspect_it
= inspect
;
729 if (exp
&& *exp
== '/')
732 fmt
= decode_format (&exp
, last_format
, 0);
733 validate_format (fmt
, "print");
734 last_format
= format
= fmt
.format
;
745 extern int objectprint
;
747 expr
= parse_expression (exp
);
748 old_chain
= make_cleanup (free_current_contents
, &expr
);
750 val
= evaluate_expression (expr
);
752 /* C++: figure out what type we actually want to print it as. */
753 type
= VALUE_TYPE (val
);
756 && ( TYPE_CODE (type
) == TYPE_CODE_PTR
757 || TYPE_CODE (type
) == TYPE_CODE_REF
)
758 && ( TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
759 || TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_UNION
))
763 v
= value_from_vtable_info (val
, TYPE_TARGET_TYPE (type
));
767 type
= VALUE_TYPE (val
);
772 val
= access_value_history (0);
774 if (voidprint
|| (val
&& VALUE_TYPE (val
) &&
775 TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_VOID
))
777 int histindex
= record_latest_value (val
);
780 printf ("\031(gdb-makebuffer \"%s\" %d '(\"", exp
, histindex
);
782 if (histindex
>= 0) printf_filtered ("$%d = ", histindex
);
784 print_formatted (val
, format
, fmt
.size
);
785 printf_filtered ("\n");
791 do_cleanups (old_chain
);
792 inspect_it
= 0; /* Reset print routines to normal */
797 print_command (exp
, from_tty
)
801 print_command_1 (exp
, 0, 1);
804 /* Same as print, except in epoch, it gets its own window */
807 inspect_command (exp
, from_tty
)
811 extern int epoch_interface
;
813 print_command_1 (exp
, epoch_interface
, 1);
816 /* Same as print, except it doesn't print void results. */
819 call_command (exp
, from_tty
)
823 print_command_1 (exp
, 0, 0);
828 output_command (exp
, from_tty
)
832 struct expression
*expr
;
833 register struct cleanup
*old_chain
;
834 register char format
= 0;
836 struct format_data fmt
;
838 if (exp
&& *exp
== '/')
841 fmt
= decode_format (&exp
, 0, 0);
842 validate_format (fmt
, "print");
846 expr
= parse_expression (exp
);
847 old_chain
= make_cleanup (free_current_contents
, &expr
);
849 val
= evaluate_expression (expr
);
851 print_formatted (val
, format
, fmt
.size
);
853 do_cleanups (old_chain
);
858 set_command (exp
, from_tty
)
862 struct expression
*expr
= parse_expression (exp
);
863 register struct cleanup
*old_chain
864 = make_cleanup (free_current_contents
, &expr
);
865 evaluate_expression (expr
);
866 do_cleanups (old_chain
);
871 address_info (exp
, from_tty
)
875 register struct symbol
*sym
;
876 register struct minimal_symbol
*msymbol
;
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(msymbol
-> address
));
900 error ("No symbol \"%s\" in current context.", exp
);
904 printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym
));
905 val
= SYMBOL_VALUE (sym
);
907 switch (SYMBOL_CLASS (sym
))
910 case LOC_CONST_BYTES
:
915 printf ("a label at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym
)));
919 printf ("a variable in register %s", reg_names
[val
]);
923 printf ("static storage at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym
)));
927 printf ("an argument in register %s", reg_names
[val
]);
931 printf ("an argument at offset %ld", val
);
935 printf ("an argument at frame offset %ld", val
);
939 printf ("a local variable at frame offset %ld", val
);
943 printf ("a reference argument at offset %ld", val
);
947 printf ("a typedef");
951 printf ("a function at address %s",
952 local_hex_string(BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
956 printf ("of unknown (botched) type");
963 x_command (exp
, from_tty
)
967 struct expression
*expr
;
968 struct format_data fmt
;
969 struct cleanup
*old_chain
;
972 fmt
.format
= last_format
;
973 fmt
.size
= last_size
;
976 if (exp
&& *exp
== '/')
979 fmt
= decode_format (&exp
, last_format
, last_size
);
980 last_size
= fmt
.size
;
981 last_format
= fmt
.format
;
984 /* If we have an expression, evaluate it and use it as the address. */
986 if (exp
!= 0 && *exp
!= 0)
988 expr
= parse_expression (exp
);
989 /* Cause expression not to be there any more
990 if this command is repeated with Newline.
991 But don't clobber a user-defined command's definition. */
994 old_chain
= make_cleanup (free_current_contents
, &expr
);
995 val
= evaluate_expression (expr
);
996 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_REF
)
997 val
= value_ind (val
);
998 /* In rvalue contexts, such as this, functions are coerced into
999 pointers to functions. This makes "x/i main" work. */
1000 if (/* last_format == 'i'
1001 && */ TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FUNC
1002 && VALUE_LVAL (val
) == lval_memory
)
1003 next_address
= VALUE_ADDRESS (val
);
1005 next_address
= value_as_pointer (val
);
1006 do_cleanups (old_chain
);
1009 do_examine (fmt
, next_address
);
1011 /* Set a couple of internal variables if appropriate. */
1012 if (last_examine_value
)
1014 /* Make last address examined available to the user as $_. Use
1015 the correct pointer type. */
1016 set_internalvar (lookup_internalvar ("_"),
1017 value_from_longest (
1018 lookup_pointer_type (VALUE_TYPE (last_examine_value
)),
1019 (LONGEST
) last_examine_address
));
1021 /* Make contents of last address examined available to the user as $__.*/
1022 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1026 /* Commands for printing types of things. */
1028 /* Print type of EXP, or last thing in value history if EXP == NULL.
1029 show is passed to type_print. */
1031 whatis_exp (exp
, show
)
1035 struct expression
*expr
;
1037 register struct cleanup
*old_chain
;
1041 expr
= parse_expression (exp
);
1042 old_chain
= make_cleanup (free_current_contents
, &expr
);
1043 val
= evaluate_type (expr
);
1046 val
= access_value_history (0);
1048 printf_filtered ("type = ");
1049 type_print (VALUE_TYPE (val
), "", stdout
, show
);
1050 printf_filtered ("\n");
1053 do_cleanups (old_chain
);
1058 whatis_command (exp
, from_tty
)
1062 /* Most of the time users do not want to see all the fields
1063 in a structure. If they do they can use the "ptype" command.
1064 Hence the "-1" below. */
1065 whatis_exp (exp
, -1);
1068 /* Simple subroutine for ptype_command. */
1072 struct expression
*exp
;
1074 if(exp
->elts
[0].opcode
==OP_TYPE
)
1075 return exp
->elts
[1].type
;
1080 /* TYPENAME is either the name of a type, or an expression. */
1083 ptype_command (typename
, from_tty
)
1087 register struct type
*type
;
1088 struct expression
*expr
;
1089 register struct cleanup
*old_chain
;
1093 expr
= parse_expression (typename
);
1094 old_chain
= make_cleanup (free_current_contents
, &expr
);
1095 type
= ptype_eval (expr
);
1099 printf_filtered ("type = ");
1100 type_print (type
, "", stdout
, 1);
1101 printf_filtered ("\n");
1102 do_cleanups (old_chain
);
1106 do_cleanups (old_chain
);
1107 whatis_exp (typename
, 1);
1111 whatis_exp (typename
, 1);
1114 /* Add an expression to the auto-display chain.
1115 Specify the expression. */
1118 display_command (exp
, from_tty
)
1122 struct format_data fmt
;
1123 register struct expression
*expr
;
1124 register struct display
*new;
1135 fmt
= decode_format (&exp
, 0, 0);
1136 if (fmt
.size
&& fmt
.format
== 0)
1138 if (fmt
.format
== 'i' || fmt
.format
== 's')
1148 innermost_block
= 0;
1149 expr
= parse_expression (exp
);
1151 new = (struct display
*) xmalloc (sizeof (struct display
));
1154 new->block
= innermost_block
;
1155 new->next
= display_chain
;
1156 new->number
= ++display_number
;
1158 new->status
= enabled
;
1159 display_chain
= new;
1161 if (from_tty
&& target_has_execution
)
1162 do_one_display (new);
1175 /* Clear out the display_chain.
1176 Done when new symtabs are loaded, since this invalidates
1177 the types stored in many expressions. */
1182 register struct display
*d
;
1184 while (d
= display_chain
)
1187 display_chain
= d
->next
;
1192 /* Delete the auto-display number NUM. */
1195 delete_display (num
)
1198 register struct display
*d1
, *d
;
1201 error ("No display number %d.", num
);
1203 if (display_chain
->number
== num
)
1206 display_chain
= d1
->next
;
1210 for (d
= display_chain
; ; d
= d
->next
)
1213 error ("No display number %d.", num
);
1214 if (d
->next
->number
== num
)
1224 /* Delete some values from the auto-display chain.
1225 Specify the element numbers. */
1228 undisplay_command (args
)
1231 register char *p
= args
;
1237 if (query ("Delete all auto-display expressions? "))
1246 while (*p1
>= '0' && *p1
<= '9') p1
++;
1247 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1248 error ("Arguments must be display numbers.");
1252 delete_display (num
);
1255 while (*p
== ' ' || *p
== '\t') p
++;
1260 /* Display a single auto-display.
1261 Do nothing if the display cannot be printed in the current context,
1262 or if the display is disabled. */
1268 int within_current_scope
;
1270 if (d
->status
== disabled
)
1274 within_current_scope
= contained_in (get_selected_block (), d
->block
);
1276 within_current_scope
= 1;
1277 if (!within_current_scope
)
1280 current_display_number
= d
->number
;
1282 printf_filtered ("%d: ", d
->number
);
1287 printf_filtered ("x/");
1288 if (d
->format
.count
!= 1)
1289 printf_filtered ("%d", d
->format
.count
);
1290 printf_filtered ("%c", d
->format
.format
);
1291 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1292 printf_filtered ("%c", d
->format
.size
);
1293 printf_filtered (" ");
1294 print_expression (d
->exp
, stdout
);
1295 if (d
->format
.count
!= 1)
1296 printf_filtered ("\n");
1298 printf_filtered (" ");
1300 addr
= value_as_pointer (evaluate_expression (d
->exp
));
1301 if (d
->format
.format
== 'i')
1302 addr
= ADDR_BITS_REMOVE (addr
);
1304 do_examine (d
->format
, addr
);
1308 if (d
->format
.format
)
1309 printf_filtered ("/%c ", d
->format
.format
);
1310 print_expression (d
->exp
, stdout
);
1311 printf_filtered (" = ");
1312 print_formatted (evaluate_expression (d
->exp
),
1313 d
->format
.format
, d
->format
.size
);
1314 printf_filtered ("\n");
1318 current_display_number
= -1;
1321 /* Display all of the values on the auto-display chain which can be
1322 evaluated in the current scope. */
1327 register struct display
*d
;
1329 for (d
= display_chain
; d
; d
= d
->next
)
1333 /* Delete the auto-display which we were in the process of displaying.
1334 This is done when there is an error or a signal. */
1337 disable_display (num
)
1340 register struct display
*d
;
1342 for (d
= display_chain
; d
; d
= d
->next
)
1343 if (d
->number
== num
)
1345 d
->status
= disabled
;
1348 printf ("No display number %d.\n", num
);
1352 disable_current_display ()
1354 if (current_display_number
>= 0)
1356 disable_display (current_display_number
);
1357 fprintf (stderr
, "Disabling display %d to avoid infinite recursion.\n",
1358 current_display_number
);
1360 current_display_number
= -1;
1366 register struct display
*d
;
1369 printf ("There are no auto-display expressions now.\n");
1371 printf_filtered ("Auto-display expressions now in effect:\n\
1372 Num Enb Expression\n");
1374 for (d
= display_chain
; d
; d
= d
->next
)
1376 printf_filtered ("%d: %c ", d
->number
, "ny"[(int)d
->status
]);
1378 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1380 else if (d
->format
.format
)
1381 printf_filtered ("/%c ", d
->format
.format
);
1382 print_expression (d
->exp
, stdout
);
1383 if (d
->block
&& !contained_in (get_selected_block (), d
->block
))
1384 printf_filtered (" (cannot be evaluated in the current context)");
1385 printf_filtered ("\n");
1391 enable_display (args
)
1394 register char *p
= args
;
1397 register struct display
*d
;
1401 for (d
= display_chain
; d
; d
= d
->next
)
1402 d
->status
= enabled
;
1408 while (*p1
>= '0' && *p1
<= '9')
1410 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1411 error ("Arguments must be display numbers.");
1415 for (d
= display_chain
; d
; d
= d
->next
)
1416 if (d
->number
== num
)
1418 d
->status
= enabled
;
1421 printf ("No display number %d.\n", num
);
1424 while (*p
== ' ' || *p
== '\t')
1431 disable_display_command (args
, from_tty
)
1435 register char *p
= args
;
1437 register struct display
*d
;
1441 for (d
= display_chain
; d
; d
= d
->next
)
1442 d
->status
= disabled
;
1448 while (*p1
>= '0' && *p1
<= '9')
1450 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1451 error ("Arguments must be display numbers.");
1453 disable_display (atoi (p
));
1456 while (*p
== ' ' || *p
== '\t')
1462 /* Print the value in stack frame FRAME of a variable
1463 specified by a struct symbol. */
1466 print_variable_value (var
, frame
, stream
)
1471 value val
= read_var_value (var
, frame
);
1472 value_print (val
, stream
, 0, Val_pretty_default
);
1475 /* Print the arguments of a stack frame, given the function FUNC
1476 running in that frame (as a symbol), the info on the frame,
1477 and the number of args according to the stack frame (or -1 if unknown). */
1479 /* References here and elsewhere to "number of args according to the
1480 stack frame" appear in all cases to refer to "number of ints of args
1481 according to the stack frame". At least for VAX, i386, isi. */
1484 print_frame_args (func
, fi
, num
, stream
)
1485 struct symbol
*func
;
1486 struct frame_info
*fi
;
1494 register struct symbol
*sym
;
1496 /* Offset of next stack argument beyond the one we have seen that is
1497 at the highest offset.
1498 -1 if we haven't come to a stack argument yet. */
1499 long highest_offset
= -1;
1501 /* Number of ints of arguments that we have printed so far. */
1502 int args_printed
= 0;
1506 b
= SYMBOL_BLOCK_VALUE (func
);
1507 nsyms
= BLOCK_NSYMS (b
);
1510 for (i
= 0; i
< nsyms
; i
++)
1513 sym
= BLOCK_SYM (b
, i
);
1515 /* Keep track of the highest stack argument offset seen, and
1516 skip over any kinds of symbols we don't care about. */
1518 switch (SYMBOL_CLASS (sym
)) {
1522 long current_offset
= SYMBOL_VALUE (sym
);
1524 arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
1526 /* Compute address of next argument by adding the size of
1527 this argument and rounding to an int boundary. */
1529 = ((current_offset
+ arg_size
+ sizeof (int) - 1)
1530 & ~(sizeof (int) - 1));
1532 /* If this is the highest offset seen yet, set highest_offset. */
1533 if (highest_offset
== -1
1534 || (current_offset
> highest_offset
))
1535 highest_offset
= current_offset
;
1537 /* Add the number of ints we're about to print to args_printed. */
1538 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
1541 /* We care about types of symbols, but don't need to keep track of
1542 stack offsets in them. */
1547 /* Other types of symbols we just skip over. */
1552 /* We have to re-look-up the symbol because arguments often have
1553 two entries (one a parameter, one a register or local), and the one
1554 we want is the non-parm, which lookup_symbol will find for
1555 us. After this, sym could be any SYMBOL_CLASS... */
1556 sym
= lookup_symbol (SYMBOL_NAME (sym
),
1557 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
1559 /* Print the current arg. */
1561 fprintf_filtered (stream
, ", ");
1563 fprint_symbol (stream
, SYMBOL_NAME (sym
));
1564 fputs_filtered ("=", stream
);
1566 /* Avoid value_print because it will deref ref parameters. We just
1567 want to print their addresses. Print ??? for args whose address
1568 we do not know. We pass 2 as "recurse" to val_print because our
1569 standard indentation here is 4 spaces, and val_print indents
1570 2 for each recurse. */
1571 val
= read_var_value (sym
, FRAME_INFO_ID (fi
));
1573 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), VALUE_ADDRESS (val
),
1574 stream
, 0, 0, 2, Val_no_prettyprint
);
1576 fputs_filtered ("???", stream
);
1580 /* Don't print nameless args in situations where we don't know
1581 enough about the stack to find them. */
1587 if (highest_offset
== -1)
1588 start
= FRAME_ARGS_SKIP
;
1590 start
= highest_offset
;
1592 addr
= FRAME_ARGS_ADDRESS (fi
);
1594 print_frame_nameless_args (addr
, start
, num
- args_printed
,
1599 /* Print nameless args on STREAM.
1600 ARGSADDR is the address of the arglist, START is the offset
1601 of the first nameless arg, and NUM is the number of nameless args to
1602 print. FIRST is nonzero if this is the first argument (not just
1603 the first nameless arg). */
1605 print_frame_nameless_args (argsaddr
, start
, num
, first
, stream
)
1613 for (i
= 0; i
< num
; i
++)
1617 fprintf_filtered (stream
, ", ");
1618 #ifndef PRINT_TYPELESS_INTEGER
1619 fprintf_filtered (stream
, "%d",
1620 read_memory_integer (argsaddr
+ start
, sizeof (int)));
1622 PRINT_TYPELESS_INTEGER (stream
, builtin_type_int
,
1624 read_memory_integer (argsaddr
+ start
,
1628 start
+= sizeof (int);
1634 printf_command (arg
, from_tty
)
1639 register char *s
= arg
;
1643 int allocated_args
= 20;
1646 val_args
= (value
*) xmalloc (allocated_args
* sizeof (value
));
1649 error_no_arg ("format-control string and values to print");
1651 /* Skip white space before format string */
1652 while (*s
== ' ' || *s
== '\t') s
++;
1654 /* A format string should follow, enveloped in double quotes */
1656 error ("Bad format string, missing '\"'.");
1658 /* Parse the format-control string and copy it into the string STRING,
1659 processing some kinds of escape sequence. */
1661 f
= string
= (char *) alloca (strlen (s
) + 1);
1668 error ("Bad format string, non-terminated '\"'.");
1669 /* doesn't return */
1690 /* ??? TODO: handle other escape sequences */
1691 error ("Unrecognized \\ escape character in format string.");
1700 /* Skip over " and following space and comma. */
1703 while (*s
== ' ' || *s
== '\t') s
++;
1705 if (*s
!= ',' && *s
!= 0)
1706 error ("Invalid argument syntax");
1709 while (*s
== ' ' || *s
== '\t') s
++;
1712 /* Now scan the string for %-specs and see what kinds of args they want.
1713 argclass[I] classifies the %-specs so we can give vprintf something
1714 of the right size. */
1716 enum argclass
{int_arg
, string_arg
, double_arg
, long_long_arg
};
1717 enum argclass
*argclass
;
1723 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1730 while (strchr ("0123456789.hlL-+ #", *f
))
1732 if (*f
== 'l' || *f
== 'L')
1737 argclass
[nargs_wanted
++] = string_arg
;
1738 else if (*f
== 'e' || *f
== 'f' || *f
== 'g')
1739 argclass
[nargs_wanted
++] = double_arg
;
1740 else if (lcount
> 1)
1741 argclass
[nargs_wanted
++] = long_long_arg
;
1743 argclass
[nargs_wanted
++] = int_arg
;
1747 /* Now, parse all arguments and evaluate them.
1748 Store the VALUEs in VAL_ARGS. */
1753 if (nargs
== allocated_args
)
1754 val_args
= (value
*) xrealloc ((char *) val_args
,
1755 (allocated_args
*= 2)
1758 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
1760 /* If format string wants a float, unchecked-convert the value to
1761 floating point of the same size */
1763 if (argclass
[nargs
] == double_arg
)
1765 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (float))
1766 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
1767 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (double))
1768 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
1776 if (nargs
!= nargs_wanted
)
1777 error ("Wrong number of arguments for specified format-string");
1779 /* Now lay out an argument-list containing the arguments
1780 as doubles, integers and C pointers. */
1782 arg_bytes
= (char *) alloca (sizeof (double) * nargs
);
1784 for (i
= 0; i
< nargs
; i
++)
1786 if (argclass
[i
] == string_arg
)
1791 tem
= value_as_pointer (val_args
[i
]);
1793 /* This is a %s argument. Find the length of the string. */
1798 read_memory (tem
+ j
, &c
, 1);
1803 /* Copy the string contents into a string inside GDB. */
1804 str
= (char *) alloca (j
+ 1);
1805 read_memory (tem
, str
, j
);
1808 /* Pass address of internal copy as the arg to vprintf. */
1809 *((int *) &arg_bytes
[argindex
]) = (int) str
;
1810 argindex
+= sizeof (int);
1812 else if (VALUE_TYPE (val_args
[i
])->code
== TYPE_CODE_FLT
)
1814 *((double *) &arg_bytes
[argindex
]) = value_as_double (val_args
[i
]);
1815 argindex
+= sizeof (double);
1819 if (argclass
[i
] == long_long_arg
)
1821 *(long long *) &arg_bytes
[argindex
] = value_as_long (val_args
[i
]);
1822 argindex
+= sizeof (long long);
1827 *((long *) &arg_bytes
[argindex
]) = value_as_long (val_args
[i
]);
1828 argindex
+= sizeof (long);
1833 /* There is not a standard way to make a va_list, so we need
1834 to do various things for different systems. */
1835 #if defined (__INT_VARARGS_H)
1840 list
.__va_stk
= (int *) arg_bytes
;
1841 list
.__va_reg
= (int *) arg_bytes
;
1842 vprintf (string
, list
);
1844 #else /* No __INT_VARARGS_H. */
1845 vprintf (string
, arg_bytes
);
1846 #endif /* No __INT_VARARGS_H. */
1849 /* Helper function for asdump_command. Finds the bounds of a function
1850 for a specified section of text. PC is an address within the
1851 function which you want bounds for; *LOW and *HIGH are set to the
1852 beginning (inclusive) and end (exclusive) of the function. This
1853 function returns 1 on success and 0 on failure. */
1856 containing_function_bounds (pc
, low
, high
)
1857 CORE_ADDR pc
, *low
, *high
;
1861 if (!find_pc_partial_function (pc
, 0, low
))
1867 if (!find_pc_partial_function (scan
, 0, high
))
1869 } while (*low
== *high
);
1874 /* Dump a specified section of assembly code. With no command line
1875 arguments, this command will dump the assembly code for the
1876 function surrounding the pc value in the selected frame. With one
1877 argument, it will dump the assembly code surrounding that pc value.
1878 Two arguments are interpeted as bounds within which to dump
1883 disassemble_command (arg
, from_tty
)
1887 CORE_ADDR low
, high
;
1893 if (!selected_frame
)
1894 error ("No frame selected.\n");
1896 pc
= get_frame_pc (selected_frame
);
1897 if (!containing_function_bounds (pc
, &low
, &high
))
1898 error ("No function contains pc specified by selected frame.\n");
1900 else if (!(space_index
= (char *) strchr (arg
, ' ')))
1903 pc
= parse_and_eval_address (arg
);
1904 if (!containing_function_bounds (pc
, &low
, &high
))
1905 error ("No function contains specified pc.\n");
1909 /* Two arguments. */
1910 *space_index
= '\0';
1911 low
= parse_and_eval_address (arg
);
1912 high
= parse_and_eval_address (space_index
+ 1);
1915 printf_filtered ("Dump of assembler code ");
1919 find_pc_partial_function (pc
, &name
, 0);
1920 printf_filtered ("for function %s:\n", name
);
1923 printf_filtered ("from %s ", local_hex_string(low
));
1924 printf_filtered ("to %s:\n", local_hex_string(high
));
1926 /* Dump the specified range. */
1927 for (pc
= low
; pc
< high
; )
1930 print_address (pc
, stdout
);
1931 printf_filtered (":\t");
1932 pc
+= print_insn (pc
, stdout
);
1933 printf_filtered ("\n");
1935 printf_filtered ("End of assembler dump.\n");
1941 _initialize_printcmd ()
1943 current_display_number
= -1;
1945 add_info ("address", address_info
,
1946 "Describe where variable VAR is stored.");
1948 add_com ("x", class_vars
, x_command
,
1949 "Examine memory: x/FMT ADDRESS.\n\
1950 ADDRESS is an expression for the memory address to examine.\n\
1951 FMT is a repeat count followed by a format letter and a size letter.\n\
1952 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1953 f(float), a(address), i(instruction), c(char) and s(string).\n\
1954 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1955 g is meaningful only with f, for type double.\n\
1956 The specified number of objects of the specified size are printed\n\
1957 according to the format.\n\n\
1958 Defaults for format and size letters are those previously used.\n\
1959 Default count is 1. Default address is following last thing printed\n\
1960 with this command or \"print\".");
1962 add_com ("disassemble", class_vars
, disassemble_command
,
1963 "Disassemble a specified section of memory.\n\
1964 Default is the function surrounding the pc of the selected frame.\n\
1965 With a single argument, the function surrounding that address is dumped.\n\
1966 Two arguments are taken as a range of memory to dump.");
1968 add_com ("ptype", class_vars
, ptype_command
,
1969 "Print definition of type TYPE.\n\
1970 Argument may be a type name defined by typedef, or \"struct STRUCTNAME\"\n\
1971 or \"union UNIONNAME\" or \"enum ENUMNAME\".\n\
1972 The selected stack frame's lexical context is used to look up the name.");
1974 add_com ("whatis", class_vars
, whatis_command
,
1975 "Print data type of expression EXP.");
1978 add_com ("whereis", class_vars
, whereis_command
,
1979 "Print line number and file of definition of variable.");
1982 add_info ("display", display_info
,
1983 "Expressions to display when program stops, with code numbers.");
1985 add_cmd ("undisplay", class_vars
, undisplay_command
,
1986 "Cancel some expressions to be displayed when program stops.\n\
1987 Arguments are the code numbers of the expressions to stop displaying.\n\
1988 No argument means cancel all automatic-display expressions.\n\
1989 \"delete display\" has the same effect as this command.\n\
1990 Do \"info display\" to see current list of code numbers.",
1993 add_com ("display", class_vars
, display_command
,
1994 "Print value of expression EXP each time the program stops.\n\
1995 /FMT may be used before EXP as in the \"print\" command.\n\
1996 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
1997 as in the \"x\" command, and then EXP is used to get the address to examine\n\
1998 and examining is done as in the \"x\" command.\n\n\
1999 With no argument, display all currently requested auto-display expressions.\n\
2000 Use \"undisplay\" to cancel display requests previously made.");
2002 add_cmd ("display", class_vars
, enable_display
,
2003 "Enable some expressions to be displayed when program stops.\n\
2004 Arguments are the code numbers of the expressions to resume displaying.\n\
2005 No argument means enable all automatic-display expressions.\n\
2006 Do \"info display\" to see current list of code numbers.", &enablelist
);
2008 add_cmd ("display", class_vars
, disable_display_command
,
2009 "Disable some expressions to be displayed when program stops.\n\
2010 Arguments are the code numbers of the expressions to stop displaying.\n\
2011 No argument means disable all automatic-display expressions.\n\
2012 Do \"info display\" to see current list of code numbers.", &disablelist
);
2014 add_cmd ("display", class_vars
, undisplay_command
,
2015 "Cancel some expressions to be displayed when program stops.\n\
2016 Arguments are the code numbers of the expressions to stop displaying.\n\
2017 No argument means cancel all automatic-display expressions.\n\
2018 Do \"info display\" to see current list of code numbers.", &deletelist
);
2020 add_com ("printf", class_vars
, printf_command
,
2021 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2022 This is useful for formatted output in user-defined commands.");
2023 add_com ("output", class_vars
, output_command
,
2024 "Like \"print\" but don't put in value history and don't print newline.\n\
2025 This is useful in user-defined commands.");
2027 add_prefix_cmd ("set", class_vars
, set_command
,
2028 "Perform an assignment VAR = EXP.\n\
2029 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
2030 (names starting with $), a register (a few standard names starting with $),\n\
2031 or an actual variable in the program being debugged. EXP is any expression.\n\
2032 Use \"set variable\" for variables with names identical to set subcommands.\n\
2033 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2034 You can see these environment settings with the \"show\" command.",
2035 &setlist
, "set ", 1, &cmdlist
);
2037 /* "call" is the same as "set", but handy for dbx users to call fns. */
2038 add_com ("call", class_vars
, call_command
,
2039 "Call a function in the inferior process.\n\
2040 The argument is the function name and arguments, in the notation of the\n\
2041 current working language. The result is printed and saved in the value\n\
2042 history, if it is not void.");
2044 add_cmd ("variable", class_vars
, set_command
,
2045 "Perform an assignment VAR = EXP.\n\
2046 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
2047 (names starting with $), a register (a few standard names starting with $),\n\
2048 or an actual variable in the program being debugged. EXP is any expression.\n\
2049 This may usually be abbreviated to simply \"set\".",
2052 add_com ("print", class_vars
, print_command
,
2053 concat ("Print value of expression EXP.\n\
2054 Variables accessible are those of the lexical environment of the selected\n\
2055 stack frame, plus all those whose scope is global or an entire file.\n\
2057 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2058 $$NUM refers to NUM'th value back from the last one.\n\
2059 Names starting with $ refer to registers (with the values they would have\n\
2060 if the program were to return to the stack frame now selected, restoring\n\
2061 all registers saved by frames farther in) or else to debugger\n\
2062 \"convenience\" variables (any such name not a known register).\n\
2063 Use assignment expressions to give values to convenience variables.\n",
2065 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2066 @ is a binary operator for treating consecutive data objects\n\
2067 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2068 element is FOO, whose second element is stored in the space following\n\
2069 where FOO is stored, etc. FOO must be an expression whose value\n\
2070 resides in memory.\n",
2072 EXP may be preceded with /FMT, where FMT is a format letter\n\
2073 but no count or size letter (see \"x\" command).", NULL
));
2074 add_com_alias ("p", "print", class_vars
, 1);
2076 add_com ("inspect", class_vars
, inspect_command
,
2077 "Same as \"print\" command, except that if you are running in the epoch\n\
2078 environment, the value is printed in its own window.");