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 CORE_ADDR highest_offset
= 0;
1237 register CORE_ADDR addr
= FRAME_ARGS_ADDRESS (fi
);
1241 b
= SYMBOL_BLOCK_VALUE (func
);
1242 nsyms
= BLOCK_NSYMS (b
);
1245 for (i
= 0; i
< nsyms
; i
++)
1248 sym
= BLOCK_SYM (b
, i
);
1250 if (SYMBOL_CLASS (sym
) != LOC_REGPARM
1251 && SYMBOL_CLASS (sym
) != LOC_ARG
1252 && SYMBOL_CLASS (sym
) != LOC_REF_ARG
)
1255 /* Print the next arg. */
1256 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
)
1257 val
= value_from_register (SYMBOL_TYPE (sym
),
1259 FRAME_INFO_ID (fi
));
1262 int current_offset
= SYMBOL_VALUE (sym
);
1263 int arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
1265 if (SYMBOL_CLASS (sym
) == LOC_REF_ARG
)
1266 val
= value_at (SYMBOL_TYPE (sym
),
1267 read_memory_integer (addr
+ current_offset
,
1268 sizeof (CORE_ADDR
)));
1270 val
= value_at (SYMBOL_TYPE (sym
), addr
+ current_offset
);
1272 /* Round up address of next arg to multiple of size of int. */
1274 = (((current_offset
+ sizeof (int) - 1) / sizeof (int))
1278 + (arg_size
- sizeof (int) + 3) / (sizeof (int)))
1280 highest_offset
= current_offset
;
1284 fprintf_filtered (stream
, ", ");
1285 fputs_filtered (SYMBOL_NAME (sym
), stream
);
1286 fputs_filtered ("=", stream
);
1287 value_print (val
, stream
, 0, Val_no_prettyprint
);
1291 /* Don't print nameless args in situations where we don't know
1292 enough about the stack to find them. */
1295 if (i
&& num
* sizeof (int) + FRAME_ARGS_SKIP
> highest_offset
)
1296 print_frame_nameless_args (addr
,
1297 highest_offset
+ sizeof (int),
1298 num
* sizeof (int) + FRAME_ARGS_SKIP
,
1301 print_frame_nameless_args (addr
, FRAME_ARGS_SKIP
,
1302 num
* sizeof (int) + FRAME_ARGS_SKIP
,
1308 print_frame_nameless_args (argsaddr
, start
, end
, stream
)
1317 if (start
!= FRAME_ARGS_SKIP
)
1318 fprintf_filtered (stream
, ", ");
1319 #ifndef PRINT_TYPELESS_INTEGER
1320 fprintf_filtered (stream
, "%d",
1321 read_memory_integer (argsaddr
+ start
, sizeof (int)));
1323 PRINT_TYPELESS_INTEGER (stream
, builtin_type_int
,
1325 read_memory_integer (argsaddr
+ start
,
1328 start
+= sizeof (int);
1333 printf_command (arg
)
1337 register char *s
= arg
;
1341 int allocated_args
= 20;
1344 val_args
= (value
*) xmalloc (allocated_args
* sizeof (value
));
1347 error_no_arg ("format-control string and values to print");
1349 /* Skip white space before format string */
1350 while (*s
== ' ' || *s
== '\t') s
++;
1352 /* A format string should follow, enveloped in double quotes */
1354 error ("Bad format string, missing '\"'.");
1356 /* Parse the format-control string and copy it into the string STRING,
1357 processing some kinds of escape sequence. */
1359 f
= string
= (char *) alloca (strlen (s
) + 1);
1366 error ("Bad format string, non-terminated '\"'.");
1367 /* doesn't return */
1388 /* ??? TODO: handle other escape sequences */
1389 error ("Unrecognized \\ escape character in format string.");
1398 /* Skip over " and following space and comma. */
1401 while (*s
== ' ' || *s
== '\t') s
++;
1403 if (*s
!= ',' && *s
!= 0)
1404 error ("Invalid argument syntax");
1407 while (*s
== ' ' || *s
== '\t') s
++;
1410 /* Now scan the string for %-specs and see what kinds of args they want.
1411 argclass[I] classifies the %-specs so we can give vprintf something
1412 of the right size. */
1414 enum argclass
{int_arg
, string_arg
, double_arg
, long_long_arg
};
1415 enum argclass
*argclass
;
1421 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1428 while (index ("0123456789.hlL-+ #", *f
))
1430 if (*f
== 'l' || *f
== 'L')
1435 argclass
[nargs_wanted
++] = string_arg
;
1436 else if (*f
== 'e' || *f
== 'f' || *f
== 'g')
1437 argclass
[nargs_wanted
++] = double_arg
;
1438 else if (lcount
> 1)
1439 argclass
[nargs_wanted
++] = long_long_arg
;
1441 argclass
[nargs_wanted
++] = int_arg
;
1445 /* Now, parse all arguments and evaluate them.
1446 Store the VALUEs in VAL_ARGS. */
1451 if (nargs
== allocated_args
)
1452 val_args
= (value
*) xrealloc (val_args
,
1453 (allocated_args
*= 2)
1456 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
1458 /* If format string wants a float, unchecked-convert the value to
1459 floating point of the same size */
1461 if (argclass
[nargs
] == double_arg
)
1463 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (float))
1464 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
1465 if (TYPE_LENGTH (VALUE_TYPE (val_args
[nargs
])) == sizeof (double))
1466 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
1474 if (nargs
!= nargs_wanted
)
1475 error ("Wrong number of arguments for specified format-string");
1477 /* Now lay out an argument-list containing the arguments
1478 as doubles, integers and C pointers. */
1480 arg_bytes
= (char *) alloca (sizeof (double) * nargs
);
1482 for (i
= 0; i
< nargs
; i
++)
1484 if (argclass
[i
] == string_arg
)
1488 tem
= value_as_long (val_args
[i
]);
1490 /* This is a %s argument. Find the length of the string. */
1495 read_memory (tem
+ j
, &c
, 1);
1500 /* Copy the string contents into a string inside GDB. */
1501 str
= (char *) alloca (j
+ 1);
1502 read_memory (tem
, str
, j
);
1505 /* Pass address of internal copy as the arg to vprintf. */
1506 *((int *) &arg_bytes
[argindex
]) = (int) str
;
1507 argindex
+= sizeof (int);
1509 else if (VALUE_TYPE (val_args
[i
])->code
== TYPE_CODE_FLT
)
1511 *((double *) &arg_bytes
[argindex
]) = value_as_double (val_args
[i
]);
1512 argindex
+= sizeof (double);
1516 if (argclass
[i
] == long_long_arg
)
1518 *(long long *) &arg_bytes
[argindex
] = value_as_long (val_args
[i
]);
1519 argindex
+= sizeof (long long);
1524 *((int *) &arg_bytes
[argindex
]) = value_as_long (val_args
[i
]);
1525 argindex
+= sizeof (int);
1529 vprintf (string
, arg_bytes
);
1532 /* Helper function for asdump_command. Finds the bounds of a function
1533 for a specified section of text. PC is an address within the
1534 function which you want bounds for; *LOW and *HIGH are set to the
1535 beginning (inclusive) and end (exclusive) of the function. This
1536 function returns 1 on success and 0 on failure. */
1539 containing_function_bounds (pc
, low
, high
)
1540 CORE_ADDR pc
, *low
, *high
;
1544 if (!find_pc_partial_function (pc
, 0, low
))
1550 if (!find_pc_partial_function (scan
, 0, high
))
1552 } while (*low
== *high
);
1557 /* Dump a specified section of assembly code. With no command line
1558 arguments, this command will dump the assembly code for the
1559 function surrounding the pc value in the selected frame. With one
1560 argument, it will dump the assembly code surrounding that pc value.
1561 Two arguments are interpeted as bounds within which to dump
1565 disassemble_command (arg
, from_tty
)
1569 CORE_ADDR low
, high
;
1575 if (!selected_frame
)
1576 error ("No frame selected.\n");
1578 pc
= get_frame_pc (selected_frame
);
1579 if (!containing_function_bounds (pc
, &low
, &high
))
1580 error ("No function contains pc specified by selected frame.\n");
1582 else if (!(space_index
= (char *) index (arg
, ' ')))
1585 pc
= parse_and_eval_address (arg
);
1586 if (!containing_function_bounds (pc
, &low
, &high
))
1587 error ("No function contains specified pc.\n");
1591 /* Two arguments. */
1592 *space_index
= '\0';
1593 low
= parse_and_eval_address (arg
);
1594 high
= parse_and_eval_address (space_index
+ 1);
1597 printf_filtered ("Dump of assembler code ");
1601 find_pc_partial_function (pc
, &name
, 0);
1602 printf_filtered ("for function %s:\n", name
);
1605 printf_filtered ("from 0x%x to 0x%x:\n", low
, high
);
1607 /* Dump the specified range. */
1608 for (pc
= low
; pc
< high
; )
1611 print_address (pc
, stdout
);
1612 printf_filtered (":\t");
1613 pc
+= print_insn (pc
, stdout
);
1614 printf_filtered ("\n");
1616 printf_filtered ("End of assembler dump.\n");
1621 extern struct cmd_list_element
*enablelist
, *disablelist
, *deletelist
;
1622 extern struct cmd_list_element
*cmdlist
, *setlist
;
1625 _initialize_printcmd ()
1627 current_display_number
= -1;
1629 add_info ("address", address_info
,
1630 "Describe where variable VAR is stored.");
1632 add_com ("x", class_vars
, x_command
,
1633 "Examine memory: x/FMT ADDRESS.\n\
1634 ADDRESS is an expression for the memory address to examine.\n\
1635 FMT is a repeat count followed by a format letter and a size letter.\n\
1636 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1637 f(float), a(address), i(instruction), c(char) and s(string).\n\
1638 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1639 g is meaningful only with f, for type double.\n\
1640 The specified number of objects of the specified size are printed\n\
1641 according to the format.\n\n\
1642 Defaults for format and size letters are those previously used.\n\
1643 Default count is 1. Default address is following last thing printed\n\
1644 with this command or \"print\".");
1646 add_com ("disassemble", class_vars
, disassemble_command
,
1647 "Disassemble a specified section of memory.\n\
1648 Default is the function surrounding the pc of the selected frame.\n\
1649 With a single argument, the function surrounding that address is dumped.\n\
1650 Two arguments are taken as a range of memory to dump.");
1652 add_com ("ptype", class_vars
, ptype_command
,
1653 "Print definition of type TYPE.\n\
1654 Argument may be a type name defined by typedef, or \"struct STRUCTNAME\"\n\
1655 or \"union UNIONNAME\" or \"enum ENUMNAME\".\n\
1656 The selected stack frame's lexical context is used to look up the name.");
1658 add_com ("whatis", class_vars
, whatis_command
,
1659 "Print data type of expression EXP.");
1661 add_info ("display", display_info
,
1662 "Expressions to display when program stops, with code numbers.");
1664 add_cmd ("undisplay", class_vars
, undisplay_command
,
1665 "Cancel some expressions to be displayed when program stops.\n\
1666 Arguments are the code numbers of the expressions to stop displaying.\n\
1667 No argument means cancel all automatic-display expressions.\n\
1668 \"delete display\" has the same effect as this command.\n\
1669 Do \"info display\" to see current list of code numbers.",
1672 add_com ("display", class_vars
, display_command
,
1673 "Print value of expression EXP each time the program stops.\n\
1674 /FMT may be used before EXP as in the \"print\" command.\n\
1675 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
1676 as in the \"x\" command, and then EXP is used to get the address to examine\n\
1677 and examining is done as in the \"x\" command.\n\n\
1678 With no argument, display all currently requested auto-display expressions.\n\
1679 Use \"undisplay\" to cancel display requests previously made.");
1681 add_cmd ("display", class_vars
, enable_display
,
1682 "Enable some expressions to be displayed when program stops.\n\
1683 Arguments are the code numbers of the expressions to resume displaying.\n\
1684 No argument means enable all automatic-display expressions.\n\
1685 Do \"info display\" to see current list of code numbers.", &enablelist
);
1687 add_cmd ("display", class_vars
, disable_display_command
,
1688 "Disable some expressions to be displayed when program stops.\n\
1689 Arguments are the code numbers of the expressions to stop displaying.\n\
1690 No argument means disable all automatic-display expressions.\n\
1691 Do \"info display\" to see current list of code numbers.", &disablelist
);
1693 add_cmd ("display", class_vars
, undisplay_command
,
1694 "Cancel some expressions to be displayed when program stops.\n\
1695 Arguments are the code numbers of the expressions to stop displaying.\n\
1696 No argument means cancel all automatic-display expressions.\n\
1697 Do \"info display\" to see current list of code numbers.", &deletelist
);
1699 add_com ("printf", class_vars
, printf_command
,
1700 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
1701 This is useful for formatted output in user-defined commands.");
1702 add_com ("output", class_vars
, output_command
,
1703 "Like \"print\" but don't put in value history and don't print newline.\n\
1704 This is useful in user-defined commands.");
1706 add_prefix_cmd ("set", class_vars
, set_command
,
1707 "Perform an assignment VAR = EXP.\n\
1708 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
1709 (names starting with $), a register (a few standard names starting with $),\n\
1710 or an actual variable in the program being debugged. EXP is any expression.\n\
1711 Use \"set variable\" for variables with names identical to set subcommands.\n\
1712 \nWith a subcommand, this command modifies parts of the gdb environment",
1713 &setlist
, "set ", 1, &cmdlist
);
1715 add_cmd ("variable", class_vars
, set_command
,
1716 "Perform an assignment VAR = EXP.\n\
1717 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
1718 (names starting with $), a register (a few standard names starting with $),\n\
1719 or an actual variable in the program being debugged. EXP is any expression.\n\
1720 This may usually be abbreviated to simply \"set\".",
1723 add_com ("print", class_vars
, print_command
,
1724 concat ("Print value of expression EXP.\n\
1725 Variables accessible are those of the lexical environment of the selected\n\
1726 stack frame, plus all those whose scope is global or an entire file.\n\
1728 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
1729 $$NUM refers to NUM'th value back from the last one.\n\
1730 Names starting with $ refer to registers (with the values they would have\n\
1731 if the program were to return to the stack frame now selected, restoring\n\
1732 all registers saved by frames farther in) or else to debugger\n\
1733 \"convenience\" variables (any such name not a known register).\n\
1734 Use assignment expressions to give values to convenience variables.\n",
1736 \{TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
1737 @ is a binary operator for treating consecutive data objects\n\
1738 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
1739 element is FOO, whose second element is stored in the space following\n\
1740 where FOO is stored, etc. FOO must be an expression whose value\n\
1741 resides in memory.\n",
1743 EXP may be preceded with /FMT, where FMT is a format letter\n\
1744 but no count or size letter (see \"x\" command)."));
1745 add_com_alias ("p", "print", class_vars
, 1);