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 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
25 #include "gdb_string.h"
31 #include "expression.h"
35 #include "breakpoint.h"
39 #include "symfile.h" /* for overlay functions */
40 #include "objfiles.h" /* ditto */
41 #include "completer.h" /* for completion functions */
43 #include "gdb_assert.h"
48 #include "tui/tui.h" /* For tui_active et.al. */
51 extern int asm_demangle
; /* Whether to demangle syms in asm printouts */
52 extern int addressprint
; /* Whether to print hex addresses in HLL " */
61 /* Last specified output format. */
63 static char last_format
= 'x';
65 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
67 static char last_size
= 'w';
69 /* Default address to examine next. */
71 static CORE_ADDR next_address
;
73 /* Number of delay instructions following current disassembled insn. */
75 static int branch_delay_insns
;
77 /* Last address examined. */
79 static CORE_ADDR last_examine_address
;
81 /* Contents of last address examined.
82 This is not valid past the end of the `x' command! */
84 static struct value
*last_examine_value
;
86 /* Largest offset between a symbolic value and an address, that will be
87 printed as `0x1234 <symbol+offset>'. */
89 static unsigned int max_symbolic_offset
= UINT_MAX
;
91 show_max_symbolic_offset (struct ui_file
*file
, int from_tty
,
92 struct cmd_list_element
*c
, const char *value
)
94 fprintf_filtered (file
, _("\
95 The largest offset that will be printed in <symbol+1234> form is %s.\n"),
99 /* Append the source filename and linenumber of the symbol when
100 printing a symbolic value as `<symbol at filename:linenum>' if set. */
101 static int print_symbol_filename
= 0;
103 show_print_symbol_filename (struct ui_file
*file
, int from_tty
,
104 struct cmd_list_element
*c
, const char *value
)
106 fprintf_filtered (file
, _("\
107 Printing of source filename and line number with <symbol> is %s.\n"),
111 /* Number of auto-display expression currently being displayed.
112 So that we can disable it if we get an error or a signal within it.
113 -1 when not doing one. */
115 int current_display_number
;
117 /* Flag to low-level print routines that this value is being printed
118 in an epoch window. We'd like to pass this as a parameter, but
119 every routine would need to take it. Perhaps we can encapsulate
120 this in the I/O stream once we have GNU stdio. */
126 /* Chain link to next auto-display item. */
127 struct display
*next
;
128 /* Expression to be evaluated and displayed. */
129 struct expression
*exp
;
130 /* Item number of this auto-display item. */
132 /* Display format specified. */
133 struct format_data format
;
134 /* Innermost block required by this expression when evaluated */
136 /* Status of this display (enabled or disabled) */
140 /* Chain of expressions whose values should be displayed
141 automatically each time the program stops. */
143 static struct display
*display_chain
;
145 static int display_number
;
147 /* Prototypes for exported functions. */
149 void output_command (char *, int);
151 void _initialize_printcmd (void);
153 /* Prototypes for local functions. */
155 static void do_one_display (struct display
*);
158 /* Decode a format specification. *STRING_PTR should point to it.
159 OFORMAT and OSIZE are used as defaults for the format and size
160 if none are given in the format specification.
161 If OSIZE is zero, then the size field of the returned value
162 should be set only if a size is explicitly specified by the
164 The structure returned describes all the data
165 found in the specification. In addition, *STRING_PTR is advanced
166 past the specification and past all whitespace following it. */
168 static struct format_data
169 decode_format (char **string_ptr
, int oformat
, int osize
)
171 struct format_data val
;
172 char *p
= *string_ptr
;
178 if (*p
>= '0' && *p
<= '9')
179 val
.count
= atoi (p
);
180 while (*p
>= '0' && *p
<= '9')
183 /* Now process size or format letters that follow. */
187 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
189 else if (*p
>= 'a' && *p
<= 'z')
195 while (*p
== ' ' || *p
== '\t')
199 /* Set defaults for format and size if not specified. */
200 if (val
.format
== '?')
204 /* Neither has been specified. */
205 val
.format
= oformat
;
209 /* If a size is specified, any format makes a reasonable
210 default except 'i'. */
211 val
.format
= oformat
== 'i' ? 'x' : oformat
;
213 else if (val
.size
== '?')
218 /* Pick the appropriate size for an address. */
219 if (gdbarch_ptr_bit (current_gdbarch
) == 64)
220 val
.size
= osize
? 'g' : osize
;
221 else if (gdbarch_ptr_bit (current_gdbarch
) == 32)
222 val
.size
= osize
? 'w' : osize
;
223 else if (gdbarch_ptr_bit (current_gdbarch
) == 16)
224 val
.size
= osize
? 'h' : osize
;
226 /* Bad value for gdbarch_ptr_bit. */
227 internal_error (__FILE__
, __LINE__
,
228 _("failed internal consistency check"));
231 /* Floating point has to be word or giantword. */
232 if (osize
== 'w' || osize
== 'g')
235 /* Default it to giantword if the last used size is not
237 val
.size
= osize
? 'g' : osize
;
240 /* Characters default to one byte. */
241 val
.size
= osize
? 'b' : osize
;
244 /* The default is the size most recently specified. */
251 /* Print value VAL on stream according to FORMAT, a letter or 0.
252 Do not end with a newline.
253 0 means print VAL according to its own type.
254 SIZE is the letter for the size of datum being printed.
255 This is used to pad hex numbers so they line up. */
258 print_formatted (struct value
*val
, int format
, int size
,
259 struct ui_file
*stream
)
261 struct type
*type
= check_typedef (value_type (val
));
262 int len
= TYPE_LENGTH (type
);
264 if (VALUE_LVAL (val
) == lval_memory
)
265 next_address
= VALUE_ADDRESS (val
) + len
;
270 /* FIXME: Need to handle wchar_t's here... */
271 next_address
= VALUE_ADDRESS (val
)
272 + val_print_string (VALUE_ADDRESS (val
), -1, 1, stream
);
276 /* The old comment says
277 "Force output out, print_insn not using _filtered".
278 I'm not completely sure what that means, I suspect most print_insn
279 now do use _filtered, so I guess it's obsolete.
280 --Yes, it does filter now, and so this is obsolete. -JB */
282 /* We often wrap here if there are long symbolic names. */
284 next_address
= (VALUE_ADDRESS (val
)
285 + gdb_print_insn (VALUE_ADDRESS (val
), stream
,
286 &branch_delay_insns
));
291 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
292 || TYPE_CODE (type
) == TYPE_CODE_STRING
293 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
294 || TYPE_CODE (type
) == TYPE_CODE_UNION
295 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
296 /* If format is 0, use the 'natural' format for that type of
297 value. If the type is non-scalar, we have to use language
298 rules to print it as a series of scalars. */
299 value_print (val
, stream
, format
, Val_pretty_default
);
301 /* User specified format, so don't look to the the type to
302 tell us what to do. */
303 print_scalar_formatted (value_contents (val
), type
,
304 format
, size
, stream
);
308 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
309 according to letters FORMAT and SIZE on STREAM.
310 FORMAT may not be zero. Formats s and i are not supported at this level.
312 This is how the elements of an array or structure are printed
316 print_scalar_formatted (const void *valaddr
, struct type
*type
,
317 int format
, int size
, struct ui_file
*stream
)
319 LONGEST val_long
= 0;
320 unsigned int len
= TYPE_LENGTH (type
);
322 if (len
> sizeof(LONGEST
) &&
323 (TYPE_CODE (type
) == TYPE_CODE_INT
324 || TYPE_CODE (type
) == TYPE_CODE_ENUM
))
329 print_octal_chars (stream
, valaddr
, len
);
333 print_decimal_chars (stream
, valaddr
, len
);
336 print_binary_chars (stream
, valaddr
, len
);
339 print_hex_chars (stream
, valaddr
, len
);
342 print_char_chars (stream
, valaddr
, len
);
350 val_long
= unpack_long (type
, valaddr
);
352 /* If the value is a pointer, and pointers and addresses are not the
353 same, then at this point, the value's length (in target bytes) is
354 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
355 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
356 len
= gdbarch_addr_bit (current_gdbarch
) / TARGET_CHAR_BIT
;
358 /* If we are printing it as unsigned, truncate it in case it is actually
359 a negative signed value (e.g. "print/u (short)-1" should print 65535
360 (if shorts are 16 bits) instead of 4294967295). */
363 if (len
< sizeof (LONGEST
))
364 val_long
&= ((LONGEST
) 1 << HOST_CHAR_BIT
* len
) - 1;
372 /* No size specified, like in print. Print varying # of digits. */
373 print_longest (stream
, 'x', 1, val_long
);
382 print_longest (stream
, size
, 1, val_long
);
385 error (_("Undefined output size \"%c\"."), size
);
390 print_longest (stream
, 'd', 1, val_long
);
394 print_longest (stream
, 'u', 0, val_long
);
399 print_longest (stream
, 'o', 1, val_long
);
401 fprintf_filtered (stream
, "0");
406 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
407 print_address (addr
, stream
);
412 value_print (value_from_longest (builtin_type_true_char
, val_long
),
413 stream
, 0, Val_pretty_default
);
417 if (len
== TYPE_LENGTH (builtin_type_float
))
418 type
= builtin_type_float
;
419 else if (len
== TYPE_LENGTH (builtin_type_double
))
420 type
= builtin_type_double
;
421 else if (len
== TYPE_LENGTH (builtin_type_long_double
))
422 type
= builtin_type_long_double
;
423 print_floating (valaddr
, type
, stream
);
427 internal_error (__FILE__
, __LINE__
,
428 _("failed internal consistency check"));
431 /* Binary; 't' stands for "two". */
433 char bits
[8 * (sizeof val_long
) + 1];
434 char buf
[8 * (sizeof val_long
) + 32];
439 width
= 8 * (sizeof val_long
);
456 error (_("Undefined output size \"%c\"."), size
);
462 bits
[width
] = (val_long
& 1) ? '1' : '0';
467 while (*cp
&& *cp
== '0')
473 fputs_filtered (buf
, stream
);
478 error (_("Undefined output format \"%c\"."), format
);
482 /* Specify default address for `x' command.
483 The `info lines' command uses this. */
486 set_next_address (CORE_ADDR addr
)
490 /* Make address available to the user as $_. */
491 set_internalvar (lookup_internalvar ("_"),
492 value_from_pointer (lookup_pointer_type (builtin_type_void
),
496 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
497 after LEADIN. Print nothing if no symbolic name is found nearby.
498 Optionally also print source file and line number, if available.
499 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
500 or to interpret it as a possible C++ name and convert it back to source
501 form. However note that DO_DEMANGLE can be overridden by the specific
502 settings of the demangle and asm_demangle variables. */
505 print_address_symbolic (CORE_ADDR addr
, struct ui_file
*stream
,
506 int do_demangle
, char *leadin
)
509 char *filename
= NULL
;
514 /* Throw away both name and filename. */
515 struct cleanup
*cleanup_chain
= make_cleanup (free_current_contents
, &name
);
516 make_cleanup (free_current_contents
, &filename
);
518 if (build_address_symbolic (addr
, do_demangle
, &name
, &offset
,
519 &filename
, &line
, &unmapped
))
521 do_cleanups (cleanup_chain
);
525 fputs_filtered (leadin
, stream
);
527 fputs_filtered ("<*", stream
);
529 fputs_filtered ("<", stream
);
530 fputs_filtered (name
, stream
);
532 fprintf_filtered (stream
, "+%u", (unsigned int) offset
);
534 /* Append source filename and line number if desired. Give specific
535 line # of this addr, if we have it; else line # of the nearest symbol. */
536 if (print_symbol_filename
&& filename
!= NULL
)
539 fprintf_filtered (stream
, " at %s:%d", filename
, line
);
541 fprintf_filtered (stream
, " in %s", filename
);
544 fputs_filtered ("*>", stream
);
546 fputs_filtered (">", stream
);
548 do_cleanups (cleanup_chain
);
551 /* Given an address ADDR return all the elements needed to print the
552 address in a symbolic form. NAME can be mangled or not depending
553 on DO_DEMANGLE (and also on the asm_demangle global variable,
554 manipulated via ''set print asm-demangle''). Return 0 in case of
555 success, when all the info in the OUT paramters is valid. Return 1
558 build_address_symbolic (CORE_ADDR addr
, /* IN */
559 int do_demangle
, /* IN */
560 char **name
, /* OUT */
561 int *offset
, /* OUT */
562 char **filename
, /* OUT */
564 int *unmapped
) /* OUT */
566 struct minimal_symbol
*msymbol
;
567 struct symbol
*symbol
;
568 CORE_ADDR name_location
= 0;
569 asection
*section
= 0;
570 char *name_temp
= "";
572 /* Let's say it is unmapped. */
575 /* Determine if the address is in an overlay, and whether it is
577 if (overlay_debugging
)
579 section
= find_pc_overlay (addr
);
580 if (pc_in_unmapped_range (addr
, section
))
583 addr
= overlay_mapped_address (addr
, section
);
587 /* First try to find the address in the symbol table, then
588 in the minsyms. Take the closest one. */
590 /* This is defective in the sense that it only finds text symbols. So
591 really this is kind of pointless--we should make sure that the
592 minimal symbols have everything we need (by changing that we could
593 save some memory, but for many debug format--ELF/DWARF or
594 anything/stabs--it would be inconvenient to eliminate those minimal
596 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
597 symbol
= find_pc_sect_function (addr
, section
);
601 name_location
= BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
));
602 if (do_demangle
|| asm_demangle
)
603 name_temp
= SYMBOL_PRINT_NAME (symbol
);
605 name_temp
= DEPRECATED_SYMBOL_NAME (symbol
);
610 if (SYMBOL_VALUE_ADDRESS (msymbol
) > name_location
|| symbol
== NULL
)
612 /* The msymbol is closer to the address than the symbol;
613 use the msymbol instead. */
615 name_location
= SYMBOL_VALUE_ADDRESS (msymbol
);
616 if (do_demangle
|| asm_demangle
)
617 name_temp
= SYMBOL_PRINT_NAME (msymbol
);
619 name_temp
= DEPRECATED_SYMBOL_NAME (msymbol
);
622 if (symbol
== NULL
&& msymbol
== NULL
)
625 /* If the nearest symbol is too far away, don't print anything symbolic. */
627 /* For when CORE_ADDR is larger than unsigned int, we do math in
628 CORE_ADDR. But when we detect unsigned wraparound in the
629 CORE_ADDR math, we ignore this test and print the offset,
630 because addr+max_symbolic_offset has wrapped through the end
631 of the address space back to the beginning, giving bogus comparison. */
632 if (addr
> name_location
+ max_symbolic_offset
633 && name_location
+ max_symbolic_offset
> name_location
)
636 *offset
= addr
- name_location
;
638 *name
= xstrdup (name_temp
);
640 if (print_symbol_filename
)
642 struct symtab_and_line sal
;
644 sal
= find_pc_sect_line (addr
, section
, 0);
648 *filename
= xstrdup (sal
.symtab
->filename
);
655 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
658 deprecated_print_address_numeric (CORE_ADDR addr
, int use_local
,
659 struct ui_file
*stream
)
662 fputs_filtered (paddress (addr
), stream
);
665 int addr_bit
= gdbarch_addr_bit (current_gdbarch
);
667 if (addr_bit
< (sizeof (CORE_ADDR
) * HOST_CHAR_BIT
))
668 addr
&= ((CORE_ADDR
) 1 << addr_bit
) - 1;
669 print_longest (stream
, 'x', 0, (ULONGEST
) addr
);
673 /* Print address ADDR symbolically on STREAM.
674 First print it as a number. Then perhaps print
675 <SYMBOL + OFFSET> after the number. */
678 print_address (CORE_ADDR addr
, struct ui_file
*stream
)
680 deprecated_print_address_numeric (addr
, 1, stream
);
681 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
684 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
685 controls whether to print the symbolic name "raw" or demangled.
686 Global setting "addressprint" controls whether to print hex address
690 print_address_demangle (CORE_ADDR addr
, struct ui_file
*stream
,
695 fprintf_filtered (stream
, "0");
697 else if (addressprint
)
699 deprecated_print_address_numeric (addr
, 1, stream
);
700 print_address_symbolic (addr
, stream
, do_demangle
, " ");
704 print_address_symbolic (addr
, stream
, do_demangle
, "");
709 /* These are the types that $__ will get after an examine command of one
712 static struct type
*examine_i_type
;
714 static struct type
*examine_b_type
;
715 static struct type
*examine_h_type
;
716 static struct type
*examine_w_type
;
717 static struct type
*examine_g_type
;
719 /* Examine data at address ADDR in format FMT.
720 Fetch it from memory and print on gdb_stdout. */
723 do_examine (struct format_data fmt
, CORE_ADDR addr
)
728 struct type
*val_type
= NULL
;
737 /* String or instruction format implies fetch single bytes
738 regardless of the specified size. */
739 if (format
== 's' || format
== 'i')
743 val_type
= examine_i_type
;
744 else if (size
== 'b')
745 val_type
= examine_b_type
;
746 else if (size
== 'h')
747 val_type
= examine_h_type
;
748 else if (size
== 'w')
749 val_type
= examine_w_type
;
750 else if (size
== 'g')
751 val_type
= examine_g_type
;
758 if (format
== 's' || format
== 'i')
761 /* Print as many objects as specified in COUNT, at most maxelts per line,
762 with the address of the next one at the start of each line. */
767 print_address (next_address
, gdb_stdout
);
768 printf_filtered (":");
773 printf_filtered ("\t");
774 /* Note that print_formatted sets next_address for the next
776 last_examine_address
= next_address
;
778 if (last_examine_value
)
779 value_free (last_examine_value
);
781 /* The value to be displayed is not fetched greedily.
782 Instead, to avoid the possibility of a fetched value not
783 being used, its retrieval is delayed until the print code
784 uses it. When examining an instruction stream, the
785 disassembler will perform its own memory fetch using just
786 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
787 the disassembler be modified so that LAST_EXAMINE_VALUE
788 is left with the byte sequence from the last complete
789 instruction fetched from memory? */
790 last_examine_value
= value_at_lazy (val_type
, next_address
);
792 if (last_examine_value
)
793 release_value (last_examine_value
);
795 print_formatted (last_examine_value
, format
, size
, gdb_stdout
);
797 /* Display any branch delay slots following the final insn. */
798 if (format
== 'i' && count
== 1)
799 count
+= branch_delay_insns
;
801 printf_filtered ("\n");
802 gdb_flush (gdb_stdout
);
807 validate_format (struct format_data fmt
, char *cmdname
)
810 error (_("Size letters are meaningless in \"%s\" command."), cmdname
);
812 error (_("Item count other than 1 is meaningless in \"%s\" command."),
814 if (fmt
.format
== 'i' || fmt
.format
== 's')
815 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
816 fmt
.format
, cmdname
);
819 /* Evaluate string EXP as an expression in the current language and
820 print the resulting value. EXP may contain a format specifier as the
821 first argument ("/x myvar" for example, to print myvar in hex). */
824 print_command_1 (char *exp
, int inspect
, int voidprint
)
826 struct expression
*expr
;
827 struct cleanup
*old_chain
= 0;
830 struct format_data fmt
;
833 /* Pass inspect flag to the rest of the print routines in a global
835 inspect_it
= inspect
;
837 if (exp
&& *exp
== '/')
840 fmt
= decode_format (&exp
, last_format
, 0);
841 validate_format (fmt
, "print");
842 last_format
= format
= fmt
.format
;
854 expr
= parse_expression (exp
);
855 old_chain
= make_cleanup (free_current_contents
, &expr
);
857 val
= evaluate_expression (expr
);
860 val
= access_value_history (0);
862 if (voidprint
|| (val
&& value_type (val
) &&
863 TYPE_CODE (value_type (val
)) != TYPE_CODE_VOID
))
865 int histindex
= record_latest_value (val
);
868 annotate_value_history_begin (histindex
, value_type (val
));
870 annotate_value_begin (value_type (val
));
873 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"",
875 else if (histindex
>= 0)
876 printf_filtered ("$%d = ", histindex
);
879 annotate_value_history_value ();
881 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
882 printf_filtered ("\n");
885 annotate_value_history_end ();
887 annotate_value_end ();
890 printf_unfiltered ("\") )\030");
894 do_cleanups (old_chain
);
895 inspect_it
= 0; /* Reset print routines to normal. */
899 print_command (char *exp
, int from_tty
)
901 print_command_1 (exp
, 0, 1);
904 /* Same as print, except in epoch, it gets its own window. */
906 inspect_command (char *exp
, int from_tty
)
908 extern int epoch_interface
;
910 print_command_1 (exp
, epoch_interface
, 1);
913 /* Same as print, except it doesn't print void results. */
915 call_command (char *exp
, int from_tty
)
917 print_command_1 (exp
, 0, 0);
921 output_command (char *exp
, int from_tty
)
923 struct expression
*expr
;
924 struct cleanup
*old_chain
;
927 struct format_data fmt
;
931 if (exp
&& *exp
== '/')
934 fmt
= decode_format (&exp
, 0, 0);
935 validate_format (fmt
, "output");
939 expr
= parse_expression (exp
);
940 old_chain
= make_cleanup (free_current_contents
, &expr
);
942 val
= evaluate_expression (expr
);
944 annotate_value_begin (value_type (val
));
946 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
948 annotate_value_end ();
951 gdb_flush (gdb_stdout
);
953 do_cleanups (old_chain
);
957 set_command (char *exp
, int from_tty
)
959 struct expression
*expr
= parse_expression (exp
);
960 struct cleanup
*old_chain
=
961 make_cleanup (free_current_contents
, &expr
);
962 evaluate_expression (expr
);
963 do_cleanups (old_chain
);
967 sym_info (char *arg
, int from_tty
)
969 struct minimal_symbol
*msymbol
;
970 struct objfile
*objfile
;
971 struct obj_section
*osect
;
973 CORE_ADDR addr
, sect_addr
;
978 error_no_arg (_("address"));
980 addr
= parse_and_eval_address (arg
);
981 ALL_OBJSECTIONS (objfile
, osect
)
983 /* Only process each object file once, even if there's a separate
985 if (objfile
->separate_debug_objfile_backlink
)
988 sect
= osect
->the_bfd_section
;
989 sect_addr
= overlay_mapped_address (addr
, sect
);
991 if (osect
->addr
<= sect_addr
&& sect_addr
< osect
->endaddr
&&
992 (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr
, sect
)))
995 offset
= sect_addr
- SYMBOL_VALUE_ADDRESS (msymbol
);
997 printf_filtered ("%s + %u in ",
998 SYMBOL_PRINT_NAME (msymbol
), offset
);
1000 printf_filtered ("%s in ",
1001 SYMBOL_PRINT_NAME (msymbol
));
1002 if (pc_in_unmapped_range (addr
, sect
))
1003 printf_filtered (_("load address range of "));
1004 if (section_is_overlay (sect
))
1005 printf_filtered (_("%s overlay "),
1006 section_is_mapped (sect
) ? "mapped" : "unmapped");
1007 printf_filtered (_("section %s"), sect
->name
);
1008 printf_filtered ("\n");
1012 printf_filtered (_("No symbol matches %s.\n"), arg
);
1016 address_info (char *exp
, int from_tty
)
1019 struct minimal_symbol
*msymbol
;
1023 CORE_ADDR load_addr
;
1024 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
1025 if exp is a field of `this'. */
1028 error (_("Argument required."));
1030 sym
= lookup_symbol (exp
, get_selected_block (0), VAR_DOMAIN
,
1031 &is_a_field_of_this
, (struct symtab
**) NULL
);
1034 if (is_a_field_of_this
)
1036 printf_filtered ("Symbol \"");
1037 fprintf_symbol_filtered (gdb_stdout
, exp
,
1038 current_language
->la_language
, DMGL_ANSI
);
1039 printf_filtered ("\" is a field of the local class variable ");
1040 if (current_language
->la_language
== language_objc
)
1041 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1043 printf_filtered ("`this'\n");
1047 msymbol
= lookup_minimal_symbol (exp
, NULL
, NULL
);
1049 if (msymbol
!= NULL
)
1051 load_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
1053 printf_filtered ("Symbol \"");
1054 fprintf_symbol_filtered (gdb_stdout
, exp
,
1055 current_language
->la_language
, DMGL_ANSI
);
1056 printf_filtered ("\" is at ");
1057 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1058 printf_filtered (" in a file compiled without debugging");
1059 section
= SYMBOL_BFD_SECTION (msymbol
);
1060 if (section_is_overlay (section
))
1062 load_addr
= overlay_unmapped_address (load_addr
, section
);
1063 printf_filtered (",\n -- loaded at ");
1064 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1065 printf_filtered (" in overlay section %s", section
->name
);
1067 printf_filtered (".\n");
1070 error (_("No symbol \"%s\" in current context."), exp
);
1074 printf_filtered ("Symbol \"");
1075 fprintf_symbol_filtered (gdb_stdout
, DEPRECATED_SYMBOL_NAME (sym
),
1076 current_language
->la_language
, DMGL_ANSI
);
1077 printf_filtered ("\" is ");
1078 val
= SYMBOL_VALUE (sym
);
1079 basereg
= SYMBOL_BASEREG (sym
);
1080 section
= SYMBOL_BFD_SECTION (sym
);
1082 switch (SYMBOL_CLASS (sym
))
1085 case LOC_CONST_BYTES
:
1086 printf_filtered ("constant");
1090 printf_filtered ("a label at address ");
1091 deprecated_print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1093 if (section_is_overlay (section
))
1095 load_addr
= overlay_unmapped_address (load_addr
, section
);
1096 printf_filtered (",\n -- loaded at ");
1097 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1098 printf_filtered (" in overlay section %s", section
->name
);
1103 case LOC_COMPUTED_ARG
:
1104 /* FIXME: cagney/2004-01-26: It should be possible to
1105 unconditionally call the SYMBOL_OPS method when available.
1106 Unfortunately DWARF 2 stores the frame-base (instead of the
1107 function) location in a function's symbol. Oops! For the
1108 moment enable this when/where applicable. */
1109 SYMBOL_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1113 printf_filtered (_("a variable in register %s"),
1114 gdbarch_register_name (current_gdbarch
, val
));
1118 printf_filtered (_("static storage at address "));
1119 deprecated_print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1121 if (section_is_overlay (section
))
1123 load_addr
= overlay_unmapped_address (load_addr
, section
);
1124 printf_filtered (_(",\n -- loaded at "));
1125 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1126 printf_filtered (_(" in overlay section %s"), section
->name
);
1131 printf_filtered (_("external global (indirect addressing), at address *("));
1132 deprecated_print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1134 printf_filtered (")");
1135 if (section_is_overlay (section
))
1137 load_addr
= overlay_unmapped_address (load_addr
, section
);
1138 printf_filtered (_(",\n -- loaded at "));
1139 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1140 printf_filtered (_(" in overlay section %s"), section
->name
);
1145 printf_filtered (_("an argument in register %s"),
1146 gdbarch_register_name (current_gdbarch
, val
));
1149 case LOC_REGPARM_ADDR
:
1150 printf_filtered (_("address of an argument in register %s"),
1151 gdbarch_register_name (current_gdbarch
, val
));
1155 printf_filtered (_("an argument at offset %ld"), val
);
1159 printf_filtered (_("an argument at frame offset %ld"), val
);
1163 printf_filtered (_("a local variable at frame offset %ld"), val
);
1167 printf_filtered (_("a reference argument at offset %ld"), val
);
1171 printf_filtered (_("a variable at offset %ld from register %s"),
1172 val
, gdbarch_register_name (current_gdbarch
, basereg
));
1175 case LOC_BASEREG_ARG
:
1176 printf_filtered (_("an argument at offset %ld from register %s"),
1177 val
, gdbarch_register_name (current_gdbarch
, basereg
));
1181 printf_filtered (_("a typedef"));
1185 printf_filtered (_("a function at address "));
1186 load_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1187 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1188 if (section_is_overlay (section
))
1190 load_addr
= overlay_unmapped_address (load_addr
, section
);
1191 printf_filtered (_(",\n -- loaded at "));
1192 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1193 printf_filtered (_(" in overlay section %s"), section
->name
);
1197 case LOC_UNRESOLVED
:
1199 struct minimal_symbol
*msym
;
1201 msym
= lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym
), NULL
, NULL
);
1203 printf_filtered ("unresolved");
1206 section
= SYMBOL_BFD_SECTION (msym
);
1207 printf_filtered (_("static storage at address "));
1208 load_addr
= SYMBOL_VALUE_ADDRESS (msym
);
1209 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1210 if (section_is_overlay (section
))
1212 load_addr
= overlay_unmapped_address (load_addr
, section
);
1213 printf_filtered (_(",\n -- loaded at "));
1214 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1215 printf_filtered (_(" in overlay section %s"), section
->name
);
1221 case LOC_HP_THREAD_LOCAL_STATIC
:
1222 printf_filtered (_("\
1223 a thread-local variable at offset %ld from the thread base register %s"),
1224 val
, gdbarch_register_name (current_gdbarch
, basereg
));
1227 case LOC_OPTIMIZED_OUT
:
1228 printf_filtered (_("optimized out"));
1232 printf_filtered (_("of unknown (botched) type"));
1235 printf_filtered (".\n");
1240 x_command (char *exp
, int from_tty
)
1242 struct expression
*expr
;
1243 struct format_data fmt
;
1244 struct cleanup
*old_chain
;
1247 fmt
.format
= last_format
;
1248 fmt
.size
= last_size
;
1251 if (exp
&& *exp
== '/')
1254 fmt
= decode_format (&exp
, last_format
, last_size
);
1257 /* If we have an expression, evaluate it and use it as the address. */
1259 if (exp
!= 0 && *exp
!= 0)
1261 expr
= parse_expression (exp
);
1262 /* Cause expression not to be there any more if this command is
1263 repeated with Newline. But don't clobber a user-defined
1264 command's definition. */
1267 old_chain
= make_cleanup (free_current_contents
, &expr
);
1268 val
= evaluate_expression (expr
);
1269 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_REF
)
1270 val
= value_ind (val
);
1271 /* In rvalue contexts, such as this, functions are coerced into
1272 pointers to functions. This makes "x/i main" work. */
1273 if (/* last_format == 'i' && */
1274 TYPE_CODE (value_type (val
)) == TYPE_CODE_FUNC
1275 && VALUE_LVAL (val
) == lval_memory
)
1276 next_address
= VALUE_ADDRESS (val
);
1278 next_address
= value_as_address (val
);
1279 do_cleanups (old_chain
);
1282 do_examine (fmt
, next_address
);
1284 /* If the examine succeeds, we remember its size and format for next
1286 last_size
= fmt
.size
;
1287 last_format
= fmt
.format
;
1289 /* Set a couple of internal variables if appropriate. */
1290 if (last_examine_value
)
1292 /* Make last address examined available to the user as $_. Use
1293 the correct pointer type. */
1294 struct type
*pointer_type
1295 = lookup_pointer_type (value_type (last_examine_value
));
1296 set_internalvar (lookup_internalvar ("_"),
1297 value_from_pointer (pointer_type
,
1298 last_examine_address
));
1300 /* Make contents of last address examined available to the user
1301 as $__. If the last value has not been fetched from memory
1302 then don't fetch it now; instead mark it by voiding the $__
1304 if (value_lazy (last_examine_value
))
1305 set_internalvar (lookup_internalvar ("__"),
1306 allocate_value (builtin_type_void
));
1308 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1313 /* Add an expression to the auto-display chain.
1314 Specify the expression. */
1317 display_command (char *exp
, int from_tty
)
1319 struct format_data fmt
;
1320 struct expression
*expr
;
1321 struct display
*new;
1325 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1327 if (tui_active
&& exp
!= NULL
&& *exp
== '$')
1328 display_it
= (tui_set_layout_for_display_command (exp
) == TUI_FAILURE
);
1342 fmt
= decode_format (&exp
, 0, 0);
1343 if (fmt
.size
&& fmt
.format
== 0)
1345 if (fmt
.format
== 'i' || fmt
.format
== 's')
1355 innermost_block
= 0;
1356 expr
= parse_expression (exp
);
1358 new = (struct display
*) xmalloc (sizeof (struct display
));
1361 new->block
= innermost_block
;
1362 new->next
= display_chain
;
1363 new->number
= ++display_number
;
1366 display_chain
= new;
1368 if (from_tty
&& target_has_execution
)
1369 do_one_display (new);
1376 free_display (struct display
*d
)
1382 /* Clear out the display_chain. Done when new symtabs are loaded,
1383 since this invalidates the types stored in many expressions. */
1386 clear_displays (void)
1390 while ((d
= display_chain
) != NULL
)
1393 display_chain
= d
->next
;
1398 /* Delete the auto-display number NUM. */
1401 delete_display (int num
)
1403 struct display
*d1
, *d
;
1406 error (_("No display number %d."), num
);
1408 if (display_chain
->number
== num
)
1411 display_chain
= d1
->next
;
1415 for (d
= display_chain
;; d
= d
->next
)
1418 error (_("No display number %d."), num
);
1419 if (d
->next
->number
== num
)
1429 /* Delete some values from the auto-display chain.
1430 Specify the element numbers. */
1433 undisplay_command (char *args
, int from_tty
)
1441 if (query ("Delete all auto-display expressions? "))
1450 while (*p1
>= '0' && *p1
<= '9')
1452 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1453 error (_("Arguments must be display numbers."));
1457 delete_display (num
);
1460 while (*p
== ' ' || *p
== '\t')
1466 /* Display a single auto-display.
1467 Do nothing if the display cannot be printed in the current context,
1468 or if the display is disabled. */
1471 do_one_display (struct display
*d
)
1473 int within_current_scope
;
1475 if (d
->enabled_p
== 0)
1479 within_current_scope
= contained_in (get_selected_block (0), d
->block
);
1481 within_current_scope
= 1;
1482 if (!within_current_scope
)
1485 current_display_number
= d
->number
;
1487 annotate_display_begin ();
1488 printf_filtered ("%d", d
->number
);
1489 annotate_display_number_end ();
1490 printf_filtered (": ");
1496 annotate_display_format ();
1498 printf_filtered ("x/");
1499 if (d
->format
.count
!= 1)
1500 printf_filtered ("%d", d
->format
.count
);
1501 printf_filtered ("%c", d
->format
.format
);
1502 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1503 printf_filtered ("%c", d
->format
.size
);
1504 printf_filtered (" ");
1506 annotate_display_expression ();
1508 print_expression (d
->exp
, gdb_stdout
);
1509 annotate_display_expression_end ();
1511 if (d
->format
.count
!= 1 || d
->format
.format
== 'i')
1512 printf_filtered ("\n");
1514 printf_filtered (" ");
1516 val
= evaluate_expression (d
->exp
);
1517 addr
= value_as_address (val
);
1518 if (d
->format
.format
== 'i')
1519 addr
= gdbarch_addr_bits_remove (current_gdbarch
, addr
);
1521 annotate_display_value ();
1523 do_examine (d
->format
, addr
);
1527 annotate_display_format ();
1529 if (d
->format
.format
)
1530 printf_filtered ("/%c ", d
->format
.format
);
1532 annotate_display_expression ();
1534 print_expression (d
->exp
, gdb_stdout
);
1535 annotate_display_expression_end ();
1537 printf_filtered (" = ");
1539 annotate_display_expression ();
1541 print_formatted (evaluate_expression (d
->exp
),
1542 d
->format
.format
, d
->format
.size
, gdb_stdout
);
1543 printf_filtered ("\n");
1546 annotate_display_end ();
1548 gdb_flush (gdb_stdout
);
1549 current_display_number
= -1;
1552 /* Display all of the values on the auto-display chain which can be
1553 evaluated in the current scope. */
1560 for (d
= display_chain
; d
; d
= d
->next
)
1564 /* Delete the auto-display which we were in the process of displaying.
1565 This is done when there is an error or a signal. */
1568 disable_display (int num
)
1572 for (d
= display_chain
; d
; d
= d
->next
)
1573 if (d
->number
== num
)
1578 printf_unfiltered (_("No display number %d.\n"), num
);
1582 disable_current_display (void)
1584 if (current_display_number
>= 0)
1586 disable_display (current_display_number
);
1587 fprintf_unfiltered (gdb_stderr
, _("\
1588 Disabling display %d to avoid infinite recursion.\n"),
1589 current_display_number
);
1591 current_display_number
= -1;
1595 display_info (char *ignore
, int from_tty
)
1600 printf_unfiltered (_("There are no auto-display expressions now.\n"));
1602 printf_filtered (_("Auto-display expressions now in effect:\n\
1603 Num Enb Expression\n"));
1605 for (d
= display_chain
; d
; d
= d
->next
)
1607 printf_filtered ("%d: %c ", d
->number
, "ny"[(int) d
->enabled_p
]);
1609 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1611 else if (d
->format
.format
)
1612 printf_filtered ("/%c ", d
->format
.format
);
1613 print_expression (d
->exp
, gdb_stdout
);
1614 if (d
->block
&& !contained_in (get_selected_block (0), d
->block
))
1615 printf_filtered (_(" (cannot be evaluated in the current context)"));
1616 printf_filtered ("\n");
1617 gdb_flush (gdb_stdout
);
1622 enable_display (char *args
, int from_tty
)
1631 for (d
= display_chain
; d
; d
= d
->next
)
1638 while (*p1
>= '0' && *p1
<= '9')
1640 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1641 error (_("Arguments must be display numbers."));
1645 for (d
= display_chain
; d
; d
= d
->next
)
1646 if (d
->number
== num
)
1651 printf_unfiltered (_("No display number %d.\n"), num
);
1654 while (*p
== ' ' || *p
== '\t')
1660 disable_display_command (char *args
, int from_tty
)
1668 for (d
= display_chain
; d
; d
= d
->next
)
1675 while (*p1
>= '0' && *p1
<= '9')
1677 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1678 error (_("Arguments must be display numbers."));
1680 disable_display (atoi (p
));
1683 while (*p
== ' ' || *p
== '\t')
1689 /* Print the value in stack frame FRAME of a variable specified by a
1693 print_variable_value (struct symbol
*var
, struct frame_info
*frame
,
1694 struct ui_file
*stream
)
1696 struct value
*val
= read_var_value (var
, frame
);
1698 value_print (val
, stream
, 0, Val_pretty_default
);
1702 printf_command (char *arg
, int from_tty
)
1706 char *string
= NULL
;
1707 struct value
**val_args
;
1709 char *current_substring
;
1711 int allocated_args
= 20;
1712 struct cleanup
*old_cleanups
;
1714 val_args
= xmalloc (allocated_args
* sizeof (struct value
*));
1715 old_cleanups
= make_cleanup (free_current_contents
, &val_args
);
1718 error_no_arg (_("format-control string and values to print"));
1720 /* Skip white space before format string */
1721 while (*s
== ' ' || *s
== '\t')
1724 /* A format string should follow, enveloped in double quotes. */
1726 error (_("Bad format string, missing '\"'."));
1728 /* Parse the format-control string and copy it into the string STRING,
1729 processing some kinds of escape sequence. */
1731 f
= string
= (char *) alloca (strlen (s
) + 1);
1739 error (_("Bad format string, non-terminated '\"'."));
1772 /* ??? TODO: handle other escape sequences */
1773 error (_("Unrecognized escape character \\%c in format string."),
1783 /* Skip over " and following space and comma. */
1786 while (*s
== ' ' || *s
== '\t')
1789 if (*s
!= ',' && *s
!= 0)
1790 error (_("Invalid argument syntax"));
1794 while (*s
== ' ' || *s
== '\t')
1797 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1798 substrings
= alloca (strlen (string
) * 2);
1799 current_substring
= substrings
;
1802 /* Now scan the string for %-specs and see what kinds of args they want.
1803 argclass[I] classifies the %-specs so we can give printf_filtered
1804 something of the right size. */
1808 int_arg
, long_arg
, long_long_arg
, ptr_arg
, string_arg
,
1809 double_arg
, long_double_arg
1811 enum argclass
*argclass
;
1812 enum argclass this_argclass
;
1817 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1824 int seen_hash
= 0, seen_zero
= 0, lcount
= 0, seen_prec
= 0;
1825 int seen_space
= 0, seen_plus
= 0;
1826 int seen_big_l
= 0, seen_h
= 0;
1829 /* Check the validity of the format specifier, and work
1830 out what argument it expects. We only accept C89
1831 format strings, with the exception of long long (which
1832 we autoconf for). */
1834 /* Skip over "%%". */
1841 /* The first part of a format specifier is a set of flag
1843 while (strchr ("0-+ #", *f
))
1856 /* The next part of a format specifier is a width. */
1857 while (strchr ("0123456789", *f
))
1860 /* The next part of a format specifier is a precision. */
1865 while (strchr ("0123456789", *f
))
1869 /* The next part of a format specifier is a length modifier. */
1901 if (seen_space
|| seen_plus
)
1908 this_argclass
= int_arg
;
1909 else if (lcount
== 1)
1910 this_argclass
= long_arg
;
1912 this_argclass
= long_long_arg
;
1919 this_argclass
= int_arg
;
1920 if (lcount
|| seen_h
|| seen_big_l
)
1922 if (seen_prec
|| seen_zero
|| seen_space
|| seen_plus
)
1927 this_argclass
= ptr_arg
;
1928 if (lcount
|| seen_h
|| seen_big_l
)
1930 if (seen_prec
|| seen_zero
|| seen_space
|| seen_plus
)
1935 this_argclass
= string_arg
;
1936 if (lcount
|| seen_h
|| seen_big_l
)
1938 if (seen_zero
|| seen_space
|| seen_plus
)
1948 this_argclass
= long_double_arg
;
1950 this_argclass
= double_arg
;
1952 if (lcount
|| seen_h
)
1957 error (_("`*' not supported for precision or width in printf"));
1960 error (_("Format specifier `n' not supported in printf"));
1963 error (_("Incomplete format specifier at end of format string"));
1966 error (_("Unrecognized format specifier '%c' in printf"), *f
);
1970 error (_("Inappropriate modifiers to format specifier '%c' in printf"),
1974 strncpy (current_substring
, last_arg
, f
- last_arg
);
1975 current_substring
+= f
- last_arg
;
1976 *current_substring
++ = '\0';
1978 argclass
[nargs_wanted
++] = this_argclass
;
1981 /* Now, parse all arguments and evaluate them.
1982 Store the VALUEs in VAL_ARGS. */
1987 if (nargs
== allocated_args
)
1988 val_args
= (struct value
**) xrealloc ((char *) val_args
,
1989 (allocated_args
*= 2)
1990 * sizeof (struct value
*));
1992 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
1994 /* If format string wants a float, unchecked-convert the value to
1995 floating point of the same size */
1997 if (argclass
[nargs
] == double_arg
)
1999 struct type
*type
= value_type (val_args
[nargs
]);
2000 if (TYPE_LENGTH (type
) == sizeof (float))
2001 deprecated_set_value_type (val_args
[nargs
], builtin_type_float
);
2002 if (TYPE_LENGTH (type
) == sizeof (double))
2003 deprecated_set_value_type (val_args
[nargs
], builtin_type_double
);
2011 if (nargs
!= nargs_wanted
)
2012 error (_("Wrong number of arguments for specified format-string"));
2014 /* Now actually print them. */
2015 current_substring
= substrings
;
2016 for (i
= 0; i
< nargs
; i
++)
2018 switch (argclass
[i
])
2025 tem
= value_as_address (val_args
[i
]);
2027 /* This is a %s argument. Find the length of the string. */
2032 read_memory (tem
+ j
, &c
, 1);
2037 /* Copy the string contents into a string inside GDB. */
2038 str
= (gdb_byte
*) alloca (j
+ 1);
2040 read_memory (tem
, str
, j
);
2043 printf_filtered (current_substring
, (char *) str
);
2048 double val
= value_as_double (val_args
[i
]);
2049 printf_filtered (current_substring
, val
);
2052 case long_double_arg
:
2053 #ifdef HAVE_LONG_DOUBLE
2055 long double val
= value_as_double (val_args
[i
]);
2056 printf_filtered (current_substring
, val
);
2060 error (_("long double not supported in printf"));
2063 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2065 long long val
= value_as_long (val_args
[i
]);
2066 printf_filtered (current_substring
, val
);
2070 error (_("long long not supported in printf"));
2074 int val
= value_as_long (val_args
[i
]);
2075 printf_filtered (current_substring
, val
);
2080 long val
= value_as_long (val_args
[i
]);
2081 printf_filtered (current_substring
, val
);
2085 internal_error (__FILE__
, __LINE__
,
2086 _("failed internal consitency check"));
2088 /* Skip to the next substring. */
2089 current_substring
+= strlen (current_substring
) + 1;
2091 /* Print the portion of the format string after the last argument. */
2092 puts_filtered (last_arg
);
2094 do_cleanups (old_cleanups
);
2098 _initialize_printcmd (void)
2100 struct cmd_list_element
*c
;
2102 current_display_number
= -1;
2104 add_info ("address", address_info
,
2105 _("Describe where symbol SYM is stored."));
2107 add_info ("symbol", sym_info
, _("\
2108 Describe what symbol is at location ADDR.\n\
2109 Only for symbols with fixed locations (global or static scope)."));
2111 add_com ("x", class_vars
, x_command
, _("\
2112 Examine memory: x/FMT ADDRESS.\n\
2113 ADDRESS is an expression for the memory address to examine.\n\
2114 FMT is a repeat count followed by a format letter and a size letter.\n\
2115 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2116 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2117 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2118 The specified number of objects of the specified size are printed\n\
2119 according to the format.\n\n\
2120 Defaults for format and size letters are those previously used.\n\
2121 Default count is 1. Default address is following last thing printed\n\
2122 with this command or \"print\"."));
2125 add_com ("whereis", class_vars
, whereis_command
,
2126 _("Print line number and file of definition of variable."));
2129 add_info ("display", display_info
, _("\
2130 Expressions to display when program stops, with code numbers."));
2132 add_cmd ("undisplay", class_vars
, undisplay_command
, _("\
2133 Cancel some expressions to be displayed when program stops.\n\
2134 Arguments are the code numbers of the expressions to stop displaying.\n\
2135 No argument means cancel all automatic-display expressions.\n\
2136 \"delete display\" has the same effect as this command.\n\
2137 Do \"info display\" to see current list of code numbers."),
2140 add_com ("display", class_vars
, display_command
, _("\
2141 Print value of expression EXP each time the program stops.\n\
2142 /FMT may be used before EXP as in the \"print\" command.\n\
2143 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2144 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2145 and examining is done as in the \"x\" command.\n\n\
2146 With no argument, display all currently requested auto-display expressions.\n\
2147 Use \"undisplay\" to cancel display requests previously made."));
2149 add_cmd ("display", class_vars
, enable_display
, _("\
2150 Enable some expressions to be displayed when program stops.\n\
2151 Arguments are the code numbers of the expressions to resume displaying.\n\
2152 No argument means enable all automatic-display expressions.\n\
2153 Do \"info display\" to see current list of code numbers."), &enablelist
);
2155 add_cmd ("display", class_vars
, disable_display_command
, _("\
2156 Disable some expressions to be displayed when program stops.\n\
2157 Arguments are the code numbers of the expressions to stop displaying.\n\
2158 No argument means disable all automatic-display expressions.\n\
2159 Do \"info display\" to see current list of code numbers."), &disablelist
);
2161 add_cmd ("display", class_vars
, undisplay_command
, _("\
2162 Cancel some expressions to be displayed when program stops.\n\
2163 Arguments are the code numbers of the expressions to stop displaying.\n\
2164 No argument means cancel all automatic-display expressions.\n\
2165 Do \"info display\" to see current list of code numbers."), &deletelist
);
2167 add_com ("printf", class_vars
, printf_command
, _("\
2168 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2169 This is useful for formatted output in user-defined commands."));
2171 add_com ("output", class_vars
, output_command
, _("\
2172 Like \"print\" but don't put in value history and don't print newline.\n\
2173 This is useful in user-defined commands."));
2175 add_prefix_cmd ("set", class_vars
, set_command
, _("\
2176 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2177 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2178 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2179 with $), a register (a few standard names starting with $), or an actual\n\
2180 variable in the program being debugged. EXP is any valid expression.\n\
2181 Use \"set variable\" for variables with names identical to set subcommands.\n\
2183 With a subcommand, this command modifies parts of the gdb environment.\n\
2184 You can see these environment settings with the \"show\" command."),
2185 &setlist
, "set ", 1, &cmdlist
);
2187 add_com ("assign", class_vars
, set_command
, _("\
2188 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2189 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2190 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2191 with $), a register (a few standard names starting with $), or an actual\n\
2192 variable in the program being debugged. EXP is any valid expression.\n\
2193 Use \"set variable\" for variables with names identical to set subcommands.\n\
2194 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2195 You can see these environment settings with the \"show\" command."));
2197 /* "call" is the same as "set", but handy for dbx users to call fns. */
2198 c
= add_com ("call", class_vars
, call_command
, _("\
2199 Call a function in the program.\n\
2200 The argument is the function name and arguments, in the notation of the\n\
2201 current working language. The result is printed and saved in the value\n\
2202 history, if it is not void."));
2203 set_cmd_completer (c
, location_completer
);
2205 add_cmd ("variable", class_vars
, set_command
, _("\
2206 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2207 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2208 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2209 with $), a register (a few standard names starting with $), or an actual\n\
2210 variable in the program being debugged. EXP is any valid expression.\n\
2211 This may usually be abbreviated to simply \"set\"."),
2214 c
= add_com ("print", class_vars
, print_command
, _("\
2215 Print value of expression EXP.\n\
2216 Variables accessible are those of the lexical environment of the selected\n\
2217 stack frame, plus all those whose scope is global or an entire file.\n\
2219 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2220 $$NUM refers to NUM'th value back from the last one.\n\
2221 Names starting with $ refer to registers (with the values they would have\n\
2222 if the program were to return to the stack frame now selected, restoring\n\
2223 all registers saved by frames farther in) or else to debugger\n\
2224 \"convenience\" variables (any such name not a known register).\n\
2225 Use assignment expressions to give values to convenience variables.\n\
2227 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2228 @ is a binary operator for treating consecutive data objects\n\
2229 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2230 element is FOO, whose second element is stored in the space following\n\
2231 where FOO is stored, etc. FOO must be an expression whose value\n\
2232 resides in memory.\n\
2234 EXP may be preceded with /FMT, where FMT is a format letter\n\
2235 but no count or size letter (see \"x\" command)."));
2236 set_cmd_completer (c
, location_completer
);
2237 add_com_alias ("p", "print", class_vars
, 1);
2239 c
= add_com ("inspect", class_vars
, inspect_command
, _("\
2240 Same as \"print\" command, except that if you are running in the epoch\n\
2241 environment, the value is printed in its own window."));
2242 set_cmd_completer (c
, location_completer
);
2244 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class
,
2245 &max_symbolic_offset
, _("\
2246 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2247 Show the largest offset that will be printed in <symbol+1234> form."), NULL
,
2249 show_max_symbolic_offset
,
2250 &setprintlist
, &showprintlist
);
2251 add_setshow_boolean_cmd ("symbol-filename", no_class
,
2252 &print_symbol_filename
, _("\
2253 Set printing of source filename and line number with <symbol>."), _("\
2254 Show printing of source filename and line number with <symbol>."), NULL
,
2256 show_print_symbol_filename
,
2257 &setprintlist
, &showprintlist
);
2259 /* For examine/instruction a single byte quantity is specified as
2260 the data. This avoids problems with value_at_lazy() requiring a
2261 valid data type (and rejecting VOID). */
2262 examine_i_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_i_type", NULL
);
2264 examine_b_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_b_type", NULL
);
2265 examine_h_type
= init_type (TYPE_CODE_INT
, 2, 0, "examine_h_type", NULL
);
2266 examine_w_type
= init_type (TYPE_CODE_INT
, 4, 0, "examine_w_type", NULL
);
2267 examine_g_type
= init_type (TYPE_CODE_INT
, 8, 0, "examine_g_type", NULL
);