1 /* Print values for GNU debugger GDB.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 GDB 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 1, or (at your option)
11 GDB 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 GDB; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "expression.h"
32 extern int asm_demangle
; /* Whether to demangle syms in asm printouts */
34 extern struct block
*get_current_block ();
36 static void print_frame_nameless_args ();
45 /* Last specified output format. */
47 static char last_format
= 'x';
49 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
51 static char last_size
= 'w';
53 /* Default address to examine next. */
55 static CORE_ADDR next_address
;
57 /* Last address examined. */
59 static CORE_ADDR last_examine_address
;
61 /* Contents of last address examined.
62 This is not valid past the end of the `x' command! */
64 static value last_examine_value
;
66 /* Number of auto-display expression currently being displayed.
67 So that we can deleted it if we get an error or a signal within it.
68 -1 when not doing one. */
70 int current_display_number
;
72 /* Flag to low-level print routines that this value is being printed
73 in an epoch window. We'd like to pass this as a parameter, but
74 every routine would need to take it. Perhaps we can encapsulate
75 this in the I/O stream once we have GNU stdio. */
79 static void do_one_display ();
82 void print_scalar_formatted ();
85 /* Decode a format specification. *STRING_PTR should point to it.
86 OFORMAT and OSIZE are used as defaults for the format and size
87 if none are given in the format specification.
88 If OSIZE is zero, then the size field of the returned value
89 should be set only if a size is explicitly specified by the
91 The structure returned describes all the data
92 found in the specification. In addition, *STRING_PTR is advanced
93 past the specification and past all whitespace following it. */
96 decode_format (string_ptr
, oformat
, osize
)
101 struct format_data val
;
102 register char *p
= *string_ptr
;
108 if (*p
>= '0' && *p
<= '9')
109 val
.count
= atoi (p
);
110 while (*p
>= '0' && *p
<= '9') p
++;
112 /* Now process size or format letters that follow. */
116 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
125 else if (*p
>= 'a' && *p
<= 'z')
132 /* Make sure 'g' size is not used on integer types.
133 Well, actually, we can handle hex. */
134 if (val
.size
== 'g' && val
.format
!= 'f' && val
.format
!= 'x')
138 while (*p
== ' ' || *p
== '\t') p
++;
141 /* Set defaults for format and size if not specified. */
142 if (val
.format
== '?')
146 /* Neither has been specified. */
147 val
.format
= oformat
;
151 /* If a size is specified, any format makes a reasonable
152 default except 'i'. */
153 val
.format
= oformat
== 'i' ? 'x' : oformat
;
155 else if (val
.size
== '?')
160 /* Addresses must be words. */
161 val
.size
= osize
? 'w' : osize
;
164 /* Floating point has to be word or giantword. */
165 if (osize
== 'w' || osize
== 'g')
168 /* Default it to giantword if the last used size is not
170 val
.size
= osize
? 'g' : osize
;
173 /* Characters default to one byte. */
174 val
.size
= osize
? 'b' : osize
;
177 /* The default is the size most recently specified. */
184 /* Print value VAL on stdout according to FORMAT, a letter or 0.
185 Do not end with a newline.
186 0 means print VAL according to its own type.
187 SIZE is the letter for the size of datum being printed.
188 This is used to pad hex numbers so they line up. */
191 print_formatted (val
, format
, size
)
193 register char format
;
196 int len
= TYPE_LENGTH (VALUE_TYPE (val
));
198 if (VALUE_LVAL (val
) == lval_memory
)
199 next_address
= VALUE_ADDRESS (val
) + len
;
204 next_address
= VALUE_ADDRESS (val
)
205 + value_print (value_addr (val
), stdout
, format
, Val_pretty_default
);
209 next_address
= VALUE_ADDRESS (val
)
210 + print_insn (VALUE_ADDRESS (val
), stdout
);
215 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_ARRAY
216 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_STRUCT
217 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_UNION
218 || VALUE_REPEATED (val
))
219 value_print (val
, stdout
, format
, Val_pretty_default
);
221 print_scalar_formatted (VALUE_CONTENTS (val
), VALUE_TYPE (val
),
222 format
, size
, stdout
);
226 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
227 according to letters FORMAT and SIZE on STREAM.
228 FORMAT may not be zero. Formats s and i are not supported at this level.
230 This is how the elements of an array or structure are printed
234 print_scalar_formatted (valaddr
, type
, format
, size
, stream
)
242 int len
= TYPE_LENGTH (type
);
244 if (size
== 'g' && sizeof (LONGEST
) < 8
247 /* ok, we're going to have to get fancy here. Assumption: a
248 long is four bytes. FIXME. */
249 unsigned long v1
, v2
, tmp
;
251 v1
= unpack_long (builtin_type_long
, valaddr
);
252 v2
= unpack_long (builtin_type_long
, valaddr
+ 4);
254 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
255 /* Swap the two for printing */
264 fprintf_filtered (stream
, "0x%08x%08x", v1
, v2
);
267 error ("Output size \"g\" unimplemented for format \"%c\".",
273 val_long
= unpack_long (type
, valaddr
);
275 /* If value is unsigned, truncate it in case negative. */
278 if (len
== sizeof (char))
279 val_long
&= (1 << 8 * sizeof(char)) - 1;
280 else if (len
== sizeof (short))
281 val_long
&= (1 << 8 * sizeof(short)) - 1;
282 else if (len
== sizeof (long))
283 val_long
&= (unsigned long) - 1;
291 /* no size specified, like in print. Print varying # of digits. */
292 #if defined (LONG_LONG)
293 fprintf_filtered (stream
, "0x%llx", val_long
);
294 #else /* not LONG_LONG. */
295 fprintf_filtered (stream
, "0x%lx", val_long
);
296 #endif /* not LONG_LONG. */
299 #if defined (LONG_LONG)
303 fprintf_filtered (stream
, "0x%02llx", val_long
);
306 fprintf_filtered (stream
, "0x%04llx", val_long
);
309 fprintf_filtered (stream
, "0x%08llx", val_long
);
312 fprintf_filtered (stream
, "0x%016llx", val_long
);
315 error ("Undefined output size \"%c\".", size
);
317 #else /* not LONG_LONG. */
321 fprintf_filtered (stream
, "0x%02x", val_long
);
324 fprintf_filtered (stream
, "0x%04x", val_long
);
327 fprintf_filtered (stream
, "0x%08x", val_long
);
330 fprintf_filtered (stream
, "0x%016x", val_long
);
333 error ("Undefined output size \"%c\".", size
);
335 #endif /* not LONG_LONG */
340 fprintf_filtered (stream
, "%lld", val_long
);
342 fprintf_filtered (stream
, "%d", val_long
);
348 fprintf_filtered (stream
, "%llu", val_long
);
350 fprintf_filtered (stream
, "%u", val_long
);
357 fprintf_filtered (stream
, "0%llo", val_long
);
359 fprintf_filtered (stream
, "0%o", val_long
);
362 fprintf_filtered (stream
, "0");
366 print_address (unpack_pointer (type
, valaddr
), stream
);
370 value_print (value_from_long (builtin_type_char
, val_long
), stream
, 0,
375 if (len
== sizeof (float))
376 type
= builtin_type_float
;
377 else if (len
== sizeof (double))
378 type
= builtin_type_double
;
379 print_floating (valaddr
, type
, stream
);
386 /* Binary; 't' stands for "two". */
388 char bits
[8*(sizeof val_long
) + 1];
393 width
= 8*(sizeof val_long
);
410 error ("Undefined output size \"%c\".", size
);
416 bits
[width
] = (val_long
& 1) ? '1' : '0';
421 while (*cp
&& *cp
== '0')
426 fprintf_filtered (stream
, cp
);
431 error ("Undefined output format \"%c\".", format
);
435 /* Specify default address for `x' command.
436 `info lines' uses this. */
439 set_next_address (addr
)
444 /* Make address available to the user as $_. */
445 set_internalvar (lookup_internalvar ("_"),
446 value_from_long (builtin_type_int
, (LONGEST
) addr
));
449 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM.
450 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
451 or to interpret it as a possible C++ name and convert it back to source
455 print_address_symbolic (addr
, stream
, do_demangle
)
461 register int i
= find_pc_misc_function (addr
);
463 /* If nothing comes out, don't print anything symbolic. */
468 fputs_filtered (" <", stream
);
470 fputs_demangled (misc_function_vector
[i
].name
, stream
, 1);
472 fputs_filtered (misc_function_vector
[i
].name
, stream
);
473 name_location
= misc_function_vector
[i
].address
;
474 if (addr
- name_location
)
475 fprintf_filtered (stream
, "+%d>", addr
- name_location
);
477 fputs_filtered (">", stream
);
480 /* Print address ADDR symbolically on STREAM.
481 First print it as a number. Then perhaps print
482 <SYMBOL + OFFSET> after the number. */
485 print_address (addr
, stream
)
489 fprintf_filtered (stream
, "0x%x", addr
);
490 print_address_symbolic (addr
, stream
, asm_demangle
);
493 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
494 controls whether to print the symbolic name "raw" or demangled. */
497 print_address_demangle (addr
, stream
, do_demangle
)
502 fprintf_filtered (stream
, "0x%x", addr
);
503 print_address_symbolic (addr
, stream
, do_demangle
);
508 /* Examine data at address ADDR in format FMT.
509 Fetch it from memory and print on stdout. */
512 do_examine (fmt
, addr
)
513 struct format_data fmt
;
516 register char format
= 0;
518 register int count
= 1;
519 struct type
*val_type
;
521 register int maxelts
;
528 /* String or instruction format implies fetch single bytes
529 regardless of the specified size. */
530 if (format
== 's' || format
== 'i')
534 val_type
= builtin_type_char
;
535 else if (size
== 'h')
536 val_type
= builtin_type_short
;
537 else if (size
== 'w')
538 val_type
= builtin_type_long
;
539 else if (size
== 'g')
541 val_type
= builtin_type_double
;
543 val_type
= builtin_type_long_long
;
551 if (format
== 's' || format
== 'i')
554 /* Print as many objects as specified in COUNT, at most maxelts per line,
555 with the address of the next one at the start of each line. */
559 print_address (next_address
, stdout
);
560 printf_filtered (":");
565 printf_filtered ("\t");
566 /* Note that print_formatted sets next_address for the next
568 last_examine_address
= next_address
;
569 last_examine_value
= value_at (val_type
, next_address
);
570 print_formatted (last_examine_value
, format
, size
);
572 printf_filtered ("\n");
578 validate_format (fmt
, cmdname
)
579 struct format_data fmt
;
583 error ("Size letters are meaningless in \"%s\" command.", cmdname
);
585 error ("Item count other than 1 is meaningless in \"%s\" command.",
587 if (fmt
.format
== 'i' || fmt
.format
== 's')
588 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
589 fmt
.format
, cmdname
);
593 print_command_1 (exp
, inspect
, voidprint
)
598 struct expression
*expr
;
599 register struct cleanup
*old_chain
= 0;
600 register char format
= 0;
602 struct format_data fmt
;
605 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
606 inspect_it
= inspect
;
608 if (exp
&& *exp
== '/')
611 fmt
= decode_format (&exp
, last_format
, 0);
612 validate_format (fmt
, "print");
613 last_format
= format
= fmt
.format
;
624 extern int objectprint
;
626 expr
= parse_c_expression (exp
);
627 old_chain
= make_cleanup (free_current_contents
, &expr
);
629 val
= evaluate_expression (expr
);
631 /* C++: figure out what type we actually want to print it as. */
632 type
= VALUE_TYPE (val
);
635 && (TYPE_CODE (type
) == TYPE_CODE_PTR
636 || TYPE_CODE (type
) == TYPE_CODE_REF
)
637 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
)
641 v
= value_from_vtable_info (val
, TYPE_TARGET_TYPE (type
));
645 type
= VALUE_TYPE (val
);
650 val
= access_value_history (0);
652 if (voidprint
|| (val
&& VALUE_TYPE (val
) &&
653 TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_VOID
))
655 int histindex
= record_latest_value (val
);
658 printf ("\031(gdb-makebuffer \"%s\" %d '(\"", exp
, histindex
);
660 if (histindex
>= 0) printf_filtered ("$%d = ", histindex
);
662 print_formatted (val
, format
, fmt
.size
);
663 printf_filtered ("\n");
669 do_cleanups (old_chain
);
670 inspect_it
= 0; /* Reset print routines to normal */
675 print_command (exp
, from_tty
)
679 print_command_1 (exp
, 0, 1);
682 /* Same as print, except in epoch, it gets its own window */
685 inspect_command (exp
, from_tty
)
689 extern int epoch_interface
;
691 print_command_1 (exp
, epoch_interface
, 1);
694 /* Same as print, except it doesn't print void results. */
697 call_command (exp
, from_tty
)
701 print_command_1 (exp
, 0, 0);
706 output_command (exp
, from_tty
)
710 struct expression
*expr
;
711 register struct cleanup
*old_chain
;
712 register char format
= 0;
714 struct format_data fmt
;
716 if (exp
&& *exp
== '/')
719 fmt
= decode_format (&exp
, 0, 0);
720 validate_format (fmt
, "print");
724 expr
= parse_c_expression (exp
);
725 old_chain
= make_cleanup (free_current_contents
, &expr
);
727 val
= evaluate_expression (expr
);
729 print_formatted (val
, format
, fmt
.size
);
731 do_cleanups (old_chain
);
736 set_command (exp
, from_tty
)
740 struct expression
*expr
= parse_c_expression (exp
);
741 register struct cleanup
*old_chain
742 = make_cleanup (free_current_contents
, &expr
);
743 evaluate_expression (expr
);
744 do_cleanups (old_chain
);
749 address_info (exp
, from_tty
)
753 register struct symbol
*sym
;
755 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
756 if exp is a field of `this'. */
759 error ("Argument required.");
761 sym
= lookup_symbol (exp
, get_selected_block (), VAR_NAMESPACE
,
762 &is_a_field_of_this
, (struct symtab
**)NULL
);
767 if (is_a_field_of_this
)
769 printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp
);
773 for (i
= 0; i
< misc_function_count
; i
++)
774 if (!strcmp (misc_function_vector
[i
].name
, exp
))
777 if (i
< misc_function_count
)
778 printf ("Symbol \"%s\" is at 0x%x in a file compiled without -g.\n",
779 exp
, misc_function_vector
[i
].address
);
781 error ("No symbol \"%s\" in current context.", exp
);
785 printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym
));
786 val
= SYMBOL_VALUE (sym
);
788 switch (SYMBOL_CLASS (sym
))
791 case LOC_CONST_BYTES
:
796 printf ("a label at address 0x%x", SYMBOL_VALUE_ADDRESS (sym
));
800 printf ("a variable in register %s", reg_names
[val
]);
804 printf ("static at address 0x%x", SYMBOL_VALUE_ADDRESS (sym
));
808 printf ("an argument in register %s", reg_names
[val
]);
812 printf ("an argument at offset %ld", val
);
816 printf ("an argument at frame offset %ld", val
);
820 printf ("a local variable at frame offset %ld", val
);
824 printf ("a reference argument at offset %ld", val
);
828 printf ("a typedef");
832 printf ("a function at address 0x%x",
833 BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)));
837 printf ("an external symbol at address 0x%x",
838 SYMBOL_VALUE_ADDRESS (sym
));
842 printf ("of unknown (botched) type");
849 x_command (exp
, from_tty
)
853 struct expression
*expr
;
854 struct format_data fmt
;
855 struct cleanup
*old_chain
;
858 fmt
.format
= last_format
;
859 fmt
.size
= last_size
;
862 if (exp
&& *exp
== '/')
865 fmt
= decode_format (&exp
, last_format
, last_size
);
866 last_size
= fmt
.size
;
867 last_format
= fmt
.format
;
870 /* If we have an expression, evaluate it and use it as the address. */
872 if (exp
!= 0 && *exp
!= 0)
874 expr
= parse_c_expression (exp
);
875 /* Cause expression not to be there any more
876 if this command is repeated with Newline.
877 But don't clobber a user-defined command's definition. */
880 old_chain
= make_cleanup (free_current_contents
, &expr
);
881 val
= evaluate_expression (expr
);
882 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_REF
)
883 val
= value_ind (val
);
884 /* In rvalue contexts, such as this, functions are coerced into
885 pointers to functions. This makes "x/i main" work. */
886 if (/* last_format == 'i'
887 && */ TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FUNC
888 && VALUE_LVAL (val
) == lval_memory
)
889 next_address
= VALUE_ADDRESS (val
);
891 next_address
= value_as_pointer (val
);
892 do_cleanups (old_chain
);
895 do_examine (fmt
, next_address
);
897 /* Set a couple of internal variables if appropriate. */
898 if (last_examine_value
)
900 /* Make last address examined available to the user as $_. */
901 set_internalvar (lookup_internalvar ("_"),
902 value_from_long (builtin_type_int
,
903 (LONGEST
) last_examine_address
));
905 /* Make contents of last address examined available to the user as $__.*/
906 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
910 /* Commands for printing types of things. */
912 /* Print type of EXP, or last thing in value history if EXP == NULL.
913 show is passed to type_print. */
915 whatis_exp (exp
, show
)
919 struct expression
*expr
;
921 register struct cleanup
*old_chain
;
925 expr
= parse_c_expression (exp
);
926 old_chain
= make_cleanup (free_current_contents
, &expr
);
927 val
= evaluate_type (expr
);
930 val
= access_value_history (0);
932 printf_filtered ("type = ");
933 type_print (VALUE_TYPE (val
), "", stdout
, show
);
934 printf_filtered ("\n");
937 do_cleanups (old_chain
);
942 whatis_command (exp
, from_tty
)
946 /* Most of the time users do not want to see all the fields
947 in a structure. If they do they can use the "ptype" command.
948 Hence the "-1" below. */
949 whatis_exp (exp
, -1);
952 /* TYPENAME is either the name of a type, or an expression. */
955 ptype_command (typename
, from_tty
)
959 register char *p
= typename
;
961 register struct block
*b
962 = target_has_stack
? get_current_block () : 0;
963 register struct type
*type
;
967 whatis_exp (typename
, 1);
971 while (*p
&& *p
!= ' ' && *p
!= '\t') p
++;
973 while (*p
== ' ' || *p
== '\t') p
++;
975 if (len
== 6 && !strncmp (typename
, "struct", 6))
976 type
= lookup_struct (p
, b
);
977 else if (len
== 5 && !strncmp (typename
, "union", 5))
978 type
= lookup_union (p
, b
);
979 else if (len
== 4 && !strncmp (typename
, "enum", 4))
980 type
= lookup_enum (p
, b
);
983 type
= lookup_typename (typename
, b
, 1);
986 register struct symbol
*sym
987 = lookup_symbol (typename
, b
, STRUCT_NAMESPACE
, 0,
988 (struct symtab
**)NULL
);
991 /* It's not the name of a type, either VAR_NAMESPACE
992 or STRUCT_NAMESPACE, so it must be an expression. */
993 whatis_exp (typename
, 1);
996 printf_filtered ("No type named %s, ", typename
);
998 printf_filtered ("but there is ");
999 switch (TYPE_CODE (SYMBOL_TYPE (sym
)))
1001 case TYPE_CODE_STRUCT
:
1002 printf_filtered ("a struct");
1005 case TYPE_CODE_UNION
:
1006 printf_filtered ("a union");
1009 case TYPE_CODE_ENUM
:
1010 printf_filtered ("an enum");
1014 printf_filtered ("(Internal error in gdb)");
1017 printf_filtered (" %s. ", typename
);
1019 printf_filtered ("(Type \"help ptype\".)\n");
1020 type
= SYMBOL_TYPE (sym
);
1024 type_print (type
, "", stdout
, 1);
1025 printf_filtered ("\n");
1029 /* This is not necessary. Instead, decode_line_1 takes any variable,
1030 so "info line foo" is a close equivalent to "whereis foo". */
1032 whereis_command (var
, from_tty
)
1040 error_no_arg ("Variable name.");
1042 sym
= lookup_symbol (var
, get_selected_block (), VAR_NAMESPACE
,
1045 if (sym
!= NULL
&& s
!= NULL
)
1046 printf_filtered ("Symbol \"%s\" is at line %d of file %s\n",
1047 var
, sym
->line
, s
->filename
);
1050 if (lookup_misc_func (var
) >= 0)
1051 printf_filtered ("Symbol \"%s\" is in a file compiled without -g.",
1054 error ("No symbol \"%s\" in current context.", var
);
1059 enum display_status
{disabled
, enabled
};
1063 /* Chain link to next auto-display item. */
1064 struct display
*next
;
1065 /* Expression to be evaluated and displayed. */
1066 struct expression
*exp
;
1067 /* Item number of this auto-display item. */
1069 /* Display format specified. */
1070 struct format_data format
;
1071 /* Innermost block required by this expression when evaluated */
1072 struct block
*block
;
1073 /* Status of this display (enabled or disabled) */
1074 enum display_status status
;
1077 /* Chain of expressions whose values should be displayed
1078 automatically each time the program stops. */
1080 static struct display
*display_chain
;
1082 static int display_number
;
1084 /* Add an expression to the auto-display chain.
1085 Specify the expression. */
1088 display_command (exp
, from_tty
)
1092 struct format_data fmt
;
1093 register struct expression
*expr
;
1094 register struct display
*new;
1105 fmt
= decode_format (&exp
, 0, 0);
1106 if (fmt
.size
&& fmt
.format
== 0)
1108 if (fmt
.format
== 'i' || fmt
.format
== 's')
1118 innermost_block
= 0;
1119 expr
= parse_c_expression (exp
);
1121 new = (struct display
*) xmalloc (sizeof (struct display
));
1124 new->block
= innermost_block
;
1125 new->next
= display_chain
;
1126 new->number
= ++display_number
;
1128 new->status
= enabled
;
1129 display_chain
= new;
1131 if (from_tty
&& target_has_execution
)
1132 do_one_display (new);
1145 /* Clear out the display_chain.
1146 Done when new symtabs are loaded, since this invalidates
1147 the types stored in many expressions. */
1152 register struct display
*d
;
1154 while (d
= display_chain
)
1157 display_chain
= d
->next
;
1162 /* Delete the auto-display number NUM. */
1165 delete_display (num
)
1168 register struct display
*d1
, *d
;
1171 error ("No display number %d.", num
);
1173 if (display_chain
->number
== num
)
1176 display_chain
= d1
->next
;
1180 for (d
= display_chain
; ; d
= d
->next
)
1183 error ("No display number %d.", num
);
1184 if (d
->next
->number
== num
)
1194 /* Delete some values from the auto-display chain.
1195 Specify the element numbers. */
1198 undisplay_command (args
)
1201 register char *p
= args
;
1207 if (query ("Delete all auto-display expressions? "))
1216 while (*p1
>= '0' && *p1
<= '9') p1
++;
1217 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1218 error ("Arguments must be display numbers.");
1222 delete_display (num
);
1225 while (*p
== ' ' || *p
== '\t') p
++;
1230 /* Display a single auto-display.
1231 Do nothing if the display cannot be printed in the current context,
1232 or if the display is disabled. */
1238 int within_current_scope
;
1240 if (d
->status
== disabled
)
1244 within_current_scope
= contained_in (get_selected_block (), d
->block
);
1246 within_current_scope
= 1;
1247 if (!within_current_scope
)
1250 current_display_number
= d
->number
;
1252 printf_filtered ("%d: ", d
->number
);
1257 printf_filtered ("x/");
1258 if (d
->format
.count
!= 1)
1259 printf_filtered ("%d", d
->format
.count
);
1260 printf_filtered ("%c", d
->format
.format
);
1261 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1262 printf_filtered ("%c", d
->format
.size
);
1263 printf_filtered (" ");
1264 print_expression (d
->exp
, stdout
);
1265 if (d
->format
.count
!= 1)
1266 printf_filtered ("\n");
1268 printf_filtered (" ");
1270 addr
= value_as_pointer (evaluate_expression (d
->exp
));
1271 if (d
->format
.format
== 'i')
1272 addr
= ADDR_BITS_REMOVE (addr
);
1274 do_examine (d
->format
, addr
);
1278 if (d
->format
.format
)
1279 printf_filtered ("/%c ", d
->format
.format
);
1280 print_expression (d
->exp
, stdout
);
1281 printf_filtered (" = ");
1282 print_formatted (evaluate_expression (d
->exp
),
1283 d
->format
.format
, d
->format
.size
);
1284 printf_filtered ("\n");
1288 current_display_number
= -1;
1291 /* Display all of the values on the auto-display chain which can be
1292 evaluated in the current scope. */
1297 register struct display
*d
;
1299 for (d
= display_chain
; d
; d
= d
->next
)
1303 /* Delete the auto-display which we were in the process of displaying.
1304 This is done when there is an error or a signal. */
1307 disable_display (num
)
1310 register struct display
*d
;
1312 for (d
= display_chain
; d
; d
= d
->next
)
1313 if (d
->number
== num
)
1315 d
->status
= disabled
;
1318 printf ("No display number %d.\n", num
);
1322 disable_current_display ()
1324 if (current_display_number
>= 0)
1326 disable_display (current_display_number
);
1327 fprintf (stderr
, "Disabling display %d to avoid infinite recursion.\n",
1328 current_display_number
);
1330 current_display_number
= -1;
1336 register struct display
*d
;
1339 printf ("There are no auto-display expressions now.\n");
1341 printf_filtered ("Auto-display expressions now in effect:\n\
1342 Num Enb Expression\n");
1344 for (d
= display_chain
; d
; d
= d
->next
)
1346 printf_filtered ("%d: %c ", d
->number
, "ny"[(int)d
->status
]);
1348 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1350 else if (d
->format
.format
)
1351 printf_filtered ("/%c ", d
->format
.format
);
1352 print_expression (d
->exp
, stdout
);
1353 if (d
->block
&& !contained_in (get_selected_block (), d
->block
))
1354 printf_filtered (" (cannot be evaluated in the current context)");
1355 printf_filtered ("\n");
1361 enable_display (args
)
1364 register char *p
= args
;
1367 register struct display
*d
;
1371 for (d
= display_chain
; d
; d
= d
->next
)
1372 d
->status
= enabled
;
1378 while (*p1
>= '0' && *p1
<= '9')
1380 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1381 error ("Arguments must be display numbers.");
1385 for (d
= display_chain
; d
; d
= d
->next
)
1386 if (d
->number
== num
)
1388 d
->status
= enabled
;
1391 printf ("No display number %d.\n", num
);
1394 while (*p
== ' ' || *p
== '\t')
1401 disable_display_command (args
, from_tty
)
1405 register char *p
= args
;
1407 register struct display
*d
;
1411 for (d
= display_chain
; d
; d
= d
->next
)
1412 d
->status
= disabled
;
1418 while (*p1
>= '0' && *p1
<= '9')
1420 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1421 error ("Arguments must be display numbers.");
1423 disable_display (atoi (p
));
1426 while (*p
== ' ' || *p
== '\t')
1432 /* Print the value in stack frame FRAME of a variable
1433 specified by a struct symbol. */
1436 print_variable_value (var
, frame
, stream
)
1441 value val
= read_var_value (var
, frame
);
1442 value_print (val
, stream
, 0, Val_pretty_default
);
1445 /* Print the arguments of a stack frame, given the function FUNC
1446 running in that frame (as a symbol), the info on the frame,
1447 and the number of args according to the stack frame (or -1 if unknown). */
1449 /* References here and elsewhere to "number of args according to the
1450 stack frame" appear in all cases to refer to "number of ints of args
1451 according to the stack frame". At least for VAX, i386, isi. */
1454 print_frame_args (func
, fi
, num
, stream
)
1455 struct symbol
*func
;
1456 struct frame_info
*fi
;
1464 register struct symbol
*sym
;
1466 /* Offset of next stack argument beyond the one we have seen that is
1467 at the highest offset.
1468 -1 if we haven't come to a stack argument yet. */
1469 long highest_offset
= -1;
1471 /* Number of ints of arguments that we have printed so far. */
1472 int args_printed
= 0;
1476 b
= SYMBOL_BLOCK_VALUE (func
);
1477 nsyms
= BLOCK_NSYMS (b
);
1480 for (i
= 0; i
< nsyms
; i
++)
1483 sym
= BLOCK_SYM (b
, i
);
1485 if (SYMBOL_CLASS (sym
) != LOC_REGPARM
1486 && SYMBOL_CLASS (sym
) != LOC_ARG
1487 && SYMBOL_CLASS (sym
) != LOC_LOCAL_ARG
1488 && SYMBOL_CLASS (sym
) != LOC_REF_ARG
)
1491 /* We have to re-look-up the symbol because arguments often have
1492 two entries (one a parameter, one a register or local), and the one
1493 we want is the non-parm, which lookup_symbol will find for
1494 us. After this, sym could be any SYMBOL_CLASS... */
1495 sym
= lookup_symbol (SYMBOL_NAME (sym
),
1496 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
1498 switch (SYMBOL_CLASS (sym
)) {
1500 /* Keep track of the highest stack argument offset seen */
1504 long current_offset
= SYMBOL_VALUE (sym
);
1506 arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
1508 /* Compute address of next argument by adding the size of
1509 this argument and rounding to an int boundary. */
1511 = ((current_offset
+ arg_size
+ sizeof (int) - 1)
1512 & ~(sizeof (int) - 1));
1514 /* If this is the highest offset seen yet, set highest_offset. */
1515 if (highest_offset
== -1
1516 || (current_offset
> highest_offset
))
1517 highest_offset
= current_offset
;
1519 /* Add the number of ints we're about to print to args_printed. */
1520 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
1523 /* Other types of symbols don't need to be kept track of. */
1528 /* Print the current arg. */
1530 fprintf_filtered (stream
, ", ");
1532 fprint_symbol (stream
, SYMBOL_NAME (sym
));
1533 fputs_filtered ("=", stream
);
1535 /* Avoid value_print because it will deref ref parameters. We just
1536 want to print their addresses. Print ??? for args whose address
1537 we do not know. We pass 2 as "recurse" to val_print because our
1538 standard indentation here is 4 spaces, and val_print indents
1539 2 for each recurse. */
1540 val
= read_var_value (sym
, FRAME_INFO_ID (fi
));
1542 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), VALUE_ADDRESS (val
),
1543 stream
, 0, 0, 2, Val_no_prettyprint
);
1545 fputs_filtered ("???", stream
);
1549 /* Don't print nameless args in situations where we don't know
1550 enough about the stack to find them. */
1556 if (highest_offset
== -1)
1557 start
= FRAME_ARGS_SKIP
;
1559 start
= highest_offset
;
1561 addr
= FRAME_ARGS_ADDRESS (fi
);
1563 print_frame_nameless_args (addr
, start
, num
- args_printed
,
1568 /* Print nameless args on STREAM.
1569 ARGSADDR is the address of the arglist, START is the offset
1570 of the first nameless arg, and NUM is the number of nameless args to
1571 print. FIRST is nonzero if this is the first argument (not just
1572 the first nameless arg). */
1574 print_frame_nameless_args (argsaddr
, start
, num
, first
, stream
)
1582 for (i
= 0; i
< num
; i
++)
1586 fprintf_filtered (stream
, ", ");
1587 #ifndef PRINT_TYPELESS_INTEGER
1588 fprintf_filtered (stream
, "%d",
1589 read_memory_integer (argsaddr
+ start
, sizeof (int)));
1591 PRINT_TYPELESS_INTEGER (stream
, builtin_type_int
,
1593 read_memory_integer (argsaddr
+ start
,
1597 start
+= sizeof (int);
1603 printf_command (arg
, from_tty
)
1608 register char *s
= arg
;
1612 int allocated_args
= 20;
1615 val_args
= (value
*) xmalloc (allocated_args
* sizeof (value
));
1618 error_no_arg ("format-control string and values to print");
1620 /* Skip white space before format string */
1621 while (*s
== ' ' || *s
== '\t') s
++;
1623 /* A format string should follow, enveloped in double quotes */
1625 error ("Bad format string, missing '\"'.");
1627 /* Parse the format-control string and copy it into the string STRING,
1628 processing some kinds of escape sequence. */
1630 f
= string
= (char *) alloca (strlen (s
) + 1);
1637 error ("Bad format string, non-terminated '\"'.");
1638 /* doesn't return */
1659 /* ??? TODO: handle other escape sequences */
1660 error ("Unrecognized \\ escape character in format string.");
1669 /* Skip over " and following space and comma. */
1672 while (*s
== ' ' || *s
== '\t') s
++;
1674 if (*s
!= ',' && *s
!= 0)
1675 error ("Invalid argument syntax");
1678 while (*s
== ' ' || *s
== '\t') s
++;
1681 /* Now scan the string for %-specs and see what kinds of args they want.
1682 argclass[I] classifies the %-specs so we can give vprintf something
1683 of the right size. */
1685 enum argclass
{int_arg
, string_arg
, double_arg
, long_long_arg
};
1686 enum argclass
*argclass
;
1692 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1699 while (strchr ("0123456789.hlL-+ #", *f
))
1701 if (*f
== 'l' || *f
== 'L')
1706 argclass
[nargs_wanted
++] = string_arg
;
1707 else if (*f
== 'e' || *f
== 'f' || *f
== 'g')
1708 argclass
[nargs_wanted
++] = double_arg
;
1709 else if (lcount
> 1)
1710 argclass
[nargs_wanted
++] = long_long_arg
;
1712 argclass
[nargs_wanted
++] = int_arg
;
1716 /* Now, parse all arguments and evaluate them.
1717 Store the VALUEs in VAL_ARGS. */
1722 if (nargs
== allocated_args
)
1723 val_args
= (value
*) xrealloc (val_args
,
1724 (allocated_args
*= 2)
1727 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
1729 /* If format string wants a float, unchecked-convert the value to
1730 floating point of the same size */
1732 if (argclass
[nargs
] == double_arg
)
1734 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (float))
1735 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
1736 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (double))
1737 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
1745 if (nargs
!= nargs_wanted
)
1746 error ("Wrong number of arguments for specified format-string");
1748 /* Now lay out an argument-list containing the arguments
1749 as doubles, integers and C pointers. */
1751 arg_bytes
= (char *) alloca (sizeof (double) * nargs
);
1753 for (i
= 0; i
< nargs
; i
++)
1755 if (argclass
[i
] == string_arg
)
1760 tem
= value_as_pointer (val_args
[i
]);
1762 /* This is a %s argument. Find the length of the string. */
1767 read_memory (tem
+ j
, &c
, 1);
1772 /* Copy the string contents into a string inside GDB. */
1773 str
= (char *) alloca (j
+ 1);
1774 read_memory (tem
, str
, j
);
1777 /* Pass address of internal copy as the arg to vprintf. */
1778 *((int *) &arg_bytes
[argindex
]) = (int) str
;
1779 argindex
+= sizeof (int);
1781 else if (VALUE_TYPE (val_args
[i
])->code
== TYPE_CODE_FLT
)
1783 *((double *) &arg_bytes
[argindex
]) = value_as_double (val_args
[i
]);
1784 argindex
+= sizeof (double);
1788 if (argclass
[i
] == long_long_arg
)
1790 *(long long *) &arg_bytes
[argindex
] = value_as_long (val_args
[i
]);
1791 argindex
+= sizeof (long long);
1796 *((long *) &arg_bytes
[argindex
]) = value_as_long (val_args
[i
]);
1797 argindex
+= sizeof (long);
1802 /* There is not a standard way to make a va_list, so we need
1803 to do various things for different systems. */
1804 #if defined (__INT_VARARGS_H)
1809 list
.__va_stk
= (int *) arg_bytes
;
1810 list
.__va_reg
= (int *) arg_bytes
;
1811 vprintf (string
, list
);
1813 #else /* No __INT_VARARGS_H. */
1814 vprintf (string
, arg_bytes
);
1815 #endif /* No __INT_VARARGS_H. */
1818 /* Helper function for asdump_command. Finds the bounds of a function
1819 for a specified section of text. PC is an address within the
1820 function which you want bounds for; *LOW and *HIGH are set to the
1821 beginning (inclusive) and end (exclusive) of the function. This
1822 function returns 1 on success and 0 on failure. */
1825 containing_function_bounds (pc
, low
, high
)
1826 CORE_ADDR pc
, *low
, *high
;
1830 if (!find_pc_partial_function (pc
, 0, low
))
1836 if (!find_pc_partial_function (scan
, 0, high
))
1838 } while (*low
== *high
);
1843 /* Dump a specified section of assembly code. With no command line
1844 arguments, this command will dump the assembly code for the
1845 function surrounding the pc value in the selected frame. With one
1846 argument, it will dump the assembly code surrounding that pc value.
1847 Two arguments are interpeted as bounds within which to dump
1852 disassemble_command (arg
, from_tty
)
1856 CORE_ADDR low
, high
;
1862 if (!selected_frame
)
1863 error ("No frame selected.\n");
1865 pc
= get_frame_pc (selected_frame
);
1866 if (!containing_function_bounds (pc
, &low
, &high
))
1867 error ("No function contains pc specified by selected frame.\n");
1869 else if (!(space_index
= (char *) strchr (arg
, ' ')))
1872 pc
= parse_and_eval_address (arg
);
1873 if (!containing_function_bounds (pc
, &low
, &high
))
1874 error ("No function contains specified pc.\n");
1878 /* Two arguments. */
1879 *space_index
= '\0';
1880 low
= parse_and_eval_address (arg
);
1881 high
= parse_and_eval_address (space_index
+ 1);
1884 printf_filtered ("Dump of assembler code ");
1888 find_pc_partial_function (pc
, &name
, 0);
1889 printf_filtered ("for function %s:\n", name
);
1892 printf_filtered ("from 0x%x to 0x%x:\n", low
, high
);
1894 /* Dump the specified range. */
1895 for (pc
= low
; pc
< high
; )
1898 print_address (pc
, stdout
);
1899 printf_filtered (":\t");
1900 pc
+= print_insn (pc
, stdout
);
1901 printf_filtered ("\n");
1903 printf_filtered ("End of assembler dump.\n");
1909 _initialize_printcmd ()
1911 current_display_number
= -1;
1913 add_info ("address", address_info
,
1914 "Describe where variable VAR is stored.");
1916 add_com ("x", class_vars
, x_command
,
1917 "Examine memory: x/FMT ADDRESS.\n\
1918 ADDRESS is an expression for the memory address to examine.\n\
1919 FMT is a repeat count followed by a format letter and a size letter.\n\
1920 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1921 f(float), a(address), i(instruction), c(char) and s(string).\n\
1922 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1923 g is meaningful only with f, for type double.\n\
1924 The specified number of objects of the specified size are printed\n\
1925 according to the format.\n\n\
1926 Defaults for format and size letters are those previously used.\n\
1927 Default count is 1. Default address is following last thing printed\n\
1928 with this command or \"print\".");
1930 add_com ("disassemble", class_vars
, disassemble_command
,
1931 "Disassemble a specified section of memory.\n\
1932 Default is the function surrounding the pc of the selected frame.\n\
1933 With a single argument, the function surrounding that address is dumped.\n\
1934 Two arguments are taken as a range of memory to dump.");
1936 add_com ("ptype", class_vars
, ptype_command
,
1937 "Print definition of type TYPE.\n\
1938 Argument may be a type name defined by typedef, or \"struct STRUCTNAME\"\n\
1939 or \"union UNIONNAME\" or \"enum ENUMNAME\".\n\
1940 The selected stack frame's lexical context is used to look up the name.");
1942 add_com ("whatis", class_vars
, whatis_command
,
1943 "Print data type of expression EXP.");
1946 add_com ("whereis", class_vars
, whereis_command
,
1947 "Print line number and file of definition of variable.");
1950 add_info ("display", display_info
,
1951 "Expressions to display when program stops, with code numbers.");
1953 add_cmd ("undisplay", class_vars
, undisplay_command
,
1954 "Cancel some expressions to be displayed when program stops.\n\
1955 Arguments are the code numbers of the expressions to stop displaying.\n\
1956 No argument means cancel all automatic-display expressions.\n\
1957 \"delete display\" has the same effect as this command.\n\
1958 Do \"info display\" to see current list of code numbers.",
1961 add_com ("display", class_vars
, display_command
,
1962 "Print value of expression EXP each time the program stops.\n\
1963 /FMT may be used before EXP as in the \"print\" command.\n\
1964 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
1965 as in the \"x\" command, and then EXP is used to get the address to examine\n\
1966 and examining is done as in the \"x\" command.\n\n\
1967 With no argument, display all currently requested auto-display expressions.\n\
1968 Use \"undisplay\" to cancel display requests previously made.");
1970 add_cmd ("display", class_vars
, enable_display
,
1971 "Enable some expressions to be displayed when program stops.\n\
1972 Arguments are the code numbers of the expressions to resume displaying.\n\
1973 No argument means enable all automatic-display expressions.\n\
1974 Do \"info display\" to see current list of code numbers.", &enablelist
);
1976 add_cmd ("display", class_vars
, disable_display_command
,
1977 "Disable some expressions to be displayed when program stops.\n\
1978 Arguments are the code numbers of the expressions to stop displaying.\n\
1979 No argument means disable all automatic-display expressions.\n\
1980 Do \"info display\" to see current list of code numbers.", &disablelist
);
1982 add_cmd ("display", class_vars
, undisplay_command
,
1983 "Cancel some expressions to be displayed when program stops.\n\
1984 Arguments are the code numbers of the expressions to stop displaying.\n\
1985 No argument means cancel all automatic-display expressions.\n\
1986 Do \"info display\" to see current list of code numbers.", &deletelist
);
1988 add_com ("printf", class_vars
, printf_command
,
1989 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
1990 This is useful for formatted output in user-defined commands.");
1991 add_com ("output", class_vars
, output_command
,
1992 "Like \"print\" but don't put in value history and don't print newline.\n\
1993 This is useful in user-defined commands.");
1995 add_prefix_cmd ("set", class_vars
, set_command
,
1996 "Perform an assignment VAR = EXP.\n\
1997 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
1998 (names starting with $), a register (a few standard names starting with $),\n\
1999 or an actual variable in the program being debugged. EXP is any expression.\n\
2000 Use \"set variable\" for variables with names identical to set subcommands.\n\
2001 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2002 You can see these environment settings with the \"show\" command.",
2003 &setlist
, "set ", 1, &cmdlist
);
2005 /* "call" is the same as "set", but handy for dbx users to call fns. */
2006 add_com ("call", class_vars
, call_command
,
2007 "Call a function in the inferior process.\n\
2008 The argument is the function name and arguments, in standard C notation.\n\
2009 The result is printed and saved in the value history, if it is not void.");
2011 add_cmd ("variable", class_vars
, set_command
,
2012 "Perform an assignment VAR = EXP.\n\
2013 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
2014 (names starting with $), a register (a few standard names starting with $),\n\
2015 or an actual variable in the program being debugged. EXP is any expression.\n\
2016 This may usually be abbreviated to simply \"set\".",
2019 add_com ("print", class_vars
, print_command
,
2020 concat ("Print value of expression EXP.\n\
2021 Variables accessible are those of the lexical environment of the selected\n\
2022 stack frame, plus all those whose scope is global or an entire file.\n\
2024 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2025 $$NUM refers to NUM'th value back from the last one.\n\
2026 Names starting with $ refer to registers (with the values they would have\n\
2027 if the program were to return to the stack frame now selected, restoring\n\
2028 all registers saved by frames farther in) or else to debugger\n\
2029 \"convenience\" variables (any such name not a known register).\n\
2030 Use assignment expressions to give values to convenience variables.\n",
2032 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2033 @ is a binary operator for treating consecutive data objects\n\
2034 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2035 element is FOO, whose second element is stored in the space following\n\
2036 where FOO is stored, etc. FOO must be an expression whose value\n\
2037 resides in memory.\n",
2039 EXP may be preceded with /FMT, where FMT is a format letter\n\
2040 but no count or size letter (see \"x\" command)."));
2041 add_com_alias ("p", "print", class_vars
, 1);
2043 add_com ("inspect", class_vars
, inspect_command
,
2044 "Same as \"print\" command, except that if you are running in the epoch\n\
2045 environment, the value is printed in its own window.");