1 /* Print values for GNU debugger GDB.
2 Copyright (C) 1986, 1987, 1988, 1989 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. */
26 #include "expression.h"
35 /* Last specified output format. */
37 static char last_format
= 'x';
39 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
41 static char last_size
= 'w';
43 /* Default address to examine next. */
45 static CORE_ADDR next_address
;
47 /* Last address examined. */
49 static CORE_ADDR last_examine_address
;
51 /* Contents of last address examined.
52 This is not valid past the end of the `x' command! */
54 static value last_examine_value
;
56 /* Number of auto-display expression currently being displayed.
57 So that we can deleted it if we get an error or a signal within it.
58 -1 when not doing one. */
60 int current_display_number
;
62 static void do_one_display ();
65 void print_address ();
66 void print_scalar_formatted ();
69 /* Decode a format specification. *STRING_PTR should point to it.
70 OFORMAT and OSIZE are used as defaults for the format and size
71 if none are given in the format specification.
72 If OSIZE is zero, then the size field of the returned value
73 should be set only if a size is explicitly specified by the
75 The structure returned describes all the data
76 found in the specification. In addition, *STRING_PTR is advanced
77 past the specification and past all whitespace following it. */
80 decode_format (string_ptr
, oformat
, osize
)
85 struct format_data val
;
86 register char *p
= *string_ptr
;
92 if (*p
>= '0' && *p
<= '9')
94 while (*p
>= '0' && *p
<= '9') p
++;
96 /* Now process size or format letters that follow. */
100 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
109 else if (*p
>= 'a' && *p
<= 'z')
116 /* Make sure 'g' size is not used on integer types.
117 Well, actually, we can handle hex. */
118 if (val
.size
== 'g' && val
.format
!= 'f' && val
.format
!= 'x')
122 while (*p
== ' ' || *p
== '\t') p
++;
125 /* Set defaults for format and size if not specified. */
126 if (val
.format
== '?')
130 /* Neither has been specified. */
131 val
.format
= oformat
;
135 /* If a size is specified, any format makes a reasonable
136 default except 'i'. */
137 val
.format
= oformat
== 'i' ? 'x' : oformat
;
139 else if (val
.size
== '?')
144 /* Addresses must be words. */
145 val
.size
= osize
? 'w' : osize
;
148 /* Floating point has to be word or giantword. */
149 if (osize
== 'w' || osize
== 'g')
152 /* Default it to giantword if the last used size is not
154 val
.size
= osize
? 'g' : osize
;
157 /* Characters default to one byte. */
158 val
.size
= osize
? 'b' : osize
;
161 /* The default is the size most recently specified. */
168 /* Print value VAL on stdout according to FORMAT, a letter or 0.
169 Do not end with a newline.
170 0 means print VAL according to its own type.
171 SIZE is the letter for the size of datum being printed.
172 This is used to pad hex numbers so they line up. */
175 print_formatted (val
, format
, size
)
177 register char format
;
180 int len
= TYPE_LENGTH (VALUE_TYPE (val
));
182 if (VALUE_LVAL (val
) == lval_memory
)
183 next_address
= VALUE_ADDRESS (val
) + len
;
188 next_address
= VALUE_ADDRESS (val
)
189 + value_print (value_addr (val
), stdout
, 0, Val_pretty_default
);
193 next_address
= VALUE_ADDRESS (val
)
194 + print_insn (VALUE_ADDRESS (val
), stdout
);
199 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_ARRAY
200 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_STRUCT
201 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_UNION
202 || VALUE_REPEATED (val
))
203 value_print (val
, stdout
, format
, Val_pretty_default
);
205 print_scalar_formatted (VALUE_CONTENTS (val
), VALUE_TYPE (val
),
206 format
, size
, stdout
);
210 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
211 according to letters FORMAT and SIZE on STREAM.
212 FORMAT may not be zero. Formats s and i are not supported at this level.
214 This is how the elements of an array or structure are printed
218 print_scalar_formatted (valaddr
, type
, format
, size
, stream
)
226 int len
= TYPE_LENGTH (type
);
228 if (size
== 'g' && sizeof (LONGEST
) < 8
231 /* ok, we're going to have to get fancy here. Assumption: a
232 long is four bytes. */
233 unsigned long v1
, v2
, tmp
;
235 v1
= unpack_long (builtin_type_long
, valaddr
);
236 v2
= unpack_long (builtin_type_long
, valaddr
+ 4);
238 #ifdef BYTES_BIG_ENDIAN
240 /* Little endian -- swap the two for printing */
249 fprintf_filtered (stream
, "0x%08x%08x", v1
, v2
);
252 error ("Output size \"g\" unimplemented for format \"%c\".",
258 val_long
= unpack_long (type
, valaddr
);
260 /* If value is unsigned, truncate it in case negative. */
263 if (len
== sizeof (char))
264 val_long
&= (1 << 8 * sizeof(char)) - 1;
265 else if (len
== sizeof (short))
266 val_long
&= (1 << 8 * sizeof(short)) - 1;
267 else if (len
== sizeof (long))
268 val_long
&= (unsigned long) - 1;
276 size
= (len
< sizeof (long long) ? 'w' : 'g');
280 fprintf_filtered (stream
, "0x%02llx", val_long
);
283 fprintf_filtered (stream
, "0x%04llx", val_long
);
285 case 0: /* no size specified, like in print */
287 fprintf_filtered (stream
, "0x%08llx", val_long
);
290 fprintf_filtered (stream
, "0x%016llx", val_long
);
293 error ("Undefined output size \"%c\".", size
);
299 fprintf_filtered (stream
, "0x%02x", val_long
);
302 fprintf_filtered (stream
, "0x%04x", val_long
);
304 case 0: /* no size specified, like in print */
306 fprintf_filtered (stream
, "0x%08x", val_long
);
309 fprintf_filtered (stream
, "0x%o16x", val_long
);
312 error ("Undefined output size \"%c\".", size
);
314 #endif /* not LONG_LONG */
319 fprintf_filtered (stream
, "%lld", val_long
);
321 fprintf_filtered (stream
, "%d", val_long
);
327 fprintf_filtered (stream
, "%llu", val_long
);
329 fprintf_filtered (stream
, "%u", val_long
);
336 fprintf_filtered (stream
, "0%llo", val_long
);
338 fprintf_filtered (stream
, "0%o", val_long
);
341 fprintf_filtered (stream
, "0");
345 print_address ((CORE_ADDR
) val_long
, stream
);
349 value_print (value_from_long (builtin_type_char
, val_long
), stream
, 0,
354 if (len
== sizeof (float))
355 type
= builtin_type_float
;
356 else if (len
== sizeof (double))
357 type
= builtin_type_double
;
359 if (is_nan (type
, valaddr
))
361 fprintf_filtered (stream
, "Nan");
369 doub
= unpack_double (type
, valaddr
, &inv
);
371 fprintf_filtered (stream
, "Invalid float value");
373 fprintf_filtered (stream
, len
> 4 ? "%.16g" : "%.6g", doub
);
381 error ("Undefined output format \"%c\".", format
);
385 /* Specify default address for `x' command.
386 `info lines' uses this. */
389 set_next_address (addr
)
394 /* Make address available to the user as $_. */
395 set_internalvar (lookup_internalvar ("_"),
396 value_from_long (builtin_type_int
, (LONGEST
) addr
));
399 /* Print address ADDR symbolically on STREAM.
400 First print it as a number. Then perhaps print
401 <SYMBOL + OFFSET> after the number. */
404 print_address (addr
, stream
)
409 register char *format
;
410 register struct symbol
*fs
;
414 i
= find_pc_partial_function (addr
, &name
, &name_location
);
416 /* If nothing comes out, don't print anything symbolic. */
420 else if (addr
- name_location
)
421 format
= "0x%x <%s+%d>";
423 format
= "0x%x <%s>";
425 fprintf_filtered (stream
, format
, addr
, name
, addr
- name_location
);
428 /* Examine data at address ADDR in format FMT.
429 Fetch it from memory and print on stdout. */
432 do_examine (fmt
, addr
)
433 struct format_data fmt
;
436 register char format
= 0;
438 register int count
= 1;
439 struct type
*val_type
;
441 register int maxelts
;
448 /* String or instruction format implies fetch single bytes
449 regardless of the specified size. */
450 if (format
== 's' || format
== 'i')
454 val_type
= builtin_type_char
;
455 else if (size
== 'h')
456 val_type
= builtin_type_short
;
457 else if (size
== 'w')
458 val_type
= builtin_type_long
;
459 else if (size
== 'g')
461 val_type
= builtin_type_double
;
463 val_type
= builtin_type_long_long
;
471 if (format
== 's' || format
== 'i')
474 /* Print as many objects as specified in COUNT, at most maxelts per line,
475 with the address of the next one at the start of each line. */
479 print_address (next_address
, stdout
);
480 printf_filtered (":");
485 printf_filtered ("\t");
486 /* Note that print_formatted sets next_address for the next
488 last_examine_address
= next_address
;
489 last_examine_value
= value_at (val_type
, next_address
);
490 print_formatted (last_examine_value
, format
, size
);
492 printf_filtered ("\n");
498 validate_format (fmt
, cmdname
)
499 struct format_data fmt
;
503 error ("Size letters are meaningless in \"%s\" command.", cmdname
);
505 error ("Item count other than 1 is meaningless in \"%s\" command.",
507 if (fmt
.format
== 'i' || fmt
.format
== 's')
508 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
509 fmt
.format
, cmdname
);
516 struct expression
*expr
;
517 register struct cleanup
*old_chain
= 0;
518 register char format
= 0;
520 struct format_data fmt
;
524 if (exp
&& *exp
== '/')
527 fmt
= decode_format (&exp
, last_format
, 0);
528 validate_format (fmt
, "print");
529 last_format
= format
= fmt
.format
;
534 expr
= parse_c_expression (exp
);
535 old_chain
= make_cleanup (free_current_contents
, &expr
);
537 val
= evaluate_expression (expr
);
540 val
= access_value_history (0);
542 histindex
= record_latest_value (val
);
543 if (histindex
>= 0) printf_filtered ("$%d = ", histindex
);
545 print_formatted (val
, format
, fmt
.size
);
546 printf_filtered ("\n");
549 do_cleanups (old_chain
);
556 struct expression
*expr
;
557 register struct cleanup
*old_chain
;
558 register char format
= 0;
560 struct format_data fmt
;
562 if (exp
&& *exp
== '/')
565 fmt
= decode_format (&exp
, 0, 0);
566 validate_format (fmt
, "print");
570 expr
= parse_c_expression (exp
);
571 old_chain
= make_cleanup (free_current_contents
, &expr
);
573 val
= evaluate_expression (expr
);
575 print_formatted (val
, format
, fmt
.size
);
577 do_cleanups (old_chain
);
584 struct expression
*expr
= parse_c_expression (exp
);
585 register struct cleanup
*old_chain
586 = make_cleanup (free_current_contents
, &expr
);
587 evaluate_expression (expr
);
588 do_cleanups (old_chain
);
595 register struct symbol
*sym
;
596 register CORE_ADDR val
;
597 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
598 if exp is a field of `this'. */
601 error ("Argument required.");
603 sym
= lookup_symbol (exp
, get_selected_block (), VAR_NAMESPACE
,
604 &is_a_field_of_this
);
609 if (is_a_field_of_this
)
611 printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp
);
615 for (i
= 0; i
< misc_function_count
; i
++)
616 if (!strcmp (misc_function_vector
[i
].name
, exp
))
619 if (i
< misc_function_count
)
620 printf ("Symbol \"%s\" is at 0x%x in a file compiled without -g.\n",
621 exp
, misc_function_vector
[i
].address
);
623 error ("No symbol \"%s\" in current context.", exp
);
627 printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym
));
628 val
= SYMBOL_VALUE (sym
);
630 switch (SYMBOL_CLASS (sym
))
633 case LOC_CONST_BYTES
:
638 printf ("a label at address 0x%x", val
);
642 printf ("a variable in register %s", reg_names
[val
]);
646 printf ("static at address 0x%x", val
);
650 printf ("an argument in register %s", reg_names
[val
]);
654 printf ("an argument at offset %d", val
);
658 printf ("a local variable at frame offset %d", val
);
662 printf ("a reference argument at offset %d", val
);
666 printf ("a typedef");
670 printf ("a function at address 0x%x",
671 BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)));
678 x_command (exp
, from_tty
)
682 struct expression
*expr
;
683 struct format_data fmt
;
684 struct cleanup
*old_chain
;
687 fmt
.format
= last_format
;
688 fmt
.size
= last_size
;
691 if (exp
&& *exp
== '/')
694 fmt
= decode_format (&exp
, last_format
, last_size
);
695 last_size
= fmt
.size
;
696 last_format
= fmt
.format
;
699 /* If we have an expression, evaluate it and use it as the address. */
701 if (exp
!= 0 && *exp
!= 0)
703 expr
= parse_c_expression (exp
);
704 /* Cause expression not to be there any more
705 if this command is repeated with Newline.
706 But don't clobber a user-defined command's definition. */
709 old_chain
= make_cleanup (free_current_contents
, &expr
);
710 val
= evaluate_expression (expr
);
711 /* In rvalue contexts, such as this, functions are coerced into
712 pointers to functions. This makes "x/i main" work. */
713 if (/* last_format == 'i'
714 && */ TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FUNC
715 && VALUE_LVAL (val
) == lval_memory
)
716 next_address
= VALUE_ADDRESS (val
);
718 next_address
= (CORE_ADDR
) value_as_long (val
);
719 do_cleanups (old_chain
);
722 do_examine (fmt
, next_address
);
724 /* Set a couple of internal variables if appropriate. */
725 if (last_examine_value
)
727 /* Make last address examined available to the user as $_. */
728 set_internalvar (lookup_internalvar ("_"),
729 value_from_long (builtin_type_int
,
730 (LONGEST
) last_examine_address
));
732 /* Make contents of last address examined available to the user as $__.*/
733 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
737 /* Commands for printing types of things. */
743 struct expression
*expr
;
745 register struct cleanup
*old_chain
;
749 expr
= parse_c_expression (exp
);
750 old_chain
= make_cleanup (free_current_contents
, &expr
);
751 val
= evaluate_type (expr
);
754 val
= access_value_history (0);
756 printf_filtered ("type = ");
757 /* Most of the time users do not want to see all the fields
758 in a structure. If they do they can use the "ptype" command.
759 Hence the "-1" below. */
760 type_print (VALUE_TYPE (val
), "", stdout
, -1);
761 printf_filtered ("\n");
764 do_cleanups (old_chain
);
768 ptype_command (typename
)
771 register char *p
= typename
;
773 extern struct block
*get_current_block ();
774 register struct block
*b
775 = (have_inferior_p () || have_core_file_p ()) ? get_current_block () : 0;
776 register struct type
*type
;
779 error_no_arg ("type name");
781 while (*p
&& *p
!= ' ' && *p
!= '\t') p
++;
783 while (*p
== ' ' || *p
== '\t') p
++;
785 if (len
== 6 && !strncmp (typename
, "struct", 6))
786 type
= lookup_struct (p
, b
);
787 else if (len
== 5 && !strncmp (typename
, "union", 5))
788 type
= lookup_union (p
, b
);
789 else if (len
== 4 && !strncmp (typename
, "enum", 4))
790 type
= lookup_enum (p
, b
);
793 type
= lookup_typename (typename
, b
, 1);
796 register struct symbol
*sym
797 = lookup_symbol (typename
, b
, STRUCT_NAMESPACE
, 0);
799 error ("No type named %s.", typename
);
800 printf_filtered ("No type named %s, but there is a ",
802 switch (TYPE_CODE (SYMBOL_TYPE (sym
)))
804 case TYPE_CODE_STRUCT
:
805 printf_filtered ("struct");
808 case TYPE_CODE_UNION
:
809 printf_filtered ("union");
813 printf_filtered ("enum");
815 printf_filtered (" %s. Type \"help ptype\".\n", typename
);
816 type
= SYMBOL_TYPE (sym
);
820 type_print (type
, "", stdout
, 1);
821 printf_filtered ("\n");
824 enum display_status
{disabled
, enabled
};
828 /* Chain link to next auto-display item. */
829 struct display
*next
;
830 /* Expression to be evaluated and displayed. */
831 struct expression
*exp
;
832 /* Item number of this auto-display item. */
834 /* Display format specified. */
835 struct format_data format
;
836 /* Innermost block required by this expression when evaluated */
838 /* Status of this display (enabled or disabled) */
839 enum display_status status
;
842 /* Chain of expressions whose values should be displayed
843 automatically each time the program stops. */
845 static struct display
*display_chain
;
847 static int display_number
;
849 /* Add an expression to the auto-display chain.
850 Specify the expression. */
853 display_command (exp
, from_tty
)
857 struct format_data fmt
;
858 register struct expression
*expr
;
859 register struct display
*new;
860 extern struct block
*innermost_block
;
871 fmt
= decode_format (&exp
, 0, 0);
872 if (fmt
.size
&& fmt
.format
== 0)
874 if (fmt
.format
== 'i' || fmt
.format
== 's')
885 expr
= parse_c_expression (exp
);
887 new = (struct display
*) xmalloc (sizeof (struct display
));
890 new->block
= innermost_block
;
891 new->next
= display_chain
;
892 new->number
= ++display_number
;
894 new->status
= enabled
;
897 if (from_tty
&& have_inferior_p ())
898 do_one_display (new);
911 /* Clear out the display_chain.
912 Done when new symtabs are loaded, since this invalidates
913 the types stored in many expressions. */
918 register struct display
*d
;
920 while (d
= display_chain
)
923 display_chain
= d
->next
;
928 /* Delete the auto-display number NUM. */
934 register struct display
*d1
, *d
;
937 error ("No display number %d.", num
);
939 if (display_chain
->number
== num
)
942 display_chain
= d1
->next
;
946 for (d
= display_chain
; ; d
= d
->next
)
949 error ("No display number %d.", num
);
950 if (d
->next
->number
== num
)
960 /* Delete some values from the auto-display chain.
961 Specify the element numbers. */
964 undisplay_command (args
)
967 register char *p
= args
;
970 register struct display
*d
, *d1
;
974 if (query ("Delete all auto-display expressions? "))
983 while (*p1
>= '0' && *p1
<= '9') p1
++;
984 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
985 error ("Arguments must be display numbers.");
989 delete_display (num
);
992 while (*p
== ' ' || *p
== '\t') p
++;
997 /* Display a single auto-display.
998 Do nothing if the display cannot be printed in the current context,
999 or if the display is disabled. */
1005 int within_current_scope
;
1007 if (d
->status
== disabled
)
1011 within_current_scope
= contained_in (get_selected_block (), d
->block
);
1013 within_current_scope
= 1;
1014 if (!within_current_scope
)
1017 current_display_number
= d
->number
;
1019 printf_filtered ("%d: ", d
->number
);
1022 printf_filtered ("x/");
1023 if (d
->format
.count
!= 1)
1024 printf_filtered ("%d", d
->format
.count
);
1025 printf_filtered ("%c", d
->format
.format
);
1026 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1027 printf_filtered ("%c", d
->format
.size
);
1028 printf_filtered (" ");
1029 print_expression (d
->exp
, stdout
);
1030 if (d
->format
.count
!= 1)
1031 printf_filtered ("\n");
1033 printf_filtered (" ");
1034 do_examine (d
->format
,
1035 (CORE_ADDR
) value_as_long (evaluate_expression (d
->exp
)));
1040 if (d
->format
.format
)
1041 printf_filtered ("/%c ", d
->format
.format
);
1042 print_expression (d
->exp
, stdout
);
1043 printf_filtered (" = ");
1044 print_formatted (evaluate_expression (d
->exp
),
1045 d
->format
.format
, d
->format
.size
);
1046 printf_filtered ("\n");
1050 current_display_number
= -1;
1053 /* Display all of the values on the auto-display chain which can be
1054 evaluated in the current scope. */
1059 register struct display
*d
;
1061 for (d
= display_chain
; d
; d
= d
->next
)
1065 /* Delete the auto-display which we were in the process of displaying.
1066 This is done when there is an error or a signal. */
1069 disable_display (num
)
1072 register struct display
*d
;
1074 for (d
= display_chain
; d
; d
= d
->next
)
1075 if (d
->number
== num
)
1077 d
->status
= disabled
;
1080 printf ("No display number %d.\n", num
);
1084 disable_current_display ()
1086 if (current_display_number
>= 0)
1088 disable_display (current_display_number
);
1089 fprintf (stderr
, "Disabling display %d to avoid infinite recursion.\n",
1090 current_display_number
);
1092 current_display_number
= -1;
1098 register struct display
*d
;
1101 printf ("There are no auto-display expressions now.\n");
1103 printf_filtered ("Auto-display expressions now in effect:\n\
1104 Num Enb Expression\n");
1106 for (d
= display_chain
; d
; d
= d
->next
)
1108 printf_filtered ("%d: %c ", d
->number
, "ny"[(int)d
->status
]);
1110 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1112 else if (d
->format
.format
)
1113 printf_filtered ("/%c ", d
->format
.format
);
1114 print_expression (d
->exp
, stdout
);
1115 if (d
->block
&& !contained_in (get_selected_block (), d
->block
))
1116 printf_filtered (" (cannot be evaluated in the current context)");
1117 printf_filtered ("\n");
1123 enable_display (args
)
1126 register char *p
= args
;
1129 register struct display
*d
;
1133 for (d
= display_chain
; d
; d
= d
->next
)
1134 d
->status
= enabled
;
1140 while (*p1
>= '0' && *p1
<= '9')
1142 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1143 error ("Arguments must be display numbers.");
1147 for (d
= display_chain
; d
; d
= d
->next
)
1148 if (d
->number
== num
)
1150 d
->status
= enabled
;
1153 printf ("No display number %d.\n", num
);
1156 while (*p
== ' ' || *p
== '\t')
1162 disable_display_command (args
, from_tty
)
1166 register char *p
= args
;
1169 register struct display
*d
;
1173 for (d
= display_chain
; d
; d
= d
->next
)
1174 d
->status
= disabled
;
1180 while (*p1
>= '0' && *p1
<= '9')
1182 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1183 error ("Arguments must be display numbers.");
1187 disable_display (atoi (p
));
1190 while (*p
== ' ' || *p
== '\t')
1196 /* Print the value in stack frame FRAME of a variable
1197 specified by a struct symbol. */
1200 print_variable_value (var
, frame
, stream
)
1205 value val
= read_var_value (var
, frame
);
1206 value_print (val
, stream
, 0, Val_pretty_default
);
1216 /* Print the arguments of a stack frame, given the function FUNC
1217 running in that frame (as a symbol), the info on the frame,
1218 and the number of args according to the stack frame (or -1 if unknown). */
1220 static void print_frame_nameless_args ();
1223 print_frame_args (func
, fi
, num
, stream
)
1224 struct symbol
*func
;
1225 struct frame_info
*fi
;
1233 register int last_regparm
= 0;
1234 register struct symbol
*lastsym
, *sym
, *nextsym
;
1236 /* Offset of stack argument that is at the highest offset.
1237 -1 if we haven't come to a stack argument yet. */
1238 CORE_ADDR highest_offset
= (CORE_ADDR
) -1;
1239 register CORE_ADDR addr
= FRAME_ARGS_ADDRESS (fi
);
1243 b
= SYMBOL_BLOCK_VALUE (func
);
1244 nsyms
= BLOCK_NSYMS (b
);
1247 for (i
= 0; i
< nsyms
; i
++)
1250 sym
= BLOCK_SYM (b
, i
);
1252 if (SYMBOL_CLASS (sym
) != LOC_REGPARM
1253 && SYMBOL_CLASS (sym
) != LOC_ARG
1254 && SYMBOL_CLASS (sym
) != LOC_REF_ARG
)
1257 /* Print the next arg. */
1258 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
)
1259 val
= value_from_register (SYMBOL_TYPE (sym
),
1261 FRAME_INFO_ID (fi
));
1264 int current_offset
= SYMBOL_VALUE (sym
);
1265 int arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
1267 if (SYMBOL_CLASS (sym
) == LOC_REF_ARG
)
1268 val
= value_at (SYMBOL_TYPE (sym
),
1269 read_memory_integer (addr
+ current_offset
,
1270 sizeof (CORE_ADDR
)));
1272 val
= value_at (SYMBOL_TYPE (sym
), addr
+ current_offset
);
1274 /* Round up address of next arg to multiple of size of int. */
1276 = (((current_offset
+ sizeof (int) - 1) / sizeof (int))
1279 /* If this is the highest offset seen yet, set highest_offset. */
1280 if (highest_offset
== (CORE_ADDR
)-1
1282 + (arg_size
- sizeof (int) + 3) / (sizeof (int)))
1284 highest_offset
= current_offset
;
1288 fprintf_filtered (stream
, ", ");
1289 fputs_filtered (SYMBOL_NAME (sym
), stream
);
1290 fputs_filtered ("=", stream
);
1292 /* Nonzero if a LOC_ARG which is a struct is useless. */
1293 #if !defined (STRUCT_ARG_SYM_GARBAGE)
1294 #define STRUCT_ARG_SYM_GARBAGE(gcc_p) 0
1297 if (STRUCT_ARG_SYM_GARBAGE (b
->gcc_compile_flag
)
1298 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1299 && SYMBOL_CLASS (sym
) == LOC_ARG
)
1301 /* Try looking up that name. SunOS4 puts out a usable
1302 symbol as a local variable (in addition to the one
1304 struct symbol
*sym2
=
1305 lookup_symbol (SYMBOL_NAME (sym
), b
, VAR_NAMESPACE
, 0);
1308 val
= value_of_variable (sym2
);
1311 fputs_filtered ("?", stream
);
1317 value_print (val
, stream
, 0, Val_no_prettyprint
);
1321 /* Don't print nameless args in situations where we don't know
1322 enough about the stack to find them. */
1325 if (highest_offset
!= (CORE_ADDR
) -1
1326 && num
* sizeof (int) + FRAME_ARGS_SKIP
> highest_offset
)
1327 print_frame_nameless_args (addr
,
1328 highest_offset
+ sizeof (int),
1329 num
* sizeof (int) + FRAME_ARGS_SKIP
,
1332 print_frame_nameless_args (addr
, FRAME_ARGS_SKIP
,
1333 num
* sizeof (int) + FRAME_ARGS_SKIP
,
1339 print_frame_nameless_args (argsaddr
, start
, end
, stream
)
1348 if (start
!= FRAME_ARGS_SKIP
)
1349 fprintf_filtered (stream
, ", ");
1350 #ifndef PRINT_TYPELESS_INTEGER
1351 fprintf_filtered (stream
, "%d",
1352 read_memory_integer (argsaddr
+ start
, sizeof (int)));
1354 PRINT_TYPELESS_INTEGER (stream
, builtin_type_int
,
1356 read_memory_integer (argsaddr
+ start
,
1359 start
+= sizeof (int);
1364 printf_command (arg
)
1368 register char *s
= arg
;
1372 int allocated_args
= 20;
1375 val_args
= (value
*) xmalloc (allocated_args
* sizeof (value
));
1378 error_no_arg ("format-control string and values to print");
1380 /* Skip white space before format string */
1381 while (*s
== ' ' || *s
== '\t') s
++;
1383 /* A format string should follow, enveloped in double quotes */
1385 error ("Bad format string, missing '\"'.");
1387 /* Parse the format-control string and copy it into the string STRING,
1388 processing some kinds of escape sequence. */
1390 f
= string
= (char *) alloca (strlen (s
) + 1);
1397 error ("Bad format string, non-terminated '\"'.");
1398 /* doesn't return */
1419 /* ??? TODO: handle other escape sequences */
1420 error ("Unrecognized \\ escape character in format string.");
1429 /* Skip over " and following space and comma. */
1432 while (*s
== ' ' || *s
== '\t') s
++;
1434 if (*s
!= ',' && *s
!= 0)
1435 error ("Invalid argument syntax");
1438 while (*s
== ' ' || *s
== '\t') s
++;
1441 /* Now scan the string for %-specs and see what kinds of args they want.
1442 argclass[I] classifies the %-specs so we can give vprintf something
1443 of the right size. */
1445 enum argclass
{int_arg
, string_arg
, double_arg
, long_long_arg
};
1446 enum argclass
*argclass
;
1452 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1459 while (index ("0123456789.hlL-+ #", *f
))
1461 if (*f
== 'l' || *f
== 'L')
1466 argclass
[nargs_wanted
++] = string_arg
;
1467 else if (*f
== 'e' || *f
== 'f' || *f
== 'g')
1468 argclass
[nargs_wanted
++] = double_arg
;
1469 else if (lcount
> 1)
1470 argclass
[nargs_wanted
++] = long_long_arg
;
1472 argclass
[nargs_wanted
++] = int_arg
;
1476 /* Now, parse all arguments and evaluate them.
1477 Store the VALUEs in VAL_ARGS. */
1482 if (nargs
== allocated_args
)
1483 val_args
= (value
*) xrealloc (val_args
,
1484 (allocated_args
*= 2)
1487 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
1489 /* If format string wants a float, unchecked-convert the value to
1490 floating point of the same size */
1492 if (argclass
[nargs
] == double_arg
)
1494 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (float))
1495 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
1496 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (double))
1497 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
1505 if (nargs
!= nargs_wanted
)
1506 error ("Wrong number of arguments for specified format-string");
1508 /* Now lay out an argument-list containing the arguments
1509 as doubles, integers and C pointers. */
1511 arg_bytes
= (char *) alloca (sizeof (double) * nargs
);
1513 for (i
= 0; i
< nargs
; i
++)
1515 if (argclass
[i
] == string_arg
)
1519 tem
= value_as_long (val_args
[i
]);
1521 /* This is a %s argument. Find the length of the string. */
1526 read_memory (tem
+ j
, &c
, 1);
1531 /* Copy the string contents into a string inside GDB. */
1532 str
= (char *) alloca (j
+ 1);
1533 read_memory (tem
, str
, j
);
1536 /* Pass address of internal copy as the arg to vprintf. */
1537 *((int *) &arg_bytes
[argindex
]) = (int) str
;
1538 argindex
+= sizeof (int);
1540 else if (VALUE_TYPE (val_args
[i
])->code
== TYPE_CODE_FLT
)
1542 *((double *) &arg_bytes
[argindex
]) = value_as_double (val_args
[i
]);
1543 argindex
+= sizeof (double);
1547 if (argclass
[i
] == long_long_arg
)
1549 *(long long *) &arg_bytes
[argindex
] = value_as_long (val_args
[i
]);
1550 argindex
+= sizeof (long long);
1555 *((int *) &arg_bytes
[argindex
]) = value_as_long (val_args
[i
]);
1556 argindex
+= sizeof (int);
1560 vprintf (string
, arg_bytes
);
1563 /* Helper function for asdump_command. Finds the bounds of a function
1564 for a specified section of text. PC is an address within the
1565 function which you want bounds for; *LOW and *HIGH are set to the
1566 beginning (inclusive) and end (exclusive) of the function. This
1567 function returns 1 on success and 0 on failure. */
1570 containing_function_bounds (pc
, low
, high
)
1571 CORE_ADDR pc
, *low
, *high
;
1575 if (!find_pc_partial_function (pc
, 0, low
))
1581 if (!find_pc_partial_function (scan
, 0, high
))
1583 } while (*low
== *high
);
1588 /* Dump a specified section of assembly code. With no command line
1589 arguments, this command will dump the assembly code for the
1590 function surrounding the pc value in the selected frame. With one
1591 argument, it will dump the assembly code surrounding that pc value.
1592 Two arguments are interpeted as bounds within which to dump
1596 disassemble_command (arg
, from_tty
)
1600 CORE_ADDR low
, high
;
1606 if (!selected_frame
)
1607 error ("No frame selected.\n");
1609 pc
= get_frame_pc (selected_frame
);
1610 if (!containing_function_bounds (pc
, &low
, &high
))
1611 error ("No function contains pc specified by selected frame.\n");
1613 else if (!(space_index
= (char *) index (arg
, ' ')))
1616 pc
= parse_and_eval_address (arg
);
1617 if (!containing_function_bounds (pc
, &low
, &high
))
1618 error ("No function contains specified pc.\n");
1622 /* Two arguments. */
1623 *space_index
= '\0';
1624 low
= parse_and_eval_address (arg
);
1625 high
= parse_and_eval_address (space_index
+ 1);
1628 printf_filtered ("Dump of assembler code ");
1632 find_pc_partial_function (pc
, &name
, 0);
1633 printf_filtered ("for function %s:\n", name
);
1636 printf_filtered ("from 0x%x to 0x%x:\n", low
, high
);
1638 /* Dump the specified range. */
1639 for (pc
= low
; pc
< high
; )
1642 print_address (pc
, stdout
);
1643 printf_filtered (":\t");
1644 pc
+= print_insn (pc
, stdout
);
1645 printf_filtered ("\n");
1647 printf_filtered ("End of assembler dump.\n");
1652 extern struct cmd_list_element
*enablelist
, *disablelist
, *deletelist
;
1653 extern struct cmd_list_element
*cmdlist
, *setlist
;
1656 _initialize_printcmd ()
1658 current_display_number
= -1;
1660 add_info ("address", address_info
,
1661 "Describe where variable VAR is stored.");
1663 add_com ("x", class_vars
, x_command
,
1664 "Examine memory: x/FMT ADDRESS.\n\
1665 ADDRESS is an expression for the memory address to examine.\n\
1666 FMT is a repeat count followed by a format letter and a size letter.\n\
1667 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1668 f(float), a(address), i(instruction), c(char) and s(string).\n\
1669 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1670 g is meaningful only with f, for type double.\n\
1671 The specified number of objects of the specified size are printed\n\
1672 according to the format.\n\n\
1673 Defaults for format and size letters are those previously used.\n\
1674 Default count is 1. Default address is following last thing printed\n\
1675 with this command or \"print\".");
1677 add_com ("disassemble", class_vars
, disassemble_command
,
1678 "Disassemble a specified section of memory.\n\
1679 Default is the function surrounding the pc of the selected frame.\n\
1680 With a single argument, the function surrounding that address is dumped.\n\
1681 Two arguments are taken as a range of memory to dump.");
1683 add_com ("ptype", class_vars
, ptype_command
,
1684 "Print definition of type TYPE.\n\
1685 Argument may be a type name defined by typedef, or \"struct STRUCTNAME\"\n\
1686 or \"union UNIONNAME\" or \"enum ENUMNAME\".\n\
1687 The selected stack frame's lexical context is used to look up the name.");
1689 add_com ("whatis", class_vars
, whatis_command
,
1690 "Print data type of expression EXP.");
1692 add_info ("display", display_info
,
1693 "Expressions to display when program stops, with code numbers.");
1695 add_cmd ("undisplay", class_vars
, undisplay_command
,
1696 "Cancel some expressions to be displayed when program stops.\n\
1697 Arguments are the code numbers of the expressions to stop displaying.\n\
1698 No argument means cancel all automatic-display expressions.\n\
1699 \"delete display\" has the same effect as this command.\n\
1700 Do \"info display\" to see current list of code numbers.",
1703 add_com ("display", class_vars
, display_command
,
1704 "Print value of expression EXP each time the program stops.\n\
1705 /FMT may be used before EXP as in the \"print\" command.\n\
1706 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
1707 as in the \"x\" command, and then EXP is used to get the address to examine\n\
1708 and examining is done as in the \"x\" command.\n\n\
1709 With no argument, display all currently requested auto-display expressions.\n\
1710 Use \"undisplay\" to cancel display requests previously made.");
1712 add_cmd ("display", class_vars
, enable_display
,
1713 "Enable some expressions to be displayed when program stops.\n\
1714 Arguments are the code numbers of the expressions to resume displaying.\n\
1715 No argument means enable all automatic-display expressions.\n\
1716 Do \"info display\" to see current list of code numbers.", &enablelist
);
1718 add_cmd ("display", class_vars
, disable_display_command
,
1719 "Disable some expressions to be displayed when program stops.\n\
1720 Arguments are the code numbers of the expressions to stop displaying.\n\
1721 No argument means disable all automatic-display expressions.\n\
1722 Do \"info display\" to see current list of code numbers.", &disablelist
);
1724 add_cmd ("display", class_vars
, undisplay_command
,
1725 "Cancel some expressions to be displayed when program stops.\n\
1726 Arguments are the code numbers of the expressions to stop displaying.\n\
1727 No argument means cancel all automatic-display expressions.\n\
1728 Do \"info display\" to see current list of code numbers.", &deletelist
);
1730 add_com ("printf", class_vars
, printf_command
,
1731 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
1732 This is useful for formatted output in user-defined commands.");
1733 add_com ("output", class_vars
, output_command
,
1734 "Like \"print\" but don't put in value history and don't print newline.\n\
1735 This is useful in user-defined commands.");
1737 add_prefix_cmd ("set", class_vars
, set_command
,
1738 "Perform an assignment VAR = EXP.\n\
1739 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
1740 (names starting with $), a register (a few standard names starting with $),\n\
1741 or an actual variable in the program being debugged. EXP is any expression.\n\
1742 Use \"set variable\" for variables with names identical to set subcommands.\n\
1743 \nWith a subcommand, this command modifies parts of the gdb environment",
1744 &setlist
, "set ", 1, &cmdlist
);
1746 add_cmd ("variable", class_vars
, set_command
,
1747 "Perform an assignment VAR = EXP.\n\
1748 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
1749 (names starting with $), a register (a few standard names starting with $),\n\
1750 or an actual variable in the program being debugged. EXP is any expression.\n\
1751 This may usually be abbreviated to simply \"set\".",
1754 add_com ("print", class_vars
, print_command
,
1755 concat ("Print value of expression EXP.\n\
1756 Variables accessible are those of the lexical environment of the selected\n\
1757 stack frame, plus all those whose scope is global or an entire file.\n\
1759 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
1760 $$NUM refers to NUM'th value back from the last one.\n\
1761 Names starting with $ refer to registers (with the values they would have\n\
1762 if the program were to return to the stack frame now selected, restoring\n\
1763 all registers saved by frames farther in) or else to debugger\n\
1764 \"convenience\" variables (any such name not a known register).\n\
1765 Use assignment expressions to give values to convenience variables.\n",
1767 \{TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
1768 @ is a binary operator for treating consecutive data objects\n\
1769 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
1770 element is FOO, whose second element is stored in the space following\n\
1771 where FOO is stored, etc. FOO must be an expression whose value\n\
1772 resides in memory.\n",
1774 EXP may be preceded with /FMT, where FMT is a format letter\n\
1775 but no count or size letter (see \"x\" command)."));
1776 add_com_alias ("p", "print", class_vars
, 1);