1 /* Print values for GNU debugger GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>. */
23 #include "gdb_string.h"
29 #include "expression.h"
33 #include "breakpoint.h"
37 #include "symfile.h" /* for overlay functions */
38 #include "objfiles.h" /* ditto */
39 #include "completer.h" /* for completion functions */
41 #include "gdb_assert.h"
47 #include "tui/tui.h" /* For tui_active et.al. */
50 #if defined(__MINGW32__)
51 # define USE_PRINTF_I64 1
52 # define PRINTF_HAS_LONG_LONG
54 # define USE_PRINTF_I64 0
57 extern int asm_demangle
; /* Whether to demangle syms in asm printouts */
58 extern int addressprint
; /* Whether to print hex addresses in HLL " */
67 /* Last specified output format. */
69 static char last_format
= 'x';
71 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
73 static char last_size
= 'w';
75 /* Default address to examine next. */
77 static CORE_ADDR next_address
;
79 /* Number of delay instructions following current disassembled insn. */
81 static int branch_delay_insns
;
83 /* Last address examined. */
85 static CORE_ADDR last_examine_address
;
87 /* Contents of last address examined.
88 This is not valid past the end of the `x' command! */
90 static struct value
*last_examine_value
;
92 /* Largest offset between a symbolic value and an address, that will be
93 printed as `0x1234 <symbol+offset>'. */
95 static unsigned int max_symbolic_offset
= UINT_MAX
;
97 show_max_symbolic_offset (struct ui_file
*file
, int from_tty
,
98 struct cmd_list_element
*c
, const char *value
)
100 fprintf_filtered (file
, _("\
101 The largest offset that will be printed in <symbol+1234> form is %s.\n"),
105 /* Append the source filename and linenumber of the symbol when
106 printing a symbolic value as `<symbol at filename:linenum>' if set. */
107 static int print_symbol_filename
= 0;
109 show_print_symbol_filename (struct ui_file
*file
, int from_tty
,
110 struct cmd_list_element
*c
, const char *value
)
112 fprintf_filtered (file
, _("\
113 Printing of source filename and line number with <symbol> is %s.\n"),
117 /* Number of auto-display expression currently being displayed.
118 So that we can disable it if we get an error or a signal within it.
119 -1 when not doing one. */
121 int current_display_number
;
123 /* Flag to low-level print routines that this value is being printed
124 in an epoch window. We'd like to pass this as a parameter, but
125 every routine would need to take it. Perhaps we can encapsulate
126 this in the I/O stream once we have GNU stdio. */
132 /* Chain link to next auto-display item. */
133 struct display
*next
;
134 /* Expression to be evaluated and displayed. */
135 struct expression
*exp
;
136 /* Item number of this auto-display item. */
138 /* Display format specified. */
139 struct format_data format
;
140 /* Innermost block required by this expression when evaluated */
142 /* Status of this display (enabled or disabled) */
146 /* Chain of expressions whose values should be displayed
147 automatically each time the program stops. */
149 static struct display
*display_chain
;
151 static int display_number
;
153 /* Prototypes for exported functions. */
155 void output_command (char *, int);
157 void _initialize_printcmd (void);
159 /* Prototypes for local functions. */
161 static void do_one_display (struct display
*);
164 /* Decode a format specification. *STRING_PTR should point to it.
165 OFORMAT and OSIZE are used as defaults for the format and size
166 if none are given in the format specification.
167 If OSIZE is zero, then the size field of the returned value
168 should be set only if a size is explicitly specified by the
170 The structure returned describes all the data
171 found in the specification. In addition, *STRING_PTR is advanced
172 past the specification and past all whitespace following it. */
174 static struct format_data
175 decode_format (char **string_ptr
, int oformat
, int osize
)
177 struct format_data val
;
178 char *p
= *string_ptr
;
184 if (*p
>= '0' && *p
<= '9')
185 val
.count
= atoi (p
);
186 while (*p
>= '0' && *p
<= '9')
189 /* Now process size or format letters that follow. */
193 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
195 else if (*p
>= 'a' && *p
<= 'z')
201 while (*p
== ' ' || *p
== '\t')
205 /* Set defaults for format and size if not specified. */
206 if (val
.format
== '?')
210 /* Neither has been specified. */
211 val
.format
= oformat
;
215 /* If a size is specified, any format makes a reasonable
216 default except 'i'. */
217 val
.format
= oformat
== 'i' ? 'x' : oformat
;
219 else if (val
.size
== '?')
224 /* Pick the appropriate size for an address. */
225 if (gdbarch_ptr_bit (current_gdbarch
) == 64)
226 val
.size
= osize
? 'g' : osize
;
227 else if (gdbarch_ptr_bit (current_gdbarch
) == 32)
228 val
.size
= osize
? 'w' : osize
;
229 else if (gdbarch_ptr_bit (current_gdbarch
) == 16)
230 val
.size
= osize
? 'h' : osize
;
232 /* Bad value for gdbarch_ptr_bit. */
233 internal_error (__FILE__
, __LINE__
,
234 _("failed internal consistency check"));
237 /* Floating point has to be word or giantword. */
238 if (osize
== 'w' || osize
== 'g')
241 /* Default it to giantword if the last used size is not
243 val
.size
= osize
? 'g' : osize
;
246 /* Characters default to one byte. */
247 val
.size
= osize
? 'b' : osize
;
250 /* The default is the size most recently specified. */
257 /* Print value VAL on stream according to FORMAT, a letter or 0.
258 Do not end with a newline.
259 0 means print VAL according to its own type.
260 SIZE is the letter for the size of datum being printed.
261 This is used to pad hex numbers so they line up. SIZE is 0
262 for print / output and set for examine. */
265 print_formatted (struct value
*val
, int format
, int size
,
266 struct ui_file
*stream
)
268 struct type
*type
= check_typedef (value_type (val
));
269 int len
= TYPE_LENGTH (type
);
271 if (VALUE_LVAL (val
) == lval_memory
)
272 next_address
= VALUE_ADDRESS (val
) + len
;
279 /* FIXME: Need to handle wchar_t's here... */
280 next_address
= VALUE_ADDRESS (val
)
281 + val_print_string (VALUE_ADDRESS (val
), -1, 1, stream
);
285 /* We often wrap here if there are long symbolic names. */
287 next_address
= (VALUE_ADDRESS (val
)
288 + gdb_print_insn (VALUE_ADDRESS (val
), stream
,
289 &branch_delay_insns
));
294 if (format
== 0 || format
== 's'
295 || TYPE_CODE (type
) == TYPE_CODE_REF
296 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
297 || TYPE_CODE (type
) == TYPE_CODE_STRING
298 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
299 || TYPE_CODE (type
) == TYPE_CODE_UNION
300 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
301 /* If format is 0, use the 'natural' format for that type of
302 value. If the type is non-scalar, we have to use language
303 rules to print it as a series of scalars. */
304 value_print (val
, stream
, format
, Val_pretty_default
);
306 /* User specified format, so don't look to the the type to
307 tell us what to do. */
308 print_scalar_formatted (value_contents (val
), type
,
309 format
, size
, stream
);
312 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
313 according to letters FORMAT and SIZE on STREAM.
314 FORMAT may not be zero. Formats s and i are not supported at this level.
316 This is how the elements of an array or structure are printed
320 print_scalar_formatted (const void *valaddr
, struct type
*type
,
321 int format
, int size
, struct ui_file
*stream
)
323 LONGEST val_long
= 0;
324 unsigned int len
= TYPE_LENGTH (type
);
325 enum bfd_endian byte_order
= gdbarch_byte_order (current_gdbarch
);
327 /* If we get here with a string format, try again without it. Go
328 all the way back to the language printers, which may call us
332 val_print (type
, valaddr
, 0, 0, stream
, 0, 0, 0, Val_pretty_default
,
337 if (len
> sizeof(LONGEST
) &&
338 (TYPE_CODE (type
) == TYPE_CODE_INT
339 || TYPE_CODE (type
) == TYPE_CODE_ENUM
))
344 print_octal_chars (stream
, valaddr
, len
, byte_order
);
348 print_decimal_chars (stream
, valaddr
, len
, byte_order
);
351 print_binary_chars (stream
, valaddr
, len
, byte_order
);
354 print_hex_chars (stream
, valaddr
, len
, byte_order
);
357 print_char_chars (stream
, valaddr
, len
, byte_order
);
365 val_long
= unpack_long (type
, valaddr
);
367 /* If the value is a pointer, and pointers and addresses are not the
368 same, then at this point, the value's length (in target bytes) is
369 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
370 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
371 len
= gdbarch_addr_bit (current_gdbarch
) / TARGET_CHAR_BIT
;
373 /* If we are printing it as unsigned, truncate it in case it is actually
374 a negative signed value (e.g. "print/u (short)-1" should print 65535
375 (if shorts are 16 bits) instead of 4294967295). */
378 if (len
< sizeof (LONGEST
))
379 val_long
&= ((LONGEST
) 1 << HOST_CHAR_BIT
* len
) - 1;
387 /* No size specified, like in print. Print varying # of digits. */
388 print_longest (stream
, 'x', 1, val_long
);
397 print_longest (stream
, size
, 1, val_long
);
400 error (_("Undefined output size \"%c\"."), size
);
405 print_longest (stream
, 'd', 1, val_long
);
409 print_longest (stream
, 'u', 0, val_long
);
414 print_longest (stream
, 'o', 1, val_long
);
416 fprintf_filtered (stream
, "0");
421 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
422 print_address (addr
, stream
);
427 if (TYPE_UNSIGNED (type
))
428 value_print (value_from_longest (builtin_type_true_unsigned_char
,
430 stream
, 0, Val_pretty_default
);
432 value_print (value_from_longest (builtin_type_true_char
, val_long
),
433 stream
, 0, Val_pretty_default
);
437 if (len
== TYPE_LENGTH (builtin_type_float
))
438 type
= builtin_type_float
;
439 else if (len
== TYPE_LENGTH (builtin_type_double
))
440 type
= builtin_type_double
;
441 else if (len
== TYPE_LENGTH (builtin_type_long_double
))
442 type
= builtin_type_long_double
;
443 print_floating (valaddr
, type
, stream
);
447 internal_error (__FILE__
, __LINE__
,
448 _("failed internal consistency check"));
451 /* Binary; 't' stands for "two". */
453 char bits
[8 * (sizeof val_long
) + 1];
454 char buf
[8 * (sizeof val_long
) + 32];
459 width
= 8 * (sizeof val_long
);
476 error (_("Undefined output size \"%c\"."), size
);
482 bits
[width
] = (val_long
& 1) ? '1' : '0';
487 while (*cp
&& *cp
== '0')
493 fputs_filtered (buf
, stream
);
498 error (_("Undefined output format \"%c\"."), format
);
502 /* Specify default address for `x' command.
503 The `info lines' command uses this. */
506 set_next_address (CORE_ADDR addr
)
510 /* Make address available to the user as $_. */
511 set_internalvar (lookup_internalvar ("_"),
512 value_from_pointer (builtin_type_void_data_ptr
, addr
));
515 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
516 after LEADIN. Print nothing if no symbolic name is found nearby.
517 Optionally also print source file and line number, if available.
518 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
519 or to interpret it as a possible C++ name and convert it back to source
520 form. However note that DO_DEMANGLE can be overridden by the specific
521 settings of the demangle and asm_demangle variables. */
524 print_address_symbolic (CORE_ADDR addr
, struct ui_file
*stream
,
525 int do_demangle
, char *leadin
)
528 char *filename
= NULL
;
533 /* Throw away both name and filename. */
534 struct cleanup
*cleanup_chain
= make_cleanup (free_current_contents
, &name
);
535 make_cleanup (free_current_contents
, &filename
);
537 if (build_address_symbolic (addr
, do_demangle
, &name
, &offset
,
538 &filename
, &line
, &unmapped
))
540 do_cleanups (cleanup_chain
);
544 fputs_filtered (leadin
, stream
);
546 fputs_filtered ("<*", stream
);
548 fputs_filtered ("<", stream
);
549 fputs_filtered (name
, stream
);
551 fprintf_filtered (stream
, "+%u", (unsigned int) offset
);
553 /* Append source filename and line number if desired. Give specific
554 line # of this addr, if we have it; else line # of the nearest symbol. */
555 if (print_symbol_filename
&& filename
!= NULL
)
558 fprintf_filtered (stream
, " at %s:%d", filename
, line
);
560 fprintf_filtered (stream
, " in %s", filename
);
563 fputs_filtered ("*>", stream
);
565 fputs_filtered (">", stream
);
567 do_cleanups (cleanup_chain
);
570 /* Given an address ADDR return all the elements needed to print the
571 address in a symbolic form. NAME can be mangled or not depending
572 on DO_DEMANGLE (and also on the asm_demangle global variable,
573 manipulated via ''set print asm-demangle''). Return 0 in case of
574 success, when all the info in the OUT paramters is valid. Return 1
577 build_address_symbolic (CORE_ADDR addr
, /* IN */
578 int do_demangle
, /* IN */
579 char **name
, /* OUT */
580 int *offset
, /* OUT */
581 char **filename
, /* OUT */
583 int *unmapped
) /* OUT */
585 struct minimal_symbol
*msymbol
;
586 struct symbol
*symbol
;
587 CORE_ADDR name_location
= 0;
588 struct obj_section
*section
= NULL
;
589 char *name_temp
= "";
591 /* Let's say it is unmapped. */
594 /* Determine if the address is in an overlay, and whether it is
596 if (overlay_debugging
)
598 section
= find_pc_overlay (addr
);
599 if (pc_in_unmapped_range (addr
, section
))
602 addr
= overlay_mapped_address (addr
, section
);
606 /* First try to find the address in the symbol table, then
607 in the minsyms. Take the closest one. */
609 /* This is defective in the sense that it only finds text symbols. So
610 really this is kind of pointless--we should make sure that the
611 minimal symbols have everything we need (by changing that we could
612 save some memory, but for many debug format--ELF/DWARF or
613 anything/stabs--it would be inconvenient to eliminate those minimal
615 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
616 symbol
= find_pc_sect_function (addr
, section
);
620 name_location
= BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
));
621 if (do_demangle
|| asm_demangle
)
622 name_temp
= SYMBOL_PRINT_NAME (symbol
);
624 name_temp
= SYMBOL_LINKAGE_NAME (symbol
);
629 if (SYMBOL_VALUE_ADDRESS (msymbol
) > name_location
|| symbol
== NULL
)
631 /* The msymbol is closer to the address than the symbol;
632 use the msymbol instead. */
634 name_location
= SYMBOL_VALUE_ADDRESS (msymbol
);
635 if (do_demangle
|| asm_demangle
)
636 name_temp
= SYMBOL_PRINT_NAME (msymbol
);
638 name_temp
= SYMBOL_LINKAGE_NAME (msymbol
);
641 if (symbol
== NULL
&& msymbol
== NULL
)
644 /* If the nearest symbol is too far away, don't print anything symbolic. */
646 /* For when CORE_ADDR is larger than unsigned int, we do math in
647 CORE_ADDR. But when we detect unsigned wraparound in the
648 CORE_ADDR math, we ignore this test and print the offset,
649 because addr+max_symbolic_offset has wrapped through the end
650 of the address space back to the beginning, giving bogus comparison. */
651 if (addr
> name_location
+ max_symbolic_offset
652 && name_location
+ max_symbolic_offset
> name_location
)
655 *offset
= addr
- name_location
;
657 *name
= xstrdup (name_temp
);
659 if (print_symbol_filename
)
661 struct symtab_and_line sal
;
663 sal
= find_pc_sect_line (addr
, section
, 0);
667 *filename
= xstrdup (sal
.symtab
->filename
);
675 /* Print address ADDR symbolically on STREAM.
676 First print it as a number. Then perhaps print
677 <SYMBOL + OFFSET> after the number. */
680 print_address (CORE_ADDR addr
, struct ui_file
*stream
)
682 fputs_filtered (paddress (addr
), stream
);
683 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
686 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
687 controls whether to print the symbolic name "raw" or demangled.
688 Global setting "addressprint" controls whether to print hex address
692 print_address_demangle (CORE_ADDR addr
, struct ui_file
*stream
,
697 fprintf_filtered (stream
, "0");
699 else if (addressprint
)
701 fputs_filtered (paddress (addr
), stream
);
702 print_address_symbolic (addr
, stream
, do_demangle
, " ");
706 print_address_symbolic (addr
, stream
, do_demangle
, "");
711 /* These are the types that $__ will get after an examine command of one
714 static struct type
*examine_i_type
;
716 static struct type
*examine_b_type
;
717 static struct type
*examine_h_type
;
718 static struct type
*examine_w_type
;
719 static struct type
*examine_g_type
;
721 /* Examine data at address ADDR in format FMT.
722 Fetch it from memory and print on gdb_stdout. */
725 do_examine (struct format_data fmt
, CORE_ADDR addr
)
730 struct type
*val_type
= NULL
;
739 /* String or instruction format implies fetch single bytes
740 regardless of the specified size. */
741 if (format
== 's' || format
== 'i')
745 val_type
= examine_i_type
;
746 else if (size
== 'b')
747 val_type
= examine_b_type
;
748 else if (size
== 'h')
749 val_type
= examine_h_type
;
750 else if (size
== 'w')
751 val_type
= examine_w_type
;
752 else if (size
== 'g')
753 val_type
= examine_g_type
;
760 if (format
== 's' || format
== 'i')
763 /* Print as many objects as specified in COUNT, at most maxelts per line,
764 with the address of the next one at the start of each line. */
769 print_address (next_address
, gdb_stdout
);
770 printf_filtered (":");
775 printf_filtered ("\t");
776 /* Note that print_formatted sets next_address for the next
778 last_examine_address
= next_address
;
780 if (last_examine_value
)
781 value_free (last_examine_value
);
783 /* The value to be displayed is not fetched greedily.
784 Instead, to avoid the possibility of a fetched value not
785 being used, its retrieval is delayed until the print code
786 uses it. When examining an instruction stream, the
787 disassembler will perform its own memory fetch using just
788 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
789 the disassembler be modified so that LAST_EXAMINE_VALUE
790 is left with the byte sequence from the last complete
791 instruction fetched from memory? */
792 last_examine_value
= value_at_lazy (val_type
, next_address
);
794 if (last_examine_value
)
795 release_value (last_examine_value
);
797 print_formatted (last_examine_value
, format
, size
, gdb_stdout
);
799 /* Display any branch delay slots following the final insn. */
800 if (format
== 'i' && count
== 1)
801 count
+= branch_delay_insns
;
803 printf_filtered ("\n");
804 gdb_flush (gdb_stdout
);
809 validate_format (struct format_data fmt
, char *cmdname
)
812 error (_("Size letters are meaningless in \"%s\" command."), cmdname
);
814 error (_("Item count other than 1 is meaningless in \"%s\" command."),
816 if (fmt
.format
== 'i')
817 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
818 fmt
.format
, cmdname
);
821 /* Evaluate string EXP as an expression in the current language and
822 print the resulting value. EXP may contain a format specifier as the
823 first argument ("/x myvar" for example, to print myvar in hex). */
826 print_command_1 (char *exp
, int inspect
, int voidprint
)
828 struct expression
*expr
;
829 struct cleanup
*old_chain
= 0;
832 struct format_data fmt
;
835 /* Pass inspect flag to the rest of the print routines in a global
837 inspect_it
= inspect
;
839 if (exp
&& *exp
== '/')
842 fmt
= decode_format (&exp
, last_format
, 0);
843 validate_format (fmt
, "print");
844 last_format
= format
= fmt
.format
;
856 expr
= parse_expression (exp
);
857 old_chain
= make_cleanup (free_current_contents
, &expr
);
859 val
= evaluate_expression (expr
);
862 val
= access_value_history (0);
864 if (voidprint
|| (val
&& value_type (val
) &&
865 TYPE_CODE (value_type (val
)) != TYPE_CODE_VOID
))
867 int histindex
= record_latest_value (val
);
870 annotate_value_history_begin (histindex
, value_type (val
));
872 annotate_value_begin (value_type (val
));
875 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"",
877 else if (histindex
>= 0)
878 printf_filtered ("$%d = ", histindex
);
881 annotate_value_history_value ();
883 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
884 printf_filtered ("\n");
887 annotate_value_history_end ();
889 annotate_value_end ();
892 printf_unfiltered ("\") )\030");
896 do_cleanups (old_chain
);
897 inspect_it
= 0; /* Reset print routines to normal. */
901 print_command (char *exp
, int from_tty
)
903 print_command_1 (exp
, 0, 1);
906 /* Same as print, except in epoch, it gets its own window. */
908 inspect_command (char *exp
, int from_tty
)
910 extern int epoch_interface
;
912 print_command_1 (exp
, epoch_interface
, 1);
915 /* Same as print, except it doesn't print void results. */
917 call_command (char *exp
, int from_tty
)
919 print_command_1 (exp
, 0, 0);
923 output_command (char *exp
, int from_tty
)
925 struct expression
*expr
;
926 struct cleanup
*old_chain
;
929 struct format_data fmt
;
933 if (exp
&& *exp
== '/')
936 fmt
= decode_format (&exp
, 0, 0);
937 validate_format (fmt
, "output");
941 expr
= parse_expression (exp
);
942 old_chain
= make_cleanup (free_current_contents
, &expr
);
944 val
= evaluate_expression (expr
);
946 annotate_value_begin (value_type (val
));
948 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
950 annotate_value_end ();
953 gdb_flush (gdb_stdout
);
955 do_cleanups (old_chain
);
959 set_command (char *exp
, int from_tty
)
961 struct expression
*expr
= parse_expression (exp
);
962 struct cleanup
*old_chain
=
963 make_cleanup (free_current_contents
, &expr
);
964 evaluate_expression (expr
);
965 do_cleanups (old_chain
);
969 sym_info (char *arg
, int from_tty
)
971 struct minimal_symbol
*msymbol
;
972 struct objfile
*objfile
;
973 struct obj_section
*osect
;
974 CORE_ADDR addr
, sect_addr
;
979 error_no_arg (_("address"));
981 addr
= parse_and_eval_address (arg
);
982 ALL_OBJSECTIONS (objfile
, osect
)
984 /* Only process each object file once, even if there's a separate
986 if (objfile
->separate_debug_objfile_backlink
)
989 sect_addr
= overlay_mapped_address (addr
, osect
);
991 if (obj_section_addr (osect
) <= sect_addr
992 && sect_addr
< obj_section_endaddr (osect
)
993 && (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr
, osect
)))
996 offset
= sect_addr
- SYMBOL_VALUE_ADDRESS (msymbol
);
998 printf_filtered ("%s + %u in ",
999 SYMBOL_PRINT_NAME (msymbol
), offset
);
1001 printf_filtered ("%s in ",
1002 SYMBOL_PRINT_NAME (msymbol
));
1003 if (pc_in_unmapped_range (addr
, osect
))
1004 printf_filtered (_("load address range of "));
1005 if (section_is_overlay (osect
))
1006 printf_filtered (_("%s overlay "),
1007 section_is_mapped (osect
) ? "mapped" : "unmapped");
1008 printf_filtered (_("section %s"), osect
->the_bfd_section
->name
);
1009 printf_filtered ("\n");
1013 printf_filtered (_("No symbol matches %s.\n"), arg
);
1017 address_info (char *exp
, int from_tty
)
1020 struct minimal_symbol
*msymbol
;
1022 struct obj_section
*section
;
1023 CORE_ADDR load_addr
;
1024 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
1025 if exp is a field of `this'. */
1028 error (_("Argument required."));
1030 sym
= lookup_symbol (exp
, get_selected_block (0), VAR_DOMAIN
,
1031 &is_a_field_of_this
);
1034 if (is_a_field_of_this
)
1036 printf_filtered ("Symbol \"");
1037 fprintf_symbol_filtered (gdb_stdout
, exp
,
1038 current_language
->la_language
, DMGL_ANSI
);
1039 printf_filtered ("\" is a field of the local class variable ");
1040 if (current_language
->la_language
== language_objc
)
1041 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1043 printf_filtered ("`this'\n");
1047 msymbol
= lookup_minimal_symbol (exp
, NULL
, NULL
);
1049 if (msymbol
!= NULL
)
1051 load_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
1053 printf_filtered ("Symbol \"");
1054 fprintf_symbol_filtered (gdb_stdout
, exp
,
1055 current_language
->la_language
, DMGL_ANSI
);
1056 printf_filtered ("\" is at ");
1057 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1058 printf_filtered (" in a file compiled without debugging");
1059 section
= SYMBOL_OBJ_SECTION (msymbol
);
1060 if (section_is_overlay (section
))
1062 load_addr
= overlay_unmapped_address (load_addr
, section
);
1063 printf_filtered (",\n -- loaded at ");
1064 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1065 printf_filtered (" in overlay section %s",
1066 section
->the_bfd_section
->name
);
1068 printf_filtered (".\n");
1071 error (_("No symbol \"%s\" in current context."), exp
);
1075 printf_filtered ("Symbol \"");
1076 fprintf_symbol_filtered (gdb_stdout
, SYMBOL_PRINT_NAME (sym
),
1077 current_language
->la_language
, DMGL_ANSI
);
1078 printf_filtered ("\" is ");
1079 val
= SYMBOL_VALUE (sym
);
1080 section
= SYMBOL_OBJ_SECTION (sym
);
1082 switch (SYMBOL_CLASS (sym
))
1085 case LOC_CONST_BYTES
:
1086 printf_filtered ("constant");
1090 printf_filtered ("a label at address ");
1091 fputs_filtered (paddress (load_addr
= SYMBOL_VALUE_ADDRESS (sym
)),
1093 if (section_is_overlay (section
))
1095 load_addr
= overlay_unmapped_address (load_addr
, section
);
1096 printf_filtered (",\n -- loaded at ");
1097 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1098 printf_filtered (" in overlay section %s",
1099 section
->the_bfd_section
->name
);
1104 /* FIXME: cagney/2004-01-26: It should be possible to
1105 unconditionally call the SYMBOL_OPS method when available.
1106 Unfortunately DWARF 2 stores the frame-base (instead of the
1107 function) location in a function's symbol. Oops! For the
1108 moment enable this when/where applicable. */
1109 SYMBOL_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1113 if (SYMBOL_IS_ARGUMENT (sym
))
1114 printf_filtered (_("an argument in register %s"),
1115 gdbarch_register_name (current_gdbarch
, val
));
1117 printf_filtered (_("a variable in register %s"),
1118 gdbarch_register_name (current_gdbarch
, val
));
1122 printf_filtered (_("static storage at address "));
1123 fputs_filtered (paddress (load_addr
= SYMBOL_VALUE_ADDRESS (sym
)),
1125 if (section_is_overlay (section
))
1127 load_addr
= overlay_unmapped_address (load_addr
, section
);
1128 printf_filtered (_(",\n -- loaded at "));
1129 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1130 printf_filtered (_(" in overlay section %s"),
1131 section
->the_bfd_section
->name
);
1135 case LOC_REGPARM_ADDR
:
1136 printf_filtered (_("address of an argument in register %s"),
1137 gdbarch_register_name (current_gdbarch
, val
));
1141 printf_filtered (_("an argument at offset %ld"), val
);
1145 printf_filtered (_("a local variable at frame offset %ld"), val
);
1149 printf_filtered (_("a reference argument at offset %ld"), val
);
1153 printf_filtered (_("a typedef"));
1157 printf_filtered (_("a function at address "));
1158 load_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1159 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1160 if (section_is_overlay (section
))
1162 load_addr
= overlay_unmapped_address (load_addr
, section
);
1163 printf_filtered (_(",\n -- loaded at "));
1164 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1165 printf_filtered (_(" in overlay section %s"),
1166 section
->the_bfd_section
->name
);
1170 case LOC_UNRESOLVED
:
1172 struct minimal_symbol
*msym
;
1174 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
), NULL
, NULL
);
1176 printf_filtered ("unresolved");
1179 section
= SYMBOL_OBJ_SECTION (msym
);
1180 printf_filtered (_("static storage at address "));
1181 load_addr
= SYMBOL_VALUE_ADDRESS (msym
);
1182 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1183 if (section_is_overlay (section
))
1185 load_addr
= overlay_unmapped_address (load_addr
, section
);
1186 printf_filtered (_(",\n -- loaded at "));
1187 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1188 printf_filtered (_(" in overlay section %s"),
1189 section
->the_bfd_section
->name
);
1195 case LOC_OPTIMIZED_OUT
:
1196 printf_filtered (_("optimized out"));
1200 printf_filtered (_("of unknown (botched) type"));
1203 printf_filtered (".\n");
1208 x_command (char *exp
, int from_tty
)
1210 struct expression
*expr
;
1211 struct format_data fmt
;
1212 struct cleanup
*old_chain
;
1215 fmt
.format
= last_format
;
1216 fmt
.size
= last_size
;
1219 if (exp
&& *exp
== '/')
1222 fmt
= decode_format (&exp
, last_format
, last_size
);
1225 /* If we have an expression, evaluate it and use it as the address. */
1227 if (exp
!= 0 && *exp
!= 0)
1229 expr
= parse_expression (exp
);
1230 /* Cause expression not to be there any more if this command is
1231 repeated with Newline. But don't clobber a user-defined
1232 command's definition. */
1235 old_chain
= make_cleanup (free_current_contents
, &expr
);
1236 val
= evaluate_expression (expr
);
1237 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_REF
)
1238 val
= value_ind (val
);
1239 /* In rvalue contexts, such as this, functions are coerced into
1240 pointers to functions. This makes "x/i main" work. */
1241 if (/* last_format == 'i' && */
1242 TYPE_CODE (value_type (val
)) == TYPE_CODE_FUNC
1243 && VALUE_LVAL (val
) == lval_memory
)
1244 next_address
= VALUE_ADDRESS (val
);
1246 next_address
= value_as_address (val
);
1247 do_cleanups (old_chain
);
1250 do_examine (fmt
, next_address
);
1252 /* If the examine succeeds, we remember its size and format for next
1254 last_size
= fmt
.size
;
1255 last_format
= fmt
.format
;
1257 /* Set a couple of internal variables if appropriate. */
1258 if (last_examine_value
)
1260 /* Make last address examined available to the user as $_. Use
1261 the correct pointer type. */
1262 struct type
*pointer_type
1263 = lookup_pointer_type (value_type (last_examine_value
));
1264 set_internalvar (lookup_internalvar ("_"),
1265 value_from_pointer (pointer_type
,
1266 last_examine_address
));
1268 /* Make contents of last address examined available to the user
1269 as $__. If the last value has not been fetched from memory
1270 then don't fetch it now; instead mark it by voiding the $__
1272 if (value_lazy (last_examine_value
))
1273 set_internalvar (lookup_internalvar ("__"),
1274 allocate_value (builtin_type_void
));
1276 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1281 /* Add an expression to the auto-display chain.
1282 Specify the expression. */
1285 display_command (char *exp
, int from_tty
)
1287 struct format_data fmt
;
1288 struct expression
*expr
;
1289 struct display
*new;
1293 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1295 if (tui_active
&& exp
!= NULL
&& *exp
== '$')
1296 display_it
= (tui_set_layout_for_display_command (exp
) == TUI_FAILURE
);
1310 fmt
= decode_format (&exp
, 0, 0);
1311 if (fmt
.size
&& fmt
.format
== 0)
1313 if (fmt
.format
== 'i' || fmt
.format
== 's')
1323 innermost_block
= 0;
1324 expr
= parse_expression (exp
);
1326 new = (struct display
*) xmalloc (sizeof (struct display
));
1329 new->block
= innermost_block
;
1330 new->next
= display_chain
;
1331 new->number
= ++display_number
;
1334 display_chain
= new;
1336 if (from_tty
&& target_has_execution
)
1337 do_one_display (new);
1344 free_display (struct display
*d
)
1350 /* Clear out the display_chain. Done when new symtabs are loaded,
1351 since this invalidates the types stored in many expressions. */
1354 clear_displays (void)
1358 while ((d
= display_chain
) != NULL
)
1361 display_chain
= d
->next
;
1366 /* Delete the auto-display number NUM. */
1369 delete_display (int num
)
1371 struct display
*d1
, *d
;
1374 error (_("No display number %d."), num
);
1376 if (display_chain
->number
== num
)
1379 display_chain
= d1
->next
;
1383 for (d
= display_chain
;; d
= d
->next
)
1386 error (_("No display number %d."), num
);
1387 if (d
->next
->number
== num
)
1397 /* Delete some values from the auto-display chain.
1398 Specify the element numbers. */
1401 undisplay_command (char *args
, int from_tty
)
1409 if (query ("Delete all auto-display expressions? "))
1418 while (*p1
>= '0' && *p1
<= '9')
1420 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1421 error (_("Arguments must be display numbers."));
1425 delete_display (num
);
1428 while (*p
== ' ' || *p
== '\t')
1434 /* Display a single auto-display.
1435 Do nothing if the display cannot be printed in the current context,
1436 or if the display is disabled. */
1439 do_one_display (struct display
*d
)
1441 int within_current_scope
;
1443 if (d
->enabled_p
== 0)
1447 within_current_scope
= contained_in (get_selected_block (0), d
->block
);
1449 within_current_scope
= 1;
1450 if (!within_current_scope
)
1453 current_display_number
= d
->number
;
1455 annotate_display_begin ();
1456 printf_filtered ("%d", d
->number
);
1457 annotate_display_number_end ();
1458 printf_filtered (": ");
1464 annotate_display_format ();
1466 printf_filtered ("x/");
1467 if (d
->format
.count
!= 1)
1468 printf_filtered ("%d", d
->format
.count
);
1469 printf_filtered ("%c", d
->format
.format
);
1470 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1471 printf_filtered ("%c", d
->format
.size
);
1472 printf_filtered (" ");
1474 annotate_display_expression ();
1476 print_expression (d
->exp
, gdb_stdout
);
1477 annotate_display_expression_end ();
1479 if (d
->format
.count
!= 1 || d
->format
.format
== 'i')
1480 printf_filtered ("\n");
1482 printf_filtered (" ");
1484 val
= evaluate_expression (d
->exp
);
1485 addr
= value_as_address (val
);
1486 if (d
->format
.format
== 'i')
1487 addr
= gdbarch_addr_bits_remove (current_gdbarch
, addr
);
1489 annotate_display_value ();
1491 do_examine (d
->format
, addr
);
1495 annotate_display_format ();
1497 if (d
->format
.format
)
1498 printf_filtered ("/%c ", d
->format
.format
);
1500 annotate_display_expression ();
1502 print_expression (d
->exp
, gdb_stdout
);
1503 annotate_display_expression_end ();
1505 printf_filtered (" = ");
1507 annotate_display_expression ();
1509 print_formatted (evaluate_expression (d
->exp
),
1510 d
->format
.format
, d
->format
.size
, gdb_stdout
);
1511 printf_filtered ("\n");
1514 annotate_display_end ();
1516 gdb_flush (gdb_stdout
);
1517 current_display_number
= -1;
1520 /* Display all of the values on the auto-display chain which can be
1521 evaluated in the current scope. */
1528 for (d
= display_chain
; d
; d
= d
->next
)
1532 /* Delete the auto-display which we were in the process of displaying.
1533 This is done when there is an error or a signal. */
1536 disable_display (int num
)
1540 for (d
= display_chain
; d
; d
= d
->next
)
1541 if (d
->number
== num
)
1546 printf_unfiltered (_("No display number %d.\n"), num
);
1550 disable_current_display (void)
1552 if (current_display_number
>= 0)
1554 disable_display (current_display_number
);
1555 fprintf_unfiltered (gdb_stderr
, _("\
1556 Disabling display %d to avoid infinite recursion.\n"),
1557 current_display_number
);
1559 current_display_number
= -1;
1563 display_info (char *ignore
, int from_tty
)
1568 printf_unfiltered (_("There are no auto-display expressions now.\n"));
1570 printf_filtered (_("Auto-display expressions now in effect:\n\
1571 Num Enb Expression\n"));
1573 for (d
= display_chain
; d
; d
= d
->next
)
1575 printf_filtered ("%d: %c ", d
->number
, "ny"[(int) d
->enabled_p
]);
1577 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1579 else if (d
->format
.format
)
1580 printf_filtered ("/%c ", d
->format
.format
);
1581 print_expression (d
->exp
, gdb_stdout
);
1582 if (d
->block
&& !contained_in (get_selected_block (0), d
->block
))
1583 printf_filtered (_(" (cannot be evaluated in the current context)"));
1584 printf_filtered ("\n");
1585 gdb_flush (gdb_stdout
);
1590 enable_display (char *args
, int from_tty
)
1599 for (d
= display_chain
; d
; d
= d
->next
)
1606 while (*p1
>= '0' && *p1
<= '9')
1608 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1609 error (_("Arguments must be display numbers."));
1613 for (d
= display_chain
; d
; d
= d
->next
)
1614 if (d
->number
== num
)
1619 printf_unfiltered (_("No display number %d.\n"), num
);
1622 while (*p
== ' ' || *p
== '\t')
1628 disable_display_command (char *args
, int from_tty
)
1636 for (d
= display_chain
; d
; d
= d
->next
)
1643 while (*p1
>= '0' && *p1
<= '9')
1645 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1646 error (_("Arguments must be display numbers."));
1648 disable_display (atoi (p
));
1651 while (*p
== ' ' || *p
== '\t')
1657 /* Print the value in stack frame FRAME of a variable specified by a
1661 print_variable_value (struct symbol
*var
, struct frame_info
*frame
,
1662 struct ui_file
*stream
)
1664 struct value
*val
= read_var_value (var
, frame
);
1666 value_print (val
, stream
, 0, Val_pretty_default
);
1670 printf_command (char *arg
, int from_tty
)
1674 char *string
= NULL
;
1675 struct value
**val_args
;
1677 char *current_substring
;
1679 int allocated_args
= 20;
1680 struct cleanup
*old_cleanups
;
1682 val_args
= xmalloc (allocated_args
* sizeof (struct value
*));
1683 old_cleanups
= make_cleanup (free_current_contents
, &val_args
);
1686 error_no_arg (_("format-control string and values to print"));
1688 /* Skip white space before format string */
1689 while (*s
== ' ' || *s
== '\t')
1692 /* A format string should follow, enveloped in double quotes. */
1694 error (_("Bad format string, missing '\"'."));
1696 /* Parse the format-control string and copy it into the string STRING,
1697 processing some kinds of escape sequence. */
1699 f
= string
= (char *) alloca (strlen (s
) + 1);
1707 error (_("Bad format string, non-terminated '\"'."));
1740 /* ??? TODO: handle other escape sequences */
1741 error (_("Unrecognized escape character \\%c in format string."),
1751 /* Skip over " and following space and comma. */
1754 while (*s
== ' ' || *s
== '\t')
1757 if (*s
!= ',' && *s
!= 0)
1758 error (_("Invalid argument syntax"));
1762 while (*s
== ' ' || *s
== '\t')
1765 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1766 substrings
= alloca (strlen (string
) * 2);
1767 current_substring
= substrings
;
1770 /* Now scan the string for %-specs and see what kinds of args they want.
1771 argclass[I] classifies the %-specs so we can give printf_filtered
1772 something of the right size. */
1776 int_arg
, long_arg
, long_long_arg
, ptr_arg
, string_arg
,
1777 double_arg
, long_double_arg
, decfloat_arg
1779 enum argclass
*argclass
;
1780 enum argclass this_argclass
;
1785 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1792 int seen_hash
= 0, seen_zero
= 0, lcount
= 0, seen_prec
= 0;
1793 int seen_space
= 0, seen_plus
= 0;
1794 int seen_big_l
= 0, seen_h
= 0, seen_big_h
= 0;
1795 int seen_big_d
= 0, seen_double_big_d
= 0;
1798 /* Check the validity of the format specifier, and work
1799 out what argument it expects. We only accept C89
1800 format strings, with the exception of long long (which
1801 we autoconf for). */
1803 /* Skip over "%%". */
1810 /* The first part of a format specifier is a set of flag
1812 while (strchr ("0-+ #", *f
))
1825 /* The next part of a format specifier is a width. */
1826 while (strchr ("0123456789", *f
))
1829 /* The next part of a format specifier is a precision. */
1834 while (strchr ("0123456789", *f
))
1838 /* The next part of a format specifier is a length modifier. */
1859 /* Decimal32 modifier. */
1865 /* Decimal64 and Decimal128 modifiers. */
1870 /* Check for a Decimal128. */
1874 seen_double_big_d
= 1;
1890 if (seen_space
|| seen_plus
)
1897 this_argclass
= int_arg
;
1898 else if (lcount
== 1)
1899 this_argclass
= long_arg
;
1901 this_argclass
= long_long_arg
;
1908 this_argclass
= int_arg
;
1909 if (lcount
|| seen_h
|| seen_big_l
)
1911 if (seen_prec
|| seen_zero
|| seen_space
|| seen_plus
)
1916 this_argclass
= ptr_arg
;
1917 if (lcount
|| seen_h
|| seen_big_l
)
1919 if (seen_prec
|| seen_zero
|| seen_space
|| seen_plus
)
1924 this_argclass
= string_arg
;
1925 if (lcount
|| seen_h
|| seen_big_l
)
1927 if (seen_zero
|| seen_space
|| seen_plus
)
1936 if (seen_big_h
|| seen_big_d
|| seen_double_big_d
)
1937 this_argclass
= decfloat_arg
;
1938 else if (seen_big_l
)
1939 this_argclass
= long_double_arg
;
1941 this_argclass
= double_arg
;
1943 if (lcount
|| seen_h
)
1948 error (_("`*' not supported for precision or width in printf"));
1951 error (_("Format specifier `n' not supported in printf"));
1954 error (_("Incomplete format specifier at end of format string"));
1957 error (_("Unrecognized format specifier '%c' in printf"), *f
);
1961 error (_("Inappropriate modifiers to format specifier '%c' in printf"),
1966 if (lcount
> 1 && USE_PRINTF_I64
)
1968 /* Windows' printf does support long long, but not the usual way.
1969 Convert %lld to %I64d. */
1970 int length_before_ll
= f
- last_arg
- 1 - lcount
;
1971 strncpy (current_substring
, last_arg
, length_before_ll
);
1972 strcpy (current_substring
+ length_before_ll
, "I64");
1973 current_substring
[length_before_ll
+ 3] =
1974 last_arg
[length_before_ll
+ lcount
];
1975 current_substring
+= length_before_ll
+ 4;
1979 strncpy (current_substring
, last_arg
, f
- last_arg
);
1980 current_substring
+= f
- last_arg
;
1982 *current_substring
++ = '\0';
1984 argclass
[nargs_wanted
++] = this_argclass
;
1987 /* Now, parse all arguments and evaluate them.
1988 Store the VALUEs in VAL_ARGS. */
1993 if (nargs
== allocated_args
)
1994 val_args
= (struct value
**) xrealloc ((char *) val_args
,
1995 (allocated_args
*= 2)
1996 * sizeof (struct value
*));
1998 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
2000 /* If format string wants a float, unchecked-convert the value to
2001 floating point of the same size */
2003 if (argclass
[nargs
] == double_arg
)
2005 struct type
*type
= value_type (val_args
[nargs
]);
2006 if (TYPE_LENGTH (type
) == sizeof (float))
2007 deprecated_set_value_type (val_args
[nargs
], builtin_type_float
);
2008 if (TYPE_LENGTH (type
) == sizeof (double))
2009 deprecated_set_value_type (val_args
[nargs
], builtin_type_double
);
2017 if (nargs
!= nargs_wanted
)
2018 error (_("Wrong number of arguments for specified format-string"));
2020 /* Now actually print them. */
2021 current_substring
= substrings
;
2022 for (i
= 0; i
< nargs
; i
++)
2024 switch (argclass
[i
])
2031 tem
= value_as_address (val_args
[i
]);
2033 /* This is a %s argument. Find the length of the string. */
2038 read_memory (tem
+ j
, &c
, 1);
2043 /* Copy the string contents into a string inside GDB. */
2044 str
= (gdb_byte
*) alloca (j
+ 1);
2046 read_memory (tem
, str
, j
);
2049 printf_filtered (current_substring
, (char *) str
);
2054 double val
= value_as_double (val_args
[i
]);
2055 printf_filtered (current_substring
, val
);
2058 case long_double_arg
:
2059 #ifdef HAVE_LONG_DOUBLE
2061 long double val
= value_as_double (val_args
[i
]);
2062 printf_filtered (current_substring
, val
);
2066 error (_("long double not supported in printf"));
2069 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2071 long long val
= value_as_long (val_args
[i
]);
2072 printf_filtered (current_substring
, val
);
2076 error (_("long long not supported in printf"));
2080 int val
= value_as_long (val_args
[i
]);
2081 printf_filtered (current_substring
, val
);
2086 long val
= value_as_long (val_args
[i
]);
2087 printf_filtered (current_substring
, val
);
2091 /* Handles decimal floating values. */
2094 const gdb_byte
*param_ptr
= value_contents (val_args
[i
]);
2095 #if defined (PRINTF_HAS_DECFLOAT)
2096 /* If we have native support for Decimal floating
2097 printing, handle it here. */
2098 printf_filtered (current_substring
, param_ptr
);
2101 /* As a workaround until vasprintf has native support for DFP
2102 we convert the DFP values to string and print them using
2103 the %s format specifier. */
2106 int nnull_chars
= 0;
2108 /* Parameter data. */
2109 struct type
*param_type
= value_type (val_args
[i
]);
2110 unsigned int param_len
= TYPE_LENGTH (param_type
);
2112 /* DFP output data. */
2113 struct value
*dfp_value
= NULL
;
2117 struct type
*dfp_type
= NULL
;
2118 char decstr
[MAX_DECIMAL_STRING
];
2120 /* Points to the end of the string so that we can go back
2121 and check for DFP length modifiers. */
2122 eos
= current_substring
+ strlen (current_substring
);
2124 /* Look for the float/double format specifier. */
2125 while (*eos
!= 'f' && *eos
!= 'e' && *eos
!= 'E'
2126 && *eos
!= 'g' && *eos
!= 'G')
2131 /* Search for the '%' char and extract the size and type of
2132 the output decimal value based on its modifiers
2133 (%Hf, %Df, %DDf). */
2134 while (*--sos
!= '%')
2139 dfp_type
= builtin_type (current_gdbarch
)->builtin_decfloat
;
2141 else if (*sos
== 'D' && *(sos
- 1) == 'D')
2144 dfp_type
= builtin_type (current_gdbarch
)->builtin_declong
;
2150 dfp_type
= builtin_type (current_gdbarch
)->builtin_decdouble
;
2154 /* Replace %Hf, %Df and %DDf with %s's. */
2157 /* Go through the whole format string and pull the correct
2158 number of chars back to compensate for the change in the
2159 format specifier. */
2160 while (nnull_chars
< nargs
- i
)
2168 /* Conversion between different DFP types. */
2169 if (TYPE_CODE (param_type
) == TYPE_CODE_DECFLOAT
)
2170 decimal_convert (param_ptr
, param_len
, dec
, dfp_len
);
2172 /* If this is a non-trivial conversion, just output 0.
2173 A correct converted value can be displayed by explicitly
2174 casting to a DFP type. */
2175 decimal_from_string (dec
, dfp_len
, "0");
2177 dfp_value
= value_from_decfloat (dfp_type
, dec
);
2179 dfp_ptr
= (gdb_byte
*) value_contents (dfp_value
);
2181 decimal_to_string (dfp_ptr
, dfp_len
, decstr
);
2183 /* Print the DFP value. */
2184 printf_filtered (current_substring
, decstr
);
2192 /* We avoid the host's %p because pointers are too
2193 likely to be the wrong size. The only interesting
2194 modifier for %p is a width; extract that, and then
2195 handle %p as glibc would: %#x or a literal "(nil)". */
2197 char *p
, *fmt
, *fmt_p
;
2198 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2199 long long val
= value_as_long (val_args
[i
]);
2201 long val
= value_as_long (val_args
[i
]);
2204 fmt
= alloca (strlen (current_substring
) + 5);
2206 /* Copy up to the leading %. */
2207 p
= current_substring
;
2211 int is_percent
= (*p
== '%');
2225 /* Copy any width. */
2226 while (*p
>= '0' && *p
< '9')
2229 gdb_assert (*p
== 'p' && *(p
+ 1) == '\0');
2232 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2238 printf_filtered (fmt
, val
);
2244 printf_filtered (fmt
, "(nil)");
2250 internal_error (__FILE__
, __LINE__
,
2251 _("failed internal consistency check"));
2253 /* Skip to the next substring. */
2254 current_substring
+= strlen (current_substring
) + 1;
2256 /* Print the portion of the format string after the last argument. */
2257 puts_filtered (last_arg
);
2259 do_cleanups (old_cleanups
);
2263 _initialize_printcmd (void)
2265 struct cmd_list_element
*c
;
2267 current_display_number
= -1;
2269 add_info ("address", address_info
,
2270 _("Describe where symbol SYM is stored."));
2272 add_info ("symbol", sym_info
, _("\
2273 Describe what symbol is at location ADDR.\n\
2274 Only for symbols with fixed locations (global or static scope)."));
2276 add_com ("x", class_vars
, x_command
, _("\
2277 Examine memory: x/FMT ADDRESS.\n\
2278 ADDRESS is an expression for the memory address to examine.\n\
2279 FMT is a repeat count followed by a format letter and a size letter.\n\
2280 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2281 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2282 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2283 The specified number of objects of the specified size are printed\n\
2284 according to the format.\n\n\
2285 Defaults for format and size letters are those previously used.\n\
2286 Default count is 1. Default address is following last thing printed\n\
2287 with this command or \"print\"."));
2290 add_com ("whereis", class_vars
, whereis_command
,
2291 _("Print line number and file of definition of variable."));
2294 add_info ("display", display_info
, _("\
2295 Expressions to display when program stops, with code numbers."));
2297 add_cmd ("undisplay", class_vars
, undisplay_command
, _("\
2298 Cancel some expressions to be displayed when program stops.\n\
2299 Arguments are the code numbers of the expressions to stop displaying.\n\
2300 No argument means cancel all automatic-display expressions.\n\
2301 \"delete display\" has the same effect as this command.\n\
2302 Do \"info display\" to see current list of code numbers."),
2305 add_com ("display", class_vars
, display_command
, _("\
2306 Print value of expression EXP each time the program stops.\n\
2307 /FMT may be used before EXP as in the \"print\" command.\n\
2308 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2309 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2310 and examining is done as in the \"x\" command.\n\n\
2311 With no argument, display all currently requested auto-display expressions.\n\
2312 Use \"undisplay\" to cancel display requests previously made."));
2314 add_cmd ("display", class_vars
, enable_display
, _("\
2315 Enable some expressions to be displayed when program stops.\n\
2316 Arguments are the code numbers of the expressions to resume displaying.\n\
2317 No argument means enable all automatic-display expressions.\n\
2318 Do \"info display\" to see current list of code numbers."), &enablelist
);
2320 add_cmd ("display", class_vars
, disable_display_command
, _("\
2321 Disable some expressions to be displayed when program stops.\n\
2322 Arguments are the code numbers of the expressions to stop displaying.\n\
2323 No argument means disable all automatic-display expressions.\n\
2324 Do \"info display\" to see current list of code numbers."), &disablelist
);
2326 add_cmd ("display", class_vars
, undisplay_command
, _("\
2327 Cancel some expressions to be displayed when program stops.\n\
2328 Arguments are the code numbers of the expressions to stop displaying.\n\
2329 No argument means cancel all automatic-display expressions.\n\
2330 Do \"info display\" to see current list of code numbers."), &deletelist
);
2332 add_com ("printf", class_vars
, printf_command
, _("\
2333 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2334 This is useful for formatted output in user-defined commands."));
2336 add_com ("output", class_vars
, output_command
, _("\
2337 Like \"print\" but don't put in value history and don't print newline.\n\
2338 This is useful in user-defined commands."));
2340 add_prefix_cmd ("set", class_vars
, set_command
, _("\
2341 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2342 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2343 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2344 with $), a register (a few standard names starting with $), or an actual\n\
2345 variable in the program being debugged. EXP is any valid expression.\n\
2346 Use \"set variable\" for variables with names identical to set subcommands.\n\
2348 With a subcommand, this command modifies parts of the gdb environment.\n\
2349 You can see these environment settings with the \"show\" command."),
2350 &setlist
, "set ", 1, &cmdlist
);
2352 add_com ("assign", class_vars
, set_command
, _("\
2353 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2354 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2355 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2356 with $), a register (a few standard names starting with $), or an actual\n\
2357 variable in the program being debugged. EXP is any valid expression.\n\
2358 Use \"set variable\" for variables with names identical to set subcommands.\n\
2359 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2360 You can see these environment settings with the \"show\" command."));
2362 /* "call" is the same as "set", but handy for dbx users to call fns. */
2363 c
= add_com ("call", class_vars
, call_command
, _("\
2364 Call a function in the program.\n\
2365 The argument is the function name and arguments, in the notation of the\n\
2366 current working language. The result is printed and saved in the value\n\
2367 history, if it is not void."));
2368 set_cmd_completer (c
, expression_completer
);
2370 add_cmd ("variable", class_vars
, set_command
, _("\
2371 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2372 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2373 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2374 with $), a register (a few standard names starting with $), or an actual\n\
2375 variable in the program being debugged. EXP is any valid expression.\n\
2376 This may usually be abbreviated to simply \"set\"."),
2379 c
= add_com ("print", class_vars
, print_command
, _("\
2380 Print value of expression EXP.\n\
2381 Variables accessible are those of the lexical environment of the selected\n\
2382 stack frame, plus all those whose scope is global or an entire file.\n\
2384 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2385 $$NUM refers to NUM'th value back from the last one.\n\
2386 Names starting with $ refer to registers (with the values they would have\n\
2387 if the program were to return to the stack frame now selected, restoring\n\
2388 all registers saved by frames farther in) or else to debugger\n\
2389 \"convenience\" variables (any such name not a known register).\n\
2390 Use assignment expressions to give values to convenience variables.\n\
2392 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2393 @ is a binary operator for treating consecutive data objects\n\
2394 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2395 element is FOO, whose second element is stored in the space following\n\
2396 where FOO is stored, etc. FOO must be an expression whose value\n\
2397 resides in memory.\n\
2399 EXP may be preceded with /FMT, where FMT is a format letter\n\
2400 but no count or size letter (see \"x\" command)."));
2401 set_cmd_completer (c
, expression_completer
);
2402 add_com_alias ("p", "print", class_vars
, 1);
2404 c
= add_com ("inspect", class_vars
, inspect_command
, _("\
2405 Same as \"print\" command, except that if you are running in the epoch\n\
2406 environment, the value is printed in its own window."));
2407 set_cmd_completer (c
, expression_completer
);
2409 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class
,
2410 &max_symbolic_offset
, _("\
2411 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2412 Show the largest offset that will be printed in <symbol+1234> form."), NULL
,
2414 show_max_symbolic_offset
,
2415 &setprintlist
, &showprintlist
);
2416 add_setshow_boolean_cmd ("symbol-filename", no_class
,
2417 &print_symbol_filename
, _("\
2418 Set printing of source filename and line number with <symbol>."), _("\
2419 Show printing of source filename and line number with <symbol>."), NULL
,
2421 show_print_symbol_filename
,
2422 &setprintlist
, &showprintlist
);
2424 /* For examine/instruction a single byte quantity is specified as
2425 the data. This avoids problems with value_at_lazy() requiring a
2426 valid data type (and rejecting VOID). */
2427 examine_i_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_i_type", NULL
);
2429 examine_b_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_b_type", NULL
);
2430 examine_h_type
= init_type (TYPE_CODE_INT
, 2, 0, "examine_h_type", NULL
);
2431 examine_w_type
= init_type (TYPE_CODE_INT
, 4, 0, "examine_w_type", NULL
);
2432 examine_g_type
= init_type (TYPE_CODE_INT
, 8, 0, "examine_g_type", NULL
);