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 ((CORE_ADDR
) val_long
, 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 error ("Undefined output format \"%c\".", format
);
390 /* Specify default address for `x' command.
391 `info lines' uses this. */
394 set_next_address (addr
)
399 /* Make address available to the user as $_. */
400 set_internalvar (lookup_internalvar ("_"),
401 value_from_long (builtin_type_int
, (LONGEST
) addr
));
404 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM.
405 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
406 or to interpret it as a possible C++ name and convert it back to source
410 print_address_symbolic (addr
, stream
, do_demangle
)
416 register int i
= find_pc_misc_function (addr
);
418 /* If nothing comes out, don't print anything symbolic. */
423 fputs_filtered (" <", stream
);
425 fputs_demangled (misc_function_vector
[i
].name
, stream
, 1);
427 fputs_filtered (misc_function_vector
[i
].name
, stream
);
428 name_location
= misc_function_vector
[i
].address
;
429 if (addr
- name_location
)
430 fprintf_filtered (stream
, "+%d>", addr
- name_location
);
432 fputs_filtered (">", stream
);
435 /* Print address ADDR symbolically on STREAM.
436 First print it as a number. Then perhaps print
437 <SYMBOL + OFFSET> after the number. */
440 print_address (addr
, stream
)
444 fprintf_filtered (stream
, "0x%x", addr
);
445 print_address_symbolic (addr
, stream
, asm_demangle
);
448 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
449 controls whether to print the symbolic name "raw" or demangled. */
452 print_address_demangle (addr
, stream
, do_demangle
)
457 fprintf_filtered (stream
, "0x%x", addr
);
458 print_address_symbolic (addr
, stream
, do_demangle
);
463 /* Examine data at address ADDR in format FMT.
464 Fetch it from memory and print on stdout. */
467 do_examine (fmt
, addr
)
468 struct format_data fmt
;
471 register char format
= 0;
473 register int count
= 1;
474 struct type
*val_type
;
476 register int maxelts
;
483 /* String or instruction format implies fetch single bytes
484 regardless of the specified size. */
485 if (format
== 's' || format
== 'i')
489 val_type
= builtin_type_char
;
490 else if (size
== 'h')
491 val_type
= builtin_type_short
;
492 else if (size
== 'w')
493 val_type
= builtin_type_long
;
494 else if (size
== 'g')
496 val_type
= builtin_type_double
;
498 val_type
= builtin_type_long_long
;
506 if (format
== 's' || format
== 'i')
509 /* Print as many objects as specified in COUNT, at most maxelts per line,
510 with the address of the next one at the start of each line. */
514 print_address (next_address
, stdout
);
515 printf_filtered (":");
520 printf_filtered ("\t");
521 /* Note that print_formatted sets next_address for the next
523 last_examine_address
= next_address
;
524 last_examine_value
= value_at (val_type
, next_address
);
525 print_formatted (last_examine_value
, format
, size
);
527 printf_filtered ("\n");
533 validate_format (fmt
, cmdname
)
534 struct format_data fmt
;
538 error ("Size letters are meaningless in \"%s\" command.", cmdname
);
540 error ("Item count other than 1 is meaningless in \"%s\" command.",
542 if (fmt
.format
== 'i' || fmt
.format
== 's')
543 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
544 fmt
.format
, cmdname
);
548 print_command_1 (exp
, inspect
, voidprint
)
553 struct expression
*expr
;
554 register struct cleanup
*old_chain
= 0;
555 register char format
= 0;
557 struct format_data fmt
;
560 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
561 inspect_it
= inspect
;
563 if (exp
&& *exp
== '/')
566 fmt
= decode_format (&exp
, last_format
, 0);
567 validate_format (fmt
, "print");
568 last_format
= format
= fmt
.format
;
579 expr
= parse_c_expression (exp
);
580 old_chain
= make_cleanup (free_current_contents
, &expr
);
582 val
= evaluate_expression (expr
);
585 val
= access_value_history (0);
587 if (voidprint
|| (val
&& VALUE_TYPE (val
) &&
588 TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_VOID
))
590 int histindex
= record_latest_value (val
);
593 printf ("\031(gdb-makebuffer \"%s\" %d '(\"", exp
, histindex
);
595 if (histindex
>= 0) printf_filtered ("$%d = ", histindex
);
597 print_formatted (val
, format
, fmt
.size
);
598 printf_filtered ("\n");
604 do_cleanups (old_chain
);
605 inspect_it
= 0; /* Reset print routines to normal */
609 print_command (exp
, from_tty
)
613 print_command_1 (exp
, 0, 1);
616 /* Same as print, except in epoch, it gets its own window */
618 inspect_command (exp
, from_tty
)
622 extern int epoch_interface
;
624 print_command_1 (exp
, epoch_interface
, 1);
627 /* Same as print, except it doesn't print void results. */
629 call_command (exp
, from_tty
)
633 print_command_1 (exp
, 0, 0);
637 output_command (exp
, from_tty
)
641 struct expression
*expr
;
642 register struct cleanup
*old_chain
;
643 register char format
= 0;
645 struct format_data fmt
;
647 if (exp
&& *exp
== '/')
650 fmt
= decode_format (&exp
, 0, 0);
651 validate_format (fmt
, "print");
655 expr
= parse_c_expression (exp
);
656 old_chain
= make_cleanup (free_current_contents
, &expr
);
658 val
= evaluate_expression (expr
);
660 print_formatted (val
, format
, fmt
.size
);
662 do_cleanups (old_chain
);
666 set_command (exp
, from_tty
)
670 struct expression
*expr
= parse_c_expression (exp
);
671 register struct cleanup
*old_chain
672 = make_cleanup (free_current_contents
, &expr
);
673 evaluate_expression (expr
);
674 do_cleanups (old_chain
);
678 address_info (exp
, from_tty
)
682 register struct symbol
*sym
;
683 register CORE_ADDR val
;
684 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
685 if exp is a field of `this'. */
688 error ("Argument required.");
690 sym
= lookup_symbol (exp
, get_selected_block (), VAR_NAMESPACE
,
691 &is_a_field_of_this
, (struct symtab
**)NULL
);
696 if (is_a_field_of_this
)
698 printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp
);
702 for (i
= 0; i
< misc_function_count
; i
++)
703 if (!strcmp (misc_function_vector
[i
].name
, exp
))
706 if (i
< misc_function_count
)
707 printf ("Symbol \"%s\" is at 0x%x in a file compiled without -g.\n",
708 exp
, misc_function_vector
[i
].address
);
710 error ("No symbol \"%s\" in current context.", exp
);
714 printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym
));
715 val
= SYMBOL_VALUE (sym
);
717 switch (SYMBOL_CLASS (sym
))
720 case LOC_CONST_BYTES
:
725 printf ("a label at address 0x%x", SYMBOL_VALUE_ADDRESS (sym
));
729 printf ("a variable in register %s", reg_names
[val
]);
733 printf ("static at address 0x%x", SYMBOL_VALUE_ADDRESS (sym
));
737 printf ("an argument in register %s", reg_names
[val
]);
741 printf ("an argument at offset %d", (int)val
);
745 printf ("an argument at frame offset %d", (int)val
);
749 printf ("a local variable at frame offset %d", (int)val
);
753 printf ("a reference argument at offset %d", (int)val
);
757 printf ("a typedef");
761 printf ("a function at address 0x%x",
762 BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)));
766 printf ("an external symbol at address 0x%x",
767 SYMBOL_VALUE_ADDRESS (sym
));
771 printf ("of unknown (botched) type");
778 x_command (exp
, from_tty
)
782 struct expression
*expr
;
783 struct format_data fmt
;
784 struct cleanup
*old_chain
;
787 fmt
.format
= last_format
;
788 fmt
.size
= last_size
;
791 if (exp
&& *exp
== '/')
794 fmt
= decode_format (&exp
, last_format
, last_size
);
795 last_size
= fmt
.size
;
796 last_format
= fmt
.format
;
799 /* If we have an expression, evaluate it and use it as the address. */
801 if (exp
!= 0 && *exp
!= 0)
803 expr
= parse_c_expression (exp
);
804 /* Cause expression not to be there any more
805 if this command is repeated with Newline.
806 But don't clobber a user-defined command's definition. */
809 old_chain
= make_cleanup (free_current_contents
, &expr
);
810 val
= evaluate_expression (expr
);
811 /* In rvalue contexts, such as this, functions are coerced into
812 pointers to functions. This makes "x/i main" work. */
813 if (/* last_format == 'i'
814 && */ TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FUNC
815 && VALUE_LVAL (val
) == lval_memory
)
816 next_address
= VALUE_ADDRESS (val
);
818 next_address
= (CORE_ADDR
) value_as_long (val
);
819 do_cleanups (old_chain
);
822 do_examine (fmt
, next_address
);
824 /* Set a couple of internal variables if appropriate. */
825 if (last_examine_value
)
827 /* Make last address examined available to the user as $_. */
828 set_internalvar (lookup_internalvar ("_"),
829 value_from_long (builtin_type_int
,
830 (LONGEST
) last_examine_address
));
832 /* Make contents of last address examined available to the user as $__.*/
833 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
837 /* Commands for printing types of things. */
839 /* Print type of EXP, or last thing in value history if EXP == NULL.
840 show is passed to type_print. */
842 whatis_exp (exp
, show
)
846 struct expression
*expr
;
848 register struct cleanup
*old_chain
;
852 expr
= parse_c_expression (exp
);
853 old_chain
= make_cleanup (free_current_contents
, &expr
);
854 val
= evaluate_type (expr
);
857 val
= access_value_history (0);
859 printf_filtered ("type = ");
860 type_print (VALUE_TYPE (val
), "", stdout
, show
);
861 printf_filtered ("\n");
864 do_cleanups (old_chain
);
868 whatis_command (exp
, from_tty
)
872 /* Most of the time users do not want to see all the fields
873 in a structure. If they do they can use the "ptype" command.
874 Hence the "-1" below. */
875 whatis_exp (exp
, -1);
878 /* TYPENAME is either the name of a type, or an expression. */
880 ptype_command (typename
, from_tty
)
884 register char *p
= typename
;
886 register struct block
*b
887 = target_has_stack
? get_current_block () : 0;
888 register struct type
*type
;
892 whatis_exp (typename
, 1);
896 while (*p
&& *p
!= ' ' && *p
!= '\t') p
++;
898 while (*p
== ' ' || *p
== '\t') p
++;
900 if (len
== 6 && !strncmp (typename
, "struct", 6))
901 type
= lookup_struct (p
, b
);
902 else if (len
== 5 && !strncmp (typename
, "union", 5))
903 type
= lookup_union (p
, b
);
904 else if (len
== 4 && !strncmp (typename
, "enum", 4))
905 type
= lookup_enum (p
, b
);
908 type
= lookup_typename (typename
, b
, 1);
911 register struct symbol
*sym
912 = lookup_symbol (typename
, b
, STRUCT_NAMESPACE
, 0,
913 (struct symtab
**)NULL
);
916 whatis_exp (typename
, 1 /* FIXME: right? */);
919 printf_filtered ("No type named %s, but there is a ",
921 switch (TYPE_CODE (SYMBOL_TYPE (sym
)))
923 case TYPE_CODE_STRUCT
:
924 printf_filtered ("struct");
927 case TYPE_CODE_UNION
:
928 printf_filtered ("union");
932 printf_filtered ("enum");
936 printf_filtered ("(Internal error in gdb)");
939 printf_filtered (" %s. Type \"help ptype\".\n", typename
);
940 type
= SYMBOL_TYPE (sym
);
944 type_print (type
, "", stdout
, 1);
945 printf_filtered ("\n");
949 /* This is not necessary. Instead, decode_line_1 takes any variable,
950 so "info line foo" is a close equivalent to "whereis foo". */
952 whereis_command (var
, from_tty
)
960 error_no_arg ("Variable name.");
962 sym
= lookup_symbol (var
, get_selected_block (), VAR_NAMESPACE
,
965 if (sym
!= NULL
&& s
!= NULL
)
966 printf_filtered ("Symbol \"%s\" is at line %d of file %s\n",
967 var
, sym
->line
, s
->filename
);
970 if (lookup_misc_func (var
) >= 0)
971 printf_filtered ("Symbol \"%s\" is in a file compiled without -g.",
974 error ("No symbol \"%s\" in current context.", var
);
979 enum display_status
{disabled
, enabled
};
983 /* Chain link to next auto-display item. */
984 struct display
*next
;
985 /* Expression to be evaluated and displayed. */
986 struct expression
*exp
;
987 /* Item number of this auto-display item. */
989 /* Display format specified. */
990 struct format_data format
;
991 /* Innermost block required by this expression when evaluated */
993 /* Status of this display (enabled or disabled) */
994 enum display_status status
;
997 /* Chain of expressions whose values should be displayed
998 automatically each time the program stops. */
1000 static struct display
*display_chain
;
1002 static int display_number
;
1004 /* Add an expression to the auto-display chain.
1005 Specify the expression. */
1008 display_command (exp
, from_tty
)
1012 struct format_data fmt
;
1013 register struct expression
*expr
;
1014 register struct display
*new;
1025 fmt
= decode_format (&exp
, 0, 0);
1026 if (fmt
.size
&& fmt
.format
== 0)
1028 if (fmt
.format
== 'i' || fmt
.format
== 's')
1038 innermost_block
= 0;
1039 expr
= parse_c_expression (exp
);
1041 new = (struct display
*) xmalloc (sizeof (struct display
));
1044 new->block
= innermost_block
;
1045 new->next
= display_chain
;
1046 new->number
= ++display_number
;
1048 new->status
= enabled
;
1049 display_chain
= new;
1051 if (from_tty
&& target_has_execution
)
1052 do_one_display (new);
1065 /* Clear out the display_chain.
1066 Done when new symtabs are loaded, since this invalidates
1067 the types stored in many expressions. */
1072 register struct display
*d
;
1074 while (d
= display_chain
)
1077 display_chain
= d
->next
;
1082 /* Delete the auto-display number NUM. */
1085 delete_display (num
)
1088 register struct display
*d1
, *d
;
1091 error ("No display number %d.", num
);
1093 if (display_chain
->number
== num
)
1096 display_chain
= d1
->next
;
1100 for (d
= display_chain
; ; d
= d
->next
)
1103 error ("No display number %d.", num
);
1104 if (d
->next
->number
== num
)
1114 /* Delete some values from the auto-display chain.
1115 Specify the element numbers. */
1118 undisplay_command (args
)
1121 register char *p
= args
;
1127 if (query ("Delete all auto-display expressions? "))
1136 while (*p1
>= '0' && *p1
<= '9') p1
++;
1137 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1138 error ("Arguments must be display numbers.");
1142 delete_display (num
);
1145 while (*p
== ' ' || *p
== '\t') p
++;
1150 /* Display a single auto-display.
1151 Do nothing if the display cannot be printed in the current context,
1152 or if the display is disabled. */
1158 int within_current_scope
;
1160 if (d
->status
== disabled
)
1164 within_current_scope
= contained_in (get_selected_block (), d
->block
);
1166 within_current_scope
= 1;
1167 if (!within_current_scope
)
1170 current_display_number
= d
->number
;
1172 printf_filtered ("%d: ", d
->number
);
1177 printf_filtered ("x/");
1178 if (d
->format
.count
!= 1)
1179 printf_filtered ("%d", d
->format
.count
);
1180 printf_filtered ("%c", d
->format
.format
);
1181 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1182 printf_filtered ("%c", d
->format
.size
);
1183 printf_filtered (" ");
1184 print_expression (d
->exp
, stdout
);
1185 if (d
->format
.count
!= 1)
1186 printf_filtered ("\n");
1188 printf_filtered (" ");
1190 addr
= (CORE_ADDR
) value_as_long (evaluate_expression (d
->exp
));
1191 if (d
->format
.format
== 'i')
1192 addr
= ADDR_BITS_REMOVE (addr
);
1194 do_examine (d
->format
, addr
);
1198 if (d
->format
.format
)
1199 printf_filtered ("/%c ", d
->format
.format
);
1200 print_expression (d
->exp
, stdout
);
1201 printf_filtered (" = ");
1202 print_formatted (evaluate_expression (d
->exp
),
1203 d
->format
.format
, d
->format
.size
);
1204 printf_filtered ("\n");
1208 current_display_number
= -1;
1211 /* Display all of the values on the auto-display chain which can be
1212 evaluated in the current scope. */
1217 register struct display
*d
;
1219 for (d
= display_chain
; d
; d
= d
->next
)
1223 /* Delete the auto-display which we were in the process of displaying.
1224 This is done when there is an error or a signal. */
1227 disable_display (num
)
1230 register struct display
*d
;
1232 for (d
= display_chain
; d
; d
= d
->next
)
1233 if (d
->number
== num
)
1235 d
->status
= disabled
;
1238 printf ("No display number %d.\n", num
);
1242 disable_current_display ()
1244 if (current_display_number
>= 0)
1246 disable_display (current_display_number
);
1247 fprintf (stderr
, "Disabling display %d to avoid infinite recursion.\n",
1248 current_display_number
);
1250 current_display_number
= -1;
1256 register struct display
*d
;
1259 printf ("There are no auto-display expressions now.\n");
1261 printf_filtered ("Auto-display expressions now in effect:\n\
1262 Num Enb Expression\n");
1264 for (d
= display_chain
; d
; d
= d
->next
)
1266 printf_filtered ("%d: %c ", d
->number
, "ny"[(int)d
->status
]);
1268 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1270 else if (d
->format
.format
)
1271 printf_filtered ("/%c ", d
->format
.format
);
1272 print_expression (d
->exp
, stdout
);
1273 if (d
->block
&& !contained_in (get_selected_block (), d
->block
))
1274 printf_filtered (" (cannot be evaluated in the current context)");
1275 printf_filtered ("\n");
1281 enable_display (args
)
1284 register char *p
= args
;
1287 register struct display
*d
;
1291 for (d
= display_chain
; d
; d
= d
->next
)
1292 d
->status
= enabled
;
1298 while (*p1
>= '0' && *p1
<= '9')
1300 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1301 error ("Arguments must be display numbers.");
1305 for (d
= display_chain
; d
; d
= d
->next
)
1306 if (d
->number
== num
)
1308 d
->status
= enabled
;
1311 printf ("No display number %d.\n", num
);
1314 while (*p
== ' ' || *p
== '\t')
1320 disable_display_command (args
, from_tty
)
1324 register char *p
= args
;
1326 register struct display
*d
;
1330 for (d
= display_chain
; d
; d
= d
->next
)
1331 d
->status
= disabled
;
1337 while (*p1
>= '0' && *p1
<= '9')
1339 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1340 error ("Arguments must be display numbers.");
1342 disable_display (atoi (p
));
1345 while (*p
== ' ' || *p
== '\t')
1351 /* Print the value in stack frame FRAME of a variable
1352 specified by a struct symbol. */
1355 print_variable_value (var
, frame
, stream
)
1360 value val
= read_var_value (var
, frame
);
1361 value_print (val
, stream
, 0, Val_pretty_default
);
1364 /* Print the arguments of a stack frame, given the function FUNC
1365 running in that frame (as a symbol), the info on the frame,
1366 and the number of args according to the stack frame (or -1 if unknown). */
1368 /* References here and elsewhere to "number of args according to the
1369 stack frame" appear in all cases to refer to "number of ints of args
1370 according to the stack frame". At least for VAX, i386, isi. */
1373 print_frame_args (func
, fi
, num
, stream
)
1374 struct symbol
*func
;
1375 struct frame_info
*fi
;
1383 register struct symbol
*sym
;
1385 /* Offset of next stack argument beyond the one we have seen that is
1386 at the highest offset.
1387 -1 if we haven't come to a stack argument yet. */
1388 int highest_offset
= -1;
1390 /* Number of ints of arguments that we have printed so far. */
1391 int args_printed
= 0;
1395 b
= SYMBOL_BLOCK_VALUE (func
);
1396 nsyms
= BLOCK_NSYMS (b
);
1399 for (i
= 0; i
< nsyms
; i
++)
1402 sym
= BLOCK_SYM (b
, i
);
1404 if (SYMBOL_CLASS (sym
) != LOC_REGPARM
1405 && SYMBOL_CLASS (sym
) != LOC_ARG
1406 && SYMBOL_CLASS (sym
) != LOC_LOCAL_ARG
1407 && SYMBOL_CLASS (sym
) != LOC_REF_ARG
)
1410 /* We have to re-look-up the symbol because arguments often have
1411 two entries (one a parameter, one a register or local), and the one
1412 we want is the non-parm, which lookup_symbol will find for
1413 us. After this, sym could be any SYMBOL_CLASS... */
1414 sym
= lookup_symbol (SYMBOL_NAME (sym
),
1415 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
1417 switch (SYMBOL_CLASS (sym
)) {
1419 /* Keep track of the highest stack argument offset seen */
1423 int current_offset
= SYMBOL_VALUE (sym
);
1425 arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
1427 /* Compute address of next argument by adding the size of
1428 this argument and rounding to an int boundary. */
1430 = ((current_offset
+ arg_size
+ sizeof (int) - 1)
1431 & ~(sizeof (int) - 1));
1433 /* If this is the highest offset seen yet, set highest_offset. */
1434 if (highest_offset
== -1
1435 || (current_offset
> highest_offset
))
1436 highest_offset
= current_offset
;
1438 /* Add the number of ints we're about to print to args_printed. */
1439 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
1442 /* Other types of symbols don't need to be kept track of. */
1447 /* Print the current arg. */
1449 fprintf_filtered (stream
, ", ");
1451 fprint_symbol (stream
, SYMBOL_NAME (sym
));
1452 fputs_filtered ("=", stream
);
1454 /* Avoid value_print because it will deref ref parameters. We just
1455 want to print their addresses. Print ??? for args whose address
1457 val
= read_var_value (sym
, FRAME_INFO_ID (fi
));
1459 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), VALUE_ADDRESS (val
),
1460 stream
, 0, 0, 0, Val_no_prettyprint
);
1462 fputs_filtered ("???", stream
);
1466 /* Don't print nameless args in situations where we don't know
1467 enough about the stack to find them. */
1473 if (highest_offset
== -1)
1474 start
= FRAME_ARGS_SKIP
;
1476 start
= highest_offset
;
1478 addr
= FRAME_ARGS_ADDRESS (fi
);
1480 print_frame_nameless_args (addr
, start
, num
- args_printed
,
1485 /* Print nameless args on STREAM.
1486 ARGSADDR is the address of the arglist, START is the offset
1487 of the first nameless arg, and NUM is the number of nameless args to
1488 print. FIRST is nonzero if this is the first argument (not just
1489 the first nameless arg). */
1491 print_frame_nameless_args (argsaddr
, start
, num
, first
, stream
)
1499 for (i
= 0; i
< num
; i
++)
1503 fprintf_filtered (stream
, ", ");
1504 #ifndef PRINT_TYPELESS_INTEGER
1505 fprintf_filtered (stream
, "%d",
1506 read_memory_integer (argsaddr
+ start
, sizeof (int)));
1508 PRINT_TYPELESS_INTEGER (stream
, builtin_type_int
,
1510 read_memory_integer (argsaddr
+ start
,
1514 start
+= sizeof (int);
1519 printf_command (arg
, from_tty
)
1524 register char *s
= arg
;
1528 int allocated_args
= 20;
1531 val_args
= (value
*) xmalloc (allocated_args
* sizeof (value
));
1534 error_no_arg ("format-control string and values to print");
1536 /* Skip white space before format string */
1537 while (*s
== ' ' || *s
== '\t') s
++;
1539 /* A format string should follow, enveloped in double quotes */
1541 error ("Bad format string, missing '\"'.");
1543 /* Parse the format-control string and copy it into the string STRING,
1544 processing some kinds of escape sequence. */
1546 f
= string
= (char *) alloca (strlen (s
) + 1);
1553 error ("Bad format string, non-terminated '\"'.");
1554 /* doesn't return */
1575 /* ??? TODO: handle other escape sequences */
1576 error ("Unrecognized \\ escape character in format string.");
1585 /* Skip over " and following space and comma. */
1588 while (*s
== ' ' || *s
== '\t') s
++;
1590 if (*s
!= ',' && *s
!= 0)
1591 error ("Invalid argument syntax");
1594 while (*s
== ' ' || *s
== '\t') s
++;
1597 /* Now scan the string for %-specs and see what kinds of args they want.
1598 argclass[I] classifies the %-specs so we can give vprintf something
1599 of the right size. */
1601 enum argclass
{int_arg
, string_arg
, double_arg
, long_long_arg
};
1602 enum argclass
*argclass
;
1608 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1615 while (strchr ("0123456789.hlL-+ #", *f
))
1617 if (*f
== 'l' || *f
== 'L')
1622 argclass
[nargs_wanted
++] = string_arg
;
1623 else if (*f
== 'e' || *f
== 'f' || *f
== 'g')
1624 argclass
[nargs_wanted
++] = double_arg
;
1625 else if (lcount
> 1)
1626 argclass
[nargs_wanted
++] = long_long_arg
;
1628 argclass
[nargs_wanted
++] = int_arg
;
1632 /* Now, parse all arguments and evaluate them.
1633 Store the VALUEs in VAL_ARGS. */
1638 if (nargs
== allocated_args
)
1639 val_args
= (value
*) xrealloc (val_args
,
1640 (allocated_args
*= 2)
1643 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
1645 /* If format string wants a float, unchecked-convert the value to
1646 floating point of the same size */
1648 if (argclass
[nargs
] == double_arg
)
1650 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (float))
1651 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
1652 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (double))
1653 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
1661 if (nargs
!= nargs_wanted
)
1662 error ("Wrong number of arguments for specified format-string");
1664 /* Now lay out an argument-list containing the arguments
1665 as doubles, integers and C pointers. */
1667 arg_bytes
= (char *) alloca (sizeof (double) * nargs
);
1669 for (i
= 0; i
< nargs
; i
++)
1671 if (argclass
[i
] == string_arg
)
1675 tem
= value_as_long (val_args
[i
]);
1677 /* This is a %s argument. Find the length of the string. */
1682 read_memory (tem
+ j
, &c
, 1);
1687 /* Copy the string contents into a string inside GDB. */
1688 str
= (char *) alloca (j
+ 1);
1689 read_memory (tem
, str
, j
);
1692 /* Pass address of internal copy as the arg to vprintf. */
1693 *((int *) &arg_bytes
[argindex
]) = (int) str
;
1694 argindex
+= sizeof (int);
1696 else if (VALUE_TYPE (val_args
[i
])->code
== TYPE_CODE_FLT
)
1698 *((double *) &arg_bytes
[argindex
]) = value_as_double (val_args
[i
]);
1699 argindex
+= sizeof (double);
1703 if (argclass
[i
] == long_long_arg
)
1705 *(long long *) &arg_bytes
[argindex
] = value_as_long (val_args
[i
]);
1706 argindex
+= sizeof (long long);
1711 *((int *) &arg_bytes
[argindex
]) = value_as_long (val_args
[i
]);
1712 argindex
+= sizeof (int);
1717 /* There is not a standard way to make a va_list, so we need
1718 to do various things for different systems. */
1719 #if defined (__INT_VARARGS_H)
1724 list
.__va_stk
= (int *) arg_bytes
;
1725 list
.__va_reg
= (int *) arg_bytes
;
1726 vprintf (string
, list
);
1728 #else /* No __INT_VARARGS_H. */
1729 vprintf (string
, arg_bytes
);
1730 #endif /* No __INT_VARARGS_H. */
1733 /* Helper function for asdump_command. Finds the bounds of a function
1734 for a specified section of text. PC is an address within the
1735 function which you want bounds for; *LOW and *HIGH are set to the
1736 beginning (inclusive) and end (exclusive) of the function. This
1737 function returns 1 on success and 0 on failure. */
1740 containing_function_bounds (pc
, low
, high
)
1741 CORE_ADDR pc
, *low
, *high
;
1745 if (!find_pc_partial_function (pc
, 0, low
))
1751 if (!find_pc_partial_function (scan
, 0, high
))
1753 } while (*low
== *high
);
1758 /* Dump a specified section of assembly code. With no command line
1759 arguments, this command will dump the assembly code for the
1760 function surrounding the pc value in the selected frame. With one
1761 argument, it will dump the assembly code surrounding that pc value.
1762 Two arguments are interpeted as bounds within which to dump
1766 disassemble_command (arg
, from_tty
)
1770 CORE_ADDR low
, high
;
1776 if (!selected_frame
)
1777 error ("No frame selected.\n");
1779 pc
= get_frame_pc (selected_frame
);
1780 if (!containing_function_bounds (pc
, &low
, &high
))
1781 error ("No function contains pc specified by selected frame.\n");
1783 else if (!(space_index
= (char *) strchr (arg
, ' ')))
1786 pc
= parse_and_eval_address (arg
);
1787 if (!containing_function_bounds (pc
, &low
, &high
))
1788 error ("No function contains specified pc.\n");
1792 /* Two arguments. */
1793 *space_index
= '\0';
1794 low
= parse_and_eval_address (arg
);
1795 high
= parse_and_eval_address (space_index
+ 1);
1798 printf_filtered ("Dump of assembler code ");
1802 find_pc_partial_function (pc
, &name
, 0);
1803 printf_filtered ("for function %s:\n", name
);
1806 printf_filtered ("from 0x%x to 0x%x:\n", low
, high
);
1808 /* Dump the specified range. */
1809 for (pc
= low
; pc
< high
; )
1812 print_address (pc
, stdout
);
1813 printf_filtered (":\t");
1814 pc
+= print_insn (pc
, stdout
);
1815 printf_filtered ("\n");
1817 printf_filtered ("End of assembler dump.\n");
1823 _initialize_printcmd ()
1825 current_display_number
= -1;
1827 add_info ("address", address_info
,
1828 "Describe where variable VAR is stored.");
1830 add_com ("x", class_vars
, x_command
,
1831 "Examine memory: x/FMT ADDRESS.\n\
1832 ADDRESS is an expression for the memory address to examine.\n\
1833 FMT is a repeat count followed by a format letter and a size letter.\n\
1834 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1835 f(float), a(address), i(instruction), c(char) and s(string).\n\
1836 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1837 g is meaningful only with f, for type double.\n\
1838 The specified number of objects of the specified size are printed\n\
1839 according to the format.\n\n\
1840 Defaults for format and size letters are those previously used.\n\
1841 Default count is 1. Default address is following last thing printed\n\
1842 with this command or \"print\".");
1844 add_com ("disassemble", class_vars
, disassemble_command
,
1845 "Disassemble a specified section of memory.\n\
1846 Default is the function surrounding the pc of the selected frame.\n\
1847 With a single argument, the function surrounding that address is dumped.\n\
1848 Two arguments are taken as a range of memory to dump.");
1850 add_com ("ptype", class_vars
, ptype_command
,
1851 "Print definition of type TYPE.\n\
1852 Argument may be a type name defined by typedef, or \"struct STRUCTNAME\"\n\
1853 or \"union UNIONNAME\" or \"enum ENUMNAME\".\n\
1854 The selected stack frame's lexical context is used to look up the name.");
1856 add_com ("whatis", class_vars
, whatis_command
,
1857 "Print data type of expression EXP.");
1860 add_com ("whereis", class_vars
, whereis_command
,
1861 "Print line number and file of definition of variable.");
1864 add_info ("display", display_info
,
1865 "Expressions to display when program stops, with code numbers.");
1867 add_cmd ("undisplay", class_vars
, undisplay_command
,
1868 "Cancel some expressions to be displayed when program stops.\n\
1869 Arguments are the code numbers of the expressions to stop displaying.\n\
1870 No argument means cancel all automatic-display expressions.\n\
1871 \"delete display\" has the same effect as this command.\n\
1872 Do \"info display\" to see current list of code numbers.",
1875 add_com ("display", class_vars
, display_command
,
1876 "Print value of expression EXP each time the program stops.\n\
1877 /FMT may be used before EXP as in the \"print\" command.\n\
1878 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
1879 as in the \"x\" command, and then EXP is used to get the address to examine\n\
1880 and examining is done as in the \"x\" command.\n\n\
1881 With no argument, display all currently requested auto-display expressions.\n\
1882 Use \"undisplay\" to cancel display requests previously made.");
1884 add_cmd ("display", class_vars
, enable_display
,
1885 "Enable some expressions to be displayed when program stops.\n\
1886 Arguments are the code numbers of the expressions to resume displaying.\n\
1887 No argument means enable all automatic-display expressions.\n\
1888 Do \"info display\" to see current list of code numbers.", &enablelist
);
1890 add_cmd ("display", class_vars
, disable_display_command
,
1891 "Disable some expressions to be displayed when program stops.\n\
1892 Arguments are the code numbers of the expressions to stop displaying.\n\
1893 No argument means disable all automatic-display expressions.\n\
1894 Do \"info display\" to see current list of code numbers.", &disablelist
);
1896 add_cmd ("display", class_vars
, undisplay_command
,
1897 "Cancel some expressions to be displayed when program stops.\n\
1898 Arguments are the code numbers of the expressions to stop displaying.\n\
1899 No argument means cancel all automatic-display expressions.\n\
1900 Do \"info display\" to see current list of code numbers.", &deletelist
);
1902 add_com ("printf", class_vars
, printf_command
,
1903 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
1904 This is useful for formatted output in user-defined commands.");
1905 add_com ("output", class_vars
, output_command
,
1906 "Like \"print\" but don't put in value history and don't print newline.\n\
1907 This is useful in user-defined commands.");
1909 add_prefix_cmd ("set", class_vars
, set_command
,
1910 "Perform an assignment VAR = EXP.\n\
1911 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
1912 (names starting with $), a register (a few standard names starting with $),\n\
1913 or an actual variable in the program being debugged. EXP is any expression.\n\
1914 Use \"set variable\" for variables with names identical to set subcommands.\n\
1915 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
1916 You can see these environment settings with the \"show\" command.",
1917 &setlist
, "set ", 1, &cmdlist
);
1919 /* "call" is the same as "set", but handy for dbx users to call fns. */
1920 add_com ("call", class_vars
, call_command
,
1921 "Call a function in the inferior process.\n\
1922 The argument is the function name and arguments, in standard C notation.\n\
1923 The result is printed and saved in the value history, if it is not void.");
1925 add_cmd ("variable", class_vars
, set_command
,
1926 "Perform an assignment VAR = EXP.\n\
1927 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
1928 (names starting with $), a register (a few standard names starting with $),\n\
1929 or an actual variable in the program being debugged. EXP is any expression.\n\
1930 This may usually be abbreviated to simply \"set\".",
1933 add_com ("print", class_vars
, print_command
,
1934 concat ("Print value of expression EXP.\n\
1935 Variables accessible are those of the lexical environment of the selected\n\
1936 stack frame, plus all those whose scope is global or an entire file.\n\
1938 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
1939 $$NUM refers to NUM'th value back from the last one.\n\
1940 Names starting with $ refer to registers (with the values they would have\n\
1941 if the program were to return to the stack frame now selected, restoring\n\
1942 all registers saved by frames farther in) or else to debugger\n\
1943 \"convenience\" variables (any such name not a known register).\n\
1944 Use assignment expressions to give values to convenience variables.\n",
1946 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
1947 @ is a binary operator for treating consecutive data objects\n\
1948 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
1949 element is FOO, whose second element is stored in the space following\n\
1950 where FOO is stored, etc. FOO must be an expression whose value\n\
1951 resides in memory.\n",
1953 EXP may be preceded with /FMT, where FMT is a format letter\n\
1954 but no count or size letter (see \"x\" command)."));
1955 add_com_alias ("p", "print", class_vars
, 1);
1957 add_com ("inspect", class_vars
, inspect_command
,
1958 "Same as \"print\" command, except that if you are running in the epoch\n\
1959 environment, the value is printed in its own window.");