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"
48 #include "tui/tui.h" /* For tui_active et.al. */
51 #if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG)
52 # define USE_PRINTF_I64 1
53 # define PRINTF_HAS_LONG_LONG
55 # define USE_PRINTF_I64 0
58 extern int asm_demangle
; /* Whether to demangle syms in asm printouts */
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
;
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 OPTIONS.
251 Do not end with a newline.
252 SIZE is the letter for the size of datum being printed.
253 This is used to pad hex numbers so they line up. SIZE is 0
254 for print / output and set for examine. */
257 print_formatted (struct value
*val
, int size
,
258 const struct value_print_options
*options
,
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
;
269 switch (options
->format
)
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
,
279 /* We often wrap here if there are long symbolic names. */
281 next_address
= (VALUE_ADDRESS (val
)
282 + gdb_print_insn (VALUE_ADDRESS (val
), stream
,
283 &branch_delay_insns
));
288 if (options
->format
== 0 || options
->format
== 's'
289 || TYPE_CODE (type
) == TYPE_CODE_REF
290 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
291 || TYPE_CODE (type
) == TYPE_CODE_STRING
292 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
293 || TYPE_CODE (type
) == TYPE_CODE_UNION
294 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
295 value_print (val
, stream
, options
);
297 /* User specified format, so don't look to the the type to
298 tell us what to do. */
299 print_scalar_formatted (value_contents (val
), type
,
300 options
, size
, stream
);
303 /* Return builtin floating point type of same length as TYPE.
304 If no such type is found, return TYPE itself. */
306 float_type_from_length (struct gdbarch
*gdbarch
, struct type
*type
)
308 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
309 unsigned int len
= TYPE_LENGTH (type
);
311 if (len
== TYPE_LENGTH (builtin
->builtin_float
))
312 type
= builtin
->builtin_float
;
313 else if (len
== TYPE_LENGTH (builtin
->builtin_double
))
314 type
= builtin
->builtin_double
;
315 else if (len
== TYPE_LENGTH (builtin
->builtin_long_double
))
316 type
= builtin
->builtin_long_double
;
321 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
322 according to OPTIONS and SIZE on STREAM.
323 Formats s and i are not supported at this level.
325 This is how the elements of an array or structure are printed
329 print_scalar_formatted (const void *valaddr
, struct type
*type
,
330 const struct value_print_options
*options
,
331 int size
, struct ui_file
*stream
)
333 LONGEST val_long
= 0;
334 unsigned int len
= TYPE_LENGTH (type
);
335 enum bfd_endian byte_order
= gdbarch_byte_order (current_gdbarch
);
337 /* If we get here with a string format, try again without it. Go
338 all the way back to the language printers, which may call us
340 if (options
->format
== 's')
342 struct value_print_options opts
= *options
;
345 val_print (type
, valaddr
, 0, 0, stream
, 0, &opts
,
350 if (len
> sizeof(LONGEST
) &&
351 (TYPE_CODE (type
) == TYPE_CODE_INT
352 || TYPE_CODE (type
) == TYPE_CODE_ENUM
))
354 switch (options
->format
)
357 print_octal_chars (stream
, valaddr
, len
, byte_order
);
361 print_decimal_chars (stream
, valaddr
, len
, byte_order
);
364 print_binary_chars (stream
, valaddr
, len
, byte_order
);
367 print_hex_chars (stream
, valaddr
, len
, byte_order
);
370 print_char_chars (stream
, valaddr
, len
, byte_order
);
377 if (options
->format
!= 'f')
378 val_long
= unpack_long (type
, valaddr
);
380 /* If the value is a pointer, and pointers and addresses are not the
381 same, then at this point, the value's length (in target bytes) is
382 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
383 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
384 len
= gdbarch_addr_bit (current_gdbarch
) / TARGET_CHAR_BIT
;
386 /* If we are printing it as unsigned, truncate it in case it is actually
387 a negative signed value (e.g. "print/u (short)-1" should print 65535
388 (if shorts are 16 bits) instead of 4294967295). */
389 if (options
->format
!= 'd')
391 if (len
< sizeof (LONGEST
))
392 val_long
&= ((LONGEST
) 1 << HOST_CHAR_BIT
* len
) - 1;
395 switch (options
->format
)
400 /* No size specified, like in print. Print varying # of digits. */
401 print_longest (stream
, 'x', 1, val_long
);
410 print_longest (stream
, size
, 1, val_long
);
413 error (_("Undefined output size \"%c\"."), size
);
418 print_longest (stream
, 'd', 1, val_long
);
422 print_longest (stream
, 'u', 0, val_long
);
427 print_longest (stream
, 'o', 1, val_long
);
429 fprintf_filtered (stream
, "0");
434 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
435 print_address (addr
, stream
);
441 struct value_print_options opts
= *options
;
443 if (TYPE_UNSIGNED (type
))
444 value_print (value_from_longest (builtin_type_true_unsigned_char
,
448 value_print (value_from_longest (builtin_type_true_char
, val_long
),
454 type
= float_type_from_length (current_gdbarch
, type
);
455 print_floating (valaddr
, type
, stream
);
459 internal_error (__FILE__
, __LINE__
,
460 _("failed internal consistency check"));
463 /* Binary; 't' stands for "two". */
465 char bits
[8 * (sizeof val_long
) + 1];
466 char buf
[8 * (sizeof val_long
) + 32];
471 width
= 8 * (sizeof val_long
);
488 error (_("Undefined output size \"%c\"."), size
);
494 bits
[width
] = (val_long
& 1) ? '1' : '0';
499 while (*cp
&& *cp
== '0')
505 fputs_filtered (buf
, stream
);
510 error (_("Undefined output format \"%c\"."), options
->format
);
514 /* Specify default address for `x' command.
515 The `info lines' command uses this. */
518 set_next_address (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
520 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
524 /* Make address available to the user as $_. */
525 set_internalvar (lookup_internalvar ("_"),
526 value_from_pointer (ptr_type
, addr
));
529 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
530 after LEADIN. Print nothing if no symbolic name is found nearby.
531 Optionally also print source file and line number, if available.
532 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
533 or to interpret it as a possible C++ name and convert it back to source
534 form. However note that DO_DEMANGLE can be overridden by the specific
535 settings of the demangle and asm_demangle variables. */
538 print_address_symbolic (CORE_ADDR addr
, struct ui_file
*stream
,
539 int do_demangle
, char *leadin
)
542 char *filename
= NULL
;
547 /* Throw away both name and filename. */
548 struct cleanup
*cleanup_chain
= make_cleanup (free_current_contents
, &name
);
549 make_cleanup (free_current_contents
, &filename
);
551 if (build_address_symbolic (addr
, do_demangle
, &name
, &offset
,
552 &filename
, &line
, &unmapped
))
554 do_cleanups (cleanup_chain
);
558 fputs_filtered (leadin
, stream
);
560 fputs_filtered ("<*", stream
);
562 fputs_filtered ("<", stream
);
563 fputs_filtered (name
, stream
);
565 fprintf_filtered (stream
, "+%u", (unsigned int) offset
);
567 /* Append source filename and line number if desired. Give specific
568 line # of this addr, if we have it; else line # of the nearest symbol. */
569 if (print_symbol_filename
&& filename
!= NULL
)
572 fprintf_filtered (stream
, " at %s:%d", filename
, line
);
574 fprintf_filtered (stream
, " in %s", filename
);
577 fputs_filtered ("*>", stream
);
579 fputs_filtered (">", stream
);
581 do_cleanups (cleanup_chain
);
584 /* Given an address ADDR return all the elements needed to print the
585 address in a symbolic form. NAME can be mangled or not depending
586 on DO_DEMANGLE (and also on the asm_demangle global variable,
587 manipulated via ''set print asm-demangle''). Return 0 in case of
588 success, when all the info in the OUT paramters is valid. Return 1
591 build_address_symbolic (CORE_ADDR addr
, /* IN */
592 int do_demangle
, /* IN */
593 char **name
, /* OUT */
594 int *offset
, /* OUT */
595 char **filename
, /* OUT */
597 int *unmapped
) /* OUT */
599 struct minimal_symbol
*msymbol
;
600 struct symbol
*symbol
;
601 CORE_ADDR name_location
= 0;
602 struct obj_section
*section
= NULL
;
603 char *name_temp
= "";
605 /* Let's say it is unmapped. */
608 /* Determine if the address is in an overlay, and whether it is
610 if (overlay_debugging
)
612 section
= find_pc_overlay (addr
);
613 if (pc_in_unmapped_range (addr
, section
))
616 addr
= overlay_mapped_address (addr
, section
);
620 /* First try to find the address in the symbol table, then
621 in the minsyms. Take the closest one. */
623 /* This is defective in the sense that it only finds text symbols. So
624 really this is kind of pointless--we should make sure that the
625 minimal symbols have everything we need (by changing that we could
626 save some memory, but for many debug format--ELF/DWARF or
627 anything/stabs--it would be inconvenient to eliminate those minimal
629 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
630 symbol
= find_pc_sect_function (addr
, section
);
634 name_location
= BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
));
635 if (do_demangle
|| asm_demangle
)
636 name_temp
= SYMBOL_PRINT_NAME (symbol
);
638 name_temp
= SYMBOL_LINKAGE_NAME (symbol
);
643 if (SYMBOL_VALUE_ADDRESS (msymbol
) > name_location
|| symbol
== NULL
)
645 /* The msymbol is closer to the address than the symbol;
646 use the msymbol instead. */
648 name_location
= SYMBOL_VALUE_ADDRESS (msymbol
);
649 if (do_demangle
|| asm_demangle
)
650 name_temp
= SYMBOL_PRINT_NAME (msymbol
);
652 name_temp
= SYMBOL_LINKAGE_NAME (msymbol
);
655 if (symbol
== NULL
&& msymbol
== NULL
)
658 /* If the nearest symbol is too far away, don't print anything symbolic. */
660 /* For when CORE_ADDR is larger than unsigned int, we do math in
661 CORE_ADDR. But when we detect unsigned wraparound in the
662 CORE_ADDR math, we ignore this test and print the offset,
663 because addr+max_symbolic_offset has wrapped through the end
664 of the address space back to the beginning, giving bogus comparison. */
665 if (addr
> name_location
+ max_symbolic_offset
666 && name_location
+ max_symbolic_offset
> name_location
)
669 *offset
= addr
- name_location
;
671 *name
= xstrdup (name_temp
);
673 if (print_symbol_filename
)
675 struct symtab_and_line sal
;
677 sal
= find_pc_sect_line (addr
, section
, 0);
681 *filename
= xstrdup (sal
.symtab
->filename
);
689 /* Print address ADDR symbolically on STREAM.
690 First print it as a number. Then perhaps print
691 <SYMBOL + OFFSET> after the number. */
694 print_address (CORE_ADDR addr
, struct ui_file
*stream
)
696 fputs_filtered (paddress (addr
), stream
);
697 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
700 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
701 controls whether to print the symbolic name "raw" or demangled.
702 Global setting "addressprint" controls whether to print hex address
706 print_address_demangle (CORE_ADDR addr
, struct ui_file
*stream
,
709 struct value_print_options opts
;
710 get_user_print_options (&opts
);
713 fprintf_filtered (stream
, "0");
715 else if (opts
.addressprint
)
717 fputs_filtered (paddress (addr
), stream
);
718 print_address_symbolic (addr
, stream
, do_demangle
, " ");
722 print_address_symbolic (addr
, stream
, do_demangle
, "");
727 /* These are the types that $__ will get after an examine command of one
730 static struct type
*examine_i_type
;
732 static struct type
*examine_b_type
;
733 static struct type
*examine_h_type
;
734 static struct type
*examine_w_type
;
735 static struct type
*examine_g_type
;
737 /* Examine data at address ADDR in format FMT.
738 Fetch it from memory and print on gdb_stdout. */
741 do_examine (struct format_data fmt
, CORE_ADDR addr
)
746 struct type
*val_type
= NULL
;
749 struct value_print_options opts
;
756 /* String or instruction format implies fetch single bytes
757 regardless of the specified size. */
758 if (format
== 's' || format
== 'i')
762 val_type
= examine_i_type
;
763 else if (size
== 'b')
764 val_type
= examine_b_type
;
765 else if (size
== 'h')
766 val_type
= examine_h_type
;
767 else if (size
== 'w')
768 val_type
= examine_w_type
;
769 else if (size
== 'g')
770 val_type
= examine_g_type
;
777 if (format
== 's' || format
== 'i')
780 get_formatted_print_options (&opts
, format
);
782 /* Print as many objects as specified in COUNT, at most maxelts per line,
783 with the address of the next one at the start of each line. */
788 print_address (next_address
, gdb_stdout
);
789 printf_filtered (":");
794 printf_filtered ("\t");
795 /* Note that print_formatted sets next_address for the next
797 last_examine_address
= next_address
;
799 if (last_examine_value
)
800 value_free (last_examine_value
);
802 /* The value to be displayed is not fetched greedily.
803 Instead, to avoid the possibility of a fetched value not
804 being used, its retrieval is delayed until the print code
805 uses it. When examining an instruction stream, the
806 disassembler will perform its own memory fetch using just
807 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
808 the disassembler be modified so that LAST_EXAMINE_VALUE
809 is left with the byte sequence from the last complete
810 instruction fetched from memory? */
811 last_examine_value
= value_at_lazy (val_type
, next_address
);
813 if (last_examine_value
)
814 release_value (last_examine_value
);
816 print_formatted (last_examine_value
, size
, &opts
, gdb_stdout
);
818 /* Display any branch delay slots following the final insn. */
819 if (format
== 'i' && count
== 1)
820 count
+= branch_delay_insns
;
822 printf_filtered ("\n");
823 gdb_flush (gdb_stdout
);
828 validate_format (struct format_data fmt
, char *cmdname
)
831 error (_("Size letters are meaningless in \"%s\" command."), cmdname
);
833 error (_("Item count other than 1 is meaningless in \"%s\" command."),
835 if (fmt
.format
== 'i')
836 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
837 fmt
.format
, cmdname
);
840 /* Evaluate string EXP as an expression in the current language and
841 print the resulting value. EXP may contain a format specifier as the
842 first argument ("/x myvar" for example, to print myvar in hex). */
845 print_command_1 (char *exp
, int inspect
, int voidprint
)
847 struct expression
*expr
;
848 struct cleanup
*old_chain
= 0;
851 struct format_data fmt
;
854 if (exp
&& *exp
== '/')
857 fmt
= decode_format (&exp
, last_format
, 0);
858 validate_format (fmt
, "print");
859 last_format
= format
= fmt
.format
;
871 expr
= parse_expression (exp
);
872 old_chain
= make_cleanup (free_current_contents
, &expr
);
874 val
= evaluate_expression (expr
);
877 val
= access_value_history (0);
879 if (voidprint
|| (val
&& value_type (val
) &&
880 TYPE_CODE (value_type (val
)) != TYPE_CODE_VOID
))
882 struct value_print_options opts
;
883 int histindex
= record_latest_value (val
);
886 annotate_value_history_begin (histindex
, value_type (val
));
888 annotate_value_begin (value_type (val
));
891 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"",
893 else if (histindex
>= 0)
894 printf_filtered ("$%d = ", histindex
);
897 annotate_value_history_value ();
899 get_formatted_print_options (&opts
, format
);
900 opts
.inspect_it
= inspect
;
902 print_formatted (val
, fmt
.size
, &opts
, gdb_stdout
);
903 printf_filtered ("\n");
906 annotate_value_history_end ();
908 annotate_value_end ();
911 printf_unfiltered ("\") )\030");
915 do_cleanups (old_chain
);
919 print_command (char *exp
, int from_tty
)
921 print_command_1 (exp
, 0, 1);
924 /* Same as print, except in epoch, it gets its own window. */
926 inspect_command (char *exp
, int from_tty
)
928 extern int epoch_interface
;
930 print_command_1 (exp
, epoch_interface
, 1);
933 /* Same as print, except it doesn't print void results. */
935 call_command (char *exp
, int from_tty
)
937 print_command_1 (exp
, 0, 0);
941 output_command (char *exp
, int from_tty
)
943 struct expression
*expr
;
944 struct cleanup
*old_chain
;
947 struct format_data fmt
;
948 struct value_print_options opts
;
952 if (exp
&& *exp
== '/')
955 fmt
= decode_format (&exp
, 0, 0);
956 validate_format (fmt
, "output");
960 expr
= parse_expression (exp
);
961 old_chain
= make_cleanup (free_current_contents
, &expr
);
963 val
= evaluate_expression (expr
);
965 annotate_value_begin (value_type (val
));
967 get_formatted_print_options (&opts
, format
);
968 print_formatted (val
, fmt
.size
, &opts
, gdb_stdout
);
970 annotate_value_end ();
973 gdb_flush (gdb_stdout
);
975 do_cleanups (old_chain
);
979 set_command (char *exp
, int from_tty
)
981 struct expression
*expr
= parse_expression (exp
);
982 struct cleanup
*old_chain
=
983 make_cleanup (free_current_contents
, &expr
);
984 evaluate_expression (expr
);
985 do_cleanups (old_chain
);
989 sym_info (char *arg
, int from_tty
)
991 struct minimal_symbol
*msymbol
;
992 struct objfile
*objfile
;
993 struct obj_section
*osect
;
994 CORE_ADDR addr
, sect_addr
;
999 error_no_arg (_("address"));
1001 addr
= parse_and_eval_address (arg
);
1002 ALL_OBJSECTIONS (objfile
, osect
)
1004 /* Only process each object file once, even if there's a separate
1006 if (objfile
->separate_debug_objfile_backlink
)
1009 sect_addr
= overlay_mapped_address (addr
, osect
);
1011 if (obj_section_addr (osect
) <= sect_addr
1012 && sect_addr
< obj_section_endaddr (osect
)
1013 && (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr
, osect
)))
1015 const char *obj_name
, *mapped
, *sec_name
, *msym_name
;
1018 offset
= sect_addr
- SYMBOL_VALUE_ADDRESS (msymbol
);
1019 mapped
= section_is_mapped (osect
) ? _("mapped") : _("unmapped");
1020 sec_name
= osect
->the_bfd_section
->name
;
1021 msym_name
= SYMBOL_PRINT_NAME (msymbol
);
1023 gdb_assert (osect
->objfile
&& osect
->objfile
->name
);
1024 obj_name
= osect
->objfile
->name
;
1026 if (MULTI_OBJFILE_P ())
1027 if (pc_in_unmapped_range (addr
, osect
))
1028 if (section_is_overlay (osect
))
1029 printf_filtered (_("%s + %u in load address range of "
1030 "%s overlay section %s of %s\n"),
1032 mapped
, sec_name
, obj_name
);
1034 printf_filtered (_("%s + %u in load address range of "
1035 "section %s of %s\n"),
1036 msym_name
, offset
, sec_name
, obj_name
);
1038 if (section_is_overlay (osect
))
1039 printf_filtered (_("%s + %u in %s overlay section %s of %s\n"),
1040 msym_name
, offset
, mapped
, sec_name
, obj_name
);
1042 printf_filtered (_("%s + %u in section %s of %s\n"),
1043 msym_name
, offset
, sec_name
, obj_name
);
1045 if (pc_in_unmapped_range (addr
, osect
))
1046 if (section_is_overlay (osect
))
1047 printf_filtered (_("%s + %u in load address range of %s overlay "
1049 msym_name
, offset
, mapped
, sec_name
);
1051 printf_filtered (_("%s + %u in load address range of section %s\n"),
1052 msym_name
, offset
, sec_name
);
1054 if (section_is_overlay (osect
))
1055 printf_filtered (_("%s + %u in %s overlay section %s\n"),
1056 msym_name
, offset
, mapped
, sec_name
);
1058 printf_filtered (_("%s + %u in section %s\n"),
1059 msym_name
, offset
, sec_name
);
1063 printf_filtered (_("No symbol matches %s.\n"), arg
);
1067 address_info (char *exp
, int from_tty
)
1070 struct minimal_symbol
*msymbol
;
1072 struct obj_section
*section
;
1073 CORE_ADDR load_addr
;
1074 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
1075 if exp is a field of `this'. */
1078 error (_("Argument required."));
1080 sym
= lookup_symbol (exp
, get_selected_block (0), VAR_DOMAIN
,
1081 &is_a_field_of_this
);
1084 if (is_a_field_of_this
)
1086 printf_filtered ("Symbol \"");
1087 fprintf_symbol_filtered (gdb_stdout
, exp
,
1088 current_language
->la_language
, DMGL_ANSI
);
1089 printf_filtered ("\" is a field of the local class variable ");
1090 if (current_language
->la_language
== language_objc
)
1091 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1093 printf_filtered ("`this'\n");
1097 msymbol
= lookup_minimal_symbol (exp
, NULL
, NULL
);
1099 if (msymbol
!= NULL
)
1101 load_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
1103 printf_filtered ("Symbol \"");
1104 fprintf_symbol_filtered (gdb_stdout
, exp
,
1105 current_language
->la_language
, DMGL_ANSI
);
1106 printf_filtered ("\" is at ");
1107 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1108 printf_filtered (" in a file compiled without debugging");
1109 section
= SYMBOL_OBJ_SECTION (msymbol
);
1110 if (section_is_overlay (section
))
1112 load_addr
= overlay_unmapped_address (load_addr
, section
);
1113 printf_filtered (",\n -- loaded at ");
1114 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1115 printf_filtered (" in overlay section %s",
1116 section
->the_bfd_section
->name
);
1118 printf_filtered (".\n");
1121 error (_("No symbol \"%s\" in current context."), exp
);
1125 printf_filtered ("Symbol \"");
1126 fprintf_symbol_filtered (gdb_stdout
, SYMBOL_PRINT_NAME (sym
),
1127 current_language
->la_language
, DMGL_ANSI
);
1128 printf_filtered ("\" is ");
1129 val
= SYMBOL_VALUE (sym
);
1130 section
= SYMBOL_OBJ_SECTION (sym
);
1132 switch (SYMBOL_CLASS (sym
))
1135 case LOC_CONST_BYTES
:
1136 printf_filtered ("constant");
1140 printf_filtered ("a label at address ");
1141 fputs_filtered (paddress (load_addr
= SYMBOL_VALUE_ADDRESS (sym
)),
1143 if (section_is_overlay (section
))
1145 load_addr
= overlay_unmapped_address (load_addr
, section
);
1146 printf_filtered (",\n -- loaded at ");
1147 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1148 printf_filtered (" in overlay section %s",
1149 section
->the_bfd_section
->name
);
1154 /* FIXME: cagney/2004-01-26: It should be possible to
1155 unconditionally call the SYMBOL_OPS method when available.
1156 Unfortunately DWARF 2 stores the frame-base (instead of the
1157 function) location in a function's symbol. Oops! For the
1158 moment enable this when/where applicable. */
1159 SYMBOL_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1163 if (SYMBOL_IS_ARGUMENT (sym
))
1164 printf_filtered (_("an argument in register %s"),
1165 gdbarch_register_name (current_gdbarch
, val
));
1167 printf_filtered (_("a variable in register %s"),
1168 gdbarch_register_name (current_gdbarch
, val
));
1172 printf_filtered (_("static storage at address "));
1173 fputs_filtered (paddress (load_addr
= SYMBOL_VALUE_ADDRESS (sym
)),
1175 if (section_is_overlay (section
))
1177 load_addr
= overlay_unmapped_address (load_addr
, section
);
1178 printf_filtered (_(",\n -- loaded at "));
1179 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1180 printf_filtered (_(" in overlay section %s"),
1181 section
->the_bfd_section
->name
);
1185 case LOC_REGPARM_ADDR
:
1186 printf_filtered (_("address of an argument in register %s"),
1187 gdbarch_register_name (current_gdbarch
, val
));
1191 printf_filtered (_("an argument at offset %ld"), val
);
1195 printf_filtered (_("a local variable at frame offset %ld"), val
);
1199 printf_filtered (_("a reference argument at offset %ld"), val
);
1203 printf_filtered (_("a typedef"));
1207 printf_filtered (_("a function at address "));
1208 load_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1209 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1210 if (section_is_overlay (section
))
1212 load_addr
= overlay_unmapped_address (load_addr
, section
);
1213 printf_filtered (_(",\n -- loaded at "));
1214 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1215 printf_filtered (_(" in overlay section %s"),
1216 section
->the_bfd_section
->name
);
1220 case LOC_UNRESOLVED
:
1222 struct minimal_symbol
*msym
;
1224 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
), NULL
, NULL
);
1226 printf_filtered ("unresolved");
1229 section
= SYMBOL_OBJ_SECTION (msym
);
1230 printf_filtered (_("static storage at address "));
1231 load_addr
= SYMBOL_VALUE_ADDRESS (msym
);
1232 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1233 if (section_is_overlay (section
))
1235 load_addr
= overlay_unmapped_address (load_addr
, section
);
1236 printf_filtered (_(",\n -- loaded at "));
1237 fputs_filtered (paddress (load_addr
), gdb_stdout
);
1238 printf_filtered (_(" in overlay section %s"),
1239 section
->the_bfd_section
->name
);
1245 case LOC_OPTIMIZED_OUT
:
1246 printf_filtered (_("optimized out"));
1250 printf_filtered (_("of unknown (botched) type"));
1253 printf_filtered (".\n");
1258 x_command (char *exp
, int from_tty
)
1260 struct expression
*expr
;
1261 struct format_data fmt
;
1262 struct cleanup
*old_chain
;
1265 fmt
.format
= last_format
;
1266 fmt
.size
= last_size
;
1269 if (exp
&& *exp
== '/')
1272 fmt
= decode_format (&exp
, last_format
, last_size
);
1275 /* If we have an expression, evaluate it and use it as the address. */
1277 if (exp
!= 0 && *exp
!= 0)
1279 expr
= parse_expression (exp
);
1280 /* Cause expression not to be there any more if this command is
1281 repeated with Newline. But don't clobber a user-defined
1282 command's definition. */
1285 old_chain
= make_cleanup (free_current_contents
, &expr
);
1286 val
= evaluate_expression (expr
);
1287 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_REF
)
1288 val
= value_ind (val
);
1289 /* In rvalue contexts, such as this, functions are coerced into
1290 pointers to functions. This makes "x/i main" work. */
1291 if (/* last_format == 'i' && */
1292 TYPE_CODE (value_type (val
)) == TYPE_CODE_FUNC
1293 && VALUE_LVAL (val
) == lval_memory
)
1294 next_address
= VALUE_ADDRESS (val
);
1296 next_address
= value_as_address (val
);
1297 do_cleanups (old_chain
);
1300 do_examine (fmt
, next_address
);
1302 /* If the examine succeeds, we remember its size and format for next
1304 last_size
= fmt
.size
;
1305 last_format
= fmt
.format
;
1307 /* Set a couple of internal variables if appropriate. */
1308 if (last_examine_value
)
1310 /* Make last address examined available to the user as $_. Use
1311 the correct pointer type. */
1312 struct type
*pointer_type
1313 = lookup_pointer_type (value_type (last_examine_value
));
1314 set_internalvar (lookup_internalvar ("_"),
1315 value_from_pointer (pointer_type
,
1316 last_examine_address
));
1318 /* Make contents of last address examined available to the user
1319 as $__. If the last value has not been fetched from memory
1320 then don't fetch it now; instead mark it by voiding the $__
1322 if (value_lazy (last_examine_value
))
1323 set_internalvar (lookup_internalvar ("__"),
1324 allocate_value (builtin_type_void
));
1326 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1331 /* Add an expression to the auto-display chain.
1332 Specify the expression. */
1335 display_command (char *exp
, int from_tty
)
1337 struct format_data fmt
;
1338 struct expression
*expr
;
1339 struct display
*new;
1343 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1345 if (tui_active
&& exp
!= NULL
&& *exp
== '$')
1346 display_it
= (tui_set_layout_for_display_command (exp
) == TUI_FAILURE
);
1360 fmt
= decode_format (&exp
, 0, 0);
1361 if (fmt
.size
&& fmt
.format
== 0)
1363 if (fmt
.format
== 'i' || fmt
.format
== 's')
1373 innermost_block
= 0;
1374 expr
= parse_expression (exp
);
1376 new = (struct display
*) xmalloc (sizeof (struct display
));
1379 new->block
= innermost_block
;
1380 new->next
= display_chain
;
1381 new->number
= ++display_number
;
1384 display_chain
= new;
1386 if (from_tty
&& target_has_execution
)
1387 do_one_display (new);
1394 free_display (struct display
*d
)
1400 /* Clear out the display_chain. Done when new symtabs are loaded,
1401 since this invalidates the types stored in many expressions. */
1404 clear_displays (void)
1408 while ((d
= display_chain
) != NULL
)
1411 display_chain
= d
->next
;
1416 /* Delete the auto-display number NUM. */
1419 delete_display (int num
)
1421 struct display
*d1
, *d
;
1424 error (_("No display number %d."), num
);
1426 if (display_chain
->number
== num
)
1429 display_chain
= d1
->next
;
1433 for (d
= display_chain
;; d
= d
->next
)
1436 error (_("No display number %d."), num
);
1437 if (d
->next
->number
== num
)
1447 /* Delete some values from the auto-display chain.
1448 Specify the element numbers. */
1451 undisplay_command (char *args
, int from_tty
)
1459 if (query ("Delete all auto-display expressions? "))
1468 while (*p1
>= '0' && *p1
<= '9')
1470 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1471 error (_("Arguments must be display numbers."));
1475 delete_display (num
);
1478 while (*p
== ' ' || *p
== '\t')
1484 /* Display a single auto-display.
1485 Do nothing if the display cannot be printed in the current context,
1486 or if the display is disabled. */
1489 do_one_display (struct display
*d
)
1491 int within_current_scope
;
1493 if (d
->enabled_p
== 0)
1497 within_current_scope
= contained_in (get_selected_block (0), d
->block
);
1499 within_current_scope
= 1;
1500 if (!within_current_scope
)
1503 current_display_number
= d
->number
;
1505 annotate_display_begin ();
1506 printf_filtered ("%d", d
->number
);
1507 annotate_display_number_end ();
1508 printf_filtered (": ");
1514 annotate_display_format ();
1516 printf_filtered ("x/");
1517 if (d
->format
.count
!= 1)
1518 printf_filtered ("%d", d
->format
.count
);
1519 printf_filtered ("%c", d
->format
.format
);
1520 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1521 printf_filtered ("%c", d
->format
.size
);
1522 printf_filtered (" ");
1524 annotate_display_expression ();
1526 print_expression (d
->exp
, gdb_stdout
);
1527 annotate_display_expression_end ();
1529 if (d
->format
.count
!= 1 || d
->format
.format
== 'i')
1530 printf_filtered ("\n");
1532 printf_filtered (" ");
1534 val
= evaluate_expression (d
->exp
);
1535 addr
= value_as_address (val
);
1536 if (d
->format
.format
== 'i')
1537 addr
= gdbarch_addr_bits_remove (current_gdbarch
, addr
);
1539 annotate_display_value ();
1541 do_examine (d
->format
, addr
);
1545 struct value_print_options opts
;
1547 annotate_display_format ();
1549 if (d
->format
.format
)
1550 printf_filtered ("/%c ", d
->format
.format
);
1552 annotate_display_expression ();
1554 print_expression (d
->exp
, gdb_stdout
);
1555 annotate_display_expression_end ();
1557 printf_filtered (" = ");
1559 annotate_display_expression ();
1561 get_formatted_print_options (&opts
, d
->format
.format
);
1562 print_formatted (evaluate_expression (d
->exp
),
1563 d
->format
.size
, &opts
, gdb_stdout
);
1564 printf_filtered ("\n");
1567 annotate_display_end ();
1569 gdb_flush (gdb_stdout
);
1570 current_display_number
= -1;
1573 /* Display all of the values on the auto-display chain which can be
1574 evaluated in the current scope. */
1581 for (d
= display_chain
; d
; d
= d
->next
)
1585 /* Delete the auto-display which we were in the process of displaying.
1586 This is done when there is an error or a signal. */
1589 disable_display (int num
)
1593 for (d
= display_chain
; d
; d
= d
->next
)
1594 if (d
->number
== num
)
1599 printf_unfiltered (_("No display number %d.\n"), num
);
1603 disable_current_display (void)
1605 if (current_display_number
>= 0)
1607 disable_display (current_display_number
);
1608 fprintf_unfiltered (gdb_stderr
, _("\
1609 Disabling display %d to avoid infinite recursion.\n"),
1610 current_display_number
);
1612 current_display_number
= -1;
1616 display_info (char *ignore
, int from_tty
)
1621 printf_unfiltered (_("There are no auto-display expressions now.\n"));
1623 printf_filtered (_("Auto-display expressions now in effect:\n\
1624 Num Enb Expression\n"));
1626 for (d
= display_chain
; d
; d
= d
->next
)
1628 printf_filtered ("%d: %c ", d
->number
, "ny"[(int) d
->enabled_p
]);
1630 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1632 else if (d
->format
.format
)
1633 printf_filtered ("/%c ", d
->format
.format
);
1634 print_expression (d
->exp
, gdb_stdout
);
1635 if (d
->block
&& !contained_in (get_selected_block (0), d
->block
))
1636 printf_filtered (_(" (cannot be evaluated in the current context)"));
1637 printf_filtered ("\n");
1638 gdb_flush (gdb_stdout
);
1643 enable_display (char *args
, int from_tty
)
1652 for (d
= display_chain
; d
; d
= d
->next
)
1659 while (*p1
>= '0' && *p1
<= '9')
1661 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1662 error (_("Arguments must be display numbers."));
1666 for (d
= display_chain
; d
; d
= d
->next
)
1667 if (d
->number
== num
)
1672 printf_unfiltered (_("No display number %d.\n"), num
);
1675 while (*p
== ' ' || *p
== '\t')
1681 disable_display_command (char *args
, int from_tty
)
1689 for (d
= display_chain
; d
; d
= d
->next
)
1696 while (*p1
>= '0' && *p1
<= '9')
1698 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1699 error (_("Arguments must be display numbers."));
1701 disable_display (atoi (p
));
1704 while (*p
== ' ' || *p
== '\t')
1710 /* Print the value in stack frame FRAME of a variable specified by a
1714 print_variable_value (struct symbol
*var
, struct frame_info
*frame
,
1715 struct ui_file
*stream
)
1717 struct value
*val
= read_var_value (var
, frame
);
1718 struct value_print_options opts
;
1720 get_user_print_options (&opts
);
1721 value_print (val
, stream
, &opts
);
1725 printf_command (char *arg
, int from_tty
)
1729 char *string
= NULL
;
1730 struct value
**val_args
;
1732 char *current_substring
;
1734 int allocated_args
= 20;
1735 struct cleanup
*old_cleanups
;
1737 val_args
= xmalloc (allocated_args
* sizeof (struct value
*));
1738 old_cleanups
= make_cleanup (free_current_contents
, &val_args
);
1741 error_no_arg (_("format-control string and values to print"));
1743 /* Skip white space before format string */
1744 while (*s
== ' ' || *s
== '\t')
1747 /* A format string should follow, enveloped in double quotes. */
1749 error (_("Bad format string, missing '\"'."));
1751 /* Parse the format-control string and copy it into the string STRING,
1752 processing some kinds of escape sequence. */
1754 f
= string
= (char *) alloca (strlen (s
) + 1);
1762 error (_("Bad format string, non-terminated '\"'."));
1795 /* ??? TODO: handle other escape sequences */
1796 error (_("Unrecognized escape character \\%c in format string."),
1806 /* Skip over " and following space and comma. */
1809 while (*s
== ' ' || *s
== '\t')
1812 if (*s
!= ',' && *s
!= 0)
1813 error (_("Invalid argument syntax"));
1817 while (*s
== ' ' || *s
== '\t')
1820 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1821 substrings
= alloca (strlen (string
) * 2);
1822 current_substring
= substrings
;
1825 /* Now scan the string for %-specs and see what kinds of args they want.
1826 argclass[I] classifies the %-specs so we can give printf_filtered
1827 something of the right size. */
1831 int_arg
, long_arg
, long_long_arg
, ptr_arg
, string_arg
,
1832 double_arg
, long_double_arg
, decfloat_arg
1834 enum argclass
*argclass
;
1835 enum argclass this_argclass
;
1840 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1847 int seen_hash
= 0, seen_zero
= 0, lcount
= 0, seen_prec
= 0;
1848 int seen_space
= 0, seen_plus
= 0;
1849 int seen_big_l
= 0, seen_h
= 0, seen_big_h
= 0;
1850 int seen_big_d
= 0, seen_double_big_d
= 0;
1853 /* Check the validity of the format specifier, and work
1854 out what argument it expects. We only accept C89
1855 format strings, with the exception of long long (which
1856 we autoconf for). */
1858 /* Skip over "%%". */
1865 /* The first part of a format specifier is a set of flag
1867 while (strchr ("0-+ #", *f
))
1880 /* The next part of a format specifier is a width. */
1881 while (strchr ("0123456789", *f
))
1884 /* The next part of a format specifier is a precision. */
1889 while (strchr ("0123456789", *f
))
1893 /* The next part of a format specifier is a length modifier. */
1914 /* Decimal32 modifier. */
1920 /* Decimal64 and Decimal128 modifiers. */
1925 /* Check for a Decimal128. */
1929 seen_double_big_d
= 1;
1945 if (seen_space
|| seen_plus
)
1952 this_argclass
= int_arg
;
1953 else if (lcount
== 1)
1954 this_argclass
= long_arg
;
1956 this_argclass
= long_long_arg
;
1963 this_argclass
= int_arg
;
1964 if (lcount
|| seen_h
|| seen_big_l
)
1966 if (seen_prec
|| seen_zero
|| seen_space
|| seen_plus
)
1971 this_argclass
= ptr_arg
;
1972 if (lcount
|| seen_h
|| seen_big_l
)
1974 if (seen_prec
|| seen_zero
|| seen_space
|| seen_plus
)
1979 this_argclass
= string_arg
;
1980 if (lcount
|| seen_h
|| seen_big_l
)
1982 if (seen_zero
|| seen_space
|| seen_plus
)
1991 if (seen_big_h
|| seen_big_d
|| seen_double_big_d
)
1992 this_argclass
= decfloat_arg
;
1993 else if (seen_big_l
)
1994 this_argclass
= long_double_arg
;
1996 this_argclass
= double_arg
;
1998 if (lcount
|| seen_h
)
2003 error (_("`*' not supported for precision or width in printf"));
2006 error (_("Format specifier `n' not supported in printf"));
2009 error (_("Incomplete format specifier at end of format string"));
2012 error (_("Unrecognized format specifier '%c' in printf"), *f
);
2016 error (_("Inappropriate modifiers to format specifier '%c' in printf"),
2021 if (lcount
> 1 && USE_PRINTF_I64
)
2023 /* Windows' printf does support long long, but not the usual way.
2024 Convert %lld to %I64d. */
2025 int length_before_ll
= f
- last_arg
- 1 - lcount
;
2026 strncpy (current_substring
, last_arg
, length_before_ll
);
2027 strcpy (current_substring
+ length_before_ll
, "I64");
2028 current_substring
[length_before_ll
+ 3] =
2029 last_arg
[length_before_ll
+ lcount
];
2030 current_substring
+= length_before_ll
+ 4;
2034 strncpy (current_substring
, last_arg
, f
- last_arg
);
2035 current_substring
+= f
- last_arg
;
2037 *current_substring
++ = '\0';
2039 argclass
[nargs_wanted
++] = this_argclass
;
2042 /* Now, parse all arguments and evaluate them.
2043 Store the VALUEs in VAL_ARGS. */
2048 if (nargs
== allocated_args
)
2049 val_args
= (struct value
**) xrealloc ((char *) val_args
,
2050 (allocated_args
*= 2)
2051 * sizeof (struct value
*));
2053 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
2061 if (nargs
!= nargs_wanted
)
2062 error (_("Wrong number of arguments for specified format-string"));
2064 /* Now actually print them. */
2065 current_substring
= substrings
;
2066 for (i
= 0; i
< nargs
; i
++)
2068 switch (argclass
[i
])
2075 tem
= value_as_address (val_args
[i
]);
2077 /* This is a %s argument. Find the length of the string. */
2082 read_memory (tem
+ j
, &c
, 1);
2087 /* Copy the string contents into a string inside GDB. */
2088 str
= (gdb_byte
*) alloca (j
+ 1);
2090 read_memory (tem
, str
, j
);
2093 printf_filtered (current_substring
, (char *) str
);
2098 struct type
*type
= value_type (val_args
[i
]);
2102 /* If format string wants a float, unchecked-convert the value
2103 to floating point of the same size. */
2104 type
= float_type_from_length (current_gdbarch
, type
);
2105 val
= unpack_double (type
, value_contents (val_args
[i
]), &inv
);
2107 error (_("Invalid floating value found in program."));
2109 printf_filtered (current_substring
, (double) val
);
2112 case long_double_arg
:
2113 #ifdef HAVE_LONG_DOUBLE
2115 struct type
*type
= value_type (val_args
[i
]);
2119 /* If format string wants a float, unchecked-convert the value
2120 to floating point of the same size. */
2121 type
= float_type_from_length (current_gdbarch
, type
);
2122 val
= unpack_double (type
, value_contents (val_args
[i
]), &inv
);
2124 error (_("Invalid floating value found in program."));
2126 printf_filtered (current_substring
, (long double) val
);
2130 error (_("long double not supported in printf"));
2133 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2135 long long val
= value_as_long (val_args
[i
]);
2136 printf_filtered (current_substring
, val
);
2140 error (_("long long not supported in printf"));
2144 int val
= value_as_long (val_args
[i
]);
2145 printf_filtered (current_substring
, val
);
2150 long val
= value_as_long (val_args
[i
]);
2151 printf_filtered (current_substring
, val
);
2155 /* Handles decimal floating values. */
2158 const gdb_byte
*param_ptr
= value_contents (val_args
[i
]);
2159 #if defined (PRINTF_HAS_DECFLOAT)
2160 /* If we have native support for Decimal floating
2161 printing, handle it here. */
2162 printf_filtered (current_substring
, param_ptr
);
2165 /* As a workaround until vasprintf has native support for DFP
2166 we convert the DFP values to string and print them using
2167 the %s format specifier. */
2170 int nnull_chars
= 0;
2172 /* Parameter data. */
2173 struct type
*param_type
= value_type (val_args
[i
]);
2174 unsigned int param_len
= TYPE_LENGTH (param_type
);
2176 /* DFP output data. */
2177 struct value
*dfp_value
= NULL
;
2181 struct type
*dfp_type
= NULL
;
2182 char decstr
[MAX_DECIMAL_STRING
];
2184 /* Points to the end of the string so that we can go back
2185 and check for DFP length modifiers. */
2186 eos
= current_substring
+ strlen (current_substring
);
2188 /* Look for the float/double format specifier. */
2189 while (*eos
!= 'f' && *eos
!= 'e' && *eos
!= 'E'
2190 && *eos
!= 'g' && *eos
!= 'G')
2195 /* Search for the '%' char and extract the size and type of
2196 the output decimal value based on its modifiers
2197 (%Hf, %Df, %DDf). */
2198 while (*--sos
!= '%')
2203 dfp_type
= builtin_type (current_gdbarch
)->builtin_decfloat
;
2205 else if (*sos
== 'D' && *(sos
- 1) == 'D')
2208 dfp_type
= builtin_type (current_gdbarch
)->builtin_declong
;
2214 dfp_type
= builtin_type (current_gdbarch
)->builtin_decdouble
;
2218 /* Replace %Hf, %Df and %DDf with %s's. */
2221 /* Go through the whole format string and pull the correct
2222 number of chars back to compensate for the change in the
2223 format specifier. */
2224 while (nnull_chars
< nargs
- i
)
2232 /* Conversion between different DFP types. */
2233 if (TYPE_CODE (param_type
) == TYPE_CODE_DECFLOAT
)
2234 decimal_convert (param_ptr
, param_len
, dec
, dfp_len
);
2236 /* If this is a non-trivial conversion, just output 0.
2237 A correct converted value can be displayed by explicitly
2238 casting to a DFP type. */
2239 decimal_from_string (dec
, dfp_len
, "0");
2241 dfp_value
= value_from_decfloat (dfp_type
, dec
);
2243 dfp_ptr
= (gdb_byte
*) value_contents (dfp_value
);
2245 decimal_to_string (dfp_ptr
, dfp_len
, decstr
);
2247 /* Print the DFP value. */
2248 printf_filtered (current_substring
, decstr
);
2256 /* We avoid the host's %p because pointers are too
2257 likely to be the wrong size. The only interesting
2258 modifier for %p is a width; extract that, and then
2259 handle %p as glibc would: %#x or a literal "(nil)". */
2261 char *p
, *fmt
, *fmt_p
;
2262 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2263 long long val
= value_as_long (val_args
[i
]);
2265 long val
= value_as_long (val_args
[i
]);
2268 fmt
= alloca (strlen (current_substring
) + 5);
2270 /* Copy up to the leading %. */
2271 p
= current_substring
;
2275 int is_percent
= (*p
== '%');
2289 /* Copy any width. */
2290 while (*p
>= '0' && *p
< '9')
2293 gdb_assert (*p
== 'p' && *(p
+ 1) == '\0');
2296 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2302 printf_filtered (fmt
, val
);
2308 printf_filtered (fmt
, "(nil)");
2314 internal_error (__FILE__
, __LINE__
,
2315 _("failed internal consistency check"));
2317 /* Skip to the next substring. */
2318 current_substring
+= strlen (current_substring
) + 1;
2320 /* Print the portion of the format string after the last argument. */
2321 puts_filtered (last_arg
);
2323 do_cleanups (old_cleanups
);
2327 _initialize_printcmd (void)
2329 struct cmd_list_element
*c
;
2331 current_display_number
= -1;
2333 add_info ("address", address_info
,
2334 _("Describe where symbol SYM is stored."));
2336 add_info ("symbol", sym_info
, _("\
2337 Describe what symbol is at location ADDR.\n\
2338 Only for symbols with fixed locations (global or static scope)."));
2340 add_com ("x", class_vars
, x_command
, _("\
2341 Examine memory: x/FMT ADDRESS.\n\
2342 ADDRESS is an expression for the memory address to examine.\n\
2343 FMT is a repeat count followed by a format letter and a size letter.\n\
2344 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2345 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2346 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2347 The specified number of objects of the specified size are printed\n\
2348 according to the format.\n\n\
2349 Defaults for format and size letters are those previously used.\n\
2350 Default count is 1. Default address is following last thing printed\n\
2351 with this command or \"print\"."));
2354 add_com ("whereis", class_vars
, whereis_command
,
2355 _("Print line number and file of definition of variable."));
2358 add_info ("display", display_info
, _("\
2359 Expressions to display when program stops, with code numbers."));
2361 add_cmd ("undisplay", class_vars
, undisplay_command
, _("\
2362 Cancel some expressions to be displayed when program stops.\n\
2363 Arguments are the code numbers of the expressions to stop displaying.\n\
2364 No argument means cancel all automatic-display expressions.\n\
2365 \"delete display\" has the same effect as this command.\n\
2366 Do \"info display\" to see current list of code numbers."),
2369 add_com ("display", class_vars
, display_command
, _("\
2370 Print value of expression EXP each time the program stops.\n\
2371 /FMT may be used before EXP as in the \"print\" command.\n\
2372 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2373 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2374 and examining is done as in the \"x\" command.\n\n\
2375 With no argument, display all currently requested auto-display expressions.\n\
2376 Use \"undisplay\" to cancel display requests previously made."));
2378 add_cmd ("display", class_vars
, enable_display
, _("\
2379 Enable some expressions to be displayed when program stops.\n\
2380 Arguments are the code numbers of the expressions to resume displaying.\n\
2381 No argument means enable all automatic-display expressions.\n\
2382 Do \"info display\" to see current list of code numbers."), &enablelist
);
2384 add_cmd ("display", class_vars
, disable_display_command
, _("\
2385 Disable some expressions to be displayed when program stops.\n\
2386 Arguments are the code numbers of the expressions to stop displaying.\n\
2387 No argument means disable all automatic-display expressions.\n\
2388 Do \"info display\" to see current list of code numbers."), &disablelist
);
2390 add_cmd ("display", class_vars
, undisplay_command
, _("\
2391 Cancel some expressions to be displayed when program stops.\n\
2392 Arguments are the code numbers of the expressions to stop displaying.\n\
2393 No argument means cancel all automatic-display expressions.\n\
2394 Do \"info display\" to see current list of code numbers."), &deletelist
);
2396 add_com ("printf", class_vars
, printf_command
, _("\
2397 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2398 This is useful for formatted output in user-defined commands."));
2400 add_com ("output", class_vars
, output_command
, _("\
2401 Like \"print\" but don't put in value history and don't print newline.\n\
2402 This is useful in user-defined commands."));
2404 add_prefix_cmd ("set", class_vars
, set_command
, _("\
2405 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2406 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2407 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2408 with $), a register (a few standard names starting with $), or an actual\n\
2409 variable in the program being debugged. EXP is any valid expression.\n\
2410 Use \"set variable\" for variables with names identical to set subcommands.\n\
2412 With a subcommand, this command modifies parts of the gdb environment.\n\
2413 You can see these environment settings with the \"show\" command."),
2414 &setlist
, "set ", 1, &cmdlist
);
2416 add_com ("assign", class_vars
, set_command
, _("\
2417 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2418 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2419 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2420 with $), a register (a few standard names starting with $), or an actual\n\
2421 variable in the program being debugged. EXP is any valid expression.\n\
2422 Use \"set variable\" for variables with names identical to set subcommands.\n\
2423 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2424 You can see these environment settings with the \"show\" command."));
2426 /* "call" is the same as "set", but handy for dbx users to call fns. */
2427 c
= add_com ("call", class_vars
, call_command
, _("\
2428 Call a function in the program.\n\
2429 The argument is the function name and arguments, in the notation of the\n\
2430 current working language. The result is printed and saved in the value\n\
2431 history, if it is not void."));
2432 set_cmd_completer (c
, expression_completer
);
2434 add_cmd ("variable", class_vars
, set_command
, _("\
2435 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2436 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2437 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2438 with $), a register (a few standard names starting with $), or an actual\n\
2439 variable in the program being debugged. EXP is any valid expression.\n\
2440 This may usually be abbreviated to simply \"set\"."),
2443 c
= add_com ("print", class_vars
, print_command
, _("\
2444 Print value of expression EXP.\n\
2445 Variables accessible are those of the lexical environment of the selected\n\
2446 stack frame, plus all those whose scope is global or an entire file.\n\
2448 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2449 $$NUM refers to NUM'th value back from the last one.\n\
2450 Names starting with $ refer to registers (with the values they would have\n\
2451 if the program were to return to the stack frame now selected, restoring\n\
2452 all registers saved by frames farther in) or else to debugger\n\
2453 \"convenience\" variables (any such name not a known register).\n\
2454 Use assignment expressions to give values to convenience variables.\n\
2456 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2457 @ is a binary operator for treating consecutive data objects\n\
2458 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2459 element is FOO, whose second element is stored in the space following\n\
2460 where FOO is stored, etc. FOO must be an expression whose value\n\
2461 resides in memory.\n\
2463 EXP may be preceded with /FMT, where FMT is a format letter\n\
2464 but no count or size letter (see \"x\" command)."));
2465 set_cmd_completer (c
, expression_completer
);
2466 add_com_alias ("p", "print", class_vars
, 1);
2468 c
= add_com ("inspect", class_vars
, inspect_command
, _("\
2469 Same as \"print\" command, except that if you are running in the epoch\n\
2470 environment, the value is printed in its own window."));
2471 set_cmd_completer (c
, expression_completer
);
2473 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class
,
2474 &max_symbolic_offset
, _("\
2475 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2476 Show the largest offset that will be printed in <symbol+1234> form."), NULL
,
2478 show_max_symbolic_offset
,
2479 &setprintlist
, &showprintlist
);
2480 add_setshow_boolean_cmd ("symbol-filename", no_class
,
2481 &print_symbol_filename
, _("\
2482 Set printing of source filename and line number with <symbol>."), _("\
2483 Show printing of source filename and line number with <symbol>."), NULL
,
2485 show_print_symbol_filename
,
2486 &setprintlist
, &showprintlist
);
2488 /* For examine/instruction a single byte quantity is specified as
2489 the data. This avoids problems with value_at_lazy() requiring a
2490 valid data type (and rejecting VOID). */
2491 examine_i_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_i_type", NULL
);
2493 examine_b_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_b_type", NULL
);
2494 examine_h_type
= init_type (TYPE_CODE_INT
, 2, 0, "examine_h_type", NULL
);
2495 examine_w_type
= init_type (TYPE_CODE_INT
, 4, 0, "examine_w_type", NULL
);
2496 examine_g_type
= init_type (TYPE_CODE_INT
, 8, 0, "examine_g_type", NULL
);