* linux-low.c (regsets_fetch_inferior_registers): Fix memory leak.
[gdb/SamB.git] / gdb / printcmd.c
blob8403d5fcffef119d7e15dfe71f4c2ec0bd282b1e
1 /* Print values for GNU debugger GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "defs.h"
23 #include "gdb_string.h"
24 #include "frame.h"
25 #include "symtab.h"
26 #include "gdbtypes.h"
27 #include "value.h"
28 #include "language.h"
29 #include "expression.h"
30 #include "gdbcore.h"
31 #include "gdbcmd.h"
32 #include "target.h"
33 #include "breakpoint.h"
34 #include "demangle.h"
35 #include "valprint.h"
36 #include "annotate.h"
37 #include "symfile.h" /* for overlay functions */
38 #include "objfiles.h" /* ditto */
39 #include "completer.h" /* for completion functions */
40 #include "ui-out.h"
41 #include "gdb_assert.h"
42 #include "block.h"
43 #include "disasm.h"
44 #include "dfp.h"
45 #include "valprint.h"
46 #include "exceptions.h"
47 #include "observer.h"
48 #include "solist.h"
49 #include "solib.h"
50 #include "parser-defs.h"
51 #include "charset.h"
53 #ifdef TUI
54 #include "tui/tui.h" /* For tui_active et.al. */
55 #endif
57 #if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG)
58 # define USE_PRINTF_I64 1
59 # define PRINTF_HAS_LONG_LONG
60 #else
61 # define USE_PRINTF_I64 0
62 #endif
64 extern int asm_demangle; /* Whether to demangle syms in asm printouts */
66 struct format_data
68 int count;
69 char format;
70 char size;
73 /* Last specified output format. */
75 static char last_format = 'x';
77 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
79 static char last_size = 'w';
81 /* Default address to examine next. */
83 static CORE_ADDR next_address;
85 /* Number of delay instructions following current disassembled insn. */
87 static int branch_delay_insns;
89 /* Last address examined. */
91 static CORE_ADDR last_examine_address;
93 /* Contents of last address examined.
94 This is not valid past the end of the `x' command! */
96 static struct value *last_examine_value;
98 /* Largest offset between a symbolic value and an address, that will be
99 printed as `0x1234 <symbol+offset>'. */
101 static unsigned int max_symbolic_offset = UINT_MAX;
102 static void
103 show_max_symbolic_offset (struct ui_file *file, int from_tty,
104 struct cmd_list_element *c, const char *value)
106 fprintf_filtered (file, _("\
107 The largest offset that will be printed in <symbol+1234> form is %s.\n"),
108 value);
111 /* Append the source filename and linenumber of the symbol when
112 printing a symbolic value as `<symbol at filename:linenum>' if set. */
113 static int print_symbol_filename = 0;
114 static void
115 show_print_symbol_filename (struct ui_file *file, int from_tty,
116 struct cmd_list_element *c, const char *value)
118 fprintf_filtered (file, _("\
119 Printing of source filename and line number with <symbol> is %s.\n"),
120 value);
123 /* Number of auto-display expression currently being displayed.
124 So that we can disable it if we get an error or a signal within it.
125 -1 when not doing one. */
127 int current_display_number;
129 struct display
131 /* Chain link to next auto-display item. */
132 struct display *next;
133 /* The expression as the user typed it. */
134 char *exp_string;
135 /* Expression to be evaluated and displayed. */
136 struct expression *exp;
137 /* Item number of this auto-display item. */
138 int number;
139 /* Display format specified. */
140 struct format_data format;
141 /* Innermost block required by this expression when evaluated */
142 struct block *block;
143 /* Status of this display (enabled or disabled) */
144 int enabled_p;
147 /* Chain of expressions whose values should be displayed
148 automatically each time the program stops. */
150 static struct display *display_chain;
152 static int display_number;
154 /* Prototypes for exported functions. */
156 void output_command (char *, int);
158 void _initialize_printcmd (void);
160 /* Prototypes for local functions. */
162 static void do_one_display (struct display *);
165 /* Decode a format specification. *STRING_PTR should point to it.
166 OFORMAT and OSIZE are used as defaults for the format and size
167 if none are given in the format specification.
168 If OSIZE is zero, then the size field of the returned value
169 should be set only if a size is explicitly specified by the
170 user.
171 The structure returned describes all the data
172 found in the specification. In addition, *STRING_PTR is advanced
173 past the specification and past all whitespace following it. */
175 static struct format_data
176 decode_format (char **string_ptr, int oformat, int osize)
178 struct format_data val;
179 char *p = *string_ptr;
181 val.format = '?';
182 val.size = '?';
183 val.count = 1;
185 if (*p >= '0' && *p <= '9')
186 val.count = atoi (p);
187 while (*p >= '0' && *p <= '9')
188 p++;
190 /* Now process size or format letters that follow. */
192 while (1)
194 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
195 val.size = *p++;
196 else if (*p >= 'a' && *p <= 'z')
197 val.format = *p++;
198 else
199 break;
202 while (*p == ' ' || *p == '\t')
203 p++;
204 *string_ptr = p;
206 /* Set defaults for format and size if not specified. */
207 if (val.format == '?')
209 if (val.size == '?')
211 /* Neither has been specified. */
212 val.format = oformat;
213 val.size = osize;
215 else
216 /* If a size is specified, any format makes a reasonable
217 default except 'i'. */
218 val.format = oformat == 'i' ? 'x' : oformat;
220 else if (val.size == '?')
221 switch (val.format)
223 case 'a':
224 case 's':
225 /* Pick the appropriate size for an address. */
226 if (gdbarch_ptr_bit (current_gdbarch) == 64)
227 val.size = osize ? 'g' : osize;
228 else if (gdbarch_ptr_bit (current_gdbarch) == 32)
229 val.size = osize ? 'w' : osize;
230 else if (gdbarch_ptr_bit (current_gdbarch) == 16)
231 val.size = osize ? 'h' : osize;
232 else
233 /* Bad value for gdbarch_ptr_bit. */
234 internal_error (__FILE__, __LINE__,
235 _("failed internal consistency check"));
236 break;
237 case 'f':
238 /* Floating point has to be word or giantword. */
239 if (osize == 'w' || osize == 'g')
240 val.size = osize;
241 else
242 /* Default it to giantword if the last used size is not
243 appropriate. */
244 val.size = osize ? 'g' : osize;
245 break;
246 case 'c':
247 /* Characters default to one byte. */
248 val.size = osize ? 'b' : osize;
249 break;
250 default:
251 /* The default is the size most recently specified. */
252 val.size = osize;
255 return val;
258 /* Print value VAL on stream according to OPTIONS.
259 Do not end with a newline.
260 SIZE is the letter for the size of datum being printed.
261 This is used to pad hex numbers so they line up. SIZE is 0
262 for print / output and set for examine. */
264 static void
265 print_formatted (struct value *val, int size,
266 const struct value_print_options *options,
267 struct ui_file *stream)
269 struct type *type = check_typedef (value_type (val));
270 int len = TYPE_LENGTH (type);
272 if (VALUE_LVAL (val) == lval_memory)
273 next_address = VALUE_ADDRESS (val) + len;
275 if (size)
277 switch (options->format)
279 case 's':
281 struct type *elttype = value_type (val);
282 next_address = (VALUE_ADDRESS (val)
283 + val_print_string (elttype,
284 VALUE_ADDRESS (val), -1,
285 stream, options));
287 return;
289 case 'i':
290 /* We often wrap here if there are long symbolic names. */
291 wrap_here (" ");
292 next_address = (VALUE_ADDRESS (val)
293 + gdb_print_insn (VALUE_ADDRESS (val), stream,
294 &branch_delay_insns));
295 return;
299 if (options->format == 0 || options->format == 's'
300 || TYPE_CODE (type) == TYPE_CODE_REF
301 || TYPE_CODE (type) == TYPE_CODE_ARRAY
302 || TYPE_CODE (type) == TYPE_CODE_STRING
303 || TYPE_CODE (type) == TYPE_CODE_STRUCT
304 || TYPE_CODE (type) == TYPE_CODE_UNION
305 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
306 value_print (val, stream, options);
307 else
308 /* User specified format, so don't look to the the type to
309 tell us what to do. */
310 print_scalar_formatted (value_contents (val), type,
311 options, size, stream);
314 /* Return builtin floating point type of same length as TYPE.
315 If no such type is found, return TYPE itself. */
316 static struct type *
317 float_type_from_length (struct gdbarch *gdbarch, struct type *type)
319 const struct builtin_type *builtin = builtin_type (gdbarch);
320 unsigned int len = TYPE_LENGTH (type);
322 if (len == TYPE_LENGTH (builtin->builtin_float))
323 type = builtin->builtin_float;
324 else if (len == TYPE_LENGTH (builtin->builtin_double))
325 type = builtin->builtin_double;
326 else if (len == TYPE_LENGTH (builtin->builtin_long_double))
327 type = builtin->builtin_long_double;
329 return type;
332 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
333 according to OPTIONS and SIZE on STREAM.
334 Formats s and i are not supported at this level.
336 This is how the elements of an array or structure are printed
337 with a format. */
339 void
340 print_scalar_formatted (const void *valaddr, struct type *type,
341 const struct value_print_options *options,
342 int size, struct ui_file *stream)
344 LONGEST val_long = 0;
345 unsigned int len = TYPE_LENGTH (type);
346 enum bfd_endian byte_order = gdbarch_byte_order (current_gdbarch);
348 /* If we get here with a string format, try again without it. Go
349 all the way back to the language printers, which may call us
350 again. */
351 if (options->format == 's')
353 struct value_print_options opts = *options;
354 opts.format = 0;
355 opts.deref_ref = 0;
356 val_print (type, valaddr, 0, 0, stream, 0, &opts,
357 current_language);
358 return;
361 if (len > sizeof(LONGEST) &&
362 (TYPE_CODE (type) == TYPE_CODE_INT
363 || TYPE_CODE (type) == TYPE_CODE_ENUM))
365 switch (options->format)
367 case 'o':
368 print_octal_chars (stream, valaddr, len, byte_order);
369 return;
370 case 'u':
371 case 'd':
372 print_decimal_chars (stream, valaddr, len, byte_order);
373 return;
374 case 't':
375 print_binary_chars (stream, valaddr, len, byte_order);
376 return;
377 case 'x':
378 print_hex_chars (stream, valaddr, len, byte_order);
379 return;
380 case 'c':
381 print_char_chars (stream, type, valaddr, len, byte_order);
382 return;
383 default:
384 break;
388 if (options->format != 'f')
389 val_long = unpack_long (type, valaddr);
391 /* If the value is a pointer, and pointers and addresses are not the
392 same, then at this point, the value's length (in target bytes) is
393 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
394 if (TYPE_CODE (type) == TYPE_CODE_PTR)
395 len = gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT;
397 /* If we are printing it as unsigned, truncate it in case it is actually
398 a negative signed value (e.g. "print/u (short)-1" should print 65535
399 (if shorts are 16 bits) instead of 4294967295). */
400 if (options->format != 'd')
402 if (len < sizeof (LONGEST))
403 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
406 switch (options->format)
408 case 'x':
409 if (!size)
411 /* No size specified, like in print. Print varying # of digits. */
412 print_longest (stream, 'x', 1, val_long);
414 else
415 switch (size)
417 case 'b':
418 case 'h':
419 case 'w':
420 case 'g':
421 print_longest (stream, size, 1, val_long);
422 break;
423 default:
424 error (_("Undefined output size \"%c\"."), size);
426 break;
428 case 'd':
429 print_longest (stream, 'd', 1, val_long);
430 break;
432 case 'u':
433 print_longest (stream, 'u', 0, val_long);
434 break;
436 case 'o':
437 if (val_long)
438 print_longest (stream, 'o', 1, val_long);
439 else
440 fprintf_filtered (stream, "0");
441 break;
443 case 'a':
445 CORE_ADDR addr = unpack_pointer (type, valaddr);
446 print_address (addr, stream);
448 break;
450 case 'c':
452 struct value_print_options opts = *options;
453 opts.format = 0;
454 if (TYPE_UNSIGNED (type))
455 value_print (value_from_longest (builtin_type_true_unsigned_char,
456 val_long),
457 stream, &opts);
458 else
459 value_print (value_from_longest (builtin_type_true_char, val_long),
460 stream, &opts);
462 break;
464 case 'f':
465 type = float_type_from_length (current_gdbarch, type);
466 print_floating (valaddr, type, stream);
467 break;
469 case 0:
470 internal_error (__FILE__, __LINE__,
471 _("failed internal consistency check"));
473 case 't':
474 /* Binary; 't' stands for "two". */
476 char bits[8 * (sizeof val_long) + 1];
477 char buf[8 * (sizeof val_long) + 32];
478 char *cp = bits;
479 int width;
481 if (!size)
482 width = 8 * (sizeof val_long);
483 else
484 switch (size)
486 case 'b':
487 width = 8;
488 break;
489 case 'h':
490 width = 16;
491 break;
492 case 'w':
493 width = 32;
494 break;
495 case 'g':
496 width = 64;
497 break;
498 default:
499 error (_("Undefined output size \"%c\"."), size);
502 bits[width] = '\0';
503 while (width-- > 0)
505 bits[width] = (val_long & 1) ? '1' : '0';
506 val_long >>= 1;
508 if (!size)
510 while (*cp && *cp == '0')
511 cp++;
512 if (*cp == '\0')
513 cp--;
515 strcpy (buf, cp);
516 fputs_filtered (buf, stream);
518 break;
520 default:
521 error (_("Undefined output format \"%c\"."), options->format);
525 /* Specify default address for `x' command.
526 The `info lines' command uses this. */
528 void
529 set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr)
531 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
533 next_address = addr;
535 /* Make address available to the user as $_. */
536 set_internalvar (lookup_internalvar ("_"),
537 value_from_pointer (ptr_type, addr));
540 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
541 after LEADIN. Print nothing if no symbolic name is found nearby.
542 Optionally also print source file and line number, if available.
543 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
544 or to interpret it as a possible C++ name and convert it back to source
545 form. However note that DO_DEMANGLE can be overridden by the specific
546 settings of the demangle and asm_demangle variables. */
548 void
549 print_address_symbolic (CORE_ADDR addr, struct ui_file *stream,
550 int do_demangle, char *leadin)
552 char *name = NULL;
553 char *filename = NULL;
554 int unmapped = 0;
555 int offset = 0;
556 int line = 0;
558 /* Throw away both name and filename. */
559 struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
560 make_cleanup (free_current_contents, &filename);
562 if (build_address_symbolic (addr, do_demangle, &name, &offset,
563 &filename, &line, &unmapped))
565 do_cleanups (cleanup_chain);
566 return;
569 fputs_filtered (leadin, stream);
570 if (unmapped)
571 fputs_filtered ("<*", stream);
572 else
573 fputs_filtered ("<", stream);
574 fputs_filtered (name, stream);
575 if (offset != 0)
576 fprintf_filtered (stream, "+%u", (unsigned int) offset);
578 /* Append source filename and line number if desired. Give specific
579 line # of this addr, if we have it; else line # of the nearest symbol. */
580 if (print_symbol_filename && filename != NULL)
582 if (line != -1)
583 fprintf_filtered (stream, " at %s:%d", filename, line);
584 else
585 fprintf_filtered (stream, " in %s", filename);
587 if (unmapped)
588 fputs_filtered ("*>", stream);
589 else
590 fputs_filtered (">", stream);
592 do_cleanups (cleanup_chain);
595 /* Given an address ADDR return all the elements needed to print the
596 address in a symbolic form. NAME can be mangled or not depending
597 on DO_DEMANGLE (and also on the asm_demangle global variable,
598 manipulated via ''set print asm-demangle''). Return 0 in case of
599 success, when all the info in the OUT paramters is valid. Return 1
600 otherwise. */
602 build_address_symbolic (CORE_ADDR addr, /* IN */
603 int do_demangle, /* IN */
604 char **name, /* OUT */
605 int *offset, /* OUT */
606 char **filename, /* OUT */
607 int *line, /* OUT */
608 int *unmapped) /* OUT */
610 struct minimal_symbol *msymbol;
611 struct symbol *symbol;
612 CORE_ADDR name_location = 0;
613 struct obj_section *section = NULL;
614 char *name_temp = "";
616 /* Let's say it is mapped (not unmapped). */
617 *unmapped = 0;
619 /* Determine if the address is in an overlay, and whether it is
620 mapped. */
621 if (overlay_debugging)
623 section = find_pc_overlay (addr);
624 if (pc_in_unmapped_range (addr, section))
626 *unmapped = 1;
627 addr = overlay_mapped_address (addr, section);
631 /* First try to find the address in the symbol table, then
632 in the minsyms. Take the closest one. */
634 /* This is defective in the sense that it only finds text symbols. So
635 really this is kind of pointless--we should make sure that the
636 minimal symbols have everything we need (by changing that we could
637 save some memory, but for many debug format--ELF/DWARF or
638 anything/stabs--it would be inconvenient to eliminate those minimal
639 symbols anyway). */
640 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
641 symbol = find_pc_sect_function (addr, section);
643 if (symbol)
645 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
646 if (do_demangle || asm_demangle)
647 name_temp = SYMBOL_PRINT_NAME (symbol);
648 else
649 name_temp = SYMBOL_LINKAGE_NAME (symbol);
652 if (msymbol != NULL)
654 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
656 /* The msymbol is closer to the address than the symbol;
657 use the msymbol instead. */
658 symbol = 0;
659 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
660 if (do_demangle || asm_demangle)
661 name_temp = SYMBOL_PRINT_NAME (msymbol);
662 else
663 name_temp = SYMBOL_LINKAGE_NAME (msymbol);
666 if (symbol == NULL && msymbol == NULL)
667 return 1;
669 /* If the nearest symbol is too far away, don't print anything symbolic. */
671 /* For when CORE_ADDR is larger than unsigned int, we do math in
672 CORE_ADDR. But when we detect unsigned wraparound in the
673 CORE_ADDR math, we ignore this test and print the offset,
674 because addr+max_symbolic_offset has wrapped through the end
675 of the address space back to the beginning, giving bogus comparison. */
676 if (addr > name_location + max_symbolic_offset
677 && name_location + max_symbolic_offset > name_location)
678 return 1;
680 *offset = addr - name_location;
682 *name = xstrdup (name_temp);
684 if (print_symbol_filename)
686 struct symtab_and_line sal;
688 sal = find_pc_sect_line (addr, section, 0);
690 if (sal.symtab)
692 *filename = xstrdup (sal.symtab->filename);
693 *line = sal.line;
696 return 0;
700 /* Print address ADDR symbolically on STREAM.
701 First print it as a number. Then perhaps print
702 <SYMBOL + OFFSET> after the number. */
704 void
705 print_address (CORE_ADDR addr, struct ui_file *stream)
707 fputs_filtered (paddress (addr), stream);
708 print_address_symbolic (addr, stream, asm_demangle, " ");
711 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
712 controls whether to print the symbolic name "raw" or demangled.
713 Global setting "addressprint" controls whether to print hex address
714 or not. */
716 void
717 print_address_demangle (CORE_ADDR addr, struct ui_file *stream,
718 int do_demangle)
720 struct value_print_options opts;
721 get_user_print_options (&opts);
722 if (addr == 0)
724 fprintf_filtered (stream, "0");
726 else if (opts.addressprint)
728 fputs_filtered (paddress (addr), stream);
729 print_address_symbolic (addr, stream, do_demangle, " ");
731 else
733 print_address_symbolic (addr, stream, do_demangle, "");
738 /* These are the types that $__ will get after an examine command of one
739 of these sizes. */
741 static struct type *examine_i_type;
743 static struct type *examine_b_type;
744 static struct type *examine_h_type;
745 static struct type *examine_w_type;
746 static struct type *examine_g_type;
748 /* Examine data at address ADDR in format FMT.
749 Fetch it from memory and print on gdb_stdout. */
751 static void
752 do_examine (struct format_data fmt, CORE_ADDR addr)
754 char format = 0;
755 char size;
756 int count = 1;
757 struct type *val_type = NULL;
758 int i;
759 int maxelts;
760 struct value_print_options opts;
762 format = fmt.format;
763 size = fmt.size;
764 count = fmt.count;
765 next_address = addr;
767 /* String or instruction format implies fetch single bytes
768 regardless of the specified size. */
769 if (format == 's' || format == 'i')
770 size = 'b';
772 if (format == 'i')
773 val_type = examine_i_type;
774 else if (size == 'b')
775 val_type = examine_b_type;
776 else if (size == 'h')
777 val_type = examine_h_type;
778 else if (size == 'w')
779 val_type = examine_w_type;
780 else if (size == 'g')
781 val_type = examine_g_type;
783 maxelts = 8;
784 if (size == 'w')
785 maxelts = 4;
786 if (size == 'g')
787 maxelts = 2;
788 if (format == 's' || format == 'i')
789 maxelts = 1;
791 get_formatted_print_options (&opts, format);
793 /* Print as many objects as specified in COUNT, at most maxelts per line,
794 with the address of the next one at the start of each line. */
796 while (count > 0)
798 QUIT;
799 print_address (next_address, gdb_stdout);
800 printf_filtered (":");
801 for (i = maxelts;
802 i > 0 && count > 0;
803 i--, count--)
805 printf_filtered ("\t");
806 /* Note that print_formatted sets next_address for the next
807 object. */
808 last_examine_address = next_address;
810 if (last_examine_value)
811 value_free (last_examine_value);
813 /* The value to be displayed is not fetched greedily.
814 Instead, to avoid the possibility of a fetched value not
815 being used, its retrieval is delayed until the print code
816 uses it. When examining an instruction stream, the
817 disassembler will perform its own memory fetch using just
818 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
819 the disassembler be modified so that LAST_EXAMINE_VALUE
820 is left with the byte sequence from the last complete
821 instruction fetched from memory? */
822 last_examine_value = value_at_lazy (val_type, next_address);
824 if (last_examine_value)
825 release_value (last_examine_value);
827 print_formatted (last_examine_value, size, &opts, gdb_stdout);
829 /* Display any branch delay slots following the final insn. */
830 if (format == 'i' && count == 1)
831 count += branch_delay_insns;
833 printf_filtered ("\n");
834 gdb_flush (gdb_stdout);
838 static void
839 validate_format (struct format_data fmt, char *cmdname)
841 if (fmt.size != 0)
842 error (_("Size letters are meaningless in \"%s\" command."), cmdname);
843 if (fmt.count != 1)
844 error (_("Item count other than 1 is meaningless in \"%s\" command."),
845 cmdname);
846 if (fmt.format == 'i')
847 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
848 fmt.format, cmdname);
851 /* Evaluate string EXP as an expression in the current language and
852 print the resulting value. EXP may contain a format specifier as the
853 first argument ("/x myvar" for example, to print myvar in hex). */
855 static void
856 print_command_1 (char *exp, int inspect, int voidprint)
858 struct expression *expr;
859 struct cleanup *old_chain = 0;
860 char format = 0;
861 struct value *val;
862 struct format_data fmt;
863 int cleanup = 0;
865 if (exp && *exp == '/')
867 exp++;
868 fmt = decode_format (&exp, last_format, 0);
869 validate_format (fmt, "print");
870 last_format = format = fmt.format;
872 else
874 fmt.count = 1;
875 fmt.format = 0;
876 fmt.size = 0;
879 if (exp && *exp)
881 struct type *type;
882 expr = parse_expression (exp);
883 old_chain = make_cleanup (free_current_contents, &expr);
884 cleanup = 1;
885 val = evaluate_expression (expr);
887 else
888 val = access_value_history (0);
890 if (voidprint || (val && value_type (val) &&
891 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
893 struct value_print_options opts;
894 int histindex = record_latest_value (val);
896 if (histindex >= 0)
897 annotate_value_history_begin (histindex, value_type (val));
898 else
899 annotate_value_begin (value_type (val));
901 if (inspect)
902 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"",
903 exp, histindex);
904 else if (histindex >= 0)
905 printf_filtered ("$%d = ", histindex);
907 if (histindex >= 0)
908 annotate_value_history_value ();
910 get_formatted_print_options (&opts, format);
911 opts.inspect_it = inspect;
913 print_formatted (val, fmt.size, &opts, gdb_stdout);
914 printf_filtered ("\n");
916 if (histindex >= 0)
917 annotate_value_history_end ();
918 else
919 annotate_value_end ();
921 if (inspect)
922 printf_unfiltered ("\") )\030");
925 if (cleanup)
926 do_cleanups (old_chain);
929 static void
930 print_command (char *exp, int from_tty)
932 print_command_1 (exp, 0, 1);
935 /* Same as print, except in epoch, it gets its own window. */
936 static void
937 inspect_command (char *exp, int from_tty)
939 extern int epoch_interface;
941 print_command_1 (exp, epoch_interface, 1);
944 /* Same as print, except it doesn't print void results. */
945 static void
946 call_command (char *exp, int from_tty)
948 print_command_1 (exp, 0, 0);
951 void
952 output_command (char *exp, int from_tty)
954 struct expression *expr;
955 struct cleanup *old_chain;
956 char format = 0;
957 struct value *val;
958 struct format_data fmt;
959 struct value_print_options opts;
961 fmt.size = 0;
963 if (exp && *exp == '/')
965 exp++;
966 fmt = decode_format (&exp, 0, 0);
967 validate_format (fmt, "output");
968 format = fmt.format;
971 expr = parse_expression (exp);
972 old_chain = make_cleanup (free_current_contents, &expr);
974 val = evaluate_expression (expr);
976 annotate_value_begin (value_type (val));
978 get_formatted_print_options (&opts, format);
979 print_formatted (val, fmt.size, &opts, gdb_stdout);
981 annotate_value_end ();
983 wrap_here ("");
984 gdb_flush (gdb_stdout);
986 do_cleanups (old_chain);
989 static void
990 set_command (char *exp, int from_tty)
992 struct expression *expr = parse_expression (exp);
993 struct cleanup *old_chain =
994 make_cleanup (free_current_contents, &expr);
995 evaluate_expression (expr);
996 do_cleanups (old_chain);
999 static void
1000 sym_info (char *arg, int from_tty)
1002 struct minimal_symbol *msymbol;
1003 struct objfile *objfile;
1004 struct obj_section *osect;
1005 CORE_ADDR addr, sect_addr;
1006 int matches = 0;
1007 unsigned int offset;
1009 if (!arg)
1010 error_no_arg (_("address"));
1012 addr = parse_and_eval_address (arg);
1013 ALL_OBJSECTIONS (objfile, osect)
1015 /* Only process each object file once, even if there's a separate
1016 debug file. */
1017 if (objfile->separate_debug_objfile_backlink)
1018 continue;
1020 sect_addr = overlay_mapped_address (addr, osect);
1022 if (obj_section_addr (osect) <= sect_addr
1023 && sect_addr < obj_section_endaddr (osect)
1024 && (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, osect)))
1026 const char *obj_name, *mapped, *sec_name, *msym_name;
1027 char *loc_string;
1028 struct cleanup *old_chain;
1030 matches = 1;
1031 offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
1032 mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
1033 sec_name = osect->the_bfd_section->name;
1034 msym_name = SYMBOL_PRINT_NAME (msymbol);
1036 /* Don't print the offset if it is zero.
1037 We assume there's no need to handle i18n of "sym + offset". */
1038 if (offset)
1039 loc_string = xstrprintf ("%s + %u", msym_name, offset);
1040 else
1041 loc_string = xstrprintf ("%s", msym_name);
1043 /* Use a cleanup to free loc_string in case the user quits
1044 a pagination request inside printf_filtered. */
1045 old_chain = make_cleanup (xfree, loc_string);
1047 gdb_assert (osect->objfile && osect->objfile->name);
1048 obj_name = osect->objfile->name;
1050 if (MULTI_OBJFILE_P ())
1051 if (pc_in_unmapped_range (addr, osect))
1052 if (section_is_overlay (osect))
1053 printf_filtered (_("%s in load address range of "
1054 "%s overlay section %s of %s\n"),
1055 loc_string, mapped, sec_name, obj_name);
1056 else
1057 printf_filtered (_("%s in load address range of "
1058 "section %s of %s\n"),
1059 loc_string, sec_name, obj_name);
1060 else
1061 if (section_is_overlay (osect))
1062 printf_filtered (_("%s in %s overlay section %s of %s\n"),
1063 loc_string, mapped, sec_name, obj_name);
1064 else
1065 printf_filtered (_("%s in section %s of %s\n"),
1066 loc_string, sec_name, obj_name);
1067 else
1068 if (pc_in_unmapped_range (addr, osect))
1069 if (section_is_overlay (osect))
1070 printf_filtered (_("%s in load address range of %s overlay "
1071 "section %s\n"),
1072 loc_string, mapped, sec_name);
1073 else
1074 printf_filtered (_("%s in load address range of section %s\n"),
1075 loc_string, sec_name);
1076 else
1077 if (section_is_overlay (osect))
1078 printf_filtered (_("%s in %s overlay section %s\n"),
1079 loc_string, mapped, sec_name);
1080 else
1081 printf_filtered (_("%s in section %s\n"),
1082 loc_string, sec_name);
1084 do_cleanups (old_chain);
1087 if (matches == 0)
1088 printf_filtered (_("No symbol matches %s.\n"), arg);
1091 static void
1092 address_info (char *exp, int from_tty)
1094 struct symbol *sym;
1095 struct minimal_symbol *msymbol;
1096 long val;
1097 struct obj_section *section;
1098 CORE_ADDR load_addr;
1099 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
1100 if exp is a field of `this'. */
1102 if (exp == 0)
1103 error (_("Argument required."));
1105 sym = lookup_symbol (exp, get_selected_block (0), VAR_DOMAIN,
1106 &is_a_field_of_this);
1107 if (sym == NULL)
1109 if (is_a_field_of_this)
1111 printf_filtered ("Symbol \"");
1112 fprintf_symbol_filtered (gdb_stdout, exp,
1113 current_language->la_language, DMGL_ANSI);
1114 printf_filtered ("\" is a field of the local class variable ");
1115 if (current_language->la_language == language_objc)
1116 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1117 else
1118 printf_filtered ("`this'\n");
1119 return;
1122 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1124 if (msymbol != NULL)
1126 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1128 printf_filtered ("Symbol \"");
1129 fprintf_symbol_filtered (gdb_stdout, exp,
1130 current_language->la_language, DMGL_ANSI);
1131 printf_filtered ("\" is at ");
1132 fputs_filtered (paddress (load_addr), gdb_stdout);
1133 printf_filtered (" in a file compiled without debugging");
1134 section = SYMBOL_OBJ_SECTION (msymbol);
1135 if (section_is_overlay (section))
1137 load_addr = overlay_unmapped_address (load_addr, section);
1138 printf_filtered (",\n -- loaded at ");
1139 fputs_filtered (paddress (load_addr), gdb_stdout);
1140 printf_filtered (" in overlay section %s",
1141 section->the_bfd_section->name);
1143 printf_filtered (".\n");
1145 else
1146 error (_("No symbol \"%s\" in current context."), exp);
1147 return;
1150 printf_filtered ("Symbol \"");
1151 fprintf_symbol_filtered (gdb_stdout, SYMBOL_PRINT_NAME (sym),
1152 current_language->la_language, DMGL_ANSI);
1153 printf_filtered ("\" is ");
1154 val = SYMBOL_VALUE (sym);
1155 section = SYMBOL_OBJ_SECTION (sym);
1157 switch (SYMBOL_CLASS (sym))
1159 case LOC_CONST:
1160 case LOC_CONST_BYTES:
1161 printf_filtered ("constant");
1162 break;
1164 case LOC_LABEL:
1165 printf_filtered ("a label at address ");
1166 fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)),
1167 gdb_stdout);
1168 if (section_is_overlay (section))
1170 load_addr = overlay_unmapped_address (load_addr, section);
1171 printf_filtered (",\n -- loaded at ");
1172 fputs_filtered (paddress (load_addr), gdb_stdout);
1173 printf_filtered (" in overlay section %s",
1174 section->the_bfd_section->name);
1176 break;
1178 case LOC_COMPUTED:
1179 /* FIXME: cagney/2004-01-26: It should be possible to
1180 unconditionally call the SYMBOL_OPS method when available.
1181 Unfortunately DWARF 2 stores the frame-base (instead of the
1182 function) location in a function's symbol. Oops! For the
1183 moment enable this when/where applicable. */
1184 SYMBOL_OPS (sym)->describe_location (sym, gdb_stdout);
1185 break;
1187 case LOC_REGISTER:
1188 if (SYMBOL_IS_ARGUMENT (sym))
1189 printf_filtered (_("an argument in register %s"),
1190 gdbarch_register_name (current_gdbarch, val));
1191 else
1192 printf_filtered (_("a variable in register %s"),
1193 gdbarch_register_name (current_gdbarch, val));
1194 break;
1196 case LOC_STATIC:
1197 printf_filtered (_("static storage at address "));
1198 fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)),
1199 gdb_stdout);
1200 if (section_is_overlay (section))
1202 load_addr = overlay_unmapped_address (load_addr, section);
1203 printf_filtered (_(",\n -- loaded at "));
1204 fputs_filtered (paddress (load_addr), gdb_stdout);
1205 printf_filtered (_(" in overlay section %s"),
1206 section->the_bfd_section->name);
1208 break;
1210 case LOC_REGPARM_ADDR:
1211 printf_filtered (_("address of an argument in register %s"),
1212 gdbarch_register_name (current_gdbarch, val));
1213 break;
1215 case LOC_ARG:
1216 printf_filtered (_("an argument at offset %ld"), val);
1217 break;
1219 case LOC_LOCAL:
1220 printf_filtered (_("a local variable at frame offset %ld"), val);
1221 break;
1223 case LOC_REF_ARG:
1224 printf_filtered (_("a reference argument at offset %ld"), val);
1225 break;
1227 case LOC_TYPEDEF:
1228 printf_filtered (_("a typedef"));
1229 break;
1231 case LOC_BLOCK:
1232 printf_filtered (_("a function at address "));
1233 load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1234 fputs_filtered (paddress (load_addr), gdb_stdout);
1235 if (section_is_overlay (section))
1237 load_addr = overlay_unmapped_address (load_addr, section);
1238 printf_filtered (_(",\n -- loaded at "));
1239 fputs_filtered (paddress (load_addr), gdb_stdout);
1240 printf_filtered (_(" in overlay section %s"),
1241 section->the_bfd_section->name);
1243 break;
1245 case LOC_UNRESOLVED:
1247 struct minimal_symbol *msym;
1249 msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), NULL, NULL);
1250 if (msym == NULL)
1251 printf_filtered ("unresolved");
1252 else
1254 section = SYMBOL_OBJ_SECTION (msym);
1255 load_addr = SYMBOL_VALUE_ADDRESS (msym);
1257 if (section
1258 && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
1259 printf_filtered (_("a thread-local variable at offset %s "
1260 "in the thread-local storage for `%s'"),
1261 paddr_nz (load_addr), section->objfile->name);
1262 else
1264 printf_filtered (_("static storage at address "));
1265 fputs_filtered (paddress (load_addr), gdb_stdout);
1266 if (section_is_overlay (section))
1268 load_addr = overlay_unmapped_address (load_addr, section);
1269 printf_filtered (_(",\n -- loaded at "));
1270 fputs_filtered (paddress (load_addr), gdb_stdout);
1271 printf_filtered (_(" in overlay section %s"),
1272 section->the_bfd_section->name);
1277 break;
1279 case LOC_OPTIMIZED_OUT:
1280 printf_filtered (_("optimized out"));
1281 break;
1283 default:
1284 printf_filtered (_("of unknown (botched) type"));
1285 break;
1287 printf_filtered (".\n");
1291 static void
1292 x_command (char *exp, int from_tty)
1294 struct expression *expr;
1295 struct format_data fmt;
1296 struct cleanup *old_chain;
1297 struct value *val;
1299 fmt.format = last_format;
1300 fmt.size = last_size;
1301 fmt.count = 1;
1303 if (exp && *exp == '/')
1305 exp++;
1306 fmt = decode_format (&exp, last_format, last_size);
1309 /* If we have an expression, evaluate it and use it as the address. */
1311 if (exp != 0 && *exp != 0)
1313 expr = parse_expression (exp);
1314 /* Cause expression not to be there any more if this command is
1315 repeated with Newline. But don't clobber a user-defined
1316 command's definition. */
1317 if (from_tty)
1318 *exp = 0;
1319 old_chain = make_cleanup (free_current_contents, &expr);
1320 val = evaluate_expression (expr);
1321 if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
1322 val = value_ind (val);
1323 /* In rvalue contexts, such as this, functions are coerced into
1324 pointers to functions. This makes "x/i main" work. */
1325 if (/* last_format == 'i' && */
1326 TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
1327 && VALUE_LVAL (val) == lval_memory)
1328 next_address = VALUE_ADDRESS (val);
1329 else
1330 next_address = value_as_address (val);
1331 do_cleanups (old_chain);
1334 do_examine (fmt, next_address);
1336 /* If the examine succeeds, we remember its size and format for next
1337 time. */
1338 last_size = fmt.size;
1339 last_format = fmt.format;
1341 /* Set a couple of internal variables if appropriate. */
1342 if (last_examine_value)
1344 /* Make last address examined available to the user as $_. Use
1345 the correct pointer type. */
1346 struct type *pointer_type
1347 = lookup_pointer_type (value_type (last_examine_value));
1348 set_internalvar (lookup_internalvar ("_"),
1349 value_from_pointer (pointer_type,
1350 last_examine_address));
1352 /* Make contents of last address examined available to the user
1353 as $__. If the last value has not been fetched from memory
1354 then don't fetch it now; instead mark it by voiding the $__
1355 variable. */
1356 if (value_lazy (last_examine_value))
1357 set_internalvar (lookup_internalvar ("__"),
1358 allocate_value (builtin_type_void));
1359 else
1360 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1365 /* Add an expression to the auto-display chain.
1366 Specify the expression. */
1368 static void
1369 display_command (char *exp, int from_tty)
1371 struct format_data fmt;
1372 struct expression *expr;
1373 struct display *new;
1374 int display_it = 1;
1376 #if defined(TUI)
1377 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1378 `tui_version'. */
1379 if (tui_active && exp != NULL && *exp == '$')
1380 display_it = (tui_set_layout_for_display_command (exp) == TUI_FAILURE);
1381 #endif
1383 if (display_it)
1385 if (exp == 0)
1387 do_displays ();
1388 return;
1391 if (*exp == '/')
1393 exp++;
1394 fmt = decode_format (&exp, 0, 0);
1395 if (fmt.size && fmt.format == 0)
1396 fmt.format = 'x';
1397 if (fmt.format == 'i' || fmt.format == 's')
1398 fmt.size = 'b';
1400 else
1402 fmt.format = 0;
1403 fmt.size = 0;
1404 fmt.count = 0;
1407 innermost_block = NULL;
1408 expr = parse_expression (exp);
1410 new = (struct display *) xmalloc (sizeof (struct display));
1412 new->exp_string = xstrdup (exp);
1413 new->exp = expr;
1414 new->block = innermost_block;
1415 new->next = display_chain;
1416 new->number = ++display_number;
1417 new->format = fmt;
1418 new->enabled_p = 1;
1419 display_chain = new;
1421 if (from_tty && target_has_execution)
1422 do_one_display (new);
1424 dont_repeat ();
1428 static void
1429 free_display (struct display *d)
1431 xfree (d->exp_string);
1432 xfree (d->exp);
1433 xfree (d);
1436 /* Clear out the display_chain. Done when new symtabs are loaded,
1437 since this invalidates the types stored in many expressions. */
1439 void
1440 clear_displays (void)
1442 struct display *d;
1444 while ((d = display_chain) != NULL)
1446 display_chain = d->next;
1447 free_display (d);
1451 /* Delete the auto-display number NUM. */
1453 static void
1454 delete_display (int num)
1456 struct display *d1, *d;
1458 if (!display_chain)
1459 error (_("No display number %d."), num);
1461 if (display_chain->number == num)
1463 d1 = display_chain;
1464 display_chain = d1->next;
1465 free_display (d1);
1467 else
1468 for (d = display_chain;; d = d->next)
1470 if (d->next == 0)
1471 error (_("No display number %d."), num);
1472 if (d->next->number == num)
1474 d1 = d->next;
1475 d->next = d1->next;
1476 free_display (d1);
1477 break;
1482 /* Delete some values from the auto-display chain.
1483 Specify the element numbers. */
1485 static void
1486 undisplay_command (char *args, int from_tty)
1488 char *p = args;
1489 char *p1;
1490 int num;
1492 if (args == 0)
1494 if (query (_("Delete all auto-display expressions? ")))
1495 clear_displays ();
1496 dont_repeat ();
1497 return;
1500 while (*p)
1502 p1 = p;
1503 while (*p1 >= '0' && *p1 <= '9')
1504 p1++;
1505 if (*p1 && *p1 != ' ' && *p1 != '\t')
1506 error (_("Arguments must be display numbers."));
1508 num = atoi (p);
1510 delete_display (num);
1512 p = p1;
1513 while (*p == ' ' || *p == '\t')
1514 p++;
1516 dont_repeat ();
1519 /* Display a single auto-display.
1520 Do nothing if the display cannot be printed in the current context,
1521 or if the display is disabled. */
1523 static void
1524 do_one_display (struct display *d)
1526 int within_current_scope;
1528 if (d->enabled_p == 0)
1529 return;
1531 if (d->exp == NULL)
1533 volatile struct gdb_exception ex;
1534 TRY_CATCH (ex, RETURN_MASK_ALL)
1536 innermost_block = NULL;
1537 d->exp = parse_expression (d->exp_string);
1538 d->block = innermost_block;
1540 if (ex.reason < 0)
1542 /* Can't re-parse the expression. Disable this display item. */
1543 d->enabled_p = 0;
1544 warning (_("Unable to display \"%s\": %s"),
1545 d->exp_string, ex.message);
1546 return;
1550 if (d->block)
1551 within_current_scope = contained_in (get_selected_block (0), d->block);
1552 else
1553 within_current_scope = 1;
1554 if (!within_current_scope)
1555 return;
1557 current_display_number = d->number;
1559 annotate_display_begin ();
1560 printf_filtered ("%d", d->number);
1561 annotate_display_number_end ();
1562 printf_filtered (": ");
1563 if (d->format.size)
1565 CORE_ADDR addr;
1566 struct value *val;
1568 annotate_display_format ();
1570 printf_filtered ("x/");
1571 if (d->format.count != 1)
1572 printf_filtered ("%d", d->format.count);
1573 printf_filtered ("%c", d->format.format);
1574 if (d->format.format != 'i' && d->format.format != 's')
1575 printf_filtered ("%c", d->format.size);
1576 printf_filtered (" ");
1578 annotate_display_expression ();
1580 puts_filtered (d->exp_string);
1581 annotate_display_expression_end ();
1583 if (d->format.count != 1 || d->format.format == 'i')
1584 printf_filtered ("\n");
1585 else
1586 printf_filtered (" ");
1588 val = evaluate_expression (d->exp);
1589 addr = value_as_address (val);
1590 if (d->format.format == 'i')
1591 addr = gdbarch_addr_bits_remove (current_gdbarch, addr);
1593 annotate_display_value ();
1595 do_examine (d->format, addr);
1597 else
1599 struct value_print_options opts;
1601 annotate_display_format ();
1603 if (d->format.format)
1604 printf_filtered ("/%c ", d->format.format);
1606 annotate_display_expression ();
1608 puts_filtered (d->exp_string);
1609 annotate_display_expression_end ();
1611 printf_filtered (" = ");
1613 annotate_display_expression ();
1615 get_formatted_print_options (&opts, d->format.format);
1616 print_formatted (evaluate_expression (d->exp),
1617 d->format.size, &opts, gdb_stdout);
1618 printf_filtered ("\n");
1621 annotate_display_end ();
1623 gdb_flush (gdb_stdout);
1624 current_display_number = -1;
1627 /* Display all of the values on the auto-display chain which can be
1628 evaluated in the current scope. */
1630 void
1631 do_displays (void)
1633 struct display *d;
1635 for (d = display_chain; d; d = d->next)
1636 do_one_display (d);
1639 /* Delete the auto-display which we were in the process of displaying.
1640 This is done when there is an error or a signal. */
1642 void
1643 disable_display (int num)
1645 struct display *d;
1647 for (d = display_chain; d; d = d->next)
1648 if (d->number == num)
1650 d->enabled_p = 0;
1651 return;
1653 printf_unfiltered (_("No display number %d.\n"), num);
1656 void
1657 disable_current_display (void)
1659 if (current_display_number >= 0)
1661 disable_display (current_display_number);
1662 fprintf_unfiltered (gdb_stderr, _("\
1663 Disabling display %d to avoid infinite recursion.\n"),
1664 current_display_number);
1666 current_display_number = -1;
1669 static void
1670 display_info (char *ignore, int from_tty)
1672 struct display *d;
1674 if (!display_chain)
1675 printf_unfiltered (_("There are no auto-display expressions now.\n"));
1676 else
1677 printf_filtered (_("Auto-display expressions now in effect:\n\
1678 Num Enb Expression\n"));
1680 for (d = display_chain; d; d = d->next)
1682 printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]);
1683 if (d->format.size)
1684 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1685 d->format.format);
1686 else if (d->format.format)
1687 printf_filtered ("/%c ", d->format.format);
1688 puts_filtered (d->exp_string);
1689 if (d->block && !contained_in (get_selected_block (0), d->block))
1690 printf_filtered (_(" (cannot be evaluated in the current context)"));
1691 printf_filtered ("\n");
1692 gdb_flush (gdb_stdout);
1696 static void
1697 enable_display (char *args, int from_tty)
1699 char *p = args;
1700 char *p1;
1701 int num;
1702 struct display *d;
1704 if (p == 0)
1706 for (d = display_chain; d; d = d->next)
1707 d->enabled_p = 1;
1709 else
1710 while (*p)
1712 p1 = p;
1713 while (*p1 >= '0' && *p1 <= '9')
1714 p1++;
1715 if (*p1 && *p1 != ' ' && *p1 != '\t')
1716 error (_("Arguments must be display numbers."));
1718 num = atoi (p);
1720 for (d = display_chain; d; d = d->next)
1721 if (d->number == num)
1723 d->enabled_p = 1;
1724 goto win;
1726 printf_unfiltered (_("No display number %d.\n"), num);
1727 win:
1728 p = p1;
1729 while (*p == ' ' || *p == '\t')
1730 p++;
1734 static void
1735 disable_display_command (char *args, int from_tty)
1737 char *p = args;
1738 char *p1;
1739 struct display *d;
1741 if (p == 0)
1743 for (d = display_chain; d; d = d->next)
1744 d->enabled_p = 0;
1746 else
1747 while (*p)
1749 p1 = p;
1750 while (*p1 >= '0' && *p1 <= '9')
1751 p1++;
1752 if (*p1 && *p1 != ' ' && *p1 != '\t')
1753 error (_("Arguments must be display numbers."));
1755 disable_display (atoi (p));
1757 p = p1;
1758 while (*p == ' ' || *p == '\t')
1759 p++;
1763 /* Return 1 if D uses SOLIB (and will become dangling when SOLIB
1764 is unloaded), otherwise return 0. */
1766 static int
1767 display_uses_solib_p (const struct display *d,
1768 const struct so_list *solib)
1770 int endpos;
1771 struct expression *const exp = d->exp;
1772 const union exp_element *const elts = exp->elts;
1774 if (d->block != NULL
1775 && solib_contains_address_p (solib, d->block->startaddr))
1776 return 1;
1778 for (endpos = exp->nelts; endpos > 0; )
1780 int i, args, oplen = 0;
1782 exp->language_defn->la_exp_desc->operator_length (exp, endpos,
1783 &oplen, &args);
1784 gdb_assert (oplen > 0);
1786 i = endpos - oplen;
1787 if (elts[i].opcode == OP_VAR_VALUE)
1789 const struct block *const block = elts[i + 1].block;
1790 const struct symbol *const symbol = elts[i + 2].symbol;
1791 const struct obj_section *const section =
1792 SYMBOL_OBJ_SECTION (symbol);
1794 if (block != NULL
1795 && solib_contains_address_p (solib, block->startaddr))
1796 return 1;
1798 if (section && section->objfile == solib->objfile)
1799 return 1;
1801 endpos -= oplen;
1804 return 0;
1807 /* display_chain items point to blocks and expressions. Some expressions in
1808 turn may point to symbols.
1809 Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
1810 obstack_free'd when a shared library is unloaded.
1811 Clear pointers that are about to become dangling.
1812 Both .exp and .block fields will be restored next time we need to display
1813 an item by re-parsing .exp_string field in the new execution context. */
1815 static void
1816 clear_dangling_display_expressions (struct so_list *solib)
1818 struct display *d;
1819 struct objfile *objfile = NULL;
1821 for (d = display_chain; d; d = d->next)
1823 if (d->exp && display_uses_solib_p (d, solib))
1825 xfree (d->exp);
1826 d->exp = NULL;
1827 d->block = NULL;
1833 /* Print the value in stack frame FRAME of a variable specified by a
1834 struct symbol. NAME is the name to print; if NULL then VAR's print
1835 name will be used. STREAM is the ui_file on which to print the
1836 value. INDENT specifies the number of indent levels to print
1837 before printing the variable name. */
1839 void
1840 print_variable_and_value (const char *name, struct symbol *var,
1841 struct frame_info *frame,
1842 struct ui_file *stream, int indent)
1844 struct value *val;
1845 struct value_print_options opts;
1847 if (!name)
1848 name = SYMBOL_PRINT_NAME (var);
1850 fprintf_filtered (stream, "%s%s = ", n_spaces (2 * indent), name);
1852 val = read_var_value (var, frame);
1853 get_user_print_options (&opts);
1854 common_val_print (val, stream, indent, &opts, current_language);
1855 fprintf_filtered (stream, "\n");
1858 static void
1859 printf_command (char *arg, int from_tty)
1861 char *f = NULL;
1862 char *s = arg;
1863 char *string = NULL;
1864 struct value **val_args;
1865 char *substrings;
1866 char *current_substring;
1867 int nargs = 0;
1868 int allocated_args = 20;
1869 struct cleanup *old_cleanups;
1871 val_args = xmalloc (allocated_args * sizeof (struct value *));
1872 old_cleanups = make_cleanup (free_current_contents, &val_args);
1874 if (s == 0)
1875 error_no_arg (_("format-control string and values to print"));
1877 /* Skip white space before format string */
1878 while (*s == ' ' || *s == '\t')
1879 s++;
1881 /* A format string should follow, enveloped in double quotes. */
1882 if (*s++ != '"')
1883 error (_("Bad format string, missing '\"'."));
1885 /* Parse the format-control string and copy it into the string STRING,
1886 processing some kinds of escape sequence. */
1888 f = string = (char *) alloca (strlen (s) + 1);
1890 while (*s != '"')
1892 int c = *s++;
1893 switch (c)
1895 case '\0':
1896 error (_("Bad format string, non-terminated '\"'."));
1898 case '\\':
1899 switch (c = *s++)
1901 case '\\':
1902 *f++ = '\\';
1903 break;
1904 case 'a':
1905 *f++ = '\a';
1906 break;
1907 case 'b':
1908 *f++ = '\b';
1909 break;
1910 case 'f':
1911 *f++ = '\f';
1912 break;
1913 case 'n':
1914 *f++ = '\n';
1915 break;
1916 case 'r':
1917 *f++ = '\r';
1918 break;
1919 case 't':
1920 *f++ = '\t';
1921 break;
1922 case 'v':
1923 *f++ = '\v';
1924 break;
1925 case '"':
1926 *f++ = '"';
1927 break;
1928 default:
1929 /* ??? TODO: handle other escape sequences */
1930 error (_("Unrecognized escape character \\%c in format string."),
1933 break;
1935 default:
1936 *f++ = c;
1940 /* Skip over " and following space and comma. */
1941 s++;
1942 *f++ = '\0';
1943 while (*s == ' ' || *s == '\t')
1944 s++;
1946 if (*s != ',' && *s != 0)
1947 error (_("Invalid argument syntax"));
1949 if (*s == ',')
1950 s++;
1951 while (*s == ' ' || *s == '\t')
1952 s++;
1954 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1955 substrings = alloca (strlen (string) * 2);
1956 current_substring = substrings;
1959 /* Now scan the string for %-specs and see what kinds of args they want.
1960 argclass[I] classifies the %-specs so we can give printf_filtered
1961 something of the right size. */
1963 enum argclass
1965 int_arg, long_arg, long_long_arg, ptr_arg,
1966 string_arg, wide_string_arg, wide_char_arg,
1967 double_arg, long_double_arg, decfloat_arg
1969 enum argclass *argclass;
1970 enum argclass this_argclass;
1971 char *last_arg;
1972 int nargs_wanted;
1973 int i;
1975 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1976 nargs_wanted = 0;
1977 f = string;
1978 last_arg = string;
1979 while (*f)
1980 if (*f++ == '%')
1982 int seen_hash = 0, seen_zero = 0, lcount = 0, seen_prec = 0;
1983 int seen_space = 0, seen_plus = 0;
1984 int seen_big_l = 0, seen_h = 0, seen_big_h = 0;
1985 int seen_big_d = 0, seen_double_big_d = 0;
1986 int bad = 0;
1988 /* Check the validity of the format specifier, and work
1989 out what argument it expects. We only accept C89
1990 format strings, with the exception of long long (which
1991 we autoconf for). */
1993 /* Skip over "%%". */
1994 if (*f == '%')
1996 f++;
1997 continue;
2000 /* The first part of a format specifier is a set of flag
2001 characters. */
2002 while (strchr ("0-+ #", *f))
2004 if (*f == '#')
2005 seen_hash = 1;
2006 else if (*f == '0')
2007 seen_zero = 1;
2008 else if (*f == ' ')
2009 seen_space = 1;
2010 else if (*f == '+')
2011 seen_plus = 1;
2012 f++;
2015 /* The next part of a format specifier is a width. */
2016 while (strchr ("0123456789", *f))
2017 f++;
2019 /* The next part of a format specifier is a precision. */
2020 if (*f == '.')
2022 seen_prec = 1;
2023 f++;
2024 while (strchr ("0123456789", *f))
2025 f++;
2028 /* The next part of a format specifier is a length modifier. */
2029 if (*f == 'h')
2031 seen_h = 1;
2032 f++;
2034 else if (*f == 'l')
2036 f++;
2037 lcount++;
2038 if (*f == 'l')
2040 f++;
2041 lcount++;
2044 else if (*f == 'L')
2046 seen_big_l = 1;
2047 f++;
2049 /* Decimal32 modifier. */
2050 else if (*f == 'H')
2052 seen_big_h = 1;
2053 f++;
2055 /* Decimal64 and Decimal128 modifiers. */
2056 else if (*f == 'D')
2058 f++;
2060 /* Check for a Decimal128. */
2061 if (*f == 'D')
2063 f++;
2064 seen_double_big_d = 1;
2066 else
2067 seen_big_d = 1;
2070 switch (*f)
2072 case 'u':
2073 if (seen_hash)
2074 bad = 1;
2075 /* FALLTHROUGH */
2077 case 'o':
2078 case 'x':
2079 case 'X':
2080 if (seen_space || seen_plus)
2081 bad = 1;
2082 /* FALLTHROUGH */
2084 case 'd':
2085 case 'i':
2086 if (lcount == 0)
2087 this_argclass = int_arg;
2088 else if (lcount == 1)
2089 this_argclass = long_arg;
2090 else
2091 this_argclass = long_long_arg;
2093 if (seen_big_l)
2094 bad = 1;
2095 break;
2097 case 'c':
2098 this_argclass = lcount == 0 ? int_arg : wide_char_arg;
2099 if (lcount > 1 || seen_h || seen_big_l)
2100 bad = 1;
2101 if (seen_prec || seen_zero || seen_space || seen_plus)
2102 bad = 1;
2103 break;
2105 case 'p':
2106 this_argclass = ptr_arg;
2107 if (lcount || seen_h || seen_big_l)
2108 bad = 1;
2109 if (seen_prec || seen_zero || seen_space || seen_plus)
2110 bad = 1;
2111 break;
2113 case 's':
2114 this_argclass = lcount == 0 ? string_arg : wide_string_arg;
2115 if (lcount > 1 || seen_h || seen_big_l)
2116 bad = 1;
2117 if (seen_zero || seen_space || seen_plus)
2118 bad = 1;
2119 break;
2121 case 'e':
2122 case 'f':
2123 case 'g':
2124 case 'E':
2125 case 'G':
2126 if (seen_big_h || seen_big_d || seen_double_big_d)
2127 this_argclass = decfloat_arg;
2128 else if (seen_big_l)
2129 this_argclass = long_double_arg;
2130 else
2131 this_argclass = double_arg;
2133 if (lcount || seen_h)
2134 bad = 1;
2135 break;
2137 case '*':
2138 error (_("`*' not supported for precision or width in printf"));
2140 case 'n':
2141 error (_("Format specifier `n' not supported in printf"));
2143 case '\0':
2144 error (_("Incomplete format specifier at end of format string"));
2146 default:
2147 error (_("Unrecognized format specifier '%c' in printf"), *f);
2150 if (bad)
2151 error (_("Inappropriate modifiers to format specifier '%c' in printf"),
2152 *f);
2154 f++;
2156 if (lcount > 1 && USE_PRINTF_I64)
2158 /* Windows' printf does support long long, but not the usual way.
2159 Convert %lld to %I64d. */
2160 int length_before_ll = f - last_arg - 1 - lcount;
2161 strncpy (current_substring, last_arg, length_before_ll);
2162 strcpy (current_substring + length_before_ll, "I64");
2163 current_substring[length_before_ll + 3] =
2164 last_arg[length_before_ll + lcount];
2165 current_substring += length_before_ll + 4;
2167 else if (this_argclass == wide_string_arg
2168 || this_argclass == wide_char_arg)
2170 /* Convert %ls or %lc to %s. */
2171 int length_before_ls = f - last_arg - 2;
2172 strncpy (current_substring, last_arg, length_before_ls);
2173 strcpy (current_substring + length_before_ls, "s");
2174 current_substring += length_before_ls + 2;
2176 else
2178 strncpy (current_substring, last_arg, f - last_arg);
2179 current_substring += f - last_arg;
2181 *current_substring++ = '\0';
2182 last_arg = f;
2183 argclass[nargs_wanted++] = this_argclass;
2186 /* Now, parse all arguments and evaluate them.
2187 Store the VALUEs in VAL_ARGS. */
2189 while (*s != '\0')
2191 char *s1;
2192 if (nargs == allocated_args)
2193 val_args = (struct value **) xrealloc ((char *) val_args,
2194 (allocated_args *= 2)
2195 * sizeof (struct value *));
2196 s1 = s;
2197 val_args[nargs] = parse_to_comma_and_eval (&s1);
2199 nargs++;
2200 s = s1;
2201 if (*s == ',')
2202 s++;
2205 if (nargs != nargs_wanted)
2206 error (_("Wrong number of arguments for specified format-string"));
2208 /* Now actually print them. */
2209 current_substring = substrings;
2210 for (i = 0; i < nargs; i++)
2212 switch (argclass[i])
2214 case string_arg:
2216 gdb_byte *str;
2217 CORE_ADDR tem;
2218 int j;
2219 tem = value_as_address (val_args[i]);
2221 /* This is a %s argument. Find the length of the string. */
2222 for (j = 0;; j++)
2224 gdb_byte c;
2225 QUIT;
2226 read_memory (tem + j, &c, 1);
2227 if (c == 0)
2228 break;
2231 /* Copy the string contents into a string inside GDB. */
2232 str = (gdb_byte *) alloca (j + 1);
2233 if (j != 0)
2234 read_memory (tem, str, j);
2235 str[j] = 0;
2237 printf_filtered (current_substring, (char *) str);
2239 break;
2240 case wide_string_arg:
2242 gdb_byte *str;
2243 CORE_ADDR tem;
2244 int j;
2245 struct type *wctype = lookup_typename ("wchar_t", NULL, 0);
2246 int wcwidth = TYPE_LENGTH (wctype);
2247 gdb_byte *buf = alloca (wcwidth);
2248 struct obstack output;
2249 struct cleanup *inner_cleanup;
2251 tem = value_as_address (val_args[i]);
2253 /* This is a %s argument. Find the length of the string. */
2254 for (j = 0;; j += wcwidth)
2256 QUIT;
2257 read_memory (tem + j, buf, wcwidth);
2258 if (extract_unsigned_integer (buf, wcwidth) == 0)
2259 break;
2262 /* Copy the string contents into a string inside GDB. */
2263 str = (gdb_byte *) alloca (j + wcwidth);
2264 if (j != 0)
2265 read_memory (tem, str, j);
2266 memset (&str[j], 0, wcwidth);
2268 obstack_init (&output);
2269 inner_cleanup = make_cleanup_obstack_free (&output);
2271 convert_between_encodings (target_wide_charset (),
2272 host_charset (),
2273 str, j, wcwidth,
2274 &output, translit_char);
2275 obstack_grow_str0 (&output, "");
2277 printf_filtered (current_substring, obstack_base (&output));
2278 do_cleanups (inner_cleanup);
2280 break;
2281 case wide_char_arg:
2283 struct type *wctype = lookup_typename ("wchar_t", NULL, 0);
2284 struct type *valtype;
2285 struct obstack output;
2286 struct cleanup *inner_cleanup;
2287 const gdb_byte *bytes;
2289 valtype = value_type (val_args[i]);
2290 if (TYPE_LENGTH (valtype) != TYPE_LENGTH (wctype)
2291 || TYPE_CODE (valtype) != TYPE_CODE_INT)
2292 error (_("expected wchar_t argument for %%lc"));
2294 bytes = value_contents (val_args[i]);
2296 obstack_init (&output);
2297 inner_cleanup = make_cleanup_obstack_free (&output);
2299 convert_between_encodings (target_wide_charset (),
2300 host_charset (),
2301 bytes, TYPE_LENGTH (valtype),
2302 TYPE_LENGTH (valtype),
2303 &output, translit_char);
2304 obstack_grow_str0 (&output, "");
2306 printf_filtered (current_substring, obstack_base (&output));
2307 do_cleanups (inner_cleanup);
2309 break;
2310 case double_arg:
2312 struct type *type = value_type (val_args[i]);
2313 DOUBLEST val;
2314 int inv;
2316 /* If format string wants a float, unchecked-convert the value
2317 to floating point of the same size. */
2318 type = float_type_from_length (current_gdbarch, type);
2319 val = unpack_double (type, value_contents (val_args[i]), &inv);
2320 if (inv)
2321 error (_("Invalid floating value found in program."));
2323 printf_filtered (current_substring, (double) val);
2324 break;
2326 case long_double_arg:
2327 #ifdef HAVE_LONG_DOUBLE
2329 struct type *type = value_type (val_args[i]);
2330 DOUBLEST val;
2331 int inv;
2333 /* If format string wants a float, unchecked-convert the value
2334 to floating point of the same size. */
2335 type = float_type_from_length (current_gdbarch, type);
2336 val = unpack_double (type, value_contents (val_args[i]), &inv);
2337 if (inv)
2338 error (_("Invalid floating value found in program."));
2340 printf_filtered (current_substring, (long double) val);
2341 break;
2343 #else
2344 error (_("long double not supported in printf"));
2345 #endif
2346 case long_long_arg:
2347 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2349 long long val = value_as_long (val_args[i]);
2350 printf_filtered (current_substring, val);
2351 break;
2353 #else
2354 error (_("long long not supported in printf"));
2355 #endif
2356 case int_arg:
2358 int val = value_as_long (val_args[i]);
2359 printf_filtered (current_substring, val);
2360 break;
2362 case long_arg:
2364 long val = value_as_long (val_args[i]);
2365 printf_filtered (current_substring, val);
2366 break;
2369 /* Handles decimal floating values. */
2370 case decfloat_arg:
2372 const gdb_byte *param_ptr = value_contents (val_args[i]);
2373 #if defined (PRINTF_HAS_DECFLOAT)
2374 /* If we have native support for Decimal floating
2375 printing, handle it here. */
2376 printf_filtered (current_substring, param_ptr);
2377 #else
2379 /* As a workaround until vasprintf has native support for DFP
2380 we convert the DFP values to string and print them using
2381 the %s format specifier. */
2383 char *eos, *sos;
2384 int nnull_chars = 0;
2386 /* Parameter data. */
2387 struct type *param_type = value_type (val_args[i]);
2388 unsigned int param_len = TYPE_LENGTH (param_type);
2390 /* DFP output data. */
2391 struct value *dfp_value = NULL;
2392 gdb_byte *dfp_ptr;
2393 int dfp_len = 16;
2394 gdb_byte dec[16];
2395 struct type *dfp_type = NULL;
2396 char decstr[MAX_DECIMAL_STRING];
2398 /* Points to the end of the string so that we can go back
2399 and check for DFP length modifiers. */
2400 eos = current_substring + strlen (current_substring);
2402 /* Look for the float/double format specifier. */
2403 while (*eos != 'f' && *eos != 'e' && *eos != 'E'
2404 && *eos != 'g' && *eos != 'G')
2405 eos--;
2407 sos = eos;
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). */
2412 while (*--sos != '%')
2414 if (*sos == 'H')
2416 dfp_len = 4;
2417 dfp_type = builtin_type (current_gdbarch)->builtin_decfloat;
2419 else if (*sos == 'D' && *(sos - 1) == 'D')
2421 dfp_len = 16;
2422 dfp_type = builtin_type (current_gdbarch)->builtin_declong;
2423 sos--;
2425 else
2427 dfp_len = 8;
2428 dfp_type = builtin_type (current_gdbarch)->builtin_decdouble;
2432 /* Replace %Hf, %Df and %DDf with %s's. */
2433 *++sos = 's';
2435 /* Go through the whole format string and pull the correct
2436 number of chars back to compensate for the change in the
2437 format specifier. */
2438 while (nnull_chars < nargs - i)
2440 if (*eos == '\0')
2441 nnull_chars++;
2443 *++sos = *++eos;
2446 /* Conversion between different DFP types. */
2447 if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT)
2448 decimal_convert (param_ptr, param_len, dec, dfp_len);
2449 else
2450 /* If this is a non-trivial conversion, just output 0.
2451 A correct converted value can be displayed by explicitly
2452 casting to a DFP type. */
2453 decimal_from_string (dec, dfp_len, "0");
2455 dfp_value = value_from_decfloat (dfp_type, dec);
2457 dfp_ptr = (gdb_byte *) value_contents (dfp_value);
2459 decimal_to_string (dfp_ptr, dfp_len, decstr);
2461 /* Print the DFP value. */
2462 printf_filtered (current_substring, decstr);
2464 break;
2465 #endif
2468 case ptr_arg:
2470 /* We avoid the host's %p because pointers are too
2471 likely to be the wrong size. The only interesting
2472 modifier for %p is a width; extract that, and then
2473 handle %p as glibc would: %#x or a literal "(nil)". */
2475 char *p, *fmt, *fmt_p;
2476 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2477 long long val = value_as_long (val_args[i]);
2478 #else
2479 long val = value_as_long (val_args[i]);
2480 #endif
2482 fmt = alloca (strlen (current_substring) + 5);
2484 /* Copy up to the leading %. */
2485 p = current_substring;
2486 fmt_p = fmt;
2487 while (*p)
2489 int is_percent = (*p == '%');
2490 *fmt_p++ = *p++;
2491 if (is_percent)
2493 if (*p == '%')
2494 *fmt_p++ = *p++;
2495 else
2496 break;
2500 if (val != 0)
2501 *fmt_p++ = '#';
2503 /* Copy any width. */
2504 while (*p >= '0' && *p < '9')
2505 *fmt_p++ = *p++;
2507 gdb_assert (*p == 'p' && *(p + 1) == '\0');
2508 if (val != 0)
2510 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2511 *fmt_p++ = 'l';
2512 #endif
2513 *fmt_p++ = 'l';
2514 *fmt_p++ = 'x';
2515 *fmt_p++ = '\0';
2516 printf_filtered (fmt, val);
2518 else
2520 *fmt_p++ = 's';
2521 *fmt_p++ = '\0';
2522 printf_filtered (fmt, "(nil)");
2525 break;
2527 default:
2528 internal_error (__FILE__, __LINE__,
2529 _("failed internal consistency check"));
2531 /* Skip to the next substring. */
2532 current_substring += strlen (current_substring) + 1;
2534 /* Print the portion of the format string after the last argument. */
2535 puts_filtered (last_arg);
2537 do_cleanups (old_cleanups);
2540 void
2541 _initialize_printcmd (void)
2543 struct cmd_list_element *c;
2545 current_display_number = -1;
2547 observer_attach_solib_unloaded (clear_dangling_display_expressions);
2549 add_info ("address", address_info,
2550 _("Describe where symbol SYM is stored."));
2552 add_info ("symbol", sym_info, _("\
2553 Describe what symbol is at location ADDR.\n\
2554 Only for symbols with fixed locations (global or static scope)."));
2556 add_com ("x", class_vars, x_command, _("\
2557 Examine memory: x/FMT ADDRESS.\n\
2558 ADDRESS is an expression for the memory address to examine.\n\
2559 FMT is a repeat count followed by a format letter and a size letter.\n\
2560 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2561 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2562 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2563 The specified number of objects of the specified size are printed\n\
2564 according to the format.\n\n\
2565 Defaults for format and size letters are those previously used.\n\
2566 Default count is 1. Default address is following last thing printed\n\
2567 with this command or \"print\"."));
2569 #if 0
2570 add_com ("whereis", class_vars, whereis_command,
2571 _("Print line number and file of definition of variable."));
2572 #endif
2574 add_info ("display", display_info, _("\
2575 Expressions to display when program stops, with code numbers."));
2577 add_cmd ("undisplay", class_vars, undisplay_command, _("\
2578 Cancel some expressions to be displayed when program stops.\n\
2579 Arguments are the code numbers of the expressions to stop displaying.\n\
2580 No argument means cancel all automatic-display expressions.\n\
2581 \"delete display\" has the same effect as this command.\n\
2582 Do \"info display\" to see current list of code numbers."),
2583 &cmdlist);
2585 add_com ("display", class_vars, display_command, _("\
2586 Print value of expression EXP each time the program stops.\n\
2587 /FMT may be used before EXP as in the \"print\" command.\n\
2588 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2589 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2590 and examining is done as in the \"x\" command.\n\n\
2591 With no argument, display all currently requested auto-display expressions.\n\
2592 Use \"undisplay\" to cancel display requests previously made."));
2594 add_cmd ("display", class_vars, enable_display, _("\
2595 Enable some expressions to be displayed when program stops.\n\
2596 Arguments are the code numbers of the expressions to resume displaying.\n\
2597 No argument means enable all automatic-display expressions.\n\
2598 Do \"info display\" to see current list of code numbers."), &enablelist);
2600 add_cmd ("display", class_vars, disable_display_command, _("\
2601 Disable some expressions to be displayed when program stops.\n\
2602 Arguments are the code numbers of the expressions to stop displaying.\n\
2603 No argument means disable all automatic-display expressions.\n\
2604 Do \"info display\" to see current list of code numbers."), &disablelist);
2606 add_cmd ("display", class_vars, undisplay_command, _("\
2607 Cancel some expressions to be displayed when program stops.\n\
2608 Arguments are the code numbers of the expressions to stop displaying.\n\
2609 No argument means cancel all automatic-display expressions.\n\
2610 Do \"info display\" to see current list of code numbers."), &deletelist);
2612 add_com ("printf", class_vars, printf_command, _("\
2613 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2614 This is useful for formatted output in user-defined commands."));
2616 add_com ("output", class_vars, output_command, _("\
2617 Like \"print\" but don't put in value history and don't print newline.\n\
2618 This is useful in user-defined commands."));
2620 add_prefix_cmd ("set", class_vars, set_command, _("\
2621 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2622 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2623 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2624 with $), a register (a few standard names starting with $), or an actual\n\
2625 variable in the program being debugged. EXP is any valid expression.\n\
2626 Use \"set variable\" for variables with names identical to set subcommands.\n\
2628 With a subcommand, this command modifies parts of the gdb environment.\n\
2629 You can see these environment settings with the \"show\" command."),
2630 &setlist, "set ", 1, &cmdlist);
2631 if (dbx_commands)
2632 add_com ("assign", class_vars, set_command, _("\
2633 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2634 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2635 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2636 with $), a register (a few standard names starting with $), or an actual\n\
2637 variable in the program being debugged. EXP is any valid expression.\n\
2638 Use \"set variable\" for variables with names identical to set subcommands.\n\
2639 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2640 You can see these environment settings with the \"show\" command."));
2642 /* "call" is the same as "set", but handy for dbx users to call fns. */
2643 c = add_com ("call", class_vars, call_command, _("\
2644 Call a function in the program.\n\
2645 The argument is the function name and arguments, in the notation of the\n\
2646 current working language. The result is printed and saved in the value\n\
2647 history, if it is not void."));
2648 set_cmd_completer (c, expression_completer);
2650 add_cmd ("variable", class_vars, set_command, _("\
2651 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2652 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2653 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2654 with $), a register (a few standard names starting with $), or an actual\n\
2655 variable in the program being debugged. EXP is any valid expression.\n\
2656 This may usually be abbreviated to simply \"set\"."),
2657 &setlist);
2659 c = add_com ("print", class_vars, print_command, _("\
2660 Print value of expression EXP.\n\
2661 Variables accessible are those of the lexical environment of the selected\n\
2662 stack frame, plus all those whose scope is global or an entire file.\n\
2664 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2665 $$NUM refers to NUM'th value back from the last one.\n\
2666 Names starting with $ refer to registers (with the values they would have\n\
2667 if the program were to return to the stack frame now selected, restoring\n\
2668 all registers saved by frames farther in) or else to debugger\n\
2669 \"convenience\" variables (any such name not a known register).\n\
2670 Use assignment expressions to give values to convenience variables.\n\
2672 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2673 @ is a binary operator for treating consecutive data objects\n\
2674 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2675 element is FOO, whose second element is stored in the space following\n\
2676 where FOO is stored, etc. FOO must be an expression whose value\n\
2677 resides in memory.\n\
2679 EXP may be preceded with /FMT, where FMT is a format letter\n\
2680 but no count or size letter (see \"x\" command)."));
2681 set_cmd_completer (c, expression_completer);
2682 add_com_alias ("p", "print", class_vars, 1);
2684 c = add_com ("inspect", class_vars, inspect_command, _("\
2685 Same as \"print\" command, except that if you are running in the epoch\n\
2686 environment, the value is printed in its own window."));
2687 set_cmd_completer (c, expression_completer);
2689 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
2690 &max_symbolic_offset, _("\
2691 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2692 Show the largest offset that will be printed in <symbol+1234> form."), NULL,
2693 NULL,
2694 show_max_symbolic_offset,
2695 &setprintlist, &showprintlist);
2696 add_setshow_boolean_cmd ("symbol-filename", no_class,
2697 &print_symbol_filename, _("\
2698 Set printing of source filename and line number with <symbol>."), _("\
2699 Show printing of source filename and line number with <symbol>."), NULL,
2700 NULL,
2701 show_print_symbol_filename,
2702 &setprintlist, &showprintlist);
2704 /* For examine/instruction a single byte quantity is specified as
2705 the data. This avoids problems with value_at_lazy() requiring a
2706 valid data type (and rejecting VOID). */
2707 examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
2709 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2710 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2711 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2712 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);