1 /* Print values for GNU debugger GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "gdb_string.h"
29 #include "expression.h"
33 #include "breakpoint.h"
35 #include "gdb-demangle.h"
38 #include "symfile.h" /* for overlay functions */
39 #include "objfiles.h" /* ditto */
40 #include "completer.h" /* for completion functions */
42 #include "gdb_assert.h"
47 #include "exceptions.h"
50 #include "parser-defs.h"
52 #include "arch-utils.h"
53 #include "cli/cli-utils.h"
56 #include "tui/tui.h" /* For tui_active et al. */
59 #if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG)
60 # define USE_PRINTF_I64 1
61 # define PRINTF_HAS_LONG_LONG
63 # define USE_PRINTF_I64 0
72 /* True if the value should be printed raw -- that is, bypassing
73 python-based formatters. */
77 /* Last specified output format. */
79 static char last_format
= 0;
81 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
83 static char last_size
= 'w';
85 /* Default address to examine next, and associated architecture. */
87 static struct gdbarch
*next_gdbarch
;
88 static CORE_ADDR next_address
;
90 /* Number of delay instructions following current disassembled insn. */
92 static int branch_delay_insns
;
94 /* Last address examined. */
96 static CORE_ADDR last_examine_address
;
98 /* Contents of last address examined.
99 This is not valid past the end of the `x' command! */
101 static struct value
*last_examine_value
;
103 /* Largest offset between a symbolic value and an address, that will be
104 printed as `0x1234 <symbol+offset>'. */
106 static unsigned int max_symbolic_offset
= UINT_MAX
;
108 show_max_symbolic_offset (struct ui_file
*file
, int from_tty
,
109 struct cmd_list_element
*c
, const char *value
)
111 fprintf_filtered (file
,
112 _("The largest offset that will be "
113 "printed in <symbol+1234> form is %s.\n"),
117 /* Append the source filename and linenumber of the symbol when
118 printing a symbolic value as `<symbol at filename:linenum>' if set. */
119 static int print_symbol_filename
= 0;
121 show_print_symbol_filename (struct ui_file
*file
, int from_tty
,
122 struct cmd_list_element
*c
, const char *value
)
124 fprintf_filtered (file
, _("Printing of source filename and "
125 "line number with <symbol> is %s.\n"),
129 /* Number of auto-display expression currently being displayed.
130 So that we can disable it if we get a signal within it.
131 -1 when not doing one. */
133 int current_display_number
;
137 /* Chain link to next auto-display item. */
138 struct display
*next
;
140 /* The expression as the user typed it. */
143 /* Expression to be evaluated and displayed. */
144 struct expression
*exp
;
146 /* Item number of this auto-display item. */
149 /* Display format specified. */
150 struct format_data format
;
152 /* Program space associated with `block'. */
153 struct program_space
*pspace
;
155 /* Innermost block required by this expression when evaluated. */
158 /* Status of this display (enabled or disabled). */
162 /* Chain of expressions whose values should be displayed
163 automatically each time the program stops. */
165 static struct display
*display_chain
;
167 static int display_number
;
169 /* Walk the following statement or block through all displays.
170 ALL_DISPLAYS_SAFE does so even if the statement deletes the current
173 #define ALL_DISPLAYS(B) \
174 for (B = display_chain; B; B = B->next)
176 #define ALL_DISPLAYS_SAFE(B,TMP) \
177 for (B = display_chain; \
178 B ? (TMP = B->next, 1): 0; \
181 /* Prototypes for exported functions. */
183 void output_command (char *, int);
185 void _initialize_printcmd (void);
187 /* Prototypes for local functions. */
189 static void do_one_display (struct display
*);
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
;
213 if (*p
>= '0' && *p
<= '9')
214 val
.count
= atoi (p
);
215 while (*p
>= '0' && *p
<= '9')
218 /* Now process size or format letters that follow. */
222 if (*p
== 'b' || *p
== 'h' || *p
== 'w' || *p
== 'g')
229 else if (*p
>= 'a' && *p
<= 'z')
235 while (*p
== ' ' || *p
== '\t')
239 /* Set defaults for format and size if not specified. */
240 if (val
.format
== '?')
244 /* Neither has been specified. */
245 val
.format
= oformat
;
249 /* If a size is specified, any format makes a reasonable
250 default except 'i'. */
251 val
.format
= oformat
== 'i' ? 'x' : oformat
;
253 else if (val
.size
== '?')
257 /* Pick the appropriate size for an address. This is deferred
258 until do_examine when we know the actual architecture to use.
259 A special size value of 'a' is used to indicate this case. */
260 val
.size
= osize
? 'a' : osize
;
263 /* Floating point has to be word or giantword. */
264 if (osize
== 'w' || osize
== 'g')
267 /* Default it to giantword if the last used size is not
269 val
.size
= osize
? 'g' : osize
;
272 /* Characters default to one byte. */
273 val
.size
= osize
? 'b' : osize
;
276 /* Display strings with byte size chars unless explicitly
282 /* The default is the size most recently specified. */
289 /* Print value VAL on stream according to OPTIONS.
290 Do not end with a newline.
291 SIZE is the letter for the size of datum being printed.
292 This is used to pad hex numbers so they line up. SIZE is 0
293 for print / output and set for examine. */
296 print_formatted (struct value
*val
, int size
,
297 const struct value_print_options
*options
,
298 struct ui_file
*stream
)
300 struct type
*type
= check_typedef (value_type (val
));
301 int len
= TYPE_LENGTH (type
);
303 if (VALUE_LVAL (val
) == lval_memory
)
304 next_address
= value_address (val
) + len
;
308 switch (options
->format
)
312 struct type
*elttype
= value_type (val
);
314 next_address
= (value_address (val
)
315 + val_print_string (elttype
, NULL
,
316 value_address (val
), -1,
317 stream
, options
) * len
);
322 /* We often wrap here if there are long symbolic names. */
324 next_address
= (value_address (val
)
325 + gdb_print_insn (get_type_arch (type
),
326 value_address (val
), stream
,
327 &branch_delay_insns
));
332 if (options
->format
== 0 || options
->format
== 's'
333 || TYPE_CODE (type
) == TYPE_CODE_REF
334 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
335 || TYPE_CODE (type
) == TYPE_CODE_STRING
336 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
337 || TYPE_CODE (type
) == TYPE_CODE_UNION
338 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
339 value_print (val
, stream
, options
);
341 /* User specified format, so don't look to the type to tell us
343 val_print_scalar_formatted (type
,
344 value_contents_for_printing (val
),
345 value_embedded_offset (val
),
347 options
, size
, stream
);
350 /* Return builtin floating point type of same length as TYPE.
351 If no such type is found, return TYPE itself. */
353 float_type_from_length (struct type
*type
)
355 struct gdbarch
*gdbarch
= get_type_arch (type
);
356 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
357 unsigned int len
= TYPE_LENGTH (type
);
359 if (len
== TYPE_LENGTH (builtin
->builtin_float
))
360 type
= builtin
->builtin_float
;
361 else if (len
== TYPE_LENGTH (builtin
->builtin_double
))
362 type
= builtin
->builtin_double
;
363 else if (len
== TYPE_LENGTH (builtin
->builtin_long_double
))
364 type
= builtin
->builtin_long_double
;
369 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
370 according to OPTIONS and SIZE on STREAM. Formats s and i are not
371 supported at this level. */
374 print_scalar_formatted (const void *valaddr
, struct type
*type
,
375 const struct value_print_options
*options
,
376 int size
, struct ui_file
*stream
)
378 struct gdbarch
*gdbarch
= get_type_arch (type
);
379 LONGEST val_long
= 0;
380 unsigned int len
= TYPE_LENGTH (type
);
381 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
383 /* String printing should go through val_print_scalar_formatted. */
384 gdb_assert (options
->format
!= 's');
386 if (len
> sizeof(LONGEST
) &&
387 (TYPE_CODE (type
) == TYPE_CODE_INT
388 || TYPE_CODE (type
) == TYPE_CODE_ENUM
))
390 switch (options
->format
)
393 print_octal_chars (stream
, valaddr
, len
, byte_order
);
397 print_decimal_chars (stream
, valaddr
, len
, byte_order
);
400 print_binary_chars (stream
, valaddr
, len
, byte_order
);
403 print_hex_chars (stream
, valaddr
, len
, byte_order
);
406 print_char_chars (stream
, type
, valaddr
, len
, byte_order
);
413 if (options
->format
!= 'f')
414 val_long
= unpack_long (type
, valaddr
);
416 /* If the value is a pointer, and pointers and addresses are not the
417 same, then at this point, the value's length (in target bytes) is
418 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
419 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
420 len
= gdbarch_addr_bit (gdbarch
) / TARGET_CHAR_BIT
;
422 /* If we are printing it as unsigned, truncate it in case it is actually
423 a negative signed value (e.g. "print/u (short)-1" should print 65535
424 (if shorts are 16 bits) instead of 4294967295). */
425 if (options
->format
!= 'd' || TYPE_UNSIGNED (type
))
427 if (len
< sizeof (LONGEST
))
428 val_long
&= ((LONGEST
) 1 << HOST_CHAR_BIT
* len
) - 1;
431 switch (options
->format
)
436 /* No size specified, like in print. Print varying # of digits. */
437 print_longest (stream
, 'x', 1, val_long
);
446 print_longest (stream
, size
, 1, val_long
);
449 error (_("Undefined output size \"%c\"."), size
);
454 print_longest (stream
, 'd', 1, val_long
);
458 print_longest (stream
, 'u', 0, val_long
);
463 print_longest (stream
, 'o', 1, val_long
);
465 fprintf_filtered (stream
, "0");
470 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
472 print_address (gdbarch
, addr
, stream
);
478 struct value_print_options opts
= *options
;
481 if (TYPE_UNSIGNED (type
))
482 type
= builtin_type (gdbarch
)->builtin_true_unsigned_char
;
484 type
= builtin_type (gdbarch
)->builtin_true_char
;
486 value_print (value_from_longest (type
, val_long
), stream
, &opts
);
491 type
= float_type_from_length (type
);
492 print_floating (valaddr
, type
, stream
);
496 internal_error (__FILE__
, __LINE__
,
497 _("failed internal consistency check"));
500 /* Binary; 't' stands for "two". */
502 char bits
[8 * (sizeof val_long
) + 1];
503 char buf
[8 * (sizeof val_long
) + 32];
508 width
= 8 * (sizeof val_long
);
525 error (_("Undefined output size \"%c\"."), size
);
531 bits
[width
] = (val_long
& 1) ? '1' : '0';
536 while (*cp
&& *cp
== '0')
541 strncpy (buf
, cp
, sizeof (bits
));
542 fputs_filtered (buf
, stream
);
547 error (_("Undefined output format \"%c\"."), options
->format
);
551 /* Specify default address for `x' command.
552 The `info lines' command uses this. */
555 set_next_address (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
557 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
559 next_gdbarch
= gdbarch
;
562 /* Make address available to the user as $_. */
563 set_internalvar (lookup_internalvar ("_"),
564 value_from_pointer (ptr_type
, addr
));
567 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
568 after LEADIN. Print nothing if no symbolic name is found nearby.
569 Optionally also print source file and line number, if available.
570 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
571 or to interpret it as a possible C++ name and convert it back to source
572 form. However note that DO_DEMANGLE can be overridden by the specific
573 settings of the demangle and asm_demangle variables. */
576 print_address_symbolic (struct gdbarch
*gdbarch
, CORE_ADDR addr
,
577 struct ui_file
*stream
,
578 int do_demangle
, char *leadin
)
581 char *filename
= NULL
;
586 /* Throw away both name and filename. */
587 struct cleanup
*cleanup_chain
= make_cleanup (free_current_contents
, &name
);
588 make_cleanup (free_current_contents
, &filename
);
590 if (build_address_symbolic (gdbarch
, addr
, do_demangle
, &name
, &offset
,
591 &filename
, &line
, &unmapped
))
593 do_cleanups (cleanup_chain
);
597 fputs_filtered (leadin
, stream
);
599 fputs_filtered ("<*", stream
);
601 fputs_filtered ("<", stream
);
602 fputs_filtered (name
, stream
);
604 fprintf_filtered (stream
, "+%u", (unsigned int) offset
);
606 /* Append source filename and line number if desired. Give specific
607 line # of this addr, if we have it; else line # of the nearest symbol. */
608 if (print_symbol_filename
&& filename
!= NULL
)
611 fprintf_filtered (stream
, " at %s:%d", filename
, line
);
613 fprintf_filtered (stream
, " in %s", filename
);
616 fputs_filtered ("*>", stream
);
618 fputs_filtered (">", stream
);
620 do_cleanups (cleanup_chain
);
623 /* Given an address ADDR return all the elements needed to print the
624 address in a symbolic form. NAME can be mangled or not depending
625 on DO_DEMANGLE (and also on the asm_demangle global variable,
626 manipulated via ''set print asm-demangle''). Return 0 in case of
627 success, when all the info in the OUT paramters is valid. Return 1
630 build_address_symbolic (struct gdbarch
*gdbarch
,
631 CORE_ADDR addr
, /* IN */
632 int do_demangle
, /* IN */
633 char **name
, /* OUT */
634 int *offset
, /* OUT */
635 char **filename
, /* OUT */
637 int *unmapped
) /* OUT */
639 struct minimal_symbol
*msymbol
;
640 struct symbol
*symbol
;
641 CORE_ADDR name_location
= 0;
642 struct obj_section
*section
= NULL
;
643 char *name_temp
= "";
645 /* Let's say it is mapped (not unmapped). */
648 /* Determine if the address is in an overlay, and whether it is
650 if (overlay_debugging
)
652 section
= find_pc_overlay (addr
);
653 if (pc_in_unmapped_range (addr
, section
))
656 addr
= overlay_mapped_address (addr
, section
);
660 /* First try to find the address in the symbol table, then
661 in the minsyms. Take the closest one. */
663 /* This is defective in the sense that it only finds text symbols. So
664 really this is kind of pointless--we should make sure that the
665 minimal symbols have everything we need (by changing that we could
666 save some memory, but for many debug format--ELF/DWARF or
667 anything/stabs--it would be inconvenient to eliminate those minimal
669 msymbol
= lookup_minimal_symbol_by_pc_section (addr
, section
);
670 symbol
= find_pc_sect_function (addr
, section
);
674 /* If this is a function (i.e. a code address), strip out any
675 non-address bits. For instance, display a pointer to the
676 first instruction of a Thumb function as <function>; the
677 second instruction will be <function+2>, even though the
678 pointer is <function+3>. This matches the ISA behavior. */
679 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
681 name_location
= BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
));
682 if (do_demangle
|| asm_demangle
)
683 name_temp
= SYMBOL_PRINT_NAME (symbol
);
685 name_temp
= SYMBOL_LINKAGE_NAME (symbol
);
690 if (SYMBOL_VALUE_ADDRESS (msymbol
) > name_location
|| symbol
== NULL
)
692 /* The msymbol is closer to the address than the symbol;
693 use the msymbol instead. */
695 name_location
= SYMBOL_VALUE_ADDRESS (msymbol
);
696 if (do_demangle
|| asm_demangle
)
697 name_temp
= SYMBOL_PRINT_NAME (msymbol
);
699 name_temp
= SYMBOL_LINKAGE_NAME (msymbol
);
702 if (symbol
== NULL
&& msymbol
== NULL
)
705 /* If the nearest symbol is too far away, don't print anything symbolic. */
707 /* For when CORE_ADDR is larger than unsigned int, we do math in
708 CORE_ADDR. But when we detect unsigned wraparound in the
709 CORE_ADDR math, we ignore this test and print the offset,
710 because addr+max_symbolic_offset has wrapped through the end
711 of the address space back to the beginning, giving bogus comparison. */
712 if (addr
> name_location
+ max_symbolic_offset
713 && name_location
+ max_symbolic_offset
> name_location
)
716 *offset
= addr
- name_location
;
718 *name
= xstrdup (name_temp
);
720 if (print_symbol_filename
)
722 struct symtab_and_line sal
;
724 sal
= find_pc_sect_line (addr
, section
, 0);
728 *filename
= xstrdup (sal
.symtab
->filename
);
736 /* Print address ADDR symbolically on STREAM.
737 First print it as a number. Then perhaps print
738 <SYMBOL + OFFSET> after the number. */
741 print_address (struct gdbarch
*gdbarch
,
742 CORE_ADDR addr
, struct ui_file
*stream
)
744 fputs_filtered (paddress (gdbarch
, addr
), stream
);
745 print_address_symbolic (gdbarch
, addr
, stream
, asm_demangle
, " ");
748 /* Return a prefix for instruction address:
749 "=> " for current instruction, else " ". */
752 pc_prefix (CORE_ADDR addr
)
754 if (has_stack_frames ())
756 struct frame_info
*frame
;
759 frame
= get_selected_frame (NULL
);
760 if (get_frame_pc_if_available (frame
, &pc
) && pc
== addr
)
766 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
767 controls whether to print the symbolic name "raw" or demangled.
768 Global setting "addressprint" controls whether to print hex address
772 print_address_demangle (struct gdbarch
*gdbarch
, CORE_ADDR addr
,
773 struct ui_file
*stream
, int do_demangle
)
775 struct value_print_options opts
;
777 get_user_print_options (&opts
);
780 fprintf_filtered (stream
, "0");
782 else if (opts
.addressprint
)
784 fputs_filtered (paddress (gdbarch
, addr
), stream
);
785 print_address_symbolic (gdbarch
, addr
, stream
, do_demangle
, " ");
789 print_address_symbolic (gdbarch
, addr
, stream
, do_demangle
, "");
794 /* Examine data at address ADDR in format FMT.
795 Fetch it from memory and print on gdb_stdout. */
798 do_examine (struct format_data fmt
, struct gdbarch
*gdbarch
, CORE_ADDR addr
)
803 struct type
*val_type
= NULL
;
806 struct value_print_options opts
;
811 next_gdbarch
= gdbarch
;
814 /* Instruction format implies fetch single bytes
815 regardless of the specified size.
816 The case of strings is handled in decode_format, only explicit
817 size operator are not changed to 'b'. */
823 /* Pick the appropriate size for an address. */
824 if (gdbarch_ptr_bit (next_gdbarch
) == 64)
826 else if (gdbarch_ptr_bit (next_gdbarch
) == 32)
828 else if (gdbarch_ptr_bit (next_gdbarch
) == 16)
831 /* Bad value for gdbarch_ptr_bit. */
832 internal_error (__FILE__
, __LINE__
,
833 _("failed internal consistency check"));
837 val_type
= builtin_type (next_gdbarch
)->builtin_int8
;
838 else if (size
== 'h')
839 val_type
= builtin_type (next_gdbarch
)->builtin_int16
;
840 else if (size
== 'w')
841 val_type
= builtin_type (next_gdbarch
)->builtin_int32
;
842 else if (size
== 'g')
843 val_type
= builtin_type (next_gdbarch
)->builtin_int64
;
847 struct type
*char_type
= NULL
;
849 /* Search for "char16_t" or "char32_t" types or fall back to 8-bit char
850 if type is not found. */
852 char_type
= builtin_type (next_gdbarch
)->builtin_char16
;
853 else if (size
== 'w')
854 char_type
= builtin_type (next_gdbarch
)->builtin_char32
;
856 val_type
= char_type
;
859 if (size
!= '\0' && size
!= 'b')
860 warning (_("Unable to display strings with "
861 "size '%c', using 'b' instead."), size
);
863 val_type
= builtin_type (next_gdbarch
)->builtin_int8
;
872 if (format
== 's' || format
== 'i')
875 get_formatted_print_options (&opts
, format
);
877 /* Print as many objects as specified in COUNT, at most maxelts per line,
878 with the address of the next one at the start of each line. */
884 fputs_filtered (pc_prefix (next_address
), gdb_stdout
);
885 print_address (next_gdbarch
, next_address
, gdb_stdout
);
886 printf_filtered (":");
891 printf_filtered ("\t");
892 /* Note that print_formatted sets next_address for the next
894 last_examine_address
= next_address
;
896 if (last_examine_value
)
897 value_free (last_examine_value
);
899 /* The value to be displayed is not fetched greedily.
900 Instead, to avoid the possibility of a fetched value not
901 being used, its retrieval is delayed until the print code
902 uses it. When examining an instruction stream, the
903 disassembler will perform its own memory fetch using just
904 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
905 the disassembler be modified so that LAST_EXAMINE_VALUE
906 is left with the byte sequence from the last complete
907 instruction fetched from memory? */
908 last_examine_value
= value_at_lazy (val_type
, next_address
);
910 if (last_examine_value
)
911 release_value (last_examine_value
);
913 print_formatted (last_examine_value
, size
, &opts
, gdb_stdout
);
915 /* Display any branch delay slots following the final insn. */
916 if (format
== 'i' && count
== 1)
917 count
+= branch_delay_insns
;
919 printf_filtered ("\n");
920 gdb_flush (gdb_stdout
);
925 validate_format (struct format_data fmt
, char *cmdname
)
928 error (_("Size letters are meaningless in \"%s\" command."), cmdname
);
930 error (_("Item count other than 1 is meaningless in \"%s\" command."),
932 if (fmt
.format
== 'i')
933 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
934 fmt
.format
, cmdname
);
937 /* Evaluate string EXP as an expression in the current language and
938 print the resulting value. EXP may contain a format specifier as the
939 first argument ("/x myvar" for example, to print myvar in hex). */
942 print_command_1 (char *exp
, int inspect
, int voidprint
)
944 struct expression
*expr
;
945 struct cleanup
*old_chain
= 0;
948 struct format_data fmt
;
951 if (exp
&& *exp
== '/')
954 fmt
= decode_format (&exp
, last_format
, 0);
955 validate_format (fmt
, "print");
956 last_format
= format
= fmt
.format
;
968 expr
= parse_expression (exp
);
969 old_chain
= make_cleanup (free_current_contents
, &expr
);
971 val
= evaluate_expression (expr
);
974 val
= access_value_history (0);
976 if (voidprint
|| (val
&& value_type (val
) &&
977 TYPE_CODE (value_type (val
)) != TYPE_CODE_VOID
))
979 struct value_print_options opts
;
980 int histindex
= record_latest_value (val
);
983 annotate_value_history_begin (histindex
, value_type (val
));
985 annotate_value_begin (value_type (val
));
988 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"",
990 else if (histindex
>= 0)
991 printf_filtered ("$%d = ", histindex
);
994 annotate_value_history_value ();
996 get_formatted_print_options (&opts
, format
);
997 opts
.inspect_it
= inspect
;
1000 print_formatted (val
, fmt
.size
, &opts
, gdb_stdout
);
1001 printf_filtered ("\n");
1004 annotate_value_history_end ();
1006 annotate_value_end ();
1009 printf_unfiltered ("\") )\030");
1013 do_cleanups (old_chain
);
1017 print_command (char *exp
, int from_tty
)
1019 print_command_1 (exp
, 0, 1);
1022 /* Same as print, except in epoch, it gets its own window. */
1024 inspect_command (char *exp
, int from_tty
)
1026 extern int epoch_interface
;
1028 print_command_1 (exp
, epoch_interface
, 1);
1031 /* Same as print, except it doesn't print void results. */
1033 call_command (char *exp
, int from_tty
)
1035 print_command_1 (exp
, 0, 0);
1039 output_command (char *exp
, int from_tty
)
1041 struct expression
*expr
;
1042 struct cleanup
*old_chain
;
1045 struct format_data fmt
;
1046 struct value_print_options opts
;
1051 if (exp
&& *exp
== '/')
1054 fmt
= decode_format (&exp
, 0, 0);
1055 validate_format (fmt
, "output");
1056 format
= fmt
.format
;
1059 expr
= parse_expression (exp
);
1060 old_chain
= make_cleanup (free_current_contents
, &expr
);
1062 val
= evaluate_expression (expr
);
1064 annotate_value_begin (value_type (val
));
1066 get_formatted_print_options (&opts
, format
);
1068 print_formatted (val
, fmt
.size
, &opts
, gdb_stdout
);
1070 annotate_value_end ();
1073 gdb_flush (gdb_stdout
);
1075 do_cleanups (old_chain
);
1079 set_command (char *exp
, int from_tty
)
1081 struct expression
*expr
= parse_expression (exp
);
1082 struct cleanup
*old_chain
=
1083 make_cleanup (free_current_contents
, &expr
);
1085 evaluate_expression (expr
);
1086 do_cleanups (old_chain
);
1090 sym_info (char *arg
, int from_tty
)
1092 struct minimal_symbol
*msymbol
;
1093 struct objfile
*objfile
;
1094 struct obj_section
*osect
;
1095 CORE_ADDR addr
, sect_addr
;
1097 unsigned int offset
;
1100 error_no_arg (_("address"));
1102 addr
= parse_and_eval_address (arg
);
1103 ALL_OBJSECTIONS (objfile
, osect
)
1105 /* Only process each object file once, even if there's a separate
1107 if (objfile
->separate_debug_objfile_backlink
)
1110 sect_addr
= overlay_mapped_address (addr
, osect
);
1112 if (obj_section_addr (osect
) <= sect_addr
1113 && sect_addr
< obj_section_endaddr (osect
)
1114 && (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr
, osect
)))
1116 const char *obj_name
, *mapped
, *sec_name
, *msym_name
;
1118 struct cleanup
*old_chain
;
1121 offset
= sect_addr
- SYMBOL_VALUE_ADDRESS (msymbol
);
1122 mapped
= section_is_mapped (osect
) ? _("mapped") : _("unmapped");
1123 sec_name
= osect
->the_bfd_section
->name
;
1124 msym_name
= SYMBOL_PRINT_NAME (msymbol
);
1126 /* Don't print the offset if it is zero.
1127 We assume there's no need to handle i18n of "sym + offset". */
1129 loc_string
= xstrprintf ("%s + %u", msym_name
, offset
);
1131 loc_string
= xstrprintf ("%s", msym_name
);
1133 /* Use a cleanup to free loc_string in case the user quits
1134 a pagination request inside printf_filtered. */
1135 old_chain
= make_cleanup (xfree
, loc_string
);
1137 gdb_assert (osect
->objfile
&& osect
->objfile
->name
);
1138 obj_name
= osect
->objfile
->name
;
1140 if (MULTI_OBJFILE_P ())
1141 if (pc_in_unmapped_range (addr
, osect
))
1142 if (section_is_overlay (osect
))
1143 printf_filtered (_("%s in load address range of "
1144 "%s overlay section %s of %s\n"),
1145 loc_string
, mapped
, sec_name
, obj_name
);
1147 printf_filtered (_("%s in load address range of "
1148 "section %s of %s\n"),
1149 loc_string
, sec_name
, obj_name
);
1151 if (section_is_overlay (osect
))
1152 printf_filtered (_("%s in %s overlay section %s of %s\n"),
1153 loc_string
, mapped
, sec_name
, obj_name
);
1155 printf_filtered (_("%s in section %s of %s\n"),
1156 loc_string
, sec_name
, obj_name
);
1158 if (pc_in_unmapped_range (addr
, osect
))
1159 if (section_is_overlay (osect
))
1160 printf_filtered (_("%s in load address range of %s overlay "
1162 loc_string
, mapped
, sec_name
);
1164 printf_filtered (_("%s in load address range of section %s\n"),
1165 loc_string
, sec_name
);
1167 if (section_is_overlay (osect
))
1168 printf_filtered (_("%s in %s overlay section %s\n"),
1169 loc_string
, mapped
, sec_name
);
1171 printf_filtered (_("%s in section %s\n"),
1172 loc_string
, sec_name
);
1174 do_cleanups (old_chain
);
1178 printf_filtered (_("No symbol matches %s.\n"), arg
);
1182 address_info (char *exp
, int from_tty
)
1184 struct gdbarch
*gdbarch
;
1187 struct minimal_symbol
*msymbol
;
1189 struct obj_section
*section
;
1190 CORE_ADDR load_addr
, context_pc
= 0;
1191 int is_a_field_of_this
; /* C++: lookup_symbol sets this to nonzero
1192 if exp is a field of `this'. */
1195 error (_("Argument required."));
1197 sym
= lookup_symbol (exp
, get_selected_block (&context_pc
), VAR_DOMAIN
,
1198 &is_a_field_of_this
);
1201 if (is_a_field_of_this
)
1203 printf_filtered ("Symbol \"");
1204 fprintf_symbol_filtered (gdb_stdout
, exp
,
1205 current_language
->la_language
, DMGL_ANSI
);
1206 printf_filtered ("\" is a field of the local class variable ");
1207 if (current_language
->la_language
== language_objc
)
1208 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1210 printf_filtered ("`this'\n");
1214 msymbol
= lookup_minimal_symbol (exp
, NULL
, NULL
);
1216 if (msymbol
!= NULL
)
1218 gdbarch
= get_objfile_arch (msymbol_objfile (msymbol
));
1219 load_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
1221 printf_filtered ("Symbol \"");
1222 fprintf_symbol_filtered (gdb_stdout
, exp
,
1223 current_language
->la_language
, DMGL_ANSI
);
1224 printf_filtered ("\" is at ");
1225 fputs_filtered (paddress (gdbarch
, load_addr
), gdb_stdout
);
1226 printf_filtered (" in a file compiled without debugging");
1227 section
= SYMBOL_OBJ_SECTION (msymbol
);
1228 if (section_is_overlay (section
))
1230 load_addr
= overlay_unmapped_address (load_addr
, section
);
1231 printf_filtered (",\n -- loaded at ");
1232 fputs_filtered (paddress (gdbarch
, load_addr
), gdb_stdout
);
1233 printf_filtered (" in overlay section %s",
1234 section
->the_bfd_section
->name
);
1236 printf_filtered (".\n");
1239 error (_("No symbol \"%s\" in current context."), exp
);
1243 printf_filtered ("Symbol \"");
1244 fprintf_symbol_filtered (gdb_stdout
, SYMBOL_PRINT_NAME (sym
),
1245 current_language
->la_language
, DMGL_ANSI
);
1246 printf_filtered ("\" is ");
1247 val
= SYMBOL_VALUE (sym
);
1248 section
= SYMBOL_OBJ_SECTION (sym
);
1249 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
1251 switch (SYMBOL_CLASS (sym
))
1254 case LOC_CONST_BYTES
:
1255 printf_filtered ("constant");
1259 printf_filtered ("a label at address ");
1260 load_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1261 fputs_filtered (paddress (gdbarch
, load_addr
), gdb_stdout
);
1262 if (section_is_overlay (section
))
1264 load_addr
= overlay_unmapped_address (load_addr
, section
);
1265 printf_filtered (",\n -- loaded at ");
1266 fputs_filtered (paddress (gdbarch
, load_addr
), gdb_stdout
);
1267 printf_filtered (" in overlay section %s",
1268 section
->the_bfd_section
->name
);
1273 /* FIXME: cagney/2004-01-26: It should be possible to
1274 unconditionally call the SYMBOL_COMPUTED_OPS method when available.
1275 Unfortunately DWARF 2 stores the frame-base (instead of the
1276 function) location in a function's symbol. Oops! For the
1277 moment enable this when/where applicable. */
1278 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, context_pc
,
1283 /* GDBARCH is the architecture associated with the objfile the symbol
1284 is defined in; the target architecture may be different, and may
1285 provide additional registers. However, we do not know the target
1286 architecture at this point. We assume the objfile architecture
1287 will contain all the standard registers that occur in debug info
1289 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1291 if (SYMBOL_IS_ARGUMENT (sym
))
1292 printf_filtered (_("an argument in register %s"),
1293 gdbarch_register_name (gdbarch
, regno
));
1295 printf_filtered (_("a variable in register %s"),
1296 gdbarch_register_name (gdbarch
, regno
));
1300 printf_filtered (_("static storage at address "));
1301 load_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1302 fputs_filtered (paddress (gdbarch
, load_addr
), gdb_stdout
);
1303 if (section_is_overlay (section
))
1305 load_addr
= overlay_unmapped_address (load_addr
, section
);
1306 printf_filtered (_(",\n -- loaded at "));
1307 fputs_filtered (paddress (gdbarch
, load_addr
), gdb_stdout
);
1308 printf_filtered (_(" in overlay section %s"),
1309 section
->the_bfd_section
->name
);
1313 case LOC_REGPARM_ADDR
:
1314 /* Note comment at LOC_REGISTER. */
1315 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1316 printf_filtered (_("address of an argument in register %s"),
1317 gdbarch_register_name (gdbarch
, regno
));
1321 printf_filtered (_("an argument at offset %ld"), val
);
1325 printf_filtered (_("a local variable at frame offset %ld"), val
);
1329 printf_filtered (_("a reference argument at offset %ld"), val
);
1333 printf_filtered (_("a typedef"));
1337 printf_filtered (_("a function at address "));
1338 load_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1339 fputs_filtered (paddress (gdbarch
, load_addr
), gdb_stdout
);
1340 if (section_is_overlay (section
))
1342 load_addr
= overlay_unmapped_address (load_addr
, section
);
1343 printf_filtered (_(",\n -- loaded at "));
1344 fputs_filtered (paddress (gdbarch
, load_addr
), gdb_stdout
);
1345 printf_filtered (_(" in overlay section %s"),
1346 section
->the_bfd_section
->name
);
1350 case LOC_UNRESOLVED
:
1352 struct minimal_symbol
*msym
;
1354 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
), NULL
, NULL
);
1356 printf_filtered ("unresolved");
1359 section
= SYMBOL_OBJ_SECTION (msym
);
1360 load_addr
= SYMBOL_VALUE_ADDRESS (msym
);
1363 && (section
->the_bfd_section
->flags
& SEC_THREAD_LOCAL
) != 0)
1364 printf_filtered (_("a thread-local variable at offset %s "
1365 "in the thread-local storage for `%s'"),
1366 paddress (gdbarch
, load_addr
),
1367 section
->objfile
->name
);
1370 printf_filtered (_("static storage at address "));
1371 fputs_filtered (paddress (gdbarch
, load_addr
), gdb_stdout
);
1372 if (section_is_overlay (section
))
1374 load_addr
= overlay_unmapped_address (load_addr
, section
);
1375 printf_filtered (_(",\n -- loaded at "));
1376 fputs_filtered (paddress (gdbarch
, load_addr
), gdb_stdout
);
1377 printf_filtered (_(" in overlay section %s"),
1378 section
->the_bfd_section
->name
);
1385 case LOC_OPTIMIZED_OUT
:
1386 printf_filtered (_("optimized out"));
1390 printf_filtered (_("of unknown (botched) type"));
1393 printf_filtered (".\n");
1398 x_command (char *exp
, int from_tty
)
1400 struct expression
*expr
;
1401 struct format_data fmt
;
1402 struct cleanup
*old_chain
;
1405 fmt
.format
= last_format
? last_format
: 'x';
1406 fmt
.size
= last_size
;
1410 if (exp
&& *exp
== '/')
1413 fmt
= decode_format (&exp
, last_format
, last_size
);
1416 /* If we have an expression, evaluate it and use it as the address. */
1418 if (exp
!= 0 && *exp
!= 0)
1420 expr
= parse_expression (exp
);
1421 /* Cause expression not to be there any more if this command is
1422 repeated with Newline. But don't clobber a user-defined
1423 command's definition. */
1426 old_chain
= make_cleanup (free_current_contents
, &expr
);
1427 val
= evaluate_expression (expr
);
1428 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_REF
)
1429 val
= coerce_ref (val
);
1430 /* In rvalue contexts, such as this, functions are coerced into
1431 pointers to functions. This makes "x/i main" work. */
1432 if (/* last_format == 'i' && */
1433 TYPE_CODE (value_type (val
)) == TYPE_CODE_FUNC
1434 && VALUE_LVAL (val
) == lval_memory
)
1435 next_address
= value_address (val
);
1437 next_address
= value_as_address (val
);
1439 next_gdbarch
= expr
->gdbarch
;
1440 do_cleanups (old_chain
);
1444 error_no_arg (_("starting display address"));
1446 do_examine (fmt
, next_gdbarch
, next_address
);
1448 /* If the examine succeeds, we remember its size and format for next
1449 time. Set last_size to 'b' for strings. */
1450 if (fmt
.format
== 's')
1453 last_size
= fmt
.size
;
1454 last_format
= fmt
.format
;
1456 /* Set a couple of internal variables if appropriate. */
1457 if (last_examine_value
)
1459 /* Make last address examined available to the user as $_. Use
1460 the correct pointer type. */
1461 struct type
*pointer_type
1462 = lookup_pointer_type (value_type (last_examine_value
));
1463 set_internalvar (lookup_internalvar ("_"),
1464 value_from_pointer (pointer_type
,
1465 last_examine_address
));
1467 /* Make contents of last address examined available to the user
1468 as $__. If the last value has not been fetched from memory
1469 then don't fetch it now; instead mark it by voiding the $__
1471 if (value_lazy (last_examine_value
))
1472 clear_internalvar (lookup_internalvar ("__"));
1474 set_internalvar (lookup_internalvar ("__"), last_examine_value
);
1479 /* Add an expression to the auto-display chain.
1480 Specify the expression. */
1483 display_command (char *exp
, int from_tty
)
1485 struct format_data fmt
;
1486 struct expression
*expr
;
1487 struct display
*new;
1491 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1493 if (tui_active
&& exp
!= NULL
&& *exp
== '$')
1494 display_it
= (tui_set_layout_for_display_command (exp
) == TUI_FAILURE
);
1508 fmt
= decode_format (&exp
, 0, 0);
1509 if (fmt
.size
&& fmt
.format
== 0)
1511 if (fmt
.format
== 'i' || fmt
.format
== 's')
1522 innermost_block
= NULL
;
1523 expr
= parse_expression (exp
);
1525 new = (struct display
*) xmalloc (sizeof (struct display
));
1527 new->exp_string
= xstrdup (exp
);
1529 new->block
= innermost_block
;
1530 new->pspace
= current_program_space
;
1531 new->next
= display_chain
;
1532 new->number
= ++display_number
;
1535 display_chain
= new;
1537 if (from_tty
&& target_has_execution
)
1538 do_one_display (new);
1545 free_display (struct display
*d
)
1547 xfree (d
->exp_string
);
1552 /* Clear out the display_chain. Done when new symtabs are loaded,
1553 since this invalidates the types stored in many expressions. */
1556 clear_displays (void)
1560 while ((d
= display_chain
) != NULL
)
1562 display_chain
= d
->next
;
1567 /* Delete the auto-display DISPLAY. */
1570 delete_display (struct display
*display
)
1574 gdb_assert (display
!= NULL
);
1576 if (display_chain
== display
)
1577 display_chain
= display
->next
;
1580 if (d
->next
== display
)
1582 d
->next
= display
->next
;
1586 free_display (display
);
1589 /* Call FUNCTION on each of the displays whose numbers are given in
1590 ARGS. DATA is passed unmodified to FUNCTION. */
1593 map_display_numbers (char *args
,
1594 void (*function
) (struct display
*,
1598 struct get_number_or_range_state state
;
1599 struct display
*b
, *tmp
;
1603 error_no_arg (_("one or more display numbers"));
1605 init_number_or_range (&state
, args
);
1607 while (!state
.finished
)
1609 char *p
= state
.string
;
1611 num
= get_number_or_range (&state
);
1613 warning (_("bad display number at or near '%s'"), p
);
1616 struct display
*d
, *tmp
;
1618 ALL_DISPLAYS_SAFE (d
, tmp
)
1619 if (d
->number
== num
)
1622 printf_unfiltered (_("No display number %d.\n"), num
);
1629 /* Callback for map_display_numbers, that deletes a display. */
1632 do_delete_display (struct display
*d
, void *data
)
1637 /* "undisplay" command. */
1640 undisplay_command (char *args
, int from_tty
)
1643 struct get_number_or_range_state state
;
1647 if (query (_("Delete all auto-display expressions? ")))
1653 map_display_numbers (args
, do_delete_display
, NULL
);
1657 /* Display a single auto-display.
1658 Do nothing if the display cannot be printed in the current context,
1659 or if the display is disabled. */
1662 do_one_display (struct display
*d
)
1664 struct cleanup
*old_chain
;
1665 int within_current_scope
;
1667 if (d
->enabled_p
== 0)
1670 /* The expression carries the architecture that was used at parse time.
1671 This is a problem if the expression depends on architecture features
1672 (e.g. register numbers), and the current architecture is now different.
1673 For example, a display statement like "display/i $pc" is expected to
1674 display the PC register of the current architecture, not the arch at
1675 the time the display command was given. Therefore, we re-parse the
1676 expression if the current architecture has changed. */
1677 if (d
->exp
!= NULL
&& d
->exp
->gdbarch
!= get_current_arch ())
1686 volatile struct gdb_exception ex
;
1688 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1690 innermost_block
= NULL
;
1691 d
->exp
= parse_expression (d
->exp_string
);
1692 d
->block
= innermost_block
;
1696 /* Can't re-parse the expression. Disable this display item. */
1698 warning (_("Unable to display \"%s\": %s"),
1699 d
->exp_string
, ex
.message
);
1706 if (d
->pspace
== current_program_space
)
1707 within_current_scope
= contained_in (get_selected_block (0), d
->block
);
1709 within_current_scope
= 0;
1712 within_current_scope
= 1;
1713 if (!within_current_scope
)
1716 old_chain
= make_cleanup_restore_integer (¤t_display_number
);
1717 current_display_number
= d
->number
;
1719 annotate_display_begin ();
1720 printf_filtered ("%d", d
->number
);
1721 annotate_display_number_end ();
1722 printf_filtered (": ");
1725 volatile struct gdb_exception ex
;
1727 annotate_display_format ();
1729 printf_filtered ("x/");
1730 if (d
->format
.count
!= 1)
1731 printf_filtered ("%d", d
->format
.count
);
1732 printf_filtered ("%c", d
->format
.format
);
1733 if (d
->format
.format
!= 'i' && d
->format
.format
!= 's')
1734 printf_filtered ("%c", d
->format
.size
);
1735 printf_filtered (" ");
1737 annotate_display_expression ();
1739 puts_filtered (d
->exp_string
);
1740 annotate_display_expression_end ();
1742 if (d
->format
.count
!= 1 || d
->format
.format
== 'i')
1743 printf_filtered ("\n");
1745 printf_filtered (" ");
1747 annotate_display_value ();
1749 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
1754 val
= evaluate_expression (d
->exp
);
1755 addr
= value_as_address (val
);
1756 if (d
->format
.format
== 'i')
1757 addr
= gdbarch_addr_bits_remove (d
->exp
->gdbarch
, addr
);
1758 do_examine (d
->format
, d
->exp
->gdbarch
, addr
);
1761 fprintf_filtered (gdb_stdout
, _("<error: %s>\n"), ex
.message
);
1765 struct value_print_options opts
;
1766 volatile struct gdb_exception ex
;
1768 annotate_display_format ();
1770 if (d
->format
.format
)
1771 printf_filtered ("/%c ", d
->format
.format
);
1773 annotate_display_expression ();
1775 puts_filtered (d
->exp_string
);
1776 annotate_display_expression_end ();
1778 printf_filtered (" = ");
1780 annotate_display_expression ();
1782 get_formatted_print_options (&opts
, d
->format
.format
);
1783 opts
.raw
= d
->format
.raw
;
1785 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
1789 val
= evaluate_expression (d
->exp
);
1790 print_formatted (val
, d
->format
.size
, &opts
, gdb_stdout
);
1793 fprintf_filtered (gdb_stdout
, _("<error: %s>"), ex
.message
);
1794 printf_filtered ("\n");
1797 annotate_display_end ();
1799 gdb_flush (gdb_stdout
);
1800 do_cleanups (old_chain
);
1803 /* Display all of the values on the auto-display chain which can be
1804 evaluated in the current scope. */
1811 for (d
= display_chain
; d
; d
= d
->next
)
1815 /* Delete the auto-display which we were in the process of displaying.
1816 This is done when there is an error or a signal. */
1819 disable_display (int num
)
1823 for (d
= display_chain
; d
; d
= d
->next
)
1824 if (d
->number
== num
)
1829 printf_unfiltered (_("No display number %d.\n"), num
);
1833 disable_current_display (void)
1835 if (current_display_number
>= 0)
1837 disable_display (current_display_number
);
1838 fprintf_unfiltered (gdb_stderr
,
1839 _("Disabling display %d to "
1840 "avoid infinite recursion.\n"),
1841 current_display_number
);
1843 current_display_number
= -1;
1847 display_info (char *ignore
, int from_tty
)
1852 printf_unfiltered (_("There are no auto-display expressions now.\n"));
1854 printf_filtered (_("Auto-display expressions now in effect:\n\
1855 Num Enb Expression\n"));
1857 for (d
= display_chain
; d
; d
= d
->next
)
1859 printf_filtered ("%d: %c ", d
->number
, "ny"[(int) d
->enabled_p
]);
1861 printf_filtered ("/%d%c%c ", d
->format
.count
, d
->format
.size
,
1863 else if (d
->format
.format
)
1864 printf_filtered ("/%c ", d
->format
.format
);
1865 puts_filtered (d
->exp_string
);
1866 if (d
->block
&& !contained_in (get_selected_block (0), d
->block
))
1867 printf_filtered (_(" (cannot be evaluated in the current context)"));
1868 printf_filtered ("\n");
1869 gdb_flush (gdb_stdout
);
1873 /* Callback fo map_display_numbers, that enables or disables the
1874 passed in display D. */
1877 do_enable_disable_display (struct display
*d
, void *data
)
1879 d
->enabled_p
= *(int *) data
;
1882 /* Implamentation of both the "disable display" and "enable display"
1883 commands. ENABLE decides what to do. */
1886 enable_disable_display_command (char *args
, int from_tty
, int enable
)
1893 d
->enabled_p
= enable
;
1897 map_display_numbers (args
, do_enable_disable_display
, &enable
);
1900 /* The "enable display" command. */
1903 enable_display_command (char *args
, int from_tty
)
1905 enable_disable_display_command (args
, from_tty
, 1);
1908 /* The "disable display" command. */
1911 disable_display_command (char *args
, int from_tty
)
1913 enable_disable_display_command (args
, from_tty
, 0);
1916 /* display_chain items point to blocks and expressions. Some expressions in
1917 turn may point to symbols.
1918 Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
1919 obstack_free'd when a shared library is unloaded.
1920 Clear pointers that are about to become dangling.
1921 Both .exp and .block fields will be restored next time we need to display
1922 an item by re-parsing .exp_string field in the new execution context. */
1925 clear_dangling_display_expressions (struct so_list
*solib
)
1927 struct objfile
*objfile
= solib
->objfile
;
1930 /* With no symbol file we cannot have a block or expression from it. */
1931 if (objfile
== NULL
)
1933 if (objfile
->separate_debug_objfile_backlink
)
1934 objfile
= objfile
->separate_debug_objfile_backlink
;
1935 gdb_assert (objfile
->pspace
== solib
->pspace
);
1937 for (d
= display_chain
; d
!= NULL
; d
= d
->next
)
1939 if (d
->pspace
!= solib
->pspace
)
1942 if (lookup_objfile_from_block (d
->block
) == objfile
1943 || (d
->exp
&& exp_uses_objfile (d
->exp
, objfile
)))
1953 /* Print the value in stack frame FRAME of a variable specified by a
1954 struct symbol. NAME is the name to print; if NULL then VAR's print
1955 name will be used. STREAM is the ui_file on which to print the
1956 value. INDENT specifies the number of indent levels to print
1957 before printing the variable name. */
1960 print_variable_and_value (const char *name
, struct symbol
*var
,
1961 struct frame_info
*frame
,
1962 struct ui_file
*stream
, int indent
)
1964 volatile struct gdb_exception except
;
1967 name
= SYMBOL_PRINT_NAME (var
);
1969 fprintf_filtered (stream
, "%s%s = ", n_spaces (2 * indent
), name
);
1970 TRY_CATCH (except
, RETURN_MASK_ERROR
)
1973 struct value_print_options opts
;
1975 val
= read_var_value (var
, frame
);
1976 get_user_print_options (&opts
);
1978 common_val_print (val
, stream
, indent
, &opts
, current_language
);
1980 if (except
.reason
< 0)
1981 fprintf_filtered(stream
, "<error reading variable %s (%s)>", name
,
1983 fprintf_filtered (stream
, "\n");
1986 /* printf "printf format string" ARG to STREAM. */
1989 ui_printf (char *arg
, struct ui_file
*stream
)
1993 char *string
= NULL
;
1994 struct value
**val_args
;
1996 char *current_substring
;
1998 int allocated_args
= 20;
1999 struct cleanup
*old_cleanups
;
2001 val_args
= xmalloc (allocated_args
* sizeof (struct value
*));
2002 old_cleanups
= make_cleanup (free_current_contents
, &val_args
);
2005 error_no_arg (_("format-control string and values to print"));
2007 s
= skip_spaces (s
);
2009 /* A format string should follow, enveloped in double quotes. */
2011 error (_("Bad format string, missing '\"'."));
2013 /* Parse the format-control string and copy it into the string STRING,
2014 processing some kinds of escape sequence. */
2016 f
= string
= (char *) alloca (strlen (s
) + 1);
2024 error (_("Bad format string, non-terminated '\"'."));
2057 /* ??? TODO: handle other escape sequences. */
2058 error (_("Unrecognized escape character \\%c in format string."),
2068 /* Skip over " and following space and comma. */
2071 s
= skip_spaces (s
);
2073 if (*s
!= ',' && *s
!= 0)
2074 error (_("Invalid argument syntax"));
2078 s
= skip_spaces (s
);
2080 /* Need extra space for the '\0's. Doubling the size is sufficient. */
2081 substrings
= alloca (strlen (string
) * 2);
2082 current_substring
= substrings
;
2085 /* Now scan the string for %-specs and see what kinds of args they want.
2086 argclass[I] classifies the %-specs so we can give printf_filtered
2087 something of the right size. */
2091 int_arg
, long_arg
, long_long_arg
, ptr_arg
,
2092 string_arg
, wide_string_arg
, wide_char_arg
,
2093 double_arg
, long_double_arg
, decfloat_arg
2095 enum argclass
*argclass
;
2096 enum argclass this_argclass
;
2101 argclass
= (enum argclass
*) alloca (strlen (s
) * sizeof *argclass
);
2108 int seen_hash
= 0, seen_zero
= 0, lcount
= 0, seen_prec
= 0;
2109 int seen_space
= 0, seen_plus
= 0;
2110 int seen_big_l
= 0, seen_h
= 0, seen_big_h
= 0;
2111 int seen_big_d
= 0, seen_double_big_d
= 0;
2114 /* Check the validity of the format specifier, and work
2115 out what argument it expects. We only accept C89
2116 format strings, with the exception of long long (which
2117 we autoconf for). */
2119 /* Skip over "%%". */
2126 /* The first part of a format specifier is a set of flag
2128 while (strchr ("0-+ #", *f
))
2141 /* The next part of a format specifier is a width. */
2142 while (strchr ("0123456789", *f
))
2145 /* The next part of a format specifier is a precision. */
2150 while (strchr ("0123456789", *f
))
2154 /* The next part of a format specifier is a length modifier. */
2175 /* Decimal32 modifier. */
2181 /* Decimal64 and Decimal128 modifiers. */
2186 /* Check for a Decimal128. */
2190 seen_double_big_d
= 1;
2206 if (seen_space
|| seen_plus
)
2213 this_argclass
= int_arg
;
2214 else if (lcount
== 1)
2215 this_argclass
= long_arg
;
2217 this_argclass
= long_long_arg
;
2224 this_argclass
= lcount
== 0 ? int_arg
: wide_char_arg
;
2225 if (lcount
> 1 || seen_h
|| seen_big_l
)
2227 if (seen_prec
|| seen_zero
|| seen_space
|| seen_plus
)
2232 this_argclass
= ptr_arg
;
2233 if (lcount
|| seen_h
|| seen_big_l
)
2235 if (seen_prec
|| seen_zero
|| seen_space
|| seen_plus
)
2240 this_argclass
= lcount
== 0 ? string_arg
: wide_string_arg
;
2241 if (lcount
> 1 || seen_h
|| seen_big_l
)
2243 if (seen_zero
|| seen_space
|| seen_plus
)
2252 if (seen_big_h
|| seen_big_d
|| seen_double_big_d
)
2253 this_argclass
= decfloat_arg
;
2254 else if (seen_big_l
)
2255 this_argclass
= long_double_arg
;
2257 this_argclass
= double_arg
;
2259 if (lcount
|| seen_h
)
2264 error (_("`*' not supported for precision or width in printf"));
2267 error (_("Format specifier `n' not supported in printf"));
2270 error (_("Incomplete format specifier at end of format string"));
2273 error (_("Unrecognized format specifier '%c' in printf"), *f
);
2277 error (_("Inappropriate modifiers to "
2278 "format specifier '%c' in printf"),
2283 if (lcount
> 1 && USE_PRINTF_I64
)
2285 /* Windows' printf does support long long, but not the usual way.
2286 Convert %lld to %I64d. */
2287 int length_before_ll
= f
- last_arg
- 1 - lcount
;
2289 strncpy (current_substring
, last_arg
, length_before_ll
);
2290 strcpy (current_substring
+ length_before_ll
, "I64");
2291 current_substring
[length_before_ll
+ 3] =
2292 last_arg
[length_before_ll
+ lcount
];
2293 current_substring
+= length_before_ll
+ 4;
2295 else if (this_argclass
== wide_string_arg
2296 || this_argclass
== wide_char_arg
)
2298 /* Convert %ls or %lc to %s. */
2299 int length_before_ls
= f
- last_arg
- 2;
2301 strncpy (current_substring
, last_arg
, length_before_ls
);
2302 strcpy (current_substring
+ length_before_ls
, "s");
2303 current_substring
+= length_before_ls
+ 2;
2307 strncpy (current_substring
, last_arg
, f
- last_arg
);
2308 current_substring
+= f
- last_arg
;
2310 *current_substring
++ = '\0';
2312 argclass
[nargs_wanted
++] = this_argclass
;
2315 /* Now, parse all arguments and evaluate them.
2316 Store the VALUEs in VAL_ARGS. */
2322 if (nargs
== allocated_args
)
2323 val_args
= (struct value
**) xrealloc ((char *) val_args
,
2324 (allocated_args
*= 2)
2325 * sizeof (struct value
*));
2327 val_args
[nargs
] = parse_to_comma_and_eval (&s1
);
2335 if (nargs
!= nargs_wanted
)
2336 error (_("Wrong number of arguments for specified format-string"));
2338 /* Now actually print them. */
2339 current_substring
= substrings
;
2340 for (i
= 0; i
< nargs
; i
++)
2342 switch (argclass
[i
])
2350 tem
= value_as_address (val_args
[i
]);
2352 /* This is a %s argument. Find the length of the string. */
2358 read_memory (tem
+ j
, &c
, 1);
2363 /* Copy the string contents into a string inside GDB. */
2364 str
= (gdb_byte
*) alloca (j
+ 1);
2366 read_memory (tem
, str
, j
);
2369 fprintf_filtered (stream
, current_substring
, (char *) str
);
2372 case wide_string_arg
:
2377 struct gdbarch
*gdbarch
2378 = get_type_arch (value_type (val_args
[i
]));
2379 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2380 struct type
*wctype
= lookup_typename (current_language
, gdbarch
,
2381 "wchar_t", NULL
, 0);
2382 int wcwidth
= TYPE_LENGTH (wctype
);
2383 gdb_byte
*buf
= alloca (wcwidth
);
2384 struct obstack output
;
2385 struct cleanup
*inner_cleanup
;
2387 tem
= value_as_address (val_args
[i
]);
2389 /* This is a %s argument. Find the length of the string. */
2390 for (j
= 0;; j
+= wcwidth
)
2393 read_memory (tem
+ j
, buf
, wcwidth
);
2394 if (extract_unsigned_integer (buf
, wcwidth
, byte_order
) == 0)
2398 /* Copy the string contents into a string inside GDB. */
2399 str
= (gdb_byte
*) alloca (j
+ wcwidth
);
2401 read_memory (tem
, str
, j
);
2402 memset (&str
[j
], 0, wcwidth
);
2404 obstack_init (&output
);
2405 inner_cleanup
= make_cleanup_obstack_free (&output
);
2407 convert_between_encodings (target_wide_charset (gdbarch
),
2410 &output
, translit_char
);
2411 obstack_grow_str0 (&output
, "");
2413 fprintf_filtered (stream
, current_substring
,
2414 obstack_base (&output
));
2415 do_cleanups (inner_cleanup
);
2420 struct gdbarch
*gdbarch
2421 = get_type_arch (value_type (val_args
[i
]));
2422 struct type
*wctype
= lookup_typename (current_language
, gdbarch
,
2423 "wchar_t", NULL
, 0);
2424 struct type
*valtype
;
2425 struct obstack output
;
2426 struct cleanup
*inner_cleanup
;
2427 const gdb_byte
*bytes
;
2429 valtype
= value_type (val_args
[i
]);
2430 if (TYPE_LENGTH (valtype
) != TYPE_LENGTH (wctype
)
2431 || TYPE_CODE (valtype
) != TYPE_CODE_INT
)
2432 error (_("expected wchar_t argument for %%lc"));
2434 bytes
= value_contents (val_args
[i
]);
2436 obstack_init (&output
);
2437 inner_cleanup
= make_cleanup_obstack_free (&output
);
2439 convert_between_encodings (target_wide_charset (gdbarch
),
2441 bytes
, TYPE_LENGTH (valtype
),
2442 TYPE_LENGTH (valtype
),
2443 &output
, translit_char
);
2444 obstack_grow_str0 (&output
, "");
2446 fprintf_filtered (stream
, current_substring
,
2447 obstack_base (&output
));
2448 do_cleanups (inner_cleanup
);
2453 struct type
*type
= value_type (val_args
[i
]);
2457 /* If format string wants a float, unchecked-convert the value
2458 to floating point of the same size. */
2459 type
= float_type_from_length (type
);
2460 val
= unpack_double (type
, value_contents (val_args
[i
]), &inv
);
2462 error (_("Invalid floating value found in program."));
2464 fprintf_filtered (stream
, current_substring
, (double) val
);
2467 case long_double_arg
:
2468 #ifdef HAVE_LONG_DOUBLE
2470 struct type
*type
= value_type (val_args
[i
]);
2474 /* If format string wants a float, unchecked-convert the value
2475 to floating point of the same size. */
2476 type
= float_type_from_length (type
);
2477 val
= unpack_double (type
, value_contents (val_args
[i
]), &inv
);
2479 error (_("Invalid floating value found in program."));
2481 fprintf_filtered (stream
, current_substring
,
2486 error (_("long double not supported in printf"));
2489 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2491 long long val
= value_as_long (val_args
[i
]);
2493 fprintf_filtered (stream
, current_substring
, val
);
2497 error (_("long long not supported in printf"));
2501 int val
= value_as_long (val_args
[i
]);
2503 fprintf_filtered (stream
, current_substring
, val
);
2508 long val
= value_as_long (val_args
[i
]);
2510 fprintf_filtered (stream
, current_substring
, val
);
2514 /* Handles decimal floating values. */
2517 const gdb_byte
*param_ptr
= value_contents (val_args
[i
]);
2519 #if defined (PRINTF_HAS_DECFLOAT)
2520 /* If we have native support for Decimal floating
2521 printing, handle it here. */
2522 fprintf_filtered (stream
, current_substring
, param_ptr
);
2525 /* As a workaround until vasprintf has native support for DFP
2526 we convert the DFP values to string and print them using
2527 the %s format specifier. */
2530 int nnull_chars
= 0;
2532 /* Parameter data. */
2533 struct type
*param_type
= value_type (val_args
[i
]);
2534 unsigned int param_len
= TYPE_LENGTH (param_type
);
2535 struct gdbarch
*gdbarch
= get_type_arch (param_type
);
2536 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2538 /* DFP output data. */
2539 struct value
*dfp_value
= NULL
;
2543 struct type
*dfp_type
= NULL
;
2544 char decstr
[MAX_DECIMAL_STRING
];
2546 /* Points to the end of the string so that we can go back
2547 and check for DFP length modifiers. */
2548 eos
= current_substring
+ strlen (current_substring
);
2550 /* Look for the float/double format specifier. */
2551 while (*eos
!= 'f' && *eos
!= 'e' && *eos
!= 'E'
2552 && *eos
!= 'g' && *eos
!= 'G')
2557 /* Search for the '%' char and extract the size and type of
2558 the output decimal value based on its modifiers
2559 (%Hf, %Df, %DDf). */
2560 while (*--sos
!= '%')
2565 dfp_type
= builtin_type (gdbarch
)->builtin_decfloat
;
2567 else if (*sos
== 'D' && *(sos
- 1) == 'D')
2570 dfp_type
= builtin_type (gdbarch
)->builtin_declong
;
2576 dfp_type
= builtin_type (gdbarch
)->builtin_decdouble
;
2580 /* Replace %Hf, %Df and %DDf with %s's. */
2583 /* Go through the whole format string and pull the correct
2584 number of chars back to compensate for the change in the
2585 format specifier. */
2586 while (nnull_chars
< nargs
- i
)
2594 /* Conversion between different DFP types. */
2595 if (TYPE_CODE (param_type
) == TYPE_CODE_DECFLOAT
)
2596 decimal_convert (param_ptr
, param_len
, byte_order
,
2597 dec
, dfp_len
, byte_order
);
2599 /* If this is a non-trivial conversion, just output 0.
2600 A correct converted value can be displayed by explicitly
2601 casting to a DFP type. */
2602 decimal_from_string (dec
, dfp_len
, byte_order
, "0");
2604 dfp_value
= value_from_decfloat (dfp_type
, dec
);
2606 dfp_ptr
= (gdb_byte
*) value_contents (dfp_value
);
2608 decimal_to_string (dfp_ptr
, dfp_len
, byte_order
, decstr
);
2610 /* Print the DFP value. */
2611 fprintf_filtered (stream
, current_substring
, decstr
);
2619 /* We avoid the host's %p because pointers are too
2620 likely to be the wrong size. The only interesting
2621 modifier for %p is a width; extract that, and then
2622 handle %p as glibc would: %#x or a literal "(nil)". */
2624 char *p
, *fmt
, *fmt_p
;
2625 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2626 long long val
= value_as_long (val_args
[i
]);
2628 long val
= value_as_long (val_args
[i
]);
2631 fmt
= alloca (strlen (current_substring
) + 5);
2633 /* Copy up to the leading %. */
2634 p
= current_substring
;
2638 int is_percent
= (*p
== '%');
2653 /* Copy any width. */
2654 while (*p
>= '0' && *p
< '9')
2657 gdb_assert (*p
== 'p' && *(p
+ 1) == '\0');
2660 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2666 fprintf_filtered (stream
, fmt
, val
);
2672 fprintf_filtered (stream
, fmt
, "(nil)");
2678 internal_error (__FILE__
, __LINE__
,
2679 _("failed internal consistency check"));
2681 /* Skip to the next substring. */
2682 current_substring
+= strlen (current_substring
) + 1;
2684 /* Print the portion of the format string after the last argument.
2685 Note that this will not include any ordinary %-specs, but it
2686 might include "%%". That is why we use printf_filtered and not
2687 puts_filtered here. Also, we pass a dummy argument because
2688 some platforms have modified GCC to include -Wformat-security
2689 by default, which will warn here if there is no argument. */
2690 fprintf_filtered (stream
, last_arg
, 0);
2692 do_cleanups (old_cleanups
);
2695 /* Implement the "printf" command. */
2698 printf_command (char *arg
, int from_tty
)
2700 ui_printf (arg
, gdb_stdout
);
2703 /* Implement the "eval" command. */
2706 eval_command (char *arg
, int from_tty
)
2708 struct ui_file
*ui_out
= mem_fileopen ();
2709 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (ui_out
);
2712 ui_printf (arg
, ui_out
);
2714 expanded
= ui_file_xstrdup (ui_out
, NULL
);
2715 make_cleanup (xfree
, expanded
);
2717 execute_command (expanded
, from_tty
);
2719 do_cleanups (cleanups
);
2723 _initialize_printcmd (void)
2725 struct cmd_list_element
*c
;
2727 current_display_number
= -1;
2729 observer_attach_solib_unloaded (clear_dangling_display_expressions
);
2731 add_info ("address", address_info
,
2732 _("Describe where symbol SYM is stored."));
2734 add_info ("symbol", sym_info
, _("\
2735 Describe what symbol is at location ADDR.\n\
2736 Only for symbols with fixed locations (global or static scope)."));
2738 add_com ("x", class_vars
, x_command
, _("\
2739 Examine memory: x/FMT ADDRESS.\n\
2740 ADDRESS is an expression for the memory address to examine.\n\
2741 FMT is a repeat count followed by a format letter and a size letter.\n\
2742 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2743 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2744 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2745 The specified number of objects of the specified size are printed\n\
2746 according to the format.\n\n\
2747 Defaults for format and size letters are those previously used.\n\
2748 Default count is 1. Default address is following last thing printed\n\
2749 with this command or \"print\"."));
2752 add_com ("whereis", class_vars
, whereis_command
,
2753 _("Print line number and file of definition of variable."));
2756 add_info ("display", display_info
, _("\
2757 Expressions to display when program stops, with code numbers."));
2759 add_cmd ("undisplay", class_vars
, undisplay_command
, _("\
2760 Cancel some expressions to be displayed when program stops.\n\
2761 Arguments are the code numbers of the expressions to stop displaying.\n\
2762 No argument means cancel all automatic-display expressions.\n\
2763 \"delete display\" has the same effect as this command.\n\
2764 Do \"info display\" to see current list of code numbers."),
2767 add_com ("display", class_vars
, display_command
, _("\
2768 Print value of expression EXP each time the program stops.\n\
2769 /FMT may be used before EXP as in the \"print\" command.\n\
2770 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2771 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2772 and examining is done as in the \"x\" command.\n\n\
2773 With no argument, display all currently requested auto-display expressions.\n\
2774 Use \"undisplay\" to cancel display requests previously made."));
2776 add_cmd ("display", class_vars
, enable_display_command
, _("\
2777 Enable some expressions to be displayed when program stops.\n\
2778 Arguments are the code numbers of the expressions to resume displaying.\n\
2779 No argument means enable all automatic-display expressions.\n\
2780 Do \"info display\" to see current list of code numbers."), &enablelist
);
2782 add_cmd ("display", class_vars
, disable_display_command
, _("\
2783 Disable some expressions to be displayed when program stops.\n\
2784 Arguments are the code numbers of the expressions to stop displaying.\n\
2785 No argument means disable all automatic-display expressions.\n\
2786 Do \"info display\" to see current list of code numbers."), &disablelist
);
2788 add_cmd ("display", class_vars
, undisplay_command
, _("\
2789 Cancel some expressions to be displayed when program stops.\n\
2790 Arguments are the code numbers of the expressions to stop displaying.\n\
2791 No argument means cancel all automatic-display expressions.\n\
2792 Do \"info display\" to see current list of code numbers."), &deletelist
);
2794 add_com ("printf", class_vars
, printf_command
, _("\
2795 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2796 This is useful for formatted output in user-defined commands."));
2798 add_com ("output", class_vars
, output_command
, _("\
2799 Like \"print\" but don't put in value history and don't print newline.\n\
2800 This is useful in user-defined commands."));
2802 add_prefix_cmd ("set", class_vars
, set_command
, _("\
2803 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2804 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2805 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2806 with $), a register (a few standard names starting with $), or an actual\n\
2807 variable in the program being debugged. EXP is any valid expression.\n\
2808 Use \"set variable\" for variables with names identical to set subcommands.\n\
2810 With a subcommand, this command modifies parts of the gdb environment.\n\
2811 You can see these environment settings with the \"show\" command."),
2812 &setlist
, "set ", 1, &cmdlist
);
2814 add_com ("assign", class_vars
, set_command
, _("\
2815 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2816 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2817 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2818 with $), a register (a few standard names starting with $), or an actual\n\
2819 variable in the program being debugged. EXP is any valid expression.\n\
2820 Use \"set variable\" for variables with names identical to set subcommands.\n\
2821 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2822 You can see these environment settings with the \"show\" command."));
2824 /* "call" is the same as "set", but handy for dbx users to call fns. */
2825 c
= add_com ("call", class_vars
, call_command
, _("\
2826 Call a function in the program.\n\
2827 The argument is the function name and arguments, in the notation of the\n\
2828 current working language. The result is printed and saved in the value\n\
2829 history, if it is not void."));
2830 set_cmd_completer (c
, expression_completer
);
2832 add_cmd ("variable", class_vars
, set_command
, _("\
2833 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2834 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2835 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2836 with $), a register (a few standard names starting with $), or an actual\n\
2837 variable in the program being debugged. EXP is any valid expression.\n\
2838 This may usually be abbreviated to simply \"set\"."),
2841 c
= add_com ("print", class_vars
, print_command
, _("\
2842 Print value of expression EXP.\n\
2843 Variables accessible are those of the lexical environment of the selected\n\
2844 stack frame, plus all those whose scope is global or an entire file.\n\
2846 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2847 $$NUM refers to NUM'th value back from the last one.\n\
2848 Names starting with $ refer to registers (with the values they would have\n\
2849 if the program were to return to the stack frame now selected, restoring\n\
2850 all registers saved by frames farther in) or else to debugger\n\
2851 \"convenience\" variables (any such name not a known register).\n\
2852 Use assignment expressions to give values to convenience variables.\n\
2854 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2855 @ is a binary operator for treating consecutive data objects\n\
2856 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2857 element is FOO, whose second element is stored in the space following\n\
2858 where FOO is stored, etc. FOO must be an expression whose value\n\
2859 resides in memory.\n\
2861 EXP may be preceded with /FMT, where FMT is a format letter\n\
2862 but no count or size letter (see \"x\" command)."));
2863 set_cmd_completer (c
, expression_completer
);
2864 add_com_alias ("p", "print", class_vars
, 1);
2866 c
= add_com ("inspect", class_vars
, inspect_command
, _("\
2867 Same as \"print\" command, except that if you are running in the epoch\n\
2868 environment, the value is printed in its own window."));
2869 set_cmd_completer (c
, expression_completer
);
2871 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class
,
2872 &max_symbolic_offset
, _("\
2873 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2874 Show the largest offset that will be printed in <symbol+1234> form."), NULL
,
2876 show_max_symbolic_offset
,
2877 &setprintlist
, &showprintlist
);
2878 add_setshow_boolean_cmd ("symbol-filename", no_class
,
2879 &print_symbol_filename
, _("\
2880 Set printing of source filename and line number with <symbol>."), _("\
2881 Show printing of source filename and line number with <symbol>."), NULL
,
2883 show_print_symbol_filename
,
2884 &setprintlist
, &showprintlist
);
2886 add_com ("eval", no_class
, eval_command
, _("\
2887 Convert \"printf format string\", arg1, arg2, arg3, ..., argn to\n\
2888 a command line, and call it."));