1 /* Print values for GNU debugger GDB.
3 Copyright (C) 1986-2016 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"
52 #include "tui/tui.h" /* For tui_active et al. */
55 /* Last specified output format. */
57 static char last_format = 0;
59 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
61 static char last_size = 'w';
63 /* Default address to examine next, and associated architecture. */
65 static struct gdbarch *next_gdbarch;
66 static CORE_ADDR next_address;
68 /* Number of delay instructions following current disassembled insn. */
70 static int branch_delay_insns;
72 /* Last address examined. */
74 static CORE_ADDR last_examine_address;
76 /* Contents of last address examined.
77 This is not valid past the end of the `x' command! */
79 static struct value *last_examine_value;
81 /* Largest offset between a symbolic value and an address, that will be
82 printed as `0x1234 <symbol+offset>'. */
84 static unsigned int max_symbolic_offset = UINT_MAX;
86 show_max_symbolic_offset (struct ui_file *file, int from_tty,
87 struct cmd_list_element *c, const char *value)
89 fprintf_filtered (file,
90 _("The largest offset that will be "
91 "printed in <symbol+1234> form is %s.\n"),
95 /* Append the source filename and linenumber of the symbol when
96 printing a symbolic value as `<symbol at filename:linenum>' if set. */
97 static int print_symbol_filename = 0;
99 show_print_symbol_filename (struct ui_file *file, int from_tty,
100 struct cmd_list_element *c, const char *value)
102 fprintf_filtered (file, _("Printing of source filename and "
103 "line number with <symbol> is %s.\n"),
107 /* Number of auto-display expression currently being displayed.
108 So that we can disable it if we get a signal within it.
109 -1 when not doing one. */
111 static int current_display_number;
115 /* Chain link to next auto-display item. */
116 struct display *next;
118 /* The expression as the user typed it. */
121 /* Expression to be evaluated and displayed. */
124 /* Item number of this auto-display item. */
127 /* Display format specified. */
128 struct format_data format;
130 /* Program space associated with `block'. */
131 struct program_space *pspace;
133 /* Innermost block required by this expression when evaluated. */
134 const struct block *block;
136 /* Status of this display (enabled or disabled). */
140 /* Chain of expressions whose values should be displayed
141 automatically each time the program stops. */
143 static struct display *display_chain;
145 static int display_number;
147 /* Walk the following statement or block through all displays.
148 ALL_DISPLAYS_SAFE does so even if the statement deletes the current
151 #define ALL_DISPLAYS(B) \
152 for (B = display_chain; B; B = B->next)
154 #define ALL_DISPLAYS_SAFE(B,TMP) \
155 for (B = display_chain; \
156 B ? (TMP = B->next, 1): 0; \
159 /* Prototypes for exported functions. */
161 void _initialize_printcmd (void);
163 /* Prototypes for local functions. */
165 static void do_one_display (struct display *);
168 /* Decode a format specification. *STRING_PTR should point to it.
169 OFORMAT and OSIZE are used as defaults for the format and size
170 if none are given in the format specification.
171 If OSIZE is zero, then the size field of the returned value
172 should be set only if a size is explicitly specified by the
174 The structure returned describes all the data
175 found in the specification. In addition, *STRING_PTR is advanced
176 past the specification and past all whitespace following it. */
178 static struct format_data
179 decode_format (const char **string_ptr, int oformat, int osize)
181 struct format_data val;
182 const char *p = *string_ptr;
194 if (*p >= '0' && *p <= '9')
195 val.count *= atoi (p);
196 while (*p >= '0' && *p <= '9')
199 /* Now process size or format letters that follow. */
203 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
210 else if (*p >= 'a' && *p <= 'z')
216 while (*p == ' ' || *p == '\t')
220 /* Set defaults for format and size if not specified. */
221 if (val.format == '?')
225 /* Neither has been specified. */
226 val.format = oformat;
230 /* If a size is specified, any format makes a reasonable
231 default except 'i'. */
232 val.format = oformat == 'i' ? 'x' : oformat;
234 else if (val.size == '?')
238 /* Pick the appropriate size for an address. This is deferred
239 until do_examine when we know the actual architecture to use.
240 A special size value of 'a' is used to indicate this case. */
241 val.size = osize ? 'a' : osize;
244 /* Floating point has to be word or giantword. */
245 if (osize == 'w' || osize == 'g')
248 /* Default it to giantword if the last used size is not
250 val.size = osize ? 'g' : osize;
253 /* Characters default to one byte. */
254 val.size = osize ? 'b' : osize;
257 /* Display strings with byte size chars unless explicitly
263 /* The default is the size most recently specified. */
270 /* Print value VAL on stream according to OPTIONS.
271 Do not end with a newline.
272 SIZE is the letter for the size of datum being printed.
273 This is used to pad hex numbers so they line up. SIZE is 0
274 for print / output and set for examine. */
277 print_formatted (struct value *val, int size,
278 const struct value_print_options *options,
279 struct ui_file *stream)
281 struct type *type = check_typedef (value_type (val));
282 int len = TYPE_LENGTH (type);
284 if (VALUE_LVAL (val) == lval_memory)
285 next_address = value_address (val) + len;
289 switch (options->format)
293 struct type *elttype = value_type (val);
295 next_address = (value_address (val)
296 + val_print_string (elttype, NULL,
297 value_address (val), -1,
298 stream, options) * len);
303 /* We often wrap here if there are long symbolic names. */
305 next_address = (value_address (val)
306 + gdb_print_insn (get_type_arch (type),
307 value_address (val), stream,
308 &branch_delay_insns));
313 if (options->format == 0 || options->format == 's'
314 || TYPE_CODE (type) == TYPE_CODE_REF
315 || TYPE_CODE (type) == TYPE_CODE_ARRAY
316 || TYPE_CODE (type) == TYPE_CODE_STRING
317 || TYPE_CODE (type) == TYPE_CODE_STRUCT
318 || TYPE_CODE (type) == TYPE_CODE_UNION
319 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
320 value_print (val, stream, options);
322 /* User specified format, so don't look to the type to tell us
324 val_print_scalar_formatted (type,
325 value_embedded_offset (val),
327 options, size, stream);
330 /* Return builtin floating point type of same length as TYPE.
331 If no such type is found, return TYPE itself. */
333 float_type_from_length (struct type *type)
335 struct gdbarch *gdbarch = get_type_arch (type);
336 const struct builtin_type *builtin = builtin_type (gdbarch);
338 if (TYPE_LENGTH (type) == TYPE_LENGTH (builtin->builtin_float))
339 type = builtin->builtin_float;
340 else if (TYPE_LENGTH (type) == TYPE_LENGTH (builtin->builtin_double))
341 type = builtin->builtin_double;
342 else if (TYPE_LENGTH (type) == TYPE_LENGTH (builtin->builtin_long_double))
343 type = builtin->builtin_long_double;
348 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
349 according to OPTIONS and SIZE on STREAM. Formats s and i are not
350 supported at this level. */
353 print_scalar_formatted (const gdb_byte *valaddr, struct type *type,
354 const struct value_print_options *options,
355 int size, struct ui_file *stream)
357 struct gdbarch *gdbarch = get_type_arch (type);
358 LONGEST val_long = 0;
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 (len > sizeof(LONGEST)
366 && (TYPE_CODE (type) == TYPE_CODE_INT
367 || TYPE_CODE (type) == TYPE_CODE_ENUM))
369 switch (options->format)
372 print_octal_chars (stream, valaddr, len, byte_order);
376 print_decimal_chars (stream, valaddr, len, byte_order);
379 print_binary_chars (stream, valaddr, len, byte_order);
382 print_hex_chars (stream, valaddr, len, byte_order);
385 print_char_chars (stream, type, valaddr, len, byte_order);
392 if (options->format != 'f')
393 val_long = unpack_long (type, valaddr);
395 /* If the value is a pointer, and pointers and addresses are not the
396 same, then at this point, the value's length (in target bytes) is
397 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
398 if (TYPE_CODE (type) == TYPE_CODE_PTR)
399 len = gdbarch_addr_bit (gdbarch) / TARGET_CHAR_BIT;
401 /* If we are printing it as unsigned, truncate it in case it is actually
402 a negative signed value (e.g. "print/u (short)-1" should print 65535
403 (if shorts are 16 bits) instead of 4294967295). */
404 if (options->format != 'd' || TYPE_UNSIGNED (type))
406 if (len < sizeof (LONGEST))
407 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
410 switch (options->format)
415 /* No size specified, like in print. Print varying # of digits. */
416 print_longest (stream, 'x', 1, val_long);
425 print_longest (stream, size, 1, val_long);
428 error (_("Undefined output size \"%c\"."), size);
433 print_longest (stream, 'd', 1, val_long);
437 print_longest (stream, 'u', 0, val_long);
442 print_longest (stream, 'o', 1, val_long);
444 fprintf_filtered (stream, "0");
449 CORE_ADDR addr = unpack_pointer (type, valaddr);
451 print_address (gdbarch, addr, stream);
457 struct value_print_options opts = *options;
460 if (TYPE_UNSIGNED (type))
461 type = builtin_type (gdbarch)->builtin_true_unsigned_char;
463 type = builtin_type (gdbarch)->builtin_true_char;
465 value_print (value_from_longest (type, val_long), stream, &opts);
470 type = float_type_from_length (type);
471 print_floating (valaddr, type, stream);
475 internal_error (__FILE__, __LINE__,
476 _("failed internal consistency check"));
479 /* Binary; 't' stands for "two". */
481 char bits[8 * (sizeof val_long) + 1];
482 char buf[8 * (sizeof val_long) + 32];
487 width = 8 * (sizeof val_long);
504 error (_("Undefined output size \"%c\"."), size);
510 bits[width] = (val_long & 1) ? '1' : '0';
515 while (*cp && *cp == '0')
520 strncpy (buf, cp, sizeof (bits));
521 fputs_filtered (buf, stream);
526 print_hex_chars (stream, valaddr, len, byte_order);
530 error (_("Undefined output format \"%c\"."), options->format);
534 /* Specify default address for `x' command.
535 The `info lines' command uses this. */
538 set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr)
540 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
542 next_gdbarch = gdbarch;
545 /* Make address available to the user as $_. */
546 set_internalvar (lookup_internalvar ("_"),
547 value_from_pointer (ptr_type, addr));
550 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
551 after LEADIN. Print nothing if no symbolic name is found nearby.
552 Optionally also print source file and line number, if available.
553 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
554 or to interpret it as a possible C++ name and convert it back to source
555 form. However note that DO_DEMANGLE can be overridden by the specific
556 settings of the demangle and asm_demangle variables. Returns
557 non-zero if anything was printed; zero otherwise. */
560 print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
561 struct ui_file *stream,
562 int do_demangle, char *leadin)
565 char *filename = NULL;
570 /* Throw away both name and filename. */
571 struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
572 make_cleanup (free_current_contents, &filename);
574 if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &offset,
575 &filename, &line, &unmapped))
577 do_cleanups (cleanup_chain);
581 fputs_filtered (leadin, stream);
583 fputs_filtered ("<*", stream);
585 fputs_filtered ("<", stream);
586 fputs_filtered (name, stream);
588 fprintf_filtered (stream, "+%u", (unsigned int) offset);
590 /* Append source filename and line number if desired. Give specific
591 line # of this addr, if we have it; else line # of the nearest symbol. */
592 if (print_symbol_filename && filename != NULL)
595 fprintf_filtered (stream, " at %s:%d", filename, line);
597 fprintf_filtered (stream, " in %s", filename);
600 fputs_filtered ("*>", stream);
602 fputs_filtered (">", stream);
604 do_cleanups (cleanup_chain);
608 /* Given an address ADDR return all the elements needed to print the
609 address in a symbolic form. NAME can be mangled or not depending
610 on DO_DEMANGLE (and also on the asm_demangle global variable,
611 manipulated via ''set print asm-demangle''). Return 0 in case of
612 success, when all the info in the OUT paramters is valid. Return 1
615 build_address_symbolic (struct gdbarch *gdbarch,
616 CORE_ADDR addr, /* IN */
617 int do_demangle, /* IN */
618 char **name, /* OUT */
619 int *offset, /* OUT */
620 char **filename, /* OUT */
622 int *unmapped) /* OUT */
624 struct bound_minimal_symbol msymbol;
625 struct symbol *symbol;
626 CORE_ADDR name_location = 0;
627 struct obj_section *section = NULL;
628 const char *name_temp = "";
630 /* Let's say it is mapped (not unmapped). */
633 /* Determine if the address is in an overlay, and whether it is
635 if (overlay_debugging)
637 section = find_pc_overlay (addr);
638 if (pc_in_unmapped_range (addr, section))
641 addr = overlay_mapped_address (addr, section);
645 /* First try to find the address in the symbol table, then
646 in the minsyms. Take the closest one. */
648 /* This is defective in the sense that it only finds text symbols. So
649 really this is kind of pointless--we should make sure that the
650 minimal symbols have everything we need (by changing that we could
651 save some memory, but for many debug format--ELF/DWARF or
652 anything/stabs--it would be inconvenient to eliminate those minimal
654 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
655 symbol = find_pc_sect_function (addr, section);
659 /* If this is a function (i.e. a code address), strip out any
660 non-address bits. For instance, display a pointer to the
661 first instruction of a Thumb function as <function>; the
662 second instruction will be <function+2>, even though the
663 pointer is <function+3>. This matches the ISA behavior. */
664 addr = gdbarch_addr_bits_remove (gdbarch, addr);
666 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
667 if (do_demangle || asm_demangle)
668 name_temp = SYMBOL_PRINT_NAME (symbol);
670 name_temp = SYMBOL_LINKAGE_NAME (symbol);
673 if (msymbol.minsym != NULL
674 && MSYMBOL_HAS_SIZE (msymbol.minsym)
675 && MSYMBOL_SIZE (msymbol.minsym) == 0
676 && MSYMBOL_TYPE (msymbol.minsym) != mst_text
677 && MSYMBOL_TYPE (msymbol.minsym) != mst_text_gnu_ifunc
678 && MSYMBOL_TYPE (msymbol.minsym) != mst_file_text)
679 msymbol.minsym = NULL;
681 if (msymbol.minsym != NULL)
683 if (BMSYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
685 /* If this is a function (i.e. a code address), strip out any
686 non-address bits. For instance, display a pointer to the
687 first instruction of a Thumb function as <function>; the
688 second instruction will be <function+2>, even though the
689 pointer is <function+3>. This matches the ISA behavior. */
690 if (MSYMBOL_TYPE (msymbol.minsym) == mst_text
691 || MSYMBOL_TYPE (msymbol.minsym) == mst_text_gnu_ifunc
692 || MSYMBOL_TYPE (msymbol.minsym) == mst_file_text
693 || MSYMBOL_TYPE (msymbol.minsym) == mst_solib_trampoline)
694 addr = gdbarch_addr_bits_remove (gdbarch, addr);
696 /* The msymbol is closer to the address than the symbol;
697 use the msymbol instead. */
699 name_location = BMSYMBOL_VALUE_ADDRESS (msymbol);
700 if (do_demangle || asm_demangle)
701 name_temp = MSYMBOL_PRINT_NAME (msymbol.minsym);
703 name_temp = MSYMBOL_LINKAGE_NAME (msymbol.minsym);
706 if (symbol == NULL && msymbol.minsym == NULL)
709 /* If the nearest symbol is too far away, don't print anything symbolic. */
711 /* For when CORE_ADDR is larger than unsigned int, we do math in
712 CORE_ADDR. But when we detect unsigned wraparound in the
713 CORE_ADDR math, we ignore this test and print the offset,
714 because addr+max_symbolic_offset has wrapped through the end
715 of the address space back to the beginning, giving bogus comparison. */
716 if (addr > name_location + max_symbolic_offset
717 && name_location + max_symbolic_offset > name_location)
720 *offset = addr - name_location;
722 *name = xstrdup (name_temp);
724 if (print_symbol_filename)
726 struct symtab_and_line sal;
728 sal = find_pc_sect_line (addr, section, 0);
732 *filename = xstrdup (symtab_to_filename_for_display (sal.symtab));
740 /* Print address ADDR symbolically on STREAM.
741 First print it as a number. Then perhaps print
742 <SYMBOL + OFFSET> after the number. */
745 print_address (struct gdbarch *gdbarch,
746 CORE_ADDR addr, struct ui_file *stream)
748 fputs_filtered (paddress (gdbarch, addr), stream);
749 print_address_symbolic (gdbarch, addr, stream, asm_demangle, " ");
752 /* Return a prefix for instruction address:
753 "=> " for current instruction, else " ". */
756 pc_prefix (CORE_ADDR addr)
758 if (has_stack_frames ())
760 struct frame_info *frame;
763 frame = get_selected_frame (NULL);
764 if (get_frame_pc_if_available (frame, &pc) && pc == addr)
770 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
771 controls whether to print the symbolic name "raw" or demangled.
772 Return non-zero if anything was printed; zero otherwise. */
775 print_address_demangle (const struct value_print_options *opts,
776 struct gdbarch *gdbarch, CORE_ADDR addr,
777 struct ui_file *stream, int do_demangle)
779 if (opts->addressprint)
781 fputs_filtered (paddress (gdbarch, addr), stream);
782 print_address_symbolic (gdbarch, addr, stream, do_demangle, " ");
786 return print_address_symbolic (gdbarch, addr, stream, do_demangle, "");
792 /* Find the address of the instruction that is INST_COUNT instructions before
793 the instruction at ADDR.
794 Since some architectures have variable-length instructions, we can't just
795 simply subtract INST_COUNT * INSN_LEN from ADDR. Instead, we use line
796 number information to locate the nearest known instruction boundary,
797 and disassemble forward from there. If we go out of the symbol range
798 during disassembling, we return the lowest address we've got so far and
799 set the number of instructions read to INST_READ. */
802 find_instruction_backward (struct gdbarch *gdbarch, CORE_ADDR addr,
803 int inst_count, int *inst_read)
805 /* The vector PCS is used to store instruction addresses within
807 CORE_ADDR loop_start, loop_end, p;
808 VEC (CORE_ADDR) *pcs = NULL;
809 struct symtab_and_line sal;
810 struct cleanup *cleanup = make_cleanup (VEC_cleanup (CORE_ADDR), &pcs);
813 loop_start = loop_end = addr;
815 /* In each iteration of the outer loop, we get a pc range that ends before
816 LOOP_START, then we count and store every instruction address of the range
817 iterated in the loop.
818 If the number of instructions counted reaches INST_COUNT, return the
819 stored address that is located INST_COUNT instructions back from ADDR.
820 If INST_COUNT is not reached, we subtract the number of counted
821 instructions from INST_COUNT, and go to the next iteration. */
824 VEC_truncate (CORE_ADDR, pcs, 0);
825 sal = find_pc_sect_line (loop_start, NULL, 1);
828 /* We reach here when line info is not available. In this case,
829 we print a message and just exit the loop. The return value
830 is calculated after the loop. */
831 printf_filtered (_("No line number information available "
834 print_address (gdbarch, loop_start - 1, gdb_stdout);
835 printf_filtered ("\n");
839 loop_end = loop_start;
842 /* This loop pushes instruction addresses in the range from
843 LOOP_START to LOOP_END. */
844 for (p = loop_start; p < loop_end;)
846 VEC_safe_push (CORE_ADDR, pcs, p);
847 p += gdb_insn_length (gdbarch, p);
850 inst_count -= VEC_length (CORE_ADDR, pcs);
851 *inst_read += VEC_length (CORE_ADDR, pcs);
853 while (inst_count > 0);
855 /* After the loop, the vector PCS has instruction addresses of the last
856 source line we processed, and INST_COUNT has a negative value.
857 We return the address at the index of -INST_COUNT in the vector for
859 Let's assume the following instruction addresses and run 'x/-4i 0x400e'.
869 find_instruction_backward is called with INST_COUNT = 4 and expected to
870 return 0x4001. When we reach here, INST_COUNT is set to -1 because
871 it was subtracted by 2 (from Line Y) and 3 (from Line X). The value
872 4001 is located at the index 1 of the last iterated line (= Line X),
873 which is simply calculated by -INST_COUNT.
874 The case when the length of PCS is 0 means that we reached an area for
875 which line info is not available. In such case, we return LOOP_START,
876 which was the lowest instruction address that had line info. */
877 p = VEC_length (CORE_ADDR, pcs) > 0
878 ? VEC_index (CORE_ADDR, pcs, -inst_count)
881 /* INST_READ includes all instruction addresses in a pc range. Need to
882 exclude the beginning part up to the address we're returning. That
883 is, exclude {0x4000} in the example above. */
885 *inst_read += inst_count;
887 do_cleanups (cleanup);
891 /* Backward read LEN bytes of target memory from address MEMADDR + LEN,
892 placing the results in GDB's memory from MYADDR + LEN. Returns
893 a count of the bytes actually read. */
896 read_memory_backward (struct gdbarch *gdbarch,
897 CORE_ADDR memaddr, gdb_byte *myaddr, int len)
900 int nread; /* Number of bytes actually read. */
902 /* First try a complete read. */
903 errcode = target_read_memory (memaddr, myaddr, len);
911 /* Loop, reading one byte at a time until we get as much as we can. */
914 for (nread = 0; nread < len; ++nread)
916 errcode = target_read_memory (--memaddr, --myaddr, 1);
919 /* The read was unsuccessful, so exit the loop. */
920 printf_filtered (_("Cannot access memory at address %s\n"),
921 paddress (gdbarch, memaddr));
929 /* Returns true if X (which is LEN bytes wide) is the number zero. */
932 integer_is_zero (const gdb_byte *x, int len)
936 while (i < len && x[i] == 0)
941 /* Find the start address of a string in which ADDR is included.
942 Basically we search for '\0' and return the next address,
943 but if OPTIONS->PRINT_MAX is smaller than the length of a string,
944 we stop searching and return the address to print characters as many as
945 PRINT_MAX from the string. */
948 find_string_backward (struct gdbarch *gdbarch,
949 CORE_ADDR addr, int count, int char_size,
950 const struct value_print_options *options,
951 int *strings_counted)
953 const int chunk_size = 0x20;
954 gdb_byte *buffer = NULL;
955 struct cleanup *cleanup = NULL;
958 int chars_to_read = chunk_size;
959 int chars_counted = 0;
960 int count_original = count;
961 CORE_ADDR string_start_addr = addr;
963 gdb_assert (char_size == 1 || char_size == 2 || char_size == 4);
964 buffer = (gdb_byte *) xmalloc (chars_to_read * char_size);
965 cleanup = make_cleanup (xfree, buffer);
966 while (count > 0 && read_error == 0)
970 addr -= chars_to_read * char_size;
971 chars_read = read_memory_backward (gdbarch, addr, buffer,
972 chars_to_read * char_size);
973 chars_read /= char_size;
974 read_error = (chars_read == chars_to_read) ? 0 : 1;
975 /* Searching for '\0' from the end of buffer in backward direction. */
976 for (i = 0; i < chars_read && count > 0 ; ++i, ++chars_counted)
978 int offset = (chars_to_read - i - 1) * char_size;
980 if (integer_is_zero (buffer + offset, char_size)
981 || chars_counted == options->print_max)
983 /* Found '\0' or reached print_max. As OFFSET is the offset to
984 '\0', we add CHAR_SIZE to return the start address of
987 string_start_addr = addr + offset + char_size;
993 /* Update STRINGS_COUNTED with the actual number of loaded strings. */
994 *strings_counted = count_original - count;
998 /* In error case, STRING_START_ADDR is pointing to the string that
999 was last successfully loaded. Rewind the partially loaded string. */
1000 string_start_addr -= chars_counted * char_size;
1003 do_cleanups (cleanup);
1004 return string_start_addr;
1007 /* Examine data at address ADDR in format FMT.
1008 Fetch it from memory and print on gdb_stdout. */
1011 do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr)
1016 struct type *val_type = NULL;
1019 struct value_print_options opts;
1020 int need_to_update_next_address = 0;
1021 CORE_ADDR addr_rewound = 0;
1023 format = fmt.format;
1026 next_gdbarch = gdbarch;
1027 next_address = addr;
1029 /* Instruction format implies fetch single bytes
1030 regardless of the specified size.
1031 The case of strings is handled in decode_format, only explicit
1032 size operator are not changed to 'b'. */
1038 /* Pick the appropriate size for an address. */
1039 if (gdbarch_ptr_bit (next_gdbarch) == 64)
1041 else if (gdbarch_ptr_bit (next_gdbarch) == 32)
1043 else if (gdbarch_ptr_bit (next_gdbarch) == 16)
1046 /* Bad value for gdbarch_ptr_bit. */
1047 internal_error (__FILE__, __LINE__,
1048 _("failed internal consistency check"));
1052 val_type = builtin_type (next_gdbarch)->builtin_int8;
1053 else if (size == 'h')
1054 val_type = builtin_type (next_gdbarch)->builtin_int16;
1055 else if (size == 'w')
1056 val_type = builtin_type (next_gdbarch)->builtin_int32;
1057 else if (size == 'g')
1058 val_type = builtin_type (next_gdbarch)->builtin_int64;
1062 struct type *char_type = NULL;
1064 /* Search for "char16_t" or "char32_t" types or fall back to 8-bit char
1065 if type is not found. */
1067 char_type = builtin_type (next_gdbarch)->builtin_char16;
1068 else if (size == 'w')
1069 char_type = builtin_type (next_gdbarch)->builtin_char32;
1071 val_type = char_type;
1074 if (size != '\0' && size != 'b')
1075 warning (_("Unable to display strings with "
1076 "size '%c', using 'b' instead."), size);
1078 val_type = builtin_type (next_gdbarch)->builtin_int8;
1087 if (format == 's' || format == 'i')
1090 get_formatted_print_options (&opts, format);
1094 /* This is the negative repeat count case.
1095 We rewind the address based on the given repeat count and format,
1096 then examine memory from there in forward direction. */
1101 next_address = find_instruction_backward (gdbarch, addr, count,
1104 else if (format == 's')
1106 next_address = find_string_backward (gdbarch, addr, count,
1107 TYPE_LENGTH (val_type),
1112 next_address = addr - count * TYPE_LENGTH (val_type);
1115 /* The following call to print_formatted updates next_address in every
1116 iteration. In backward case, we store the start address here
1117 and update next_address with it before exiting the function. */
1118 addr_rewound = (format == 's'
1119 ? next_address - TYPE_LENGTH (val_type)
1121 need_to_update_next_address = 1;
1124 /* Print as many objects as specified in COUNT, at most maxelts per line,
1125 with the address of the next one at the start of each line. */
1131 fputs_filtered (pc_prefix (next_address), gdb_stdout);
1132 print_address (next_gdbarch, next_address, gdb_stdout);
1133 printf_filtered (":");
1138 printf_filtered ("\t");
1139 /* Note that print_formatted sets next_address for the next
1141 last_examine_address = next_address;
1143 if (last_examine_value)
1144 value_free (last_examine_value);
1146 /* The value to be displayed is not fetched greedily.
1147 Instead, to avoid the possibility of a fetched value not
1148 being used, its retrieval is delayed until the print code
1149 uses it. When examining an instruction stream, the
1150 disassembler will perform its own memory fetch using just
1151 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
1152 the disassembler be modified so that LAST_EXAMINE_VALUE
1153 is left with the byte sequence from the last complete
1154 instruction fetched from memory? */
1155 last_examine_value = value_at_lazy (val_type, next_address);
1157 if (last_examine_value)
1158 release_value (last_examine_value);
1160 print_formatted (last_examine_value, size, &opts, gdb_stdout);
1162 /* Display any branch delay slots following the final insn. */
1163 if (format == 'i' && count == 1)
1164 count += branch_delay_insns;
1166 printf_filtered ("\n");
1167 gdb_flush (gdb_stdout);
1170 if (need_to_update_next_address)
1171 next_address = addr_rewound;
1175 validate_format (struct format_data fmt, const char *cmdname)
1178 error (_("Size letters are meaningless in \"%s\" command."), cmdname);
1180 error (_("Item count other than 1 is meaningless in \"%s\" command."),
1182 if (fmt.format == 'i')
1183 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
1184 fmt.format, cmdname);
1187 /* Parse print command format string into *FMTP and update *EXPP.
1188 CMDNAME should name the current command. */
1191 print_command_parse_format (const char **expp, const char *cmdname,
1192 struct format_data *fmtp)
1194 const char *exp = *expp;
1196 if (exp && *exp == '/')
1199 *fmtp = decode_format (&exp, last_format, 0);
1200 validate_format (*fmtp, cmdname);
1201 last_format = fmtp->format;
1214 /* Print VAL to console according to *FMTP, including recording it to
1218 print_value (struct value *val, const struct format_data *fmtp)
1220 struct value_print_options opts;
1221 int histindex = record_latest_value (val);
1223 annotate_value_history_begin (histindex, value_type (val));
1225 printf_filtered ("$%d = ", histindex);
1227 annotate_value_history_value ();
1229 get_formatted_print_options (&opts, fmtp->format);
1230 opts.raw = fmtp->raw;
1232 print_formatted (val, fmtp->size, &opts, gdb_stdout);
1233 printf_filtered ("\n");
1235 annotate_value_history_end ();
1238 /* Evaluate string EXP as an expression in the current language and
1239 print the resulting value. EXP may contain a format specifier as the
1240 first argument ("/x myvar" for example, to print myvar in hex). */
1243 print_command_1 (const char *exp, int voidprint)
1246 struct format_data fmt;
1248 print_command_parse_format (&exp, "print", &fmt);
1252 expression_up expr = parse_expression (exp);
1253 val = evaluate_expression (expr.get ());
1256 val = access_value_history (0);
1258 if (voidprint || (val && value_type (val) &&
1259 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
1260 print_value (val, &fmt);
1264 print_command (char *exp, int from_tty)
1266 print_command_1 (exp, 1);
1269 /* Same as print, except it doesn't print void results. */
1271 call_command (char *exp, int from_tty)
1273 print_command_1 (exp, 0);
1276 /* Implementation of the "output" command. */
1279 output_command (char *exp, int from_tty)
1281 output_command_const (exp, from_tty);
1284 /* Like output_command, but takes a const string as argument. */
1287 output_command_const (const char *exp, int from_tty)
1291 struct format_data fmt;
1292 struct value_print_options opts;
1297 if (exp && *exp == '/')
1300 fmt = decode_format (&exp, 0, 0);
1301 validate_format (fmt, "output");
1302 format = fmt.format;
1305 expression_up expr = parse_expression (exp);
1307 val = evaluate_expression (expr.get ());
1309 annotate_value_begin (value_type (val));
1311 get_formatted_print_options (&opts, format);
1313 print_formatted (val, fmt.size, &opts, gdb_stdout);
1315 annotate_value_end ();
1318 gdb_flush (gdb_stdout);
1322 set_command (char *exp, int from_tty)
1324 expression_up expr = parse_expression (exp);
1326 if (expr->nelts >= 1)
1327 switch (expr->elts[0].opcode)
1329 case UNOP_PREINCREMENT:
1330 case UNOP_POSTINCREMENT:
1331 case UNOP_PREDECREMENT:
1332 case UNOP_POSTDECREMENT:
1334 case BINOP_ASSIGN_MODIFY:
1339 (_("Expression is not an assignment (and might have no effect)"));
1342 evaluate_expression (expr.get ());
1346 sym_info (char *arg, int from_tty)
1348 struct minimal_symbol *msymbol;
1349 struct objfile *objfile;
1350 struct obj_section *osect;
1351 CORE_ADDR addr, sect_addr;
1353 unsigned int offset;
1356 error_no_arg (_("address"));
1358 addr = parse_and_eval_address (arg);
1359 ALL_OBJSECTIONS (objfile, osect)
1361 /* Only process each object file once, even if there's a separate
1363 if (objfile->separate_debug_objfile_backlink)
1366 sect_addr = overlay_mapped_address (addr, osect);
1368 if (obj_section_addr (osect) <= sect_addr
1369 && sect_addr < obj_section_endaddr (osect)
1371 = lookup_minimal_symbol_by_pc_section (sect_addr, osect).minsym))
1373 const char *obj_name, *mapped, *sec_name, *msym_name;
1375 struct cleanup *old_chain;
1378 offset = sect_addr - MSYMBOL_VALUE_ADDRESS (objfile, msymbol);
1379 mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
1380 sec_name = osect->the_bfd_section->name;
1381 msym_name = MSYMBOL_PRINT_NAME (msymbol);
1383 /* Don't print the offset if it is zero.
1384 We assume there's no need to handle i18n of "sym + offset". */
1386 loc_string = xstrprintf ("%s + %u", msym_name, offset);
1388 loc_string = xstrprintf ("%s", msym_name);
1390 /* Use a cleanup to free loc_string in case the user quits
1391 a pagination request inside printf_filtered. */
1392 old_chain = make_cleanup (xfree, loc_string);
1394 gdb_assert (osect->objfile && objfile_name (osect->objfile));
1395 obj_name = objfile_name (osect->objfile);
1397 if (MULTI_OBJFILE_P ())
1398 if (pc_in_unmapped_range (addr, osect))
1399 if (section_is_overlay (osect))
1400 printf_filtered (_("%s in load address range of "
1401 "%s overlay section %s of %s\n"),
1402 loc_string, mapped, sec_name, obj_name);
1404 printf_filtered (_("%s in load address range of "
1405 "section %s of %s\n"),
1406 loc_string, sec_name, obj_name);
1408 if (section_is_overlay (osect))
1409 printf_filtered (_("%s in %s overlay section %s of %s\n"),
1410 loc_string, mapped, sec_name, obj_name);
1412 printf_filtered (_("%s in section %s of %s\n"),
1413 loc_string, sec_name, obj_name);
1415 if (pc_in_unmapped_range (addr, osect))
1416 if (section_is_overlay (osect))
1417 printf_filtered (_("%s in load address range of %s overlay "
1419 loc_string, mapped, sec_name);
1421 printf_filtered (_("%s in load address range of section %s\n"),
1422 loc_string, sec_name);
1424 if (section_is_overlay (osect))
1425 printf_filtered (_("%s in %s overlay section %s\n"),
1426 loc_string, mapped, sec_name);
1428 printf_filtered (_("%s in section %s\n"),
1429 loc_string, sec_name);
1431 do_cleanups (old_chain);
1435 printf_filtered (_("No symbol matches %s.\n"), arg);
1439 address_info (char *exp, int from_tty)
1441 struct gdbarch *gdbarch;
1444 struct bound_minimal_symbol msymbol;
1446 struct obj_section *section;
1447 CORE_ADDR load_addr, context_pc = 0;
1448 struct field_of_this_result is_a_field_of_this;
1451 error (_("Argument required."));
1453 sym = lookup_symbol (exp, get_selected_block (&context_pc), VAR_DOMAIN,
1454 &is_a_field_of_this).symbol;
1457 if (is_a_field_of_this.type != NULL)
1459 printf_filtered ("Symbol \"");
1460 fprintf_symbol_filtered (gdb_stdout, exp,
1461 current_language->la_language, DMGL_ANSI);
1462 printf_filtered ("\" is a field of the local class variable ");
1463 if (current_language->la_language == language_objc)
1464 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1466 printf_filtered ("`this'\n");
1470 msymbol = lookup_bound_minimal_symbol (exp);
1472 if (msymbol.minsym != NULL)
1474 struct objfile *objfile = msymbol.objfile;
1476 gdbarch = get_objfile_arch (objfile);
1477 load_addr = BMSYMBOL_VALUE_ADDRESS (msymbol);
1479 printf_filtered ("Symbol \"");
1480 fprintf_symbol_filtered (gdb_stdout, exp,
1481 current_language->la_language, DMGL_ANSI);
1482 printf_filtered ("\" is at ");
1483 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1484 printf_filtered (" in a file compiled without debugging");
1485 section = MSYMBOL_OBJ_SECTION (objfile, msymbol.minsym);
1486 if (section_is_overlay (section))
1488 load_addr = overlay_unmapped_address (load_addr, section);
1489 printf_filtered (",\n -- loaded at ");
1490 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1491 printf_filtered (" in overlay section %s",
1492 section->the_bfd_section->name);
1494 printf_filtered (".\n");
1497 error (_("No symbol \"%s\" in current context."), exp);
1501 printf_filtered ("Symbol \"");
1502 fprintf_symbol_filtered (gdb_stdout, SYMBOL_PRINT_NAME (sym),
1503 current_language->la_language, DMGL_ANSI);
1504 printf_filtered ("\" is ");
1505 val = SYMBOL_VALUE (sym);
1506 if (SYMBOL_OBJFILE_OWNED (sym))
1507 section = SYMBOL_OBJ_SECTION (symbol_objfile (sym), sym);
1510 gdbarch = symbol_arch (sym);
1512 if (SYMBOL_COMPUTED_OPS (sym) != NULL)
1514 SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, context_pc,
1516 printf_filtered (".\n");
1520 switch (SYMBOL_CLASS (sym))
1523 case LOC_CONST_BYTES:
1524 printf_filtered ("constant");
1528 printf_filtered ("a label at address ");
1529 load_addr = SYMBOL_VALUE_ADDRESS (sym);
1530 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1531 if (section_is_overlay (section))
1533 load_addr = overlay_unmapped_address (load_addr, section);
1534 printf_filtered (",\n -- loaded at ");
1535 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1536 printf_filtered (" in overlay section %s",
1537 section->the_bfd_section->name);
1542 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
1545 /* GDBARCH is the architecture associated with the objfile the symbol
1546 is defined in; the target architecture may be different, and may
1547 provide additional registers. However, we do not know the target
1548 architecture at this point. We assume the objfile architecture
1549 will contain all the standard registers that occur in debug info
1551 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
1553 if (SYMBOL_IS_ARGUMENT (sym))
1554 printf_filtered (_("an argument in register %s"),
1555 gdbarch_register_name (gdbarch, regno));
1557 printf_filtered (_("a variable in register %s"),
1558 gdbarch_register_name (gdbarch, regno));
1562 printf_filtered (_("static storage at address "));
1563 load_addr = SYMBOL_VALUE_ADDRESS (sym);
1564 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1565 if (section_is_overlay (section))
1567 load_addr = overlay_unmapped_address (load_addr, section);
1568 printf_filtered (_(",\n -- loaded at "));
1569 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1570 printf_filtered (_(" in overlay section %s"),
1571 section->the_bfd_section->name);
1575 case LOC_REGPARM_ADDR:
1576 /* Note comment at LOC_REGISTER. */
1577 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
1578 printf_filtered (_("address of an argument in register %s"),
1579 gdbarch_register_name (gdbarch, regno));
1583 printf_filtered (_("an argument at offset %ld"), val);
1587 printf_filtered (_("a local variable at frame offset %ld"), val);
1591 printf_filtered (_("a reference argument at offset %ld"), val);
1595 printf_filtered (_("a typedef"));
1599 printf_filtered (_("a function at address "));
1600 load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1601 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1602 if (section_is_overlay (section))
1604 load_addr = overlay_unmapped_address (load_addr, section);
1605 printf_filtered (_(",\n -- loaded at "));
1606 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1607 printf_filtered (_(" in overlay section %s"),
1608 section->the_bfd_section->name);
1612 case LOC_UNRESOLVED:
1614 struct bound_minimal_symbol msym;
1616 msym = lookup_minimal_symbol_and_objfile (SYMBOL_LINKAGE_NAME (sym));
1617 if (msym.minsym == NULL)
1618 printf_filtered ("unresolved");
1621 section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
1624 && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
1626 load_addr = MSYMBOL_VALUE_RAW_ADDRESS (msym.minsym);
1627 printf_filtered (_("a thread-local variable at offset %s "
1628 "in the thread-local storage for `%s'"),
1629 paddress (gdbarch, load_addr),
1630 objfile_name (section->objfile));
1634 load_addr = BMSYMBOL_VALUE_ADDRESS (msym);
1635 printf_filtered (_("static storage at address "));
1636 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1637 if (section_is_overlay (section))
1639 load_addr = overlay_unmapped_address (load_addr, section);
1640 printf_filtered (_(",\n -- loaded at "));
1641 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1642 printf_filtered (_(" in overlay section %s"),
1643 section->the_bfd_section->name);
1650 case LOC_OPTIMIZED_OUT:
1651 printf_filtered (_("optimized out"));
1655 printf_filtered (_("of unknown (botched) type"));
1658 printf_filtered (".\n");
1663 x_command (char *exp, int from_tty)
1665 struct format_data fmt;
1666 struct cleanup *old_chain;
1669 fmt.format = last_format ? last_format : 'x';
1670 fmt.size = last_size;
1674 if (exp && *exp == '/')
1676 const char *tmp = exp + 1;
1678 fmt = decode_format (&tmp, last_format, last_size);
1682 /* If we have an expression, evaluate it and use it as the address. */
1684 if (exp != 0 && *exp != 0)
1686 expression_up expr = parse_expression (exp);
1687 /* Cause expression not to be there any more if this command is
1688 repeated with Newline. But don't clobber a user-defined
1689 command's definition. */
1692 val = evaluate_expression (expr.get ());
1693 if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
1694 val = coerce_ref (val);
1695 /* In rvalue contexts, such as this, functions are coerced into
1696 pointers to functions. This makes "x/i main" work. */
1697 if (/* last_format == 'i' && */
1698 TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
1699 && VALUE_LVAL (val) == lval_memory)
1700 next_address = value_address (val);
1702 next_address = value_as_address (val);
1704 next_gdbarch = expr->gdbarch;
1708 error_no_arg (_("starting display address"));
1710 do_examine (fmt, next_gdbarch, next_address);
1712 /* If the examine succeeds, we remember its size and format for next
1713 time. Set last_size to 'b' for strings. */
1714 if (fmt.format == 's')
1717 last_size = fmt.size;
1718 last_format = fmt.format;
1720 /* Set a couple of internal variables if appropriate. */
1721 if (last_examine_value)
1723 /* Make last address examined available to the user as $_. Use
1724 the correct pointer type. */
1725 struct type *pointer_type
1726 = lookup_pointer_type (value_type (last_examine_value));
1727 set_internalvar (lookup_internalvar ("_"),
1728 value_from_pointer (pointer_type,
1729 last_examine_address));
1731 /* Make contents of last address examined available to the user
1732 as $__. If the last value has not been fetched from memory
1733 then don't fetch it now; instead mark it by voiding the $__
1735 if (value_lazy (last_examine_value))
1736 clear_internalvar (lookup_internalvar ("__"));
1738 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1743 /* Add an expression to the auto-display chain.
1744 Specify the expression. */
1747 display_command (char *arg, int from_tty)
1749 struct format_data fmt;
1750 struct display *newobj;
1751 const char *exp = arg;
1762 fmt = decode_format (&exp, 0, 0);
1763 if (fmt.size && fmt.format == 0)
1765 if (fmt.format == 'i' || fmt.format == 's')
1776 innermost_block = NULL;
1777 expression_up expr = parse_expression (exp);
1779 newobj = new display ();
1781 newobj->exp_string = xstrdup (exp);
1782 newobj->exp = gdb::move (expr);
1783 newobj->block = innermost_block;
1784 newobj->pspace = current_program_space;
1785 newobj->number = ++display_number;
1786 newobj->format = fmt;
1787 newobj->enabled_p = 1;
1788 newobj->next = NULL;
1790 if (display_chain == NULL)
1791 display_chain = newobj;
1794 struct display *last;
1796 for (last = display_chain; last->next != NULL; last = last->next)
1798 last->next = newobj;
1802 do_one_display (newobj);
1808 free_display (struct display *d)
1810 xfree (d->exp_string);
1814 /* Clear out the display_chain. Done when new symtabs are loaded,
1815 since this invalidates the types stored in many expressions. */
1818 clear_displays (void)
1822 while ((d = display_chain) != NULL)
1824 display_chain = d->next;
1829 /* Delete the auto-display DISPLAY. */
1832 delete_display (struct display *display)
1836 gdb_assert (display != NULL);
1838 if (display_chain == display)
1839 display_chain = display->next;
1842 if (d->next == display)
1844 d->next = display->next;
1848 free_display (display);
1851 /* Call FUNCTION on each of the displays whose numbers are given in
1852 ARGS. DATA is passed unmodified to FUNCTION. */
1855 map_display_numbers (char *args,
1856 void (*function) (struct display *,
1863 error_no_arg (_("one or more display numbers"));
1865 number_or_range_parser parser (args);
1867 while (!parser.finished ())
1869 const char *p = parser.cur_tok ();
1871 num = parser.get_number ();
1873 warning (_("bad display number at or near '%s'"), p);
1876 struct display *d, *tmp;
1878 ALL_DISPLAYS_SAFE (d, tmp)
1879 if (d->number == num)
1882 printf_unfiltered (_("No display number %d.\n"), num);
1889 /* Callback for map_display_numbers, that deletes a display. */
1892 do_delete_display (struct display *d, void *data)
1897 /* "undisplay" command. */
1900 undisplay_command (char *args, int from_tty)
1904 if (query (_("Delete all auto-display expressions? ")))
1910 map_display_numbers (args, do_delete_display, NULL);
1914 /* Display a single auto-display.
1915 Do nothing if the display cannot be printed in the current context,
1916 or if the display is disabled. */
1919 do_one_display (struct display *d)
1921 int within_current_scope;
1923 if (d->enabled_p == 0)
1926 /* The expression carries the architecture that was used at parse time.
1927 This is a problem if the expression depends on architecture features
1928 (e.g. register numbers), and the current architecture is now different.
1929 For example, a display statement like "display/i $pc" is expected to
1930 display the PC register of the current architecture, not the arch at
1931 the time the display command was given. Therefore, we re-parse the
1932 expression if the current architecture has changed. */
1933 if (d->exp != NULL && d->exp->gdbarch != get_current_arch ())
1944 innermost_block = NULL;
1945 d->exp = parse_expression (d->exp_string);
1946 d->block = innermost_block;
1948 CATCH (ex, RETURN_MASK_ALL)
1950 /* Can't re-parse the expression. Disable this display item. */
1952 warning (_("Unable to display \"%s\": %s"),
1953 d->exp_string, ex.message);
1961 if (d->pspace == current_program_space)
1962 within_current_scope = contained_in (get_selected_block (0), d->block);
1964 within_current_scope = 0;
1967 within_current_scope = 1;
1968 if (!within_current_scope)
1971 scoped_restore save_display_number
1972 = make_scoped_restore (¤t_display_number, d->number);
1974 annotate_display_begin ();
1975 printf_filtered ("%d", d->number);
1976 annotate_display_number_end ();
1977 printf_filtered (": ");
1981 annotate_display_format ();
1983 printf_filtered ("x/");
1984 if (d->format.count != 1)
1985 printf_filtered ("%d", d->format.count);
1986 printf_filtered ("%c", d->format.format);
1987 if (d->format.format != 'i' && d->format.format != 's')
1988 printf_filtered ("%c", d->format.size);
1989 printf_filtered (" ");
1991 annotate_display_expression ();
1993 puts_filtered (d->exp_string);
1994 annotate_display_expression_end ();
1996 if (d->format.count != 1 || d->format.format == 'i')
1997 printf_filtered ("\n");
1999 printf_filtered (" ");
2001 annotate_display_value ();
2008 val = evaluate_expression (d->exp.get ());
2009 addr = value_as_address (val);
2010 if (d->format.format == 'i')
2011 addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr);
2012 do_examine (d->format, d->exp->gdbarch, addr);
2014 CATCH (ex, RETURN_MASK_ERROR)
2016 fprintf_filtered (gdb_stdout, _("<error: %s>\n"), ex.message);
2022 struct value_print_options opts;
2024 annotate_display_format ();
2026 if (d->format.format)
2027 printf_filtered ("/%c ", d->format.format);
2029 annotate_display_expression ();
2031 puts_filtered (d->exp_string);
2032 annotate_display_expression_end ();
2034 printf_filtered (" = ");
2036 annotate_display_expression ();
2038 get_formatted_print_options (&opts, d->format.format);
2039 opts.raw = d->format.raw;
2045 val = evaluate_expression (d->exp.get ());
2046 print_formatted (val, d->format.size, &opts, gdb_stdout);
2048 CATCH (ex, RETURN_MASK_ERROR)
2050 fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
2054 printf_filtered ("\n");
2057 annotate_display_end ();
2059 gdb_flush (gdb_stdout);
2062 /* Display all of the values on the auto-display chain which can be
2063 evaluated in the current scope. */
2070 for (d = display_chain; d; d = d->next)
2074 /* Delete the auto-display which we were in the process of displaying.
2075 This is done when there is an error or a signal. */
2078 disable_display (int num)
2082 for (d = display_chain; d; d = d->next)
2083 if (d->number == num)
2088 printf_unfiltered (_("No display number %d.\n"), num);
2092 disable_current_display (void)
2094 if (current_display_number >= 0)
2096 disable_display (current_display_number);
2097 fprintf_unfiltered (gdb_stderr,
2098 _("Disabling display %d to "
2099 "avoid infinite recursion.\n"),
2100 current_display_number);
2102 current_display_number = -1;
2106 display_info (char *ignore, int from_tty)
2111 printf_unfiltered (_("There are no auto-display expressions now.\n"));
2113 printf_filtered (_("Auto-display expressions now in effect:\n\
2114 Num Enb Expression\n"));
2116 for (d = display_chain; d; d = d->next)
2118 printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]);
2120 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
2122 else if (d->format.format)
2123 printf_filtered ("/%c ", d->format.format);
2124 puts_filtered (d->exp_string);
2125 if (d->block && !contained_in (get_selected_block (0), d->block))
2126 printf_filtered (_(" (cannot be evaluated in the current context)"));
2127 printf_filtered ("\n");
2128 gdb_flush (gdb_stdout);
2132 /* Callback fo map_display_numbers, that enables or disables the
2133 passed in display D. */
2136 do_enable_disable_display (struct display *d, void *data)
2138 d->enabled_p = *(int *) data;
2141 /* Implamentation of both the "disable display" and "enable display"
2142 commands. ENABLE decides what to do. */
2145 enable_disable_display_command (char *args, int from_tty, int enable)
2152 d->enabled_p = enable;
2156 map_display_numbers (args, do_enable_disable_display, &enable);
2159 /* The "enable display" command. */
2162 enable_display_command (char *args, int from_tty)
2164 enable_disable_display_command (args, from_tty, 1);
2167 /* The "disable display" command. */
2170 disable_display_command (char *args, int from_tty)
2172 enable_disable_display_command (args, from_tty, 0);
2175 /* display_chain items point to blocks and expressions. Some expressions in
2176 turn may point to symbols.
2177 Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
2178 obstack_free'd when a shared library is unloaded.
2179 Clear pointers that are about to become dangling.
2180 Both .exp and .block fields will be restored next time we need to display
2181 an item by re-parsing .exp_string field in the new execution context. */
2184 clear_dangling_display_expressions (struct objfile *objfile)
2187 struct program_space *pspace;
2189 /* With no symbol file we cannot have a block or expression from it. */
2190 if (objfile == NULL)
2192 pspace = objfile->pspace;
2193 if (objfile->separate_debug_objfile_backlink)
2195 objfile = objfile->separate_debug_objfile_backlink;
2196 gdb_assert (objfile->pspace == pspace);
2199 for (d = display_chain; d != NULL; d = d->next)
2201 if (d->pspace != pspace)
2204 if (lookup_objfile_from_block (d->block) == objfile
2205 || (d->exp != NULL && exp_uses_objfile (d->exp.get (), objfile)))
2214 /* Print the value in stack frame FRAME of a variable specified by a
2215 struct symbol. NAME is the name to print; if NULL then VAR's print
2216 name will be used. STREAM is the ui_file on which to print the
2217 value. INDENT specifies the number of indent levels to print
2218 before printing the variable name.
2220 This function invalidates FRAME. */
2223 print_variable_and_value (const char *name, struct symbol *var,
2224 struct frame_info *frame,
2225 struct ui_file *stream, int indent)
2229 name = SYMBOL_PRINT_NAME (var);
2231 fprintf_filtered (stream, "%s%s = ", n_spaces (2 * indent), name);
2235 struct value_print_options opts;
2237 /* READ_VAR_VALUE needs a block in order to deal with non-local
2238 references (i.e. to handle nested functions). In this context, we
2239 print variables that are local to this frame, so we can avoid passing
2241 val = read_var_value (var, NULL, frame);
2242 get_user_print_options (&opts);
2244 common_val_print (val, stream, indent, &opts, current_language);
2246 /* common_val_print invalidates FRAME when a pretty printer calls inferior
2250 CATCH (except, RETURN_MASK_ERROR)
2252 fprintf_filtered(stream, "<error reading variable %s (%s)>", name,
2257 fprintf_filtered (stream, "\n");
2260 /* Subroutine of ui_printf to simplify it.
2261 Print VALUE to STREAM using FORMAT.
2262 VALUE is a C-style string on the target. */
2265 printf_c_string (struct ui_file *stream, const char *format,
2266 struct value *value)
2272 tem = value_as_address (value);
2274 /* This is a %s argument. Find the length of the string. */
2280 read_memory (tem + j, &c, 1);
2285 /* Copy the string contents into a string inside GDB. */
2286 str = (gdb_byte *) alloca (j + 1);
2288 read_memory (tem, str, j);
2291 fprintf_filtered (stream, format, (char *) str);
2294 /* Subroutine of ui_printf to simplify it.
2295 Print VALUE to STREAM using FORMAT.
2296 VALUE is a wide C-style string on the target. */
2299 printf_wide_c_string (struct ui_file *stream, const char *format,
2300 struct value *value)
2305 struct gdbarch *gdbarch = get_type_arch (value_type (value));
2306 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2307 struct type *wctype = lookup_typename (current_language, gdbarch,
2308 "wchar_t", NULL, 0);
2309 int wcwidth = TYPE_LENGTH (wctype);
2310 gdb_byte *buf = (gdb_byte *) alloca (wcwidth);
2311 struct obstack output;
2312 struct cleanup *inner_cleanup;
2314 tem = value_as_address (value);
2316 /* This is a %s argument. Find the length of the string. */
2317 for (j = 0;; j += wcwidth)
2320 read_memory (tem + j, buf, wcwidth);
2321 if (extract_unsigned_integer (buf, wcwidth, byte_order) == 0)
2325 /* Copy the string contents into a string inside GDB. */
2326 str = (gdb_byte *) alloca (j + wcwidth);
2328 read_memory (tem, str, j);
2329 memset (&str[j], 0, wcwidth);
2331 obstack_init (&output);
2332 inner_cleanup = make_cleanup_obstack_free (&output);
2334 convert_between_encodings (target_wide_charset (gdbarch),
2337 &output, translit_char);
2338 obstack_grow_str0 (&output, "");
2340 fprintf_filtered (stream, format, obstack_base (&output));
2341 do_cleanups (inner_cleanup);
2344 /* Subroutine of ui_printf to simplify it.
2345 Print VALUE, a decimal floating point value, to STREAM using FORMAT. */
2348 printf_decfloat (struct ui_file *stream, const char *format,
2349 struct value *value)
2351 const gdb_byte *param_ptr = value_contents (value);
2353 #if defined (PRINTF_HAS_DECFLOAT)
2354 /* If we have native support for Decimal floating
2355 printing, handle it here. */
2356 fprintf_filtered (stream, format, param_ptr);
2358 /* As a workaround until vasprintf has native support for DFP
2359 we convert the DFP values to string and print them using
2360 the %s format specifier. */
2363 /* Parameter data. */
2364 struct type *param_type = value_type (value);
2365 struct gdbarch *gdbarch = get_type_arch (param_type);
2366 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2368 /* DFP output data. */
2369 struct value *dfp_value = NULL;
2373 struct type *dfp_type = NULL;
2374 char decstr[MAX_DECIMAL_STRING];
2376 /* Points to the end of the string so that we can go back
2377 and check for DFP length modifiers. */
2378 p = format + strlen (format);
2380 /* Look for the float/double format specifier. */
2381 while (*p != 'f' && *p != 'e' && *p != 'E'
2382 && *p != 'g' && *p != 'G')
2385 /* Search for the '%' char and extract the size and type of
2386 the output decimal value based on its modifiers
2387 (%Hf, %Df, %DDf). */
2393 dfp_type = builtin_type (gdbarch)->builtin_decfloat;
2395 else if (*p == 'D' && *(p - 1) == 'D')
2398 dfp_type = builtin_type (gdbarch)->builtin_declong;
2404 dfp_type = builtin_type (gdbarch)->builtin_decdouble;
2408 /* Conversion between different DFP types. */
2409 if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT)
2410 decimal_convert (param_ptr, TYPE_LENGTH (param_type),
2411 byte_order, dec, dfp_len, byte_order);
2413 /* If this is a non-trivial conversion, just output 0.
2414 A correct converted value can be displayed by explicitly
2415 casting to a DFP type. */
2416 decimal_from_string (dec, dfp_len, byte_order, "0");
2418 dfp_value = value_from_decfloat (dfp_type, dec);
2420 dfp_ptr = (gdb_byte *) value_contents (dfp_value);
2422 decimal_to_string (dfp_ptr, dfp_len, byte_order, decstr);
2424 /* Print the DFP value. */
2425 fprintf_filtered (stream, "%s", decstr);
2429 /* Subroutine of ui_printf to simplify it.
2430 Print VALUE, a target pointer, to STREAM using FORMAT. */
2433 printf_pointer (struct ui_file *stream, const char *format,
2434 struct value *value)
2436 /* We avoid the host's %p because pointers are too
2437 likely to be the wrong size. The only interesting
2438 modifier for %p is a width; extract that, and then
2439 handle %p as glibc would: %#x or a literal "(nil)". */
2443 #ifdef PRINTF_HAS_LONG_LONG
2444 long long val = value_as_long (value);
2446 long val = value_as_long (value);
2449 fmt = (char *) alloca (strlen (format) + 5);
2451 /* Copy up to the leading %. */
2456 int is_percent = (*p == '%');
2471 /* Copy any width. */
2472 while (*p >= '0' && *p < '9')
2475 gdb_assert (*p == 'p' && *(p + 1) == '\0');
2478 #ifdef PRINTF_HAS_LONG_LONG
2484 fprintf_filtered (stream, fmt, val);
2490 fprintf_filtered (stream, fmt, "(nil)");
2494 /* printf "printf format string" ARG to STREAM. */
2497 ui_printf (const char *arg, struct ui_file *stream)
2499 struct format_piece *fpieces;
2500 const char *s = arg;
2501 struct value **val_args;
2502 int allocated_args = 20;
2503 struct cleanup *old_cleanups;
2505 val_args = XNEWVEC (struct value *, allocated_args);
2506 old_cleanups = make_cleanup (free_current_contents, &val_args);
2509 error_no_arg (_("format-control string and values to print"));
2511 s = skip_spaces_const (s);
2513 /* A format string should follow, enveloped in double quotes. */
2515 error (_("Bad format string, missing '\"'."));
2517 fpieces = parse_format_string (&s);
2519 make_cleanup (free_format_pieces_cleanup, &fpieces);
2522 error (_("Bad format string, non-terminated '\"'."));
2524 s = skip_spaces_const (s);
2526 if (*s != ',' && *s != 0)
2527 error (_("Invalid argument syntax"));
2531 s = skip_spaces_const (s);
2537 char *current_substring;
2540 for (fr = 0; fpieces[fr].string != NULL; fr++)
2541 if (fpieces[fr].argclass != literal_piece)
2544 /* Now, parse all arguments and evaluate them.
2545 Store the VALUEs in VAL_ARGS. */
2551 if (nargs == allocated_args)
2552 val_args = (struct value **) xrealloc ((char *) val_args,
2553 (allocated_args *= 2)
2554 * sizeof (struct value *));
2556 val_args[nargs] = parse_to_comma_and_eval (&s1);
2564 if (nargs != nargs_wanted)
2565 error (_("Wrong number of arguments for specified format-string"));
2567 /* Now actually print them. */
2569 for (fr = 0; fpieces[fr].string != NULL; fr++)
2571 current_substring = fpieces[fr].string;
2572 switch (fpieces[fr].argclass)
2575 printf_c_string (stream, current_substring, val_args[i]);
2577 case wide_string_arg:
2578 printf_wide_c_string (stream, current_substring, val_args[i]);
2582 struct gdbarch *gdbarch
2583 = get_type_arch (value_type (val_args[i]));
2584 struct type *wctype = lookup_typename (current_language, gdbarch,
2585 "wchar_t", NULL, 0);
2586 struct type *valtype;
2587 struct obstack output;
2588 struct cleanup *inner_cleanup;
2589 const gdb_byte *bytes;
2591 valtype = value_type (val_args[i]);
2592 if (TYPE_LENGTH (valtype) != TYPE_LENGTH (wctype)
2593 || TYPE_CODE (valtype) != TYPE_CODE_INT)
2594 error (_("expected wchar_t argument for %%lc"));
2596 bytes = value_contents (val_args[i]);
2598 obstack_init (&output);
2599 inner_cleanup = make_cleanup_obstack_free (&output);
2601 convert_between_encodings (target_wide_charset (gdbarch),
2603 bytes, TYPE_LENGTH (valtype),
2604 TYPE_LENGTH (valtype),
2605 &output, translit_char);
2606 obstack_grow_str0 (&output, "");
2608 fprintf_filtered (stream, current_substring,
2609 obstack_base (&output));
2610 do_cleanups (inner_cleanup);
2615 struct type *type = value_type (val_args[i]);
2619 /* If format string wants a float, unchecked-convert the value
2620 to floating point of the same size. */
2621 type = float_type_from_length (type);
2622 val = unpack_double (type, value_contents (val_args[i]), &inv);
2624 error (_("Invalid floating value found in program."));
2626 fprintf_filtered (stream, current_substring, (double) val);
2629 case long_double_arg:
2630 #ifdef HAVE_LONG_DOUBLE
2632 struct type *type = value_type (val_args[i]);
2636 /* If format string wants a float, unchecked-convert the value
2637 to floating point of the same size. */
2638 type = float_type_from_length (type);
2639 val = unpack_double (type, value_contents (val_args[i]), &inv);
2641 error (_("Invalid floating value found in program."));
2643 fprintf_filtered (stream, current_substring,
2648 error (_("long double not supported in printf"));
2651 #ifdef PRINTF_HAS_LONG_LONG
2653 long long val = value_as_long (val_args[i]);
2655 fprintf_filtered (stream, current_substring, val);
2659 error (_("long long not supported in printf"));
2663 int val = value_as_long (val_args[i]);
2665 fprintf_filtered (stream, current_substring, val);
2670 long val = value_as_long (val_args[i]);
2672 fprintf_filtered (stream, current_substring, val);
2675 /* Handles decimal floating values. */
2677 printf_decfloat (stream, current_substring, val_args[i]);
2680 printf_pointer (stream, current_substring, val_args[i]);
2683 /* Print a portion of the format string that has no
2684 directives. Note that this will not include any
2685 ordinary %-specs, but it might include "%%". That is
2686 why we use printf_filtered and not puts_filtered here.
2687 Also, we pass a dummy argument because some platforms
2688 have modified GCC to include -Wformat-security by
2689 default, which will warn here if there is no
2691 fprintf_filtered (stream, current_substring, 0);
2694 internal_error (__FILE__, __LINE__,
2695 _("failed internal consistency check"));
2697 /* Maybe advance to the next argument. */
2698 if (fpieces[fr].argclass != literal_piece)
2702 do_cleanups (old_cleanups);
2705 /* Implement the "printf" command. */
2708 printf_command (char *arg, int from_tty)
2710 ui_printf (arg, gdb_stdout);
2711 gdb_flush (gdb_stdout);
2714 /* Implement the "eval" command. */
2717 eval_command (char *arg, int from_tty)
2719 struct ui_file *ui_out = mem_fileopen ();
2720 struct cleanup *cleanups = make_cleanup_ui_file_delete (ui_out);
2722 ui_printf (arg, ui_out);
2724 std::string expanded = ui_file_as_string (ui_out);
2726 execute_command (&expanded[0], from_tty);
2728 do_cleanups (cleanups);
2732 _initialize_printcmd (void)
2734 struct cmd_list_element *c;
2736 current_display_number = -1;
2738 observer_attach_free_objfile (clear_dangling_display_expressions);
2740 add_info ("address", address_info,
2741 _("Describe where symbol SYM is stored."));
2743 add_info ("symbol", sym_info, _("\
2744 Describe what symbol is at location ADDR.\n\
2745 Only for symbols with fixed locations (global or static scope)."));
2747 add_com ("x", class_vars, x_command, _("\
2748 Examine memory: x/FMT ADDRESS.\n\
2749 ADDRESS is an expression for the memory address to examine.\n\
2750 FMT is a repeat count followed by a format letter and a size letter.\n\
2751 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2752 t(binary), f(float), a(address), i(instruction), c(char), s(string)\n\
2753 and z(hex, zero padded on the left).\n\
2754 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2755 The specified number of objects of the specified size are printed\n\
2756 according to the format. If a negative number is specified, memory is\n\
2757 examined backward from the address.\n\n\
2758 Defaults for format and size letters are those previously used.\n\
2759 Default count is 1. Default address is following last thing printed\n\
2760 with this command or \"print\"."));
2763 add_com ("whereis", class_vars, whereis_command,
2764 _("Print line number and file of definition of variable."));
2767 add_info ("display", display_info, _("\
2768 Expressions to display when program stops, with code numbers."));
2770 add_cmd ("undisplay", class_vars, undisplay_command, _("\
2771 Cancel some expressions to be displayed when program stops.\n\
2772 Arguments are the code numbers of the expressions to stop displaying.\n\
2773 No argument means cancel all automatic-display expressions.\n\
2774 \"delete display\" has the same effect as this command.\n\
2775 Do \"info display\" to see current list of code numbers."),
2778 add_com ("display", class_vars, display_command, _("\
2779 Print value of expression EXP each time the program stops.\n\
2780 /FMT may be used before EXP as in the \"print\" command.\n\
2781 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2782 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2783 and examining is done as in the \"x\" command.\n\n\
2784 With no argument, display all currently requested auto-display expressions.\n\
2785 Use \"undisplay\" to cancel display requests previously made."));
2787 add_cmd ("display", class_vars, enable_display_command, _("\
2788 Enable some expressions to be displayed when program stops.\n\
2789 Arguments are the code numbers of the expressions to resume displaying.\n\
2790 No argument means enable all automatic-display expressions.\n\
2791 Do \"info display\" to see current list of code numbers."), &enablelist);
2793 add_cmd ("display", class_vars, disable_display_command, _("\
2794 Disable some expressions to be displayed when program stops.\n\
2795 Arguments are the code numbers of the expressions to stop displaying.\n\
2796 No argument means disable all automatic-display expressions.\n\
2797 Do \"info display\" to see current list of code numbers."), &disablelist);
2799 add_cmd ("display", class_vars, undisplay_command, _("\
2800 Cancel some expressions to be displayed when program stops.\n\
2801 Arguments are the code numbers of the expressions to stop displaying.\n\
2802 No argument means cancel all automatic-display expressions.\n\
2803 Do \"info display\" to see current list of code numbers."), &deletelist);
2805 add_com ("printf", class_vars, printf_command, _("\
2806 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2807 This is useful for formatted output in user-defined commands."));
2809 add_com ("output", class_vars, output_command, _("\
2810 Like \"print\" but don't put in value history and don't print newline.\n\
2811 This is useful in user-defined commands."));
2813 add_prefix_cmd ("set", class_vars, set_command, _("\
2814 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2815 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2816 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2817 with $), a register (a few standard names starting with $), or an actual\n\
2818 variable in the program being debugged. EXP is any valid expression.\n\
2819 Use \"set variable\" for variables with names identical to set subcommands.\n\
2821 With a subcommand, this command modifies parts of the gdb environment.\n\
2822 You can see these environment settings with the \"show\" command."),
2823 &setlist, "set ", 1, &cmdlist);
2825 add_com ("assign", class_vars, set_command, _("\
2826 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2827 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2828 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2829 with $), a register (a few standard names starting with $), or an actual\n\
2830 variable in the program being debugged. EXP is any valid expression.\n\
2831 Use \"set variable\" for variables with names identical to set subcommands.\n\
2832 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2833 You can see these environment settings with the \"show\" command."));
2835 /* "call" is the same as "set", but handy for dbx users to call fns. */
2836 c = add_com ("call", class_vars, call_command, _("\
2837 Call a function in the program.\n\
2838 The argument is the function name and arguments, in the notation of the\n\
2839 current working language. The result is printed and saved in the value\n\
2840 history, if it is not void."));
2841 set_cmd_completer (c, expression_completer);
2843 add_cmd ("variable", class_vars, set_command, _("\
2844 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2845 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2846 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2847 with $), a register (a few standard names starting with $), or an actual\n\
2848 variable in the program being debugged. EXP is any valid expression.\n\
2849 This may usually be abbreviated to simply \"set\"."),
2852 c = add_com ("print", class_vars, print_command, _("\
2853 Print value of expression EXP.\n\
2854 Variables accessible are those of the lexical environment of the selected\n\
2855 stack frame, plus all those whose scope is global or an entire file.\n\
2857 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2858 $$NUM refers to NUM'th value back from the last one.\n\
2859 Names starting with $ refer to registers (with the values they would have\n\
2860 if the program were to return to the stack frame now selected, restoring\n\
2861 all registers saved by frames farther in) or else to debugger\n\
2862 \"convenience\" variables (any such name not a known register).\n\
2863 Use assignment expressions to give values to convenience variables.\n\
2865 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2866 @ is a binary operator for treating consecutive data objects\n\
2867 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2868 element is FOO, whose second element is stored in the space following\n\
2869 where FOO is stored, etc. FOO must be an expression whose value\n\
2870 resides in memory.\n\
2872 EXP may be preceded with /FMT, where FMT is a format letter\n\
2873 but no count or size letter (see \"x\" command)."));
2874 set_cmd_completer (c, expression_completer);
2875 add_com_alias ("p", "print", class_vars, 1);
2876 add_com_alias ("inspect", "print", class_vars, 1);
2878 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
2879 &max_symbolic_offset, _("\
2880 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2881 Show the largest offset that will be printed in <symbol+1234> form."), _("\
2882 Tell GDB to only display the symbolic form of an address if the\n\
2883 offset between the closest earlier symbol and the address is less than\n\
2884 the specified maximum offset. The default is \"unlimited\", which tells GDB\n\
2885 to always print the symbolic form of an address if any symbol precedes\n\
2886 it. Zero is equivalent to \"unlimited\"."),
2888 show_max_symbolic_offset,
2889 &setprintlist, &showprintlist);
2890 add_setshow_boolean_cmd ("symbol-filename", no_class,
2891 &print_symbol_filename, _("\
2892 Set printing of source filename and line number with <symbol>."), _("\
2893 Show printing of source filename and line number with <symbol>."), NULL,
2895 show_print_symbol_filename,
2896 &setprintlist, &showprintlist);
2898 add_com ("eval", no_class, eval_command, _("\
2899 Convert \"printf format string\", arg1, arg2, arg3, ..., argn to\n\
2900 a command line, and call it."));