1 /* Print values for GNU debugger GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
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., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, 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 /* Last address examined. */
75 static CORE_ADDR last_examine_address
;
77 /* Contents of last address examined.
78 This is not valid past the end of the `x' command! */
80 static struct value
*last_examine_value
;
82 /* Largest offset between a symbolic value and an address, that will be
83 printed as `0x1234 <symbol+offset>'. */
85 static unsigned int max_symbolic_offset
= UINT_MAX
;
87 show_max_symbolic_offset (struct ui_file
*file
, int from_tty
,
88 struct cmd_list_element
*c
, const char *value
)
90 fprintf_filtered (file
, _("\
91 The largest offset that will be printed in <symbol+1234> form is %s.\n"),
95 /* Append the source filename and linenumber of the symbol when
96 printing a symbolic value as `<symbol at filename:linenum>' if set. */
97 static int print_symbol_filename
= 0;
99 show_print_symbol_filename (struct ui_file
*file
, int from_tty
,
100 struct cmd_list_element
*c
, const char *value
)
102 fprintf_filtered (file
, _("\
103 Printing of source filename and line number with <symbol> is %s.\n"),
107 /* Number of auto-display expression currently being displayed.
108 So that we can disable it if we get an error or a signal within it.
109 -1 when not doing one. */
111 int current_display_number
;
113 /* Flag to low-level print routines that this value is being printed
114 in an epoch window. We'd like to pass this as a parameter, but
115 every routine would need to take it. Perhaps we can encapsulate
116 this in the I/O stream once we have GNU stdio. */
122 /* Chain link to next auto-display item. */
123 struct display
*next
;
124 /* Expression to be evaluated and displayed. */
125 struct expression
*exp
;
126 /* Item number of this auto-display item. */
128 /* Display format specified. */
129 struct format_data format
;
130 /* Innermost block required by this expression when evaluated */
132 /* Status of this display (enabled or disabled) */
136 /* Chain of expressions whose values should be displayed
137 automatically each time the program stops. */
139 static struct display
*display_chain
;
141 static int display_number
;
143 /* Prototypes for exported functions. */
145 void output_command (char *, int);
147 void _initialize_printcmd (void);
149 /* Prototypes for local functions. */
151 static void delete_display (int);
153 static void enable_display (char *, int);
155 static void disable_display_command (char *, int);
157 static void printf_command (char *, int);
159 static void display_info (char *, int);
161 static void do_one_display (struct display
*);
163 static void undisplay_command (char *, int);
165 static void free_display (struct display
*);
167 static void display_command (char *, int);
169 void x_command (char *, int);
171 static void address_info (char *, int);
173 static void set_command (char *, int);
175 static void call_command (char *, int);
177 static void inspect_command (char *, int);
179 static void print_command (char *, int);
181 static void print_command_1 (char *, int, int);
183 static void validate_format (struct format_data
, char *);
185 static void print_formatted (struct value
*, int, int, struct ui_file
*);
187 static struct format_data
decode_format (char **, int, int);
189 static void sym_info (char *, int);
192 /* Decode a format specification. *STRING_PTR should point to it.
193 OFORMAT and OSIZE are used as defaults for the format and size
194 if none are given in the format specification.
195 If OSIZE is zero, then the size field of the returned value
196 should be set only if a size is explicitly specified by the
198 The structure returned describes all the data
199 found in the specification. In addition, *STRING_PTR is advanced
200 past the specification and past all whitespace following it. */
202 static struct format_data
203 decode_format (char **string_ptr
, int oformat
, int osize
)
205 struct format_data val
;
206 char *p
= *string_ptr
;
212 if (*p
>= '0' && *p
<= '9')
213 val
.count
= atoi (p
);
214 while (*p
>= '0' && *p
<= '9')
217 /* Now process size or format letters that follow. */
221 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
223 else if (*p
>= 'a' && *p
<= 'z')
229 while (*p
== ' ' || *p
== '\t')
233 /* Set defaults for format and size if not specified. */
234 if (val
.format
== '?')
238 /* Neither has been specified. */
239 val
.format
= oformat
;
243 /* If a size is specified, any format makes a reasonable
244 default except 'i'. */
245 val
.format
= oformat
== 'i' ? 'x' : oformat
;
247 else if (val
.size
== '?')
252 /* Pick the appropriate size for an address. */
253 if (TARGET_PTR_BIT
== 64)
254 val
.size
= osize
? 'g' : osize
;
255 else if (TARGET_PTR_BIT
== 32)
256 val
.size
= osize
? 'w' : osize
;
257 else if (TARGET_PTR_BIT
== 16)
258 val
.size
= osize
? 'h' : osize
;
260 /* Bad value for TARGET_PTR_BIT */
261 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
264 /* Floating point has to be word or giantword. */
265 if (osize
== 'w' || osize
== 'g')
268 /* Default it to giantword if the last used size is not
270 val
.size
= osize
? 'g' : osize
;
273 /* Characters default to one byte. */
274 val
.size
= osize
? 'b' : osize
;
277 /* The default is the size most recently specified. */
284 /* Print value VAL on stream according to FORMAT, a letter or 0.
285 Do not end with a newline.
286 0 means print VAL according to its own type.
287 SIZE is the letter for the size of datum being printed.
288 This is used to pad hex numbers so they line up. */
291 print_formatted (struct value
*val
, int format
, int size
,
292 struct ui_file
*stream
)
294 struct type
*type
= check_typedef (value_type (val
));
295 int len
= TYPE_LENGTH (type
);
297 if (VALUE_LVAL (val
) == lval_memory
)
299 next_address
= VALUE_ADDRESS (val
) + len
;
305 /* FIXME: Need to handle wchar_t's here... */
306 next_address
= VALUE_ADDRESS (val
)
307 + val_print_string (VALUE_ADDRESS (val
), -1, 1, stream
);
311 /* The old comment says
312 "Force output out, print_insn not using _filtered".
313 I'm not completely sure what that means, I suspect most print_insn
314 now do use _filtered, so I guess it's obsolete.
315 --Yes, it does filter now, and so this is obsolete. -JB */
317 /* We often wrap here if there are long symbolic names. */
319 next_address
= VALUE_ADDRESS (val
)
320 + gdb_print_insn (VALUE_ADDRESS (val
), stream
);
325 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
326 || TYPE_CODE (type
) == TYPE_CODE_STRING
327 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
328 || TYPE_CODE (type
) == TYPE_CODE_UNION
329 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
330 /* If format is 0, use the 'natural' format for
331 * that type of value. If the type is non-scalar,
332 * we have to use language rules to print it as
333 * a series of scalars.
335 value_print (val
, stream
, format
, Val_pretty_default
);
337 /* User specified format, so don't look to the
338 * the type to tell us what to do.
340 print_scalar_formatted (value_contents (val
), type
,
341 format
, size
, stream
);
345 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
346 according to letters FORMAT and SIZE on STREAM.
347 FORMAT may not be zero. Formats s and i are not supported at this level.
349 This is how the elements of an array or structure are printed
353 print_scalar_formatted (const void *valaddr
, struct type
*type
,
354 int format
, int size
, struct ui_file
*stream
)
356 LONGEST val_long
= 0;
357 unsigned int len
= TYPE_LENGTH (type
);
359 if (len
> sizeof(LONGEST
) &&
360 (TYPE_CODE (type
) == TYPE_CODE_INT
361 || TYPE_CODE (type
) == TYPE_CODE_ENUM
))
366 print_octal_chars (stream
, valaddr
, len
);
370 print_decimal_chars (stream
, valaddr
, len
);
373 print_binary_chars (stream
, valaddr
, len
);
376 print_hex_chars (stream
, valaddr
, len
);
379 print_char_chars (stream
, valaddr
, len
);
387 val_long
= unpack_long (type
, valaddr
);
389 /* If the value is a pointer, and pointers and addresses are not the
390 same, then at this point, the value's length (in target bytes) is
391 TARGET_ADDR_BIT/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
392 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
393 len
= TARGET_ADDR_BIT
/ TARGET_CHAR_BIT
;
395 /* If we are printing it as unsigned, truncate it in case it is actually
396 a negative signed value (e.g. "print/u (short)-1" should print 65535
397 (if shorts are 16 bits) instead of 4294967295). */
400 if (len
< sizeof (LONGEST
))
401 val_long
&= ((LONGEST
) 1 << HOST_CHAR_BIT
* len
) - 1;
409 /* no size specified, like in print. Print varying # of digits. */
410 print_longest (stream
, 'x', 1, val_long
);
419 print_longest (stream
, size
, 1, val_long
);
422 error (_("Undefined output size \"%c\"."), size
);
427 print_longest (stream
, 'd', 1, val_long
);
431 print_longest (stream
, 'u', 0, val_long
);
436 print_longest (stream
, 'o', 1, val_long
);
438 fprintf_filtered (stream
, "0");
443 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
444 print_address (addr
, stream
);
449 value_print (value_from_longest (builtin_type_true_char
, val_long
),
450 stream
, 0, Val_pretty_default
);
454 if (len
== TYPE_LENGTH (builtin_type_float
))
455 type
= builtin_type_float
;
456 else if (len
== TYPE_LENGTH (builtin_type_double
))
457 type
= builtin_type_double
;
458 else if (len
== TYPE_LENGTH (builtin_type_long_double
))
459 type
= builtin_type_long_double
;
460 print_floating (valaddr
, type
, stream
);
464 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
467 /* Binary; 't' stands for "two". */
469 char bits
[8 * (sizeof val_long
) + 1];
470 char buf
[8 * (sizeof val_long
) + 32];
475 width
= 8 * (sizeof val_long
);
492 error (_("Undefined output size \"%c\"."), size
);
498 bits
[width
] = (val_long
& 1) ? '1' : '0';
503 while (*cp
&& *cp
== '0')
509 fputs_filtered (buf
, stream
);
514 error (_("Undefined output format \"%c\"."), format
);
518 /* Specify default address for `x' command.
519 `info lines' uses this. */
522 set_next_address (CORE_ADDR addr
)
526 /* Make address available to the user as $_. */
527 set_internalvar (lookup_internalvar ("_"),
528 value_from_pointer (lookup_pointer_type (builtin_type_void
),
532 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
533 after LEADIN. Print nothing if no symbolic name is found nearby.
534 Optionally also print source file and line number, if available.
535 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
536 or to interpret it as a possible C++ name and convert it back to source
537 form. However note that DO_DEMANGLE can be overridden by the specific
538 settings of the demangle and asm_demangle variables. */
541 print_address_symbolic (CORE_ADDR addr
, struct ui_file
*stream
, int do_demangle
,
545 char *filename
= NULL
;
550 /* throw away both name and filename */
551 struct cleanup
*cleanup_chain
= make_cleanup (free_current_contents
, &name
);
552 make_cleanup (free_current_contents
, &filename
);
554 if (build_address_symbolic (addr
, do_demangle
, &name
, &offset
, &filename
, &line
, &unmapped
))
556 do_cleanups (cleanup_chain
);
560 fputs_filtered (leadin
, stream
);
562 fputs_filtered ("<*", stream
);
564 fputs_filtered ("<", stream
);
565 fputs_filtered (name
, stream
);
567 fprintf_filtered (stream
, "+%u", (unsigned int) offset
);
569 /* Append source filename and line number if desired. Give specific
570 line # of this addr, if we have it; else line # of the nearest symbol. */
571 if (print_symbol_filename
&& filename
!= NULL
)
574 fprintf_filtered (stream
, " at %s:%d", filename
, line
);
576 fprintf_filtered (stream
, " in %s", filename
);
579 fputs_filtered ("*>", stream
);
581 fputs_filtered (">", stream
);
583 do_cleanups (cleanup_chain
);
586 /* Given an address ADDR return all the elements needed to print the
587 address in a symbolic form. NAME can be mangled or not depending
588 on DO_DEMANGLE (and also on the asm_demangle global variable,
589 manipulated via ''set print asm-demangle''). Return 0 in case of
590 success, when all the info in the OUT paramters is valid. Return 1
593 build_address_symbolic (CORE_ADDR addr
, /* IN */
594 int do_demangle
, /* IN */
595 char **name
, /* OUT */
596 int *offset
, /* OUT */
597 char **filename
, /* OUT */
599 int *unmapped
) /* OUT */
601 struct minimal_symbol
*msymbol
;
602 struct symbol
*symbol
;
603 struct symtab
*symtab
= 0;
604 CORE_ADDR name_location
= 0;
605 asection
*section
= 0;
606 char *name_temp
= "";
608 /* Let's say it is unmapped. */
611 /* Determine if the address is in an overlay, and whether it is
613 if (overlay_debugging
)
615 section
= find_pc_overlay (addr
);
616 if (pc_in_unmapped_range (addr
, section
))
619 addr
= overlay_mapped_address (addr
, section
);
623 /* First try to find the address in the symbol table, then
624 in the minsyms. Take the closest one. */
626 /* This is defective in the sense that it only finds text symbols. So
627 really this is kind of pointless--we should make sure that the
628 minimal symbols have everything we need (by changing that we could
629 save some memory, but for many debug format--ELF/DWARF or
630 anything/stabs--it would be inconvenient to eliminate those minimal
632 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
633 symbol
= find_pc_sect_function (addr
, section
);
637 name_location
= BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
));
638 if (do_demangle
|| asm_demangle
)
639 name_temp
= SYMBOL_PRINT_NAME (symbol
);
641 name_temp
= DEPRECATED_SYMBOL_NAME (symbol
);
646 if (SYMBOL_VALUE_ADDRESS (msymbol
) > name_location
|| symbol
== NULL
)
648 /* The msymbol is closer to the address than the symbol;
649 use the msymbol instead. */
652 name_location
= SYMBOL_VALUE_ADDRESS (msymbol
);
653 if (do_demangle
|| asm_demangle
)
654 name_temp
= SYMBOL_PRINT_NAME (msymbol
);
656 name_temp
= DEPRECATED_SYMBOL_NAME (msymbol
);
659 if (symbol
== NULL
&& msymbol
== NULL
)
662 /* If the nearest symbol is too far away, don't print anything symbolic. */
664 /* For when CORE_ADDR is larger than unsigned int, we do math in
665 CORE_ADDR. But when we detect unsigned wraparound in the
666 CORE_ADDR math, we ignore this test and print the offset,
667 because addr+max_symbolic_offset has wrapped through the end
668 of the address space back to the beginning, giving bogus comparison. */
669 if (addr
> name_location
+ max_symbolic_offset
670 && name_location
+ max_symbolic_offset
> name_location
)
673 *offset
= addr
- name_location
;
675 *name
= xstrdup (name_temp
);
677 if (print_symbol_filename
)
679 struct symtab_and_line sal
;
681 sal
= find_pc_sect_line (addr
, section
, 0);
685 *filename
= xstrdup (sal
.symtab
->filename
);
688 else if (symtab
&& symbol
&& symbol
->line
)
690 *filename
= xstrdup (symtab
->filename
);
691 *line
= symbol
->line
;
695 *filename
= xstrdup (symtab
->filename
);
702 /* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
705 deprecated_print_address_numeric (CORE_ADDR addr
, int use_local
,
706 struct ui_file
*stream
)
709 fputs_filtered (paddress (addr
), stream
);
712 int addr_bit
= TARGET_ADDR_BIT
;
714 if (addr_bit
< (sizeof (CORE_ADDR
) * HOST_CHAR_BIT
))
715 addr
&= ((CORE_ADDR
) 1 << addr_bit
) - 1;
716 print_longest (stream
, 'x', 0, (ULONGEST
) addr
);
720 /* Print address ADDR symbolically on STREAM.
721 First print it as a number. Then perhaps print
722 <SYMBOL + OFFSET> after the number. */
725 print_address (CORE_ADDR addr
, struct ui_file
*stream
)
727 deprecated_print_address_numeric (addr
, 1, stream
);
728 print_address_symbolic (addr
, stream
, asm_demangle
, " ");
731 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
732 controls whether to print the symbolic name "raw" or demangled.
733 Global setting "addressprint" controls whether to print hex address
737 print_address_demangle (CORE_ADDR addr
, struct ui_file
*stream
, int do_demangle
)
741 fprintf_filtered (stream
, "0");
743 else if (addressprint
)
745 deprecated_print_address_numeric (addr
, 1, stream
);
746 print_address_symbolic (addr
, stream
, do_demangle
, " ");
750 print_address_symbolic (addr
, stream
, do_demangle
, "");
755 /* These are the types that $__ will get after an examine command of one
758 static struct type
*examine_i_type
;
760 static struct type
*examine_b_type
;
761 static struct type
*examine_h_type
;
762 static struct type
*examine_w_type
;
763 static struct type
*examine_g_type
;
765 /* Examine data at address ADDR in format FMT.
766 Fetch it from memory and print on gdb_stdout. */
769 do_examine (struct format_data fmt
, CORE_ADDR addr
)
774 struct type
*val_type
= NULL
;
783 /* String or instruction format implies fetch single bytes
784 regardless of the specified size. */
785 if (format
== 's' || format
== 'i')
789 val_type
= examine_i_type
;
790 else if (size
== 'b')
791 val_type
= examine_b_type
;
792 else if (size
== 'h')
793 val_type
= examine_h_type
;
794 else if (size
== 'w')
795 val_type
= examine_w_type
;
796 else if (size
== 'g')
797 val_type
= examine_g_type
;
804 if (format
== 's' || format
== 'i')
807 /* Print as many objects as specified in COUNT, at most maxelts per line,
808 with the address of the next one at the start of each line. */
813 print_address (next_address
, gdb_stdout
);
814 printf_filtered (":");
819 printf_filtered ("\t");
820 /* Note that print_formatted sets next_address for the next
822 last_examine_address
= next_address
;
824 if (last_examine_value
)
825 value_free (last_examine_value
);
827 /* The value to be displayed is not fetched greedily.
828 Instead, to avoid the posibility of a fetched value not
829 being used, its retreval is delayed until the print code
830 uses it. When examining an instruction stream, the
831 disassembler will perform its own memory fetch using just
832 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
833 the disassembler be modified so that LAST_EXAMINE_VALUE
834 is left with the byte sequence from the last complete
835 instruction fetched from memory? */
836 last_examine_value
= value_at_lazy (val_type
, next_address
);
838 if (last_examine_value
)
839 release_value (last_examine_value
);
841 print_formatted (last_examine_value
, format
, size
, gdb_stdout
);
843 printf_filtered ("\n");
844 gdb_flush (gdb_stdout
);
849 validate_format (struct format_data fmt
, char *cmdname
)
852 error (_("Size letters are meaningless in \"%s\" command."), cmdname
);
854 error (_("Item count other than 1 is meaningless in \"%s\" command."),
856 if (fmt
.format
== 'i' || fmt
.format
== 's')
857 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
858 fmt
.format
, cmdname
);
861 /* Evaluate string EXP as an expression in the current language and
862 print the resulting value. EXP may contain a format specifier as the
863 first argument ("/x myvar" for example, to print myvar in hex).
867 print_command_1 (char *exp
, int inspect
, int voidprint
)
869 struct expression
*expr
;
870 struct cleanup
*old_chain
= 0;
873 struct format_data fmt
;
876 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
877 inspect_it
= inspect
;
879 if (exp
&& *exp
== '/')
882 fmt
= decode_format (&exp
, last_format
, 0);
883 validate_format (fmt
, "print");
884 last_format
= format
= fmt
.format
;
896 expr
= parse_expression (exp
);
897 old_chain
= make_cleanup (free_current_contents
, &expr
);
899 val
= evaluate_expression (expr
);
902 val
= access_value_history (0);
904 if (voidprint
|| (val
&& value_type (val
) &&
905 TYPE_CODE (value_type (val
)) != TYPE_CODE_VOID
))
907 int histindex
= record_latest_value (val
);
910 annotate_value_history_begin (histindex
, value_type (val
));
912 annotate_value_begin (value_type (val
));
915 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp
, histindex
);
916 else if (histindex
>= 0)
917 printf_filtered ("$%d = ", histindex
);
920 annotate_value_history_value ();
922 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
923 printf_filtered ("\n");
926 annotate_value_history_end ();
928 annotate_value_end ();
931 printf_unfiltered ("\") )\030");
935 do_cleanups (old_chain
);
936 inspect_it
= 0; /* Reset print routines to normal */
940 print_command (char *exp
, int from_tty
)
942 print_command_1 (exp
, 0, 1);
945 /* Same as print, except in epoch, it gets its own window */
947 inspect_command (char *exp
, int from_tty
)
949 extern int epoch_interface
;
951 print_command_1 (exp
, epoch_interface
, 1);
954 /* Same as print, except it doesn't print void results. */
956 call_command (char *exp
, int from_tty
)
958 print_command_1 (exp
, 0, 0);
962 output_command (char *exp
, int from_tty
)
964 struct expression
*expr
;
965 struct cleanup
*old_chain
;
968 struct format_data fmt
;
970 if (exp
&& *exp
== '/')
973 fmt
= decode_format (&exp
, 0, 0);
974 validate_format (fmt
, "output");
978 expr
= parse_expression (exp
);
979 old_chain
= make_cleanup (free_current_contents
, &expr
);
981 val
= evaluate_expression (expr
);
983 annotate_value_begin (value_type (val
));
985 print_formatted (val
, format
, fmt
.size
, gdb_stdout
);
987 annotate_value_end ();
990 gdb_flush (gdb_stdout
);
992 do_cleanups (old_chain
);
996 set_command (char *exp
, int from_tty
)
998 struct expression
*expr
= parse_expression (exp
);
999 struct cleanup
*old_chain
=
1000 make_cleanup (free_current_contents
, &expr
);
1001 evaluate_expression (expr
);
1002 do_cleanups (old_chain
);
1006 sym_info (char *arg
, int from_tty
)
1008 struct minimal_symbol
*msymbol
;
1009 struct objfile
*objfile
;
1010 struct obj_section
*osect
;
1012 CORE_ADDR addr
, sect_addr
;
1014 unsigned int offset
;
1017 error_no_arg (_("address"));
1019 addr
= parse_and_eval_address (arg
);
1020 ALL_OBJSECTIONS (objfile
, osect
)
1022 sect
= osect
->the_bfd_section
;
1023 sect_addr
= overlay_mapped_address (addr
, sect
);
1025 if (osect
->addr
<= sect_addr
&& sect_addr
< osect
->endaddr
&&
1026 (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr
, sect
)))
1029 offset
= sect_addr
- SYMBOL_VALUE_ADDRESS (msymbol
);
1031 printf_filtered ("%s + %u in ",
1032 SYMBOL_PRINT_NAME (msymbol
), offset
);
1034 printf_filtered ("%s in ",
1035 SYMBOL_PRINT_NAME (msymbol
));
1036 if (pc_in_unmapped_range (addr
, sect
))
1037 printf_filtered (_("load address range of "));
1038 if (section_is_overlay (sect
))
1039 printf_filtered (_("%s overlay "),
1040 section_is_mapped (sect
) ? "mapped" : "unmapped");
1041 printf_filtered (_("section %s"), sect
->name
);
1042 printf_filtered ("\n");
1046 printf_filtered (_("No symbol matches %s.\n"), arg
);
1050 address_info (char *exp
, int from_tty
)
1053 struct minimal_symbol
*msymbol
;
1057 CORE_ADDR load_addr
;
1058 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
1059 if exp is a field of `this'. */
1062 error (_("Argument required."));
1064 sym
= lookup_symbol (exp
, get_selected_block (0), VAR_DOMAIN
,
1065 &is_a_field_of_this
, (struct symtab
**) NULL
);
1068 if (is_a_field_of_this
)
1070 printf_filtered ("Symbol \"");
1071 fprintf_symbol_filtered (gdb_stdout
, exp
,
1072 current_language
->la_language
, DMGL_ANSI
);
1073 printf_filtered ("\" is a field of the local class variable ");
1074 if (current_language
->la_language
== language_objc
)
1075 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1077 printf_filtered ("`this'\n");
1081 msymbol
= lookup_minimal_symbol (exp
, NULL
, NULL
);
1083 if (msymbol
!= NULL
)
1085 load_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
1087 printf_filtered ("Symbol \"");
1088 fprintf_symbol_filtered (gdb_stdout
, exp
,
1089 current_language
->la_language
, DMGL_ANSI
);
1090 printf_filtered ("\" is at ");
1091 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1092 printf_filtered (" in a file compiled without debugging");
1093 section
= SYMBOL_BFD_SECTION (msymbol
);
1094 if (section_is_overlay (section
))
1096 load_addr
= overlay_unmapped_address (load_addr
, section
);
1097 printf_filtered (",\n -- loaded at ");
1098 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1099 printf_filtered (" in overlay section %s", section
->name
);
1101 printf_filtered (".\n");
1104 error (_("No symbol \"%s\" in current context."), exp
);
1108 printf_filtered ("Symbol \"");
1109 fprintf_symbol_filtered (gdb_stdout
, DEPRECATED_SYMBOL_NAME (sym
),
1110 current_language
->la_language
, DMGL_ANSI
);
1111 printf_filtered ("\" is ");
1112 val
= SYMBOL_VALUE (sym
);
1113 basereg
= SYMBOL_BASEREG (sym
);
1114 section
= SYMBOL_BFD_SECTION (sym
);
1116 switch (SYMBOL_CLASS (sym
))
1119 case LOC_CONST_BYTES
:
1120 printf_filtered ("constant");
1124 printf_filtered ("a label at address ");
1125 deprecated_print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1127 if (section_is_overlay (section
))
1129 load_addr
= overlay_unmapped_address (load_addr
, section
);
1130 printf_filtered (",\n -- loaded at ");
1131 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1132 printf_filtered (" in overlay section %s", section
->name
);
1137 case LOC_COMPUTED_ARG
:
1138 /* FIXME: cagney/2004-01-26: It should be possible to
1139 unconditionally call the SYMBOL_OPS method when available.
1140 Unfortunately DWARF 2 stores the frame-base (instead of the
1141 function) location in a function's symbol. Oops! For the
1142 moment enable this when/where applicable. */
1143 SYMBOL_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1147 printf_filtered (_("a variable in register %s"), REGISTER_NAME (val
));
1151 printf_filtered (_("static storage at address "));
1152 deprecated_print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1154 if (section_is_overlay (section
))
1156 load_addr
= overlay_unmapped_address (load_addr
, section
);
1157 printf_filtered (_(",\n -- loaded at "));
1158 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1159 printf_filtered (_(" in overlay section %s"), section
->name
);
1164 printf_filtered (_("external global (indirect addressing), at address *("));
1165 deprecated_print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (sym
),
1167 printf_filtered (")");
1168 if (section_is_overlay (section
))
1170 load_addr
= overlay_unmapped_address (load_addr
, section
);
1171 printf_filtered (_(",\n -- loaded at "));
1172 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1173 printf_filtered (_(" in overlay section %s"), section
->name
);
1178 printf_filtered (_("an argument in register %s"), REGISTER_NAME (val
));
1181 case LOC_REGPARM_ADDR
:
1182 printf_filtered (_("address of an argument in register %s"), REGISTER_NAME (val
));
1186 printf_filtered (_("an argument at offset %ld"), val
);
1190 printf_filtered (_("an argument at frame offset %ld"), val
);
1194 printf_filtered (_("a local variable at frame offset %ld"), val
);
1198 printf_filtered (_("a reference argument at offset %ld"), val
);
1202 printf_filtered (_("a variable at offset %ld from register %s"),
1203 val
, REGISTER_NAME (basereg
));
1206 case LOC_BASEREG_ARG
:
1207 printf_filtered (_("an argument at offset %ld from register %s"),
1208 val
, REGISTER_NAME (basereg
));
1212 printf_filtered (_("a typedef"));
1216 printf_filtered (_("a function at address "));
1217 deprecated_print_address_numeric (load_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)),
1219 if (section_is_overlay (section
))
1221 load_addr
= overlay_unmapped_address (load_addr
, section
);
1222 printf_filtered (_(",\n -- loaded at "));
1223 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1224 printf_filtered (_(" in overlay section %s"), section
->name
);
1228 case LOC_UNRESOLVED
:
1230 struct minimal_symbol
*msym
;
1232 msym
= lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym
), NULL
, NULL
);
1234 printf_filtered ("unresolved");
1237 section
= SYMBOL_BFD_SECTION (msym
);
1238 printf_filtered (_("static storage at address "));
1239 deprecated_print_address_numeric (load_addr
= SYMBOL_VALUE_ADDRESS (msym
),
1241 if (section_is_overlay (section
))
1243 load_addr
= overlay_unmapped_address (load_addr
, section
);
1244 printf_filtered (_(",\n -- loaded at "));
1245 deprecated_print_address_numeric (load_addr
, 1, gdb_stdout
);
1246 printf_filtered (_(" in overlay section %s"), section
->name
);
1252 case LOC_HP_THREAD_LOCAL_STATIC
:
1254 "a thread-local variable at offset %ld from the thread base register %s",
1255 val
, REGISTER_NAME (basereg
));
1258 case LOC_OPTIMIZED_OUT
:
1259 printf_filtered (_("optimized out"));
1263 printf_filtered (_("of unknown (botched) type"));
1266 printf_filtered (".\n");
1270 x_command (char *exp
, int from_tty
)
1272 struct expression
*expr
;
1273 struct format_data fmt
;
1274 struct cleanup
*old_chain
;
1277 fmt
.format
= last_format
;
1278 fmt
.size
= last_size
;
1281 if (exp
&& *exp
== '/')
1284 fmt
= decode_format (&exp
, last_format
, last_size
);
1287 /* If we have an expression, evaluate it and use it as the address. */
1289 if (exp
!= 0 && *exp
!= 0)
1291 expr
= parse_expression (exp
);
1292 /* Cause expression not to be there any more
1293 if this command is repeated with Newline.
1294 But don't clobber a user-defined command's definition. */
1297 old_chain
= make_cleanup (free_current_contents
, &expr
);
1298 val
= evaluate_expression (expr
);
1299 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_REF
)
1300 val
= value_ind (val
);
1301 /* In rvalue contexts, such as this, functions are coerced into
1302 pointers to functions. This makes "x/i main" work. */
1303 if (/* last_format == 'i' && */
1304 TYPE_CODE (value_type (val
)) == TYPE_CODE_FUNC
1305 && VALUE_LVAL (val
) == lval_memory
)
1306 next_address
= VALUE_ADDRESS (val
);
1308 next_address
= value_as_address (val
);
1309 do_cleanups (old_chain
);
1312 do_examine (fmt
, next_address
);
1314 /* If the examine succeeds, we remember its size and format for next time. */
1315 last_size
= fmt
.size
;
1316 last_format
= fmt
.format
;
1318 /* Set a couple of internal variables if appropriate. */
1319 if (last_examine_value
)
1321 /* Make last address examined available to the user as $_. Use
1322 the correct pointer type. */
1323 struct type
*pointer_type
1324 = lookup_pointer_type (value_type (last_examine_value
));
1325 set_internalvar (lookup_internalvar ("_"),
1326 value_from_pointer (pointer_type
,
1327 last_examine_address
));
1329 /* Make contents of last address examined available to the user as $__. */
1330 /* If the last value has not been fetched from memory then don't
1331 fetch it now - instead mark it by voiding the $__ variable. */
1332 if (value_lazy (last_examine_value
))
1333 set_internalvar (lookup_internalvar ("__"),
1334 allocate_value (builtin_type_void
));
1336 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1341 /* Add an expression to the auto-display chain.
1342 Specify the expression. */
1345 display_command (char *exp
, int from_tty
)
1347 struct format_data fmt
;
1348 struct expression
*expr
;
1349 struct display
*new;
1353 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1355 if (tui_active
&& exp
!= NULL
&& *exp
== '$')
1356 display_it
= (tui_set_layout_for_display_command (exp
) == TUI_FAILURE
);
1370 fmt
= decode_format (&exp
, 0, 0);
1371 if (fmt
.size
&& fmt
.format
== 0)
1373 if (fmt
.format
== 'i' || fmt
.format
== 's')
1383 innermost_block
= 0;
1384 expr
= parse_expression (exp
);
1386 new = (struct display
*) xmalloc (sizeof (struct display
));
1389 new->block
= innermost_block
;
1390 new->next
= display_chain
;
1391 new->number
= ++display_number
;
1394 display_chain
= new;
1396 if (from_tty
&& target_has_execution
)
1397 do_one_display (new);
1404 free_display (struct display
*d
)
1410 /* Clear out the display_chain.
1411 Done when new symtabs are loaded, since this invalidates
1412 the types stored in many expressions. */
1415 clear_displays (void)
1419 while ((d
= display_chain
) != NULL
)
1422 display_chain
= d
->next
;
1427 /* Delete the auto-display number NUM. */
1430 delete_display (int num
)
1432 struct display
*d1
, *d
;
1435 error (_("No display number %d."), num
);
1437 if (display_chain
->number
== num
)
1440 display_chain
= d1
->next
;
1444 for (d
= display_chain
;; d
= d
->next
)
1447 error (_("No display number %d."), num
);
1448 if (d
->next
->number
== num
)
1458 /* Delete some values from the auto-display chain.
1459 Specify the element numbers. */
1462 undisplay_command (char *args
, int from_tty
)
1470 if (query ("Delete all auto-display expressions? "))
1479 while (*p1
>= '0' && *p1
<= '9')
1481 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1482 error (_("Arguments must be display numbers."));
1486 delete_display (num
);
1489 while (*p
== ' ' || *p
== '\t')
1495 /* Display a single auto-display.
1496 Do nothing if the display cannot be printed in the current context,
1497 or if the display is disabled. */
1500 do_one_display (struct display
*d
)
1502 int within_current_scope
;
1504 if (d
->enabled_p
== 0)
1508 within_current_scope
= contained_in (get_selected_block (0), d
->block
);
1510 within_current_scope
= 1;
1511 if (!within_current_scope
)
1514 current_display_number
= d
->number
;
1516 annotate_display_begin ();
1517 printf_filtered ("%d", d
->number
);
1518 annotate_display_number_end ();
1519 printf_filtered (": ");
1525 annotate_display_format ();
1527 printf_filtered ("x/");
1528 if (d
->format
.count
!= 1)
1529 printf_filtered ("%d", d
->format
.count
);
1530 printf_filtered ("%c", d
->format
.format
);
1531 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1532 printf_filtered ("%c", d
->format
.size
);
1533 printf_filtered (" ");
1535 annotate_display_expression ();
1537 print_expression (d
->exp
, gdb_stdout
);
1538 annotate_display_expression_end ();
1540 if (d
->format
.count
!= 1)
1541 printf_filtered ("\n");
1543 printf_filtered (" ");
1545 val
= evaluate_expression (d
->exp
);
1546 addr
= value_as_address (val
);
1547 if (d
->format
.format
== 'i')
1548 addr
= ADDR_BITS_REMOVE (addr
);
1550 annotate_display_value ();
1552 do_examine (d
->format
, addr
);
1556 annotate_display_format ();
1558 if (d
->format
.format
)
1559 printf_filtered ("/%c ", d
->format
.format
);
1561 annotate_display_expression ();
1563 print_expression (d
->exp
, gdb_stdout
);
1564 annotate_display_expression_end ();
1566 printf_filtered (" = ");
1568 annotate_display_expression ();
1570 print_formatted (evaluate_expression (d
->exp
),
1571 d
->format
.format
, d
->format
.size
, gdb_stdout
);
1572 printf_filtered ("\n");
1575 annotate_display_end ();
1577 gdb_flush (gdb_stdout
);
1578 current_display_number
= -1;
1581 /* Display all of the values on the auto-display chain which can be
1582 evaluated in the current scope. */
1589 for (d
= display_chain
; d
; d
= d
->next
)
1593 /* Delete the auto-display which we were in the process of displaying.
1594 This is done when there is an error or a signal. */
1597 disable_display (int num
)
1601 for (d
= display_chain
; d
; d
= d
->next
)
1602 if (d
->number
== num
)
1607 printf_unfiltered (_("No display number %d.\n"), num
);
1611 disable_current_display (void)
1613 if (current_display_number
>= 0)
1615 disable_display (current_display_number
);
1616 fprintf_unfiltered (gdb_stderr
, "Disabling display %d to avoid infinite recursion.\n",
1617 current_display_number
);
1619 current_display_number
= -1;
1623 display_info (char *ignore
, int from_tty
)
1628 printf_unfiltered (_("There are no auto-display expressions now.\n"));
1630 printf_filtered (_("Auto-display expressions now in effect:\n\
1631 Num Enb Expression\n"));
1633 for (d
= display_chain
; d
; d
= d
->next
)
1635 printf_filtered ("%d: %c ", d
->number
, "ny"[(int) d
->enabled_p
]);
1637 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1639 else if (d
->format
.format
)
1640 printf_filtered ("/%c ", d
->format
.format
);
1641 print_expression (d
->exp
, gdb_stdout
);
1642 if (d
->block
&& !contained_in (get_selected_block (0), d
->block
))
1643 printf_filtered (_(" (cannot be evaluated in the current context)"));
1644 printf_filtered ("\n");
1645 gdb_flush (gdb_stdout
);
1650 enable_display (char *args
, int from_tty
)
1659 for (d
= display_chain
; d
; d
= d
->next
)
1666 while (*p1
>= '0' && *p1
<= '9')
1668 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1669 error (_("Arguments must be display numbers."));
1673 for (d
= display_chain
; d
; d
= d
->next
)
1674 if (d
->number
== num
)
1679 printf_unfiltered (_("No display number %d.\n"), num
);
1682 while (*p
== ' ' || *p
== '\t')
1688 disable_display_command (char *args
, int from_tty
)
1696 for (d
= display_chain
; d
; d
= d
->next
)
1703 while (*p1
>= '0' && *p1
<= '9')
1705 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
1706 error (_("Arguments must be display numbers."));
1708 disable_display (atoi (p
));
1711 while (*p
== ' ' || *p
== '\t')
1717 /* Print the value in stack frame FRAME of a variable
1718 specified by a struct symbol. */
1721 print_variable_value (struct symbol
*var
, struct frame_info
*frame
,
1722 struct ui_file
*stream
)
1724 struct value
*val
= read_var_value (var
, frame
);
1726 value_print (val
, stream
, 0, Val_pretty_default
);
1730 printf_command (char *arg
, int from_tty
)
1734 char *string
= NULL
;
1735 struct value
**val_args
;
1737 char *current_substring
;
1739 int allocated_args
= 20;
1740 struct cleanup
*old_cleanups
;
1742 val_args
= (struct value
**) xmalloc (allocated_args
1743 * sizeof (struct value
*));
1744 old_cleanups
= make_cleanup (free_current_contents
, &val_args
);
1747 error_no_arg (_("format-control string and values to print"));
1749 /* Skip white space before format string */
1750 while (*s
== ' ' || *s
== '\t')
1753 /* A format string should follow, enveloped in double quotes */
1755 error (_("Bad format string, missing '\"'."));
1757 /* Parse the format-control string and copy it into the string STRING,
1758 processing some kinds of escape sequence. */
1760 f
= string
= (char *) alloca (strlen (s
) + 1);
1768 error (_("Bad format string, non-terminated '\"'."));
1801 /* ??? TODO: handle other escape sequences */
1802 error (_("Unrecognized escape character \\%c in format string."),
1812 /* Skip over " and following space and comma. */
1815 while (*s
== ' ' || *s
== '\t')
1818 if (*s
!= ',' && *s
!= 0)
1819 error (_("Invalid argument syntax"));
1823 while (*s
== ' ' || *s
== '\t')
1826 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1827 substrings
= alloca (strlen (string
) * 2);
1828 current_substring
= substrings
;
1831 /* Now scan the string for %-specs and see what kinds of args they want.
1832 argclass[I] classifies the %-specs so we can give printf_filtered
1833 something of the right size. */
1837 no_arg
, int_arg
, string_arg
, double_arg
, long_long_arg
1839 enum argclass
*argclass
;
1840 enum argclass this_argclass
;
1846 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
1854 while (strchr ("0123456789.hlL-+ #", *f
))
1856 if (*f
== 'l' || *f
== 'L')
1863 this_argclass
= string_arg
;
1869 this_argclass
= double_arg
;
1873 error (_("`*' not supported for precision or width in printf"));
1876 error (_("Format specifier `n' not supported in printf"));
1879 this_argclass
= no_arg
;
1884 this_argclass
= long_long_arg
;
1886 this_argclass
= int_arg
;
1890 if (this_argclass
!= no_arg
)
1892 strncpy (current_substring
, last_arg
, f
- last_arg
);
1893 current_substring
+= f
- last_arg
;
1894 *current_substring
++ = '\0';
1896 argclass
[nargs_wanted
++] = this_argclass
;
1900 /* Now, parse all arguments and evaluate them.
1901 Store the VALUEs in VAL_ARGS. */
1906 if (nargs
== allocated_args
)
1907 val_args
= (struct value
**) xrealloc ((char *) val_args
,
1908 (allocated_args
*= 2)
1909 * sizeof (struct value
*));
1911 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
1913 /* If format string wants a float, unchecked-convert the value to
1914 floating point of the same size */
1916 if (argclass
[nargs
] == double_arg
)
1918 struct type
*type
= value_type (val_args
[nargs
]);
1919 if (TYPE_LENGTH (type
) == sizeof (float))
1920 deprecated_set_value_type (val_args
[nargs
], builtin_type_float
);
1921 if (TYPE_LENGTH (type
) == sizeof (double))
1922 deprecated_set_value_type (val_args
[nargs
], builtin_type_double
);
1930 if (nargs
!= nargs_wanted
)
1931 error (_("Wrong number of arguments for specified format-string"));
1933 /* Now actually print them. */
1934 current_substring
= substrings
;
1935 for (i
= 0; i
< nargs
; i
++)
1937 switch (argclass
[i
])
1944 tem
= value_as_address (val_args
[i
]);
1946 /* This is a %s argument. Find the length of the string. */
1951 read_memory (tem
+ j
, &c
, 1);
1956 /* Copy the string contents into a string inside GDB. */
1957 str
= (char *) alloca (j
+ 1);
1959 read_memory (tem
, str
, j
);
1962 printf_filtered (current_substring
, str
);
1967 double val
= value_as_double (val_args
[i
]);
1968 printf_filtered (current_substring
, val
);
1972 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
1974 long long val
= value_as_long (val_args
[i
]);
1975 printf_filtered (current_substring
, val
);
1979 error (_("long long not supported in printf"));
1983 /* FIXME: there should be separate int_arg and long_arg. */
1984 long val
= value_as_long (val_args
[i
]);
1985 printf_filtered (current_substring
, val
);
1988 default: /* purecov: deadcode */
1989 error (_("internal error in printf_command")); /* purecov: deadcode */
1991 /* Skip to the next substring. */
1992 current_substring
+= strlen (current_substring
) + 1;
1994 /* Print the portion of the format string after the last argument. */
1995 puts_filtered (last_arg
);
1997 do_cleanups (old_cleanups
);
2001 _initialize_printcmd (void)
2003 struct cmd_list_element
*c
;
2005 current_display_number
= -1;
2007 add_info ("address", address_info
,
2008 _("Describe where symbol SYM is stored."));
2010 add_info ("symbol", sym_info
, _("\
2011 Describe what symbol is at location ADDR.\n\
2012 Only for symbols with fixed locations (global or static scope)."));
2014 add_com ("x", class_vars
, x_command
, _("\
2015 Examine memory: x/FMT ADDRESS.\n\
2016 ADDRESS is an expression for the memory address to examine.\n\
2017 FMT is a repeat count followed by a format letter and a size letter.\n\
2018 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2019 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2020 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2021 The specified number of objects of the specified size are printed\n\
2022 according to the format.\n\n\
2023 Defaults for format and size letters are those previously used.\n\
2024 Default count is 1. Default address is following last thing printed\n\
2025 with this command or \"print\"."));
2028 add_com ("whereis", class_vars
, whereis_command
,
2029 _("Print line number and file of definition of variable."));
2032 add_info ("display", display_info
, _("\
2033 Expressions to display when program stops, with code numbers."));
2035 add_cmd ("undisplay", class_vars
, undisplay_command
, _("\
2036 Cancel some expressions to be displayed when program stops.\n\
2037 Arguments are the code numbers of the expressions to stop displaying.\n\
2038 No argument means cancel all automatic-display expressions.\n\
2039 \"delete display\" has the same effect as this command.\n\
2040 Do \"info display\" to see current list of code numbers."),
2043 add_com ("display", class_vars
, display_command
, _("\
2044 Print value of expression EXP each time the program stops.\n\
2045 /FMT may be used before EXP as in the \"print\" command.\n\
2046 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2047 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2048 and examining is done as in the \"x\" command.\n\n\
2049 With no argument, display all currently requested auto-display expressions.\n\
2050 Use \"undisplay\" to cancel display requests previously made."));
2052 add_cmd ("display", class_vars
, enable_display
, _("\
2053 Enable some expressions to be displayed when program stops.\n\
2054 Arguments are the code numbers of the expressions to resume displaying.\n\
2055 No argument means enable all automatic-display expressions.\n\
2056 Do \"info display\" to see current list of code numbers."), &enablelist
);
2058 add_cmd ("display", class_vars
, disable_display_command
, _("\
2059 Disable some expressions to be displayed when program stops.\n\
2060 Arguments are the code numbers of the expressions to stop displaying.\n\
2061 No argument means disable all automatic-display expressions.\n\
2062 Do \"info display\" to see current list of code numbers."), &disablelist
);
2064 add_cmd ("display", class_vars
, undisplay_command
, _("\
2065 Cancel some expressions to be displayed when program stops.\n\
2066 Arguments are the code numbers of the expressions to stop displaying.\n\
2067 No argument means cancel all automatic-display expressions.\n\
2068 Do \"info display\" to see current list of code numbers."), &deletelist
);
2070 add_com ("printf", class_vars
, printf_command
, _("\
2071 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2072 This is useful for formatted output in user-defined commands."));
2074 add_com ("output", class_vars
, output_command
, _("\
2075 Like \"print\" but don't put in value history and don't print newline.\n\
2076 This is useful in user-defined commands."));
2078 add_prefix_cmd ("set", class_vars
, set_command
, _("\
2079 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2080 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2081 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2082 with $), a register (a few standard names starting with $), or an actual\n\
2083 variable in the program being debugged. EXP is any valid expression.\n\
2084 Use \"set variable\" for variables with names identical to set subcommands.\n\
2086 With a subcommand, this command modifies parts of the gdb environment.\n\
2087 You can see these environment settings with the \"show\" command."),
2088 &setlist
, "set ", 1, &cmdlist
);
2090 add_com ("assign", class_vars
, set_command
, _("\
2091 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2092 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2093 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2094 with $), a register (a few standard names starting with $), or an actual\n\
2095 variable in the program being debugged. EXP is any valid expression.\n\
2096 Use \"set variable\" for variables with names identical to set subcommands.\n\
2097 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2098 You can see these environment settings with the \"show\" command."));
2100 /* "call" is the same as "set", but handy for dbx users to call fns. */
2101 c
= add_com ("call", class_vars
, call_command
, _("\
2102 Call a function in the program.\n\
2103 The argument is the function name and arguments, in the notation of the\n\
2104 current working language. The result is printed and saved in the value\n\
2105 history, if it is not void."));
2106 set_cmd_completer (c
, location_completer
);
2108 add_cmd ("variable", class_vars
, set_command
, _("\
2109 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2110 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2111 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2112 with $), a register (a few standard names starting with $), or an actual\n\
2113 variable in the program being debugged. EXP is any valid expression.\n\
2114 This may usually be abbreviated to simply \"set\"."),
2117 c
= add_com ("print", class_vars
, print_command
, _("\
2118 Print value of expression EXP.\n\
2119 Variables accessible are those of the lexical environment of the selected\n\
2120 stack frame, plus all those whose scope is global or an entire file.\n\
2122 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2123 $$NUM refers to NUM'th value back from the last one.\n\
2124 Names starting with $ refer to registers (with the values they would have\n\
2125 if the program were to return to the stack frame now selected, restoring\n\
2126 all registers saved by frames farther in) or else to debugger\n\
2127 \"convenience\" variables (any such name not a known register).\n\
2128 Use assignment expressions to give values to convenience variables.\n\
2130 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2131 @ is a binary operator for treating consecutive data objects\n\
2132 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2133 element is FOO, whose second element is stored in the space following\n\
2134 where FOO is stored, etc. FOO must be an expression whose value\n\
2135 resides in memory.\n\
2137 EXP may be preceded with /FMT, where FMT is a format letter\n\
2138 but no count or size letter (see \"x\" command)."));
2139 set_cmd_completer (c
, location_completer
);
2140 add_com_alias ("p", "print", class_vars
, 1);
2142 c
= add_com ("inspect", class_vars
, inspect_command
, _("\
2143 Same as \"print\" command, except that if you are running in the epoch\n\
2144 environment, the value is printed in its own window."));
2145 set_cmd_completer (c
, location_completer
);
2147 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class
,
2148 &max_symbolic_offset
, _("\
2149 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2150 Show the largest offset that will be printed in <symbol+1234> form."), NULL
,
2152 show_max_symbolic_offset
,
2153 &setprintlist
, &showprintlist
);
2154 add_setshow_boolean_cmd ("symbol-filename", no_class
,
2155 &print_symbol_filename
, _("\
2156 Set printing of source filename and line number with <symbol>."), _("\
2157 Show printing of source filename and line number with <symbol>."), NULL
,
2159 show_print_symbol_filename
,
2160 &setprintlist
, &showprintlist
);
2162 /* For examine/instruction a single byte quantity is specified as
2163 the data. This avoids problems with value_at_lazy() requiring a
2164 valid data type (and rejecting VOID). */
2165 examine_i_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_i_type", NULL
);
2167 examine_b_type
= init_type (TYPE_CODE_INT
, 1, 0, "examine_b_type", NULL
);
2168 examine_h_type
= init_type (TYPE_CODE_INT
, 2, 0, "examine_h_type", NULL
);
2169 examine_w_type
= init_type (TYPE_CODE_INT
, 4, 0, "examine_w_type", NULL
);
2170 examine_g_type
= init_type (TYPE_CODE_INT
, 8, 0, "examine_g_type", NULL
);