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 extern int asm_demangle
; /* Whether to demangle syms in asm printouts */
51 extern int addressprint
; /* Whether to print hex addresses in HLL " */
60 /* Last specified output format. */
62 static char last_format
= 'x';
64 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
66 static char last_size
= 'w';
68 /* Default address to examine next. */
70 static CORE_ADDR next_address
;
72 /* Number of delay instructions following current disassembled insn. */
74 static int branch_delay_insns
;
76 /* Last address examined. */
78 static CORE_ADDR last_examine_address
;
80 /* Contents of last address examined.
81 This is not valid past the end of the `x' command! */
83 static struct value
*last_examine_value
;
85 /* Largest offset between a symbolic value and an address, that will be
86 printed as `0x1234 <symbol+offset>'. */
88 static unsigned int max_symbolic_offset
= UINT_MAX
;
90 show_max_symbolic_offset (struct ui_file
*file
, int from_tty
,
91 struct cmd_list_element
*c
, const char *value
)
93 fprintf_filtered (file
, _("\
94 The largest offset that will be printed in <symbol+1234> form is %s.\n"),
98 /* Append the source filename and linenumber of the symbol when
99 printing a symbolic value as `<symbol at filename:linenum>' if set. */
100 static int print_symbol_filename
= 0;
102 show_print_symbol_filename (struct ui_file
*file
, int from_tty
,
103 struct cmd_list_element
*c
, const char *value
)
105 fprintf_filtered (file
, _("\
106 Printing of source filename and line number with <symbol> is %s.\n"),
110 /* Number of auto-display expression currently being displayed.
111 So that we can disable it if we get an error or a signal within it.
112 -1 when not doing one. */
114 int current_display_number
;
116 /* Flag to low-level print routines that this value is being printed
117 in an epoch window. We'd like to pass this as a parameter, but
118 every routine would need to take it. Perhaps we can encapsulate
119 this in the I/O stream once we have GNU stdio. */
125 /* Chain link to next auto-display item. */
126 struct display
*next
;
127 /* Expression to be evaluated and displayed. */
128 struct expression
*exp
;
129 /* Item number of this auto-display item. */
131 /* Display format specified. */
132 struct format_data format
;
133 /* Innermost block required by this expression when evaluated */
135 /* Status of this display (enabled or disabled) */
139 /* Chain of expressions whose values should be displayed
140 automatically each time the program stops. */
142 static struct display
*display_chain
;
144 static int display_number
;
146 /* Prototypes for exported functions. */
148 void output_command (char *, int);
150 void _initialize_printcmd (void);
152 /* Prototypes for local functions. */
154 static void do_one_display (struct display
*);
157 /* Decode a format specification. *STRING_PTR should point to it.
158 OFORMAT and OSIZE are used as defaults for the format and size
159 if none are given in the format specification.
160 If OSIZE is zero, then the size field of the returned value
161 should be set only if a size is explicitly specified by the
163 The structure returned describes all the data
164 found in the specification. In addition, *STRING_PTR is advanced
165 past the specification and past all whitespace following it. */
167 static struct format_data
168 decode_format (char **string_ptr
, int oformat
, int osize
)
170 struct format_data val
;
171 char *p
= *string_ptr
;
177 if (*p
>= '0' && *p
<= '9')
178 val
.count
= atoi (p
);
179 while (*p
>= '0' && *p
<= '9')
182 /* Now process size or format letters that follow. */
186 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
188 else if (*p
>= 'a' && *p
<= 'z')
194 while (*p
== ' ' || *p
== '\t')
198 /* Set defaults for format and size if not specified. */
199 if (val
.format
== '?')
203 /* Neither has been specified. */
204 val
.format
= oformat
;
208 /* If a size is specified, any format makes a reasonable
209 default except 'i'. */
210 val
.format
= oformat
== 'i' ? 'x' : oformat
;
212 else if (val
.size
== '?')
217 /* Pick the appropriate size for an address. */
218 if (gdbarch_ptr_bit (current_gdbarch
) == 64)
219 val
.size
= osize
? 'g' : osize
;
220 else if (gdbarch_ptr_bit (current_gdbarch
) == 32)
221 val
.size
= osize
? 'w' : osize
;
222 else if (gdbarch_ptr_bit (current_gdbarch
) == 16)
223 val
.size
= osize
? 'h' : osize
;
225 /* Bad value for gdbarch_ptr_bit. */
226 internal_error (__FILE__
, __LINE__
,
227 _("failed internal consistency check"));
230 /* Floating point has to be word or giantword. */
231 if (osize
== 'w' || osize
== 'g')
234 /* Default it to giantword if the last used size is not
236 val
.size
= osize
? 'g' : osize
;
239 /* Characters default to one byte. */
240 val
.size
= osize
? 'b' : osize
;
243 /* The default is the size most recently specified. */
250 /* Print value VAL on stream according to FORMAT, a letter or 0.
251 Do not end with a newline.
252 0 means print VAL according to its own type.
253 SIZE is the letter for the size of datum being printed.
254 This is used to pad hex numbers so they line up. SIZE is 0
255 for print / output and set for examine. */
258 print_formatted (struct value
*val
, int format
, int size
,
259 struct ui_file
*stream
)
261 struct type
*type
= check_typedef (value_type (val
));
262 int len
= TYPE_LENGTH (type
);
264 if (VALUE_LVAL (val
) == lval_memory
)
265 next_address
= VALUE_ADDRESS (val
) + len
;
272 /* FIXME: Need to handle wchar_t's here... */
273 next_address
= VALUE_ADDRESS (val
)
274 + val_print_string (VALUE_ADDRESS (val
), -1, 1, stream
);
278 /* We often wrap here if there are long symbolic names. */
280 next_address
= (VALUE_ADDRESS (val
)
281 + gdb_print_insn (VALUE_ADDRESS (val
), stream
,
282 &branch_delay_insns
));
287 if (format
== 0 || format
== 's'
288 || TYPE_CODE (type
) == TYPE_CODE_REF
289 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
290 || TYPE_CODE (type
) == TYPE_CODE_STRING
291 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
292 || TYPE_CODE (type
) == TYPE_CODE_UNION
293 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
294 /* If format is 0, use the 'natural' format for that type of
295 value. If the type is non-scalar, we have to use language
296 rules to print it as a series of scalars. */
297 value_print (val
, stream
, format
, Val_pretty_default
);
299 /* User specified format, so don't look to the the type to
300 tell us what to do. */
301 print_scalar_formatted (value_contents (val
), type
,
302 format
, size
, stream
);
305 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
306 according to letters FORMAT and SIZE on STREAM.
307 FORMAT may not be zero. Formats s and i are not supported at this level.
309 This is how the elements of an array or structure are printed
313 print_scalar_formatted (const void *valaddr
, struct type
*type
,
314 int format
, int size
, struct ui_file
*stream
)
316 LONGEST val_long
= 0;
317 unsigned int len
= TYPE_LENGTH (type
);
319 /* If we get here with a string format, try again without it. Go
320 all the way back to the language printers, which may call us
324 val_print (type
, valaddr
, 0, 0, stream
, 0, 0, 0, Val_pretty_default
);
328 if (len
> sizeof(LONGEST
) &&
329 (TYPE_CODE (type
) == TYPE_CODE_INT
330 || TYPE_CODE (type
) == TYPE_CODE_ENUM
))
335 print_octal_chars (stream
, valaddr
, len
);
339 print_decimal_chars (stream
, valaddr
, len
);
342 print_binary_chars (stream
, valaddr
, len
);
345 print_hex_chars (stream
, valaddr
, len
);
348 print_char_chars (stream
, valaddr
, len
);
356 val_long
= unpack_long (type
, valaddr
);
358 /* If the value is a pointer, and pointers and addresses are not the
359 same, then at this point, the value's length (in target bytes) is
360 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
361 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
362 len
= gdbarch_addr_bit (current_gdbarch
) / TARGET_CHAR_BIT
;
364 /* If we are printing it as unsigned, truncate it in case it is actually
365 a negative signed value (e.g. "print/u (short)-1" should print 65535
366 (if shorts are 16 bits) instead of 4294967295). */
369 if (len
< sizeof (LONGEST
))
370 val_long
&= ((LONGEST
) 1 << HOST_CHAR_BIT
* len
) - 1;
378 /* No size specified, like in print. Print varying # of digits. */
379 print_longest (stream
, 'x', 1, val_long
);
388 print_longest (stream
, size
, 1, val_long
);
391 error (_("Undefined output size \"%c\"."), size
);
396 print_longest (stream
, 'd', 1, val_long
);
400 print_longest (stream
, 'u', 0, val_long
);
405 print_longest (stream
, 'o', 1, val_long
);
407 fprintf_filtered (stream
, "0");
412 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
413 print_address (addr
, stream
);
418 if (TYPE_UNSIGNED (type
))
422 utype
= builtin_type (current_gdbarch
)->builtin_true_unsigned_char
;
423 value_print (value_from_longest (utype
, val_long
),
424 stream
, 0, Val_pretty_default
);
427 value_print (value_from_longest (builtin_type_true_char
, val_long
),
428 stream
, 0, Val_pretty_default
);
432 if (len
== TYPE_LENGTH (builtin_type_float
))
433 type
= builtin_type_float
;
434 else if (len
== TYPE_LENGTH (builtin_type_double
))
435 type
= builtin_type_double
;
436 else if (len
== TYPE_LENGTH (builtin_type_long_double
))
437 type
= builtin_type_long_double
;
438 print_floating (valaddr
, type
, stream
);
442 internal_error (__FILE__
, __LINE__
,
443 _("failed internal consistency check"));
446 /* Binary; 't' stands for "two". */
448 char bits
[8 * (sizeof val_long
) + 1];
449 char buf
[8 * (sizeof val_long
) + 32];
454 width
= 8 * (sizeof val_long
);
471 error (_("Undefined output size \"%c\"."), size
);
477 bits
[width
] = (val_long
& 1) ? '1' : '0';
482 while (*cp
&& *cp
== '0')
488 fputs_filtered (buf
, stream
);
493 error (_("Undefined output format \"%c\"."), format
);
497 /* Specify default address for `x' command.
498 The `info lines' command uses this. */
501 set_next_address (CORE_ADDR addr
)
505 /* Make address available to the user as $_. */
506 set_internalvar (lookup_internalvar ("_"),
507 value_from_pointer (lookup_pointer_type (builtin_type_void
),
511 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
512 after LEADIN. Print nothing if no symbolic name is found nearby.
513 Optionally also print source file and line number, if available.
514 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
515 or to interpret it as a possible C++ name and convert it back to source
516 form. However note that DO_DEMANGLE can be overridden by the specific
517 settings of the demangle and asm_demangle variables. */
520 print_address_symbolic (CORE_ADDR addr
, struct ui_file
*stream
,
521 int do_demangle
, char *leadin
)
524 char *filename
= NULL
;
529 /* Throw away both name and filename. */
530 struct cleanup
*cleanup_chain
= make_cleanup (free_current_contents
, &name
);
531 make_cleanup (free_current_contents
, &filename
);
533 if (build_address_symbolic (addr
, do_demangle
, &name
, &offset
,
534 &filename
, &line
, &unmapped
))
536 do_cleanups (cleanup_chain
);
540 fputs_filtered (leadin
, stream
);
542 fputs_filtered ("<*", stream
);
544 fputs_filtered ("<", stream
);
545 fputs_filtered (name
, stream
);
547 fprintf_filtered (stream
, "+%u", (unsigned int) offset
);
549 /* Append source filename and line number if desired. Give specific
550 line # of this addr, if we have it; else line # of the nearest symbol. */
551 if (print_symbol_filename
&& filename
!= NULL
)
554 fprintf_filtered (stream
, " at %s:%d", filename
, line
);
556 fprintf_filtered (stream
, " in %s", filename
);
559 fputs_filtered ("*>", stream
);
561 fputs_filtered (">", stream
);
563 do_cleanups (cleanup_chain
);
566 /* Given an address ADDR return all the elements needed to print the
567 address in a symbolic form. NAME can be mangled or not depending
568 on DO_DEMANGLE (and also on the asm_demangle global variable,
569 manipulated via ''set print asm-demangle''). Return 0 in case of
570 success, when all the info in the OUT paramters is valid. Return 1
573 build_address_symbolic (CORE_ADDR addr
, /* IN */
574 int do_demangle
, /* IN */
575 char **name
, /* OUT */
576 int *offset
, /* OUT */
577 char **filename
, /* OUT */
579 int *unmapped
) /* OUT */
581 struct minimal_symbol
*msymbol
;
582 struct symbol
*symbol
;
583 CORE_ADDR name_location
= 0;
584 asection
*section
= 0;
585 char *name_temp
= "";
587 /* Let's say it is unmapped. */
590 /* Determine if the address is in an overlay, and whether it is
592 if (overlay_debugging
)
594 section
= find_pc_overlay (addr
);
595 if (pc_in_unmapped_range (addr
, section
))
598 addr
= overlay_mapped_address (addr
, section
);
602 /* First try to find the address in the symbol table, then
603 in the minsyms. Take the closest one. */
605 /* This is defective in the sense that it only finds text symbols. So
606 really this is kind of pointless--we should make sure that the
607 minimal symbols have everything we need (by changing that we could
608 save some memory, but for many debug format--ELF/DWARF or
609 anything/stabs--it would be inconvenient to eliminate those minimal
611 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
612 symbol
= find_pc_sect_function (addr
, section
);
616 name_location
= BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
));
617 if (do_demangle
|| asm_demangle
)
618 name_temp
= SYMBOL_PRINT_NAME (symbol
);
620 name_temp
= DEPRECATED_SYMBOL_NAME (symbol
);
625 if (SYMBOL_VALUE_ADDRESS (msymbol
) > name_location
|| symbol
== NULL
)
627 /* The msymbol is closer to the address than the symbol;
628 use the msymbol instead. */
630 name_location
= SYMBOL_VALUE_ADDRESS (msymbol
);
631 if (do_demangle
|| asm_demangle
)
632 name_temp
= SYMBOL_PRINT_NAME (msymbol
);
634 name_temp
= DEPRECATED_SYMBOL_NAME (msymbol
);
637 if (symbol
== NULL
&& msymbol
== NULL
)
640 /* If the nearest symbol is too far away, don't print anything symbolic. */
642 /* For when CORE_ADDR is larger than unsigned int, we do math in
643 CORE_ADDR. But when we detect unsigned wraparound in the
644 CORE_ADDR math, we ignore this test and print the offset,
645 because addr+max_symbolic_offset has wrapped through the end
646 of the address space back to the beginning, giving bogus comparison. */
647 if (addr
> name_location
+ max_symbolic_offset
648 && name_location
+ max_symbolic_offset
> name_location
)
651 *offset
= addr
- name_location
;
653 *name
= xstrdup (name_temp
);
655 if (print_symbol_filename
)
657 struct symtab_and_line sal
;
659 sal
= find_pc_sect_line (addr
, section
, 0);
663 *filename
= xstrdup (sal
.symtab
->filename
);
670 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
673 deprecated_print_address_numeric (CORE_ADDR addr
, int use_local
,
674 struct ui_file
*stream
)
677 fputs_filtered (paddress (addr
), stream
);
680 int addr_bit
= gdbarch_addr_bit (current_gdbarch
);
682 if (addr_bit
< (sizeof (CORE_ADDR
) * HOST_CHAR_BIT
))
683 addr
&= ((CORE_ADDR
) 1 << addr_bit
) - 1;
684 print_longest (stream
, 'x', 0, (ULONGEST
) addr
);
688 /* Print address ADDR symbolically on STREAM.
689 First print it as a number. Then perhaps print
690 <SYMBOL + OFFSET> after the number. */
693 print_address (CORE_ADDR addr
, struct ui_file
*stream
)
695 fputs_filtered (paddress (addr
), stream
);
696 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
699 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
700 controls whether to print the symbolic name "raw" or demangled.
701 Global setting "addressprint" controls whether to print hex address
705 print_address_demangle (CORE_ADDR addr
, struct ui_file
*stream
,
710 fprintf_filtered (stream
, "0");
712 else if (addressprint
)
714 fputs_filtered (paddress (addr
), stream
);
715 print_address_symbolic (addr
, stream
, do_demangle
, " ");
719 print_address_symbolic (addr
, stream
, do_demangle
, "");
724 /* These are the types that $__ will get after an examine command of one
727 static struct type
*examine_i_type
;
729 static struct type
*examine_b_type
;
730 static struct type
*examine_h_type
;
731 static struct type
*examine_w_type
;
732 static struct type
*examine_g_type
;
734 /* Examine data at address ADDR in format FMT.
735 Fetch it from memory and print on gdb_stdout. */
738 do_examine (struct format_data fmt
, CORE_ADDR addr
)
743 struct type
*val_type
= NULL
;
752 /* String or instruction format implies fetch single bytes
753 regardless of the specified size. */
754 if (format
== 's' || format
== 'i')
758 val_type
= examine_i_type
;
759 else if (size
== 'b')
760 val_type
= examine_b_type
;
761 else if (size
== 'h')
762 val_type
= examine_h_type
;
763 else if (size
== 'w')
764 val_type
= examine_w_type
;
765 else if (size
== 'g')
766 val_type
= examine_g_type
;
773 if (format
== 's' || format
== 'i')
776 /* Print as many objects as specified in COUNT, at most maxelts per line,
777 with the address of the next one at the start of each line. */
782 print_address (next_address
, gdb_stdout
);
783 printf_filtered (":");
788 printf_filtered ("\t");
789 /* Note that print_formatted sets next_address for the next
791 last_examine_address
= next_address
;
793 if (last_examine_value
)
794 value_free (last_examine_value
);
796 /* The value to be displayed is not fetched greedily.
797 Instead, to avoid the possibility of a fetched value not
798 being used, its retrieval is delayed until the print code
799 uses it. When examining an instruction stream, the
800 disassembler will perform its own memory fetch using just
801 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
802 the disassembler be modified so that LAST_EXAMINE_VALUE
803 is left with the byte sequence from the last complete
804 instruction fetched from memory? */
805 last_examine_value
= value_at_lazy (val_type
, next_address
);
807 if (last_examine_value
)
808 release_value (last_examine_value
);
810 print_formatted (last_examine_value
, format
, size
, gdb_stdout
);
812 /* Display any branch delay slots following the final insn. */
813 if (format
== 'i' && count
== 1)
814 count
+= branch_delay_insns
;
816 printf_filtered ("\n");
817 gdb_flush (gdb_stdout
);
822 validate_format (struct format_data fmt
, char *cmdname
)
825 error (_("Size letters are meaningless in \"%s\" command."), cmdname
);
827 error (_("Item count other than 1 is meaningless in \"%s\" command."),
829 if (fmt
.format
== 'i')
830 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
831 fmt
.format
, cmdname
);
834 /* Evaluate string EXP as an expression in the current language and
835 print the resulting value. EXP may contain a format specifier as the
836 first argument ("/x myvar" for example, to print myvar in hex). */
839 print_command_1 (char *exp
, int inspect
, int voidprint
)
841 struct expression
*expr
;
842 struct cleanup
*old_chain
= 0;
845 struct format_data fmt
;
848 /* Pass inspect flag to the rest of the print routines in a global
850 inspect_it
= inspect
;
852 if (exp
&& *exp
== '/')
855 fmt
= decode_format (&exp
, last_format
, 0);
856 validate_format (fmt
, "print");
857 last_format
= format
= fmt
.format
;
869 expr
= parse_expression (exp
);
870 old_chain
= make_cleanup (free_current_contents
, &expr
);
872 val
= evaluate_expression (expr
);
875 val
= access_value_history (0);
877 if (voidprint
|| (val
&& value_type (val
) &&
878 TYPE_CODE (value_type (val
)) != TYPE_CODE_VOID
))
880 int histindex
= record_latest_value (val
);
883 annotate_value_history_begin (histindex
, value_type (val
));
885 annotate_value_begin (value_type (val
));
888 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"",
890 else if (histindex
>= 0)
891 printf_filtered ("$%d = ", histindex
);
894 annotate_value_history_value ();
896 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
897 printf_filtered ("\n");
900 annotate_value_history_end ();
902 annotate_value_end ();
905 printf_unfiltered ("\") )\030");
909 do_cleanups (old_chain
);
910 inspect_it
= 0; /* Reset print routines to normal. */
914 print_command (char *exp
, int from_tty
)
916 print_command_1 (exp
, 0, 1);
919 /* Same as print, except in epoch, it gets its own window. */
921 inspect_command (char *exp
, int from_tty
)
923 extern int epoch_interface
;
925 print_command_1 (exp
, epoch_interface
, 1);
928 /* Same as print, except it doesn't print void results. */
930 call_command (char *exp
, int from_tty
)
932 print_command_1 (exp
, 0, 0);
936 output_command (char *exp
, int from_tty
)
938 struct expression
*expr
;
939 struct cleanup
*old_chain
;
942 struct format_data fmt
;
946 if (exp
&& *exp
== '/')
949 fmt
= decode_format (&exp
, 0, 0);
950 validate_format (fmt
, "output");
954 expr
= parse_expression (exp
);
955 old_chain
= make_cleanup (free_current_contents
, &expr
);
957 val
= evaluate_expression (expr
);
959 annotate_value_begin (value_type (val
));
961 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
963 annotate_value_end ();
966 gdb_flush (gdb_stdout
);
968 do_cleanups (old_chain
);
972 set_command (char *exp
, int from_tty
)
974 struct expression
*expr
= parse_expression (exp
);
975 struct cleanup
*old_chain
=
976 make_cleanup (free_current_contents
, &expr
);
977 evaluate_expression (expr
);
978 do_cleanups (old_chain
);
982 sym_info (char *arg
, int from_tty
)
984 struct minimal_symbol
*msymbol
;
985 struct objfile
*objfile
;
986 struct obj_section
*osect
;
988 CORE_ADDR addr
, sect_addr
;
993 error_no_arg (_("address"));
995 addr
= parse_and_eval_address (arg
);
996 ALL_OBJSECTIONS (objfile
, osect
)
998 /* Only process each object file once, even if there's a separate
1000 if (objfile
->separate_debug_objfile_backlink
)
1003 sect
= osect
->the_bfd_section
;
1004 sect_addr
= overlay_mapped_address (addr
, sect
);
1006 if (osect
->addr
<= sect_addr
&& sect_addr
< osect
->endaddr
&&
1007 (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr
, sect
)))
1010 offset
= sect_addr
- SYMBOL_VALUE_ADDRESS (msymbol
);
1012 printf_filtered ("%s + %u in ",
1013 SYMBOL_PRINT_NAME (msymbol
), offset
);
1015 printf_filtered ("%s in ",
1016 SYMBOL_PRINT_NAME (msymbol
));
1017 if (pc_in_unmapped_range (addr
, sect
))
1018 printf_filtered (_("load address range of "));
1019 if (section_is_overlay (sect
))
1020 printf_filtered (_("%s overlay "),
1021 section_is_mapped (sect
) ? "mapped" : "unmapped");
1022 printf_filtered (_("section %s"), sect
->name
);
1023 printf_filtered ("\n");
1027 printf_filtered (_("No symbol matches %s.\n"), arg
);
1031 address_info (char *exp
, int from_tty
)
1034 struct minimal_symbol
*msymbol
;
1038 CORE_ADDR load_addr
;
1039 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
1040 if exp is a field of `this'. */
1043 error (_("Argument required."));
1045 sym
= lookup_symbol (exp
, get_selected_block (0), VAR_DOMAIN
,
1046 &is_a_field_of_this
, (struct symtab
**) NULL
);
1049 if (is_a_field_of_this
)
1051 printf_filtered ("Symbol \"");
1052 fprintf_symbol_filtered (gdb_stdout
, exp
,
1053 current_language
->la_language
, DMGL_ANSI
);
1054 printf_filtered ("\" is a field of the local class variable ");
1055 if (current_language
->la_language
== language_objc
)
1056 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1058 printf_filtered ("`this'\n");
1062 msymbol
= lookup_minimal_symbol (exp
, NULL
, NULL
);
1064 if (msymbol
!= NULL
)
1066 load_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
1068 printf_filtered ("Symbol \"");
1069 fprintf_symbol_filtered (gdb_stdout
, exp
,
1070 current_language
->la_language
, DMGL_ANSI
);
1071 printf_filtered ("\" is at ");
1072 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1073 printf_filtered (" in a file compiled without debugging");
1074 section
= SYMBOL_BFD_SECTION (msymbol
);
1075 if (section_is_overlay (section
))
1077 load_addr
= overlay_unmapped_address (load_addr
, section
);
1078 printf_filtered (",\n -- loaded at ");
1079 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1080 printf_filtered (" in overlay section %s", section
->name
);
1082 printf_filtered (".\n");
1085 error (_("No symbol \"%s\" in current context."), exp
);
1089 printf_filtered ("Symbol \"");
1090 fprintf_symbol_filtered (gdb_stdout
, DEPRECATED_SYMBOL_NAME (sym
),
1091 current_language
->la_language
, DMGL_ANSI
);
1092 printf_filtered ("\" is ");
1093 val
= SYMBOL_VALUE (sym
);
1094 basereg
= SYMBOL_BASEREG (sym
);
1095 section
= SYMBOL_BFD_SECTION (sym
);
1097 switch (SYMBOL_CLASS (sym
))
1100 case LOC_CONST_BYTES
:
1101 printf_filtered ("constant");
1105 printf_filtered ("a label at address ");
1106 fputs_filtered (paddress (load_addr
= SYMBOL_VALUE_ADDRESS (sym
)),
1108 if (section_is_overlay (section
))
1110 load_addr
= overlay_unmapped_address (load_addr
, section
);
1111 printf_filtered (",\n -- loaded at ");
1112 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1113 printf_filtered (" in overlay section %s", section
->name
);
1118 case LOC_COMPUTED_ARG
:
1119 /* FIXME: cagney/2004-01-26: It should be possible to
1120 unconditionally call the SYMBOL_OPS method when available.
1121 Unfortunately DWARF 2 stores the frame-base (instead of the
1122 function) location in a function's symbol. Oops! For the
1123 moment enable this when/where applicable. */
1124 SYMBOL_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1128 printf_filtered (_("a variable in register %s"),
1129 gdbarch_register_name (current_gdbarch
, val
));
1133 printf_filtered (_("static storage at address "));
1134 fputs_filtered (paddress (load_addr
= SYMBOL_VALUE_ADDRESS (sym
)),
1136 if (section_is_overlay (section
))
1138 load_addr
= overlay_unmapped_address (load_addr
, section
);
1139 printf_filtered (_(",\n -- loaded at "));
1140 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1141 printf_filtered (_(" in overlay section %s"), section
->name
);
1146 printf_filtered (_("external global (indirect addressing), at address *("));
1147 fputs_filtered (paddress (load_addr
= SYMBOL_VALUE_ADDRESS (sym
)),
1149 printf_filtered (")");
1150 if (section_is_overlay (section
))
1152 load_addr
= overlay_unmapped_address (load_addr
, section
);
1153 printf_filtered (_(",\n -- loaded at "));
1154 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1155 printf_filtered (_(" in overlay section %s"), section
->name
);
1160 printf_filtered (_("an argument in register %s"),
1161 gdbarch_register_name (current_gdbarch
, val
));
1164 case LOC_REGPARM_ADDR
:
1165 printf_filtered (_("address of an argument in register %s"),
1166 gdbarch_register_name (current_gdbarch
, val
));
1170 printf_filtered (_("an argument at offset %ld"), val
);
1174 printf_filtered (_("an argument at frame offset %ld"), val
);
1178 printf_filtered (_("a local variable at frame offset %ld"), val
);
1182 printf_filtered (_("a reference argument at offset %ld"), val
);
1186 printf_filtered (_("a variable at offset %ld from register %s"),
1187 val
, gdbarch_register_name (current_gdbarch
, basereg
));
1190 case LOC_BASEREG_ARG
:
1191 printf_filtered (_("an argument at offset %ld from register %s"),
1192 val
, gdbarch_register_name (current_gdbarch
, basereg
));
1196 printf_filtered (_("a typedef"));
1200 printf_filtered (_("a function at address "));
1201 load_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1202 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1203 if (section_is_overlay (section
))
1205 load_addr
= overlay_unmapped_address (load_addr
, section
);
1206 printf_filtered (_(",\n -- loaded at "));
1207 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1208 printf_filtered (_(" in overlay section %s"), section
->name
);
1212 case LOC_UNRESOLVED
:
1214 struct minimal_symbol
*msym
;
1216 msym
= lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym
), NULL
, NULL
);
1218 printf_filtered ("unresolved");
1221 section
= SYMBOL_BFD_SECTION (msym
);
1222 printf_filtered (_("static storage at address "));
1223 load_addr
= SYMBOL_VALUE_ADDRESS (msym
);
1224 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1225 if (section_is_overlay (section
))
1227 load_addr
= overlay_unmapped_address (load_addr
, section
);
1228 printf_filtered (_(",\n -- loaded at "));
1229 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1230 printf_filtered (_(" in overlay section %s"), section
->name
);
1236 case LOC_HP_THREAD_LOCAL_STATIC
:
1237 printf_filtered (_("\
1238 a thread-local variable at offset %ld from the thread base register %s"),
1239 val
, gdbarch_register_name (current_gdbarch
, basereg
));
1242 case LOC_OPTIMIZED_OUT
:
1243 printf_filtered (_("optimized out"));
1247 printf_filtered (_("of unknown (botched) type"));
1250 printf_filtered (".\n");
1255 x_command (char *exp
, int from_tty
)
1257 struct expression
*expr
;
1258 struct format_data fmt
;
1259 struct cleanup
*old_chain
;
1262 fmt
.format
= last_format
;
1263 fmt
.size
= last_size
;
1266 if (exp
&& *exp
== '/')
1269 fmt
= decode_format (&exp
, last_format
, last_size
);
1272 /* If we have an expression, evaluate it and use it as the address. */
1274 if (exp
!= 0 && *exp
!= 0)
1276 expr
= parse_expression (exp
);
1277 /* Cause expression not to be there any more if this command is
1278 repeated with Newline. But don't clobber a user-defined
1279 command's definition. */
1282 old_chain
= make_cleanup (free_current_contents
, &expr
);
1283 val
= evaluate_expression (expr
);
1284 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_REF
)
1285 val
= value_ind (val
);
1286 /* In rvalue contexts, such as this, functions are coerced into
1287 pointers to functions. This makes "x/i main" work. */
1288 if (/* last_format == 'i' && */
1289 TYPE_CODE (value_type (val
)) == TYPE_CODE_FUNC
1290 && VALUE_LVAL (val
) == lval_memory
)
1291 next_address
= VALUE_ADDRESS (val
);
1293 next_address
= value_as_address (val
);
1294 do_cleanups (old_chain
);
1297 do_examine (fmt
, next_address
);
1299 /* If the examine succeeds, we remember its size and format for next
1301 last_size
= fmt
.size
;
1302 last_format
= fmt
.format
;
1304 /* Set a couple of internal variables if appropriate. */
1305 if (last_examine_value
)
1307 /* Make last address examined available to the user as $_. Use
1308 the correct pointer type. */
1309 struct type
*pointer_type
1310 = lookup_pointer_type (value_type (last_examine_value
));
1311 set_internalvar (lookup_internalvar ("_"),
1312 value_from_pointer (pointer_type
,
1313 last_examine_address
));
1315 /* Make contents of last address examined available to the user
1316 as $__. If the last value has not been fetched from memory
1317 then don't fetch it now; instead mark it by voiding the $__
1319 if (value_lazy (last_examine_value
))
1320 set_internalvar (lookup_internalvar ("__"),
1321 allocate_value (builtin_type_void
));
1323 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1328 /* Add an expression to the auto-display chain.
1329 Specify the expression. */
1332 display_command (char *exp
, int from_tty
)
1334 struct format_data fmt
;
1335 struct expression
*expr
;
1336 struct display
*new;
1340 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1342 if (tui_active
&& exp
!= NULL
&& *exp
== '$')
1343 display_it
= (tui_set_layout_for_display_command (exp
) == TUI_FAILURE
);
1357 fmt
= decode_format (&exp
, 0, 0);
1358 if (fmt
.size
&& fmt
.format
== 0)
1360 if (fmt
.format
== 'i' || fmt
.format
== 's')
1370 innermost_block
= 0;
1371 expr
= parse_expression (exp
);
1373 new = (struct display
*) xmalloc (sizeof (struct display
));
1376 new->block
= innermost_block
;
1377 new->next
= display_chain
;
1378 new->number
= ++display_number
;
1381 display_chain
= new;
1383 if (from_tty
&& target_has_execution
)
1384 do_one_display (new);
1391 free_display (struct display
*d
)
1397 /* Clear out the display_chain. Done when new symtabs are loaded,
1398 since this invalidates the types stored in many expressions. */
1401 clear_displays (void)
1405 while ((d
= display_chain
) != NULL
)
1408 display_chain
= d
->next
;
1413 /* Delete the auto-display number NUM. */
1416 delete_display (int num
)
1418 struct display
*d1
, *d
;
1421 error (_("No display number %d."), num
);
1423 if (display_chain
->number
== num
)
1426 display_chain
= d1
->next
;
1430 for (d
= display_chain
;; d
= d
->next
)
1433 error (_("No display number %d."), num
);
1434 if (d
->next
->number
== num
)
1444 /* Delete some values from the auto-display chain.
1445 Specify the element numbers. */
1448 undisplay_command (char *args
, int from_tty
)
1456 if (query ("Delete all auto-display expressions? "))
1465 while (*p1
>= '0' && *p1
<= '9')
1467 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1468 error (_("Arguments must be display numbers."));
1472 delete_display (num
);
1475 while (*p
== ' ' || *p
== '\t')
1481 /* Display a single auto-display.
1482 Do nothing if the display cannot be printed in the current context,
1483 or if the display is disabled. */
1486 do_one_display (struct display
*d
)
1488 int within_current_scope
;
1490 if (d
->enabled_p
== 0)
1494 within_current_scope
= contained_in (get_selected_block (0), d
->block
);
1496 within_current_scope
= 1;
1497 if (!within_current_scope
)
1500 current_display_number
= d
->number
;
1502 annotate_display_begin ();
1503 printf_filtered ("%d", d
->number
);
1504 annotate_display_number_end ();
1505 printf_filtered (": ");
1511 annotate_display_format ();
1513 printf_filtered ("x/");
1514 if (d
->format
.count
!= 1)
1515 printf_filtered ("%d", d
->format
.count
);
1516 printf_filtered ("%c", d
->format
.format
);
1517 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1518 printf_filtered ("%c", d
->format
.size
);
1519 printf_filtered (" ");
1521 annotate_display_expression ();
1523 print_expression (d
->exp
, gdb_stdout
);
1524 annotate_display_expression_end ();
1526 if (d
->format
.count
!= 1 || d
->format
.format
== 'i')
1527 printf_filtered ("\n");
1529 printf_filtered (" ");
1531 val
= evaluate_expression (d
->exp
);
1532 addr
= value_as_address (val
);
1533 if (d
->format
.format
== 'i')
1534 addr
= gdbarch_addr_bits_remove (current_gdbarch
, addr
);
1536 annotate_display_value ();
1538 do_examine (d
->format
, addr
);
1542 annotate_display_format ();
1544 if (d
->format
.format
)
1545 printf_filtered ("/%c ", d
->format
.format
);
1547 annotate_display_expression ();
1549 print_expression (d
->exp
, gdb_stdout
);
1550 annotate_display_expression_end ();
1552 printf_filtered (" = ");
1554 annotate_display_expression ();
1556 print_formatted (evaluate_expression (d
->exp
),
1557 d
->format
.format
, d
->format
.size
, gdb_stdout
);
1558 printf_filtered ("\n");
1561 annotate_display_end ();
1563 gdb_flush (gdb_stdout
);
1564 current_display_number
= -1;
1567 /* Display all of the values on the auto-display chain which can be
1568 evaluated in the current scope. */
1575 for (d
= display_chain
; d
; d
= d
->next
)
1579 /* Delete the auto-display which we were in the process of displaying.
1580 This is done when there is an error or a signal. */
1583 disable_display (int num
)
1587 for (d
= display_chain
; d
; d
= d
->next
)
1588 if (d
->number
== num
)
1593 printf_unfiltered (_("No display number %d.\n"), num
);
1597 disable_current_display (void)
1599 if (current_display_number
>= 0)
1601 disable_display (current_display_number
);
1602 fprintf_unfiltered (gdb_stderr
, _("\
1603 Disabling display %d to avoid infinite recursion.\n"),
1604 current_display_number
);
1606 current_display_number
= -1;
1610 display_info (char *ignore
, int from_tty
)
1615 printf_unfiltered (_("There are no auto-display expressions now.\n"));
1617 printf_filtered (_("Auto-display expressions now in effect:\n\
1618 Num Enb Expression\n"));
1620 for (d
= display_chain
; d
; d
= d
->next
)
1622 printf_filtered ("%d: %c ", d
->number
, "ny"[(int) d
->enabled_p
]);
1624 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1626 else if (d
->format
.format
)
1627 printf_filtered ("/%c ", d
->format
.format
);
1628 print_expression (d
->exp
, gdb_stdout
);
1629 if (d
->block
&& !contained_in (get_selected_block (0), d
->block
))
1630 printf_filtered (_(" (cannot be evaluated in the current context)"));
1631 printf_filtered ("\n");
1632 gdb_flush (gdb_stdout
);
1637 enable_display (char *args
, int from_tty
)
1646 for (d
= display_chain
; d
; d
= d
->next
)
1653 while (*p1
>= '0' && *p1
<= '9')
1655 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1656 error (_("Arguments must be display numbers."));
1660 for (d
= display_chain
; d
; d
= d
->next
)
1661 if (d
->number
== num
)
1666 printf_unfiltered (_("No display number %d.\n"), num
);
1669 while (*p
== ' ' || *p
== '\t')
1675 disable_display_command (char *args
, int from_tty
)
1683 for (d
= display_chain
; d
; d
= d
->next
)
1690 while (*p1
>= '0' && *p1
<= '9')
1692 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1693 error (_("Arguments must be display numbers."));
1695 disable_display (atoi (p
));
1698 while (*p
== ' ' || *p
== '\t')
1704 /* Print the value in stack frame FRAME of a variable specified by a
1708 print_variable_value (struct symbol
*var
, struct frame_info
*frame
,
1709 struct ui_file
*stream
)
1711 struct value
*val
= read_var_value (var
, frame
);
1713 value_print (val
, stream
, 0, Val_pretty_default
);
1717 printf_command (char *arg
, int from_tty
)
1721 char *string
= NULL
;
1722 struct value
**val_args
;
1724 char *current_substring
;
1726 int allocated_args
= 20;
1727 struct cleanup
*old_cleanups
;
1729 val_args
= xmalloc (allocated_args
* sizeof (struct value
*));
1730 old_cleanups
= make_cleanup (free_current_contents
, &val_args
);
1733 error_no_arg (_("format-control string and values to print"));
1735 /* Skip white space before format string */
1736 while (*s
== ' ' || *s
== '\t')
1739 /* A format string should follow, enveloped in double quotes. */
1741 error (_("Bad format string, missing '\"'."));
1743 /* Parse the format-control string and copy it into the string STRING,
1744 processing some kinds of escape sequence. */
1746 f
= string
= (char *) alloca (strlen (s
) + 1);
1754 error (_("Bad format string, non-terminated '\"'."));
1787 /* ??? TODO: handle other escape sequences */
1788 error (_("Unrecognized escape character \\%c in format string."),
1798 /* Skip over " and following space and comma. */
1801 while (*s
== ' ' || *s
== '\t')
1804 if (*s
!= ',' && *s
!= 0)
1805 error (_("Invalid argument syntax"));
1809 while (*s
== ' ' || *s
== '\t')
1812 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1813 substrings
= alloca (strlen (string
) * 2);
1814 current_substring
= substrings
;
1817 /* Now scan the string for %-specs and see what kinds of args they want.
1818 argclass[I] classifies the %-specs so we can give printf_filtered
1819 something of the right size. */
1823 int_arg
, long_arg
, long_long_arg
, ptr_arg
, string_arg
,
1824 double_arg
, long_double_arg
, decfloat_arg
1826 enum argclass
*argclass
;
1827 enum argclass this_argclass
;
1832 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1839 int seen_hash
= 0, seen_zero
= 0, lcount
= 0, seen_prec
= 0;
1840 int seen_space
= 0, seen_plus
= 0;
1841 int seen_big_l
= 0, seen_h
= 0, seen_big_h
= 0;
1842 int seen_big_d
= 0, seen_double_big_d
= 0;
1845 /* Check the validity of the format specifier, and work
1846 out what argument it expects. We only accept C89
1847 format strings, with the exception of long long (which
1848 we autoconf for). */
1850 /* Skip over "%%". */
1857 /* The first part of a format specifier is a set of flag
1859 while (strchr ("0-+ #", *f
))
1872 /* The next part of a format specifier is a width. */
1873 while (strchr ("0123456789", *f
))
1876 /* The next part of a format specifier is a precision. */
1881 while (strchr ("0123456789", *f
))
1885 /* The next part of a format specifier is a length modifier. */
1906 /* Decimal32 modifier. */
1912 /* Decimal64 and Decimal128 modifiers. */
1917 /* Check for a Decimal128. */
1921 seen_double_big_d
= 1;
1937 if (seen_space
|| seen_plus
)
1944 this_argclass
= int_arg
;
1945 else if (lcount
== 1)
1946 this_argclass
= long_arg
;
1948 this_argclass
= long_long_arg
;
1955 this_argclass
= int_arg
;
1956 if (lcount
|| seen_h
|| seen_big_l
)
1958 if (seen_prec
|| seen_zero
|| seen_space
|| seen_plus
)
1963 this_argclass
= ptr_arg
;
1964 if (lcount
|| seen_h
|| seen_big_l
)
1966 if (seen_prec
|| seen_zero
|| seen_space
|| seen_plus
)
1971 this_argclass
= string_arg
;
1972 if (lcount
|| seen_h
|| seen_big_l
)
1974 if (seen_zero
|| seen_space
|| seen_plus
)
1983 if (seen_big_h
|| seen_big_d
|| seen_double_big_d
)
1984 this_argclass
= decfloat_arg
;
1985 else if (seen_big_l
)
1986 this_argclass
= long_double_arg
;
1988 this_argclass
= double_arg
;
1990 if (lcount
|| seen_h
)
1995 error (_("`*' not supported for precision or width in printf"));
1998 error (_("Format specifier `n' not supported in printf"));
2001 error (_("Incomplete format specifier at end of format string"));
2004 error (_("Unrecognized format specifier '%c' in printf"), *f
);
2008 error (_("Inappropriate modifiers to format specifier '%c' in printf"),
2012 strncpy (current_substring
, last_arg
, f
- last_arg
);
2013 current_substring
+= f
- last_arg
;
2014 *current_substring
++ = '\0';
2016 argclass
[nargs_wanted
++] = this_argclass
;
2019 /* Now, parse all arguments and evaluate them.
2020 Store the VALUEs in VAL_ARGS. */
2025 if (nargs
== allocated_args
)
2026 val_args
= (struct value
**) xrealloc ((char *) val_args
,
2027 (allocated_args
*= 2)
2028 * sizeof (struct value
*));
2030 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
2032 /* If format string wants a float, unchecked-convert the value to
2033 floating point of the same size */
2035 if (argclass
[nargs
] == double_arg
)
2037 struct type
*type
= value_type (val_args
[nargs
]);
2038 if (TYPE_LENGTH (type
) == sizeof (float))
2039 deprecated_set_value_type (val_args
[nargs
], builtin_type_float
);
2040 if (TYPE_LENGTH (type
) == sizeof (double))
2041 deprecated_set_value_type (val_args
[nargs
], builtin_type_double
);
2049 if (nargs
!= nargs_wanted
)
2050 error (_("Wrong number of arguments for specified format-string"));
2052 /* Now actually print them. */
2053 current_substring
= substrings
;
2054 for (i
= 0; i
< nargs
; i
++)
2056 switch (argclass
[i
])
2063 tem
= value_as_address (val_args
[i
]);
2065 /* This is a %s argument. Find the length of the string. */
2070 read_memory (tem
+ j
, &c
, 1);
2075 /* Copy the string contents into a string inside GDB. */
2076 str
= (gdb_byte
*) alloca (j
+ 1);
2078 read_memory (tem
, str
, j
);
2081 printf_filtered (current_substring
, (char *) str
);
2086 double val
= value_as_double (val_args
[i
]);
2087 printf_filtered (current_substring
, val
);
2090 case long_double_arg
:
2091 #ifdef HAVE_LONG_DOUBLE
2093 long double val
= value_as_double (val_args
[i
]);
2094 printf_filtered (current_substring
, val
);
2098 error (_("long double not supported in printf"));
2101 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2103 long long val
= value_as_long (val_args
[i
]);
2104 printf_filtered (current_substring
, val
);
2108 error (_("long long not supported in printf"));
2112 int val
= value_as_long (val_args
[i
]);
2113 printf_filtered (current_substring
, val
);
2118 long val
= value_as_long (val_args
[i
]);
2119 printf_filtered (current_substring
, val
);
2123 /* Handles decimal floating values. */
2126 const gdb_byte
*param_ptr
= value_contents (val_args
[i
]);
2127 #if defined (PRINTF_HAS_DECFLOAT)
2128 /* If we have native support for Decimal floating
2129 printing, handle it here. */
2130 printf_filtered (current_substring
, param_ptr
);
2133 /* As a workaround until vasprintf has native support for DFP
2134 we convert the DFP values to string and print them using
2135 the %s format specifier. */
2138 int nnull_chars
= 0;
2140 /* Parameter data. */
2141 struct type
*param_type
= value_type (val_args
[i
]);
2142 unsigned int param_len
= TYPE_LENGTH (param_type
);
2144 /* DFP output data. */
2145 struct value
*dfp_value
= NULL
;
2149 struct type
*dfp_type
= NULL
;
2150 char decstr
[MAX_DECIMAL_STRING
];
2152 /* Points to the end of the string so that we can go back
2153 and check for DFP length modifiers. */
2154 eos
= current_substring
+ strlen (current_substring
);
2156 /* Look for the float/double format specifier. */
2157 while (*eos
!= 'f' && *eos
!= 'e' && *eos
!= 'E'
2158 && *eos
!= 'g' && *eos
!= 'G')
2163 /* Search for the '%' char and extract the size and type of
2164 the output decimal value based on its modifiers
2165 (%Hf, %Df, %DDf). */
2166 while (*--sos
!= '%')
2171 dfp_type
= builtin_type (current_gdbarch
)->builtin_decfloat
;
2173 else if (*sos
== 'D' && *(sos
- 1) == 'D')
2176 dfp_type
= builtin_type (current_gdbarch
)->builtin_declong
;
2182 dfp_type
= builtin_type (current_gdbarch
)->builtin_decdouble
;
2186 /* Replace %Hf, %Df and %DDf with %s's. */
2189 /* Go through the whole format string and pull the correct
2190 number of chars back to compensate for the change in the
2191 format specifier. */
2192 while (nnull_chars
< nargs
- i
)
2200 /* Conversion between different DFP types. */
2201 if (TYPE_CODE (param_type
) == TYPE_CODE_DECFLOAT
)
2202 decimal_convert (param_ptr
, param_len
, dec
, dfp_len
);
2204 /* If this is a non-trivial conversion, just output 0.
2205 A correct converted value can be displayed by explicitly
2206 casting to a DFP type. */
2207 decimal_from_string (dec
, dfp_len
, "0");
2209 dfp_value
= value_from_decfloat (dfp_type
, dec
);
2211 dfp_ptr
= (gdb_byte
*) value_contents (dfp_value
);
2213 decimal_to_string (dfp_ptr
, dfp_len
, decstr
);
2215 /* Print the DFP value. */
2216 printf_filtered (current_substring
, decstr
);
2224 /* We avoid the host's %p because pointers are too
2225 likely to be the wrong size. The only interesting
2226 modifier for %p is a width; extract that, and then
2227 handle %p as glibc would: %#x or a literal "(nil)". */
2229 char *p
, *fmt
, *fmt_p
;
2230 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2231 long long val
= value_as_long (val_args
[i
]);
2233 long val
= value_as_long (val_args
[i
]);
2236 fmt
= alloca (strlen (current_substring
) + 5);
2238 /* Copy up to the leading %. */
2239 p
= current_substring
;
2243 int is_percent
= (*p
== '%');
2257 /* Copy any width. */
2258 while (*p
>= '0' && *p
< '9')
2261 gdb_assert (*p
== 'p' && *(p
+ 1) == '\0');
2264 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2270 printf_filtered (fmt
, val
);
2276 printf_filtered (fmt
, "(nil)");
2282 internal_error (__FILE__
, __LINE__
,
2283 _("failed internal consistency check"));
2285 /* Skip to the next substring. */
2286 current_substring
+= strlen (current_substring
) + 1;
2288 /* Print the portion of the format string after the last argument. */
2289 puts_filtered (last_arg
);
2291 do_cleanups (old_cleanups
);
2295 _initialize_printcmd (void)
2297 struct cmd_list_element
*c
;
2299 current_display_number
= -1;
2301 add_info ("address", address_info
,
2302 _("Describe where symbol SYM is stored."));
2304 add_info ("symbol", sym_info
, _("\
2305 Describe what symbol is at location ADDR.\n\
2306 Only for symbols with fixed locations (global or static scope)."));
2308 add_com ("x", class_vars
, x_command
, _("\
2309 Examine memory: x/FMT ADDRESS.\n\
2310 ADDRESS is an expression for the memory address to examine.\n\
2311 FMT is a repeat count followed by a format letter and a size letter.\n\
2312 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2313 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2314 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2315 The specified number of objects of the specified size are printed\n\
2316 according to the format.\n\n\
2317 Defaults for format and size letters are those previously used.\n\
2318 Default count is 1. Default address is following last thing printed\n\
2319 with this command or \"print\"."));
2322 add_com ("whereis", class_vars
, whereis_command
,
2323 _("Print line number and file of definition of variable."));
2326 add_info ("display", display_info
, _("\
2327 Expressions to display when program stops, with code numbers."));
2329 add_cmd ("undisplay", class_vars
, undisplay_command
, _("\
2330 Cancel some expressions to be displayed when program stops.\n\
2331 Arguments are the code numbers of the expressions to stop displaying.\n\
2332 No argument means cancel all automatic-display expressions.\n\
2333 \"delete display\" has the same effect as this command.\n\
2334 Do \"info display\" to see current list of code numbers."),
2337 add_com ("display", class_vars
, display_command
, _("\
2338 Print value of expression EXP each time the program stops.\n\
2339 /FMT may be used before EXP as in the \"print\" command.\n\
2340 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2341 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2342 and examining is done as in the \"x\" command.\n\n\
2343 With no argument, display all currently requested auto-display expressions.\n\
2344 Use \"undisplay\" to cancel display requests previously made."));
2346 add_cmd ("display", class_vars
, enable_display
, _("\
2347 Enable some expressions to be displayed when program stops.\n\
2348 Arguments are the code numbers of the expressions to resume displaying.\n\
2349 No argument means enable all automatic-display expressions.\n\
2350 Do \"info display\" to see current list of code numbers."), &enablelist
);
2352 add_cmd ("display", class_vars
, disable_display_command
, _("\
2353 Disable some expressions to be displayed when program stops.\n\
2354 Arguments are the code numbers of the expressions to stop displaying.\n\
2355 No argument means disable all automatic-display expressions.\n\
2356 Do \"info display\" to see current list of code numbers."), &disablelist
);
2358 add_cmd ("display", class_vars
, undisplay_command
, _("\
2359 Cancel some expressions to be displayed when program stops.\n\
2360 Arguments are the code numbers of the expressions to stop displaying.\n\
2361 No argument means cancel all automatic-display expressions.\n\
2362 Do \"info display\" to see current list of code numbers."), &deletelist
);
2364 add_com ("printf", class_vars
, printf_command
, _("\
2365 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2366 This is useful for formatted output in user-defined commands."));
2368 add_com ("output", class_vars
, output_command
, _("\
2369 Like \"print\" but don't put in value history and don't print newline.\n\
2370 This is useful in user-defined commands."));
2372 add_prefix_cmd ("set", class_vars
, set_command
, _("\
2373 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2374 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2375 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2376 with $), a register (a few standard names starting with $), or an actual\n\
2377 variable in the program being debugged. EXP is any valid expression.\n\
2378 Use \"set variable\" for variables with names identical to set subcommands.\n\
2380 With a subcommand, this command modifies parts of the gdb environment.\n\
2381 You can see these environment settings with the \"show\" command."),
2382 &setlist
, "set ", 1, &cmdlist
);
2384 add_com ("assign", class_vars
, set_command
, _("\
2385 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2386 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2387 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2388 with $), a register (a few standard names starting with $), or an actual\n\
2389 variable in the program being debugged. EXP is any valid expression.\n\
2390 Use \"set variable\" for variables with names identical to set subcommands.\n\
2391 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2392 You can see these environment settings with the \"show\" command."));
2394 /* "call" is the same as "set", but handy for dbx users to call fns. */
2395 c
= add_com ("call", class_vars
, call_command
, _("\
2396 Call a function in the program.\n\
2397 The argument is the function name and arguments, in the notation of the\n\
2398 current working language. The result is printed and saved in the value\n\
2399 history, if it is not void."));
2400 set_cmd_completer (c
, location_completer
);
2402 add_cmd ("variable", class_vars
, set_command
, _("\
2403 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2404 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2405 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2406 with $), a register (a few standard names starting with $), or an actual\n\
2407 variable in the program being debugged. EXP is any valid expression.\n\
2408 This may usually be abbreviated to simply \"set\"."),
2411 c
= add_com ("print", class_vars
, print_command
, _("\
2412 Print value of expression EXP.\n\
2413 Variables accessible are those of the lexical environment of the selected\n\
2414 stack frame, plus all those whose scope is global or an entire file.\n\
2416 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2417 $$NUM refers to NUM'th value back from the last one.\n\
2418 Names starting with $ refer to registers (with the values they would have\n\
2419 if the program were to return to the stack frame now selected, restoring\n\
2420 all registers saved by frames farther in) or else to debugger\n\
2421 \"convenience\" variables (any such name not a known register).\n\
2422 Use assignment expressions to give values to convenience variables.\n\
2424 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2425 @ is a binary operator for treating consecutive data objects\n\
2426 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2427 element is FOO, whose second element is stored in the space following\n\
2428 where FOO is stored, etc. FOO must be an expression whose value\n\
2429 resides in memory.\n\
2431 EXP may be preceded with /FMT, where FMT is a format letter\n\
2432 but no count or size letter (see \"x\" command)."));
2433 set_cmd_completer (c
, location_completer
);
2434 add_com_alias ("p", "print", class_vars
, 1);
2436 c
= add_com ("inspect", class_vars
, inspect_command
, _("\
2437 Same as \"print\" command, except that if you are running in the epoch\n\
2438 environment, the value is printed in its own window."));
2439 set_cmd_completer (c
, location_completer
);
2441 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class
,
2442 &max_symbolic_offset
, _("\
2443 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2444 Show the largest offset that will be printed in <symbol+1234> form."), NULL
,
2446 show_max_symbolic_offset
,
2447 &setprintlist
, &showprintlist
);
2448 add_setshow_boolean_cmd ("symbol-filename", no_class
,
2449 &print_symbol_filename
, _("\
2450 Set printing of source filename and line number with <symbol>."), _("\
2451 Show printing of source filename and line number with <symbol>."), NULL
,
2453 show_print_symbol_filename
,
2454 &setprintlist
, &showprintlist
);
2456 /* For examine/instruction a single byte quantity is specified as
2457 the data. This avoids problems with value_at_lazy() requiring a
2458 valid data type (and rejecting VOID). */
2459 examine_i_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_i_type", NULL
);
2461 examine_b_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_b_type", NULL
);
2462 examine_h_type
= init_type (TYPE_CODE_INT
, 2, 0, "examine_h_type", NULL
);
2463 examine_w_type
= init_type (TYPE_CODE_INT
, 4, 0, "examine_w_type", NULL
);
2464 examine_g_type
= init_type (TYPE_CODE_INT
, 8, 0, "examine_g_type", NULL
);