1 /* Print values for GNU debugger GDB.
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "expression.h"
30 #include "breakpoint.h"
32 #include "gdb-demangle.h"
35 #include "symfile.h" /* for overlay functions */
36 #include "objfiles.h" /* ditto */
37 #include "completer.h" /* for completion functions */
44 #include "parser-defs.h"
46 #include "arch-utils.h"
47 #include "cli/cli-utils.h"
48 #include "cli/cli-script.h"
53 #include "tui/tui.h" /* For tui_active et al. */
56 /* Last specified output format. */
58 static char last_format = 0;
60 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
62 static char last_size = 'w';
64 /* Default address to examine next, and associated architecture. */
66 static struct gdbarch *next_gdbarch;
67 static CORE_ADDR next_address;
69 /* Number of delay instructions following current disassembled insn. */
71 static int branch_delay_insns;
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 "
92 "printed in <symbol+1234> form is %s.\n"),
96 /* Append the source filename and linenumber of the symbol when
97 printing a symbolic value as `<symbol at filename:linenum>' if set. */
98 static int print_symbol_filename = 0;
100 show_print_symbol_filename (struct ui_file *file, int from_tty,
101 struct cmd_list_element *c, const char *value)
103 fprintf_filtered (file, _("Printing of source filename and "
104 "line number with <symbol> is %s.\n"),
108 /* Number of auto-display expression currently being displayed.
109 So that we can disable it if we get a signal within it.
110 -1 when not doing one. */
112 static int current_display_number;
116 /* Chain link to next auto-display item. */
117 struct display *next;
119 /* The expression as the user typed it. */
122 /* Expression to be evaluated and displayed. */
125 /* Item number of this auto-display item. */
128 /* Display format specified. */
129 struct format_data format;
131 /* Program space associated with `block'. */
132 struct program_space *pspace;
134 /* Innermost block required by this expression when evaluated. */
135 const struct block *block;
137 /* Status of this display (enabled or disabled). */
141 /* Chain of expressions whose values should be displayed
142 automatically each time the program stops. */
144 static struct display *display_chain;
146 static int display_number;
148 /* Walk the following statement or block through all displays.
149 ALL_DISPLAYS_SAFE does so even if the statement deletes the current
152 #define ALL_DISPLAYS(B) \
153 for (B = display_chain; B; B = B->next)
155 #define ALL_DISPLAYS_SAFE(B,TMP) \
156 for (B = display_chain; \
157 B ? (TMP = B->next, 1): 0; \
160 /* Prototypes for exported functions. */
162 void _initialize_printcmd (void);
164 /* Prototypes for local functions. */
166 static void do_one_display (struct display *);
169 /* Decode a format specification. *STRING_PTR should point to it.
170 OFORMAT and OSIZE are used as defaults for the format and size
171 if none are given in the format specification.
172 If OSIZE is zero, then the size field of the returned value
173 should be set only if a size is explicitly specified by the
175 The structure returned describes all the data
176 found in the specification. In addition, *STRING_PTR is advanced
177 past the specification and past all whitespace following it. */
179 static struct format_data
180 decode_format (const char **string_ptr, int oformat, int osize)
182 struct format_data val;
183 const char *p = *string_ptr;
195 if (*p >= '0' && *p <= '9')
196 val.count *= atoi (p);
197 while (*p >= '0' && *p <= '9')
200 /* Now process size or format letters that follow. */
204 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
211 else if (*p >= 'a' && *p <= 'z')
217 while (*p == ' ' || *p == '\t')
221 /* Set defaults for format and size if not specified. */
222 if (val.format == '?')
226 /* Neither has been specified. */
227 val.format = oformat;
231 /* If a size is specified, any format makes a reasonable
232 default except 'i'. */
233 val.format = oformat == 'i' ? 'x' : oformat;
235 else if (val.size == '?')
239 /* Pick the appropriate size for an address. This is deferred
240 until do_examine when we know the actual architecture to use.
241 A special size value of 'a' is used to indicate this case. */
242 val.size = osize ? 'a' : osize;
245 /* Floating point has to be word or giantword. */
246 if (osize == 'w' || osize == 'g')
249 /* Default it to giantword if the last used size is not
251 val.size = osize ? 'g' : osize;
254 /* Characters default to one byte. */
255 val.size = osize ? 'b' : osize;
258 /* Display strings with byte size chars unless explicitly
264 /* The default is the size most recently specified. */
271 /* Print value VAL on stream according to OPTIONS.
272 Do not end with a newline.
273 SIZE is the letter for the size of datum being printed.
274 This is used to pad hex numbers so they line up. SIZE is 0
275 for print / output and set for examine. */
278 print_formatted (struct value *val, int size,
279 const struct value_print_options *options,
280 struct ui_file *stream)
282 struct type *type = check_typedef (value_type (val));
283 int len = TYPE_LENGTH (type);
285 if (VALUE_LVAL (val) == lval_memory)
286 next_address = value_address (val) + len;
290 switch (options->format)
294 struct type *elttype = value_type (val);
296 next_address = (value_address (val)
297 + val_print_string (elttype, NULL,
298 value_address (val), -1,
299 stream, options) * len);
304 /* We often wrap here if there are long symbolic names. */
306 next_address = (value_address (val)
307 + gdb_print_insn (get_type_arch (type),
308 value_address (val), stream,
309 &branch_delay_insns));
314 if (options->format == 0 || options->format == 's'
315 || TYPE_CODE (type) == TYPE_CODE_REF
316 || TYPE_CODE (type) == TYPE_CODE_ARRAY
317 || TYPE_CODE (type) == TYPE_CODE_STRING
318 || TYPE_CODE (type) == TYPE_CODE_STRUCT
319 || TYPE_CODE (type) == TYPE_CODE_UNION
320 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
321 value_print (val, stream, options);
323 /* User specified format, so don't look to the type to tell us
325 val_print_scalar_formatted (type,
326 value_embedded_offset (val),
328 options, size, stream);
331 /* Return builtin floating point type of same length as TYPE.
332 If no such type is found, return TYPE itself. */
334 float_type_from_length (struct type *type)
336 struct gdbarch *gdbarch = get_type_arch (type);
337 const struct builtin_type *builtin = builtin_type (gdbarch);
339 if (TYPE_LENGTH (type) == TYPE_LENGTH (builtin->builtin_float))
340 type = builtin->builtin_float;
341 else if (TYPE_LENGTH (type) == TYPE_LENGTH (builtin->builtin_double))
342 type = builtin->builtin_double;
343 else if (TYPE_LENGTH (type) == TYPE_LENGTH (builtin->builtin_long_double))
344 type = builtin->builtin_long_double;
349 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
350 according to OPTIONS and SIZE on STREAM. Formats s and i are not
351 supported at this level. */
354 print_scalar_formatted (const gdb_byte *valaddr, struct type *type,
355 const struct value_print_options *options,
356 int size, struct ui_file *stream)
358 struct gdbarch *gdbarch = get_type_arch (type);
359 unsigned int len = TYPE_LENGTH (type);
360 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
362 /* String printing should go through val_print_scalar_formatted. */
363 gdb_assert (options->format != 's');
365 /* If the value is a pointer, and pointers and addresses are not the
366 same, then at this point, the value's length (in target bytes) is
367 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
368 if (TYPE_CODE (type) == TYPE_CODE_PTR)
369 len = gdbarch_addr_bit (gdbarch) / TARGET_CHAR_BIT;
371 /* If we are printing it as unsigned, truncate it in case it is actually
372 a negative signed value (e.g. "print/u (short)-1" should print 65535
373 (if shorts are 16 bits) instead of 4294967295). */
374 if (options->format != 'c'
375 && (options->format != 'd' || TYPE_UNSIGNED (type)))
377 if (len < TYPE_LENGTH (type) && byte_order == BFD_ENDIAN_BIG)
378 valaddr += TYPE_LENGTH (type) - len;
381 if (size != 0 && (options->format == 'x' || options->format == 't'))
383 /* Truncate to fit. */
400 error (_("Undefined output size \"%c\"."), size);
402 if (newlen < len && byte_order == BFD_ENDIAN_BIG)
403 valaddr += len - newlen;
407 /* Historically gdb has printed floats by first casting them to a
408 long, and then printing the long. PR cli/16242 suggests changing
409 this to using C-style hex float format. */
410 std::vector<gdb_byte> converted_float_bytes;
411 if (TYPE_CODE (type) == TYPE_CODE_FLT
412 && (options->format == 'o'
413 || options->format == 'x'
414 || options->format == 't'
415 || options->format == 'z'))
417 LONGEST val_long = unpack_long (type, valaddr);
418 converted_float_bytes.resize (TYPE_LENGTH (type));
419 store_signed_integer (converted_float_bytes.data (), TYPE_LENGTH (type),
420 byte_order, val_long);
421 valaddr = converted_float_bytes.data ();
424 switch (options->format)
427 print_octal_chars (stream, valaddr, len, byte_order);
430 print_decimal_chars (stream, valaddr, len, false, byte_order);
434 if (TYPE_CODE (type) != TYPE_CODE_FLT)
436 print_decimal_chars (stream, valaddr, len, !TYPE_UNSIGNED (type),
442 type = float_type_from_length (type);
443 print_floating (valaddr, type, stream);
447 print_binary_chars (stream, valaddr, len, byte_order, size > 0);
450 print_hex_chars (stream, valaddr, len, byte_order, size > 0);
453 print_hex_chars (stream, valaddr, len, byte_order, true);
457 struct value_print_options opts = *options;
459 LONGEST val_long = unpack_long (type, valaddr);
462 if (TYPE_UNSIGNED (type))
463 type = builtin_type (gdbarch)->builtin_true_unsigned_char;
465 type = builtin_type (gdbarch)->builtin_true_char;
467 value_print (value_from_longest (type, val_long), stream, &opts);
473 CORE_ADDR addr = unpack_pointer (type, valaddr);
475 print_address (gdbarch, addr, stream);
480 error (_("Undefined output format \"%c\"."), options->format);
484 /* Specify default address for `x' command.
485 The `info lines' command uses this. */
488 set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr)
490 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
492 next_gdbarch = gdbarch;
495 /* Make address available to the user as $_. */
496 set_internalvar (lookup_internalvar ("_"),
497 value_from_pointer (ptr_type, addr));
500 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
501 after LEADIN. Print nothing if no symbolic name is found nearby.
502 Optionally also print source file and line number, if available.
503 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
504 or to interpret it as a possible C++ name and convert it back to source
505 form. However note that DO_DEMANGLE can be overridden by the specific
506 settings of the demangle and asm_demangle variables. Returns
507 non-zero if anything was printed; zero otherwise. */
510 print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
511 struct ui_file *stream,
512 int do_demangle, const char *leadin)
515 char *filename = NULL;
520 /* Throw away both name and filename. */
521 struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
522 make_cleanup (free_current_contents, &filename);
524 if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &offset,
525 &filename, &line, &unmapped))
527 do_cleanups (cleanup_chain);
531 fputs_filtered (leadin, stream);
533 fputs_filtered ("<*", stream);
535 fputs_filtered ("<", stream);
536 fputs_filtered (name, stream);
538 fprintf_filtered (stream, "+%u", (unsigned int) offset);
540 /* Append source filename and line number if desired. Give specific
541 line # of this addr, if we have it; else line # of the nearest symbol. */
542 if (print_symbol_filename && filename != NULL)
545 fprintf_filtered (stream, " at %s:%d", filename, line);
547 fprintf_filtered (stream, " in %s", filename);
550 fputs_filtered ("*>", stream);
552 fputs_filtered (">", stream);
554 do_cleanups (cleanup_chain);
558 /* Given an address ADDR return all the elements needed to print the
559 address in a symbolic form. NAME can be mangled or not depending
560 on DO_DEMANGLE (and also on the asm_demangle global variable,
561 manipulated via ''set print asm-demangle''). Return 0 in case of
562 success, when all the info in the OUT paramters is valid. Return 1
565 build_address_symbolic (struct gdbarch *gdbarch,
566 CORE_ADDR addr, /* IN */
567 int do_demangle, /* IN */
568 char **name, /* OUT */
569 int *offset, /* OUT */
570 char **filename, /* OUT */
572 int *unmapped) /* OUT */
574 struct bound_minimal_symbol msymbol;
575 struct symbol *symbol;
576 CORE_ADDR name_location = 0;
577 struct obj_section *section = NULL;
578 const char *name_temp = "";
580 /* Let's say it is mapped (not unmapped). */
583 /* Determine if the address is in an overlay, and whether it is
585 if (overlay_debugging)
587 section = find_pc_overlay (addr);
588 if (pc_in_unmapped_range (addr, section))
591 addr = overlay_mapped_address (addr, section);
595 /* First try to find the address in the symbol table, then
596 in the minsyms. Take the closest one. */
598 /* This is defective in the sense that it only finds text symbols. So
599 really this is kind of pointless--we should make sure that the
600 minimal symbols have everything we need (by changing that we could
601 save some memory, but for many debug format--ELF/DWARF or
602 anything/stabs--it would be inconvenient to eliminate those minimal
604 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
605 symbol = find_pc_sect_function (addr, section);
609 /* If this is a function (i.e. a code address), strip out any
610 non-address bits. For instance, display a pointer to the
611 first instruction of a Thumb function as <function>; the
612 second instruction will be <function+2>, even though the
613 pointer is <function+3>. This matches the ISA behavior. */
614 addr = gdbarch_addr_bits_remove (gdbarch, addr);
616 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
617 if (do_demangle || asm_demangle)
618 name_temp = SYMBOL_PRINT_NAME (symbol);
620 name_temp = SYMBOL_LINKAGE_NAME (symbol);
623 if (msymbol.minsym != NULL
624 && MSYMBOL_HAS_SIZE (msymbol.minsym)
625 && MSYMBOL_SIZE (msymbol.minsym) == 0
626 && MSYMBOL_TYPE (msymbol.minsym) != mst_text
627 && MSYMBOL_TYPE (msymbol.minsym) != mst_text_gnu_ifunc
628 && MSYMBOL_TYPE (msymbol.minsym) != mst_file_text)
629 msymbol.minsym = NULL;
631 if (msymbol.minsym != NULL)
633 if (BMSYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
635 /* If this is a function (i.e. a code address), strip out any
636 non-address bits. For instance, display a pointer to the
637 first instruction of a Thumb function as <function>; the
638 second instruction will be <function+2>, even though the
639 pointer is <function+3>. This matches the ISA behavior. */
640 if (MSYMBOL_TYPE (msymbol.minsym) == mst_text
641 || MSYMBOL_TYPE (msymbol.minsym) == mst_text_gnu_ifunc
642 || MSYMBOL_TYPE (msymbol.minsym) == mst_file_text
643 || MSYMBOL_TYPE (msymbol.minsym) == mst_solib_trampoline)
644 addr = gdbarch_addr_bits_remove (gdbarch, addr);
646 /* The msymbol is closer to the address than the symbol;
647 use the msymbol instead. */
649 name_location = BMSYMBOL_VALUE_ADDRESS (msymbol);
650 if (do_demangle || asm_demangle)
651 name_temp = MSYMBOL_PRINT_NAME (msymbol.minsym);
653 name_temp = MSYMBOL_LINKAGE_NAME (msymbol.minsym);
656 if (symbol == NULL && msymbol.minsym == NULL)
659 /* If the nearest symbol is too far away, don't print anything symbolic. */
661 /* For when CORE_ADDR is larger than unsigned int, we do math in
662 CORE_ADDR. But when we detect unsigned wraparound in the
663 CORE_ADDR math, we ignore this test and print the offset,
664 because addr+max_symbolic_offset has wrapped through the end
665 of the address space back to the beginning, giving bogus comparison. */
666 if (addr > name_location + max_symbolic_offset
667 && name_location + max_symbolic_offset > name_location)
670 *offset = addr - name_location;
672 *name = xstrdup (name_temp);
674 if (print_symbol_filename)
676 struct symtab_and_line sal;
678 sal = find_pc_sect_line (addr, section, 0);
682 *filename = xstrdup (symtab_to_filename_for_display (sal.symtab));
690 /* Print address ADDR symbolically on STREAM.
691 First print it as a number. Then perhaps print
692 <SYMBOL + OFFSET> after the number. */
695 print_address (struct gdbarch *gdbarch,
696 CORE_ADDR addr, struct ui_file *stream)
698 fputs_filtered (paddress (gdbarch, addr), stream);
699 print_address_symbolic (gdbarch, addr, stream, asm_demangle, " ");
702 /* Return a prefix for instruction address:
703 "=> " for current instruction, else " ". */
706 pc_prefix (CORE_ADDR addr)
708 if (has_stack_frames ())
710 struct frame_info *frame;
713 frame = get_selected_frame (NULL);
714 if (get_frame_pc_if_available (frame, &pc) && pc == addr)
720 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
721 controls whether to print the symbolic name "raw" or demangled.
722 Return non-zero if anything was printed; zero otherwise. */
725 print_address_demangle (const struct value_print_options *opts,
726 struct gdbarch *gdbarch, CORE_ADDR addr,
727 struct ui_file *stream, int do_demangle)
729 if (opts->addressprint)
731 fputs_filtered (paddress (gdbarch, addr), stream);
732 print_address_symbolic (gdbarch, addr, stream, do_demangle, " ");
736 return print_address_symbolic (gdbarch, addr, stream, do_demangle, "");
742 /* Find the address of the instruction that is INST_COUNT instructions before
743 the instruction at ADDR.
744 Since some architectures have variable-length instructions, we can't just
745 simply subtract INST_COUNT * INSN_LEN from ADDR. Instead, we use line
746 number information to locate the nearest known instruction boundary,
747 and disassemble forward from there. If we go out of the symbol range
748 during disassembling, we return the lowest address we've got so far and
749 set the number of instructions read to INST_READ. */
752 find_instruction_backward (struct gdbarch *gdbarch, CORE_ADDR addr,
753 int inst_count, int *inst_read)
755 /* The vector PCS is used to store instruction addresses within
757 CORE_ADDR loop_start, loop_end, p;
758 std::vector<CORE_ADDR> pcs;
759 struct symtab_and_line sal;
762 loop_start = loop_end = addr;
764 /* In each iteration of the outer loop, we get a pc range that ends before
765 LOOP_START, then we count and store every instruction address of the range
766 iterated in the loop.
767 If the number of instructions counted reaches INST_COUNT, return the
768 stored address that is located INST_COUNT instructions back from ADDR.
769 If INST_COUNT is not reached, we subtract the number of counted
770 instructions from INST_COUNT, and go to the next iteration. */
774 sal = find_pc_sect_line (loop_start, NULL, 1);
777 /* We reach here when line info is not available. In this case,
778 we print a message and just exit the loop. The return value
779 is calculated after the loop. */
780 printf_filtered (_("No line number information available "
783 print_address (gdbarch, loop_start - 1, gdb_stdout);
784 printf_filtered ("\n");
788 loop_end = loop_start;
791 /* This loop pushes instruction addresses in the range from
792 LOOP_START to LOOP_END. */
793 for (p = loop_start; p < loop_end;)
796 p += gdb_insn_length (gdbarch, p);
799 inst_count -= pcs.size ();
800 *inst_read += pcs.size ();
802 while (inst_count > 0);
804 /* After the loop, the vector PCS has instruction addresses of the last
805 source line we processed, and INST_COUNT has a negative value.
806 We return the address at the index of -INST_COUNT in the vector for
808 Let's assume the following instruction addresses and run 'x/-4i 0x400e'.
818 find_instruction_backward is called with INST_COUNT = 4 and expected to
819 return 0x4001. When we reach here, INST_COUNT is set to -1 because
820 it was subtracted by 2 (from Line Y) and 3 (from Line X). The value
821 4001 is located at the index 1 of the last iterated line (= Line X),
822 which is simply calculated by -INST_COUNT.
823 The case when the length of PCS is 0 means that we reached an area for
824 which line info is not available. In such case, we return LOOP_START,
825 which was the lowest instruction address that had line info. */
826 p = pcs.size () > 0 ? pcs[-inst_count] : loop_start;
828 /* INST_READ includes all instruction addresses in a pc range. Need to
829 exclude the beginning part up to the address we're returning. That
830 is, exclude {0x4000} in the example above. */
832 *inst_read += inst_count;
837 /* Backward read LEN bytes of target memory from address MEMADDR + LEN,
838 placing the results in GDB's memory from MYADDR + LEN. Returns
839 a count of the bytes actually read. */
842 read_memory_backward (struct gdbarch *gdbarch,
843 CORE_ADDR memaddr, gdb_byte *myaddr, int len)
846 int nread; /* Number of bytes actually read. */
848 /* First try a complete read. */
849 errcode = target_read_memory (memaddr, myaddr, len);
857 /* Loop, reading one byte at a time until we get as much as we can. */
860 for (nread = 0; nread < len; ++nread)
862 errcode = target_read_memory (--memaddr, --myaddr, 1);
865 /* The read was unsuccessful, so exit the loop. */
866 printf_filtered (_("Cannot access memory at address %s\n"),
867 paddress (gdbarch, memaddr));
875 /* Returns true if X (which is LEN bytes wide) is the number zero. */
878 integer_is_zero (const gdb_byte *x, int len)
882 while (i < len && x[i] == 0)
887 /* Find the start address of a string in which ADDR is included.
888 Basically we search for '\0' and return the next address,
889 but if OPTIONS->PRINT_MAX is smaller than the length of a string,
890 we stop searching and return the address to print characters as many as
891 PRINT_MAX from the string. */
894 find_string_backward (struct gdbarch *gdbarch,
895 CORE_ADDR addr, int count, int char_size,
896 const struct value_print_options *options,
897 int *strings_counted)
899 const int chunk_size = 0x20;
900 gdb_byte *buffer = NULL;
901 struct cleanup *cleanup = NULL;
904 int chars_to_read = chunk_size;
905 int chars_counted = 0;
906 int count_original = count;
907 CORE_ADDR string_start_addr = addr;
909 gdb_assert (char_size == 1 || char_size == 2 || char_size == 4);
910 buffer = (gdb_byte *) xmalloc (chars_to_read * char_size);
911 cleanup = make_cleanup (xfree, buffer);
912 while (count > 0 && read_error == 0)
916 addr -= chars_to_read * char_size;
917 chars_read = read_memory_backward (gdbarch, addr, buffer,
918 chars_to_read * char_size);
919 chars_read /= char_size;
920 read_error = (chars_read == chars_to_read) ? 0 : 1;
921 /* Searching for '\0' from the end of buffer in backward direction. */
922 for (i = 0; i < chars_read && count > 0 ; ++i, ++chars_counted)
924 int offset = (chars_to_read - i - 1) * char_size;
926 if (integer_is_zero (buffer + offset, char_size)
927 || chars_counted == options->print_max)
929 /* Found '\0' or reached print_max. As OFFSET is the offset to
930 '\0', we add CHAR_SIZE to return the start address of
933 string_start_addr = addr + offset + char_size;
939 /* Update STRINGS_COUNTED with the actual number of loaded strings. */
940 *strings_counted = count_original - count;
944 /* In error case, STRING_START_ADDR is pointing to the string that
945 was last successfully loaded. Rewind the partially loaded string. */
946 string_start_addr -= chars_counted * char_size;
949 do_cleanups (cleanup);
950 return string_start_addr;
953 /* Examine data at address ADDR in format FMT.
954 Fetch it from memory and print on gdb_stdout. */
957 do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr)
962 struct type *val_type = NULL;
965 struct value_print_options opts;
966 int need_to_update_next_address = 0;
967 CORE_ADDR addr_rewound = 0;
972 next_gdbarch = gdbarch;
975 /* Instruction format implies fetch single bytes
976 regardless of the specified size.
977 The case of strings is handled in decode_format, only explicit
978 size operator are not changed to 'b'. */
984 /* Pick the appropriate size for an address. */
985 if (gdbarch_ptr_bit (next_gdbarch) == 64)
987 else if (gdbarch_ptr_bit (next_gdbarch) == 32)
989 else if (gdbarch_ptr_bit (next_gdbarch) == 16)
992 /* Bad value for gdbarch_ptr_bit. */
993 internal_error (__FILE__, __LINE__,
994 _("failed internal consistency check"));
998 val_type = builtin_type (next_gdbarch)->builtin_int8;
999 else if (size == 'h')
1000 val_type = builtin_type (next_gdbarch)->builtin_int16;
1001 else if (size == 'w')
1002 val_type = builtin_type (next_gdbarch)->builtin_int32;
1003 else if (size == 'g')
1004 val_type = builtin_type (next_gdbarch)->builtin_int64;
1008 struct type *char_type = NULL;
1010 /* Search for "char16_t" or "char32_t" types or fall back to 8-bit char
1011 if type is not found. */
1013 char_type = builtin_type (next_gdbarch)->builtin_char16;
1014 else if (size == 'w')
1015 char_type = builtin_type (next_gdbarch)->builtin_char32;
1017 val_type = char_type;
1020 if (size != '\0' && size != 'b')
1021 warning (_("Unable to display strings with "
1022 "size '%c', using 'b' instead."), size);
1024 val_type = builtin_type (next_gdbarch)->builtin_int8;
1033 if (format == 's' || format == 'i')
1036 get_formatted_print_options (&opts, format);
1040 /* This is the negative repeat count case.
1041 We rewind the address based on the given repeat count and format,
1042 then examine memory from there in forward direction. */
1047 next_address = find_instruction_backward (gdbarch, addr, count,
1050 else if (format == 's')
1052 next_address = find_string_backward (gdbarch, addr, count,
1053 TYPE_LENGTH (val_type),
1058 next_address = addr - count * TYPE_LENGTH (val_type);
1061 /* The following call to print_formatted updates next_address in every
1062 iteration. In backward case, we store the start address here
1063 and update next_address with it before exiting the function. */
1064 addr_rewound = (format == 's'
1065 ? next_address - TYPE_LENGTH (val_type)
1067 need_to_update_next_address = 1;
1070 /* Print as many objects as specified in COUNT, at most maxelts per line,
1071 with the address of the next one at the start of each line. */
1077 fputs_filtered (pc_prefix (next_address), gdb_stdout);
1078 print_address (next_gdbarch, next_address, gdb_stdout);
1079 printf_filtered (":");
1084 printf_filtered ("\t");
1085 /* Note that print_formatted sets next_address for the next
1087 last_examine_address = next_address;
1089 if (last_examine_value)
1090 value_free (last_examine_value);
1092 /* The value to be displayed is not fetched greedily.
1093 Instead, to avoid the possibility of a fetched value not
1094 being used, its retrieval is delayed until the print code
1095 uses it. When examining an instruction stream, the
1096 disassembler will perform its own memory fetch using just
1097 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
1098 the disassembler be modified so that LAST_EXAMINE_VALUE
1099 is left with the byte sequence from the last complete
1100 instruction fetched from memory? */
1101 last_examine_value = value_at_lazy (val_type, next_address);
1103 if (last_examine_value)
1104 release_value (last_examine_value);
1106 print_formatted (last_examine_value, size, &opts, gdb_stdout);
1108 /* Display any branch delay slots following the final insn. */
1109 if (format == 'i' && count == 1)
1110 count += branch_delay_insns;
1112 printf_filtered ("\n");
1113 gdb_flush (gdb_stdout);
1116 if (need_to_update_next_address)
1117 next_address = addr_rewound;
1121 validate_format (struct format_data fmt, const char *cmdname)
1124 error (_("Size letters are meaningless in \"%s\" command."), cmdname);
1126 error (_("Item count other than 1 is meaningless in \"%s\" command."),
1128 if (fmt.format == 'i')
1129 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
1130 fmt.format, cmdname);
1133 /* Parse print command format string into *FMTP and update *EXPP.
1134 CMDNAME should name the current command. */
1137 print_command_parse_format (const char **expp, const char *cmdname,
1138 struct format_data *fmtp)
1140 const char *exp = *expp;
1142 if (exp && *exp == '/')
1145 *fmtp = decode_format (&exp, last_format, 0);
1146 validate_format (*fmtp, cmdname);
1147 last_format = fmtp->format;
1160 /* Print VAL to console according to *FMTP, including recording it to
1164 print_value (struct value *val, const struct format_data *fmtp)
1166 struct value_print_options opts;
1167 int histindex = record_latest_value (val);
1169 annotate_value_history_begin (histindex, value_type (val));
1171 printf_filtered ("$%d = ", histindex);
1173 annotate_value_history_value ();
1175 get_formatted_print_options (&opts, fmtp->format);
1176 opts.raw = fmtp->raw;
1178 print_formatted (val, fmtp->size, &opts, gdb_stdout);
1179 printf_filtered ("\n");
1181 annotate_value_history_end ();
1184 /* Evaluate string EXP as an expression in the current language and
1185 print the resulting value. EXP may contain a format specifier as the
1186 first argument ("/x myvar" for example, to print myvar in hex). */
1189 print_command_1 (const char *exp, int voidprint)
1192 struct format_data fmt;
1194 print_command_parse_format (&exp, "print", &fmt);
1198 expression_up expr = parse_expression (exp);
1199 val = evaluate_expression (expr.get ());
1202 val = access_value_history (0);
1204 if (voidprint || (val && value_type (val) &&
1205 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
1206 print_value (val, &fmt);
1210 print_command (char *exp, int from_tty)
1212 print_command_1 (exp, 1);
1215 /* Same as print, except it doesn't print void results. */
1217 call_command (char *exp, int from_tty)
1219 print_command_1 (exp, 0);
1222 /* Implementation of the "output" command. */
1225 output_command (char *exp, int from_tty)
1227 output_command_const (exp, from_tty);
1230 /* Like output_command, but takes a const string as argument. */
1233 output_command_const (const char *exp, int from_tty)
1237 struct format_data fmt;
1238 struct value_print_options opts;
1243 if (exp && *exp == '/')
1246 fmt = decode_format (&exp, 0, 0);
1247 validate_format (fmt, "output");
1248 format = fmt.format;
1251 expression_up expr = parse_expression (exp);
1253 val = evaluate_expression (expr.get ());
1255 annotate_value_begin (value_type (val));
1257 get_formatted_print_options (&opts, format);
1259 print_formatted (val, fmt.size, &opts, gdb_stdout);
1261 annotate_value_end ();
1264 gdb_flush (gdb_stdout);
1268 set_command (char *exp, int from_tty)
1270 expression_up expr = parse_expression (exp);
1272 if (expr->nelts >= 1)
1273 switch (expr->elts[0].opcode)
1275 case UNOP_PREINCREMENT:
1276 case UNOP_POSTINCREMENT:
1277 case UNOP_PREDECREMENT:
1278 case UNOP_POSTDECREMENT:
1280 case BINOP_ASSIGN_MODIFY:
1285 (_("Expression is not an assignment (and might have no effect)"));
1288 evaluate_expression (expr.get ());
1292 sym_info (char *arg, int from_tty)
1294 struct minimal_symbol *msymbol;
1295 struct objfile *objfile;
1296 struct obj_section *osect;
1297 CORE_ADDR addr, sect_addr;
1299 unsigned int offset;
1302 error_no_arg (_("address"));
1304 addr = parse_and_eval_address (arg);
1305 ALL_OBJSECTIONS (objfile, osect)
1307 /* Only process each object file once, even if there's a separate
1309 if (objfile->separate_debug_objfile_backlink)
1312 sect_addr = overlay_mapped_address (addr, osect);
1314 if (obj_section_addr (osect) <= sect_addr
1315 && sect_addr < obj_section_endaddr (osect)
1317 = lookup_minimal_symbol_by_pc_section (sect_addr, osect).minsym))
1319 const char *obj_name, *mapped, *sec_name, *msym_name;
1321 struct cleanup *old_chain;
1324 offset = sect_addr - MSYMBOL_VALUE_ADDRESS (objfile, msymbol);
1325 mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
1326 sec_name = osect->the_bfd_section->name;
1327 msym_name = MSYMBOL_PRINT_NAME (msymbol);
1329 /* Don't print the offset if it is zero.
1330 We assume there's no need to handle i18n of "sym + offset". */
1332 loc_string = xstrprintf ("%s + %u", msym_name, offset);
1334 loc_string = xstrprintf ("%s", msym_name);
1336 /* Use a cleanup to free loc_string in case the user quits
1337 a pagination request inside printf_filtered. */
1338 old_chain = make_cleanup (xfree, loc_string);
1340 gdb_assert (osect->objfile && objfile_name (osect->objfile));
1341 obj_name = objfile_name (osect->objfile);
1343 if (MULTI_OBJFILE_P ())
1344 if (pc_in_unmapped_range (addr, osect))
1345 if (section_is_overlay (osect))
1346 printf_filtered (_("%s in load address range of "
1347 "%s overlay section %s of %s\n"),
1348 loc_string, mapped, sec_name, obj_name);
1350 printf_filtered (_("%s in load address range of "
1351 "section %s of %s\n"),
1352 loc_string, sec_name, obj_name);
1354 if (section_is_overlay (osect))
1355 printf_filtered (_("%s in %s overlay section %s of %s\n"),
1356 loc_string, mapped, sec_name, obj_name);
1358 printf_filtered (_("%s in section %s of %s\n"),
1359 loc_string, sec_name, obj_name);
1361 if (pc_in_unmapped_range (addr, osect))
1362 if (section_is_overlay (osect))
1363 printf_filtered (_("%s in load address range of %s overlay "
1365 loc_string, mapped, sec_name);
1367 printf_filtered (_("%s in load address range of section %s\n"),
1368 loc_string, sec_name);
1370 if (section_is_overlay (osect))
1371 printf_filtered (_("%s in %s overlay section %s\n"),
1372 loc_string, mapped, sec_name);
1374 printf_filtered (_("%s in section %s\n"),
1375 loc_string, sec_name);
1377 do_cleanups (old_chain);
1381 printf_filtered (_("No symbol matches %s.\n"), arg);
1385 address_info (char *exp, int from_tty)
1387 struct gdbarch *gdbarch;
1390 struct bound_minimal_symbol msymbol;
1392 struct obj_section *section;
1393 CORE_ADDR load_addr, context_pc = 0;
1394 struct field_of_this_result is_a_field_of_this;
1397 error (_("Argument required."));
1399 sym = lookup_symbol (exp, get_selected_block (&context_pc), VAR_DOMAIN,
1400 &is_a_field_of_this).symbol;
1403 if (is_a_field_of_this.type != NULL)
1405 printf_filtered ("Symbol \"");
1406 fprintf_symbol_filtered (gdb_stdout, exp,
1407 current_language->la_language, DMGL_ANSI);
1408 printf_filtered ("\" is a field of the local class variable ");
1409 if (current_language->la_language == language_objc)
1410 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1412 printf_filtered ("`this'\n");
1416 msymbol = lookup_bound_minimal_symbol (exp);
1418 if (msymbol.minsym != NULL)
1420 struct objfile *objfile = msymbol.objfile;
1422 gdbarch = get_objfile_arch (objfile);
1423 load_addr = BMSYMBOL_VALUE_ADDRESS (msymbol);
1425 printf_filtered ("Symbol \"");
1426 fprintf_symbol_filtered (gdb_stdout, exp,
1427 current_language->la_language, DMGL_ANSI);
1428 printf_filtered ("\" is at ");
1429 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1430 printf_filtered (" in a file compiled without debugging");
1431 section = MSYMBOL_OBJ_SECTION (objfile, msymbol.minsym);
1432 if (section_is_overlay (section))
1434 load_addr = overlay_unmapped_address (load_addr, section);
1435 printf_filtered (",\n -- loaded at ");
1436 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1437 printf_filtered (" in overlay section %s",
1438 section->the_bfd_section->name);
1440 printf_filtered (".\n");
1443 error (_("No symbol \"%s\" in current context."), exp);
1447 printf_filtered ("Symbol \"");
1448 fprintf_symbol_filtered (gdb_stdout, SYMBOL_PRINT_NAME (sym),
1449 current_language->la_language, DMGL_ANSI);
1450 printf_filtered ("\" is ");
1451 val = SYMBOL_VALUE (sym);
1452 if (SYMBOL_OBJFILE_OWNED (sym))
1453 section = SYMBOL_OBJ_SECTION (symbol_objfile (sym), sym);
1456 gdbarch = symbol_arch (sym);
1458 if (SYMBOL_COMPUTED_OPS (sym) != NULL)
1460 SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, context_pc,
1462 printf_filtered (".\n");
1466 switch (SYMBOL_CLASS (sym))
1469 case LOC_CONST_BYTES:
1470 printf_filtered ("constant");
1474 printf_filtered ("a label at address ");
1475 load_addr = SYMBOL_VALUE_ADDRESS (sym);
1476 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1477 if (section_is_overlay (section))
1479 load_addr = overlay_unmapped_address (load_addr, section);
1480 printf_filtered (",\n -- loaded at ");
1481 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1482 printf_filtered (" in overlay section %s",
1483 section->the_bfd_section->name);
1488 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
1491 /* GDBARCH is the architecture associated with the objfile the symbol
1492 is defined in; the target architecture may be different, and may
1493 provide additional registers. However, we do not know the target
1494 architecture at this point. We assume the objfile architecture
1495 will contain all the standard registers that occur in debug info
1497 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
1499 if (SYMBOL_IS_ARGUMENT (sym))
1500 printf_filtered (_("an argument in register %s"),
1501 gdbarch_register_name (gdbarch, regno));
1503 printf_filtered (_("a variable in register %s"),
1504 gdbarch_register_name (gdbarch, regno));
1508 printf_filtered (_("static storage at address "));
1509 load_addr = SYMBOL_VALUE_ADDRESS (sym);
1510 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1511 if (section_is_overlay (section))
1513 load_addr = overlay_unmapped_address (load_addr, section);
1514 printf_filtered (_(",\n -- loaded at "));
1515 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1516 printf_filtered (_(" in overlay section %s"),
1517 section->the_bfd_section->name);
1521 case LOC_REGPARM_ADDR:
1522 /* Note comment at LOC_REGISTER. */
1523 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
1524 printf_filtered (_("address of an argument in register %s"),
1525 gdbarch_register_name (gdbarch, regno));
1529 printf_filtered (_("an argument at offset %ld"), val);
1533 printf_filtered (_("a local variable at frame offset %ld"), val);
1537 printf_filtered (_("a reference argument at offset %ld"), val);
1541 printf_filtered (_("a typedef"));
1545 printf_filtered (_("a function at address "));
1546 load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1547 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1548 if (section_is_overlay (section))
1550 load_addr = overlay_unmapped_address (load_addr, section);
1551 printf_filtered (_(",\n -- loaded at "));
1552 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1553 printf_filtered (_(" in overlay section %s"),
1554 section->the_bfd_section->name);
1558 case LOC_UNRESOLVED:
1560 struct bound_minimal_symbol msym;
1562 msym = lookup_minimal_symbol_and_objfile (SYMBOL_LINKAGE_NAME (sym));
1563 if (msym.minsym == NULL)
1564 printf_filtered ("unresolved");
1567 section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
1570 && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
1572 load_addr = MSYMBOL_VALUE_RAW_ADDRESS (msym.minsym);
1573 printf_filtered (_("a thread-local variable at offset %s "
1574 "in the thread-local storage for `%s'"),
1575 paddress (gdbarch, load_addr),
1576 objfile_name (section->objfile));
1580 load_addr = BMSYMBOL_VALUE_ADDRESS (msym);
1581 printf_filtered (_("static storage at address "));
1582 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1583 if (section_is_overlay (section))
1585 load_addr = overlay_unmapped_address (load_addr, section);
1586 printf_filtered (_(",\n -- loaded at "));
1587 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1588 printf_filtered (_(" in overlay section %s"),
1589 section->the_bfd_section->name);
1596 case LOC_OPTIMIZED_OUT:
1597 printf_filtered (_("optimized out"));
1601 printf_filtered (_("of unknown (botched) type"));
1604 printf_filtered (".\n");
1609 x_command (char *exp, int from_tty)
1611 struct format_data fmt;
1612 struct cleanup *old_chain;
1615 fmt.format = last_format ? last_format : 'x';
1616 fmt.size = last_size;
1620 if (exp && *exp == '/')
1622 const char *tmp = exp + 1;
1624 fmt = decode_format (&tmp, last_format, last_size);
1628 /* If we have an expression, evaluate it and use it as the address. */
1630 if (exp != 0 && *exp != 0)
1632 expression_up expr = parse_expression (exp);
1633 /* Cause expression not to be there any more if this command is
1634 repeated with Newline. But don't clobber a user-defined
1635 command's definition. */
1638 val = evaluate_expression (expr.get ());
1639 if (TYPE_IS_REFERENCE (value_type (val)))
1640 val = coerce_ref (val);
1641 /* In rvalue contexts, such as this, functions are coerced into
1642 pointers to functions. This makes "x/i main" work. */
1643 if (/* last_format == 'i' && */
1644 TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
1645 && VALUE_LVAL (val) == lval_memory)
1646 next_address = value_address (val);
1648 next_address = value_as_address (val);
1650 next_gdbarch = expr->gdbarch;
1654 error_no_arg (_("starting display address"));
1656 do_examine (fmt, next_gdbarch, next_address);
1658 /* If the examine succeeds, we remember its size and format for next
1659 time. Set last_size to 'b' for strings. */
1660 if (fmt.format == 's')
1663 last_size = fmt.size;
1664 last_format = fmt.format;
1666 /* Set a couple of internal variables if appropriate. */
1667 if (last_examine_value)
1669 /* Make last address examined available to the user as $_. Use
1670 the correct pointer type. */
1671 struct type *pointer_type
1672 = lookup_pointer_type (value_type (last_examine_value));
1673 set_internalvar (lookup_internalvar ("_"),
1674 value_from_pointer (pointer_type,
1675 last_examine_address));
1677 /* Make contents of last address examined available to the user
1678 as $__. If the last value has not been fetched from memory
1679 then don't fetch it now; instead mark it by voiding the $__
1681 if (value_lazy (last_examine_value))
1682 clear_internalvar (lookup_internalvar ("__"));
1684 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1689 /* Add an expression to the auto-display chain.
1690 Specify the expression. */
1693 display_command (char *arg, int from_tty)
1695 struct format_data fmt;
1696 struct display *newobj;
1697 const char *exp = arg;
1708 fmt = decode_format (&exp, 0, 0);
1709 if (fmt.size && fmt.format == 0)
1711 if (fmt.format == 'i' || fmt.format == 's')
1722 innermost_block = NULL;
1723 expression_up expr = parse_expression (exp);
1725 newobj = new display ();
1727 newobj->exp_string = xstrdup (exp);
1728 newobj->exp = std::move (expr);
1729 newobj->block = innermost_block;
1730 newobj->pspace = current_program_space;
1731 newobj->number = ++display_number;
1732 newobj->format = fmt;
1733 newobj->enabled_p = 1;
1734 newobj->next = NULL;
1736 if (display_chain == NULL)
1737 display_chain = newobj;
1740 struct display *last;
1742 for (last = display_chain; last->next != NULL; last = last->next)
1744 last->next = newobj;
1748 do_one_display (newobj);
1754 free_display (struct display *d)
1756 xfree (d->exp_string);
1760 /* Clear out the display_chain. Done when new symtabs are loaded,
1761 since this invalidates the types stored in many expressions. */
1764 clear_displays (void)
1768 while ((d = display_chain) != NULL)
1770 display_chain = d->next;
1775 /* Delete the auto-display DISPLAY. */
1778 delete_display (struct display *display)
1782 gdb_assert (display != NULL);
1784 if (display_chain == display)
1785 display_chain = display->next;
1788 if (d->next == display)
1790 d->next = display->next;
1794 free_display (display);
1797 /* Call FUNCTION on each of the displays whose numbers are given in
1798 ARGS. DATA is passed unmodified to FUNCTION. */
1801 map_display_numbers (char *args,
1802 void (*function) (struct display *,
1809 error_no_arg (_("one or more display numbers"));
1811 number_or_range_parser parser (args);
1813 while (!parser.finished ())
1815 const char *p = parser.cur_tok ();
1817 num = parser.get_number ();
1819 warning (_("bad display number at or near '%s'"), p);
1822 struct display *d, *tmp;
1824 ALL_DISPLAYS_SAFE (d, tmp)
1825 if (d->number == num)
1828 printf_unfiltered (_("No display number %d.\n"), num);
1835 /* Callback for map_display_numbers, that deletes a display. */
1838 do_delete_display (struct display *d, void *data)
1843 /* "undisplay" command. */
1846 undisplay_command (char *args, int from_tty)
1850 if (query (_("Delete all auto-display expressions? ")))
1856 map_display_numbers (args, do_delete_display, NULL);
1860 /* Display a single auto-display.
1861 Do nothing if the display cannot be printed in the current context,
1862 or if the display is disabled. */
1865 do_one_display (struct display *d)
1867 int within_current_scope;
1869 if (d->enabled_p == 0)
1872 /* The expression carries the architecture that was used at parse time.
1873 This is a problem if the expression depends on architecture features
1874 (e.g. register numbers), and the current architecture is now different.
1875 For example, a display statement like "display/i $pc" is expected to
1876 display the PC register of the current architecture, not the arch at
1877 the time the display command was given. Therefore, we re-parse the
1878 expression if the current architecture has changed. */
1879 if (d->exp != NULL && d->exp->gdbarch != get_current_arch ())
1890 innermost_block = NULL;
1891 d->exp = parse_expression (d->exp_string);
1892 d->block = innermost_block;
1894 CATCH (ex, RETURN_MASK_ALL)
1896 /* Can't re-parse the expression. Disable this display item. */
1898 warning (_("Unable to display \"%s\": %s"),
1899 d->exp_string, ex.message);
1907 if (d->pspace == current_program_space)
1908 within_current_scope = contained_in (get_selected_block (0), d->block);
1910 within_current_scope = 0;
1913 within_current_scope = 1;
1914 if (!within_current_scope)
1917 scoped_restore save_display_number
1918 = make_scoped_restore (¤t_display_number, d->number);
1920 annotate_display_begin ();
1921 printf_filtered ("%d", d->number);
1922 annotate_display_number_end ();
1923 printf_filtered (": ");
1927 annotate_display_format ();
1929 printf_filtered ("x/");
1930 if (d->format.count != 1)
1931 printf_filtered ("%d", d->format.count);
1932 printf_filtered ("%c", d->format.format);
1933 if (d->format.format != 'i' && d->format.format != 's')
1934 printf_filtered ("%c", d->format.size);
1935 printf_filtered (" ");
1937 annotate_display_expression ();
1939 puts_filtered (d->exp_string);
1940 annotate_display_expression_end ();
1942 if (d->format.count != 1 || d->format.format == 'i')
1943 printf_filtered ("\n");
1945 printf_filtered (" ");
1947 annotate_display_value ();
1954 val = evaluate_expression (d->exp.get ());
1955 addr = value_as_address (val);
1956 if (d->format.format == 'i')
1957 addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr);
1958 do_examine (d->format, d->exp->gdbarch, addr);
1960 CATCH (ex, RETURN_MASK_ERROR)
1962 fprintf_filtered (gdb_stdout, _("<error: %s>\n"), ex.message);
1968 struct value_print_options opts;
1970 annotate_display_format ();
1972 if (d->format.format)
1973 printf_filtered ("/%c ", d->format.format);
1975 annotate_display_expression ();
1977 puts_filtered (d->exp_string);
1978 annotate_display_expression_end ();
1980 printf_filtered (" = ");
1982 annotate_display_expression ();
1984 get_formatted_print_options (&opts, d->format.format);
1985 opts.raw = d->format.raw;
1991 val = evaluate_expression (d->exp.get ());
1992 print_formatted (val, d->format.size, &opts, gdb_stdout);
1994 CATCH (ex, RETURN_MASK_ERROR)
1996 fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
2000 printf_filtered ("\n");
2003 annotate_display_end ();
2005 gdb_flush (gdb_stdout);
2008 /* Display all of the values on the auto-display chain which can be
2009 evaluated in the current scope. */
2016 for (d = display_chain; d; d = d->next)
2020 /* Delete the auto-display which we were in the process of displaying.
2021 This is done when there is an error or a signal. */
2024 disable_display (int num)
2028 for (d = display_chain; d; d = d->next)
2029 if (d->number == num)
2034 printf_unfiltered (_("No display number %d.\n"), num);
2038 disable_current_display (void)
2040 if (current_display_number >= 0)
2042 disable_display (current_display_number);
2043 fprintf_unfiltered (gdb_stderr,
2044 _("Disabling display %d to "
2045 "avoid infinite recursion.\n"),
2046 current_display_number);
2048 current_display_number = -1;
2052 display_info (char *ignore, int from_tty)
2057 printf_unfiltered (_("There are no auto-display expressions now.\n"));
2059 printf_filtered (_("Auto-display expressions now in effect:\n\
2060 Num Enb Expression\n"));
2062 for (d = display_chain; d; d = d->next)
2064 printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]);
2066 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
2068 else if (d->format.format)
2069 printf_filtered ("/%c ", d->format.format);
2070 puts_filtered (d->exp_string);
2071 if (d->block && !contained_in (get_selected_block (0), d->block))
2072 printf_filtered (_(" (cannot be evaluated in the current context)"));
2073 printf_filtered ("\n");
2074 gdb_flush (gdb_stdout);
2078 /* Callback fo map_display_numbers, that enables or disables the
2079 passed in display D. */
2082 do_enable_disable_display (struct display *d, void *data)
2084 d->enabled_p = *(int *) data;
2087 /* Implamentation of both the "disable display" and "enable display"
2088 commands. ENABLE decides what to do. */
2091 enable_disable_display_command (char *args, int from_tty, int enable)
2098 d->enabled_p = enable;
2102 map_display_numbers (args, do_enable_disable_display, &enable);
2105 /* The "enable display" command. */
2108 enable_display_command (char *args, int from_tty)
2110 enable_disable_display_command (args, from_tty, 1);
2113 /* The "disable display" command. */
2116 disable_display_command (char *args, int from_tty)
2118 enable_disable_display_command (args, from_tty, 0);
2121 /* display_chain items point to blocks and expressions. Some expressions in
2122 turn may point to symbols.
2123 Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
2124 obstack_free'd when a shared library is unloaded.
2125 Clear pointers that are about to become dangling.
2126 Both .exp and .block fields will be restored next time we need to display
2127 an item by re-parsing .exp_string field in the new execution context. */
2130 clear_dangling_display_expressions (struct objfile *objfile)
2133 struct program_space *pspace;
2135 /* With no symbol file we cannot have a block or expression from it. */
2136 if (objfile == NULL)
2138 pspace = objfile->pspace;
2139 if (objfile->separate_debug_objfile_backlink)
2141 objfile = objfile->separate_debug_objfile_backlink;
2142 gdb_assert (objfile->pspace == pspace);
2145 for (d = display_chain; d != NULL; d = d->next)
2147 if (d->pspace != pspace)
2150 if (lookup_objfile_from_block (d->block) == objfile
2151 || (d->exp != NULL && exp_uses_objfile (d->exp.get (), objfile)))
2160 /* Print the value in stack frame FRAME of a variable specified by a
2161 struct symbol. NAME is the name to print; if NULL then VAR's print
2162 name will be used. STREAM is the ui_file on which to print the
2163 value. INDENT specifies the number of indent levels to print
2164 before printing the variable name.
2166 This function invalidates FRAME. */
2169 print_variable_and_value (const char *name, struct symbol *var,
2170 struct frame_info *frame,
2171 struct ui_file *stream, int indent)
2175 name = SYMBOL_PRINT_NAME (var);
2177 fprintf_filtered (stream, "%s%s = ", n_spaces (2 * indent), name);
2181 struct value_print_options opts;
2183 /* READ_VAR_VALUE needs a block in order to deal with non-local
2184 references (i.e. to handle nested functions). In this context, we
2185 print variables that are local to this frame, so we can avoid passing
2187 val = read_var_value (var, NULL, frame);
2188 get_user_print_options (&opts);
2190 common_val_print (val, stream, indent, &opts, current_language);
2192 /* common_val_print invalidates FRAME when a pretty printer calls inferior
2196 CATCH (except, RETURN_MASK_ERROR)
2198 fprintf_filtered(stream, "<error reading variable %s (%s)>", name,
2203 fprintf_filtered (stream, "\n");
2206 /* Subroutine of ui_printf to simplify it.
2207 Print VALUE to STREAM using FORMAT.
2208 VALUE is a C-style string on the target. */
2211 printf_c_string (struct ui_file *stream, const char *format,
2212 struct value *value)
2218 tem = value_as_address (value);
2220 /* This is a %s argument. Find the length of the string. */
2226 read_memory (tem + j, &c, 1);
2231 /* Copy the string contents into a string inside GDB. */
2232 str = (gdb_byte *) alloca (j + 1);
2234 read_memory (tem, str, j);
2237 fprintf_filtered (stream, format, (char *) str);
2240 /* Subroutine of ui_printf to simplify it.
2241 Print VALUE to STREAM using FORMAT.
2242 VALUE is a wide C-style string on the target. */
2245 printf_wide_c_string (struct ui_file *stream, const char *format,
2246 struct value *value)
2251 struct gdbarch *gdbarch = get_type_arch (value_type (value));
2252 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2253 struct type *wctype = lookup_typename (current_language, gdbarch,
2254 "wchar_t", NULL, 0);
2255 int wcwidth = TYPE_LENGTH (wctype);
2256 gdb_byte *buf = (gdb_byte *) alloca (wcwidth);
2257 struct obstack output;
2258 struct cleanup *inner_cleanup;
2260 tem = value_as_address (value);
2262 /* This is a %s argument. Find the length of the string. */
2263 for (j = 0;; j += wcwidth)
2266 read_memory (tem + j, buf, wcwidth);
2267 if (extract_unsigned_integer (buf, wcwidth, byte_order) == 0)
2271 /* Copy the string contents into a string inside GDB. */
2272 str = (gdb_byte *) alloca (j + wcwidth);
2274 read_memory (tem, str, j);
2275 memset (&str[j], 0, wcwidth);
2277 obstack_init (&output);
2278 inner_cleanup = make_cleanup_obstack_free (&output);
2280 convert_between_encodings (target_wide_charset (gdbarch),
2283 &output, translit_char);
2284 obstack_grow_str0 (&output, "");
2286 fprintf_filtered (stream, format, obstack_base (&output));
2287 do_cleanups (inner_cleanup);
2290 /* Subroutine of ui_printf to simplify it.
2291 Print VALUE, a decimal floating point value, to STREAM using FORMAT. */
2294 printf_decfloat (struct ui_file *stream, const char *format,
2295 struct value *value)
2297 const gdb_byte *param_ptr = value_contents (value);
2299 #if defined (PRINTF_HAS_DECFLOAT)
2300 /* If we have native support for Decimal floating
2301 printing, handle it here. */
2302 fprintf_filtered (stream, format, param_ptr);
2304 /* As a workaround until vasprintf has native support for DFP
2305 we convert the DFP values to string and print them using
2306 the %s format specifier. */
2309 /* Parameter data. */
2310 struct type *param_type = value_type (value);
2311 struct gdbarch *gdbarch = get_type_arch (param_type);
2312 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2314 /* DFP output data. */
2315 struct value *dfp_value = NULL;
2319 struct type *dfp_type = NULL;
2320 char decstr[MAX_DECIMAL_STRING];
2322 /* Points to the end of the string so that we can go back
2323 and check for DFP length modifiers. */
2324 p = format + strlen (format);
2326 /* Look for the float/double format specifier. */
2327 while (*p != 'f' && *p != 'e' && *p != 'E'
2328 && *p != 'g' && *p != 'G')
2331 /* Search for the '%' char and extract the size and type of
2332 the output decimal value based on its modifiers
2333 (%Hf, %Df, %DDf). */
2339 dfp_type = builtin_type (gdbarch)->builtin_decfloat;
2341 else if (*p == 'D' && *(p - 1) == 'D')
2344 dfp_type = builtin_type (gdbarch)->builtin_declong;
2350 dfp_type = builtin_type (gdbarch)->builtin_decdouble;
2354 /* Conversion between different DFP types. */
2355 if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT)
2356 decimal_convert (param_ptr, TYPE_LENGTH (param_type),
2357 byte_order, dec, dfp_len, byte_order);
2359 /* If this is a non-trivial conversion, just output 0.
2360 A correct converted value can be displayed by explicitly
2361 casting to a DFP type. */
2362 decimal_from_string (dec, dfp_len, byte_order, "0");
2364 dfp_value = value_from_decfloat (dfp_type, dec);
2366 dfp_ptr = (gdb_byte *) value_contents (dfp_value);
2368 decimal_to_string (dfp_ptr, dfp_len, byte_order, decstr);
2370 /* Print the DFP value. */
2371 fprintf_filtered (stream, "%s", decstr);
2375 /* Subroutine of ui_printf to simplify it.
2376 Print VALUE, a target pointer, to STREAM using FORMAT. */
2379 printf_pointer (struct ui_file *stream, const char *format,
2380 struct value *value)
2382 /* We avoid the host's %p because pointers are too
2383 likely to be the wrong size. The only interesting
2384 modifier for %p is a width; extract that, and then
2385 handle %p as glibc would: %#x or a literal "(nil)". */
2389 #ifdef PRINTF_HAS_LONG_LONG
2390 long long val = value_as_long (value);
2392 long val = value_as_long (value);
2395 fmt = (char *) alloca (strlen (format) + 5);
2397 /* Copy up to the leading %. */
2402 int is_percent = (*p == '%');
2417 /* Copy any width. */
2418 while (*p >= '0' && *p < '9')
2421 gdb_assert (*p == 'p' && *(p + 1) == '\0');
2424 #ifdef PRINTF_HAS_LONG_LONG
2430 fprintf_filtered (stream, fmt, val);
2436 fprintf_filtered (stream, fmt, "(nil)");
2440 /* printf "printf format string" ARG to STREAM. */
2443 ui_printf (const char *arg, struct ui_file *stream)
2445 struct format_piece *fpieces;
2446 const char *s = arg;
2447 struct value **val_args;
2448 int allocated_args = 20;
2449 struct cleanup *old_cleanups;
2451 val_args = XNEWVEC (struct value *, allocated_args);
2452 old_cleanups = make_cleanup (free_current_contents, &val_args);
2455 error_no_arg (_("format-control string and values to print"));
2457 s = skip_spaces_const (s);
2459 /* A format string should follow, enveloped in double quotes. */
2461 error (_("Bad format string, missing '\"'."));
2463 fpieces = parse_format_string (&s);
2465 make_cleanup (free_format_pieces_cleanup, &fpieces);
2468 error (_("Bad format string, non-terminated '\"'."));
2470 s = skip_spaces_const (s);
2472 if (*s != ',' && *s != 0)
2473 error (_("Invalid argument syntax"));
2477 s = skip_spaces_const (s);
2483 char *current_substring;
2486 for (fr = 0; fpieces[fr].string != NULL; fr++)
2487 if (fpieces[fr].argclass != literal_piece)
2490 /* Now, parse all arguments and evaluate them.
2491 Store the VALUEs in VAL_ARGS. */
2497 if (nargs == allocated_args)
2498 val_args = (struct value **) xrealloc ((char *) val_args,
2499 (allocated_args *= 2)
2500 * sizeof (struct value *));
2502 val_args[nargs] = parse_to_comma_and_eval (&s1);
2510 if (nargs != nargs_wanted)
2511 error (_("Wrong number of arguments for specified format-string"));
2513 /* Now actually print them. */
2515 for (fr = 0; fpieces[fr].string != NULL; fr++)
2517 current_substring = fpieces[fr].string;
2518 switch (fpieces[fr].argclass)
2521 printf_c_string (stream, current_substring, val_args[i]);
2523 case wide_string_arg:
2524 printf_wide_c_string (stream, current_substring, val_args[i]);
2528 struct gdbarch *gdbarch
2529 = get_type_arch (value_type (val_args[i]));
2530 struct type *wctype = lookup_typename (current_language, gdbarch,
2531 "wchar_t", NULL, 0);
2532 struct type *valtype;
2533 struct obstack output;
2534 struct cleanup *inner_cleanup;
2535 const gdb_byte *bytes;
2537 valtype = value_type (val_args[i]);
2538 if (TYPE_LENGTH (valtype) != TYPE_LENGTH (wctype)
2539 || TYPE_CODE (valtype) != TYPE_CODE_INT)
2540 error (_("expected wchar_t argument for %%lc"));
2542 bytes = value_contents (val_args[i]);
2544 obstack_init (&output);
2545 inner_cleanup = make_cleanup_obstack_free (&output);
2547 convert_between_encodings (target_wide_charset (gdbarch),
2549 bytes, TYPE_LENGTH (valtype),
2550 TYPE_LENGTH (valtype),
2551 &output, translit_char);
2552 obstack_grow_str0 (&output, "");
2554 fprintf_filtered (stream, current_substring,
2555 obstack_base (&output));
2556 do_cleanups (inner_cleanup);
2561 struct type *type = value_type (val_args[i]);
2565 /* If format string wants a float, unchecked-convert the value
2566 to floating point of the same size. */
2567 type = float_type_from_length (type);
2568 val = unpack_double (type, value_contents (val_args[i]), &inv);
2570 error (_("Invalid floating value found in program."));
2572 fprintf_filtered (stream, current_substring, (double) val);
2575 case long_double_arg:
2576 #ifdef HAVE_LONG_DOUBLE
2578 struct type *type = value_type (val_args[i]);
2582 /* If format string wants a float, unchecked-convert the value
2583 to floating point of the same size. */
2584 type = float_type_from_length (type);
2585 val = unpack_double (type, value_contents (val_args[i]), &inv);
2587 error (_("Invalid floating value found in program."));
2589 fprintf_filtered (stream, current_substring,
2594 error (_("long double not supported in printf"));
2597 #ifdef PRINTF_HAS_LONG_LONG
2599 long long val = value_as_long (val_args[i]);
2601 fprintf_filtered (stream, current_substring, val);
2605 error (_("long long not supported in printf"));
2609 int val = value_as_long (val_args[i]);
2611 fprintf_filtered (stream, current_substring, val);
2616 long val = value_as_long (val_args[i]);
2618 fprintf_filtered (stream, current_substring, val);
2621 /* Handles decimal floating values. */
2623 printf_decfloat (stream, current_substring, val_args[i]);
2626 printf_pointer (stream, current_substring, val_args[i]);
2629 /* Print a portion of the format string that has no
2630 directives. Note that this will not include any
2631 ordinary %-specs, but it might include "%%". That is
2632 why we use printf_filtered and not puts_filtered here.
2633 Also, we pass a dummy argument because some platforms
2634 have modified GCC to include -Wformat-security by
2635 default, which will warn here if there is no
2637 fprintf_filtered (stream, current_substring, 0);
2640 internal_error (__FILE__, __LINE__,
2641 _("failed internal consistency check"));
2643 /* Maybe advance to the next argument. */
2644 if (fpieces[fr].argclass != literal_piece)
2648 do_cleanups (old_cleanups);
2651 /* Implement the "printf" command. */
2654 printf_command (char *arg, int from_tty)
2656 ui_printf (arg, gdb_stdout);
2657 gdb_flush (gdb_stdout);
2660 /* Implement the "eval" command. */
2663 eval_command (char *arg, int from_tty)
2667 ui_printf (arg, &stb);
2669 std::string expanded = insert_user_defined_cmd_args (stb.c_str ());
2671 execute_command (&expanded[0], from_tty);
2675 _initialize_printcmd (void)
2677 struct cmd_list_element *c;
2679 current_display_number = -1;
2681 observer_attach_free_objfile (clear_dangling_display_expressions);
2683 add_info ("address", address_info,
2684 _("Describe where symbol SYM is stored."));
2686 add_info ("symbol", sym_info, _("\
2687 Describe what symbol is at location ADDR.\n\
2688 Only for symbols with fixed locations (global or static scope)."));
2690 add_com ("x", class_vars, x_command, _("\
2691 Examine memory: x/FMT ADDRESS.\n\
2692 ADDRESS is an expression for the memory address to examine.\n\
2693 FMT is a repeat count followed by a format letter and a size letter.\n\
2694 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2695 t(binary), f(float), a(address), i(instruction), c(char), s(string)\n\
2696 and z(hex, zero padded on the left).\n\
2697 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2698 The specified number of objects of the specified size are printed\n\
2699 according to the format. If a negative number is specified, memory is\n\
2700 examined backward from the address.\n\n\
2701 Defaults for format and size letters are those previously used.\n\
2702 Default count is 1. Default address is following last thing printed\n\
2703 with this command or \"print\"."));
2706 add_com ("whereis", class_vars, whereis_command,
2707 _("Print line number and file of definition of variable."));
2710 add_info ("display", display_info, _("\
2711 Expressions to display when program stops, with code numbers."));
2713 add_cmd ("undisplay", class_vars, undisplay_command, _("\
2714 Cancel some expressions to be displayed when program stops.\n\
2715 Arguments are the code numbers of the expressions to stop displaying.\n\
2716 No argument means cancel all automatic-display expressions.\n\
2717 \"delete display\" has the same effect as this command.\n\
2718 Do \"info display\" to see current list of code numbers."),
2721 add_com ("display", class_vars, display_command, _("\
2722 Print value of expression EXP each time the program stops.\n\
2723 /FMT may be used before EXP as in the \"print\" command.\n\
2724 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2725 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2726 and examining is done as in the \"x\" command.\n\n\
2727 With no argument, display all currently requested auto-display expressions.\n\
2728 Use \"undisplay\" to cancel display requests previously made."));
2730 add_cmd ("display", class_vars, enable_display_command, _("\
2731 Enable some expressions to be displayed when program stops.\n\
2732 Arguments are the code numbers of the expressions to resume displaying.\n\
2733 No argument means enable all automatic-display expressions.\n\
2734 Do \"info display\" to see current list of code numbers."), &enablelist);
2736 add_cmd ("display", class_vars, disable_display_command, _("\
2737 Disable some expressions to be displayed when program stops.\n\
2738 Arguments are the code numbers of the expressions to stop displaying.\n\
2739 No argument means disable all automatic-display expressions.\n\
2740 Do \"info display\" to see current list of code numbers."), &disablelist);
2742 add_cmd ("display", class_vars, undisplay_command, _("\
2743 Cancel some expressions to be displayed when program stops.\n\
2744 Arguments are the code numbers of the expressions to stop displaying.\n\
2745 No argument means cancel all automatic-display expressions.\n\
2746 Do \"info display\" to see current list of code numbers."), &deletelist);
2748 add_com ("printf", class_vars, printf_command, _("\
2749 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2750 This is useful for formatted output in user-defined commands."));
2752 add_com ("output", class_vars, output_command, _("\
2753 Like \"print\" but don't put in value history and don't print newline.\n\
2754 This is useful in user-defined commands."));
2756 add_prefix_cmd ("set", class_vars, set_command, _("\
2757 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2758 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2759 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2760 with $), a register (a few standard names starting with $), or an actual\n\
2761 variable in the program being debugged. EXP is any valid expression.\n\
2762 Use \"set variable\" for variables with names identical to set subcommands.\n\
2764 With a subcommand, this command modifies parts of the gdb environment.\n\
2765 You can see these environment settings with the \"show\" command."),
2766 &setlist, "set ", 1, &cmdlist);
2768 add_com ("assign", class_vars, set_command, _("\
2769 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2770 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2771 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2772 with $), a register (a few standard names starting with $), or an actual\n\
2773 variable in the program being debugged. EXP is any valid expression.\n\
2774 Use \"set variable\" for variables with names identical to set subcommands.\n\
2775 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2776 You can see these environment settings with the \"show\" command."));
2778 /* "call" is the same as "set", but handy for dbx users to call fns. */
2779 c = add_com ("call", class_vars, call_command, _("\
2780 Call a function in the program.\n\
2781 The argument is the function name and arguments, in the notation of the\n\
2782 current working language. The result is printed and saved in the value\n\
2783 history, if it is not void."));
2784 set_cmd_completer (c, expression_completer);
2786 add_cmd ("variable", class_vars, set_command, _("\
2787 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2788 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2789 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2790 with $), a register (a few standard names starting with $), or an actual\n\
2791 variable in the program being debugged. EXP is any valid expression.\n\
2792 This may usually be abbreviated to simply \"set\"."),
2795 c = add_com ("print", class_vars, print_command, _("\
2796 Print value of expression EXP.\n\
2797 Variables accessible are those of the lexical environment of the selected\n\
2798 stack frame, plus all those whose scope is global or an entire file.\n\
2800 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2801 $$NUM refers to NUM'th value back from the last one.\n\
2802 Names starting with $ refer to registers (with the values they would have\n\
2803 if the program were to return to the stack frame now selected, restoring\n\
2804 all registers saved by frames farther in) or else to debugger\n\
2805 \"convenience\" variables (any such name not a known register).\n\
2806 Use assignment expressions to give values to convenience variables.\n\
2808 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2809 @ is a binary operator for treating consecutive data objects\n\
2810 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2811 element is FOO, whose second element is stored in the space following\n\
2812 where FOO is stored, etc. FOO must be an expression whose value\n\
2813 resides in memory.\n\
2815 EXP may be preceded with /FMT, where FMT is a format letter\n\
2816 but no count or size letter (see \"x\" command)."));
2817 set_cmd_completer (c, expression_completer);
2818 add_com_alias ("p", "print", class_vars, 1);
2819 add_com_alias ("inspect", "print", class_vars, 1);
2821 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
2822 &max_symbolic_offset, _("\
2823 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2824 Show the largest offset that will be printed in <symbol+1234> form."), _("\
2825 Tell GDB to only display the symbolic form of an address if the\n\
2826 offset between the closest earlier symbol and the address is less than\n\
2827 the specified maximum offset. The default is \"unlimited\", which tells GDB\n\
2828 to always print the symbolic form of an address if any symbol precedes\n\
2829 it. Zero is equivalent to \"unlimited\"."),
2831 show_max_symbolic_offset,
2832 &setprintlist, &showprintlist);
2833 add_setshow_boolean_cmd ("symbol-filename", no_class,
2834 &print_symbol_filename, _("\
2835 Set printing of source filename and line number with <symbol>."), _("\
2836 Show printing of source filename and line number with <symbol>."), NULL,
2838 show_print_symbol_filename,
2839 &setprintlist, &showprintlist);
2841 add_com ("eval", no_class, eval_command, _("\
2842 Convert \"printf format string\", arg1, arg2, arg3, ..., argn to\n\
2843 a command line, and call it."));