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 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"
46 #include "tui/tui.h" /* For tui_active et.al. */
49 extern int asm_demangle
; /* Whether to demangle syms in asm printouts */
50 extern int addressprint
; /* Whether to print hex addresses in HLL " */
59 /* Last specified output format. */
61 static char last_format
= 'x';
63 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
65 static char last_size
= 'w';
67 /* Default address to examine next. */
69 static CORE_ADDR next_address
;
71 /* Number of delay instructions following current disassembled insn. */
73 static int branch_delay_insns
;
75 /* Last address examined. */
77 static CORE_ADDR last_examine_address
;
79 /* Contents of last address examined.
80 This is not valid past the end of the `x' command! */
82 static struct value
*last_examine_value
;
84 /* Largest offset between a symbolic value and an address, that will be
85 printed as `0x1234 <symbol+offset>'. */
87 static unsigned int max_symbolic_offset
= UINT_MAX
;
89 show_max_symbolic_offset (struct ui_file
*file
, int from_tty
,
90 struct cmd_list_element
*c
, const char *value
)
92 fprintf_filtered (file
, _("\
93 The largest offset that will be printed in <symbol+1234> form is %s.\n"),
97 /* Append the source filename and linenumber of the symbol when
98 printing a symbolic value as `<symbol at filename:linenum>' if set. */
99 static int print_symbol_filename
= 0;
101 show_print_symbol_filename (struct ui_file
*file
, int from_tty
,
102 struct cmd_list_element
*c
, const char *value
)
104 fprintf_filtered (file
, _("\
105 Printing of source filename and line number with <symbol> is %s.\n"),
109 /* Number of auto-display expression currently being displayed.
110 So that we can disable it if we get an error or a signal within it.
111 -1 when not doing one. */
113 int current_display_number
;
115 /* Flag to low-level print routines that this value is being printed
116 in an epoch window. We'd like to pass this as a parameter, but
117 every routine would need to take it. Perhaps we can encapsulate
118 this in the I/O stream once we have GNU stdio. */
124 /* Chain link to next auto-display item. */
125 struct display
*next
;
126 /* Expression to be evaluated and displayed. */
127 struct expression
*exp
;
128 /* Item number of this auto-display item. */
130 /* Display format specified. */
131 struct format_data format
;
132 /* Innermost block required by this expression when evaluated */
134 /* Status of this display (enabled or disabled) */
138 /* Chain of expressions whose values should be displayed
139 automatically each time the program stops. */
141 static struct display
*display_chain
;
143 static int display_number
;
145 /* Prototypes for exported functions. */
147 void output_command (char *, int);
149 void _initialize_printcmd (void);
151 /* Prototypes for local functions. */
153 static void do_one_display (struct display
*);
156 /* Decode a format specification. *STRING_PTR should point to it.
157 OFORMAT and OSIZE are used as defaults for the format and size
158 if none are given in the format specification.
159 If OSIZE is zero, then the size field of the returned value
160 should be set only if a size is explicitly specified by the
162 The structure returned describes all the data
163 found in the specification. In addition, *STRING_PTR is advanced
164 past the specification and past all whitespace following it. */
166 static struct format_data
167 decode_format (char **string_ptr
, int oformat
, int osize
)
169 struct format_data val
;
170 char *p
= *string_ptr
;
176 if (*p
>= '0' && *p
<= '9')
177 val
.count
= atoi (p
);
178 while (*p
>= '0' && *p
<= '9')
181 /* Now process size or format letters that follow. */
185 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
187 else if (*p
>= 'a' && *p
<= 'z')
193 while (*p
== ' ' || *p
== '\t')
197 /* Set defaults for format and size if not specified. */
198 if (val
.format
== '?')
202 /* Neither has been specified. */
203 val
.format
= oformat
;
207 /* If a size is specified, any format makes a reasonable
208 default except 'i'. */
209 val
.format
= oformat
== 'i' ? 'x' : oformat
;
211 else if (val
.size
== '?')
216 /* Pick the appropriate size for an address. */
217 if (gdbarch_ptr_bit (current_gdbarch
) == 64)
218 val
.size
= osize
? 'g' : osize
;
219 else if (gdbarch_ptr_bit (current_gdbarch
) == 32)
220 val
.size
= osize
? 'w' : osize
;
221 else if (gdbarch_ptr_bit (current_gdbarch
) == 16)
222 val
.size
= osize
? 'h' : osize
;
224 /* Bad value for gdbarch_ptr_bit. */
225 internal_error (__FILE__
, __LINE__
,
226 _("failed internal consistency check"));
229 /* Floating point has to be word or giantword. */
230 if (osize
== 'w' || osize
== 'g')
233 /* Default it to giantword if the last used size is not
235 val
.size
= osize
? 'g' : osize
;
238 /* Characters default to one byte. */
239 val
.size
= osize
? 'b' : osize
;
242 /* The default is the size most recently specified. */
249 /* Print value VAL on stream according to FORMAT, a letter or 0.
250 Do not end with a newline.
251 0 means print VAL according to its own type.
252 SIZE is the letter for the size of datum being printed.
253 This is used to pad hex numbers so they line up. */
256 print_formatted (struct value
*val
, int format
, int size
,
257 struct ui_file
*stream
)
259 struct type
*type
= check_typedef (value_type (val
));
260 int len
= TYPE_LENGTH (type
);
262 if (VALUE_LVAL (val
) == lval_memory
)
263 next_address
= VALUE_ADDRESS (val
) + len
;
268 /* FIXME: Need to handle wchar_t's here... */
269 next_address
= VALUE_ADDRESS (val
)
270 + val_print_string (VALUE_ADDRESS (val
), -1, 1, stream
);
274 /* The old comment says
275 "Force output out, print_insn not using _filtered".
276 I'm not completely sure what that means, I suspect most print_insn
277 now do use _filtered, so I guess it's obsolete.
278 --Yes, it does filter now, and so this is obsolete. -JB */
280 /* We often wrap here if there are long symbolic names. */
282 next_address
= (VALUE_ADDRESS (val
)
283 + gdb_print_insn (VALUE_ADDRESS (val
), stream
,
284 &branch_delay_insns
));
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
);
306 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
307 according to letters FORMAT and SIZE on STREAM.
308 FORMAT may not be zero. Formats s and i are not supported at this level.
310 This is how the elements of an array or structure are printed
314 print_scalar_formatted (const void *valaddr
, struct type
*type
,
315 int format
, int size
, struct ui_file
*stream
)
317 LONGEST val_long
= 0;
318 unsigned int len
= TYPE_LENGTH (type
);
320 if (len
> sizeof(LONGEST
) &&
321 (TYPE_CODE (type
) == TYPE_CODE_INT
322 || TYPE_CODE (type
) == TYPE_CODE_ENUM
))
327 print_octal_chars (stream
, valaddr
, len
);
331 print_decimal_chars (stream
, valaddr
, len
);
334 print_binary_chars (stream
, valaddr
, len
);
337 print_hex_chars (stream
, valaddr
, len
);
340 print_char_chars (stream
, valaddr
, len
);
348 val_long
= unpack_long (type
, valaddr
);
350 /* If the value is a pointer, and pointers and addresses are not the
351 same, then at this point, the value's length (in target bytes) is
352 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
353 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
354 len
= gdbarch_addr_bit (current_gdbarch
) / TARGET_CHAR_BIT
;
356 /* If we are printing it as unsigned, truncate it in case it is actually
357 a negative signed value (e.g. "print/u (short)-1" should print 65535
358 (if shorts are 16 bits) instead of 4294967295). */
361 if (len
< sizeof (LONGEST
))
362 val_long
&= ((LONGEST
) 1 << HOST_CHAR_BIT
* len
) - 1;
370 /* No size specified, like in print. Print varying # of digits. */
371 print_longest (stream
, 'x', 1, val_long
);
380 print_longest (stream
, size
, 1, val_long
);
383 error (_("Undefined output size \"%c\"."), size
);
388 print_longest (stream
, 'd', 1, val_long
);
392 print_longest (stream
, 'u', 0, val_long
);
397 print_longest (stream
, 'o', 1, val_long
);
399 fprintf_filtered (stream
, "0");
404 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
405 print_address (addr
, stream
);
410 value_print (value_from_longest (builtin_type_true_char
, val_long
),
411 stream
, 0, Val_pretty_default
);
415 if (len
== TYPE_LENGTH (builtin_type_float
))
416 type
= builtin_type_float
;
417 else if (len
== TYPE_LENGTH (builtin_type_double
))
418 type
= builtin_type_double
;
419 else if (len
== TYPE_LENGTH (builtin_type_long_double
))
420 type
= builtin_type_long_double
;
421 print_floating (valaddr
, type
, stream
);
425 internal_error (__FILE__
, __LINE__
,
426 _("failed internal consistency check"));
429 /* Binary; 't' stands for "two". */
431 char bits
[8 * (sizeof val_long
) + 1];
432 char buf
[8 * (sizeof val_long
) + 32];
437 width
= 8 * (sizeof val_long
);
454 error (_("Undefined output size \"%c\"."), size
);
460 bits
[width
] = (val_long
& 1) ? '1' : '0';
465 while (*cp
&& *cp
== '0')
471 fputs_filtered (buf
, stream
);
476 error (_("Undefined output format \"%c\"."), format
);
480 /* Specify default address for `x' command.
481 The `info lines' command uses this. */
484 set_next_address (CORE_ADDR addr
)
488 /* Make address available to the user as $_. */
489 set_internalvar (lookup_internalvar ("_"),
490 value_from_pointer (lookup_pointer_type (builtin_type_void
),
494 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
495 after LEADIN. Print nothing if no symbolic name is found nearby.
496 Optionally also print source file and line number, if available.
497 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
498 or to interpret it as a possible C++ name and convert it back to source
499 form. However note that DO_DEMANGLE can be overridden by the specific
500 settings of the demangle and asm_demangle variables. */
503 print_address_symbolic (CORE_ADDR addr
, struct ui_file
*stream
,
504 int do_demangle
, char *leadin
)
507 char *filename
= NULL
;
512 /* Throw away both name and filename. */
513 struct cleanup
*cleanup_chain
= make_cleanup (free_current_contents
, &name
);
514 make_cleanup (free_current_contents
, &filename
);
516 if (build_address_symbolic (addr
, do_demangle
, &name
, &offset
,
517 &filename
, &line
, &unmapped
))
519 do_cleanups (cleanup_chain
);
523 fputs_filtered (leadin
, stream
);
525 fputs_filtered ("<*", stream
);
527 fputs_filtered ("<", stream
);
528 fputs_filtered (name
, stream
);
530 fprintf_filtered (stream
, "+%u", (unsigned int) offset
);
532 /* Append source filename and line number if desired. Give specific
533 line # of this addr, if we have it; else line # of the nearest symbol. */
534 if (print_symbol_filename
&& filename
!= NULL
)
537 fprintf_filtered (stream
, " at %s:%d", filename
, line
);
539 fprintf_filtered (stream
, " in %s", filename
);
542 fputs_filtered ("*>", stream
);
544 fputs_filtered (">", stream
);
546 do_cleanups (cleanup_chain
);
549 /* Given an address ADDR return all the elements needed to print the
550 address in a symbolic form. NAME can be mangled or not depending
551 on DO_DEMANGLE (and also on the asm_demangle global variable,
552 manipulated via ''set print asm-demangle''). Return 0 in case of
553 success, when all the info in the OUT paramters is valid. Return 1
556 build_address_symbolic (CORE_ADDR addr
, /* IN */
557 int do_demangle
, /* IN */
558 char **name
, /* OUT */
559 int *offset
, /* OUT */
560 char **filename
, /* OUT */
562 int *unmapped
) /* OUT */
564 struct minimal_symbol
*msymbol
;
565 struct symbol
*symbol
;
566 CORE_ADDR name_location
= 0;
567 asection
*section
= 0;
568 char *name_temp
= "";
570 /* Let's say it is unmapped. */
573 /* Determine if the address is in an overlay, and whether it is
575 if (overlay_debugging
)
577 section
= find_pc_overlay (addr
);
578 if (pc_in_unmapped_range (addr
, section
))
581 addr
= overlay_mapped_address (addr
, section
);
585 /* First try to find the address in the symbol table, then
586 in the minsyms. Take the closest one. */
588 /* This is defective in the sense that it only finds text symbols. So
589 really this is kind of pointless--we should make sure that the
590 minimal symbols have everything we need (by changing that we could
591 save some memory, but for many debug format--ELF/DWARF or
592 anything/stabs--it would be inconvenient to eliminate those minimal
594 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
595 symbol
= find_pc_sect_function (addr
, section
);
599 name_location
= BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
));
600 if (do_demangle
|| asm_demangle
)
601 name_temp
= SYMBOL_PRINT_NAME (symbol
);
603 name_temp
= DEPRECATED_SYMBOL_NAME (symbol
);
608 if (SYMBOL_VALUE_ADDRESS (msymbol
) > name_location
|| symbol
== NULL
)
610 /* The msymbol is closer to the address than the symbol;
611 use the msymbol instead. */
613 name_location
= SYMBOL_VALUE_ADDRESS (msymbol
);
614 if (do_demangle
|| asm_demangle
)
615 name_temp
= SYMBOL_PRINT_NAME (msymbol
);
617 name_temp
= DEPRECATED_SYMBOL_NAME (msymbol
);
620 if (symbol
== NULL
&& msymbol
== NULL
)
623 /* If the nearest symbol is too far away, don't print anything symbolic. */
625 /* For when CORE_ADDR is larger than unsigned int, we do math in
626 CORE_ADDR. But when we detect unsigned wraparound in the
627 CORE_ADDR math, we ignore this test and print the offset,
628 because addr+max_symbolic_offset has wrapped through the end
629 of the address space back to the beginning, giving bogus comparison. */
630 if (addr
> name_location
+ max_symbolic_offset
631 && name_location
+ max_symbolic_offset
> name_location
)
634 *offset
= addr
- name_location
;
636 *name
= xstrdup (name_temp
);
638 if (print_symbol_filename
)
640 struct symtab_and_line sal
;
642 sal
= find_pc_sect_line (addr
, section
, 0);
646 *filename
= xstrdup (sal
.symtab
->filename
);
653 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
656 deprecated_print_address_numeric (CORE_ADDR addr
, int use_local
,
657 struct ui_file
*stream
)
660 fputs_filtered (paddress (addr
), stream
);
663 int addr_bit
= gdbarch_addr_bit (current_gdbarch
);
665 if (addr_bit
< (sizeof (CORE_ADDR
) * HOST_CHAR_BIT
))
666 addr
&= ((CORE_ADDR
) 1 << addr_bit
) - 1;
667 print_longest (stream
, 'x', 0, (ULONGEST
) addr
);
671 /* Print address ADDR symbolically on STREAM.
672 First print it as a number. Then perhaps print
673 <SYMBOL + OFFSET> after the number. */
676 print_address (CORE_ADDR addr
, struct ui_file
*stream
)
678 deprecated_print_address_numeric (addr
, 1, stream
);
679 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
682 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
683 controls whether to print the symbolic name "raw" or demangled.
684 Global setting "addressprint" controls whether to print hex address
688 print_address_demangle (CORE_ADDR addr
, struct ui_file
*stream
,
693 fprintf_filtered (stream
, "0");
695 else if (addressprint
)
697 deprecated_print_address_numeric (addr
, 1, stream
);
698 print_address_symbolic (addr
, stream
, do_demangle
, " ");
702 print_address_symbolic (addr
, stream
, do_demangle
, "");
707 /* These are the types that $__ will get after an examine command of one
710 static struct type
*examine_i_type
;
712 static struct type
*examine_b_type
;
713 static struct type
*examine_h_type
;
714 static struct type
*examine_w_type
;
715 static struct type
*examine_g_type
;
717 /* Examine data at address ADDR in format FMT.
718 Fetch it from memory and print on gdb_stdout. */
721 do_examine (struct format_data fmt
, CORE_ADDR addr
)
726 struct type
*val_type
= NULL
;
735 /* String or instruction format implies fetch single bytes
736 regardless of the specified size. */
737 if (format
== 's' || format
== 'i')
741 val_type
= examine_i_type
;
742 else if (size
== 'b')
743 val_type
= examine_b_type
;
744 else if (size
== 'h')
745 val_type
= examine_h_type
;
746 else if (size
== 'w')
747 val_type
= examine_w_type
;
748 else if (size
== 'g')
749 val_type
= examine_g_type
;
756 if (format
== 's' || format
== 'i')
759 /* Print as many objects as specified in COUNT, at most maxelts per line,
760 with the address of the next one at the start of each line. */
765 print_address (next_address
, gdb_stdout
);
766 printf_filtered (":");
771 printf_filtered ("\t");
772 /* Note that print_formatted sets next_address for the next
774 last_examine_address
= next_address
;
776 if (last_examine_value
)
777 value_free (last_examine_value
);
779 /* The value to be displayed is not fetched greedily.
780 Instead, to avoid the possibility of a fetched value not
781 being used, its retrieval is delayed until the print code
782 uses it. When examining an instruction stream, the
783 disassembler will perform its own memory fetch using just
784 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
785 the disassembler be modified so that LAST_EXAMINE_VALUE
786 is left with the byte sequence from the last complete
787 instruction fetched from memory? */
788 last_examine_value
= value_at_lazy (val_type
, next_address
);
790 if (last_examine_value
)
791 release_value (last_examine_value
);
793 print_formatted (last_examine_value
, format
, size
, gdb_stdout
);
795 /* Display any branch delay slots following the final insn. */
796 if (format
== 'i' && count
== 1)
797 count
+= branch_delay_insns
;
799 printf_filtered ("\n");
800 gdb_flush (gdb_stdout
);
805 validate_format (struct format_data fmt
, char *cmdname
)
808 error (_("Size letters are meaningless in \"%s\" command."), cmdname
);
810 error (_("Item count other than 1 is meaningless in \"%s\" command."),
812 if (fmt
.format
== 'i' || fmt
.format
== 's')
813 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
814 fmt
.format
, cmdname
);
817 /* Evaluate string EXP as an expression in the current language and
818 print the resulting value. EXP may contain a format specifier as the
819 first argument ("/x myvar" for example, to print myvar in hex). */
822 print_command_1 (char *exp
, int inspect
, int voidprint
)
824 struct expression
*expr
;
825 struct cleanup
*old_chain
= 0;
828 struct format_data fmt
;
831 /* Pass inspect flag to the rest of the print routines in a global
833 inspect_it
= inspect
;
835 if (exp
&& *exp
== '/')
838 fmt
= decode_format (&exp
, last_format
, 0);
839 validate_format (fmt
, "print");
840 last_format
= format
= fmt
.format
;
852 expr
= parse_expression (exp
);
853 old_chain
= make_cleanup (free_current_contents
, &expr
);
855 val
= evaluate_expression (expr
);
858 val
= access_value_history (0);
860 if (voidprint
|| (val
&& value_type (val
) &&
861 TYPE_CODE (value_type (val
)) != TYPE_CODE_VOID
))
863 int histindex
= record_latest_value (val
);
866 annotate_value_history_begin (histindex
, value_type (val
));
868 annotate_value_begin (value_type (val
));
871 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"",
873 else if (histindex
>= 0)
874 printf_filtered ("$%d = ", histindex
);
877 annotate_value_history_value ();
879 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
880 printf_filtered ("\n");
883 annotate_value_history_end ();
885 annotate_value_end ();
888 printf_unfiltered ("\") )\030");
892 do_cleanups (old_chain
);
893 inspect_it
= 0; /* Reset print routines to normal. */
897 print_command (char *exp
, int from_tty
)
899 print_command_1 (exp
, 0, 1);
902 /* Same as print, except in epoch, it gets its own window. */
904 inspect_command (char *exp
, int from_tty
)
906 extern int epoch_interface
;
908 print_command_1 (exp
, epoch_interface
, 1);
911 /* Same as print, except it doesn't print void results. */
913 call_command (char *exp
, int from_tty
)
915 print_command_1 (exp
, 0, 0);
919 output_command (char *exp
, int from_tty
)
921 struct expression
*expr
;
922 struct cleanup
*old_chain
;
925 struct format_data fmt
;
929 if (exp
&& *exp
== '/')
932 fmt
= decode_format (&exp
, 0, 0);
933 validate_format (fmt
, "output");
937 expr
= parse_expression (exp
);
938 old_chain
= make_cleanup (free_current_contents
, &expr
);
940 val
= evaluate_expression (expr
);
942 annotate_value_begin (value_type (val
));
944 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
946 annotate_value_end ();
949 gdb_flush (gdb_stdout
);
951 do_cleanups (old_chain
);
955 set_command (char *exp
, int from_tty
)
957 struct expression
*expr
= parse_expression (exp
);
958 struct cleanup
*old_chain
=
959 make_cleanup (free_current_contents
, &expr
);
960 evaluate_expression (expr
);
961 do_cleanups (old_chain
);
965 sym_info (char *arg
, int from_tty
)
967 struct minimal_symbol
*msymbol
;
968 struct objfile
*objfile
;
969 struct obj_section
*osect
;
971 CORE_ADDR addr
, sect_addr
;
976 error_no_arg (_("address"));
978 addr
= parse_and_eval_address (arg
);
979 ALL_OBJSECTIONS (objfile
, osect
)
981 /* Only process each object file once, even if there's a separate
983 if (objfile
->separate_debug_objfile_backlink
)
986 sect
= osect
->the_bfd_section
;
987 sect_addr
= overlay_mapped_address (addr
, sect
);
989 if (osect
->addr
<= sect_addr
&& sect_addr
< osect
->endaddr
&&
990 (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr
, sect
)))
993 offset
= sect_addr
- SYMBOL_VALUE_ADDRESS (msymbol
);
995 printf_filtered ("%s + %u in ",
996 SYMBOL_PRINT_NAME (msymbol
), offset
);
998 printf_filtered ("%s in ",
999 SYMBOL_PRINT_NAME (msymbol
));
1000 if (pc_in_unmapped_range (addr
, sect
))
1001 printf_filtered (_("load address range of "));
1002 if (section_is_overlay (sect
))
1003 printf_filtered (_("%s overlay "),
1004 section_is_mapped (sect
) ? "mapped" : "unmapped");
1005 printf_filtered (_("section %s"), sect
->name
);
1006 printf_filtered ("\n");
1010 printf_filtered (_("No symbol matches %s.\n"), arg
);
1014 address_info (char *exp
, int from_tty
)
1017 struct minimal_symbol
*msymbol
;
1021 CORE_ADDR load_addr
;
1022 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
1023 if exp is a field of `this'. */
1026 error (_("Argument required."));
1028 sym
= lookup_symbol (exp
, get_selected_block (0), VAR_DOMAIN
,
1029 &is_a_field_of_this
, (struct symtab
**) NULL
);
1032 if (is_a_field_of_this
)
1034 printf_filtered ("Symbol \"");
1035 fprintf_symbol_filtered (gdb_stdout
, exp
,
1036 current_language
->la_language
, DMGL_ANSI
);
1037 printf_filtered ("\" is a field of the local class variable ");
1038 if (current_language
->la_language
== language_objc
)
1039 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1041 printf_filtered ("`this'\n");
1045 msymbol
= lookup_minimal_symbol (exp
, NULL
, NULL
);
1047 if (msymbol
!= NULL
)
1049 load_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
1051 printf_filtered ("Symbol \"");
1052 fprintf_symbol_filtered (gdb_stdout
, exp
,
1053 current_language
->la_language
, DMGL_ANSI
);
1054 printf_filtered ("\" is at ");
1055 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1056 printf_filtered (" in a file compiled without debugging");
1057 section
= SYMBOL_BFD_SECTION (msymbol
);
1058 if (section_is_overlay (section
))
1060 load_addr
= overlay_unmapped_address (load_addr
, section
);
1061 printf_filtered (",\n -- loaded at ");
1062 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1063 printf_filtered (" in overlay section %s", section
->name
);
1065 printf_filtered (".\n");
1068 error (_("No symbol \"%s\" in current context."), exp
);
1072 printf_filtered ("Symbol \"");
1073 fprintf_symbol_filtered (gdb_stdout
, DEPRECATED_SYMBOL_NAME (sym
),
1074 current_language
->la_language
, DMGL_ANSI
);
1075 printf_filtered ("\" is ");
1076 val
= SYMBOL_VALUE (sym
);
1077 basereg
= SYMBOL_BASEREG (sym
);
1078 section
= SYMBOL_BFD_SECTION (sym
);
1080 switch (SYMBOL_CLASS (sym
))
1083 case LOC_CONST_BYTES
:
1084 printf_filtered ("constant");
1088 printf_filtered ("a label at address ");
1089 deprecated_print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1091 if (section_is_overlay (section
))
1093 load_addr
= overlay_unmapped_address (load_addr
, section
);
1094 printf_filtered (",\n -- loaded at ");
1095 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1096 printf_filtered (" in overlay section %s", section
->name
);
1101 case LOC_COMPUTED_ARG
:
1102 /* FIXME: cagney/2004-01-26: It should be possible to
1103 unconditionally call the SYMBOL_OPS method when available.
1104 Unfortunately DWARF 2 stores the frame-base (instead of the
1105 function) location in a function's symbol. Oops! For the
1106 moment enable this when/where applicable. */
1107 SYMBOL_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1111 printf_filtered (_("a variable in register %s"),
1112 gdbarch_register_name (current_gdbarch
, val
));
1116 printf_filtered (_("static storage at address "));
1117 deprecated_print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1119 if (section_is_overlay (section
))
1121 load_addr
= overlay_unmapped_address (load_addr
, section
);
1122 printf_filtered (_(",\n -- loaded at "));
1123 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1124 printf_filtered (_(" in overlay section %s"), section
->name
);
1129 printf_filtered (_("external global (indirect addressing), at address *("));
1130 deprecated_print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1132 printf_filtered (")");
1133 if (section_is_overlay (section
))
1135 load_addr
= overlay_unmapped_address (load_addr
, section
);
1136 printf_filtered (_(",\n -- loaded at "));
1137 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1138 printf_filtered (_(" in overlay section %s"), section
->name
);
1143 printf_filtered (_("an argument in register %s"),
1144 gdbarch_register_name (current_gdbarch
, val
));
1147 case LOC_REGPARM_ADDR
:
1148 printf_filtered (_("address of an argument in register %s"),
1149 gdbarch_register_name (current_gdbarch
, val
));
1153 printf_filtered (_("an argument at offset %ld"), val
);
1157 printf_filtered (_("an argument at frame offset %ld"), val
);
1161 printf_filtered (_("a local variable at frame offset %ld"), val
);
1165 printf_filtered (_("a reference argument at offset %ld"), val
);
1169 printf_filtered (_("a variable at offset %ld from register %s"),
1170 val
, gdbarch_register_name (current_gdbarch
, basereg
));
1173 case LOC_BASEREG_ARG
:
1174 printf_filtered (_("an argument at offset %ld from register %s"),
1175 val
, gdbarch_register_name (current_gdbarch
, basereg
));
1179 printf_filtered (_("a typedef"));
1183 printf_filtered (_("a function at address "));
1184 load_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1185 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1186 if (section_is_overlay (section
))
1188 load_addr
= overlay_unmapped_address (load_addr
, section
);
1189 printf_filtered (_(",\n -- loaded at "));
1190 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1191 printf_filtered (_(" in overlay section %s"), section
->name
);
1195 case LOC_UNRESOLVED
:
1197 struct minimal_symbol
*msym
;
1199 msym
= lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym
), NULL
, NULL
);
1201 printf_filtered ("unresolved");
1204 section
= SYMBOL_BFD_SECTION (msym
);
1205 printf_filtered (_("static storage at address "));
1206 load_addr
= SYMBOL_VALUE_ADDRESS (msym
);
1207 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1208 if (section_is_overlay (section
))
1210 load_addr
= overlay_unmapped_address (load_addr
, section
);
1211 printf_filtered (_(",\n -- loaded at "));
1212 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1213 printf_filtered (_(" in overlay section %s"), section
->name
);
1219 case LOC_HP_THREAD_LOCAL_STATIC
:
1220 printf_filtered (_("\
1221 a thread-local variable at offset %ld from the thread base register %s"),
1222 val
, gdbarch_register_name (current_gdbarch
, basereg
));
1225 case LOC_OPTIMIZED_OUT
:
1226 printf_filtered (_("optimized out"));
1230 printf_filtered (_("of unknown (botched) type"));
1233 printf_filtered (".\n");
1238 x_command (char *exp
, int from_tty
)
1240 struct expression
*expr
;
1241 struct format_data fmt
;
1242 struct cleanup
*old_chain
;
1245 fmt
.format
= last_format
;
1246 fmt
.size
= last_size
;
1249 if (exp
&& *exp
== '/')
1252 fmt
= decode_format (&exp
, last_format
, last_size
);
1255 /* If we have an expression, evaluate it and use it as the address. */
1257 if (exp
!= 0 && *exp
!= 0)
1259 expr
= parse_expression (exp
);
1260 /* Cause expression not to be there any more if this command is
1261 repeated with Newline. But don't clobber a user-defined
1262 command's definition. */
1265 old_chain
= make_cleanup (free_current_contents
, &expr
);
1266 val
= evaluate_expression (expr
);
1267 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_REF
)
1268 val
= value_ind (val
);
1269 /* In rvalue contexts, such as this, functions are coerced into
1270 pointers to functions. This makes "x/i main" work. */
1271 if (/* last_format == 'i' && */
1272 TYPE_CODE (value_type (val
)) == TYPE_CODE_FUNC
1273 && VALUE_LVAL (val
) == lval_memory
)
1274 next_address
= VALUE_ADDRESS (val
);
1276 next_address
= value_as_address (val
);
1277 do_cleanups (old_chain
);
1280 do_examine (fmt
, next_address
);
1282 /* If the examine succeeds, we remember its size and format for next
1284 last_size
= fmt
.size
;
1285 last_format
= fmt
.format
;
1287 /* Set a couple of internal variables if appropriate. */
1288 if (last_examine_value
)
1290 /* Make last address examined available to the user as $_. Use
1291 the correct pointer type. */
1292 struct type
*pointer_type
1293 = lookup_pointer_type (value_type (last_examine_value
));
1294 set_internalvar (lookup_internalvar ("_"),
1295 value_from_pointer (pointer_type
,
1296 last_examine_address
));
1298 /* Make contents of last address examined available to the user
1299 as $__. If the last value has not been fetched from memory
1300 then don't fetch it now; instead mark it by voiding the $__
1302 if (value_lazy (last_examine_value
))
1303 set_internalvar (lookup_internalvar ("__"),
1304 allocate_value (builtin_type_void
));
1306 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1311 /* Add an expression to the auto-display chain.
1312 Specify the expression. */
1315 display_command (char *exp
, int from_tty
)
1317 struct format_data fmt
;
1318 struct expression
*expr
;
1319 struct display
*new;
1323 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1325 if (tui_active
&& exp
!= NULL
&& *exp
== '$')
1326 display_it
= (tui_set_layout_for_display_command (exp
) == TUI_FAILURE
);
1340 fmt
= decode_format (&exp
, 0, 0);
1341 if (fmt
.size
&& fmt
.format
== 0)
1343 if (fmt
.format
== 'i' || fmt
.format
== 's')
1353 innermost_block
= 0;
1354 expr
= parse_expression (exp
);
1356 new = (struct display
*) xmalloc (sizeof (struct display
));
1359 new->block
= innermost_block
;
1360 new->next
= display_chain
;
1361 new->number
= ++display_number
;
1364 display_chain
= new;
1366 if (from_tty
&& target_has_execution
)
1367 do_one_display (new);
1374 free_display (struct display
*d
)
1380 /* Clear out the display_chain. Done when new symtabs are loaded,
1381 since this invalidates the types stored in many expressions. */
1384 clear_displays (void)
1388 while ((d
= display_chain
) != NULL
)
1391 display_chain
= d
->next
;
1396 /* Delete the auto-display number NUM. */
1399 delete_display (int num
)
1401 struct display
*d1
, *d
;
1404 error (_("No display number %d."), num
);
1406 if (display_chain
->number
== num
)
1409 display_chain
= d1
->next
;
1413 for (d
= display_chain
;; d
= d
->next
)
1416 error (_("No display number %d."), num
);
1417 if (d
->next
->number
== num
)
1427 /* Delete some values from the auto-display chain.
1428 Specify the element numbers. */
1431 undisplay_command (char *args
, int from_tty
)
1439 if (query ("Delete all auto-display expressions? "))
1448 while (*p1
>= '0' && *p1
<= '9')
1450 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1451 error (_("Arguments must be display numbers."));
1455 delete_display (num
);
1458 while (*p
== ' ' || *p
== '\t')
1464 /* Display a single auto-display.
1465 Do nothing if the display cannot be printed in the current context,
1466 or if the display is disabled. */
1469 do_one_display (struct display
*d
)
1471 int within_current_scope
;
1473 if (d
->enabled_p
== 0)
1477 within_current_scope
= contained_in (get_selected_block (0), d
->block
);
1479 within_current_scope
= 1;
1480 if (!within_current_scope
)
1483 current_display_number
= d
->number
;
1485 annotate_display_begin ();
1486 printf_filtered ("%d", d
->number
);
1487 annotate_display_number_end ();
1488 printf_filtered (": ");
1494 annotate_display_format ();
1496 printf_filtered ("x/");
1497 if (d
->format
.count
!= 1)
1498 printf_filtered ("%d", d
->format
.count
);
1499 printf_filtered ("%c", d
->format
.format
);
1500 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1501 printf_filtered ("%c", d
->format
.size
);
1502 printf_filtered (" ");
1504 annotate_display_expression ();
1506 print_expression (d
->exp
, gdb_stdout
);
1507 annotate_display_expression_end ();
1509 if (d
->format
.count
!= 1 || d
->format
.format
== 'i')
1510 printf_filtered ("\n");
1512 printf_filtered (" ");
1514 val
= evaluate_expression (d
->exp
);
1515 addr
= value_as_address (val
);
1516 if (d
->format
.format
== 'i')
1517 addr
= gdbarch_addr_bits_remove (current_gdbarch
, addr
);
1519 annotate_display_value ();
1521 do_examine (d
->format
, addr
);
1525 annotate_display_format ();
1527 if (d
->format
.format
)
1528 printf_filtered ("/%c ", d
->format
.format
);
1530 annotate_display_expression ();
1532 print_expression (d
->exp
, gdb_stdout
);
1533 annotate_display_expression_end ();
1535 printf_filtered (" = ");
1537 annotate_display_expression ();
1539 print_formatted (evaluate_expression (d
->exp
),
1540 d
->format
.format
, d
->format
.size
, gdb_stdout
);
1541 printf_filtered ("\n");
1544 annotate_display_end ();
1546 gdb_flush (gdb_stdout
);
1547 current_display_number
= -1;
1550 /* Display all of the values on the auto-display chain which can be
1551 evaluated in the current scope. */
1558 for (d
= display_chain
; d
; d
= d
->next
)
1562 /* Delete the auto-display which we were in the process of displaying.
1563 This is done when there is an error or a signal. */
1566 disable_display (int num
)
1570 for (d
= display_chain
; d
; d
= d
->next
)
1571 if (d
->number
== num
)
1576 printf_unfiltered (_("No display number %d.\n"), num
);
1580 disable_current_display (void)
1582 if (current_display_number
>= 0)
1584 disable_display (current_display_number
);
1585 fprintf_unfiltered (gdb_stderr
, _("\
1586 Disabling display %d to avoid infinite recursion.\n"),
1587 current_display_number
);
1589 current_display_number
= -1;
1593 display_info (char *ignore
, int from_tty
)
1598 printf_unfiltered (_("There are no auto-display expressions now.\n"));
1600 printf_filtered (_("Auto-display expressions now in effect:\n\
1601 Num Enb Expression\n"));
1603 for (d
= display_chain
; d
; d
= d
->next
)
1605 printf_filtered ("%d: %c ", d
->number
, "ny"[(int) d
->enabled_p
]);
1607 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1609 else if (d
->format
.format
)
1610 printf_filtered ("/%c ", d
->format
.format
);
1611 print_expression (d
->exp
, gdb_stdout
);
1612 if (d
->block
&& !contained_in (get_selected_block (0), d
->block
))
1613 printf_filtered (_(" (cannot be evaluated in the current context)"));
1614 printf_filtered ("\n");
1615 gdb_flush (gdb_stdout
);
1620 enable_display (char *args
, int from_tty
)
1629 for (d
= display_chain
; d
; d
= d
->next
)
1636 while (*p1
>= '0' && *p1
<= '9')
1638 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1639 error (_("Arguments must be display numbers."));
1643 for (d
= display_chain
; d
; d
= d
->next
)
1644 if (d
->number
== num
)
1649 printf_unfiltered (_("No display number %d.\n"), num
);
1652 while (*p
== ' ' || *p
== '\t')
1658 disable_display_command (char *args
, int from_tty
)
1666 for (d
= display_chain
; d
; d
= d
->next
)
1673 while (*p1
>= '0' && *p1
<= '9')
1675 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1676 error (_("Arguments must be display numbers."));
1678 disable_display (atoi (p
));
1681 while (*p
== ' ' || *p
== '\t')
1687 /* Print the value in stack frame FRAME of a variable specified by a
1691 print_variable_value (struct symbol
*var
, struct frame_info
*frame
,
1692 struct ui_file
*stream
)
1694 struct value
*val
= read_var_value (var
, frame
);
1696 value_print (val
, stream
, 0, Val_pretty_default
);
1700 printf_command (char *arg
, int from_tty
)
1704 char *string
= NULL
;
1705 struct value
**val_args
;
1707 char *current_substring
;
1709 int allocated_args
= 20;
1710 struct cleanup
*old_cleanups
;
1712 val_args
= xmalloc (allocated_args
* sizeof (struct value
*));
1713 old_cleanups
= make_cleanup (free_current_contents
, &val_args
);
1716 error_no_arg (_("format-control string and values to print"));
1718 /* Skip white space before format string */
1719 while (*s
== ' ' || *s
== '\t')
1722 /* A format string should follow, enveloped in double quotes. */
1724 error (_("Bad format string, missing '\"'."));
1726 /* Parse the format-control string and copy it into the string STRING,
1727 processing some kinds of escape sequence. */
1729 f
= string
= (char *) alloca (strlen (s
) + 1);
1737 error (_("Bad format string, non-terminated '\"'."));
1770 /* ??? TODO: handle other escape sequences */
1771 error (_("Unrecognized escape character \\%c in format string."),
1781 /* Skip over " and following space and comma. */
1784 while (*s
== ' ' || *s
== '\t')
1787 if (*s
!= ',' && *s
!= 0)
1788 error (_("Invalid argument syntax"));
1792 while (*s
== ' ' || *s
== '\t')
1795 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1796 substrings
= alloca (strlen (string
) * 2);
1797 current_substring
= substrings
;
1800 /* Now scan the string for %-specs and see what kinds of args they want.
1801 argclass[I] classifies the %-specs so we can give printf_filtered
1802 something of the right size. */
1806 int_arg
, long_arg
, long_long_arg
, ptr_arg
, string_arg
,
1807 double_arg
, long_double_arg
1809 enum argclass
*argclass
;
1810 enum argclass this_argclass
;
1815 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1822 int seen_hash
= 0, seen_zero
= 0, lcount
= 0, seen_prec
= 0;
1823 int seen_space
= 0, seen_plus
= 0;
1824 int seen_big_l
= 0, seen_h
= 0;
1827 /* Check the validity of the format specifier, and work
1828 out what argument it expects. We only accept C89
1829 format strings, with the exception of long long (which
1830 we autoconf for). */
1832 /* Skip over "%%". */
1839 /* The first part of a format specifier is a set of flag
1841 while (strchr ("0-+ #", *f
))
1854 /* The next part of a format specifier is a width. */
1855 while (strchr ("0123456789", *f
))
1858 /* The next part of a format specifier is a precision. */
1863 while (strchr ("0123456789", *f
))
1867 /* The next part of a format specifier is a length modifier. */
1899 if (seen_space
|| seen_plus
)
1906 this_argclass
= int_arg
;
1907 else if (lcount
== 1)
1908 this_argclass
= long_arg
;
1910 this_argclass
= long_long_arg
;
1917 this_argclass
= int_arg
;
1918 if (lcount
|| seen_h
|| seen_big_l
)
1920 if (seen_prec
|| seen_zero
|| seen_space
|| seen_plus
)
1925 this_argclass
= ptr_arg
;
1926 if (lcount
|| seen_h
|| seen_big_l
)
1928 if (seen_prec
|| seen_zero
|| seen_space
|| seen_plus
)
1933 this_argclass
= string_arg
;
1934 if (lcount
|| seen_h
|| seen_big_l
)
1936 if (seen_zero
|| seen_space
|| seen_plus
)
1946 this_argclass
= long_double_arg
;
1948 this_argclass
= double_arg
;
1950 if (lcount
|| seen_h
)
1955 error (_("`*' not supported for precision or width in printf"));
1958 error (_("Format specifier `n' not supported in printf"));
1961 error (_("Incomplete format specifier at end of format string"));
1964 error (_("Unrecognized format specifier '%c' in printf"), *f
);
1968 error (_("Inappropriate modifiers to format specifier '%c' in printf"),
1972 strncpy (current_substring
, last_arg
, f
- last_arg
);
1973 current_substring
+= f
- last_arg
;
1974 *current_substring
++ = '\0';
1976 argclass
[nargs_wanted
++] = this_argclass
;
1979 /* Now, parse all arguments and evaluate them.
1980 Store the VALUEs in VAL_ARGS. */
1985 if (nargs
== allocated_args
)
1986 val_args
= (struct value
**) xrealloc ((char *) val_args
,
1987 (allocated_args
*= 2)
1988 * sizeof (struct value
*));
1990 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
1992 /* If format string wants a float, unchecked-convert the value to
1993 floating point of the same size */
1995 if (argclass
[nargs
] == double_arg
)
1997 struct type
*type
= value_type (val_args
[nargs
]);
1998 if (TYPE_LENGTH (type
) == sizeof (float))
1999 deprecated_set_value_type (val_args
[nargs
], builtin_type_float
);
2000 if (TYPE_LENGTH (type
) == sizeof (double))
2001 deprecated_set_value_type (val_args
[nargs
], builtin_type_double
);
2009 if (nargs
!= nargs_wanted
)
2010 error (_("Wrong number of arguments for specified format-string"));
2012 /* Now actually print them. */
2013 current_substring
= substrings
;
2014 for (i
= 0; i
< nargs
; i
++)
2016 switch (argclass
[i
])
2023 tem
= value_as_address (val_args
[i
]);
2025 /* This is a %s argument. Find the length of the string. */
2030 read_memory (tem
+ j
, &c
, 1);
2035 /* Copy the string contents into a string inside GDB. */
2036 str
= (gdb_byte
*) alloca (j
+ 1);
2038 read_memory (tem
, str
, j
);
2041 printf_filtered (current_substring
, (char *) str
);
2046 double val
= value_as_double (val_args
[i
]);
2047 printf_filtered (current_substring
, val
);
2050 case long_double_arg
:
2051 #ifdef HAVE_LONG_DOUBLE
2053 long double val
= value_as_double (val_args
[i
]);
2054 printf_filtered (current_substring
, val
);
2058 error (_("long double not supported in printf"));
2061 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2063 long long val
= value_as_long (val_args
[i
]);
2064 printf_filtered (current_substring
, val
);
2068 error (_("long long not supported in printf"));
2072 int val
= value_as_long (val_args
[i
]);
2073 printf_filtered (current_substring
, val
);
2078 long val
= value_as_long (val_args
[i
]);
2079 printf_filtered (current_substring
, val
);
2084 /* We avoid the host's %p because pointers are too
2085 likely to be the wrong size. The only interesting
2086 modifier for %p is a width; extract that, and then
2087 handle %p as glibc would: %#x or a literal "(nil)". */
2089 char *p
, *fmt
, *fmt_p
;
2090 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2091 long long val
= value_as_long (val_args
[i
]);
2093 long val
= value_as_long (val_args
[i
]);
2096 fmt
= alloca (strlen (current_substring
) + 5);
2098 /* Copy up to the leading %. */
2099 p
= current_substring
;
2103 int is_percent
= (*p
== '%');
2117 /* Copy any width. */
2118 while (*p
>= '0' && *p
< '9')
2121 gdb_assert (*p
== 'p' && *(p
+ 1) == '\0');
2124 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2130 printf_filtered (fmt
, val
);
2136 printf_filtered (fmt
, "(nil)");
2142 internal_error (__FILE__
, __LINE__
,
2143 _("failed internal consistency check"));
2145 /* Skip to the next substring. */
2146 current_substring
+= strlen (current_substring
) + 1;
2148 /* Print the portion of the format string after the last argument. */
2149 puts_filtered (last_arg
);
2151 do_cleanups (old_cleanups
);
2155 _initialize_printcmd (void)
2157 struct cmd_list_element
*c
;
2159 current_display_number
= -1;
2161 add_info ("address", address_info
,
2162 _("Describe where symbol SYM is stored."));
2164 add_info ("symbol", sym_info
, _("\
2165 Describe what symbol is at location ADDR.\n\
2166 Only for symbols with fixed locations (global or static scope)."));
2168 add_com ("x", class_vars
, x_command
, _("\
2169 Examine memory: x/FMT ADDRESS.\n\
2170 ADDRESS is an expression for the memory address to examine.\n\
2171 FMT is a repeat count followed by a format letter and a size letter.\n\
2172 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2173 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2174 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2175 The specified number of objects of the specified size are printed\n\
2176 according to the format.\n\n\
2177 Defaults for format and size letters are those previously used.\n\
2178 Default count is 1. Default address is following last thing printed\n\
2179 with this command or \"print\"."));
2182 add_com ("whereis", class_vars
, whereis_command
,
2183 _("Print line number and file of definition of variable."));
2186 add_info ("display", display_info
, _("\
2187 Expressions to display when program stops, with code numbers."));
2189 add_cmd ("undisplay", class_vars
, undisplay_command
, _("\
2190 Cancel some expressions to be displayed when program stops.\n\
2191 Arguments are the code numbers of the expressions to stop displaying.\n\
2192 No argument means cancel all automatic-display expressions.\n\
2193 \"delete display\" has the same effect as this command.\n\
2194 Do \"info display\" to see current list of code numbers."),
2197 add_com ("display", class_vars
, display_command
, _("\
2198 Print value of expression EXP each time the program stops.\n\
2199 /FMT may be used before EXP as in the \"print\" command.\n\
2200 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2201 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2202 and examining is done as in the \"x\" command.\n\n\
2203 With no argument, display all currently requested auto-display expressions.\n\
2204 Use \"undisplay\" to cancel display requests previously made."));
2206 add_cmd ("display", class_vars
, enable_display
, _("\
2207 Enable some expressions to be displayed when program stops.\n\
2208 Arguments are the code numbers of the expressions to resume displaying.\n\
2209 No argument means enable all automatic-display expressions.\n\
2210 Do \"info display\" to see current list of code numbers."), &enablelist
);
2212 add_cmd ("display", class_vars
, disable_display_command
, _("\
2213 Disable some expressions to be displayed when program stops.\n\
2214 Arguments are the code numbers of the expressions to stop displaying.\n\
2215 No argument means disable all automatic-display expressions.\n\
2216 Do \"info display\" to see current list of code numbers."), &disablelist
);
2218 add_cmd ("display", class_vars
, undisplay_command
, _("\
2219 Cancel some expressions to be displayed when program stops.\n\
2220 Arguments are the code numbers of the expressions to stop displaying.\n\
2221 No argument means cancel all automatic-display expressions.\n\
2222 Do \"info display\" to see current list of code numbers."), &deletelist
);
2224 add_com ("printf", class_vars
, printf_command
, _("\
2225 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2226 This is useful for formatted output in user-defined commands."));
2228 add_com ("output", class_vars
, output_command
, _("\
2229 Like \"print\" but don't put in value history and don't print newline.\n\
2230 This is useful in user-defined commands."));
2232 add_prefix_cmd ("set", class_vars
, set_command
, _("\
2233 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2234 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2235 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2236 with $), a register (a few standard names starting with $), or an actual\n\
2237 variable in the program being debugged. EXP is any valid expression.\n\
2238 Use \"set variable\" for variables with names identical to set subcommands.\n\
2240 With a subcommand, this command modifies parts of the gdb environment.\n\
2241 You can see these environment settings with the \"show\" command."),
2242 &setlist
, "set ", 1, &cmdlist
);
2244 add_com ("assign", class_vars
, set_command
, _("\
2245 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2246 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2247 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2248 with $), a register (a few standard names starting with $), or an actual\n\
2249 variable in the program being debugged. EXP is any valid expression.\n\
2250 Use \"set variable\" for variables with names identical to set subcommands.\n\
2251 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2252 You can see these environment settings with the \"show\" command."));
2254 /* "call" is the same as "set", but handy for dbx users to call fns. */
2255 c
= add_com ("call", class_vars
, call_command
, _("\
2256 Call a function in the program.\n\
2257 The argument is the function name and arguments, in the notation of the\n\
2258 current working language. The result is printed and saved in the value\n\
2259 history, if it is not void."));
2260 set_cmd_completer (c
, location_completer
);
2262 add_cmd ("variable", class_vars
, set_command
, _("\
2263 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2264 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2265 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2266 with $), a register (a few standard names starting with $), or an actual\n\
2267 variable in the program being debugged. EXP is any valid expression.\n\
2268 This may usually be abbreviated to simply \"set\"."),
2271 c
= add_com ("print", class_vars
, print_command
, _("\
2272 Print value of expression EXP.\n\
2273 Variables accessible are those of the lexical environment of the selected\n\
2274 stack frame, plus all those whose scope is global or an entire file.\n\
2276 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2277 $$NUM refers to NUM'th value back from the last one.\n\
2278 Names starting with $ refer to registers (with the values they would have\n\
2279 if the program were to return to the stack frame now selected, restoring\n\
2280 all registers saved by frames farther in) or else to debugger\n\
2281 \"convenience\" variables (any such name not a known register).\n\
2282 Use assignment expressions to give values to convenience variables.\n\
2284 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2285 @ is a binary operator for treating consecutive data objects\n\
2286 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2287 element is FOO, whose second element is stored in the space following\n\
2288 where FOO is stored, etc. FOO must be an expression whose value\n\
2289 resides in memory.\n\
2291 EXP may be preceded with /FMT, where FMT is a format letter\n\
2292 but no count or size letter (see \"x\" command)."));
2293 set_cmd_completer (c
, location_completer
);
2294 add_com_alias ("p", "print", class_vars
, 1);
2296 c
= add_com ("inspect", class_vars
, inspect_command
, _("\
2297 Same as \"print\" command, except that if you are running in the epoch\n\
2298 environment, the value is printed in its own window."));
2299 set_cmd_completer (c
, location_completer
);
2301 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class
,
2302 &max_symbolic_offset
, _("\
2303 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2304 Show the largest offset that will be printed in <symbol+1234> form."), NULL
,
2306 show_max_symbolic_offset
,
2307 &setprintlist
, &showprintlist
);
2308 add_setshow_boolean_cmd ("symbol-filename", no_class
,
2309 &print_symbol_filename
, _("\
2310 Set printing of source filename and line number with <symbol>."), _("\
2311 Show printing of source filename and line number with <symbol>."), NULL
,
2313 show_print_symbol_filename
,
2314 &setprintlist
, &showprintlist
);
2316 /* For examine/instruction a single byte quantity is specified as
2317 the data. This avoids problems with value_at_lazy() requiring a
2318 valid data type (and rejecting VOID). */
2319 examine_i_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_i_type", NULL
);
2321 examine_b_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_b_type", NULL
);
2322 examine_h_type
= init_type (TYPE_CODE_INT
, 2, 0, "examine_h_type", NULL
);
2323 examine_w_type
= init_type (TYPE_CODE_INT
, 4, 0, "examine_w_type", NULL
);
2324 examine_g_type
= init_type (TYPE_CODE_INT
, 8, 0, "examine_g_type", NULL
);