1 /* Print values for GNU debugger GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
25 #include "gdb_string.h"
31 #include "expression.h"
35 #include "breakpoint.h"
39 #include "symfile.h" /* for overlay functions */
40 #include "objfiles.h" /* ditto */
41 #include "completer.h" /* for completion functions */
43 #include "gdb_assert.h"
45 extern int asm_demangle
; /* Whether to demangle syms in asm printouts */
46 extern int addressprint
; /* Whether to print hex addresses in HLL " */
55 /* Last specified output format. */
57 static char last_format
= 'x';
59 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
61 static char last_size
= 'w';
63 /* Default address to examine next. */
65 static CORE_ADDR next_address
;
67 /* Default section to examine next. */
69 static asection
*next_section
;
71 /* Last address examined. */
73 static CORE_ADDR last_examine_address
;
75 /* Contents of last address examined.
76 This is not valid past the end of the `x' command! */
78 static struct value
*last_examine_value
;
80 /* Largest offset between a symbolic value and an address, that will be
81 printed as `0x1234 <symbol+offset>'. */
83 static unsigned int max_symbolic_offset
= UINT_MAX
;
85 /* Append the source filename and linenumber of the symbol when
86 printing a symbolic value as `<symbol at filename:linenum>' if set. */
87 static int print_symbol_filename
= 0;
89 /* Number of auto-display expression currently being displayed.
90 So that we can disable it if we get an error or a signal within it.
91 -1 when not doing one. */
93 int current_display_number
;
95 /* Flag to low-level print routines that this value is being printed
96 in an epoch window. We'd like to pass this as a parameter, but
97 every routine would need to take it. Perhaps we can encapsulate
98 this in the I/O stream once we have GNU stdio. */
104 /* Chain link to next auto-display item. */
105 struct display
*next
;
106 /* Expression to be evaluated and displayed. */
107 struct expression
*exp
;
108 /* Item number of this auto-display item. */
110 /* Display format specified. */
111 struct format_data format
;
112 /* Innermost block required by this expression when evaluated */
114 /* Status of this display (enabled or disabled) */
118 /* Chain of expressions whose values should be displayed
119 automatically each time the program stops. */
121 static struct display
*display_chain
;
123 static int display_number
;
125 /* Prototypes for exported functions. */
127 void output_command (char *, int);
129 void _initialize_printcmd (void);
131 /* Prototypes for local functions. */
133 static void delete_display (int);
135 static void enable_display (char *, int);
137 static void disable_display_command (char *, int);
139 static void printf_command (char *, int);
141 static void print_frame_nameless_args (struct frame_info
*, long,
142 int, int, struct ui_file
*);
144 static void display_info (char *, int);
146 static void do_one_display (struct display
*);
148 static void undisplay_command (char *, int);
150 static void free_display (struct display
*);
152 static void display_command (char *, int);
154 void x_command (char *, int);
156 static void address_info (char *, int);
158 static void set_command (char *, int);
160 static void call_command (char *, int);
162 static void inspect_command (char *, int);
164 static void print_command (char *, int);
166 static void print_command_1 (char *, int, int);
168 static void validate_format (struct format_data
, char *);
170 static void do_examine (struct format_data
, CORE_ADDR addr
,
173 static void print_formatted (struct value
*, int, int, struct ui_file
*);
175 static struct format_data
decode_format (char **, int, int);
177 static int print_insn (CORE_ADDR
, struct ui_file
*);
179 static void sym_info (char *, int);
182 /* Decode a format specification. *STRING_PTR should point to it.
183 OFORMAT and OSIZE are used as defaults for the format and size
184 if none are given in the format specification.
185 If OSIZE is zero, then the size field of the returned value
186 should be set only if a size is explicitly specified by the
188 The structure returned describes all the data
189 found in the specification. In addition, *STRING_PTR is advanced
190 past the specification and past all whitespace following it. */
192 static struct format_data
193 decode_format (char **string_ptr
, int oformat
, int osize
)
195 struct format_data val
;
196 register char *p
= *string_ptr
;
202 if (*p
>= '0' && *p
<= '9')
203 val
.count
= atoi (p
);
204 while (*p
>= '0' && *p
<= '9')
207 /* Now process size or format letters that follow. */
211 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
213 else if (*p
>= 'a' && *p
<= 'z')
219 while (*p
== ' ' || *p
== '\t')
223 /* Set defaults for format and size if not specified. */
224 if (val
.format
== '?')
228 /* Neither has been specified. */
229 val
.format
= oformat
;
233 /* If a size is specified, any format makes a reasonable
234 default except 'i'. */
235 val
.format
= oformat
== 'i' ? 'x' : oformat
;
237 else if (val
.size
== '?')
242 /* Pick the appropriate size for an address. */
243 if (TARGET_PTR_BIT
== 64)
244 val
.size
= osize
? 'g' : osize
;
245 else if (TARGET_PTR_BIT
== 32)
246 val
.size
= osize
? 'w' : osize
;
247 else if (TARGET_PTR_BIT
== 16)
248 val
.size
= osize
? 'h' : osize
;
250 /* Bad value for TARGET_PTR_BIT */
251 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
254 /* Floating point has to be word or giantword. */
255 if (osize
== 'w' || osize
== 'g')
258 /* Default it to giantword if the last used size is not
260 val
.size
= osize
? 'g' : osize
;
263 /* Characters default to one byte. */
264 val
.size
= osize
? 'b' : osize
;
267 /* The default is the size most recently specified. */
274 /* Print value VAL on stream according to FORMAT, a letter or 0.
275 Do not end with a newline.
276 0 means print VAL according to its own type.
277 SIZE is the letter for the size of datum being printed.
278 This is used to pad hex numbers so they line up. */
281 print_formatted (struct value
*val
, register int format
, int size
,
282 struct ui_file
*stream
)
284 struct type
*type
= check_typedef (VALUE_TYPE (val
));
285 int len
= TYPE_LENGTH (type
);
287 if (VALUE_LVAL (val
) == lval_memory
)
289 next_address
= VALUE_ADDRESS (val
) + len
;
290 next_section
= VALUE_BFD_SECTION (val
);
296 /* FIXME: Need to handle wchar_t's here... */
297 next_address
= VALUE_ADDRESS (val
)
298 + val_print_string (VALUE_ADDRESS (val
), -1, 1, stream
);
299 next_section
= VALUE_BFD_SECTION (val
);
303 /* The old comment says
304 "Force output out, print_insn not using _filtered".
305 I'm not completely sure what that means, I suspect most print_insn
306 now do use _filtered, so I guess it's obsolete.
307 --Yes, it does filter now, and so this is obsolete. -JB */
309 /* We often wrap here if there are long symbolic names. */
311 next_address
= VALUE_ADDRESS (val
)
312 + print_insn (VALUE_ADDRESS (val
), stream
);
313 next_section
= VALUE_BFD_SECTION (val
);
318 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
319 || TYPE_CODE (type
) == TYPE_CODE_STRING
320 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
321 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
322 /* If format is 0, use the 'natural' format for
323 * that type of value. If the type is non-scalar,
324 * we have to use language rules to print it as
325 * a series of scalars.
327 value_print (val
, stream
, format
, Val_pretty_default
);
329 /* User specified format, so don't look to the
330 * the type to tell us what to do.
332 print_scalar_formatted (VALUE_CONTENTS (val
), type
,
333 format
, size
, stream
);
337 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
338 according to letters FORMAT and SIZE on STREAM.
339 FORMAT may not be zero. Formats s and i are not supported at this level.
341 This is how the elements of an array or structure are printed
345 print_scalar_formatted (char *valaddr
, struct type
*type
, int format
, int size
,
346 struct ui_file
*stream
)
349 unsigned int len
= TYPE_LENGTH (type
);
351 if (len
> sizeof (LONGEST
)
359 if (!TYPE_UNSIGNED (type
)
360 || !extract_long_unsigned_integer (valaddr
, len
, &val_long
))
362 /* We can't print it normally, but we can print it in hex.
363 Printing it in the wrong radix is more useful than saying
364 "use /x, you dummy". */
365 /* FIXME: we could also do octal or binary if that was the
367 /* FIXME: we should be using the size field to give us a
368 minimum field width to print. */
371 print_octal_chars (stream
, valaddr
, len
);
372 else if (format
== 'd')
373 print_decimal_chars (stream
, valaddr
, len
);
374 else if (format
== 't')
375 print_binary_chars (stream
, valaddr
, len
);
377 /* replace with call to print_hex_chars? Looks
378 like val_print_type_code_int is redoing
381 val_print_type_code_int (type
, valaddr
, stream
);
386 /* If we get here, extract_long_unsigned_integer set val_long. */
388 else if (format
!= 'f')
389 val_long
= unpack_long (type
, valaddr
);
391 /* If the value is a pointer, and pointers and addresses are not the
392 same, then at this point, the value's length (in target bytes) is
393 TARGET_ADDR_BIT/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
394 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
395 len
= TARGET_ADDR_BIT
/ TARGET_CHAR_BIT
;
397 /* If we are printing it as unsigned, truncate it in case it is actually
398 a negative signed value (e.g. "print/u (short)-1" should print 65535
399 (if shorts are 16 bits) instead of 4294967295). */
402 if (len
< sizeof (LONGEST
))
403 val_long
&= ((LONGEST
) 1 << HOST_CHAR_BIT
* len
) - 1;
411 /* no size specified, like in print. Print varying # of digits. */
412 print_longest (stream
, 'x', 1, val_long
);
421 print_longest (stream
, size
, 1, val_long
);
424 error ("Undefined output size \"%c\".", size
);
429 print_longest (stream
, 'd', 1, val_long
);
433 print_longest (stream
, 'u', 0, val_long
);
438 print_longest (stream
, 'o', 1, val_long
);
440 fprintf_filtered (stream
, "0");
445 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
446 print_address (addr
, stream
);
451 value_print (value_from_longest (builtin_type_true_char
, val_long
),
452 stream
, 0, Val_pretty_default
);
456 if (len
== TYPE_LENGTH (builtin_type_float
))
457 type
= builtin_type_float
;
458 else if (len
== TYPE_LENGTH (builtin_type_double
))
459 type
= builtin_type_double
;
460 else if (len
== TYPE_LENGTH (builtin_type_long_double
))
461 type
= builtin_type_long_double
;
462 print_floating (valaddr
, type
, stream
);
466 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
469 /* Binary; 't' stands for "two". */
471 char bits
[8 * (sizeof val_long
) + 1];
472 char buf
[8 * (sizeof val_long
) + 32];
477 width
= 8 * (sizeof val_long
);
494 error ("Undefined output size \"%c\".", size
);
500 bits
[width
] = (val_long
& 1) ? '1' : '0';
505 while (*cp
&& *cp
== '0')
510 strcpy (buf
, local_binary_format_prefix ());
512 strcat (buf
, local_binary_format_suffix ());
513 fprintf_filtered (stream
, buf
);
518 error ("Undefined output format \"%c\".", format
);
522 /* Specify default address for `x' command.
523 `info lines' uses this. */
526 set_next_address (CORE_ADDR addr
)
530 /* Make address available to the user as $_. */
531 set_internalvar (lookup_internalvar ("_"),
532 value_from_pointer (lookup_pointer_type (builtin_type_void
),
536 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
537 after LEADIN. Print nothing if no symbolic name is found nearby.
538 Optionally also print source file and line number, if available.
539 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
540 or to interpret it as a possible C++ name and convert it back to source
541 form. However note that DO_DEMANGLE can be overridden by the specific
542 settings of the demangle and asm_demangle variables. */
545 print_address_symbolic (CORE_ADDR addr
, struct ui_file
*stream
, int do_demangle
,
549 char *filename
= NULL
;
554 /* throw away both name and filename */
555 struct cleanup
*cleanup_chain
= make_cleanup (free_current_contents
, &name
);
556 make_cleanup (free_current_contents
, &filename
);
558 if (build_address_symbolic (addr
, do_demangle
, &name
, &offset
, &filename
, &line
, &unmapped
))
560 do_cleanups (cleanup_chain
);
564 fputs_filtered (leadin
, stream
);
566 fputs_filtered ("<*", stream
);
568 fputs_filtered ("<", stream
);
569 fputs_filtered (name
, stream
);
571 fprintf_filtered (stream
, "+%u", (unsigned int) offset
);
573 /* Append source filename and line number if desired. Give specific
574 line # of this addr, if we have it; else line # of the nearest symbol. */
575 if (print_symbol_filename
&& filename
!= NULL
)
578 fprintf_filtered (stream
, " at %s:%d", filename
, line
);
580 fprintf_filtered (stream
, " in %s", filename
);
583 fputs_filtered ("*>", stream
);
585 fputs_filtered (">", stream
);
587 do_cleanups (cleanup_chain
);
590 /* Given an address ADDR return all the elements needed to print the
591 address in a symbolic form. NAME can be mangled or not depending
592 on DO_DEMANGLE (and also on the asm_demangle global variable,
593 manipulated via ''set print asm-demangle''). Return 0 in case of
594 success, when all the info in the OUT paramters is valid. Return 1
597 build_address_symbolic (CORE_ADDR addr
, /* IN */
598 int do_demangle
, /* IN */
599 char **name
, /* OUT */
600 int *offset
, /* OUT */
601 char **filename
, /* OUT */
603 int *unmapped
) /* OUT */
605 struct minimal_symbol
*msymbol
;
606 struct symbol
*symbol
;
607 struct symtab
*symtab
= 0;
608 CORE_ADDR name_location
= 0;
609 asection
*section
= 0;
610 char *name_temp
= "";
612 /* Let's say it is unmapped. */
615 /* Determine if the address is in an overlay, and whether it is
617 if (overlay_debugging
)
619 section
= find_pc_overlay (addr
);
620 if (pc_in_unmapped_range (addr
, section
))
623 addr
= overlay_mapped_address (addr
, section
);
627 /* First try to find the address in the symbol table, then
628 in the minsyms. Take the closest one. */
630 /* This is defective in the sense that it only finds text symbols. So
631 really this is kind of pointless--we should make sure that the
632 minimal symbols have everything we need (by changing that we could
633 save some memory, but for many debug format--ELF/DWARF or
634 anything/stabs--it would be inconvenient to eliminate those minimal
636 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
637 symbol
= find_pc_sect_function (addr
, section
);
641 name_location
= BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
));
642 if (do_demangle
|| asm_demangle
)
643 name_temp
= SYMBOL_SOURCE_NAME (symbol
);
645 name_temp
= SYMBOL_NAME (symbol
);
650 if (SYMBOL_VALUE_ADDRESS (msymbol
) > name_location
|| symbol
== NULL
)
652 /* The msymbol is closer to the address than the symbol;
653 use the msymbol instead. */
656 name_location
= SYMBOL_VALUE_ADDRESS (msymbol
);
657 if (do_demangle
|| asm_demangle
)
658 name_temp
= SYMBOL_SOURCE_NAME (msymbol
);
660 name_temp
= SYMBOL_NAME (msymbol
);
663 if (symbol
== NULL
&& msymbol
== NULL
)
666 /* If the nearest symbol is too far away, don't print anything symbolic. */
668 /* For when CORE_ADDR is larger than unsigned int, we do math in
669 CORE_ADDR. But when we detect unsigned wraparound in the
670 CORE_ADDR math, we ignore this test and print the offset,
671 because addr+max_symbolic_offset has wrapped through the end
672 of the address space back to the beginning, giving bogus comparison. */
673 if (addr
> name_location
+ max_symbolic_offset
674 && name_location
+ max_symbolic_offset
> name_location
)
677 *offset
= addr
- name_location
;
679 *name
= xstrdup (name_temp
);
681 if (print_symbol_filename
)
683 struct symtab_and_line sal
;
685 sal
= find_pc_sect_line (addr
, section
, 0);
689 *filename
= xstrdup (sal
.symtab
->filename
);
692 else if (symtab
&& symbol
&& symbol
->line
)
694 *filename
= xstrdup (symtab
->filename
);
695 *line
= symbol
->line
;
699 *filename
= xstrdup (symtab
->filename
);
706 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
709 print_address_numeric (CORE_ADDR addr
, int use_local
, struct ui_file
*stream
)
711 /* Truncate address to the size of a target address, avoiding shifts
712 larger or equal than the width of a CORE_ADDR. The local
713 variable ADDR_BIT stops the compiler reporting a shift overflow
714 when it won't occur. */
715 /* NOTE: This assumes that the significant address information is
716 kept in the least significant bits of ADDR - the upper bits were
717 either zero or sign extended. Should ADDRESS_TO_POINTER() or
718 some ADDRESS_TO_PRINTABLE() be used to do the conversion? */
720 int addr_bit
= TARGET_ADDR_BIT
;
722 if (addr_bit
< (sizeof (CORE_ADDR
) * HOST_CHAR_BIT
))
723 addr
&= ((CORE_ADDR
) 1 << addr_bit
) - 1;
724 print_longest (stream
, 'x', use_local
, (ULONGEST
) addr
);
727 /* Print address ADDR symbolically on STREAM.
728 First print it as a number. Then perhaps print
729 <SYMBOL + OFFSET> after the number. */
732 print_address (CORE_ADDR addr
, struct ui_file
*stream
)
734 print_address_numeric (addr
, 1, stream
);
735 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
738 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
739 controls whether to print the symbolic name "raw" or demangled.
740 Global setting "addressprint" controls whether to print hex address
744 print_address_demangle (CORE_ADDR addr
, struct ui_file
*stream
, int do_demangle
)
748 fprintf_filtered (stream
, "0");
750 else if (addressprint
)
752 print_address_numeric (addr
, 1, stream
);
753 print_address_symbolic (addr
, stream
, do_demangle
, " ");
757 print_address_symbolic (addr
, stream
, do_demangle
, "");
762 /* These are the types that $__ will get after an examine command of one
765 static struct type
*examine_i_type
;
767 static struct type
*examine_b_type
;
768 static struct type
*examine_h_type
;
769 static struct type
*examine_w_type
;
770 static struct type
*examine_g_type
;
772 /* Examine data at address ADDR in format FMT.
773 Fetch it from memory and print on gdb_stdout. */
776 do_examine (struct format_data fmt
, CORE_ADDR addr
, asection
*sect
)
778 register char format
= 0;
780 register int count
= 1;
781 struct type
*val_type
= NULL
;
783 register int maxelts
;
791 /* String or instruction format implies fetch single bytes
792 regardless of the specified size. */
793 if (format
== 's' || format
== 'i')
797 val_type
= examine_i_type
;
798 else if (size
== 'b')
799 val_type
= examine_b_type
;
800 else if (size
== 'h')
801 val_type
= examine_h_type
;
802 else if (size
== 'w')
803 val_type
= examine_w_type
;
804 else if (size
== 'g')
805 val_type
= examine_g_type
;
812 if (format
== 's' || format
== 'i')
815 /* Print as many objects as specified in COUNT, at most maxelts per line,
816 with the address of the next one at the start of each line. */
821 print_address (next_address
, gdb_stdout
);
822 printf_filtered (":");
827 printf_filtered ("\t");
828 /* Note that print_formatted sets next_address for the next
830 last_examine_address
= next_address
;
832 if (last_examine_value
)
833 value_free (last_examine_value
);
835 /* The value to be displayed is not fetched greedily.
836 Instead, to avoid the posibility of a fetched value not
837 being used, its retreval is delayed until the print code
838 uses it. When examining an instruction stream, the
839 disassembler will perform its own memory fetch using just
840 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
841 the disassembler be modified so that LAST_EXAMINE_VALUE
842 is left with the byte sequence from the last complete
843 instruction fetched from memory? */
844 last_examine_value
= value_at_lazy (val_type
, next_address
, sect
);
846 if (last_examine_value
)
847 release_value (last_examine_value
);
849 print_formatted (last_examine_value
, format
, size
, gdb_stdout
);
851 printf_filtered ("\n");
852 gdb_flush (gdb_stdout
);
857 validate_format (struct format_data fmt
, char *cmdname
)
860 error ("Size letters are meaningless in \"%s\" command.", cmdname
);
862 error ("Item count other than 1 is meaningless in \"%s\" command.",
864 if (fmt
.format
== 'i' || fmt
.format
== 's')
865 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
866 fmt
.format
, cmdname
);
869 /* Evaluate string EXP as an expression in the current language and
870 print the resulting value. EXP may contain a format specifier as the
871 first argument ("/x myvar" for example, to print myvar in hex).
875 print_command_1 (char *exp
, int inspect
, int voidprint
)
877 struct expression
*expr
;
878 register struct cleanup
*old_chain
= 0;
879 register char format
= 0;
881 struct format_data fmt
;
884 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
885 inspect_it
= inspect
;
887 if (exp
&& *exp
== '/')
890 fmt
= decode_format (&exp
, last_format
, 0);
891 validate_format (fmt
, "print");
892 last_format
= format
= fmt
.format
;
904 expr
= parse_expression (exp
);
905 old_chain
= make_cleanup (free_current_contents
, &expr
);
907 val
= evaluate_expression (expr
);
910 val
= access_value_history (0);
912 if (voidprint
|| (val
&& VALUE_TYPE (val
) &&
913 TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_VOID
))
915 int histindex
= record_latest_value (val
);
918 annotate_value_history_begin (histindex
, VALUE_TYPE (val
));
920 annotate_value_begin (VALUE_TYPE (val
));
923 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp
, histindex
);
924 else if (histindex
>= 0)
925 printf_filtered ("$%d = ", histindex
);
928 annotate_value_history_value ();
930 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
931 printf_filtered ("\n");
934 annotate_value_history_end ();
936 annotate_value_end ();
939 printf_unfiltered ("\") )\030");
943 do_cleanups (old_chain
);
944 inspect_it
= 0; /* Reset print routines to normal */
949 print_command (char *exp
, int from_tty
)
951 print_command_1 (exp
, 0, 1);
954 /* Same as print, except in epoch, it gets its own window */
957 inspect_command (char *exp
, int from_tty
)
959 extern int epoch_interface
;
961 print_command_1 (exp
, epoch_interface
, 1);
964 /* Same as print, except it doesn't print void results. */
967 call_command (char *exp
, int from_tty
)
969 print_command_1 (exp
, 0, 0);
974 output_command (char *exp
, int from_tty
)
976 struct expression
*expr
;
977 register struct cleanup
*old_chain
;
978 register char format
= 0;
980 struct format_data fmt
;
982 if (exp
&& *exp
== '/')
985 fmt
= decode_format (&exp
, 0, 0);
986 validate_format (fmt
, "output");
990 expr
= parse_expression (exp
);
991 old_chain
= make_cleanup (free_current_contents
, &expr
);
993 val
= evaluate_expression (expr
);
995 annotate_value_begin (VALUE_TYPE (val
));
997 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
999 annotate_value_end ();
1002 gdb_flush (gdb_stdout
);
1004 do_cleanups (old_chain
);
1009 set_command (char *exp
, int from_tty
)
1011 struct expression
*expr
= parse_expression (exp
);
1012 register struct cleanup
*old_chain
=
1013 make_cleanup (free_current_contents
, &expr
);
1014 evaluate_expression (expr
);
1015 do_cleanups (old_chain
);
1020 sym_info (char *arg
, int from_tty
)
1022 struct minimal_symbol
*msymbol
;
1023 struct objfile
*objfile
;
1024 struct obj_section
*osect
;
1026 CORE_ADDR addr
, sect_addr
;
1028 unsigned int offset
;
1031 error_no_arg ("address");
1033 addr
= parse_and_eval_address (arg
);
1034 ALL_OBJSECTIONS (objfile
, osect
)
1036 sect
= osect
->the_bfd_section
;
1037 sect_addr
= overlay_mapped_address (addr
, sect
);
1039 if (osect
->addr
<= sect_addr
&& sect_addr
< osect
->endaddr
&&
1040 (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr
, sect
)))
1043 offset
= sect_addr
- SYMBOL_VALUE_ADDRESS (msymbol
);
1045 printf_filtered ("%s + %u in ",
1046 SYMBOL_SOURCE_NAME (msymbol
), offset
);
1048 printf_filtered ("%s in ",
1049 SYMBOL_SOURCE_NAME (msymbol
));
1050 if (pc_in_unmapped_range (addr
, sect
))
1051 printf_filtered ("load address range of ");
1052 if (section_is_overlay (sect
))
1053 printf_filtered ("%s overlay ",
1054 section_is_mapped (sect
) ? "mapped" : "unmapped");
1055 printf_filtered ("section %s", sect
->name
);
1056 printf_filtered ("\n");
1060 printf_filtered ("No symbol matches %s.\n", arg
);
1065 address_info (char *exp
, int from_tty
)
1067 register struct symbol
*sym
;
1068 register struct minimal_symbol
*msymbol
;
1070 register long basereg
;
1072 CORE_ADDR load_addr
;
1073 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
1074 if exp is a field of `this'. */
1077 error ("Argument required.");
1079 sym
= lookup_symbol (exp
, get_selected_block (0), VAR_NAMESPACE
,
1080 &is_a_field_of_this
, (struct symtab
**) NULL
);
1083 if (is_a_field_of_this
)
1085 printf_filtered ("Symbol \"");
1086 fprintf_symbol_filtered (gdb_stdout
, exp
,
1087 current_language
->la_language
, DMGL_ANSI
);
1088 printf_filtered ("\" is a field of the local class variable ");
1089 if (current_language
->la_language
== language_objc
)
1090 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1092 printf_filtered ("`this'\n");
1096 msymbol
= lookup_minimal_symbol (exp
, NULL
, NULL
);
1098 if (msymbol
!= NULL
)
1100 load_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
1102 printf_filtered ("Symbol \"");
1103 fprintf_symbol_filtered (gdb_stdout
, exp
,
1104 current_language
->la_language
, DMGL_ANSI
);
1105 printf_filtered ("\" is at ");
1106 print_address_numeric (load_addr
, 1, gdb_stdout
);
1107 printf_filtered (" in a file compiled without debugging");
1108 section
= SYMBOL_BFD_SECTION (msymbol
);
1109 if (section_is_overlay (section
))
1111 load_addr
= overlay_unmapped_address (load_addr
, section
);
1112 printf_filtered (",\n -- loaded at ");
1113 print_address_numeric (load_addr
, 1, gdb_stdout
);
1114 printf_filtered (" in overlay section %s", section
->name
);
1116 printf_filtered (".\n");
1119 error ("No symbol \"%s\" in current context.", exp
);
1123 printf_filtered ("Symbol \"");
1124 fprintf_symbol_filtered (gdb_stdout
, SYMBOL_NAME (sym
),
1125 current_language
->la_language
, DMGL_ANSI
);
1126 printf_filtered ("\" is ");
1127 val
= SYMBOL_VALUE (sym
);
1128 basereg
= SYMBOL_BASEREG (sym
);
1129 section
= SYMBOL_BFD_SECTION (sym
);
1131 switch (SYMBOL_CLASS (sym
))
1134 case LOC_CONST_BYTES
:
1135 printf_filtered ("constant");
1139 printf_filtered ("a label at address ");
1140 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1142 if (section_is_overlay (section
))
1144 load_addr
= overlay_unmapped_address (load_addr
, section
);
1145 printf_filtered (",\n -- loaded at ");
1146 print_address_numeric (load_addr
, 1, gdb_stdout
);
1147 printf_filtered (" in overlay section %s", section
->name
);
1152 printf_filtered ("a variable in register %s", REGISTER_NAME (val
));
1156 printf_filtered ("static storage at address ");
1157 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1159 if (section_is_overlay (section
))
1161 load_addr
= overlay_unmapped_address (load_addr
, section
);
1162 printf_filtered (",\n -- loaded at ");
1163 print_address_numeric (load_addr
, 1, gdb_stdout
);
1164 printf_filtered (" in overlay section %s", section
->name
);
1169 printf_filtered ("external global (indirect addressing), at address *(");
1170 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1172 printf_filtered (")");
1173 if (section_is_overlay (section
))
1175 load_addr
= overlay_unmapped_address (load_addr
, section
);
1176 printf_filtered (",\n -- loaded at ");
1177 print_address_numeric (load_addr
, 1, gdb_stdout
);
1178 printf_filtered (" in overlay section %s", section
->name
);
1183 printf_filtered ("an argument in register %s", REGISTER_NAME (val
));
1186 case LOC_REGPARM_ADDR
:
1187 printf_filtered ("address of an argument in register %s", REGISTER_NAME (val
));
1191 printf_filtered ("an argument at offset %ld", val
);
1195 printf_filtered ("an argument at frame offset %ld", val
);
1199 printf_filtered ("a local variable at frame offset %ld", val
);
1203 printf_filtered ("a reference argument at offset %ld", val
);
1207 printf_filtered ("a variable at offset %ld from register %s",
1208 val
, REGISTER_NAME (basereg
));
1211 case LOC_BASEREG_ARG
:
1212 printf_filtered ("an argument at offset %ld from register %s",
1213 val
, REGISTER_NAME (basereg
));
1217 printf_filtered ("a typedef");
1221 printf_filtered ("a function at address ");
1222 print_address_numeric (load_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)),
1224 if (section_is_overlay (section
))
1226 load_addr
= overlay_unmapped_address (load_addr
, section
);
1227 printf_filtered (",\n -- loaded at ");
1228 print_address_numeric (load_addr
, 1, gdb_stdout
);
1229 printf_filtered (" in overlay section %s", section
->name
);
1233 case LOC_UNRESOLVED
:
1235 struct minimal_symbol
*msym
;
1237 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, NULL
);
1239 printf_filtered ("unresolved");
1242 section
= SYMBOL_BFD_SECTION (msym
);
1243 printf_filtered ("static storage at address ");
1244 print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (msym
),
1246 if (section_is_overlay (section
))
1248 load_addr
= overlay_unmapped_address (load_addr
, section
);
1249 printf_filtered (",\n -- loaded at ");
1250 print_address_numeric (load_addr
, 1, gdb_stdout
);
1251 printf_filtered (" in overlay section %s", section
->name
);
1257 case LOC_HP_THREAD_LOCAL_STATIC
:
1259 "a thread-local variable at offset %ld from the thread base register %s",
1260 val
, REGISTER_NAME (basereg
));
1263 case LOC_THREAD_LOCAL_STATIC
:
1264 printf_filtered ("a thread-local variable at offset %ld in the "
1265 "thread-local storage for `%s'",
1266 val
, SYMBOL_OBJFILE (sym
)->name
);
1269 case LOC_OPTIMIZED_OUT
:
1270 printf_filtered ("optimized out");
1274 printf_filtered ("of unknown (botched) type");
1277 printf_filtered (".\n");
1281 x_command (char *exp
, int from_tty
)
1283 struct expression
*expr
;
1284 struct format_data fmt
;
1285 struct cleanup
*old_chain
;
1288 fmt
.format
= last_format
;
1289 fmt
.size
= last_size
;
1292 if (exp
&& *exp
== '/')
1295 fmt
= decode_format (&exp
, last_format
, last_size
);
1298 /* If we have an expression, evaluate it and use it as the address. */
1300 if (exp
!= 0 && *exp
!= 0)
1302 expr
= parse_expression (exp
);
1303 /* Cause expression not to be there any more
1304 if this command is repeated with Newline.
1305 But don't clobber a user-defined command's definition. */
1308 old_chain
= make_cleanup (free_current_contents
, &expr
);
1309 val
= evaluate_expression (expr
);
1310 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_REF
)
1311 val
= value_ind (val
);
1312 /* In rvalue contexts, such as this, functions are coerced into
1313 pointers to functions. This makes "x/i main" work. */
1314 if (/* last_format == 'i' && */
1315 TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FUNC
1316 && VALUE_LVAL (val
) == lval_memory
)
1317 next_address
= VALUE_ADDRESS (val
);
1319 next_address
= value_as_address (val
);
1320 if (VALUE_BFD_SECTION (val
))
1321 next_section
= VALUE_BFD_SECTION (val
);
1322 do_cleanups (old_chain
);
1325 do_examine (fmt
, next_address
, next_section
);
1327 /* If the examine succeeds, we remember its size and format for next time. */
1328 last_size
= fmt
.size
;
1329 last_format
= fmt
.format
;
1331 /* Set a couple of internal variables if appropriate. */
1332 if (last_examine_value
)
1334 /* Make last address examined available to the user as $_. Use
1335 the correct pointer type. */
1336 struct type
*pointer_type
1337 = lookup_pointer_type (VALUE_TYPE (last_examine_value
));
1338 set_internalvar (lookup_internalvar ("_"),
1339 value_from_pointer (pointer_type
,
1340 last_examine_address
));
1342 /* Make contents of last address examined available to the user as $__. */
1343 /* If the last value has not been fetched from memory then don't
1344 fetch it now - instead mark it by voiding the $__ variable. */
1345 if (VALUE_LAZY (last_examine_value
))
1346 set_internalvar (lookup_internalvar ("__"),
1347 allocate_value (builtin_type_void
));
1349 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1354 /* Add an expression to the auto-display chain.
1355 Specify the expression. */
1358 display_command (char *exp
, int from_tty
)
1360 struct format_data fmt
;
1361 register struct expression
*expr
;
1362 register struct display
*new;
1366 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1368 if (tui_active
&& *exp
== '$')
1369 display_it
= (tui_set_layout (exp
) == TUI_FAILURE
);
1383 fmt
= decode_format (&exp
, 0, 0);
1384 if (fmt
.size
&& fmt
.format
== 0)
1386 if (fmt
.format
== 'i' || fmt
.format
== 's')
1396 innermost_block
= 0;
1397 expr
= parse_expression (exp
);
1399 new = (struct display
*) xmalloc (sizeof (struct display
));
1402 new->block
= innermost_block
;
1403 new->next
= display_chain
;
1404 new->number
= ++display_number
;
1407 display_chain
= new;
1409 if (from_tty
&& target_has_execution
)
1410 do_one_display (new);
1417 free_display (struct display
*d
)
1423 /* Clear out the display_chain.
1424 Done when new symtabs are loaded, since this invalidates
1425 the types stored in many expressions. */
1428 clear_displays (void)
1430 register struct display
*d
;
1432 while ((d
= display_chain
) != NULL
)
1435 display_chain
= d
->next
;
1440 /* Delete the auto-display number NUM. */
1443 delete_display (int num
)
1445 register struct display
*d1
, *d
;
1448 error ("No display number %d.", num
);
1450 if (display_chain
->number
== num
)
1453 display_chain
= d1
->next
;
1457 for (d
= display_chain
;; d
= d
->next
)
1460 error ("No display number %d.", num
);
1461 if (d
->next
->number
== num
)
1471 /* Delete some values from the auto-display chain.
1472 Specify the element numbers. */
1475 undisplay_command (char *args
, int from_tty
)
1477 register char *p
= args
;
1483 if (query ("Delete all auto-display expressions? "))
1492 while (*p1
>= '0' && *p1
<= '9')
1494 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1495 error ("Arguments must be display numbers.");
1499 delete_display (num
);
1502 while (*p
== ' ' || *p
== '\t')
1508 /* Display a single auto-display.
1509 Do nothing if the display cannot be printed in the current context,
1510 or if the display is disabled. */
1513 do_one_display (struct display
*d
)
1515 int within_current_scope
;
1517 if (d
->enabled_p
== 0)
1521 within_current_scope
= contained_in (get_selected_block (0), d
->block
);
1523 within_current_scope
= 1;
1524 if (!within_current_scope
)
1527 current_display_number
= d
->number
;
1529 annotate_display_begin ();
1530 printf_filtered ("%d", d
->number
);
1531 annotate_display_number_end ();
1532 printf_filtered (": ");
1538 annotate_display_format ();
1540 printf_filtered ("x/");
1541 if (d
->format
.count
!= 1)
1542 printf_filtered ("%d", d
->format
.count
);
1543 printf_filtered ("%c", d
->format
.format
);
1544 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1545 printf_filtered ("%c", d
->format
.size
);
1546 printf_filtered (" ");
1548 annotate_display_expression ();
1550 print_expression (d
->exp
, gdb_stdout
);
1551 annotate_display_expression_end ();
1553 if (d
->format
.count
!= 1)
1554 printf_filtered ("\n");
1556 printf_filtered (" ");
1558 val
= evaluate_expression (d
->exp
);
1559 addr
= value_as_address (val
);
1560 if (d
->format
.format
== 'i')
1561 addr
= ADDR_BITS_REMOVE (addr
);
1563 annotate_display_value ();
1565 do_examine (d
->format
, addr
, VALUE_BFD_SECTION (val
));
1569 annotate_display_format ();
1571 if (d
->format
.format
)
1572 printf_filtered ("/%c ", d
->format
.format
);
1574 annotate_display_expression ();
1576 print_expression (d
->exp
, gdb_stdout
);
1577 annotate_display_expression_end ();
1579 printf_filtered (" = ");
1581 annotate_display_expression ();
1583 print_formatted (evaluate_expression (d
->exp
),
1584 d
->format
.format
, d
->format
.size
, gdb_stdout
);
1585 printf_filtered ("\n");
1588 annotate_display_end ();
1590 gdb_flush (gdb_stdout
);
1591 current_display_number
= -1;
1594 /* Display all of the values on the auto-display chain which can be
1595 evaluated in the current scope. */
1600 register struct display
*d
;
1602 for (d
= display_chain
; d
; d
= d
->next
)
1606 /* Delete the auto-display which we were in the process of displaying.
1607 This is done when there is an error or a signal. */
1610 disable_display (int num
)
1612 register struct display
*d
;
1614 for (d
= display_chain
; d
; d
= d
->next
)
1615 if (d
->number
== num
)
1620 printf_unfiltered ("No display number %d.\n", num
);
1624 disable_current_display (void)
1626 if (current_display_number
>= 0)
1628 disable_display (current_display_number
);
1629 fprintf_unfiltered (gdb_stderr
, "Disabling display %d to avoid infinite recursion.\n",
1630 current_display_number
);
1632 current_display_number
= -1;
1636 display_info (char *ignore
, int from_tty
)
1638 register struct display
*d
;
1641 printf_unfiltered ("There are no auto-display expressions now.\n");
1643 printf_filtered ("Auto-display expressions now in effect:\n\
1644 Num Enb Expression\n");
1646 for (d
= display_chain
; d
; d
= d
->next
)
1648 printf_filtered ("%d: %c ", d
->number
, "ny"[(int) d
->enabled_p
]);
1650 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1652 else if (d
->format
.format
)
1653 printf_filtered ("/%c ", d
->format
.format
);
1654 print_expression (d
->exp
, gdb_stdout
);
1655 if (d
->block
&& !contained_in (get_selected_block (0), d
->block
))
1656 printf_filtered (" (cannot be evaluated in the current context)");
1657 printf_filtered ("\n");
1658 gdb_flush (gdb_stdout
);
1663 enable_display (char *args
, int from_tty
)
1665 register char *p
= args
;
1668 register struct display
*d
;
1672 for (d
= display_chain
; d
; d
= d
->next
)
1679 while (*p1
>= '0' && *p1
<= '9')
1681 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1682 error ("Arguments must be display numbers.");
1686 for (d
= display_chain
; d
; d
= d
->next
)
1687 if (d
->number
== num
)
1692 printf_unfiltered ("No display number %d.\n", num
);
1695 while (*p
== ' ' || *p
== '\t')
1702 disable_display_command (char *args
, int from_tty
)
1704 register char *p
= args
;
1706 register struct display
*d
;
1710 for (d
= display_chain
; d
; d
= d
->next
)
1717 while (*p1
>= '0' && *p1
<= '9')
1719 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1720 error ("Arguments must be display numbers.");
1722 disable_display (atoi (p
));
1725 while (*p
== ' ' || *p
== '\t')
1731 /* Print the value in stack frame FRAME of a variable
1732 specified by a struct symbol. */
1735 print_variable_value (struct symbol
*var
, struct frame_info
*frame
,
1736 struct ui_file
*stream
)
1738 struct value
*val
= read_var_value (var
, frame
);
1740 value_print (val
, stream
, 0, Val_pretty_default
);
1743 /* Print the arguments of a stack frame, given the function FUNC
1744 running in that frame (as a symbol), the info on the frame,
1745 and the number of args according to the stack frame (or -1 if unknown). */
1747 /* References here and elsewhere to "number of args according to the
1748 stack frame" appear in all cases to refer to "number of ints of args
1749 according to the stack frame". At least for VAX, i386, isi. */
1752 print_frame_args (struct symbol
*func
, struct frame_info
*fi
, int num
,
1753 struct ui_file
*stream
)
1755 struct block
*b
= NULL
;
1758 register struct symbol
*sym
;
1760 /* Offset of next stack argument beyond the one we have seen that is
1761 at the highest offset.
1762 -1 if we haven't come to a stack argument yet. */
1763 long highest_offset
= -1;
1765 /* Number of ints of arguments that we have printed so far. */
1766 int args_printed
= 0;
1767 struct cleanup
*old_chain
, *list_chain
;
1768 struct ui_stream
*stb
;
1770 stb
= ui_out_stream_new (uiout
);
1771 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1775 b
= SYMBOL_BLOCK_VALUE (func
);
1776 /* Function blocks are order sensitive, and thus should not be
1778 gdb_assert (BLOCK_HASHTABLE (b
) == 0);
1780 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
1784 /* Keep track of the highest stack argument offset seen, and
1785 skip over any kinds of symbols we don't care about. */
1787 switch (SYMBOL_CLASS (sym
))
1792 long current_offset
= SYMBOL_VALUE (sym
);
1793 arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
1795 /* Compute address of next argument by adding the size of
1796 this argument and rounding to an int boundary. */
1798 ((current_offset
+ arg_size
+ sizeof (int) - 1)
1799 & ~(sizeof (int) - 1));
1801 /* If this is the highest offset seen yet, set highest_offset. */
1802 if (highest_offset
== -1
1803 || (current_offset
> highest_offset
))
1804 highest_offset
= current_offset
;
1806 /* Add the number of ints we're about to print to args_printed. */
1807 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
1810 /* We care about types of symbols, but don't need to keep track of
1811 stack offsets in them. */
1813 case LOC_REGPARM_ADDR
:
1815 case LOC_BASEREG_ARG
:
1818 /* Other types of symbols we just skip over. */
1823 /* We have to look up the symbol because arguments can have
1824 two entries (one a parameter, one a local) and the one we
1825 want is the local, which lookup_symbol will find for us.
1826 This includes gcc1 (not gcc2) on the sparc when passing a
1827 small structure and gcc2 when the argument type is float
1828 and it is passed as a double and converted to float by
1829 the prologue (in the latter case the type of the LOC_ARG
1830 symbol is double and the type of the LOC_LOCAL symbol is
1832 /* But if the parameter name is null, don't try it.
1833 Null parameter names occur on the RS/6000, for traceback tables.
1834 FIXME, should we even print them? */
1836 if (*SYMBOL_NAME (sym
))
1838 struct symbol
*nsym
;
1839 nsym
= lookup_symbol
1841 b
, VAR_NAMESPACE
, (int *) NULL
, (struct symtab
**) NULL
);
1842 if (SYMBOL_CLASS (nsym
) == LOC_REGISTER
)
1844 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
1845 it was passed on the stack and loaded into a register,
1846 or passed in a register and stored in a stack slot.
1847 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
1849 Reasons for using the LOC_ARG:
1850 (1) because find_saved_registers may be slow for remote
1852 (2) because registers are often re-used and stack slots
1853 rarely (never?) are. Therefore using the stack slot is
1854 much less likely to print garbage.
1856 Reasons why we might want to use the LOC_REGISTER:
1857 (1) So that the backtrace prints the same value as
1858 "print foo". I see no compelling reason why this needs
1859 to be the case; having the backtrace print the value which
1860 was passed in, and "print foo" print the value as modified
1861 within the called function, makes perfect sense to me.
1863 Additional note: It might be nice if "info args" displayed
1865 One more note: There is a case with sparc structure passing
1866 where we need to use the LOC_REGISTER, but this is dealt with
1867 by creating a single LOC_REGPARM in symbol reading. */
1869 /* Leave sym (the LOC_ARG) alone. */
1876 /* Print the current arg. */
1878 ui_out_text (uiout
, ", ");
1879 ui_out_wrap_hint (uiout
, " ");
1881 annotate_arg_begin ();
1883 list_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
1884 fprintf_symbol_filtered (stb
->stream
, SYMBOL_SOURCE_NAME (sym
),
1885 SYMBOL_LANGUAGE (sym
), DMGL_PARAMS
| DMGL_ANSI
);
1886 ui_out_field_stream (uiout
, "name", stb
);
1887 annotate_arg_name_end ();
1888 ui_out_text (uiout
, "=");
1890 /* Avoid value_print because it will deref ref parameters. We just
1891 want to print their addresses. Print ??? for args whose address
1892 we do not know. We pass 2 as "recurse" to val_print because our
1893 standard indentation here is 4 spaces, and val_print indents
1894 2 for each recurse. */
1895 val
= read_var_value (sym
, fi
);
1897 annotate_arg_value (val
== NULL
? NULL
: VALUE_TYPE (val
));
1901 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), 0,
1902 VALUE_ADDRESS (val
),
1903 stb
->stream
, 0, 0, 2, Val_no_prettyprint
);
1904 ui_out_field_stream (uiout
, "value", stb
);
1907 ui_out_text (uiout
, "???");
1909 /* Invoke ui_out_tuple_end. */
1910 do_cleanups (list_chain
);
1912 annotate_arg_end ();
1918 /* Don't print nameless args in situations where we don't know
1919 enough about the stack to find them. */
1924 if (highest_offset
== -1)
1925 start
= FRAME_ARGS_SKIP
;
1927 start
= highest_offset
;
1929 print_frame_nameless_args (fi
, start
, num
- args_printed
,
1932 do_cleanups (old_chain
);
1935 /* Print nameless args on STREAM.
1936 FI is the frameinfo for this frame, START is the offset
1937 of the first nameless arg, and NUM is the number of nameless args to
1938 print. FIRST is nonzero if this is the first argument (not just
1939 the first nameless arg). */
1942 print_frame_nameless_args (struct frame_info
*fi
, long start
, int num
,
1943 int first
, struct ui_file
*stream
)
1949 for (i
= 0; i
< num
; i
++)
1952 #ifdef NAMELESS_ARG_VALUE
1953 NAMELESS_ARG_VALUE (fi
, start
, &arg_value
);
1955 argsaddr
= FRAME_ARGS_ADDRESS (fi
);
1959 arg_value
= read_memory_integer (argsaddr
+ start
, sizeof (int));
1963 fprintf_filtered (stream
, ", ");
1965 #ifdef PRINT_NAMELESS_INTEGER
1966 PRINT_NAMELESS_INTEGER (stream
, arg_value
);
1968 #ifdef PRINT_TYPELESS_INTEGER
1969 PRINT_TYPELESS_INTEGER (stream
, builtin_type_int
, (LONGEST
) arg_value
);
1971 fprintf_filtered (stream
, "%ld", arg_value
);
1972 #endif /* PRINT_TYPELESS_INTEGER */
1973 #endif /* PRINT_NAMELESS_INTEGER */
1975 start
+= sizeof (int);
1981 printf_command (char *arg
, int from_tty
)
1983 register char *f
= NULL
;
1984 register char *s
= arg
;
1985 char *string
= NULL
;
1986 struct value
**val_args
;
1988 char *current_substring
;
1990 int allocated_args
= 20;
1991 struct cleanup
*old_cleanups
;
1993 val_args
= (struct value
**) xmalloc (allocated_args
1994 * sizeof (struct value
*));
1995 old_cleanups
= make_cleanup (free_current_contents
, &val_args
);
1998 error_no_arg ("format-control string and values to print");
2000 /* Skip white space before format string */
2001 while (*s
== ' ' || *s
== '\t')
2004 /* A format string should follow, enveloped in double quotes */
2006 error ("Bad format string, missing '\"'.");
2008 /* Parse the format-control string and copy it into the string STRING,
2009 processing some kinds of escape sequence. */
2011 f
= string
= (char *) alloca (strlen (s
) + 1);
2019 error ("Bad format string, non-terminated '\"'.");
2052 /* ??? TODO: handle other escape sequences */
2053 error ("Unrecognized escape character \\%c in format string.",
2063 /* Skip over " and following space and comma. */
2066 while (*s
== ' ' || *s
== '\t')
2069 if (*s
!= ',' && *s
!= 0)
2070 error ("Invalid argument syntax");
2074 while (*s
== ' ' || *s
== '\t')
2077 /* Need extra space for the '\0's. Doubling the size is sufficient. */
2078 substrings
= alloca (strlen (string
) * 2);
2079 current_substring
= substrings
;
2082 /* Now scan the string for %-specs and see what kinds of args they want.
2083 argclass[I] classifies the %-specs so we can give printf_filtered
2084 something of the right size. */
2088 no_arg
, int_arg
, string_arg
, double_arg
, long_long_arg
2090 enum argclass
*argclass
;
2091 enum argclass this_argclass
;
2097 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
2105 while (strchr ("0123456789.hlL-+ #", *f
))
2107 if (*f
== 'l' || *f
== 'L')
2114 this_argclass
= string_arg
;
2120 this_argclass
= double_arg
;
2124 error ("`*' not supported for precision or width in printf");
2127 error ("Format specifier `n' not supported in printf");
2130 this_argclass
= no_arg
;
2135 this_argclass
= long_long_arg
;
2137 this_argclass
= int_arg
;
2141 if (this_argclass
!= no_arg
)
2143 strncpy (current_substring
, last_arg
, f
- last_arg
);
2144 current_substring
+= f
- last_arg
;
2145 *current_substring
++ = '\0';
2147 argclass
[nargs_wanted
++] = this_argclass
;
2151 /* Now, parse all arguments and evaluate them.
2152 Store the VALUEs in VAL_ARGS. */
2157 if (nargs
== allocated_args
)
2158 val_args
= (struct value
**) xrealloc ((char *) val_args
,
2159 (allocated_args
*= 2)
2160 * sizeof (struct value
*));
2162 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
2164 /* If format string wants a float, unchecked-convert the value to
2165 floating point of the same size */
2167 if (argclass
[nargs
] == double_arg
)
2169 struct type
*type
= VALUE_TYPE (val_args
[nargs
]);
2170 if (TYPE_LENGTH (type
) == sizeof (float))
2171 VALUE_TYPE (val_args
[nargs
]) = builtin_type_float
;
2172 if (TYPE_LENGTH (type
) == sizeof (double))
2173 VALUE_TYPE (val_args
[nargs
]) = builtin_type_double
;
2181 if (nargs
!= nargs_wanted
)
2182 error ("Wrong number of arguments for specified format-string");
2184 /* Now actually print them. */
2185 current_substring
= substrings
;
2186 for (i
= 0; i
< nargs
; i
++)
2188 switch (argclass
[i
])
2195 tem
= value_as_address (val_args
[i
]);
2197 /* This is a %s argument. Find the length of the string. */
2202 read_memory (tem
+ j
, &c
, 1);
2207 /* Copy the string contents into a string inside GDB. */
2208 str
= (char *) alloca (j
+ 1);
2210 read_memory (tem
, str
, j
);
2213 printf_filtered (current_substring
, str
);
2218 double val
= value_as_double (val_args
[i
]);
2219 printf_filtered (current_substring
, val
);
2223 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2225 long long val
= value_as_long (val_args
[i
]);
2226 printf_filtered (current_substring
, val
);
2230 error ("long long not supported in printf");
2234 /* FIXME: there should be separate int_arg and long_arg. */
2235 long val
= value_as_long (val_args
[i
]);
2236 printf_filtered (current_substring
, val
);
2239 default: /* purecov: deadcode */
2240 error ("internal error in printf_command"); /* purecov: deadcode */
2242 /* Skip to the next substring. */
2243 current_substring
+= strlen (current_substring
) + 1;
2245 /* Print the portion of the format string after the last argument. */
2246 printf_filtered (last_arg
);
2248 do_cleanups (old_cleanups
);
2251 /* Print the instruction at address MEMADDR in debugged memory,
2252 on STREAM. Returns length of the instruction, in bytes. */
2255 print_insn (CORE_ADDR memaddr
, struct ui_file
*stream
)
2257 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
2258 TARGET_PRINT_INSN_INFO
->endian
= BFD_ENDIAN_BIG
;
2260 TARGET_PRINT_INSN_INFO
->endian
= BFD_ENDIAN_LITTLE
;
2262 if (TARGET_ARCHITECTURE
!= NULL
)
2263 TARGET_PRINT_INSN_INFO
->mach
= TARGET_ARCHITECTURE
->mach
;
2264 /* else: should set .mach=0 but some disassemblers don't grok this */
2266 TARGET_PRINT_INSN_INFO
->stream
= stream
;
2268 return TARGET_PRINT_INSN (memaddr
, TARGET_PRINT_INSN_INFO
);
2273 _initialize_printcmd (void)
2275 struct cmd_list_element
*c
;
2277 current_display_number
= -1;
2279 add_info ("address", address_info
,
2280 "Describe where symbol SYM is stored.");
2282 add_info ("symbol", sym_info
,
2283 "Describe what symbol is at location ADDR.\n\
2284 Only for symbols with fixed locations (global or static scope).");
2286 add_com ("x", class_vars
, x_command
,
2287 concat ("Examine memory: x/FMT ADDRESS.\n\
2288 ADDRESS is an expression for the memory address to examine.\n\
2289 FMT is a repeat count followed by a format letter and a size letter.\n\
2290 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2291 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n",
2292 "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2293 The specified number of objects of the specified size are printed\n\
2294 according to the format.\n\n\
2295 Defaults for format and size letters are those previously used.\n\
2296 Default count is 1. Default address is following last thing printed\n\
2297 with this command or \"print\".", NULL
));
2300 add_com ("whereis", class_vars
, whereis_command
,
2301 "Print line number and file of definition of variable.");
2304 add_info ("display", display_info
,
2305 "Expressions to display when program stops, with code numbers.");
2307 add_cmd ("undisplay", class_vars
, undisplay_command
,
2308 "Cancel some expressions to be displayed when program stops.\n\
2309 Arguments are the code numbers of the expressions to stop displaying.\n\
2310 No argument means cancel all automatic-display expressions.\n\
2311 \"delete display\" has the same effect as this command.\n\
2312 Do \"info display\" to see current list of code numbers.",
2315 add_com ("display", class_vars
, display_command
,
2316 "Print value of expression EXP each time the program stops.\n\
2317 /FMT may be used before EXP as in the \"print\" command.\n\
2318 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2319 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2320 and examining is done as in the \"x\" command.\n\n\
2321 With no argument, display all currently requested auto-display expressions.\n\
2322 Use \"undisplay\" to cancel display requests previously made."
2325 add_cmd ("display", class_vars
, enable_display
,
2326 "Enable some expressions to be displayed when program stops.\n\
2327 Arguments are the code numbers of the expressions to resume displaying.\n\
2328 No argument means enable all automatic-display expressions.\n\
2329 Do \"info display\" to see current list of code numbers.", &enablelist
);
2331 add_cmd ("display", class_vars
, disable_display_command
,
2332 "Disable some expressions to be displayed when program stops.\n\
2333 Arguments are the code numbers of the expressions to stop displaying.\n\
2334 No argument means disable all automatic-display expressions.\n\
2335 Do \"info display\" to see current list of code numbers.", &disablelist
);
2337 add_cmd ("display", class_vars
, undisplay_command
,
2338 "Cancel some expressions to be displayed when program stops.\n\
2339 Arguments are the code numbers of the expressions to stop displaying.\n\
2340 No argument means cancel all automatic-display expressions.\n\
2341 Do \"info display\" to see current list of code numbers.", &deletelist
);
2343 add_com ("printf", class_vars
, printf_command
,
2344 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2345 This is useful for formatted output in user-defined commands.");
2347 add_com ("output", class_vars
, output_command
,
2348 "Like \"print\" but don't put in value history and don't print newline.\n\
2349 This is useful in user-defined commands.");
2351 add_prefix_cmd ("set", class_vars
, set_command
,
2352 concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2353 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2354 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2355 with $), a register (a few standard names starting with $), or an actual\n\
2356 variable in the program being debugged. EXP is any valid expression.\n",
2357 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2358 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2359 You can see these environment settings with the \"show\" command.", NULL
),
2360 &setlist
, "set ", 1, &cmdlist
);
2362 add_com ("assign", class_vars
, set_command
, concat ("Evaluate expression \
2363 EXP and assign result to variable VAR, using assignment\n\
2364 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2365 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2366 with $), a register (a few standard names starting with $), or an actual\n\
2367 variable in the program being debugged. EXP is any valid expression.\n",
2368 "Use \"set variable\" for variables with names identical to set subcommands.\n\
2369 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2370 You can see these environment settings with the \"show\" command.", NULL
));
2372 /* "call" is the same as "set", but handy for dbx users to call fns. */
2373 c
= add_com ("call", class_vars
, call_command
,
2374 "Call a function in the program.\n\
2375 The argument is the function name and arguments, in the notation of the\n\
2376 current working language. The result is printed and saved in the value\n\
2377 history, if it is not void.");
2378 set_cmd_completer (c
, location_completer
);
2380 add_cmd ("variable", class_vars
, set_command
,
2381 "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2382 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2383 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2384 with $), a register (a few standard names starting with $), or an actual\n\
2385 variable in the program being debugged. EXP is any valid expression.\n\
2386 This may usually be abbreviated to simply \"set\".",
2389 c
= add_com ("print", class_vars
, print_command
,
2390 concat ("Print value of expression EXP.\n\
2391 Variables accessible are those of the lexical environment of the selected\n\
2392 stack frame, plus all those whose scope is global or an entire file.\n\
2394 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2395 $$NUM refers to NUM'th value back from the last one.\n\
2396 Names starting with $ refer to registers (with the values they would have\n",
2397 "if the program were to return to the stack frame now selected, restoring\n\
2398 all registers saved by frames farther in) or else to debugger\n\
2399 \"convenience\" variables (any such name not a known register).\n\
2400 Use assignment expressions to give values to convenience variables.\n",
2402 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2403 @ is a binary operator for treating consecutive data objects\n\
2404 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2405 element is FOO, whose second element is stored in the space following\n\
2406 where FOO is stored, etc. FOO must be an expression whose value\n\
2407 resides in memory.\n",
2409 EXP may be preceded with /FMT, where FMT is a format letter\n\
2410 but no count or size letter (see \"x\" command).", NULL
));
2411 set_cmd_completer (c
, location_completer
);
2412 add_com_alias ("p", "print", class_vars
, 1);
2414 c
= add_com ("inspect", class_vars
, inspect_command
,
2415 "Same as \"print\" command, except that if you are running in the epoch\n\
2416 environment, the value is printed in its own window.");
2417 set_cmd_completer (c
, location_completer
);
2420 add_set_cmd ("max-symbolic-offset", no_class
, var_uinteger
,
2421 (char *) &max_symbolic_offset
,
2422 "Set the largest offset that will be printed in <symbol+1234> form.",
2426 add_set_cmd ("symbol-filename", no_class
, var_boolean
,
2427 (char *) &print_symbol_filename
,
2428 "Set printing of source filename and line number with <symbol>.",
2432 /* For examine/instruction a single byte quantity is specified as
2433 the data. This avoids problems with value_at_lazy() requiring a
2434 valid data type (and rejecting VOID). */
2435 examine_i_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_i_type", NULL
);
2437 examine_b_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_b_type", NULL
);
2438 examine_h_type
= init_type (TYPE_CODE_INT
, 2, 0, "examine_h_type", NULL
);
2439 examine_w_type
= init_type (TYPE_CODE_INT
, 4, 0, "examine_w_type", NULL
);
2440 examine_g_type
= init_type (TYPE_CODE_INT
, 8, 0, "examine_g_type", NULL
);