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. */
122 struct expression *exp;
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_contents_for_printing (val),
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 LONGEST val_long = 0;
360 unsigned int len = TYPE_LENGTH (type);
361 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
363 /* String printing should go through val_print_scalar_formatted. */
364 gdb_assert (options->format != 's');
366 if (len > sizeof(LONGEST)
367 && (TYPE_CODE (type) == TYPE_CODE_INT
368 || TYPE_CODE (type) == TYPE_CODE_ENUM))
370 switch (options->format)
373 print_octal_chars (stream, valaddr, len, byte_order);
377 print_decimal_chars (stream, valaddr, len, byte_order);
380 print_binary_chars (stream, valaddr, len, byte_order);
383 print_hex_chars (stream, valaddr, len, byte_order);
386 print_char_chars (stream, type, valaddr, len, byte_order);
393 if (options->format != 'f')
394 val_long = unpack_long (type, valaddr);
396 /* If the value is a pointer, and pointers and addresses are not the
397 same, then at this point, the value's length (in target bytes) is
398 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
399 if (TYPE_CODE (type) == TYPE_CODE_PTR)
400 len = gdbarch_addr_bit (gdbarch) / TARGET_CHAR_BIT;
402 /* If we are printing it as unsigned, truncate it in case it is actually
403 a negative signed value (e.g. "print/u (short)-1" should print 65535
404 (if shorts are 16 bits) instead of 4294967295). */
405 if (options->format != 'd' || TYPE_UNSIGNED (type))
407 if (len < sizeof (LONGEST))
408 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
411 switch (options->format)
416 /* No size specified, like in print. Print varying # of digits. */
417 print_longest (stream, 'x', 1, val_long);
426 print_longest (stream, size, 1, val_long);
429 error (_("Undefined output size \"%c\"."), size);
434 print_longest (stream, 'd', 1, val_long);
438 print_longest (stream, 'u', 0, val_long);
443 print_longest (stream, 'o', 1, val_long);
445 fprintf_filtered (stream, "0");
450 CORE_ADDR addr = unpack_pointer (type, valaddr);
452 print_address (gdbarch, addr, stream);
458 struct value_print_options opts = *options;
461 if (TYPE_UNSIGNED (type))
462 type = builtin_type (gdbarch)->builtin_true_unsigned_char;
464 type = builtin_type (gdbarch)->builtin_true_char;
466 value_print (value_from_longest (type, val_long), stream, &opts);
471 type = float_type_from_length (type);
472 print_floating (valaddr, type, stream);
476 internal_error (__FILE__, __LINE__,
477 _("failed internal consistency check"));
480 /* Binary; 't' stands for "two". */
482 char bits[8 * (sizeof val_long) + 1];
483 char buf[8 * (sizeof val_long) + 32];
488 width = 8 * (sizeof val_long);
505 error (_("Undefined output size \"%c\"."), size);
511 bits[width] = (val_long & 1) ? '1' : '0';
516 while (*cp && *cp == '0')
521 strncpy (buf, cp, sizeof (bits));
522 fputs_filtered (buf, stream);
527 print_hex_chars (stream, valaddr, len, byte_order);
531 error (_("Undefined output format \"%c\"."), options->format);
535 /* Specify default address for `x' command.
536 The `info lines' command uses this. */
539 set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr)
541 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
543 next_gdbarch = gdbarch;
546 /* Make address available to the user as $_. */
547 set_internalvar (lookup_internalvar ("_"),
548 value_from_pointer (ptr_type, addr));
551 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
552 after LEADIN. Print nothing if no symbolic name is found nearby.
553 Optionally also print source file and line number, if available.
554 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
555 or to interpret it as a possible C++ name and convert it back to source
556 form. However note that DO_DEMANGLE can be overridden by the specific
557 settings of the demangle and asm_demangle variables. Returns
558 non-zero if anything was printed; zero otherwise. */
561 print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
562 struct ui_file *stream,
563 int do_demangle, char *leadin)
566 char *filename = NULL;
571 /* Throw away both name and filename. */
572 struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
573 make_cleanup (free_current_contents, &filename);
575 if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &offset,
576 &filename, &line, &unmapped))
578 do_cleanups (cleanup_chain);
582 fputs_filtered (leadin, stream);
584 fputs_filtered ("<*", stream);
586 fputs_filtered ("<", stream);
587 fputs_filtered (name, stream);
589 fprintf_filtered (stream, "+%u", (unsigned int) offset);
591 /* Append source filename and line number if desired. Give specific
592 line # of this addr, if we have it; else line # of the nearest symbol. */
593 if (print_symbol_filename && filename != NULL)
596 fprintf_filtered (stream, " at %s:%d", filename, line);
598 fprintf_filtered (stream, " in %s", filename);
601 fputs_filtered ("*>", stream);
603 fputs_filtered (">", stream);
605 do_cleanups (cleanup_chain);
609 /* Given an address ADDR return all the elements needed to print the
610 address in a symbolic form. NAME can be mangled or not depending
611 on DO_DEMANGLE (and also on the asm_demangle global variable,
612 manipulated via ''set print asm-demangle''). Return 0 in case of
613 success, when all the info in the OUT paramters is valid. Return 1
616 build_address_symbolic (struct gdbarch *gdbarch,
617 CORE_ADDR addr, /* IN */
618 int do_demangle, /* IN */
619 char **name, /* OUT */
620 int *offset, /* OUT */
621 char **filename, /* OUT */
623 int *unmapped) /* OUT */
625 struct bound_minimal_symbol msymbol;
626 struct symbol *symbol;
627 CORE_ADDR name_location = 0;
628 struct obj_section *section = NULL;
629 const char *name_temp = "";
631 /* Let's say it is mapped (not unmapped). */
634 /* Determine if the address is in an overlay, and whether it is
636 if (overlay_debugging)
638 section = find_pc_overlay (addr);
639 if (pc_in_unmapped_range (addr, section))
642 addr = overlay_mapped_address (addr, section);
646 /* First try to find the address in the symbol table, then
647 in the minsyms. Take the closest one. */
649 /* This is defective in the sense that it only finds text symbols. So
650 really this is kind of pointless--we should make sure that the
651 minimal symbols have everything we need (by changing that we could
652 save some memory, but for many debug format--ELF/DWARF or
653 anything/stabs--it would be inconvenient to eliminate those minimal
655 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
656 symbol = find_pc_sect_function (addr, section);
660 /* If this is a function (i.e. a code address), strip out any
661 non-address bits. For instance, display a pointer to the
662 first instruction of a Thumb function as <function>; the
663 second instruction will be <function+2>, even though the
664 pointer is <function+3>. This matches the ISA behavior. */
665 addr = gdbarch_addr_bits_remove (gdbarch, addr);
667 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
668 if (do_demangle || asm_demangle)
669 name_temp = SYMBOL_PRINT_NAME (symbol);
671 name_temp = SYMBOL_LINKAGE_NAME (symbol);
674 if (msymbol.minsym != NULL
675 && MSYMBOL_HAS_SIZE (msymbol.minsym)
676 && MSYMBOL_SIZE (msymbol.minsym) == 0
677 && MSYMBOL_TYPE (msymbol.minsym) != mst_text
678 && MSYMBOL_TYPE (msymbol.minsym) != mst_text_gnu_ifunc
679 && MSYMBOL_TYPE (msymbol.minsym) != mst_file_text)
680 msymbol.minsym = NULL;
682 if (msymbol.minsym != NULL)
684 if (BMSYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
686 /* If this is a function (i.e. a code address), strip out any
687 non-address bits. For instance, display a pointer to the
688 first instruction of a Thumb function as <function>; the
689 second instruction will be <function+2>, even though the
690 pointer is <function+3>. This matches the ISA behavior. */
691 if (MSYMBOL_TYPE (msymbol.minsym) == mst_text
692 || MSYMBOL_TYPE (msymbol.minsym) == mst_text_gnu_ifunc
693 || MSYMBOL_TYPE (msymbol.minsym) == mst_file_text
694 || MSYMBOL_TYPE (msymbol.minsym) == mst_solib_trampoline)
695 addr = gdbarch_addr_bits_remove (gdbarch, addr);
697 /* The msymbol is closer to the address than the symbol;
698 use the msymbol instead. */
700 name_location = BMSYMBOL_VALUE_ADDRESS (msymbol);
701 if (do_demangle || asm_demangle)
702 name_temp = MSYMBOL_PRINT_NAME (msymbol.minsym);
704 name_temp = MSYMBOL_LINKAGE_NAME (msymbol.minsym);
707 if (symbol == NULL && msymbol.minsym == NULL)
710 /* If the nearest symbol is too far away, don't print anything symbolic. */
712 /* For when CORE_ADDR is larger than unsigned int, we do math in
713 CORE_ADDR. But when we detect unsigned wraparound in the
714 CORE_ADDR math, we ignore this test and print the offset,
715 because addr+max_symbolic_offset has wrapped through the end
716 of the address space back to the beginning, giving bogus comparison. */
717 if (addr > name_location + max_symbolic_offset
718 && name_location + max_symbolic_offset > name_location)
721 *offset = addr - name_location;
723 *name = xstrdup (name_temp);
725 if (print_symbol_filename)
727 struct symtab_and_line sal;
729 sal = find_pc_sect_line (addr, section, 0);
733 *filename = xstrdup (symtab_to_filename_for_display (sal.symtab));
741 /* Print address ADDR symbolically on STREAM.
742 First print it as a number. Then perhaps print
743 <SYMBOL + OFFSET> after the number. */
746 print_address (struct gdbarch *gdbarch,
747 CORE_ADDR addr, struct ui_file *stream)
749 fputs_filtered (paddress (gdbarch, addr), stream);
750 print_address_symbolic (gdbarch, addr, stream, asm_demangle, " ");
753 /* Return a prefix for instruction address:
754 "=> " for current instruction, else " ". */
757 pc_prefix (CORE_ADDR addr)
759 if (has_stack_frames ())
761 struct frame_info *frame;
764 frame = get_selected_frame (NULL);
765 if (get_frame_pc_if_available (frame, &pc) && pc == addr)
771 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
772 controls whether to print the symbolic name "raw" or demangled.
773 Return non-zero if anything was printed; zero otherwise. */
776 print_address_demangle (const struct value_print_options *opts,
777 struct gdbarch *gdbarch, CORE_ADDR addr,
778 struct ui_file *stream, int do_demangle)
780 if (opts->addressprint)
782 fputs_filtered (paddress (gdbarch, addr), stream);
783 print_address_symbolic (gdbarch, addr, stream, do_demangle, " ");
787 return print_address_symbolic (gdbarch, addr, stream, do_demangle, "");
793 /* Find the address of the instruction that is INST_COUNT instructions before
794 the instruction at ADDR.
795 Since some architectures have variable-length instructions, we can't just
796 simply subtract INST_COUNT * INSN_LEN from ADDR. Instead, we use line
797 number information to locate the nearest known instruction boundary,
798 and disassemble forward from there. If we go out of the symbol range
799 during disassembling, we return the lowest address we've got so far and
800 set the number of instructions read to INST_READ. */
803 find_instruction_backward (struct gdbarch *gdbarch, CORE_ADDR addr,
804 int inst_count, int *inst_read)
806 /* The vector PCS is used to store instruction addresses within
808 CORE_ADDR loop_start, loop_end, p;
809 VEC (CORE_ADDR) *pcs = NULL;
810 struct symtab_and_line sal;
811 struct cleanup *cleanup = make_cleanup (VEC_cleanup (CORE_ADDR), &pcs);
814 loop_start = loop_end = addr;
816 /* In each iteration of the outer loop, we get a pc range that ends before
817 LOOP_START, then we count and store every instruction address of the range
818 iterated in the loop.
819 If the number of instructions counted reaches INST_COUNT, return the
820 stored address that is located INST_COUNT instructions back from ADDR.
821 If INST_COUNT is not reached, we subtract the number of counted
822 instructions from INST_COUNT, and go to the next iteration. */
825 VEC_truncate (CORE_ADDR, pcs, 0);
826 sal = find_pc_sect_line (loop_start, NULL, 1);
829 /* We reach here when line info is not available. In this case,
830 we print a message and just exit the loop. The return value
831 is calculated after the loop. */
832 printf_filtered (_("No line number information available "
835 print_address (gdbarch, loop_start - 1, gdb_stdout);
836 printf_filtered ("\n");
840 loop_end = loop_start;
843 /* This loop pushes instruction addresses in the range from
844 LOOP_START to LOOP_END. */
845 for (p = loop_start; p < loop_end;)
847 VEC_safe_push (CORE_ADDR, pcs, p);
848 p += gdb_insn_length (gdbarch, p);
851 inst_count -= VEC_length (CORE_ADDR, pcs);
852 *inst_read += VEC_length (CORE_ADDR, pcs);
854 while (inst_count > 0);
856 /* After the loop, the vector PCS has instruction addresses of the last
857 source line we processed, and INST_COUNT has a negative value.
858 We return the address at the index of -INST_COUNT in the vector for
860 Let's assume the following instruction addresses and run 'x/-4i 0x400e'.
870 find_instruction_backward is called with INST_COUNT = 4 and expected to
871 return 0x4001. When we reach here, INST_COUNT is set to -1 because
872 it was subtracted by 2 (from Line Y) and 3 (from Line X). The value
873 4001 is located at the index 1 of the last iterated line (= Line X),
874 which is simply calculated by -INST_COUNT.
875 The case when the length of PCS is 0 means that we reached an area for
876 which line info is not available. In such case, we return LOOP_START,
877 which was the lowest instruction address that had line info. */
878 p = VEC_length (CORE_ADDR, pcs) > 0
879 ? VEC_index (CORE_ADDR, pcs, -inst_count)
882 /* INST_READ includes all instruction addresses in a pc range. Need to
883 exclude the beginning part up to the address we're returning. That
884 is, exclude {0x4000} in the example above. */
886 *inst_read += inst_count;
888 do_cleanups (cleanup);
892 /* Backward read LEN bytes of target memory from address MEMADDR + LEN,
893 placing the results in GDB's memory from MYADDR + LEN. Returns
894 a count of the bytes actually read. */
897 read_memory_backward (struct gdbarch *gdbarch,
898 CORE_ADDR memaddr, gdb_byte *myaddr, int len)
901 int nread; /* Number of bytes actually read. */
903 /* First try a complete read. */
904 errcode = target_read_memory (memaddr, myaddr, len);
912 /* Loop, reading one byte at a time until we get as much as we can. */
915 for (nread = 0; nread < len; ++nread)
917 errcode = target_read_memory (--memaddr, --myaddr, 1);
920 /* The read was unsuccessful, so exit the loop. */
921 printf_filtered (_("Cannot access memory at address %s\n"),
922 paddress (gdbarch, memaddr));
930 /* Returns true if X (which is LEN bytes wide) is the number zero. */
933 integer_is_zero (const gdb_byte *x, int len)
937 while (i < len && x[i] == 0)
942 /* Find the start address of a string in which ADDR is included.
943 Basically we search for '\0' and return the next address,
944 but if OPTIONS->PRINT_MAX is smaller than the length of a string,
945 we stop searching and return the address to print characters as many as
946 PRINT_MAX from the string. */
949 find_string_backward (struct gdbarch *gdbarch,
950 CORE_ADDR addr, int count, int char_size,
951 const struct value_print_options *options,
952 int *strings_counted)
954 const int chunk_size = 0x20;
955 gdb_byte *buffer = NULL;
956 struct cleanup *cleanup = NULL;
959 int chars_to_read = chunk_size;
960 int chars_counted = 0;
961 int count_original = count;
962 CORE_ADDR string_start_addr = addr;
964 gdb_assert (char_size == 1 || char_size == 2 || char_size == 4);
965 buffer = (gdb_byte *) xmalloc (chars_to_read * char_size);
966 cleanup = make_cleanup (xfree, buffer);
967 while (count > 0 && read_error == 0)
971 addr -= chars_to_read * char_size;
972 chars_read = read_memory_backward (gdbarch, addr, buffer,
973 chars_to_read * char_size);
974 chars_read /= char_size;
975 read_error = (chars_read == chars_to_read) ? 0 : 1;
976 /* Searching for '\0' from the end of buffer in backward direction. */
977 for (i = 0; i < chars_read && count > 0 ; ++i, ++chars_counted)
979 int offset = (chars_to_read - i - 1) * char_size;
981 if (integer_is_zero (buffer + offset, char_size)
982 || chars_counted == options->print_max)
984 /* Found '\0' or reached print_max. As OFFSET is the offset to
985 '\0', we add CHAR_SIZE to return the start address of
988 string_start_addr = addr + offset + char_size;
994 /* Update STRINGS_COUNTED with the actual number of loaded strings. */
995 *strings_counted = count_original - count;
999 /* In error case, STRING_START_ADDR is pointing to the string that
1000 was last successfully loaded. Rewind the partially loaded string. */
1001 string_start_addr -= chars_counted * char_size;
1004 do_cleanups (cleanup);
1005 return string_start_addr;
1008 /* Examine data at address ADDR in format FMT.
1009 Fetch it from memory and print on gdb_stdout. */
1012 do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr)
1017 struct type *val_type = NULL;
1020 struct value_print_options opts;
1021 int need_to_update_next_address = 0;
1022 CORE_ADDR addr_rewound = 0;
1024 format = fmt.format;
1027 next_gdbarch = gdbarch;
1028 next_address = addr;
1030 /* Instruction format implies fetch single bytes
1031 regardless of the specified size.
1032 The case of strings is handled in decode_format, only explicit
1033 size operator are not changed to 'b'. */
1039 /* Pick the appropriate size for an address. */
1040 if (gdbarch_ptr_bit (next_gdbarch) == 64)
1042 else if (gdbarch_ptr_bit (next_gdbarch) == 32)
1044 else if (gdbarch_ptr_bit (next_gdbarch) == 16)
1047 /* Bad value for gdbarch_ptr_bit. */
1048 internal_error (__FILE__, __LINE__,
1049 _("failed internal consistency check"));
1053 val_type = builtin_type (next_gdbarch)->builtin_int8;
1054 else if (size == 'h')
1055 val_type = builtin_type (next_gdbarch)->builtin_int16;
1056 else if (size == 'w')
1057 val_type = builtin_type (next_gdbarch)->builtin_int32;
1058 else if (size == 'g')
1059 val_type = builtin_type (next_gdbarch)->builtin_int64;
1063 struct type *char_type = NULL;
1065 /* Search for "char16_t" or "char32_t" types or fall back to 8-bit char
1066 if type is not found. */
1068 char_type = builtin_type (next_gdbarch)->builtin_char16;
1069 else if (size == 'w')
1070 char_type = builtin_type (next_gdbarch)->builtin_char32;
1072 val_type = char_type;
1075 if (size != '\0' && size != 'b')
1076 warning (_("Unable to display strings with "
1077 "size '%c', using 'b' instead."), size);
1079 val_type = builtin_type (next_gdbarch)->builtin_int8;
1088 if (format == 's' || format == 'i')
1091 get_formatted_print_options (&opts, format);
1095 /* This is the negative repeat count case.
1096 We rewind the address based on the given repeat count and format,
1097 then examine memory from there in forward direction. */
1102 next_address = find_instruction_backward (gdbarch, addr, count,
1105 else if (format == 's')
1107 next_address = find_string_backward (gdbarch, addr, count,
1108 TYPE_LENGTH (val_type),
1113 next_address = addr - count * TYPE_LENGTH (val_type);
1116 /* The following call to print_formatted updates next_address in every
1117 iteration. In backward case, we store the start address here
1118 and update next_address with it before exiting the function. */
1119 addr_rewound = (format == 's'
1120 ? next_address - TYPE_LENGTH (val_type)
1122 need_to_update_next_address = 1;
1125 /* Print as many objects as specified in COUNT, at most maxelts per line,
1126 with the address of the next one at the start of each line. */
1132 fputs_filtered (pc_prefix (next_address), gdb_stdout);
1133 print_address (next_gdbarch, next_address, gdb_stdout);
1134 printf_filtered (":");
1139 printf_filtered ("\t");
1140 /* Note that print_formatted sets next_address for the next
1142 last_examine_address = next_address;
1144 if (last_examine_value)
1145 value_free (last_examine_value);
1147 /* The value to be displayed is not fetched greedily.
1148 Instead, to avoid the possibility of a fetched value not
1149 being used, its retrieval is delayed until the print code
1150 uses it. When examining an instruction stream, the
1151 disassembler will perform its own memory fetch using just
1152 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
1153 the disassembler be modified so that LAST_EXAMINE_VALUE
1154 is left with the byte sequence from the last complete
1155 instruction fetched from memory? */
1156 last_examine_value = value_at_lazy (val_type, next_address);
1158 if (last_examine_value)
1159 release_value (last_examine_value);
1161 print_formatted (last_examine_value, size, &opts, gdb_stdout);
1163 /* Display any branch delay slots following the final insn. */
1164 if (format == 'i' && count == 1)
1165 count += branch_delay_insns;
1167 printf_filtered ("\n");
1168 gdb_flush (gdb_stdout);
1171 if (need_to_update_next_address)
1172 next_address = addr_rewound;
1176 validate_format (struct format_data fmt, const char *cmdname)
1179 error (_("Size letters are meaningless in \"%s\" command."), cmdname);
1181 error (_("Item count other than 1 is meaningless in \"%s\" command."),
1183 if (fmt.format == 'i')
1184 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
1185 fmt.format, cmdname);
1188 /* Parse print command format string into *FMTP and update *EXPP.
1189 CMDNAME should name the current command. */
1192 print_command_parse_format (const char **expp, const char *cmdname,
1193 struct format_data *fmtp)
1195 const char *exp = *expp;
1197 if (exp && *exp == '/')
1200 *fmtp = decode_format (&exp, last_format, 0);
1201 validate_format (*fmtp, cmdname);
1202 last_format = fmtp->format;
1215 /* Print VAL to console according to *FMTP, including recording it to
1219 print_value (struct value *val, const struct format_data *fmtp)
1221 struct value_print_options opts;
1222 int histindex = record_latest_value (val);
1224 annotate_value_history_begin (histindex, value_type (val));
1226 printf_filtered ("$%d = ", histindex);
1228 annotate_value_history_value ();
1230 get_formatted_print_options (&opts, fmtp->format);
1231 opts.raw = fmtp->raw;
1233 print_formatted (val, fmtp->size, &opts, gdb_stdout);
1234 printf_filtered ("\n");
1236 annotate_value_history_end ();
1239 /* Evaluate string EXP as an expression in the current language and
1240 print the resulting value. EXP may contain a format specifier as the
1241 first argument ("/x myvar" for example, to print myvar in hex). */
1244 print_command_1 (const char *exp, int voidprint)
1246 struct expression *expr;
1247 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
1249 struct format_data fmt;
1251 print_command_parse_format (&exp, "print", &fmt);
1255 expr = parse_expression (exp);
1256 make_cleanup (free_current_contents, &expr);
1257 val = evaluate_expression (expr);
1260 val = access_value_history (0);
1262 if (voidprint || (val && value_type (val) &&
1263 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
1264 print_value (val, &fmt);
1266 do_cleanups (old_chain);
1270 print_command (char *exp, int from_tty)
1272 print_command_1 (exp, 1);
1275 /* Same as print, except it doesn't print void results. */
1277 call_command (char *exp, int from_tty)
1279 print_command_1 (exp, 0);
1282 /* Implementation of the "output" command. */
1285 output_command (char *exp, int from_tty)
1287 output_command_const (exp, from_tty);
1290 /* Like output_command, but takes a const string as argument. */
1293 output_command_const (const char *exp, int from_tty)
1295 struct expression *expr;
1296 struct cleanup *old_chain;
1299 struct format_data fmt;
1300 struct value_print_options opts;
1305 if (exp && *exp == '/')
1308 fmt = decode_format (&exp, 0, 0);
1309 validate_format (fmt, "output");
1310 format = fmt.format;
1313 expr = parse_expression (exp);
1314 old_chain = make_cleanup (free_current_contents, &expr);
1316 val = evaluate_expression (expr);
1318 annotate_value_begin (value_type (val));
1320 get_formatted_print_options (&opts, format);
1322 print_formatted (val, fmt.size, &opts, gdb_stdout);
1324 annotate_value_end ();
1327 gdb_flush (gdb_stdout);
1329 do_cleanups (old_chain);
1333 set_command (char *exp, int from_tty)
1335 struct expression *expr = parse_expression (exp);
1336 struct cleanup *old_chain =
1337 make_cleanup (free_current_contents, &expr);
1339 if (expr->nelts >= 1)
1340 switch (expr->elts[0].opcode)
1342 case UNOP_PREINCREMENT:
1343 case UNOP_POSTINCREMENT:
1344 case UNOP_PREDECREMENT:
1345 case UNOP_POSTDECREMENT:
1347 case BINOP_ASSIGN_MODIFY:
1352 (_("Expression is not an assignment (and might have no effect)"));
1355 evaluate_expression (expr);
1356 do_cleanups (old_chain);
1360 sym_info (char *arg, int from_tty)
1362 struct minimal_symbol *msymbol;
1363 struct objfile *objfile;
1364 struct obj_section *osect;
1365 CORE_ADDR addr, sect_addr;
1367 unsigned int offset;
1370 error_no_arg (_("address"));
1372 addr = parse_and_eval_address (arg);
1373 ALL_OBJSECTIONS (objfile, osect)
1375 /* Only process each object file once, even if there's a separate
1377 if (objfile->separate_debug_objfile_backlink)
1380 sect_addr = overlay_mapped_address (addr, osect);
1382 if (obj_section_addr (osect) <= sect_addr
1383 && sect_addr < obj_section_endaddr (osect)
1385 = lookup_minimal_symbol_by_pc_section (sect_addr, osect).minsym))
1387 const char *obj_name, *mapped, *sec_name, *msym_name;
1389 struct cleanup *old_chain;
1392 offset = sect_addr - MSYMBOL_VALUE_ADDRESS (objfile, msymbol);
1393 mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
1394 sec_name = osect->the_bfd_section->name;
1395 msym_name = MSYMBOL_PRINT_NAME (msymbol);
1397 /* Don't print the offset if it is zero.
1398 We assume there's no need to handle i18n of "sym + offset". */
1400 loc_string = xstrprintf ("%s + %u", msym_name, offset);
1402 loc_string = xstrprintf ("%s", msym_name);
1404 /* Use a cleanup to free loc_string in case the user quits
1405 a pagination request inside printf_filtered. */
1406 old_chain = make_cleanup (xfree, loc_string);
1408 gdb_assert (osect->objfile && objfile_name (osect->objfile));
1409 obj_name = objfile_name (osect->objfile);
1411 if (MULTI_OBJFILE_P ())
1412 if (pc_in_unmapped_range (addr, osect))
1413 if (section_is_overlay (osect))
1414 printf_filtered (_("%s in load address range of "
1415 "%s overlay section %s of %s\n"),
1416 loc_string, mapped, sec_name, obj_name);
1418 printf_filtered (_("%s in load address range of "
1419 "section %s of %s\n"),
1420 loc_string, sec_name, obj_name);
1422 if (section_is_overlay (osect))
1423 printf_filtered (_("%s in %s overlay section %s of %s\n"),
1424 loc_string, mapped, sec_name, obj_name);
1426 printf_filtered (_("%s in section %s of %s\n"),
1427 loc_string, sec_name, obj_name);
1429 if (pc_in_unmapped_range (addr, osect))
1430 if (section_is_overlay (osect))
1431 printf_filtered (_("%s in load address range of %s overlay "
1433 loc_string, mapped, sec_name);
1435 printf_filtered (_("%s in load address range of section %s\n"),
1436 loc_string, sec_name);
1438 if (section_is_overlay (osect))
1439 printf_filtered (_("%s in %s overlay section %s\n"),
1440 loc_string, mapped, sec_name);
1442 printf_filtered (_("%s in section %s\n"),
1443 loc_string, sec_name);
1445 do_cleanups (old_chain);
1449 printf_filtered (_("No symbol matches %s.\n"), arg);
1453 address_info (char *exp, int from_tty)
1455 struct gdbarch *gdbarch;
1458 struct bound_minimal_symbol msymbol;
1460 struct obj_section *section;
1461 CORE_ADDR load_addr, context_pc = 0;
1462 struct field_of_this_result is_a_field_of_this;
1465 error (_("Argument required."));
1467 sym = lookup_symbol (exp, get_selected_block (&context_pc), VAR_DOMAIN,
1468 &is_a_field_of_this).symbol;
1471 if (is_a_field_of_this.type != NULL)
1473 printf_filtered ("Symbol \"");
1474 fprintf_symbol_filtered (gdb_stdout, exp,
1475 current_language->la_language, DMGL_ANSI);
1476 printf_filtered ("\" is a field of the local class variable ");
1477 if (current_language->la_language == language_objc)
1478 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1480 printf_filtered ("`this'\n");
1484 msymbol = lookup_bound_minimal_symbol (exp);
1486 if (msymbol.minsym != NULL)
1488 struct objfile *objfile = msymbol.objfile;
1490 gdbarch = get_objfile_arch (objfile);
1491 load_addr = BMSYMBOL_VALUE_ADDRESS (msymbol);
1493 printf_filtered ("Symbol \"");
1494 fprintf_symbol_filtered (gdb_stdout, exp,
1495 current_language->la_language, DMGL_ANSI);
1496 printf_filtered ("\" is at ");
1497 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1498 printf_filtered (" in a file compiled without debugging");
1499 section = MSYMBOL_OBJ_SECTION (objfile, msymbol.minsym);
1500 if (section_is_overlay (section))
1502 load_addr = overlay_unmapped_address (load_addr, section);
1503 printf_filtered (",\n -- loaded at ");
1504 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1505 printf_filtered (" in overlay section %s",
1506 section->the_bfd_section->name);
1508 printf_filtered (".\n");
1511 error (_("No symbol \"%s\" in current context."), exp);
1515 printf_filtered ("Symbol \"");
1516 fprintf_symbol_filtered (gdb_stdout, SYMBOL_PRINT_NAME (sym),
1517 current_language->la_language, DMGL_ANSI);
1518 printf_filtered ("\" is ");
1519 val = SYMBOL_VALUE (sym);
1520 if (SYMBOL_OBJFILE_OWNED (sym))
1521 section = SYMBOL_OBJ_SECTION (symbol_objfile (sym), sym);
1524 gdbarch = symbol_arch (sym);
1526 if (SYMBOL_COMPUTED_OPS (sym) != NULL)
1528 SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, context_pc,
1530 printf_filtered (".\n");
1534 switch (SYMBOL_CLASS (sym))
1537 case LOC_CONST_BYTES:
1538 printf_filtered ("constant");
1542 printf_filtered ("a label at address ");
1543 load_addr = SYMBOL_VALUE_ADDRESS (sym);
1544 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1545 if (section_is_overlay (section))
1547 load_addr = overlay_unmapped_address (load_addr, section);
1548 printf_filtered (",\n -- loaded at ");
1549 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1550 printf_filtered (" in overlay section %s",
1551 section->the_bfd_section->name);
1556 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
1559 /* GDBARCH is the architecture associated with the objfile the symbol
1560 is defined in; the target architecture may be different, and may
1561 provide additional registers. However, we do not know the target
1562 architecture at this point. We assume the objfile architecture
1563 will contain all the standard registers that occur in debug info
1565 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
1567 if (SYMBOL_IS_ARGUMENT (sym))
1568 printf_filtered (_("an argument in register %s"),
1569 gdbarch_register_name (gdbarch, regno));
1571 printf_filtered (_("a variable in register %s"),
1572 gdbarch_register_name (gdbarch, regno));
1576 printf_filtered (_("static storage at address "));
1577 load_addr = SYMBOL_VALUE_ADDRESS (sym);
1578 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1579 if (section_is_overlay (section))
1581 load_addr = overlay_unmapped_address (load_addr, section);
1582 printf_filtered (_(",\n -- loaded at "));
1583 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1584 printf_filtered (_(" in overlay section %s"),
1585 section->the_bfd_section->name);
1589 case LOC_REGPARM_ADDR:
1590 /* Note comment at LOC_REGISTER. */
1591 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
1592 printf_filtered (_("address of an argument in register %s"),
1593 gdbarch_register_name (gdbarch, regno));
1597 printf_filtered (_("an argument at offset %ld"), val);
1601 printf_filtered (_("a local variable at frame offset %ld"), val);
1605 printf_filtered (_("a reference argument at offset %ld"), val);
1609 printf_filtered (_("a typedef"));
1613 printf_filtered (_("a function at address "));
1614 load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1615 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1616 if (section_is_overlay (section))
1618 load_addr = overlay_unmapped_address (load_addr, section);
1619 printf_filtered (_(",\n -- loaded at "));
1620 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1621 printf_filtered (_(" in overlay section %s"),
1622 section->the_bfd_section->name);
1626 case LOC_UNRESOLVED:
1628 struct bound_minimal_symbol msym;
1630 msym = lookup_minimal_symbol_and_objfile (SYMBOL_LINKAGE_NAME (sym));
1631 if (msym.minsym == NULL)
1632 printf_filtered ("unresolved");
1635 section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
1638 && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
1640 load_addr = MSYMBOL_VALUE_RAW_ADDRESS (msym.minsym);
1641 printf_filtered (_("a thread-local variable at offset %s "
1642 "in the thread-local storage for `%s'"),
1643 paddress (gdbarch, load_addr),
1644 objfile_name (section->objfile));
1648 load_addr = BMSYMBOL_VALUE_ADDRESS (msym);
1649 printf_filtered (_("static storage at address "));
1650 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1651 if (section_is_overlay (section))
1653 load_addr = overlay_unmapped_address (load_addr, section);
1654 printf_filtered (_(",\n -- loaded at "));
1655 fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
1656 printf_filtered (_(" in overlay section %s"),
1657 section->the_bfd_section->name);
1664 case LOC_OPTIMIZED_OUT:
1665 printf_filtered (_("optimized out"));
1669 printf_filtered (_("of unknown (botched) type"));
1672 printf_filtered (".\n");
1677 x_command (char *exp, int from_tty)
1679 struct expression *expr;
1680 struct format_data fmt;
1681 struct cleanup *old_chain;
1684 fmt.format = last_format ? last_format : 'x';
1685 fmt.size = last_size;
1689 if (exp && *exp == '/')
1691 const char *tmp = exp + 1;
1693 fmt = decode_format (&tmp, last_format, last_size);
1697 /* If we have an expression, evaluate it and use it as the address. */
1699 if (exp != 0 && *exp != 0)
1701 expr = parse_expression (exp);
1702 /* Cause expression not to be there any more if this command is
1703 repeated with Newline. But don't clobber a user-defined
1704 command's definition. */
1707 old_chain = make_cleanup (free_current_contents, &expr);
1708 val = evaluate_expression (expr);
1709 if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
1710 val = coerce_ref (val);
1711 /* In rvalue contexts, such as this, functions are coerced into
1712 pointers to functions. This makes "x/i main" work. */
1713 if (/* last_format == 'i' && */
1714 TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
1715 && VALUE_LVAL (val) == lval_memory)
1716 next_address = value_address (val);
1718 next_address = value_as_address (val);
1720 next_gdbarch = expr->gdbarch;
1721 do_cleanups (old_chain);
1725 error_no_arg (_("starting display address"));
1727 do_examine (fmt, next_gdbarch, next_address);
1729 /* If the examine succeeds, we remember its size and format for next
1730 time. Set last_size to 'b' for strings. */
1731 if (fmt.format == 's')
1734 last_size = fmt.size;
1735 last_format = fmt.format;
1737 /* Set a couple of internal variables if appropriate. */
1738 if (last_examine_value)
1740 /* Make last address examined available to the user as $_. Use
1741 the correct pointer type. */
1742 struct type *pointer_type
1743 = lookup_pointer_type (value_type (last_examine_value));
1744 set_internalvar (lookup_internalvar ("_"),
1745 value_from_pointer (pointer_type,
1746 last_examine_address));
1748 /* Make contents of last address examined available to the user
1749 as $__. If the last value has not been fetched from memory
1750 then don't fetch it now; instead mark it by voiding the $__
1752 if (value_lazy (last_examine_value))
1753 clear_internalvar (lookup_internalvar ("__"));
1755 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1760 /* Add an expression to the auto-display chain.
1761 Specify the expression. */
1764 display_command (char *arg, int from_tty)
1766 struct format_data fmt;
1767 struct expression *expr;
1768 struct display *newobj;
1769 const char *exp = arg;
1780 fmt = decode_format (&exp, 0, 0);
1781 if (fmt.size && fmt.format == 0)
1783 if (fmt.format == 'i' || fmt.format == 's')
1794 innermost_block = NULL;
1795 expr = parse_expression (exp);
1797 newobj = XNEW (struct display);
1799 newobj->exp_string = xstrdup (exp);
1801 newobj->block = innermost_block;
1802 newobj->pspace = current_program_space;
1803 newobj->number = ++display_number;
1804 newobj->format = fmt;
1805 newobj->enabled_p = 1;
1806 newobj->next = NULL;
1808 if (display_chain == NULL)
1809 display_chain = newobj;
1812 struct display *last;
1814 for (last = display_chain; last->next != NULL; last = last->next)
1816 last->next = newobj;
1820 do_one_display (newobj);
1826 free_display (struct display *d)
1828 xfree (d->exp_string);
1833 /* Clear out the display_chain. Done when new symtabs are loaded,
1834 since this invalidates the types stored in many expressions. */
1837 clear_displays (void)
1841 while ((d = display_chain) != NULL)
1843 display_chain = d->next;
1848 /* Delete the auto-display DISPLAY. */
1851 delete_display (struct display *display)
1855 gdb_assert (display != NULL);
1857 if (display_chain == display)
1858 display_chain = display->next;
1861 if (d->next == display)
1863 d->next = display->next;
1867 free_display (display);
1870 /* Call FUNCTION on each of the displays whose numbers are given in
1871 ARGS. DATA is passed unmodified to FUNCTION. */
1874 map_display_numbers (char *args,
1875 void (*function) (struct display *,
1879 struct get_number_or_range_state state;
1883 error_no_arg (_("one or more display numbers"));
1885 init_number_or_range (&state, args);
1887 while (!state.finished)
1889 const char *p = state.string;
1891 num = get_number_or_range (&state);
1893 warning (_("bad display number at or near '%s'"), p);
1896 struct display *d, *tmp;
1898 ALL_DISPLAYS_SAFE (d, tmp)
1899 if (d->number == num)
1902 printf_unfiltered (_("No display number %d.\n"), num);
1909 /* Callback for map_display_numbers, that deletes a display. */
1912 do_delete_display (struct display *d, void *data)
1917 /* "undisplay" command. */
1920 undisplay_command (char *args, int from_tty)
1924 if (query (_("Delete all auto-display expressions? ")))
1930 map_display_numbers (args, do_delete_display, NULL);
1934 /* Display a single auto-display.
1935 Do nothing if the display cannot be printed in the current context,
1936 or if the display is disabled. */
1939 do_one_display (struct display *d)
1941 struct cleanup *old_chain;
1942 int within_current_scope;
1944 if (d->enabled_p == 0)
1947 /* The expression carries the architecture that was used at parse time.
1948 This is a problem if the expression depends on architecture features
1949 (e.g. register numbers), and the current architecture is now different.
1950 For example, a display statement like "display/i $pc" is expected to
1951 display the PC register of the current architecture, not the arch at
1952 the time the display command was given. Therefore, we re-parse the
1953 expression if the current architecture has changed. */
1954 if (d->exp != NULL && d->exp->gdbarch != get_current_arch ())
1966 innermost_block = NULL;
1967 d->exp = parse_expression (d->exp_string);
1968 d->block = innermost_block;
1970 CATCH (ex, RETURN_MASK_ALL)
1972 /* Can't re-parse the expression. Disable this display item. */
1974 warning (_("Unable to display \"%s\": %s"),
1975 d->exp_string, ex.message);
1983 if (d->pspace == current_program_space)
1984 within_current_scope = contained_in (get_selected_block (0), d->block);
1986 within_current_scope = 0;
1989 within_current_scope = 1;
1990 if (!within_current_scope)
1993 old_chain = make_cleanup_restore_integer (¤t_display_number);
1994 current_display_number = d->number;
1996 annotate_display_begin ();
1997 printf_filtered ("%d", d->number);
1998 annotate_display_number_end ();
1999 printf_filtered (": ");
2003 annotate_display_format ();
2005 printf_filtered ("x/");
2006 if (d->format.count != 1)
2007 printf_filtered ("%d", d->format.count);
2008 printf_filtered ("%c", d->format.format);
2009 if (d->format.format != 'i' && d->format.format != 's')
2010 printf_filtered ("%c", d->format.size);
2011 printf_filtered (" ");
2013 annotate_display_expression ();
2015 puts_filtered (d->exp_string);
2016 annotate_display_expression_end ();
2018 if (d->format.count != 1 || d->format.format == 'i')
2019 printf_filtered ("\n");
2021 printf_filtered (" ");
2023 annotate_display_value ();
2030 val = evaluate_expression (d->exp);
2031 addr = value_as_address (val);
2032 if (d->format.format == 'i')
2033 addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr);
2034 do_examine (d->format, d->exp->gdbarch, addr);
2036 CATCH (ex, RETURN_MASK_ERROR)
2038 fprintf_filtered (gdb_stdout, _("<error: %s>\n"), ex.message);
2044 struct value_print_options opts;
2046 annotate_display_format ();
2048 if (d->format.format)
2049 printf_filtered ("/%c ", d->format.format);
2051 annotate_display_expression ();
2053 puts_filtered (d->exp_string);
2054 annotate_display_expression_end ();
2056 printf_filtered (" = ");
2058 annotate_display_expression ();
2060 get_formatted_print_options (&opts, d->format.format);
2061 opts.raw = d->format.raw;
2067 val = evaluate_expression (d->exp);
2068 print_formatted (val, d->format.size, &opts, gdb_stdout);
2070 CATCH (ex, RETURN_MASK_ERROR)
2072 fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
2076 printf_filtered ("\n");
2079 annotate_display_end ();
2081 gdb_flush (gdb_stdout);
2082 do_cleanups (old_chain);
2085 /* Display all of the values on the auto-display chain which can be
2086 evaluated in the current scope. */
2093 for (d = display_chain; d; d = d->next)
2097 /* Delete the auto-display which we were in the process of displaying.
2098 This is done when there is an error or a signal. */
2101 disable_display (int num)
2105 for (d = display_chain; d; d = d->next)
2106 if (d->number == num)
2111 printf_unfiltered (_("No display number %d.\n"), num);
2115 disable_current_display (void)
2117 if (current_display_number >= 0)
2119 disable_display (current_display_number);
2120 fprintf_unfiltered (gdb_stderr,
2121 _("Disabling display %d to "
2122 "avoid infinite recursion.\n"),
2123 current_display_number);
2125 current_display_number = -1;
2129 display_info (char *ignore, int from_tty)
2134 printf_unfiltered (_("There are no auto-display expressions now.\n"));
2136 printf_filtered (_("Auto-display expressions now in effect:\n\
2137 Num Enb Expression\n"));
2139 for (d = display_chain; d; d = d->next)
2141 printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]);
2143 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
2145 else if (d->format.format)
2146 printf_filtered ("/%c ", d->format.format);
2147 puts_filtered (d->exp_string);
2148 if (d->block && !contained_in (get_selected_block (0), d->block))
2149 printf_filtered (_(" (cannot be evaluated in the current context)"));
2150 printf_filtered ("\n");
2151 gdb_flush (gdb_stdout);
2155 /* Callback fo map_display_numbers, that enables or disables the
2156 passed in display D. */
2159 do_enable_disable_display (struct display *d, void *data)
2161 d->enabled_p = *(int *) data;
2164 /* Implamentation of both the "disable display" and "enable display"
2165 commands. ENABLE decides what to do. */
2168 enable_disable_display_command (char *args, int from_tty, int enable)
2175 d->enabled_p = enable;
2179 map_display_numbers (args, do_enable_disable_display, &enable);
2182 /* The "enable display" command. */
2185 enable_display_command (char *args, int from_tty)
2187 enable_disable_display_command (args, from_tty, 1);
2190 /* The "disable display" command. */
2193 disable_display_command (char *args, int from_tty)
2195 enable_disable_display_command (args, from_tty, 0);
2198 /* display_chain items point to blocks and expressions. Some expressions in
2199 turn may point to symbols.
2200 Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
2201 obstack_free'd when a shared library is unloaded.
2202 Clear pointers that are about to become dangling.
2203 Both .exp and .block fields will be restored next time we need to display
2204 an item by re-parsing .exp_string field in the new execution context. */
2207 clear_dangling_display_expressions (struct objfile *objfile)
2210 struct program_space *pspace;
2212 /* With no symbol file we cannot have a block or expression from it. */
2213 if (objfile == NULL)
2215 pspace = objfile->pspace;
2216 if (objfile->separate_debug_objfile_backlink)
2218 objfile = objfile->separate_debug_objfile_backlink;
2219 gdb_assert (objfile->pspace == pspace);
2222 for (d = display_chain; d != NULL; d = d->next)
2224 if (d->pspace != pspace)
2227 if (lookup_objfile_from_block (d->block) == objfile
2228 || (d->exp && exp_uses_objfile (d->exp, objfile)))
2238 /* Print the value in stack frame FRAME of a variable specified by a
2239 struct symbol. NAME is the name to print; if NULL then VAR's print
2240 name will be used. STREAM is the ui_file on which to print the
2241 value. INDENT specifies the number of indent levels to print
2242 before printing the variable name.
2244 This function invalidates FRAME. */
2247 print_variable_and_value (const char *name, struct symbol *var,
2248 struct frame_info *frame,
2249 struct ui_file *stream, int indent)
2253 name = SYMBOL_PRINT_NAME (var);
2255 fprintf_filtered (stream, "%s%s = ", n_spaces (2 * indent), name);
2259 struct value_print_options opts;
2261 /* READ_VAR_VALUE needs a block in order to deal with non-local
2262 references (i.e. to handle nested functions). In this context, we
2263 print variables that are local to this frame, so we can avoid passing
2265 val = read_var_value (var, NULL, frame);
2266 get_user_print_options (&opts);
2268 common_val_print (val, stream, indent, &opts, current_language);
2270 /* common_val_print invalidates FRAME when a pretty printer calls inferior
2274 CATCH (except, RETURN_MASK_ERROR)
2276 fprintf_filtered(stream, "<error reading variable %s (%s)>", name,
2281 fprintf_filtered (stream, "\n");
2284 /* Subroutine of ui_printf to simplify it.
2285 Print VALUE to STREAM using FORMAT.
2286 VALUE is a C-style string on the target. */
2289 printf_c_string (struct ui_file *stream, const char *format,
2290 struct value *value)
2296 tem = value_as_address (value);
2298 /* This is a %s argument. Find the length of the string. */
2304 read_memory (tem + j, &c, 1);
2309 /* Copy the string contents into a string inside GDB. */
2310 str = (gdb_byte *) alloca (j + 1);
2312 read_memory (tem, str, j);
2315 fprintf_filtered (stream, format, (char *) str);
2318 /* Subroutine of ui_printf to simplify it.
2319 Print VALUE to STREAM using FORMAT.
2320 VALUE is a wide C-style string on the target. */
2323 printf_wide_c_string (struct ui_file *stream, const char *format,
2324 struct value *value)
2329 struct gdbarch *gdbarch = get_type_arch (value_type (value));
2330 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2331 struct type *wctype = lookup_typename (current_language, gdbarch,
2332 "wchar_t", NULL, 0);
2333 int wcwidth = TYPE_LENGTH (wctype);
2334 gdb_byte *buf = (gdb_byte *) alloca (wcwidth);
2335 struct obstack output;
2336 struct cleanup *inner_cleanup;
2338 tem = value_as_address (value);
2340 /* This is a %s argument. Find the length of the string. */
2341 for (j = 0;; j += wcwidth)
2344 read_memory (tem + j, buf, wcwidth);
2345 if (extract_unsigned_integer (buf, wcwidth, byte_order) == 0)
2349 /* Copy the string contents into a string inside GDB. */
2350 str = (gdb_byte *) alloca (j + wcwidth);
2352 read_memory (tem, str, j);
2353 memset (&str[j], 0, wcwidth);
2355 obstack_init (&output);
2356 inner_cleanup = make_cleanup_obstack_free (&output);
2358 convert_between_encodings (target_wide_charset (gdbarch),
2361 &output, translit_char);
2362 obstack_grow_str0 (&output, "");
2364 fprintf_filtered (stream, format, obstack_base (&output));
2365 do_cleanups (inner_cleanup);
2368 /* Subroutine of ui_printf to simplify it.
2369 Print VALUE, a decimal floating point value, to STREAM using FORMAT. */
2372 printf_decfloat (struct ui_file *stream, const char *format,
2373 struct value *value)
2375 const gdb_byte *param_ptr = value_contents (value);
2377 #if defined (PRINTF_HAS_DECFLOAT)
2378 /* If we have native support for Decimal floating
2379 printing, handle it here. */
2380 fprintf_filtered (stream, format, param_ptr);
2382 /* As a workaround until vasprintf has native support for DFP
2383 we convert the DFP values to string and print them using
2384 the %s format specifier. */
2387 /* Parameter data. */
2388 struct type *param_type = value_type (value);
2389 struct gdbarch *gdbarch = get_type_arch (param_type);
2390 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2392 /* DFP output data. */
2393 struct value *dfp_value = NULL;
2397 struct type *dfp_type = NULL;
2398 char decstr[MAX_DECIMAL_STRING];
2400 /* Points to the end of the string so that we can go back
2401 and check for DFP length modifiers. */
2402 p = format + strlen (format);
2404 /* Look for the float/double format specifier. */
2405 while (*p != 'f' && *p != 'e' && *p != 'E'
2406 && *p != 'g' && *p != 'G')
2409 /* Search for the '%' char and extract the size and type of
2410 the output decimal value based on its modifiers
2411 (%Hf, %Df, %DDf). */
2417 dfp_type = builtin_type (gdbarch)->builtin_decfloat;
2419 else if (*p == 'D' && *(p - 1) == 'D')
2422 dfp_type = builtin_type (gdbarch)->builtin_declong;
2428 dfp_type = builtin_type (gdbarch)->builtin_decdouble;
2432 /* Conversion between different DFP types. */
2433 if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT)
2434 decimal_convert (param_ptr, TYPE_LENGTH (param_type),
2435 byte_order, dec, dfp_len, byte_order);
2437 /* If this is a non-trivial conversion, just output 0.
2438 A correct converted value can be displayed by explicitly
2439 casting to a DFP type. */
2440 decimal_from_string (dec, dfp_len, byte_order, "0");
2442 dfp_value = value_from_decfloat (dfp_type, dec);
2444 dfp_ptr = (gdb_byte *) value_contents (dfp_value);
2446 decimal_to_string (dfp_ptr, dfp_len, byte_order, decstr);
2448 /* Print the DFP value. */
2449 fprintf_filtered (stream, "%s", decstr);
2453 /* Subroutine of ui_printf to simplify it.
2454 Print VALUE, a target pointer, to STREAM using FORMAT. */
2457 printf_pointer (struct ui_file *stream, const char *format,
2458 struct value *value)
2460 /* We avoid the host's %p because pointers are too
2461 likely to be the wrong size. The only interesting
2462 modifier for %p is a width; extract that, and then
2463 handle %p as glibc would: %#x or a literal "(nil)". */
2467 #ifdef PRINTF_HAS_LONG_LONG
2468 long long val = value_as_long (value);
2470 long val = value_as_long (value);
2473 fmt = (char *) alloca (strlen (format) + 5);
2475 /* Copy up to the leading %. */
2480 int is_percent = (*p == '%');
2495 /* Copy any width. */
2496 while (*p >= '0' && *p < '9')
2499 gdb_assert (*p == 'p' && *(p + 1) == '\0');
2502 #ifdef PRINTF_HAS_LONG_LONG
2508 fprintf_filtered (stream, fmt, val);
2514 fprintf_filtered (stream, fmt, "(nil)");
2518 /* printf "printf format string" ARG to STREAM. */
2521 ui_printf (const char *arg, struct ui_file *stream)
2523 struct format_piece *fpieces;
2524 const char *s = arg;
2525 struct value **val_args;
2526 int allocated_args = 20;
2527 struct cleanup *old_cleanups;
2529 val_args = XNEWVEC (struct value *, allocated_args);
2530 old_cleanups = make_cleanup (free_current_contents, &val_args);
2533 error_no_arg (_("format-control string and values to print"));
2535 s = skip_spaces_const (s);
2537 /* A format string should follow, enveloped in double quotes. */
2539 error (_("Bad format string, missing '\"'."));
2541 fpieces = parse_format_string (&s);
2543 make_cleanup (free_format_pieces_cleanup, &fpieces);
2546 error (_("Bad format string, non-terminated '\"'."));
2548 s = skip_spaces_const (s);
2550 if (*s != ',' && *s != 0)
2551 error (_("Invalid argument syntax"));
2555 s = skip_spaces_const (s);
2561 char *current_substring;
2564 for (fr = 0; fpieces[fr].string != NULL; fr++)
2565 if (fpieces[fr].argclass != literal_piece)
2568 /* Now, parse all arguments and evaluate them.
2569 Store the VALUEs in VAL_ARGS. */
2575 if (nargs == allocated_args)
2576 val_args = (struct value **) xrealloc ((char *) val_args,
2577 (allocated_args *= 2)
2578 * sizeof (struct value *));
2580 val_args[nargs] = parse_to_comma_and_eval (&s1);
2588 if (nargs != nargs_wanted)
2589 error (_("Wrong number of arguments for specified format-string"));
2591 /* Now actually print them. */
2593 for (fr = 0; fpieces[fr].string != NULL; fr++)
2595 current_substring = fpieces[fr].string;
2596 switch (fpieces[fr].argclass)
2599 printf_c_string (stream, current_substring, val_args[i]);
2601 case wide_string_arg:
2602 printf_wide_c_string (stream, current_substring, val_args[i]);
2606 struct gdbarch *gdbarch
2607 = get_type_arch (value_type (val_args[i]));
2608 struct type *wctype = lookup_typename (current_language, gdbarch,
2609 "wchar_t", NULL, 0);
2610 struct type *valtype;
2611 struct obstack output;
2612 struct cleanup *inner_cleanup;
2613 const gdb_byte *bytes;
2615 valtype = value_type (val_args[i]);
2616 if (TYPE_LENGTH (valtype) != TYPE_LENGTH (wctype)
2617 || TYPE_CODE (valtype) != TYPE_CODE_INT)
2618 error (_("expected wchar_t argument for %%lc"));
2620 bytes = value_contents (val_args[i]);
2622 obstack_init (&output);
2623 inner_cleanup = make_cleanup_obstack_free (&output);
2625 convert_between_encodings (target_wide_charset (gdbarch),
2627 bytes, TYPE_LENGTH (valtype),
2628 TYPE_LENGTH (valtype),
2629 &output, translit_char);
2630 obstack_grow_str0 (&output, "");
2632 fprintf_filtered (stream, current_substring,
2633 obstack_base (&output));
2634 do_cleanups (inner_cleanup);
2639 struct type *type = value_type (val_args[i]);
2643 /* If format string wants a float, unchecked-convert the value
2644 to floating point of the same size. */
2645 type = float_type_from_length (type);
2646 val = unpack_double (type, value_contents (val_args[i]), &inv);
2648 error (_("Invalid floating value found in program."));
2650 fprintf_filtered (stream, current_substring, (double) val);
2653 case long_double_arg:
2654 #ifdef HAVE_LONG_DOUBLE
2656 struct type *type = value_type (val_args[i]);
2660 /* If format string wants a float, unchecked-convert the value
2661 to floating point of the same size. */
2662 type = float_type_from_length (type);
2663 val = unpack_double (type, value_contents (val_args[i]), &inv);
2665 error (_("Invalid floating value found in program."));
2667 fprintf_filtered (stream, current_substring,
2672 error (_("long double not supported in printf"));
2675 #ifdef PRINTF_HAS_LONG_LONG
2677 long long val = value_as_long (val_args[i]);
2679 fprintf_filtered (stream, current_substring, val);
2683 error (_("long long not supported in printf"));
2687 int val = value_as_long (val_args[i]);
2689 fprintf_filtered (stream, current_substring, val);
2694 long val = value_as_long (val_args[i]);
2696 fprintf_filtered (stream, current_substring, val);
2699 /* Handles decimal floating values. */
2701 printf_decfloat (stream, current_substring, val_args[i]);
2704 printf_pointer (stream, current_substring, val_args[i]);
2707 /* Print a portion of the format string that has no
2708 directives. Note that this will not include any
2709 ordinary %-specs, but it might include "%%". That is
2710 why we use printf_filtered and not puts_filtered here.
2711 Also, we pass a dummy argument because some platforms
2712 have modified GCC to include -Wformat-security by
2713 default, which will warn here if there is no
2715 fprintf_filtered (stream, current_substring, 0);
2718 internal_error (__FILE__, __LINE__,
2719 _("failed internal consistency check"));
2721 /* Maybe advance to the next argument. */
2722 if (fpieces[fr].argclass != literal_piece)
2726 do_cleanups (old_cleanups);
2729 /* Implement the "printf" command. */
2732 printf_command (char *arg, int from_tty)
2734 ui_printf (arg, gdb_stdout);
2735 gdb_flush (gdb_stdout);
2738 /* Implement the "eval" command. */
2741 eval_command (char *arg, int from_tty)
2743 struct ui_file *ui_out = mem_fileopen ();
2744 struct cleanup *cleanups = make_cleanup_ui_file_delete (ui_out);
2747 ui_printf (arg, ui_out);
2749 expanded = ui_file_xstrdup (ui_out, NULL);
2750 make_cleanup (xfree, expanded);
2752 execute_command (expanded, from_tty);
2754 do_cleanups (cleanups);
2758 _initialize_printcmd (void)
2760 struct cmd_list_element *c;
2762 current_display_number = -1;
2764 observer_attach_free_objfile (clear_dangling_display_expressions);
2766 add_info ("address", address_info,
2767 _("Describe where symbol SYM is stored."));
2769 add_info ("symbol", sym_info, _("\
2770 Describe what symbol is at location ADDR.\n\
2771 Only for symbols with fixed locations (global or static scope)."));
2773 add_com ("x", class_vars, x_command, _("\
2774 Examine memory: x/FMT ADDRESS.\n\
2775 ADDRESS is an expression for the memory address to examine.\n\
2776 FMT is a repeat count followed by a format letter and a size letter.\n\
2777 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2778 t(binary), f(float), a(address), i(instruction), c(char), s(string)\n\
2779 and z(hex, zero padded on the left).\n\
2780 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2781 The specified number of objects of the specified size are printed\n\
2782 according to the format. If a negative number is specified, memory is\n\
2783 examined backward from the address.\n\n\
2784 Defaults for format and size letters are those previously used.\n\
2785 Default count is 1. Default address is following last thing printed\n\
2786 with this command or \"print\"."));
2789 add_com ("whereis", class_vars, whereis_command,
2790 _("Print line number and file of definition of variable."));
2793 add_info ("display", display_info, _("\
2794 Expressions to display when program stops, with code numbers."));
2796 add_cmd ("undisplay", class_vars, undisplay_command, _("\
2797 Cancel some expressions to be displayed when program stops.\n\
2798 Arguments are the code numbers of the expressions to stop displaying.\n\
2799 No argument means cancel all automatic-display expressions.\n\
2800 \"delete display\" has the same effect as this command.\n\
2801 Do \"info display\" to see current list of code numbers."),
2804 add_com ("display", class_vars, display_command, _("\
2805 Print value of expression EXP each time the program stops.\n\
2806 /FMT may be used before EXP as in the \"print\" command.\n\
2807 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2808 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2809 and examining is done as in the \"x\" command.\n\n\
2810 With no argument, display all currently requested auto-display expressions.\n\
2811 Use \"undisplay\" to cancel display requests previously made."));
2813 add_cmd ("display", class_vars, enable_display_command, _("\
2814 Enable some expressions to be displayed when program stops.\n\
2815 Arguments are the code numbers of the expressions to resume displaying.\n\
2816 No argument means enable all automatic-display expressions.\n\
2817 Do \"info display\" to see current list of code numbers."), &enablelist);
2819 add_cmd ("display", class_vars, disable_display_command, _("\
2820 Disable some expressions to be displayed when program stops.\n\
2821 Arguments are the code numbers of the expressions to stop displaying.\n\
2822 No argument means disable all automatic-display expressions.\n\
2823 Do \"info display\" to see current list of code numbers."), &disablelist);
2825 add_cmd ("display", class_vars, undisplay_command, _("\
2826 Cancel some expressions to be displayed when program stops.\n\
2827 Arguments are the code numbers of the expressions to stop displaying.\n\
2828 No argument means cancel all automatic-display expressions.\n\
2829 Do \"info display\" to see current list of code numbers."), &deletelist);
2831 add_com ("printf", class_vars, printf_command, _("\
2832 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2833 This is useful for formatted output in user-defined commands."));
2835 add_com ("output", class_vars, output_command, _("\
2836 Like \"print\" but don't put in value history and don't print newline.\n\
2837 This is useful in user-defined commands."));
2839 add_prefix_cmd ("set", class_vars, set_command, _("\
2840 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2841 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2842 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2843 with $), a register (a few standard names starting with $), or an actual\n\
2844 variable in the program being debugged. EXP is any valid expression.\n\
2845 Use \"set variable\" for variables with names identical to set subcommands.\n\
2847 With a subcommand, this command modifies parts of the gdb environment.\n\
2848 You can see these environment settings with the \"show\" command."),
2849 &setlist, "set ", 1, &cmdlist);
2851 add_com ("assign", class_vars, set_command, _("\
2852 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2853 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2854 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2855 with $), a register (a few standard names starting with $), or an actual\n\
2856 variable in the program being debugged. EXP is any valid expression.\n\
2857 Use \"set variable\" for variables with names identical to set subcommands.\n\
2858 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2859 You can see these environment settings with the \"show\" command."));
2861 /* "call" is the same as "set", but handy for dbx users to call fns. */
2862 c = add_com ("call", class_vars, call_command, _("\
2863 Call a function in the program.\n\
2864 The argument is the function name and arguments, in the notation of the\n\
2865 current working language. The result is printed and saved in the value\n\
2866 history, if it is not void."));
2867 set_cmd_completer (c, expression_completer);
2869 add_cmd ("variable", class_vars, set_command, _("\
2870 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2871 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2872 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2873 with $), a register (a few standard names starting with $), or an actual\n\
2874 variable in the program being debugged. EXP is any valid expression.\n\
2875 This may usually be abbreviated to simply \"set\"."),
2878 c = add_com ("print", class_vars, print_command, _("\
2879 Print value of expression EXP.\n\
2880 Variables accessible are those of the lexical environment of the selected\n\
2881 stack frame, plus all those whose scope is global or an entire file.\n\
2883 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2884 $$NUM refers to NUM'th value back from the last one.\n\
2885 Names starting with $ refer to registers (with the values they would have\n\
2886 if the program were to return to the stack frame now selected, restoring\n\
2887 all registers saved by frames farther in) or else to debugger\n\
2888 \"convenience\" variables (any such name not a known register).\n\
2889 Use assignment expressions to give values to convenience variables.\n\
2891 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2892 @ is a binary operator for treating consecutive data objects\n\
2893 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2894 element is FOO, whose second element is stored in the space following\n\
2895 where FOO is stored, etc. FOO must be an expression whose value\n\
2896 resides in memory.\n\
2898 EXP may be preceded with /FMT, where FMT is a format letter\n\
2899 but no count or size letter (see \"x\" command)."));
2900 set_cmd_completer (c, expression_completer);
2901 add_com_alias ("p", "print", class_vars, 1);
2902 add_com_alias ("inspect", "print", class_vars, 1);
2904 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
2905 &max_symbolic_offset, _("\
2906 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2907 Show the largest offset that will be printed in <symbol+1234> form."), _("\
2908 Tell GDB to only display the symbolic form of an address if the\n\
2909 offset between the closest earlier symbol and the address is less than\n\
2910 the specified maximum offset. The default is \"unlimited\", which tells GDB\n\
2911 to always print the symbolic form of an address if any symbol precedes\n\
2912 it. Zero is equivalent to \"unlimited\"."),
2914 show_max_symbolic_offset,
2915 &setprintlist, &showprintlist);
2916 add_setshow_boolean_cmd ("symbol-filename", no_class,
2917 &print_symbol_filename, _("\
2918 Set printing of source filename and line number with <symbol>."), _("\
2919 Show printing of source filename and line number with <symbol>."), NULL,
2921 show_print_symbol_filename,
2922 &setprintlist, &showprintlist);
2924 add_com ("eval", no_class, eval_command, _("\
2925 Convert \"printf format string\", arg1, arg2, arg3, ..., argn to\n\
2926 a command line, and call it."));