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"
32 extern int asm_demangle
; /* Whether to demangle syms in asm printouts */
33 extern int addressprint
; /* Whether to print hex addresses in HLL " */
35 extern struct block
*get_current_block ();
37 static void print_frame_nameless_args ();
46 /* Last specified output format. */
48 static char last_format
= 'x';
50 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
52 static char last_size
= 'w';
54 /* Default address to examine next. */
56 static CORE_ADDR next_address
;
58 /* Last address examined. */
60 static CORE_ADDR last_examine_address
;
62 /* Contents of last address examined.
63 This is not valid past the end of the `x' command! */
65 static value last_examine_value
;
67 /* Number of auto-display expression currently being displayed.
68 So that we can deleted it if we get an error or a signal within it.
69 -1 when not doing one. */
71 int current_display_number
;
73 /* Flag to low-level print routines that this value is being printed
74 in an epoch window. We'd like to pass this as a parameter, but
75 every routine would need to take it. Perhaps we can encapsulate
76 this in the I/O stream once we have GNU stdio. */
80 static void do_one_display ();
83 void print_scalar_formatted ();
86 /* Decode a format specification. *STRING_PTR should point to it.
87 OFORMAT and OSIZE are used as defaults for the format and size
88 if none are given in the format specification.
89 If OSIZE is zero, then the size field of the returned value
90 should be set only if a size is explicitly specified by the
92 The structure returned describes all the data
93 found in the specification. In addition, *STRING_PTR is advanced
94 past the specification and past all whitespace following it. */
97 decode_format (string_ptr
, oformat
, osize
)
102 struct format_data val
;
103 register char *p
= *string_ptr
;
109 if (*p
>= '0' && *p
<= '9')
110 val
.count
= atoi (p
);
111 while (*p
>= '0' && *p
<= '9') p
++;
113 /* Now process size or format letters that follow. */
117 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
126 else if (*p
>= 'a' && *p
<= 'z')
133 /* Make sure 'g' size is not used on integer types.
134 Well, actually, we can handle hex. */
135 if (val
.size
== 'g' && val
.format
!= 'f' && val
.format
!= 'x')
139 while (*p
== ' ' || *p
== '\t') p
++;
142 /* Set defaults for format and size if not specified. */
143 if (val
.format
== '?')
147 /* Neither has been specified. */
148 val
.format
= oformat
;
152 /* If a size is specified, any format makes a reasonable
153 default except 'i'. */
154 val
.format
= oformat
== 'i' ? 'x' : oformat
;
156 else if (val
.size
== '?')
161 /* Addresses must be words. */
162 val
.size
= osize
? 'w' : osize
;
165 /* Floating point has to be word or giantword. */
166 if (osize
== 'w' || osize
== 'g')
169 /* Default it to giantword if the last used size is not
171 val
.size
= osize
? 'g' : osize
;
174 /* Characters default to one byte. */
175 val
.size
= osize
? 'b' : osize
;
178 /* The default is the size most recently specified. */
185 /* Print value VAL on stdout according to FORMAT, a letter or 0.
186 Do not end with a newline.
187 0 means print VAL according to its own type.
188 SIZE is the letter for the size of datum being printed.
189 This is used to pad hex numbers so they line up. */
192 print_formatted (val
, format
, size
)
194 register char format
;
197 int len
= TYPE_LENGTH (VALUE_TYPE (val
));
199 if (VALUE_LVAL (val
) == lval_memory
)
200 next_address
= VALUE_ADDRESS (val
) + len
;
205 next_address
= VALUE_ADDRESS (val
)
206 + value_print (value_addr (val
), stdout
, format
, Val_pretty_default
);
210 wrap_here (""); /* Force output out, print_insn not using _filtered */
211 next_address
= VALUE_ADDRESS (val
)
212 + print_insn (VALUE_ADDRESS (val
), stdout
);
217 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_ARRAY
218 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_STRUCT
219 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_UNION
220 || VALUE_REPEATED (val
))
221 value_print (val
, stdout
, format
, Val_pretty_default
);
223 print_scalar_formatted (VALUE_CONTENTS (val
), VALUE_TYPE (val
),
224 format
, size
, stdout
);
228 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
229 according to letters FORMAT and SIZE on STREAM.
230 FORMAT may not be zero. Formats s and i are not supported at this level.
232 This is how the elements of an array or structure are printed
236 print_scalar_formatted (valaddr
, type
, format
, size
, stream
)
244 int len
= TYPE_LENGTH (type
);
246 if (size
== 'g' && sizeof (LONGEST
) < 8
249 /* ok, we're going to have to get fancy here. Assumption: a
250 long is four bytes. FIXME. */
251 unsigned long v1
, v2
;
253 v1
= unpack_long (builtin_type_long
, valaddr
);
254 v2
= unpack_long (builtin_type_long
, valaddr
+ 4);
256 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
257 /* Swap the two for printing */
270 fprintf_filtered (stream
, local_hex_format_custom("08x%08"), v1
, v2
);
273 error ("Output size \"g\" unimplemented for format \"%c\".",
279 val_long
= unpack_long (type
, valaddr
);
281 /* If value is unsigned, truncate it in case negative. */
284 if (len
== sizeof (char))
285 val_long
&= (1 << 8 * sizeof(char)) - 1;
286 else if (len
== sizeof (short))
287 val_long
&= (1 << 8 * sizeof(short)) - 1;
288 else if (len
== sizeof (long))
289 val_long
&= (unsigned long) - 1;
297 /* no size specified, like in print. Print varying # of digits. */
298 #if defined (LONG_LONG)
299 fprintf_filtered (stream
, local_hex_format_custom("ll"), val_long
);
300 #else /* not LONG_LONG. */
301 fprintf_filtered (stream
, local_hex_format_custom("l"), val_long
);
302 #endif /* not LONG_LONG. */
305 #if defined (LONG_LONG)
309 fprintf_filtered (stream
, local_hex_format_custom("02ll"), val_long
);
312 fprintf_filtered (stream
, local_hex_format_custom("04ll"), val_long
);
315 fprintf_filtered (stream
, local_hex_format_custom("08ll"), val_long
);
318 fprintf_filtered (stream
, local_hex_format_custom("016ll"), val_long
);
321 error ("Undefined output size \"%c\".", size
);
323 #else /* not LONG_LONG. */
327 fprintf_filtered (stream
, local_hex_format_custom("02"), val_long
);
330 fprintf_filtered (stream
, local_hex_format_custom("04"), val_long
);
333 fprintf_filtered (stream
, local_hex_format_custom("08"), val_long
);
336 fprintf_filtered (stream
, local_hex_format_custom("016"), val_long
);
339 error ("Undefined output size \"%c\".", size
);
341 #endif /* not LONG_LONG */
346 fprintf_filtered (stream
, "%lld", val_long
);
348 fprintf_filtered (stream
, "%d", val_long
);
354 fprintf_filtered (stream
, "%llu", val_long
);
356 fprintf_filtered (stream
, "%u", val_long
);
363 fprintf_filtered (stream
, local_octal_format_custom("ll"), val_long
);
365 fprintf_filtered (stream
, local_octal_format(), val_long
);
368 fprintf_filtered (stream
, "0");
372 print_address (unpack_pointer (type
, valaddr
), stream
);
376 value_print (value_from_longest (builtin_type_char
, val_long
), stream
, 0,
381 if (len
== sizeof (float))
382 type
= builtin_type_float
;
383 else if (len
== sizeof (double))
384 type
= builtin_type_double
;
385 print_floating (valaddr
, type
, stream
);
392 /* Binary; 't' stands for "two". */
394 char bits
[8*(sizeof val_long
) + 1];
399 width
= 8*(sizeof val_long
);
416 error ("Undefined output size \"%c\".", size
);
422 bits
[width
] = (val_long
& 1) ? '1' : '0';
427 while (*cp
&& *cp
== '0')
432 fprintf_filtered (stream
, cp
);
437 error ("Undefined output format \"%c\".", format
);
441 /* Specify default address for `x' command.
442 `info lines' uses this. */
445 set_next_address (addr
)
450 /* Make address available to the user as $_. */
451 set_internalvar (lookup_internalvar ("_"),
452 value_from_longest (lookup_pointer_type (builtin_type_void
),
456 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
457 after LEADIN. Print nothing if no symbolic name is found nearby.
458 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
459 or to interpret it as a possible C++ name and convert it back to source
463 print_address_symbolic (addr
, stream
, do_demangle
, leadin
)
470 register int i
= find_pc_misc_function (addr
);
472 /* If nothing comes out, don't print anything symbolic. */
477 fputs_filtered (leadin
, stream
);
478 fputs_filtered ("<", stream
);
480 fputs_demangled (misc_function_vector
[i
].name
, stream
, 1);
482 fputs_filtered (misc_function_vector
[i
].name
, stream
);
483 name_location
= misc_function_vector
[i
].address
;
484 if (addr
- name_location
)
485 fprintf_filtered (stream
, "+%d>", addr
- name_location
);
487 fputs_filtered (">", stream
);
490 /* Print address ADDR symbolically on STREAM.
491 First print it as a number. Then perhaps print
492 <SYMBOL + OFFSET> after the number. */
495 print_address (addr
, stream
)
499 fprintf_filtered (stream
, local_hex_format(), addr
);
500 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
503 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
504 controls whether to print the symbolic name "raw" or demangled.
505 Global setting "addressprint" controls whether to print hex address
509 print_address_demangle (addr
, stream
, do_demangle
)
515 fprintf_filtered (stream
, "0");
516 } else if (addressprint
) {
517 fprintf_filtered (stream
, local_hex_format(), addr
);
518 print_address_symbolic (addr
, stream
, do_demangle
, " ");
520 print_address_symbolic (addr
, stream
, do_demangle
, "");
525 /* Examine data at address ADDR in format FMT.
526 Fetch it from memory and print on stdout. */
529 do_examine (fmt
, addr
)
530 struct format_data fmt
;
533 register char format
= 0;
535 register int count
= 1;
536 struct type
*val_type
;
538 register int maxelts
;
545 /* String or instruction format implies fetch single bytes
546 regardless of the specified size. */
547 if (format
== 's' || format
== 'i')
551 val_type
= builtin_type_char
;
552 else if (size
== 'h')
553 val_type
= builtin_type_short
;
554 else if (size
== 'w')
555 val_type
= builtin_type_long
;
556 else if (size
== 'g')
558 val_type
= builtin_type_double
;
560 val_type
= builtin_type_long_long
;
568 if (format
== 's' || format
== 'i')
571 /* Print as many objects as specified in COUNT, at most maxelts per line,
572 with the address of the next one at the start of each line. */
576 print_address (next_address
, stdout
);
577 printf_filtered (":");
582 printf_filtered ("\t");
583 /* Note that print_formatted sets next_address for the next
585 last_examine_address
= next_address
;
586 last_examine_value
= value_at (val_type
, next_address
);
587 print_formatted (last_examine_value
, format
, size
);
589 printf_filtered ("\n");
595 validate_format (fmt
, cmdname
)
596 struct format_data fmt
;
600 error ("Size letters are meaningless in \"%s\" command.", cmdname
);
602 error ("Item count other than 1 is meaningless in \"%s\" command.",
604 if (fmt
.format
== 'i' || fmt
.format
== 's')
605 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
606 fmt
.format
, cmdname
);
610 print_command_1 (exp
, inspect
, voidprint
)
615 struct expression
*expr
;
616 register struct cleanup
*old_chain
= 0;
617 register char format
= 0;
619 struct format_data fmt
;
622 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
623 inspect_it
= inspect
;
625 if (exp
&& *exp
== '/')
628 fmt
= decode_format (&exp
, last_format
, 0);
629 validate_format (fmt
, "print");
630 last_format
= format
= fmt
.format
;
641 extern int objectprint
;
643 expr
= parse_expression (exp
);
644 old_chain
= make_cleanup (free_current_contents
, &expr
);
646 val
= evaluate_expression (expr
);
648 /* C++: figure out what type we actually want to print it as. */
649 type
= VALUE_TYPE (val
);
652 && (TYPE_CODE (type
) == TYPE_CODE_PTR
653 || TYPE_CODE (type
) == TYPE_CODE_REF
)
654 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
)
658 v
= value_from_vtable_info (val
, TYPE_TARGET_TYPE (type
));
662 type
= VALUE_TYPE (val
);
667 val
= access_value_history (0);
669 if (voidprint
|| (val
&& VALUE_TYPE (val
) &&
670 TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_VOID
))
672 int histindex
= record_latest_value (val
);
675 printf ("\031(gdb-makebuffer \"%s\" %d '(\"", exp
, histindex
);
677 if (histindex
>= 0) printf_filtered ("$%d = ", histindex
);
679 print_formatted (val
, format
, fmt
.size
);
680 printf_filtered ("\n");
686 do_cleanups (old_chain
);
687 inspect_it
= 0; /* Reset print routines to normal */
692 print_command (exp
, from_tty
)
696 print_command_1 (exp
, 0, 1);
699 /* Same as print, except in epoch, it gets its own window */
702 inspect_command (exp
, from_tty
)
706 extern int epoch_interface
;
708 print_command_1 (exp
, epoch_interface
, 1);
711 /* Same as print, except it doesn't print void results. */
714 call_command (exp
, from_tty
)
718 print_command_1 (exp
, 0, 0);
723 output_command (exp
, from_tty
)
727 struct expression
*expr
;
728 register struct cleanup
*old_chain
;
729 register char format
= 0;
731 struct format_data fmt
;
733 if (exp
&& *exp
== '/')
736 fmt
= decode_format (&exp
, 0, 0);
737 validate_format (fmt
, "print");
741 expr
= parse_expression (exp
);
742 old_chain
= make_cleanup (free_current_contents
, &expr
);
744 val
= evaluate_expression (expr
);
746 print_formatted (val
, format
, fmt
.size
);
748 do_cleanups (old_chain
);
753 set_command (exp
, from_tty
)
757 struct expression
*expr
= parse_expression (exp
);
758 register struct cleanup
*old_chain
759 = make_cleanup (free_current_contents
, &expr
);
760 evaluate_expression (expr
);
761 do_cleanups (old_chain
);
766 address_info (exp
, from_tty
)
770 register struct symbol
*sym
;
772 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
773 if exp is a field of `this'. */
776 error ("Argument required.");
778 sym
= lookup_symbol (exp
, get_selected_block (), VAR_NAMESPACE
,
779 &is_a_field_of_this
, (struct symtab
**)NULL
);
784 if (is_a_field_of_this
)
786 printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp
);
790 for (i
= 0; i
< misc_function_count
; i
++)
791 if (!strcmp (misc_function_vector
[i
].name
, exp
))
794 if (i
< misc_function_count
)
795 printf ("Symbol \"%s\" is at %s in a file compiled without debugging.\n",
796 exp
, local_hex_string(misc_function_vector
[i
].address
));
798 error ("No symbol \"%s\" in current context.", exp
);
802 printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym
));
803 val
= SYMBOL_VALUE (sym
);
805 switch (SYMBOL_CLASS (sym
))
808 case LOC_CONST_BYTES
:
813 printf ("a label at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym
)));
817 printf ("a variable in register %s", reg_names
[val
]);
821 printf ("static storage at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym
)));
825 printf ("an argument in register %s", reg_names
[val
]);
829 printf ("an argument at offset %ld", val
);
833 printf ("an argument at frame offset %ld", val
);
837 printf ("a local variable at frame offset %ld", val
);
841 printf ("a reference argument at offset %ld", val
);
845 printf ("a typedef");
849 printf ("a function at address %s",
850 local_hex_string(BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
854 printf ("of unknown (botched) type");
861 x_command (exp
, from_tty
)
865 struct expression
*expr
;
866 struct format_data fmt
;
867 struct cleanup
*old_chain
;
870 fmt
.format
= last_format
;
871 fmt
.size
= last_size
;
874 if (exp
&& *exp
== '/')
877 fmt
= decode_format (&exp
, last_format
, last_size
);
878 last_size
= fmt
.size
;
879 last_format
= fmt
.format
;
882 /* If we have an expression, evaluate it and use it as the address. */
884 if (exp
!= 0 && *exp
!= 0)
886 expr
= parse_expression (exp
);
887 /* Cause expression not to be there any more
888 if this command is repeated with Newline.
889 But don't clobber a user-defined command's definition. */
892 old_chain
= make_cleanup (free_current_contents
, &expr
);
893 val
= evaluate_expression (expr
);
894 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_REF
)
895 val
= value_ind (val
);
896 /* In rvalue contexts, such as this, functions are coerced into
897 pointers to functions. This makes "x/i main" work. */
898 if (/* last_format == 'i'
899 && */ TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FUNC
900 && VALUE_LVAL (val
) == lval_memory
)
901 next_address
= VALUE_ADDRESS (val
);
903 next_address
= value_as_pointer (val
);
904 do_cleanups (old_chain
);
907 do_examine (fmt
, next_address
);
909 /* Set a couple of internal variables if appropriate. */
910 if (last_examine_value
)
912 /* Make last address examined available to the user as $_. Use
913 the correct pointer type. */
914 set_internalvar (lookup_internalvar ("_"),
916 lookup_pointer_type (VALUE_TYPE (last_examine_value
)),
917 (LONGEST
) last_examine_address
));
919 /* Make contents of last address examined available to the user as $__.*/
920 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
924 /* Commands for printing types of things. */
926 /* Print type of EXP, or last thing in value history if EXP == NULL.
927 show is passed to type_print. */
929 whatis_exp (exp
, show
)
933 struct expression
*expr
;
935 register struct cleanup
*old_chain
;
939 expr
= parse_expression (exp
);
940 old_chain
= make_cleanup (free_current_contents
, &expr
);
941 val
= evaluate_type (expr
);
944 val
= access_value_history (0);
946 printf_filtered ("type = ");
947 type_print (VALUE_TYPE (val
), "", stdout
, show
);
948 printf_filtered ("\n");
951 do_cleanups (old_chain
);
956 whatis_command (exp
, from_tty
)
960 /* Most of the time users do not want to see all the fields
961 in a structure. If they do they can use the "ptype" command.
962 Hence the "-1" below. */
963 whatis_exp (exp
, -1);
966 /* Simple subroutine for ptype_command. */
970 struct expression
*exp
;
972 if(exp
->elts
[0].opcode
==OP_TYPE
)
973 return exp
->elts
[1].type
;
978 /* TYPENAME is either the name of a type, or an expression. */
981 ptype_command (typename
, from_tty
)
985 register struct type
*type
;
986 struct expression
*expr
;
987 register struct cleanup
*old_chain
;
991 expr
= parse_expression (typename
);
992 old_chain
= make_cleanup (free_current_contents
, &expr
);
993 type
= ptype_eval (expr
);
997 printf_filtered ("type = ");
998 type_print (type
, "", stdout
, 1);
999 printf_filtered ("\n");
1000 do_cleanups (old_chain
);
1004 do_cleanups (old_chain
);
1005 whatis_exp (typename
, 1);
1009 whatis_exp (typename
, 1);
1012 enum display_status
{disabled
, enabled
};
1016 /* Chain link to next auto-display item. */
1017 struct display
*next
;
1018 /* Expression to be evaluated and displayed. */
1019 struct expression
*exp
;
1020 /* Item number of this auto-display item. */
1022 /* Display format specified. */
1023 struct format_data format
;
1024 /* Innermost block required by this expression when evaluated */
1025 struct block
*block
;
1026 /* Status of this display (enabled or disabled) */
1027 enum display_status status
;
1030 /* Chain of expressions whose values should be displayed
1031 automatically each time the program stops. */
1033 static struct display
*display_chain
;
1035 static int display_number
;
1037 /* Add an expression to the auto-display chain.
1038 Specify the expression. */
1041 display_command (exp
, from_tty
)
1045 struct format_data fmt
;
1046 register struct expression
*expr
;
1047 register struct display
*new;
1058 fmt
= decode_format (&exp
, 0, 0);
1059 if (fmt
.size
&& fmt
.format
== 0)
1061 if (fmt
.format
== 'i' || fmt
.format
== 's')
1071 innermost_block
= 0;
1072 expr
= parse_expression (exp
);
1074 new = (struct display
*) xmalloc (sizeof (struct display
));
1077 new->block
= innermost_block
;
1078 new->next
= display_chain
;
1079 new->number
= ++display_number
;
1081 new->status
= enabled
;
1082 display_chain
= new;
1084 if (from_tty
&& target_has_execution
)
1085 do_one_display (new);
1098 /* Clear out the display_chain.
1099 Done when new symtabs are loaded, since this invalidates
1100 the types stored in many expressions. */
1105 register struct display
*d
;
1107 while (d
= display_chain
)
1110 display_chain
= d
->next
;
1115 /* Delete the auto-display number NUM. */
1118 delete_display (num
)
1121 register struct display
*d1
, *d
;
1124 error ("No display number %d.", num
);
1126 if (display_chain
->number
== num
)
1129 display_chain
= d1
->next
;
1133 for (d
= display_chain
; ; d
= d
->next
)
1136 error ("No display number %d.", num
);
1137 if (d
->next
->number
== num
)
1147 /* Delete some values from the auto-display chain.
1148 Specify the element numbers. */
1151 undisplay_command (args
)
1154 register char *p
= args
;
1160 if (query ("Delete all auto-display expressions? "))
1169 while (*p1
>= '0' && *p1
<= '9') p1
++;
1170 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1171 error ("Arguments must be display numbers.");
1175 delete_display (num
);
1178 while (*p
== ' ' || *p
== '\t') p
++;
1183 /* Display a single auto-display.
1184 Do nothing if the display cannot be printed in the current context,
1185 or if the display is disabled. */
1191 int within_current_scope
;
1193 if (d
->status
== disabled
)
1197 within_current_scope
= contained_in (get_selected_block (), d
->block
);
1199 within_current_scope
= 1;
1200 if (!within_current_scope
)
1203 current_display_number
= d
->number
;
1205 printf_filtered ("%d: ", d
->number
);
1210 printf_filtered ("x/");
1211 if (d
->format
.count
!= 1)
1212 printf_filtered ("%d", d
->format
.count
);
1213 printf_filtered ("%c", d
->format
.format
);
1214 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1215 printf_filtered ("%c", d
->format
.size
);
1216 printf_filtered (" ");
1217 print_expression (d
->exp
, stdout
);
1218 if (d
->format
.count
!= 1)
1219 printf_filtered ("\n");
1221 printf_filtered (" ");
1223 addr
= value_as_pointer (evaluate_expression (d
->exp
));
1224 if (d
->format
.format
== 'i')
1225 addr
= ADDR_BITS_REMOVE (addr
);
1227 do_examine (d
->format
, addr
);
1231 if (d
->format
.format
)
1232 printf_filtered ("/%c ", d
->format
.format
);
1233 print_expression (d
->exp
, stdout
);
1234 printf_filtered (" = ");
1235 print_formatted (evaluate_expression (d
->exp
),
1236 d
->format
.format
, d
->format
.size
);
1237 printf_filtered ("\n");
1241 current_display_number
= -1;
1244 /* Display all of the values on the auto-display chain which can be
1245 evaluated in the current scope. */
1250 register struct display
*d
;
1252 for (d
= display_chain
; d
; d
= d
->next
)
1256 /* Delete the auto-display which we were in the process of displaying.
1257 This is done when there is an error or a signal. */
1260 disable_display (num
)
1263 register struct display
*d
;
1265 for (d
= display_chain
; d
; d
= d
->next
)
1266 if (d
->number
== num
)
1268 d
->status
= disabled
;
1271 printf ("No display number %d.\n", num
);
1275 disable_current_display ()
1277 if (current_display_number
>= 0)
1279 disable_display (current_display_number
);
1280 fprintf (stderr
, "Disabling display %d to avoid infinite recursion.\n",
1281 current_display_number
);
1283 current_display_number
= -1;
1289 register struct display
*d
;
1292 printf ("There are no auto-display expressions now.\n");
1294 printf_filtered ("Auto-display expressions now in effect:\n\
1295 Num Enb Expression\n");
1297 for (d
= display_chain
; d
; d
= d
->next
)
1299 printf_filtered ("%d: %c ", d
->number
, "ny"[(int)d
->status
]);
1301 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1303 else if (d
->format
.format
)
1304 printf_filtered ("/%c ", d
->format
.format
);
1305 print_expression (d
->exp
, stdout
);
1306 if (d
->block
&& !contained_in (get_selected_block (), d
->block
))
1307 printf_filtered (" (cannot be evaluated in the current context)");
1308 printf_filtered ("\n");
1314 enable_display (args
)
1317 register char *p
= args
;
1320 register struct display
*d
;
1324 for (d
= display_chain
; d
; d
= d
->next
)
1325 d
->status
= enabled
;
1331 while (*p1
>= '0' && *p1
<= '9')
1333 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1334 error ("Arguments must be display numbers.");
1338 for (d
= display_chain
; d
; d
= d
->next
)
1339 if (d
->number
== num
)
1341 d
->status
= enabled
;
1344 printf ("No display number %d.\n", num
);
1347 while (*p
== ' ' || *p
== '\t')
1354 disable_display_command (args
, from_tty
)
1358 register char *p
= args
;
1360 register struct display
*d
;
1364 for (d
= display_chain
; d
; d
= d
->next
)
1365 d
->status
= disabled
;
1371 while (*p1
>= '0' && *p1
<= '9')
1373 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1374 error ("Arguments must be display numbers.");
1376 disable_display (atoi (p
));
1379 while (*p
== ' ' || *p
== '\t')
1385 /* Print the value in stack frame FRAME of a variable
1386 specified by a struct symbol. */
1389 print_variable_value (var
, frame
, stream
)
1394 value val
= read_var_value (var
, frame
);
1395 value_print (val
, stream
, 0, Val_pretty_default
);
1398 /* Print the arguments of a stack frame, given the function FUNC
1399 running in that frame (as a symbol), the info on the frame,
1400 and the number of args according to the stack frame (or -1 if unknown). */
1402 /* References here and elsewhere to "number of args according to the
1403 stack frame" appear in all cases to refer to "number of ints of args
1404 according to the stack frame". At least for VAX, i386, isi. */
1407 print_frame_args (func
, fi
, num
, stream
)
1408 struct symbol
*func
;
1409 struct frame_info
*fi
;
1417 register struct symbol
*sym
;
1419 /* Offset of next stack argument beyond the one we have seen that is
1420 at the highest offset.
1421 -1 if we haven't come to a stack argument yet. */
1422 long highest_offset
= -1;
1424 /* Number of ints of arguments that we have printed so far. */
1425 int args_printed
= 0;
1429 b
= SYMBOL_BLOCK_VALUE (func
);
1430 nsyms
= BLOCK_NSYMS (b
);
1433 for (i
= 0; i
< nsyms
; i
++)
1436 sym
= BLOCK_SYM (b
, i
);
1438 /* Keep track of the highest stack argument offset seen, and
1439 skip over any kinds of symbols we don't care about. */
1441 switch (SYMBOL_CLASS (sym
)) {
1445 long current_offset
= SYMBOL_VALUE (sym
);
1447 arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
1449 /* Compute address of next argument by adding the size of
1450 this argument and rounding to an int boundary. */
1452 = ((current_offset
+ arg_size
+ sizeof (int) - 1)
1453 & ~(sizeof (int) - 1));
1455 /* If this is the highest offset seen yet, set highest_offset. */
1456 if (highest_offset
== -1
1457 || (current_offset
> highest_offset
))
1458 highest_offset
= current_offset
;
1460 /* Add the number of ints we're about to print to args_printed. */
1461 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
1464 /* We care about types of symbols, but don't need to keep track of
1465 stack offsets in them. */
1470 /* Other types of symbols we just skip over. */
1475 /* We have to re-look-up the symbol because arguments often have
1476 two entries (one a parameter, one a register or local), and the one
1477 we want is the non-parm, which lookup_symbol will find for
1478 us. After this, sym could be any SYMBOL_CLASS... */
1479 sym
= lookup_symbol (SYMBOL_NAME (sym
),
1480 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
1482 /* Print the current arg. */
1484 fprintf_filtered (stream
, ", ");
1486 fprint_symbol (stream
, SYMBOL_NAME (sym
));
1487 fputs_filtered ("=", stream
);
1489 /* Avoid value_print because it will deref ref parameters. We just
1490 want to print their addresses. Print ??? for args whose address
1491 we do not know. We pass 2 as "recurse" to val_print because our
1492 standard indentation here is 4 spaces, and val_print indents
1493 2 for each recurse. */
1494 val
= read_var_value (sym
, FRAME_INFO_ID (fi
));
1496 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), VALUE_ADDRESS (val
),
1497 stream
, 0, 0, 2, Val_no_prettyprint
);
1499 fputs_filtered ("???", stream
);
1503 /* Don't print nameless args in situations where we don't know
1504 enough about the stack to find them. */
1510 if (highest_offset
== -1)
1511 start
= FRAME_ARGS_SKIP
;
1513 start
= highest_offset
;
1515 addr
= FRAME_ARGS_ADDRESS (fi
);
1517 print_frame_nameless_args (addr
, start
, num
- args_printed
,
1522 /* Print nameless args on STREAM.
1523 ARGSADDR is the address of the arglist, START is the offset
1524 of the first nameless arg, and NUM is the number of nameless args to
1525 print. FIRST is nonzero if this is the first argument (not just
1526 the first nameless arg). */
1528 print_frame_nameless_args (argsaddr
, start
, num
, first
, stream
)
1536 for (i
= 0; i
< num
; i
++)
1540 fprintf_filtered (stream
, ", ");
1541 #ifndef PRINT_TYPELESS_INTEGER
1542 fprintf_filtered (stream
, "%d",
1543 read_memory_integer (argsaddr
+ start
, sizeof (int)));
1545 PRINT_TYPELESS_INTEGER (stream
, builtin_type_int
,
1547 read_memory_integer (argsaddr
+ start
,
1551 start
+= sizeof (int);
1557 printf_command (arg
, from_tty
)
1562 register char *s
= arg
;
1566 int allocated_args
= 20;
1569 val_args
= (value
*) xmalloc (allocated_args
* sizeof (value
));
1572 error_no_arg ("format-control string and values to print");
1574 /* Skip white space before format string */
1575 while (*s
== ' ' || *s
== '\t') s
++;
1577 /* A format string should follow, enveloped in double quotes */
1579 error ("Bad format string, missing '\"'.");
1581 /* Parse the format-control string and copy it into the string STRING,
1582 processing some kinds of escape sequence. */
1584 f
= string
= (char *) alloca (strlen (s
) + 1);
1591 error ("Bad format string, non-terminated '\"'.");
1592 /* doesn't return */
1613 /* ??? TODO: handle other escape sequences */
1614 error ("Unrecognized \\ escape character in format string.");
1623 /* Skip over " and following space and comma. */
1626 while (*s
== ' ' || *s
== '\t') s
++;
1628 if (*s
!= ',' && *s
!= 0)
1629 error ("Invalid argument syntax");
1632 while (*s
== ' ' || *s
== '\t') s
++;
1635 /* Now scan the string for %-specs and see what kinds of args they want.
1636 argclass[I] classifies the %-specs so we can give vprintf something
1637 of the right size. */
1639 enum argclass
{int_arg
, string_arg
, double_arg
, long_long_arg
};
1640 enum argclass
*argclass
;
1646 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1653 while (strchr ("0123456789.hlL-+ #", *f
))
1655 if (*f
== 'l' || *f
== 'L')
1660 argclass
[nargs_wanted
++] = string_arg
;
1661 else if (*f
== 'e' || *f
== 'f' || *f
== 'g')
1662 argclass
[nargs_wanted
++] = double_arg
;
1663 else if (lcount
> 1)
1664 argclass
[nargs_wanted
++] = long_long_arg
;
1666 argclass
[nargs_wanted
++] = int_arg
;
1670 /* Now, parse all arguments and evaluate them.
1671 Store the VALUEs in VAL_ARGS. */
1676 if (nargs
== allocated_args
)
1677 val_args
= (value
*) xrealloc (val_args
,
1678 (allocated_args
*= 2)
1681 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
1683 /* If format string wants a float, unchecked-convert the value to
1684 floating point of the same size */
1686 if (argclass
[nargs
] == double_arg
)
1688 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (float))
1689 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
1690 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (double))
1691 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
1699 if (nargs
!= nargs_wanted
)
1700 error ("Wrong number of arguments for specified format-string");
1702 /* Now lay out an argument-list containing the arguments
1703 as doubles, integers and C pointers. */
1705 arg_bytes
= (char *) alloca (sizeof (double) * nargs
);
1707 for (i
= 0; i
< nargs
; i
++)
1709 if (argclass
[i
] == string_arg
)
1714 tem
= value_as_pointer (val_args
[i
]);
1716 /* This is a %s argument. Find the length of the string. */
1721 read_memory (tem
+ j
, &c
, 1);
1726 /* Copy the string contents into a string inside GDB. */
1727 str
= (char *) alloca (j
+ 1);
1728 read_memory (tem
, str
, j
);
1731 /* Pass address of internal copy as the arg to vprintf. */
1732 *((int *) &arg_bytes
[argindex
]) = (int) str
;
1733 argindex
+= sizeof (int);
1735 else if (VALUE_TYPE (val_args
[i
])->code
== TYPE_CODE_FLT
)
1737 *((double *) &arg_bytes
[argindex
]) = value_as_double (val_args
[i
]);
1738 argindex
+= sizeof (double);
1742 if (argclass
[i
] == long_long_arg
)
1744 *(long long *) &arg_bytes
[argindex
] = value_as_long (val_args
[i
]);
1745 argindex
+= sizeof (long long);
1750 *((long *) &arg_bytes
[argindex
]) = value_as_long (val_args
[i
]);
1751 argindex
+= sizeof (long);
1756 /* There is not a standard way to make a va_list, so we need
1757 to do various things for different systems. */
1758 #if defined (__INT_VARARGS_H)
1763 list
.__va_stk
= (int *) arg_bytes
;
1764 list
.__va_reg
= (int *) arg_bytes
;
1765 vprintf (string
, list
);
1767 #else /* No __INT_VARARGS_H. */
1768 vprintf (string
, arg_bytes
);
1769 #endif /* No __INT_VARARGS_H. */
1772 /* Helper function for asdump_command. Finds the bounds of a function
1773 for a specified section of text. PC is an address within the
1774 function which you want bounds for; *LOW and *HIGH are set to the
1775 beginning (inclusive) and end (exclusive) of the function. This
1776 function returns 1 on success and 0 on failure. */
1779 containing_function_bounds (pc
, low
, high
)
1780 CORE_ADDR pc
, *low
, *high
;
1784 if (!find_pc_partial_function (pc
, 0, low
))
1790 if (!find_pc_partial_function (scan
, 0, high
))
1792 } while (*low
== *high
);
1797 /* Dump a specified section of assembly code. With no command line
1798 arguments, this command will dump the assembly code for the
1799 function surrounding the pc value in the selected frame. With one
1800 argument, it will dump the assembly code surrounding that pc value.
1801 Two arguments are interpeted as bounds within which to dump
1806 disassemble_command (arg
, from_tty
)
1810 CORE_ADDR low
, high
;
1816 if (!selected_frame
)
1817 error ("No frame selected.\n");
1819 pc
= get_frame_pc (selected_frame
);
1820 if (!containing_function_bounds (pc
, &low
, &high
))
1821 error ("No function contains pc specified by selected frame.\n");
1823 else if (!(space_index
= (char *) strchr (arg
, ' ')))
1826 pc
= parse_and_eval_address (arg
);
1827 if (!containing_function_bounds (pc
, &low
, &high
))
1828 error ("No function contains specified pc.\n");
1832 /* Two arguments. */
1833 *space_index
= '\0';
1834 low
= parse_and_eval_address (arg
);
1835 high
= parse_and_eval_address (space_index
+ 1);
1838 printf_filtered ("Dump of assembler code ");
1842 find_pc_partial_function (pc
, &name
, 0);
1843 printf_filtered ("for function %s:\n", name
);
1846 printf_filtered ("from %s ", local_hex_string(low
));
1847 printf_filtered ("to %s:\n", local_hex_string(high
));
1849 /* Dump the specified range. */
1850 for (pc
= low
; pc
< high
; )
1853 print_address (pc
, stdout
);
1854 printf_filtered (":\t");
1855 pc
+= print_insn (pc
, stdout
);
1856 printf_filtered ("\n");
1858 printf_filtered ("End of assembler dump.\n");
1864 _initialize_printcmd ()
1866 current_display_number
= -1;
1868 add_info ("address", address_info
,
1869 "Describe where variable VAR is stored.");
1871 add_com ("x", class_vars
, x_command
,
1872 "Examine memory: x/FMT ADDRESS.\n\
1873 ADDRESS is an expression for the memory address to examine.\n\
1874 FMT is a repeat count followed by a format letter and a size letter.\n\
1875 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1876 f(float), a(address), i(instruction), c(char) and s(string).\n\
1877 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1878 g is meaningful only with f, for type double.\n\
1879 The specified number of objects of the specified size are printed\n\
1880 according to the format.\n\n\
1881 Defaults for format and size letters are those previously used.\n\
1882 Default count is 1. Default address is following last thing printed\n\
1883 with this command or \"print\".");
1885 add_com ("disassemble", class_vars
, disassemble_command
,
1886 "Disassemble a specified section of memory.\n\
1887 Default is the function surrounding the pc of the selected frame.\n\
1888 With a single argument, the function surrounding that address is dumped.\n\
1889 Two arguments are taken as a range of memory to dump.");
1891 add_com ("ptype", class_vars
, ptype_command
,
1892 "Print definition of type TYPE.\n\
1893 Argument may be a type name defined by typedef, or \"struct STRUCTNAME\"\n\
1894 or \"union UNIONNAME\" or \"enum ENUMNAME\".\n\
1895 The selected stack frame's lexical context is used to look up the name.");
1897 add_com ("whatis", class_vars
, whatis_command
,
1898 "Print data type of expression EXP.");
1901 add_com ("whereis", class_vars
, whereis_command
,
1902 "Print line number and file of definition of variable.");
1905 add_info ("display", display_info
,
1906 "Expressions to display when program stops, with code numbers.");
1908 add_cmd ("undisplay", class_vars
, undisplay_command
,
1909 "Cancel some expressions to be displayed when program stops.\n\
1910 Arguments are the code numbers of the expressions to stop displaying.\n\
1911 No argument means cancel all automatic-display expressions.\n\
1912 \"delete display\" has the same effect as this command.\n\
1913 Do \"info display\" to see current list of code numbers.",
1916 add_com ("display", class_vars
, display_command
,
1917 "Print value of expression EXP each time the program stops.\n\
1918 /FMT may be used before EXP as in the \"print\" command.\n\
1919 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
1920 as in the \"x\" command, and then EXP is used to get the address to examine\n\
1921 and examining is done as in the \"x\" command.\n\n\
1922 With no argument, display all currently requested auto-display expressions.\n\
1923 Use \"undisplay\" to cancel display requests previously made.");
1925 add_cmd ("display", class_vars
, enable_display
,
1926 "Enable some expressions to be displayed when program stops.\n\
1927 Arguments are the code numbers of the expressions to resume displaying.\n\
1928 No argument means enable all automatic-display expressions.\n\
1929 Do \"info display\" to see current list of code numbers.", &enablelist
);
1931 add_cmd ("display", class_vars
, disable_display_command
,
1932 "Disable some expressions to be displayed when program stops.\n\
1933 Arguments are the code numbers of the expressions to stop displaying.\n\
1934 No argument means disable all automatic-display expressions.\n\
1935 Do \"info display\" to see current list of code numbers.", &disablelist
);
1937 add_cmd ("display", class_vars
, undisplay_command
,
1938 "Cancel some expressions to be displayed when program stops.\n\
1939 Arguments are the code numbers of the expressions to stop displaying.\n\
1940 No argument means cancel all automatic-display expressions.\n\
1941 Do \"info display\" to see current list of code numbers.", &deletelist
);
1943 add_com ("printf", class_vars
, printf_command
,
1944 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
1945 This is useful for formatted output in user-defined commands.");
1946 add_com ("output", class_vars
, output_command
,
1947 "Like \"print\" but don't put in value history and don't print newline.\n\
1948 This is useful in user-defined commands.");
1950 add_prefix_cmd ("set", class_vars
, set_command
,
1951 "Perform an assignment VAR = EXP.\n\
1952 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
1953 (names starting with $), a register (a few standard names starting with $),\n\
1954 or an actual variable in the program being debugged. EXP is any expression.\n\
1955 Use \"set variable\" for variables with names identical to set subcommands.\n\
1956 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
1957 You can see these environment settings with the \"show\" command.",
1958 &setlist
, "set ", 1, &cmdlist
);
1960 /* "call" is the same as "set", but handy for dbx users to call fns. */
1961 add_com ("call", class_vars
, call_command
,
1962 "Call a function in the inferior process.\n\
1963 The argument is the function name and arguments, in the notation of the\n\
1964 current working language. The result is printed and saved in the value\n\
1965 history, if it is not void.");
1967 add_cmd ("variable", class_vars
, set_command
,
1968 "Perform an assignment VAR = EXP.\n\
1969 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
1970 (names starting with $), a register (a few standard names starting with $),\n\
1971 or an actual variable in the program being debugged. EXP is any expression.\n\
1972 This may usually be abbreviated to simply \"set\".",
1975 add_com ("print", class_vars
, print_command
,
1976 concat ("Print value of expression EXP.\n\
1977 Variables accessible are those of the lexical environment of the selected\n\
1978 stack frame, plus all those whose scope is global or an entire file.\n\
1980 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
1981 $$NUM refers to NUM'th value back from the last one.\n\
1982 Names starting with $ refer to registers (with the values they would have\n\
1983 if the program were to return to the stack frame now selected, restoring\n\
1984 all registers saved by frames farther in) or else to debugger\n\
1985 \"convenience\" variables (any such name not a known register).\n\
1986 Use assignment expressions to give values to convenience variables.\n",
1988 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
1989 @ is a binary operator for treating consecutive data objects\n\
1990 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
1991 element is FOO, whose second element is stored in the space following\n\
1992 where FOO is stored, etc. FOO must be an expression whose value\n\
1993 resides in memory.\n",
1995 EXP may be preceded with /FMT, where FMT is a format letter\n\
1996 but no count or size letter (see \"x\" command).", NULL
));
1997 add_com_alias ("p", "print", class_vars
, 1);
1999 add_com ("inspect", class_vars
, inspect_command
,
2000 "Same as \"print\" command, except that if you are running in the epoch\n\
2001 environment, the value is printed in its own window.");