* python/python-value.c (valpy_length): Remove #if.
[deliverable/binutils-gdb.git] / gdb / printcmd.c
1 /* Print values for GNU debugger GDB.
2
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 Free Software Foundation, Inc.
6
7 This file is part of GDB.
8
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.
13
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.
18
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/>. */
21
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
47 #ifdef TUI
48 #include "tui/tui.h" /* For tui_active et.al. */
49 #endif
50
51 #if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG)
52 # define USE_PRINTF_I64 1
53 # define PRINTF_HAS_LONG_LONG
54 #else
55 # define USE_PRINTF_I64 0
56 #endif
57
58 extern int asm_demangle; /* Whether to demangle syms in asm printouts */
59
60 struct format_data
61 {
62 int count;
63 char format;
64 char size;
65 };
66
67 /* Last specified output format. */
68
69 static char last_format = 'x';
70
71 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
72
73 static char last_size = 'w';
74
75 /* Default address to examine next. */
76
77 static CORE_ADDR next_address;
78
79 /* Number of delay instructions following current disassembled insn. */
80
81 static int branch_delay_insns;
82
83 /* Last address examined. */
84
85 static CORE_ADDR last_examine_address;
86
87 /* Contents of last address examined.
88 This is not valid past the end of the `x' command! */
89
90 static struct value *last_examine_value;
91
92 /* Largest offset between a symbolic value and an address, that will be
93 printed as `0x1234 <symbol+offset>'. */
94
95 static unsigned int max_symbolic_offset = UINT_MAX;
96 static void
97 show_max_symbolic_offset (struct ui_file *file, int from_tty,
98 struct cmd_list_element *c, const char *value)
99 {
100 fprintf_filtered (file, _("\
101 The largest offset that will be printed in <symbol+1234> form is %s.\n"),
102 value);
103 }
104
105 /* Append the source filename and linenumber of the symbol when
106 printing a symbolic value as `<symbol at filename:linenum>' if set. */
107 static int print_symbol_filename = 0;
108 static void
109 show_print_symbol_filename (struct ui_file *file, int from_tty,
110 struct cmd_list_element *c, const char *value)
111 {
112 fprintf_filtered (file, _("\
113 Printing of source filename and line number with <symbol> is %s.\n"),
114 value);
115 }
116
117 /* Number of auto-display expression currently being displayed.
118 So that we can disable it if we get an error or a signal within it.
119 -1 when not doing one. */
120
121 int current_display_number;
122
123 struct display
124 {
125 /* Chain link to next auto-display item. */
126 struct display *next;
127 /* Expression to be evaluated and displayed. */
128 struct expression *exp;
129 /* Item number of this auto-display item. */
130 int number;
131 /* Display format specified. */
132 struct format_data format;
133 /* Innermost block required by this expression when evaluated */
134 struct block *block;
135 /* Status of this display (enabled or disabled) */
136 int enabled_p;
137 };
138
139 /* Chain of expressions whose values should be displayed
140 automatically each time the program stops. */
141
142 static struct display *display_chain;
143
144 static int display_number;
145
146 /* Prototypes for exported functions. */
147
148 void output_command (char *, int);
149
150 void _initialize_printcmd (void);
151
152 /* Prototypes for local functions. */
153
154 static void do_one_display (struct display *);
155 \f
156
157 /* Decode a format specification. *STRING_PTR should point to it.
158 OFORMAT and OSIZE are used as defaults for the format and size
159 if none are given in the format specification.
160 If OSIZE is zero, then the size field of the returned value
161 should be set only if a size is explicitly specified by the
162 user.
163 The structure returned describes all the data
164 found in the specification. In addition, *STRING_PTR is advanced
165 past the specification and past all whitespace following it. */
166
167 static struct format_data
168 decode_format (char **string_ptr, int oformat, int osize)
169 {
170 struct format_data val;
171 char *p = *string_ptr;
172
173 val.format = '?';
174 val.size = '?';
175 val.count = 1;
176
177 if (*p >= '0' && *p <= '9')
178 val.count = atoi (p);
179 while (*p >= '0' && *p <= '9')
180 p++;
181
182 /* Now process size or format letters that follow. */
183
184 while (1)
185 {
186 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
187 val.size = *p++;
188 else if (*p >= 'a' && *p <= 'z')
189 val.format = *p++;
190 else
191 break;
192 }
193
194 while (*p == ' ' || *p == '\t')
195 p++;
196 *string_ptr = p;
197
198 /* Set defaults for format and size if not specified. */
199 if (val.format == '?')
200 {
201 if (val.size == '?')
202 {
203 /* Neither has been specified. */
204 val.format = oformat;
205 val.size = osize;
206 }
207 else
208 /* If a size is specified, any format makes a reasonable
209 default except 'i'. */
210 val.format = oformat == 'i' ? 'x' : oformat;
211 }
212 else if (val.size == '?')
213 switch (val.format)
214 {
215 case 'a':
216 case 's':
217 /* Pick the appropriate size for an address. */
218 if (gdbarch_ptr_bit (current_gdbarch) == 64)
219 val.size = osize ? 'g' : osize;
220 else if (gdbarch_ptr_bit (current_gdbarch) == 32)
221 val.size = osize ? 'w' : osize;
222 else if (gdbarch_ptr_bit (current_gdbarch) == 16)
223 val.size = osize ? 'h' : osize;
224 else
225 /* Bad value for gdbarch_ptr_bit. */
226 internal_error (__FILE__, __LINE__,
227 _("failed internal consistency check"));
228 break;
229 case 'f':
230 /* Floating point has to be word or giantword. */
231 if (osize == 'w' || osize == 'g')
232 val.size = osize;
233 else
234 /* Default it to giantword if the last used size is not
235 appropriate. */
236 val.size = osize ? 'g' : osize;
237 break;
238 case 'c':
239 /* Characters default to one byte. */
240 val.size = osize ? 'b' : osize;
241 break;
242 default:
243 /* The default is the size most recently specified. */
244 val.size = osize;
245 }
246
247 return val;
248 }
249 \f
250 /* Print value VAL on stream according to OPTIONS.
251 Do not end with a newline.
252 SIZE is the letter for the size of datum being printed.
253 This is used to pad hex numbers so they line up. SIZE is 0
254 for print / output and set for examine. */
255
256 static void
257 print_formatted (struct value *val, int size,
258 const struct value_print_options *options,
259 struct ui_file *stream)
260 {
261 struct type *type = check_typedef (value_type (val));
262 int len = TYPE_LENGTH (type);
263
264 if (VALUE_LVAL (val) == lval_memory)
265 next_address = VALUE_ADDRESS (val) + len;
266
267 if (size)
268 {
269 switch (options->format)
270 {
271 case 's':
272 /* FIXME: Need to handle wchar_t's here... */
273 next_address = VALUE_ADDRESS (val)
274 + val_print_string (VALUE_ADDRESS (val), -1, 1, stream,
275 options);
276 return;
277
278 case 'i':
279 /* We often wrap here if there are long symbolic names. */
280 wrap_here (" ");
281 next_address = (VALUE_ADDRESS (val)
282 + gdb_print_insn (VALUE_ADDRESS (val), stream,
283 &branch_delay_insns));
284 return;
285 }
286 }
287
288 if (options->format == 0 || options->format == 's'
289 || TYPE_CODE (type) == TYPE_CODE_REF
290 || TYPE_CODE (type) == TYPE_CODE_ARRAY
291 || TYPE_CODE (type) == TYPE_CODE_STRING
292 || TYPE_CODE (type) == TYPE_CODE_STRUCT
293 || TYPE_CODE (type) == TYPE_CODE_UNION
294 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
295 value_print (val, stream, options);
296 else
297 /* User specified format, so don't look to the the type to
298 tell us what to do. */
299 print_scalar_formatted (value_contents (val), type,
300 options, size, stream);
301 }
302
303 /* Return builtin floating point type of same length as TYPE.
304 If no such type is found, return TYPE itself. */
305 static struct type *
306 float_type_from_length (struct gdbarch *gdbarch, struct type *type)
307 {
308 const struct builtin_type *builtin = builtin_type (gdbarch);
309 unsigned int len = TYPE_LENGTH (type);
310
311 if (len == TYPE_LENGTH (builtin->builtin_float))
312 type = builtin->builtin_float;
313 else if (len == TYPE_LENGTH (builtin->builtin_double))
314 type = builtin->builtin_double;
315 else if (len == TYPE_LENGTH (builtin->builtin_long_double))
316 type = builtin->builtin_long_double;
317
318 return type;
319 }
320
321 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
322 according to OPTIONS and SIZE on STREAM.
323 Formats s and i are not supported at this level.
324
325 This is how the elements of an array or structure are printed
326 with a format. */
327
328 void
329 print_scalar_formatted (const void *valaddr, struct type *type,
330 const struct value_print_options *options,
331 int size, struct ui_file *stream)
332 {
333 LONGEST val_long = 0;
334 unsigned int len = TYPE_LENGTH (type);
335 enum bfd_endian byte_order = gdbarch_byte_order (current_gdbarch);
336
337 /* If we get here with a string format, try again without it. Go
338 all the way back to the language printers, which may call us
339 again. */
340 if (options->format == 's')
341 {
342 struct value_print_options opts = *options;
343 opts.format = 0;
344 opts.deref_ref = 0;
345 val_print (type, valaddr, 0, 0, stream, 0, &opts,
346 current_language);
347 return;
348 }
349
350 if (len > sizeof(LONGEST) &&
351 (TYPE_CODE (type) == TYPE_CODE_INT
352 || TYPE_CODE (type) == TYPE_CODE_ENUM))
353 {
354 switch (options->format)
355 {
356 case 'o':
357 print_octal_chars (stream, valaddr, len, byte_order);
358 return;
359 case 'u':
360 case 'd':
361 print_decimal_chars (stream, valaddr, len, byte_order);
362 return;
363 case 't':
364 print_binary_chars (stream, valaddr, len, byte_order);
365 return;
366 case 'x':
367 print_hex_chars (stream, valaddr, len, byte_order);
368 return;
369 case 'c':
370 print_char_chars (stream, valaddr, len, byte_order);
371 return;
372 default:
373 break;
374 };
375 }
376
377 if (options->format != 'f')
378 val_long = unpack_long (type, valaddr);
379
380 /* If the value is a pointer, and pointers and addresses are not the
381 same, then at this point, the value's length (in target bytes) is
382 gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
383 if (TYPE_CODE (type) == TYPE_CODE_PTR)
384 len = gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT;
385
386 /* If we are printing it as unsigned, truncate it in case it is actually
387 a negative signed value (e.g. "print/u (short)-1" should print 65535
388 (if shorts are 16 bits) instead of 4294967295). */
389 if (options->format != 'd')
390 {
391 if (len < sizeof (LONGEST))
392 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
393 }
394
395 switch (options->format)
396 {
397 case 'x':
398 if (!size)
399 {
400 /* No size specified, like in print. Print varying # of digits. */
401 print_longest (stream, 'x', 1, val_long);
402 }
403 else
404 switch (size)
405 {
406 case 'b':
407 case 'h':
408 case 'w':
409 case 'g':
410 print_longest (stream, size, 1, val_long);
411 break;
412 default:
413 error (_("Undefined output size \"%c\"."), size);
414 }
415 break;
416
417 case 'd':
418 print_longest (stream, 'd', 1, val_long);
419 break;
420
421 case 'u':
422 print_longest (stream, 'u', 0, val_long);
423 break;
424
425 case 'o':
426 if (val_long)
427 print_longest (stream, 'o', 1, val_long);
428 else
429 fprintf_filtered (stream, "0");
430 break;
431
432 case 'a':
433 {
434 CORE_ADDR addr = unpack_pointer (type, valaddr);
435 print_address (addr, stream);
436 }
437 break;
438
439 case 'c':
440 {
441 struct value_print_options opts = *options;
442 opts.format = 0;
443 if (TYPE_UNSIGNED (type))
444 value_print (value_from_longest (builtin_type_true_unsigned_char,
445 val_long),
446 stream, &opts);
447 else
448 value_print (value_from_longest (builtin_type_true_char, val_long),
449 stream, &opts);
450 }
451 break;
452
453 case 'f':
454 type = float_type_from_length (current_gdbarch, type);
455 print_floating (valaddr, type, stream);
456 break;
457
458 case 0:
459 internal_error (__FILE__, __LINE__,
460 _("failed internal consistency check"));
461
462 case 't':
463 /* Binary; 't' stands for "two". */
464 {
465 char bits[8 * (sizeof val_long) + 1];
466 char buf[8 * (sizeof val_long) + 32];
467 char *cp = bits;
468 int width;
469
470 if (!size)
471 width = 8 * (sizeof val_long);
472 else
473 switch (size)
474 {
475 case 'b':
476 width = 8;
477 break;
478 case 'h':
479 width = 16;
480 break;
481 case 'w':
482 width = 32;
483 break;
484 case 'g':
485 width = 64;
486 break;
487 default:
488 error (_("Undefined output size \"%c\"."), size);
489 }
490
491 bits[width] = '\0';
492 while (width-- > 0)
493 {
494 bits[width] = (val_long & 1) ? '1' : '0';
495 val_long >>= 1;
496 }
497 if (!size)
498 {
499 while (*cp && *cp == '0')
500 cp++;
501 if (*cp == '\0')
502 cp--;
503 }
504 strcpy (buf, cp);
505 fputs_filtered (buf, stream);
506 }
507 break;
508
509 default:
510 error (_("Undefined output format \"%c\"."), options->format);
511 }
512 }
513
514 /* Specify default address for `x' command.
515 The `info lines' command uses this. */
516
517 void
518 set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr)
519 {
520 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
521
522 next_address = addr;
523
524 /* Make address available to the user as $_. */
525 set_internalvar (lookup_internalvar ("_"),
526 value_from_pointer (ptr_type, addr));
527 }
528
529 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
530 after LEADIN. Print nothing if no symbolic name is found nearby.
531 Optionally also print source file and line number, if available.
532 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
533 or to interpret it as a possible C++ name and convert it back to source
534 form. However note that DO_DEMANGLE can be overridden by the specific
535 settings of the demangle and asm_demangle variables. */
536
537 void
538 print_address_symbolic (CORE_ADDR addr, struct ui_file *stream,
539 int do_demangle, char *leadin)
540 {
541 char *name = NULL;
542 char *filename = NULL;
543 int unmapped = 0;
544 int offset = 0;
545 int line = 0;
546
547 /* Throw away both name and filename. */
548 struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
549 make_cleanup (free_current_contents, &filename);
550
551 if (build_address_symbolic (addr, do_demangle, &name, &offset,
552 &filename, &line, &unmapped))
553 {
554 do_cleanups (cleanup_chain);
555 return;
556 }
557
558 fputs_filtered (leadin, stream);
559 if (unmapped)
560 fputs_filtered ("<*", stream);
561 else
562 fputs_filtered ("<", stream);
563 fputs_filtered (name, stream);
564 if (offset != 0)
565 fprintf_filtered (stream, "+%u", (unsigned int) offset);
566
567 /* Append source filename and line number if desired. Give specific
568 line # of this addr, if we have it; else line # of the nearest symbol. */
569 if (print_symbol_filename && filename != NULL)
570 {
571 if (line != -1)
572 fprintf_filtered (stream, " at %s:%d", filename, line);
573 else
574 fprintf_filtered (stream, " in %s", filename);
575 }
576 if (unmapped)
577 fputs_filtered ("*>", stream);
578 else
579 fputs_filtered (">", stream);
580
581 do_cleanups (cleanup_chain);
582 }
583
584 /* Given an address ADDR return all the elements needed to print the
585 address in a symbolic form. NAME can be mangled or not depending
586 on DO_DEMANGLE (and also on the asm_demangle global variable,
587 manipulated via ''set print asm-demangle''). Return 0 in case of
588 success, when all the info in the OUT paramters is valid. Return 1
589 otherwise. */
590 int
591 build_address_symbolic (CORE_ADDR addr, /* IN */
592 int do_demangle, /* IN */
593 char **name, /* OUT */
594 int *offset, /* OUT */
595 char **filename, /* OUT */
596 int *line, /* OUT */
597 int *unmapped) /* OUT */
598 {
599 struct minimal_symbol *msymbol;
600 struct symbol *symbol;
601 CORE_ADDR name_location = 0;
602 struct obj_section *section = NULL;
603 char *name_temp = "";
604
605 /* Let's say it is unmapped. */
606 *unmapped = 0;
607
608 /* Determine if the address is in an overlay, and whether it is
609 mapped. */
610 if (overlay_debugging)
611 {
612 section = find_pc_overlay (addr);
613 if (pc_in_unmapped_range (addr, section))
614 {
615 *unmapped = 1;
616 addr = overlay_mapped_address (addr, section);
617 }
618 }
619
620 /* First try to find the address in the symbol table, then
621 in the minsyms. Take the closest one. */
622
623 /* This is defective in the sense that it only finds text symbols. So
624 really this is kind of pointless--we should make sure that the
625 minimal symbols have everything we need (by changing that we could
626 save some memory, but for many debug format--ELF/DWARF or
627 anything/stabs--it would be inconvenient to eliminate those minimal
628 symbols anyway). */
629 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
630 symbol = find_pc_sect_function (addr, section);
631
632 if (symbol)
633 {
634 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
635 if (do_demangle || asm_demangle)
636 name_temp = SYMBOL_PRINT_NAME (symbol);
637 else
638 name_temp = SYMBOL_LINKAGE_NAME (symbol);
639 }
640
641 if (msymbol != NULL)
642 {
643 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
644 {
645 /* The msymbol is closer to the address than the symbol;
646 use the msymbol instead. */
647 symbol = 0;
648 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
649 if (do_demangle || asm_demangle)
650 name_temp = SYMBOL_PRINT_NAME (msymbol);
651 else
652 name_temp = SYMBOL_LINKAGE_NAME (msymbol);
653 }
654 }
655 if (symbol == NULL && msymbol == NULL)
656 return 1;
657
658 /* If the nearest symbol is too far away, don't print anything symbolic. */
659
660 /* For when CORE_ADDR is larger than unsigned int, we do math in
661 CORE_ADDR. But when we detect unsigned wraparound in the
662 CORE_ADDR math, we ignore this test and print the offset,
663 because addr+max_symbolic_offset has wrapped through the end
664 of the address space back to the beginning, giving bogus comparison. */
665 if (addr > name_location + max_symbolic_offset
666 && name_location + max_symbolic_offset > name_location)
667 return 1;
668
669 *offset = addr - name_location;
670
671 *name = xstrdup (name_temp);
672
673 if (print_symbol_filename)
674 {
675 struct symtab_and_line sal;
676
677 sal = find_pc_sect_line (addr, section, 0);
678
679 if (sal.symtab)
680 {
681 *filename = xstrdup (sal.symtab->filename);
682 *line = sal.line;
683 }
684 }
685 return 0;
686 }
687
688
689 /* Print address ADDR symbolically on STREAM.
690 First print it as a number. Then perhaps print
691 <SYMBOL + OFFSET> after the number. */
692
693 void
694 print_address (CORE_ADDR addr, struct ui_file *stream)
695 {
696 fputs_filtered (paddress (addr), stream);
697 print_address_symbolic (addr, stream, asm_demangle, " ");
698 }
699
700 /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
701 controls whether to print the symbolic name "raw" or demangled.
702 Global setting "addressprint" controls whether to print hex address
703 or not. */
704
705 void
706 print_address_demangle (CORE_ADDR addr, struct ui_file *stream,
707 int do_demangle)
708 {
709 struct value_print_options opts;
710 get_user_print_options (&opts);
711 if (addr == 0)
712 {
713 fprintf_filtered (stream, "0");
714 }
715 else if (opts.addressprint)
716 {
717 fputs_filtered (paddress (addr), stream);
718 print_address_symbolic (addr, stream, do_demangle, " ");
719 }
720 else
721 {
722 print_address_symbolic (addr, stream, do_demangle, "");
723 }
724 }
725 \f
726
727 /* These are the types that $__ will get after an examine command of one
728 of these sizes. */
729
730 static struct type *examine_i_type;
731
732 static struct type *examine_b_type;
733 static struct type *examine_h_type;
734 static struct type *examine_w_type;
735 static struct type *examine_g_type;
736
737 /* Examine data at address ADDR in format FMT.
738 Fetch it from memory and print on gdb_stdout. */
739
740 static void
741 do_examine (struct format_data fmt, CORE_ADDR addr)
742 {
743 char format = 0;
744 char size;
745 int count = 1;
746 struct type *val_type = NULL;
747 int i;
748 int maxelts;
749 struct value_print_options opts;
750
751 format = fmt.format;
752 size = fmt.size;
753 count = fmt.count;
754 next_address = addr;
755
756 /* String or instruction format implies fetch single bytes
757 regardless of the specified size. */
758 if (format == 's' || format == 'i')
759 size = 'b';
760
761 if (format == 'i')
762 val_type = examine_i_type;
763 else if (size == 'b')
764 val_type = examine_b_type;
765 else if (size == 'h')
766 val_type = examine_h_type;
767 else if (size == 'w')
768 val_type = examine_w_type;
769 else if (size == 'g')
770 val_type = examine_g_type;
771
772 maxelts = 8;
773 if (size == 'w')
774 maxelts = 4;
775 if (size == 'g')
776 maxelts = 2;
777 if (format == 's' || format == 'i')
778 maxelts = 1;
779
780 get_formatted_print_options (&opts, format);
781
782 /* Print as many objects as specified in COUNT, at most maxelts per line,
783 with the address of the next one at the start of each line. */
784
785 while (count > 0)
786 {
787 QUIT;
788 print_address (next_address, gdb_stdout);
789 printf_filtered (":");
790 for (i = maxelts;
791 i > 0 && count > 0;
792 i--, count--)
793 {
794 printf_filtered ("\t");
795 /* Note that print_formatted sets next_address for the next
796 object. */
797 last_examine_address = next_address;
798
799 if (last_examine_value)
800 value_free (last_examine_value);
801
802 /* The value to be displayed is not fetched greedily.
803 Instead, to avoid the possibility of a fetched value not
804 being used, its retrieval is delayed until the print code
805 uses it. When examining an instruction stream, the
806 disassembler will perform its own memory fetch using just
807 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
808 the disassembler be modified so that LAST_EXAMINE_VALUE
809 is left with the byte sequence from the last complete
810 instruction fetched from memory? */
811 last_examine_value = value_at_lazy (val_type, next_address);
812
813 if (last_examine_value)
814 release_value (last_examine_value);
815
816 print_formatted (last_examine_value, size, &opts, gdb_stdout);
817
818 /* Display any branch delay slots following the final insn. */
819 if (format == 'i' && count == 1)
820 count += branch_delay_insns;
821 }
822 printf_filtered ("\n");
823 gdb_flush (gdb_stdout);
824 }
825 }
826 \f
827 static void
828 validate_format (struct format_data fmt, char *cmdname)
829 {
830 if (fmt.size != 0)
831 error (_("Size letters are meaningless in \"%s\" command."), cmdname);
832 if (fmt.count != 1)
833 error (_("Item count other than 1 is meaningless in \"%s\" command."),
834 cmdname);
835 if (fmt.format == 'i')
836 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
837 fmt.format, cmdname);
838 }
839
840 /* Evaluate string EXP as an expression in the current language and
841 print the resulting value. EXP may contain a format specifier as the
842 first argument ("/x myvar" for example, to print myvar in hex). */
843
844 static void
845 print_command_1 (char *exp, int inspect, int voidprint)
846 {
847 struct expression *expr;
848 struct cleanup *old_chain = 0;
849 char format = 0;
850 struct value *val;
851 struct format_data fmt;
852 int cleanup = 0;
853
854 if (exp && *exp == '/')
855 {
856 exp++;
857 fmt = decode_format (&exp, last_format, 0);
858 validate_format (fmt, "print");
859 last_format = format = fmt.format;
860 }
861 else
862 {
863 fmt.count = 1;
864 fmt.format = 0;
865 fmt.size = 0;
866 }
867
868 if (exp && *exp)
869 {
870 struct type *type;
871 expr = parse_expression (exp);
872 old_chain = make_cleanup (free_current_contents, &expr);
873 cleanup = 1;
874 val = evaluate_expression (expr);
875 }
876 else
877 val = access_value_history (0);
878
879 if (voidprint || (val && value_type (val) &&
880 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
881 {
882 struct value_print_options opts;
883 int histindex = record_latest_value (val);
884
885 if (histindex >= 0)
886 annotate_value_history_begin (histindex, value_type (val));
887 else
888 annotate_value_begin (value_type (val));
889
890 if (inspect)
891 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"",
892 exp, histindex);
893 else if (histindex >= 0)
894 printf_filtered ("$%d = ", histindex);
895
896 if (histindex >= 0)
897 annotate_value_history_value ();
898
899 get_formatted_print_options (&opts, format);
900 opts.inspect_it = inspect;
901
902 print_formatted (val, fmt.size, &opts, gdb_stdout);
903 printf_filtered ("\n");
904
905 if (histindex >= 0)
906 annotate_value_history_end ();
907 else
908 annotate_value_end ();
909
910 if (inspect)
911 printf_unfiltered ("\") )\030");
912 }
913
914 if (cleanup)
915 do_cleanups (old_chain);
916 }
917
918 static void
919 print_command (char *exp, int from_tty)
920 {
921 print_command_1 (exp, 0, 1);
922 }
923
924 /* Same as print, except in epoch, it gets its own window. */
925 static void
926 inspect_command (char *exp, int from_tty)
927 {
928 extern int epoch_interface;
929
930 print_command_1 (exp, epoch_interface, 1);
931 }
932
933 /* Same as print, except it doesn't print void results. */
934 static void
935 call_command (char *exp, int from_tty)
936 {
937 print_command_1 (exp, 0, 0);
938 }
939
940 void
941 output_command (char *exp, int from_tty)
942 {
943 struct expression *expr;
944 struct cleanup *old_chain;
945 char format = 0;
946 struct value *val;
947 struct format_data fmt;
948 struct value_print_options opts;
949
950 fmt.size = 0;
951
952 if (exp && *exp == '/')
953 {
954 exp++;
955 fmt = decode_format (&exp, 0, 0);
956 validate_format (fmt, "output");
957 format = fmt.format;
958 }
959
960 expr = parse_expression (exp);
961 old_chain = make_cleanup (free_current_contents, &expr);
962
963 val = evaluate_expression (expr);
964
965 annotate_value_begin (value_type (val));
966
967 get_formatted_print_options (&opts, format);
968 print_formatted (val, fmt.size, &opts, gdb_stdout);
969
970 annotate_value_end ();
971
972 wrap_here ("");
973 gdb_flush (gdb_stdout);
974
975 do_cleanups (old_chain);
976 }
977
978 static void
979 set_command (char *exp, int from_tty)
980 {
981 struct expression *expr = parse_expression (exp);
982 struct cleanup *old_chain =
983 make_cleanup (free_current_contents, &expr);
984 evaluate_expression (expr);
985 do_cleanups (old_chain);
986 }
987
988 static void
989 sym_info (char *arg, int from_tty)
990 {
991 struct minimal_symbol *msymbol;
992 struct objfile *objfile;
993 struct obj_section *osect;
994 CORE_ADDR addr, sect_addr;
995 int matches = 0;
996 unsigned int offset;
997
998 if (!arg)
999 error_no_arg (_("address"));
1000
1001 addr = parse_and_eval_address (arg);
1002 ALL_OBJSECTIONS (objfile, osect)
1003 {
1004 /* Only process each object file once, even if there's a separate
1005 debug file. */
1006 if (objfile->separate_debug_objfile_backlink)
1007 continue;
1008
1009 sect_addr = overlay_mapped_address (addr, osect);
1010
1011 if (obj_section_addr (osect) <= sect_addr
1012 && sect_addr < obj_section_endaddr (osect)
1013 && (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, osect)))
1014 {
1015 const char *obj_name, *mapped, *sec_name, *msym_name;
1016 char *loc_string;
1017 struct cleanup *old_chain;
1018
1019 matches = 1;
1020 offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
1021 mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
1022 sec_name = osect->the_bfd_section->name;
1023 msym_name = SYMBOL_PRINT_NAME (msymbol);
1024
1025 /* Don't print the offset if it is zero.
1026 We assume there's no need to handle i18n of "sym + offset". */
1027 if (offset)
1028 xasprintf (&loc_string, "%s + %u", msym_name, offset);
1029 else
1030 xasprintf (&loc_string, "%s", msym_name);
1031
1032 /* Use a cleanup to free loc_string in case the user quits
1033 a pagination request inside printf_filtered. */
1034 old_chain = make_cleanup (xfree, loc_string);
1035
1036 gdb_assert (osect->objfile && osect->objfile->name);
1037 obj_name = osect->objfile->name;
1038
1039 if (MULTI_OBJFILE_P ())
1040 if (pc_in_unmapped_range (addr, osect))
1041 if (section_is_overlay (osect))
1042 printf_filtered (_("%s in load address range of "
1043 "%s overlay section %s of %s\n"),
1044 loc_string, mapped, sec_name, obj_name);
1045 else
1046 printf_filtered (_("%s in load address range of "
1047 "section %s of %s\n"),
1048 loc_string, sec_name, obj_name);
1049 else
1050 if (section_is_overlay (osect))
1051 printf_filtered (_("%s in %s overlay section %s of %s\n"),
1052 loc_string, mapped, sec_name, obj_name);
1053 else
1054 printf_filtered (_("%s in section %s of %s\n"),
1055 loc_string, sec_name, obj_name);
1056 else
1057 if (pc_in_unmapped_range (addr, osect))
1058 if (section_is_overlay (osect))
1059 printf_filtered (_("%s in load address range of %s overlay "
1060 "section %s\n"),
1061 loc_string, mapped, sec_name);
1062 else
1063 printf_filtered (_("%s in load address range of section %s\n"),
1064 loc_string, sec_name);
1065 else
1066 if (section_is_overlay (osect))
1067 printf_filtered (_("%s in %s overlay section %s\n"),
1068 loc_string, mapped, sec_name);
1069 else
1070 printf_filtered (_("%s in section %s\n"),
1071 loc_string, sec_name);
1072
1073 do_cleanups (old_chain);
1074 }
1075 }
1076 if (matches == 0)
1077 printf_filtered (_("No symbol matches %s.\n"), arg);
1078 }
1079
1080 static void
1081 address_info (char *exp, int from_tty)
1082 {
1083 struct symbol *sym;
1084 struct minimal_symbol *msymbol;
1085 long val;
1086 struct obj_section *section;
1087 CORE_ADDR load_addr;
1088 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
1089 if exp is a field of `this'. */
1090
1091 if (exp == 0)
1092 error (_("Argument required."));
1093
1094 sym = lookup_symbol (exp, get_selected_block (0), VAR_DOMAIN,
1095 &is_a_field_of_this);
1096 if (sym == NULL)
1097 {
1098 if (is_a_field_of_this)
1099 {
1100 printf_filtered ("Symbol \"");
1101 fprintf_symbol_filtered (gdb_stdout, exp,
1102 current_language->la_language, DMGL_ANSI);
1103 printf_filtered ("\" is a field of the local class variable ");
1104 if (current_language->la_language == language_objc)
1105 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1106 else
1107 printf_filtered ("`this'\n");
1108 return;
1109 }
1110
1111 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1112
1113 if (msymbol != NULL)
1114 {
1115 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1116
1117 printf_filtered ("Symbol \"");
1118 fprintf_symbol_filtered (gdb_stdout, exp,
1119 current_language->la_language, DMGL_ANSI);
1120 printf_filtered ("\" is at ");
1121 fputs_filtered (paddress (load_addr), gdb_stdout);
1122 printf_filtered (" in a file compiled without debugging");
1123 section = SYMBOL_OBJ_SECTION (msymbol);
1124 if (section_is_overlay (section))
1125 {
1126 load_addr = overlay_unmapped_address (load_addr, section);
1127 printf_filtered (",\n -- loaded at ");
1128 fputs_filtered (paddress (load_addr), gdb_stdout);
1129 printf_filtered (" in overlay section %s",
1130 section->the_bfd_section->name);
1131 }
1132 printf_filtered (".\n");
1133 }
1134 else
1135 error (_("No symbol \"%s\" in current context."), exp);
1136 return;
1137 }
1138
1139 printf_filtered ("Symbol \"");
1140 fprintf_symbol_filtered (gdb_stdout, SYMBOL_PRINT_NAME (sym),
1141 current_language->la_language, DMGL_ANSI);
1142 printf_filtered ("\" is ");
1143 val = SYMBOL_VALUE (sym);
1144 section = SYMBOL_OBJ_SECTION (sym);
1145
1146 switch (SYMBOL_CLASS (sym))
1147 {
1148 case LOC_CONST:
1149 case LOC_CONST_BYTES:
1150 printf_filtered ("constant");
1151 break;
1152
1153 case LOC_LABEL:
1154 printf_filtered ("a label at address ");
1155 fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)),
1156 gdb_stdout);
1157 if (section_is_overlay (section))
1158 {
1159 load_addr = overlay_unmapped_address (load_addr, section);
1160 printf_filtered (",\n -- loaded at ");
1161 fputs_filtered (paddress (load_addr), gdb_stdout);
1162 printf_filtered (" in overlay section %s",
1163 section->the_bfd_section->name);
1164 }
1165 break;
1166
1167 case LOC_COMPUTED:
1168 /* FIXME: cagney/2004-01-26: It should be possible to
1169 unconditionally call the SYMBOL_OPS method when available.
1170 Unfortunately DWARF 2 stores the frame-base (instead of the
1171 function) location in a function's symbol. Oops! For the
1172 moment enable this when/where applicable. */
1173 SYMBOL_OPS (sym)->describe_location (sym, gdb_stdout);
1174 break;
1175
1176 case LOC_REGISTER:
1177 if (SYMBOL_IS_ARGUMENT (sym))
1178 printf_filtered (_("an argument in register %s"),
1179 gdbarch_register_name (current_gdbarch, val));
1180 else
1181 printf_filtered (_("a variable in register %s"),
1182 gdbarch_register_name (current_gdbarch, val));
1183 break;
1184
1185 case LOC_STATIC:
1186 printf_filtered (_("static storage at address "));
1187 fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)),
1188 gdb_stdout);
1189 if (section_is_overlay (section))
1190 {
1191 load_addr = overlay_unmapped_address (load_addr, section);
1192 printf_filtered (_(",\n -- loaded at "));
1193 fputs_filtered (paddress (load_addr), gdb_stdout);
1194 printf_filtered (_(" in overlay section %s"),
1195 section->the_bfd_section->name);
1196 }
1197 break;
1198
1199 case LOC_REGPARM_ADDR:
1200 printf_filtered (_("address of an argument in register %s"),
1201 gdbarch_register_name (current_gdbarch, val));
1202 break;
1203
1204 case LOC_ARG:
1205 printf_filtered (_("an argument at offset %ld"), val);
1206 break;
1207
1208 case LOC_LOCAL:
1209 printf_filtered (_("a local variable at frame offset %ld"), val);
1210 break;
1211
1212 case LOC_REF_ARG:
1213 printf_filtered (_("a reference argument at offset %ld"), val);
1214 break;
1215
1216 case LOC_TYPEDEF:
1217 printf_filtered (_("a typedef"));
1218 break;
1219
1220 case LOC_BLOCK:
1221 printf_filtered (_("a function at address "));
1222 load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1223 fputs_filtered (paddress (load_addr), gdb_stdout);
1224 if (section_is_overlay (section))
1225 {
1226 load_addr = overlay_unmapped_address (load_addr, section);
1227 printf_filtered (_(",\n -- loaded at "));
1228 fputs_filtered (paddress (load_addr), gdb_stdout);
1229 printf_filtered (_(" in overlay section %s"),
1230 section->the_bfd_section->name);
1231 }
1232 break;
1233
1234 case LOC_UNRESOLVED:
1235 {
1236 struct minimal_symbol *msym;
1237
1238 msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), NULL, NULL);
1239 if (msym == NULL)
1240 printf_filtered ("unresolved");
1241 else
1242 {
1243 section = SYMBOL_OBJ_SECTION (msym);
1244 load_addr = SYMBOL_VALUE_ADDRESS (msym);
1245
1246 if (section
1247 && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
1248 printf_filtered (_("a thread-local variable at offset %s "
1249 "in the thread-local storage for `%s'"),
1250 paddr_nz (load_addr), section->objfile->name);
1251 else
1252 {
1253 printf_filtered (_("static storage at address "));
1254 fputs_filtered (paddress (load_addr), gdb_stdout);
1255 if (section_is_overlay (section))
1256 {
1257 load_addr = overlay_unmapped_address (load_addr, section);
1258 printf_filtered (_(",\n -- loaded at "));
1259 fputs_filtered (paddress (load_addr), gdb_stdout);
1260 printf_filtered (_(" in overlay section %s"),
1261 section->the_bfd_section->name);
1262 }
1263 }
1264 }
1265 }
1266 break;
1267
1268 case LOC_OPTIMIZED_OUT:
1269 printf_filtered (_("optimized out"));
1270 break;
1271
1272 default:
1273 printf_filtered (_("of unknown (botched) type"));
1274 break;
1275 }
1276 printf_filtered (".\n");
1277 }
1278 \f
1279
1280 static void
1281 x_command (char *exp, int from_tty)
1282 {
1283 struct expression *expr;
1284 struct format_data fmt;
1285 struct cleanup *old_chain;
1286 struct value *val;
1287
1288 fmt.format = last_format;
1289 fmt.size = last_size;
1290 fmt.count = 1;
1291
1292 if (exp && *exp == '/')
1293 {
1294 exp++;
1295 fmt = decode_format (&exp, last_format, last_size);
1296 }
1297
1298 /* If we have an expression, evaluate it and use it as the address. */
1299
1300 if (exp != 0 && *exp != 0)
1301 {
1302 expr = parse_expression (exp);
1303 /* Cause expression not to be there any more if this command is
1304 repeated with Newline. But don't clobber a user-defined
1305 command's definition. */
1306 if (from_tty)
1307 *exp = 0;
1308 old_chain = make_cleanup (free_current_contents, &expr);
1309 val = evaluate_expression (expr);
1310 if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
1311 val = value_ind (val);
1312 /* In rvalue contexts, such as this, functions are coerced into
1313 pointers to functions. This makes "x/i main" work. */
1314 if (/* last_format == 'i' && */
1315 TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
1316 && VALUE_LVAL (val) == lval_memory)
1317 next_address = VALUE_ADDRESS (val);
1318 else
1319 next_address = value_as_address (val);
1320 do_cleanups (old_chain);
1321 }
1322
1323 do_examine (fmt, next_address);
1324
1325 /* If the examine succeeds, we remember its size and format for next
1326 time. */
1327 last_size = fmt.size;
1328 last_format = fmt.format;
1329
1330 /* Set a couple of internal variables if appropriate. */
1331 if (last_examine_value)
1332 {
1333 /* Make last address examined available to the user as $_. Use
1334 the correct pointer type. */
1335 struct type *pointer_type
1336 = lookup_pointer_type (value_type (last_examine_value));
1337 set_internalvar (lookup_internalvar ("_"),
1338 value_from_pointer (pointer_type,
1339 last_examine_address));
1340
1341 /* Make contents of last address examined available to the user
1342 as $__. If the last value has not been fetched from memory
1343 then don't fetch it now; instead mark it by voiding the $__
1344 variable. */
1345 if (value_lazy (last_examine_value))
1346 set_internalvar (lookup_internalvar ("__"),
1347 allocate_value (builtin_type_void));
1348 else
1349 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1350 }
1351 }
1352 \f
1353
1354 /* Add an expression to the auto-display chain.
1355 Specify the expression. */
1356
1357 static void
1358 display_command (char *exp, int from_tty)
1359 {
1360 struct format_data fmt;
1361 struct expression *expr;
1362 struct display *new;
1363 int display_it = 1;
1364
1365 #if defined(TUI)
1366 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1367 `tui_version'. */
1368 if (tui_active && exp != NULL && *exp == '$')
1369 display_it = (tui_set_layout_for_display_command (exp) == TUI_FAILURE);
1370 #endif
1371
1372 if (display_it)
1373 {
1374 if (exp == 0)
1375 {
1376 do_displays ();
1377 return;
1378 }
1379
1380 if (*exp == '/')
1381 {
1382 exp++;
1383 fmt = decode_format (&exp, 0, 0);
1384 if (fmt.size && fmt.format == 0)
1385 fmt.format = 'x';
1386 if (fmt.format == 'i' || fmt.format == 's')
1387 fmt.size = 'b';
1388 }
1389 else
1390 {
1391 fmt.format = 0;
1392 fmt.size = 0;
1393 fmt.count = 0;
1394 }
1395
1396 innermost_block = 0;
1397 expr = parse_expression (exp);
1398
1399 new = (struct display *) xmalloc (sizeof (struct display));
1400
1401 new->exp = expr;
1402 new->block = innermost_block;
1403 new->next = display_chain;
1404 new->number = ++display_number;
1405 new->format = fmt;
1406 new->enabled_p = 1;
1407 display_chain = new;
1408
1409 if (from_tty && target_has_execution)
1410 do_one_display (new);
1411
1412 dont_repeat ();
1413 }
1414 }
1415
1416 static void
1417 free_display (struct display *d)
1418 {
1419 xfree (d->exp);
1420 xfree (d);
1421 }
1422
1423 /* Clear out the display_chain. Done when new symtabs are loaded,
1424 since this invalidates the types stored in many expressions. */
1425
1426 void
1427 clear_displays (void)
1428 {
1429 struct display *d;
1430
1431 while ((d = display_chain) != NULL)
1432 {
1433 xfree (d->exp);
1434 display_chain = d->next;
1435 xfree (d);
1436 }
1437 }
1438
1439 /* Delete the auto-display number NUM. */
1440
1441 static void
1442 delete_display (int num)
1443 {
1444 struct display *d1, *d;
1445
1446 if (!display_chain)
1447 error (_("No display number %d."), num);
1448
1449 if (display_chain->number == num)
1450 {
1451 d1 = display_chain;
1452 display_chain = d1->next;
1453 free_display (d1);
1454 }
1455 else
1456 for (d = display_chain;; d = d->next)
1457 {
1458 if (d->next == 0)
1459 error (_("No display number %d."), num);
1460 if (d->next->number == num)
1461 {
1462 d1 = d->next;
1463 d->next = d1->next;
1464 free_display (d1);
1465 break;
1466 }
1467 }
1468 }
1469
1470 /* Delete some values from the auto-display chain.
1471 Specify the element numbers. */
1472
1473 static void
1474 undisplay_command (char *args, int from_tty)
1475 {
1476 char *p = args;
1477 char *p1;
1478 int num;
1479
1480 if (args == 0)
1481 {
1482 if (query ("Delete all auto-display expressions? "))
1483 clear_displays ();
1484 dont_repeat ();
1485 return;
1486 }
1487
1488 while (*p)
1489 {
1490 p1 = p;
1491 while (*p1 >= '0' && *p1 <= '9')
1492 p1++;
1493 if (*p1 && *p1 != ' ' && *p1 != '\t')
1494 error (_("Arguments must be display numbers."));
1495
1496 num = atoi (p);
1497
1498 delete_display (num);
1499
1500 p = p1;
1501 while (*p == ' ' || *p == '\t')
1502 p++;
1503 }
1504 dont_repeat ();
1505 }
1506
1507 /* Display a single auto-display.
1508 Do nothing if the display cannot be printed in the current context,
1509 or if the display is disabled. */
1510
1511 static void
1512 do_one_display (struct display *d)
1513 {
1514 int within_current_scope;
1515
1516 if (d->enabled_p == 0)
1517 return;
1518
1519 if (d->block)
1520 within_current_scope = contained_in (get_selected_block (0), d->block);
1521 else
1522 within_current_scope = 1;
1523 if (!within_current_scope)
1524 return;
1525
1526 current_display_number = d->number;
1527
1528 annotate_display_begin ();
1529 printf_filtered ("%d", d->number);
1530 annotate_display_number_end ();
1531 printf_filtered (": ");
1532 if (d->format.size)
1533 {
1534 CORE_ADDR addr;
1535 struct value *val;
1536
1537 annotate_display_format ();
1538
1539 printf_filtered ("x/");
1540 if (d->format.count != 1)
1541 printf_filtered ("%d", d->format.count);
1542 printf_filtered ("%c", d->format.format);
1543 if (d->format.format != 'i' && d->format.format != 's')
1544 printf_filtered ("%c", d->format.size);
1545 printf_filtered (" ");
1546
1547 annotate_display_expression ();
1548
1549 print_expression (d->exp, gdb_stdout);
1550 annotate_display_expression_end ();
1551
1552 if (d->format.count != 1 || d->format.format == 'i')
1553 printf_filtered ("\n");
1554 else
1555 printf_filtered (" ");
1556
1557 val = evaluate_expression (d->exp);
1558 addr = value_as_address (val);
1559 if (d->format.format == 'i')
1560 addr = gdbarch_addr_bits_remove (current_gdbarch, addr);
1561
1562 annotate_display_value ();
1563
1564 do_examine (d->format, addr);
1565 }
1566 else
1567 {
1568 struct value_print_options opts;
1569
1570 annotate_display_format ();
1571
1572 if (d->format.format)
1573 printf_filtered ("/%c ", d->format.format);
1574
1575 annotate_display_expression ();
1576
1577 print_expression (d->exp, gdb_stdout);
1578 annotate_display_expression_end ();
1579
1580 printf_filtered (" = ");
1581
1582 annotate_display_expression ();
1583
1584 get_formatted_print_options (&opts, d->format.format);
1585 print_formatted (evaluate_expression (d->exp),
1586 d->format.size, &opts, gdb_stdout);
1587 printf_filtered ("\n");
1588 }
1589
1590 annotate_display_end ();
1591
1592 gdb_flush (gdb_stdout);
1593 current_display_number = -1;
1594 }
1595
1596 /* Display all of the values on the auto-display chain which can be
1597 evaluated in the current scope. */
1598
1599 void
1600 do_displays (void)
1601 {
1602 struct display *d;
1603
1604 for (d = display_chain; d; d = d->next)
1605 do_one_display (d);
1606 }
1607
1608 /* Delete the auto-display which we were in the process of displaying.
1609 This is done when there is an error or a signal. */
1610
1611 void
1612 disable_display (int num)
1613 {
1614 struct display *d;
1615
1616 for (d = display_chain; d; d = d->next)
1617 if (d->number == num)
1618 {
1619 d->enabled_p = 0;
1620 return;
1621 }
1622 printf_unfiltered (_("No display number %d.\n"), num);
1623 }
1624
1625 void
1626 disable_current_display (void)
1627 {
1628 if (current_display_number >= 0)
1629 {
1630 disable_display (current_display_number);
1631 fprintf_unfiltered (gdb_stderr, _("\
1632 Disabling display %d to avoid infinite recursion.\n"),
1633 current_display_number);
1634 }
1635 current_display_number = -1;
1636 }
1637
1638 static void
1639 display_info (char *ignore, int from_tty)
1640 {
1641 struct display *d;
1642
1643 if (!display_chain)
1644 printf_unfiltered (_("There are no auto-display expressions now.\n"));
1645 else
1646 printf_filtered (_("Auto-display expressions now in effect:\n\
1647 Num Enb Expression\n"));
1648
1649 for (d = display_chain; d; d = d->next)
1650 {
1651 printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]);
1652 if (d->format.size)
1653 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1654 d->format.format);
1655 else if (d->format.format)
1656 printf_filtered ("/%c ", d->format.format);
1657 print_expression (d->exp, gdb_stdout);
1658 if (d->block && !contained_in (get_selected_block (0), d->block))
1659 printf_filtered (_(" (cannot be evaluated in the current context)"));
1660 printf_filtered ("\n");
1661 gdb_flush (gdb_stdout);
1662 }
1663 }
1664
1665 static void
1666 enable_display (char *args, int from_tty)
1667 {
1668 char *p = args;
1669 char *p1;
1670 int num;
1671 struct display *d;
1672
1673 if (p == 0)
1674 {
1675 for (d = display_chain; d; d = d->next)
1676 d->enabled_p = 1;
1677 }
1678 else
1679 while (*p)
1680 {
1681 p1 = p;
1682 while (*p1 >= '0' && *p1 <= '9')
1683 p1++;
1684 if (*p1 && *p1 != ' ' && *p1 != '\t')
1685 error (_("Arguments must be display numbers."));
1686
1687 num = atoi (p);
1688
1689 for (d = display_chain; d; d = d->next)
1690 if (d->number == num)
1691 {
1692 d->enabled_p = 1;
1693 goto win;
1694 }
1695 printf_unfiltered (_("No display number %d.\n"), num);
1696 win:
1697 p = p1;
1698 while (*p == ' ' || *p == '\t')
1699 p++;
1700 }
1701 }
1702
1703 static void
1704 disable_display_command (char *args, int from_tty)
1705 {
1706 char *p = args;
1707 char *p1;
1708 struct display *d;
1709
1710 if (p == 0)
1711 {
1712 for (d = display_chain; d; d = d->next)
1713 d->enabled_p = 0;
1714 }
1715 else
1716 while (*p)
1717 {
1718 p1 = p;
1719 while (*p1 >= '0' && *p1 <= '9')
1720 p1++;
1721 if (*p1 && *p1 != ' ' && *p1 != '\t')
1722 error (_("Arguments must be display numbers."));
1723
1724 disable_display (atoi (p));
1725
1726 p = p1;
1727 while (*p == ' ' || *p == '\t')
1728 p++;
1729 }
1730 }
1731 \f
1732
1733 /* Print the value in stack frame FRAME of a variable specified by a
1734 struct symbol. */
1735
1736 void
1737 print_variable_value (struct symbol *var, struct frame_info *frame,
1738 struct ui_file *stream)
1739 {
1740 struct value *val = read_var_value (var, frame);
1741 struct value_print_options opts;
1742
1743 get_user_print_options (&opts);
1744 value_print (val, stream, &opts);
1745 }
1746
1747 static void
1748 printf_command (char *arg, int from_tty)
1749 {
1750 char *f = NULL;
1751 char *s = arg;
1752 char *string = NULL;
1753 struct value **val_args;
1754 char *substrings;
1755 char *current_substring;
1756 int nargs = 0;
1757 int allocated_args = 20;
1758 struct cleanup *old_cleanups;
1759
1760 val_args = xmalloc (allocated_args * sizeof (struct value *));
1761 old_cleanups = make_cleanup (free_current_contents, &val_args);
1762
1763 if (s == 0)
1764 error_no_arg (_("format-control string and values to print"));
1765
1766 /* Skip white space before format string */
1767 while (*s == ' ' || *s == '\t')
1768 s++;
1769
1770 /* A format string should follow, enveloped in double quotes. */
1771 if (*s++ != '"')
1772 error (_("Bad format string, missing '\"'."));
1773
1774 /* Parse the format-control string and copy it into the string STRING,
1775 processing some kinds of escape sequence. */
1776
1777 f = string = (char *) alloca (strlen (s) + 1);
1778
1779 while (*s != '"')
1780 {
1781 int c = *s++;
1782 switch (c)
1783 {
1784 case '\0':
1785 error (_("Bad format string, non-terminated '\"'."));
1786
1787 case '\\':
1788 switch (c = *s++)
1789 {
1790 case '\\':
1791 *f++ = '\\';
1792 break;
1793 case 'a':
1794 *f++ = '\a';
1795 break;
1796 case 'b':
1797 *f++ = '\b';
1798 break;
1799 case 'f':
1800 *f++ = '\f';
1801 break;
1802 case 'n':
1803 *f++ = '\n';
1804 break;
1805 case 'r':
1806 *f++ = '\r';
1807 break;
1808 case 't':
1809 *f++ = '\t';
1810 break;
1811 case 'v':
1812 *f++ = '\v';
1813 break;
1814 case '"':
1815 *f++ = '"';
1816 break;
1817 default:
1818 /* ??? TODO: handle other escape sequences */
1819 error (_("Unrecognized escape character \\%c in format string."),
1820 c);
1821 }
1822 break;
1823
1824 default:
1825 *f++ = c;
1826 }
1827 }
1828
1829 /* Skip over " and following space and comma. */
1830 s++;
1831 *f++ = '\0';
1832 while (*s == ' ' || *s == '\t')
1833 s++;
1834
1835 if (*s != ',' && *s != 0)
1836 error (_("Invalid argument syntax"));
1837
1838 if (*s == ',')
1839 s++;
1840 while (*s == ' ' || *s == '\t')
1841 s++;
1842
1843 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1844 substrings = alloca (strlen (string) * 2);
1845 current_substring = substrings;
1846
1847 {
1848 /* Now scan the string for %-specs and see what kinds of args they want.
1849 argclass[I] classifies the %-specs so we can give printf_filtered
1850 something of the right size. */
1851
1852 enum argclass
1853 {
1854 int_arg, long_arg, long_long_arg, ptr_arg, string_arg,
1855 double_arg, long_double_arg, decfloat_arg
1856 };
1857 enum argclass *argclass;
1858 enum argclass this_argclass;
1859 char *last_arg;
1860 int nargs_wanted;
1861 int i;
1862
1863 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1864 nargs_wanted = 0;
1865 f = string;
1866 last_arg = string;
1867 while (*f)
1868 if (*f++ == '%')
1869 {
1870 int seen_hash = 0, seen_zero = 0, lcount = 0, seen_prec = 0;
1871 int seen_space = 0, seen_plus = 0;
1872 int seen_big_l = 0, seen_h = 0, seen_big_h = 0;
1873 int seen_big_d = 0, seen_double_big_d = 0;
1874 int bad = 0;
1875
1876 /* Check the validity of the format specifier, and work
1877 out what argument it expects. We only accept C89
1878 format strings, with the exception of long long (which
1879 we autoconf for). */
1880
1881 /* Skip over "%%". */
1882 if (*f == '%')
1883 {
1884 f++;
1885 continue;
1886 }
1887
1888 /* The first part of a format specifier is a set of flag
1889 characters. */
1890 while (strchr ("0-+ #", *f))
1891 {
1892 if (*f == '#')
1893 seen_hash = 1;
1894 else if (*f == '0')
1895 seen_zero = 1;
1896 else if (*f == ' ')
1897 seen_space = 1;
1898 else if (*f == '+')
1899 seen_plus = 1;
1900 f++;
1901 }
1902
1903 /* The next part of a format specifier is a width. */
1904 while (strchr ("0123456789", *f))
1905 f++;
1906
1907 /* The next part of a format specifier is a precision. */
1908 if (*f == '.')
1909 {
1910 seen_prec = 1;
1911 f++;
1912 while (strchr ("0123456789", *f))
1913 f++;
1914 }
1915
1916 /* The next part of a format specifier is a length modifier. */
1917 if (*f == 'h')
1918 {
1919 seen_h = 1;
1920 f++;
1921 }
1922 else if (*f == 'l')
1923 {
1924 f++;
1925 lcount++;
1926 if (*f == 'l')
1927 {
1928 f++;
1929 lcount++;
1930 }
1931 }
1932 else if (*f == 'L')
1933 {
1934 seen_big_l = 1;
1935 f++;
1936 }
1937 /* Decimal32 modifier. */
1938 else if (*f == 'H')
1939 {
1940 seen_big_h = 1;
1941 f++;
1942 }
1943 /* Decimal64 and Decimal128 modifiers. */
1944 else if (*f == 'D')
1945 {
1946 f++;
1947
1948 /* Check for a Decimal128. */
1949 if (*f == 'D')
1950 {
1951 f++;
1952 seen_double_big_d = 1;
1953 }
1954 else
1955 seen_big_d = 1;
1956 }
1957
1958 switch (*f)
1959 {
1960 case 'u':
1961 if (seen_hash)
1962 bad = 1;
1963 /* FALLTHROUGH */
1964
1965 case 'o':
1966 case 'x':
1967 case 'X':
1968 if (seen_space || seen_plus)
1969 bad = 1;
1970 /* FALLTHROUGH */
1971
1972 case 'd':
1973 case 'i':
1974 if (lcount == 0)
1975 this_argclass = int_arg;
1976 else if (lcount == 1)
1977 this_argclass = long_arg;
1978 else
1979 this_argclass = long_long_arg;
1980
1981 if (seen_big_l)
1982 bad = 1;
1983 break;
1984
1985 case 'c':
1986 this_argclass = int_arg;
1987 if (lcount || seen_h || seen_big_l)
1988 bad = 1;
1989 if (seen_prec || seen_zero || seen_space || seen_plus)
1990 bad = 1;
1991 break;
1992
1993 case 'p':
1994 this_argclass = ptr_arg;
1995 if (lcount || seen_h || seen_big_l)
1996 bad = 1;
1997 if (seen_prec || seen_zero || seen_space || seen_plus)
1998 bad = 1;
1999 break;
2000
2001 case 's':
2002 this_argclass = string_arg;
2003 if (lcount || seen_h || seen_big_l)
2004 bad = 1;
2005 if (seen_zero || seen_space || seen_plus)
2006 bad = 1;
2007 break;
2008
2009 case 'e':
2010 case 'f':
2011 case 'g':
2012 case 'E':
2013 case 'G':
2014 if (seen_big_h || seen_big_d || seen_double_big_d)
2015 this_argclass = decfloat_arg;
2016 else if (seen_big_l)
2017 this_argclass = long_double_arg;
2018 else
2019 this_argclass = double_arg;
2020
2021 if (lcount || seen_h)
2022 bad = 1;
2023 break;
2024
2025 case '*':
2026 error (_("`*' not supported for precision or width in printf"));
2027
2028 case 'n':
2029 error (_("Format specifier `n' not supported in printf"));
2030
2031 case '\0':
2032 error (_("Incomplete format specifier at end of format string"));
2033
2034 default:
2035 error (_("Unrecognized format specifier '%c' in printf"), *f);
2036 }
2037
2038 if (bad)
2039 error (_("Inappropriate modifiers to format specifier '%c' in printf"),
2040 *f);
2041
2042 f++;
2043
2044 if (lcount > 1 && USE_PRINTF_I64)
2045 {
2046 /* Windows' printf does support long long, but not the usual way.
2047 Convert %lld to %I64d. */
2048 int length_before_ll = f - last_arg - 1 - lcount;
2049 strncpy (current_substring, last_arg, length_before_ll);
2050 strcpy (current_substring + length_before_ll, "I64");
2051 current_substring[length_before_ll + 3] =
2052 last_arg[length_before_ll + lcount];
2053 current_substring += length_before_ll + 4;
2054 }
2055 else
2056 {
2057 strncpy (current_substring, last_arg, f - last_arg);
2058 current_substring += f - last_arg;
2059 }
2060 *current_substring++ = '\0';
2061 last_arg = f;
2062 argclass[nargs_wanted++] = this_argclass;
2063 }
2064
2065 /* Now, parse all arguments and evaluate them.
2066 Store the VALUEs in VAL_ARGS. */
2067
2068 while (*s != '\0')
2069 {
2070 char *s1;
2071 if (nargs == allocated_args)
2072 val_args = (struct value **) xrealloc ((char *) val_args,
2073 (allocated_args *= 2)
2074 * sizeof (struct value *));
2075 s1 = s;
2076 val_args[nargs] = parse_to_comma_and_eval (&s1);
2077
2078 nargs++;
2079 s = s1;
2080 if (*s == ',')
2081 s++;
2082 }
2083
2084 if (nargs != nargs_wanted)
2085 error (_("Wrong number of arguments for specified format-string"));
2086
2087 /* Now actually print them. */
2088 current_substring = substrings;
2089 for (i = 0; i < nargs; i++)
2090 {
2091 switch (argclass[i])
2092 {
2093 case string_arg:
2094 {
2095 gdb_byte *str;
2096 CORE_ADDR tem;
2097 int j;
2098 tem = value_as_address (val_args[i]);
2099
2100 /* This is a %s argument. Find the length of the string. */
2101 for (j = 0;; j++)
2102 {
2103 gdb_byte c;
2104 QUIT;
2105 read_memory (tem + j, &c, 1);
2106 if (c == 0)
2107 break;
2108 }
2109
2110 /* Copy the string contents into a string inside GDB. */
2111 str = (gdb_byte *) alloca (j + 1);
2112 if (j != 0)
2113 read_memory (tem, str, j);
2114 str[j] = 0;
2115
2116 printf_filtered (current_substring, (char *) str);
2117 }
2118 break;
2119 case double_arg:
2120 {
2121 struct type *type = value_type (val_args[i]);
2122 DOUBLEST val;
2123 int inv;
2124
2125 /* If format string wants a float, unchecked-convert the value
2126 to floating point of the same size. */
2127 type = float_type_from_length (current_gdbarch, type);
2128 val = unpack_double (type, value_contents (val_args[i]), &inv);
2129 if (inv)
2130 error (_("Invalid floating value found in program."));
2131
2132 printf_filtered (current_substring, (double) val);
2133 break;
2134 }
2135 case long_double_arg:
2136 #ifdef HAVE_LONG_DOUBLE
2137 {
2138 struct type *type = value_type (val_args[i]);
2139 DOUBLEST val;
2140 int inv;
2141
2142 /* If format string wants a float, unchecked-convert the value
2143 to floating point of the same size. */
2144 type = float_type_from_length (current_gdbarch, type);
2145 val = unpack_double (type, value_contents (val_args[i]), &inv);
2146 if (inv)
2147 error (_("Invalid floating value found in program."));
2148
2149 printf_filtered (current_substring, (long double) val);
2150 break;
2151 }
2152 #else
2153 error (_("long double not supported in printf"));
2154 #endif
2155 case long_long_arg:
2156 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2157 {
2158 long long val = value_as_long (val_args[i]);
2159 printf_filtered (current_substring, val);
2160 break;
2161 }
2162 #else
2163 error (_("long long not supported in printf"));
2164 #endif
2165 case int_arg:
2166 {
2167 int val = value_as_long (val_args[i]);
2168 printf_filtered (current_substring, val);
2169 break;
2170 }
2171 case long_arg:
2172 {
2173 long val = value_as_long (val_args[i]);
2174 printf_filtered (current_substring, val);
2175 break;
2176 }
2177
2178 /* Handles decimal floating values. */
2179 case decfloat_arg:
2180 {
2181 const gdb_byte *param_ptr = value_contents (val_args[i]);
2182 #if defined (PRINTF_HAS_DECFLOAT)
2183 /* If we have native support for Decimal floating
2184 printing, handle it here. */
2185 printf_filtered (current_substring, param_ptr);
2186 #else
2187
2188 /* As a workaround until vasprintf has native support for DFP
2189 we convert the DFP values to string and print them using
2190 the %s format specifier. */
2191
2192 char *eos, *sos;
2193 int nnull_chars = 0;
2194
2195 /* Parameter data. */
2196 struct type *param_type = value_type (val_args[i]);
2197 unsigned int param_len = TYPE_LENGTH (param_type);
2198
2199 /* DFP output data. */
2200 struct value *dfp_value = NULL;
2201 gdb_byte *dfp_ptr;
2202 int dfp_len = 16;
2203 gdb_byte dec[16];
2204 struct type *dfp_type = NULL;
2205 char decstr[MAX_DECIMAL_STRING];
2206
2207 /* Points to the end of the string so that we can go back
2208 and check for DFP length modifiers. */
2209 eos = current_substring + strlen (current_substring);
2210
2211 /* Look for the float/double format specifier. */
2212 while (*eos != 'f' && *eos != 'e' && *eos != 'E'
2213 && *eos != 'g' && *eos != 'G')
2214 eos--;
2215
2216 sos = eos;
2217
2218 /* Search for the '%' char and extract the size and type of
2219 the output decimal value based on its modifiers
2220 (%Hf, %Df, %DDf). */
2221 while (*--sos != '%')
2222 {
2223 if (*sos == 'H')
2224 {
2225 dfp_len = 4;
2226 dfp_type = builtin_type (current_gdbarch)->builtin_decfloat;
2227 }
2228 else if (*sos == 'D' && *(sos - 1) == 'D')
2229 {
2230 dfp_len = 16;
2231 dfp_type = builtin_type (current_gdbarch)->builtin_declong;
2232 sos--;
2233 }
2234 else
2235 {
2236 dfp_len = 8;
2237 dfp_type = builtin_type (current_gdbarch)->builtin_decdouble;
2238 }
2239 }
2240
2241 /* Replace %Hf, %Df and %DDf with %s's. */
2242 *++sos = 's';
2243
2244 /* Go through the whole format string and pull the correct
2245 number of chars back to compensate for the change in the
2246 format specifier. */
2247 while (nnull_chars < nargs - i)
2248 {
2249 if (*eos == '\0')
2250 nnull_chars++;
2251
2252 *++sos = *++eos;
2253 }
2254
2255 /* Conversion between different DFP types. */
2256 if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT)
2257 decimal_convert (param_ptr, param_len, dec, dfp_len);
2258 else
2259 /* If this is a non-trivial conversion, just output 0.
2260 A correct converted value can be displayed by explicitly
2261 casting to a DFP type. */
2262 decimal_from_string (dec, dfp_len, "0");
2263
2264 dfp_value = value_from_decfloat (dfp_type, dec);
2265
2266 dfp_ptr = (gdb_byte *) value_contents (dfp_value);
2267
2268 decimal_to_string (dfp_ptr, dfp_len, decstr);
2269
2270 /* Print the DFP value. */
2271 printf_filtered (current_substring, decstr);
2272
2273 break;
2274 #endif
2275 }
2276
2277 case ptr_arg:
2278 {
2279 /* We avoid the host's %p because pointers are too
2280 likely to be the wrong size. The only interesting
2281 modifier for %p is a width; extract that, and then
2282 handle %p as glibc would: %#x or a literal "(nil)". */
2283
2284 char *p, *fmt, *fmt_p;
2285 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2286 long long val = value_as_long (val_args[i]);
2287 #else
2288 long val = value_as_long (val_args[i]);
2289 #endif
2290
2291 fmt = alloca (strlen (current_substring) + 5);
2292
2293 /* Copy up to the leading %. */
2294 p = current_substring;
2295 fmt_p = fmt;
2296 while (*p)
2297 {
2298 int is_percent = (*p == '%');
2299 *fmt_p++ = *p++;
2300 if (is_percent)
2301 {
2302 if (*p == '%')
2303 *fmt_p++ = *p++;
2304 else
2305 break;
2306 }
2307 }
2308
2309 if (val != 0)
2310 *fmt_p++ = '#';
2311
2312 /* Copy any width. */
2313 while (*p >= '0' && *p < '9')
2314 *fmt_p++ = *p++;
2315
2316 gdb_assert (*p == 'p' && *(p + 1) == '\0');
2317 if (val != 0)
2318 {
2319 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2320 *fmt_p++ = 'l';
2321 #endif
2322 *fmt_p++ = 'l';
2323 *fmt_p++ = 'x';
2324 *fmt_p++ = '\0';
2325 printf_filtered (fmt, val);
2326 }
2327 else
2328 {
2329 *fmt_p++ = 's';
2330 *fmt_p++ = '\0';
2331 printf_filtered (fmt, "(nil)");
2332 }
2333
2334 break;
2335 }
2336 default:
2337 internal_error (__FILE__, __LINE__,
2338 _("failed internal consistency check"));
2339 }
2340 /* Skip to the next substring. */
2341 current_substring += strlen (current_substring) + 1;
2342 }
2343 /* Print the portion of the format string after the last argument. */
2344 puts_filtered (last_arg);
2345 }
2346 do_cleanups (old_cleanups);
2347 }
2348
2349 void
2350 _initialize_printcmd (void)
2351 {
2352 struct cmd_list_element *c;
2353
2354 current_display_number = -1;
2355
2356 add_info ("address", address_info,
2357 _("Describe where symbol SYM is stored."));
2358
2359 add_info ("symbol", sym_info, _("\
2360 Describe what symbol is at location ADDR.\n\
2361 Only for symbols with fixed locations (global or static scope)."));
2362
2363 add_com ("x", class_vars, x_command, _("\
2364 Examine memory: x/FMT ADDRESS.\n\
2365 ADDRESS is an expression for the memory address to examine.\n\
2366 FMT is a repeat count followed by a format letter and a size letter.\n\
2367 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2368 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2369 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2370 The specified number of objects of the specified size are printed\n\
2371 according to the format.\n\n\
2372 Defaults for format and size letters are those previously used.\n\
2373 Default count is 1. Default address is following last thing printed\n\
2374 with this command or \"print\"."));
2375
2376 #if 0
2377 add_com ("whereis", class_vars, whereis_command,
2378 _("Print line number and file of definition of variable."));
2379 #endif
2380
2381 add_info ("display", display_info, _("\
2382 Expressions to display when program stops, with code numbers."));
2383
2384 add_cmd ("undisplay", class_vars, undisplay_command, _("\
2385 Cancel some expressions to be displayed when program stops.\n\
2386 Arguments are the code numbers of the expressions to stop displaying.\n\
2387 No argument means cancel all automatic-display expressions.\n\
2388 \"delete display\" has the same effect as this command.\n\
2389 Do \"info display\" to see current list of code numbers."),
2390 &cmdlist);
2391
2392 add_com ("display", class_vars, display_command, _("\
2393 Print value of expression EXP each time the program stops.\n\
2394 /FMT may be used before EXP as in the \"print\" command.\n\
2395 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2396 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2397 and examining is done as in the \"x\" command.\n\n\
2398 With no argument, display all currently requested auto-display expressions.\n\
2399 Use \"undisplay\" to cancel display requests previously made."));
2400
2401 add_cmd ("display", class_vars, enable_display, _("\
2402 Enable some expressions to be displayed when program stops.\n\
2403 Arguments are the code numbers of the expressions to resume displaying.\n\
2404 No argument means enable all automatic-display expressions.\n\
2405 Do \"info display\" to see current list of code numbers."), &enablelist);
2406
2407 add_cmd ("display", class_vars, disable_display_command, _("\
2408 Disable some expressions to be displayed when program stops.\n\
2409 Arguments are the code numbers of the expressions to stop displaying.\n\
2410 No argument means disable all automatic-display expressions.\n\
2411 Do \"info display\" to see current list of code numbers."), &disablelist);
2412
2413 add_cmd ("display", class_vars, undisplay_command, _("\
2414 Cancel some expressions to be displayed when program stops.\n\
2415 Arguments are the code numbers of the expressions to stop displaying.\n\
2416 No argument means cancel all automatic-display expressions.\n\
2417 Do \"info display\" to see current list of code numbers."), &deletelist);
2418
2419 add_com ("printf", class_vars, printf_command, _("\
2420 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2421 This is useful for formatted output in user-defined commands."));
2422
2423 add_com ("output", class_vars, output_command, _("\
2424 Like \"print\" but don't put in value history and don't print newline.\n\
2425 This is useful in user-defined commands."));
2426
2427 add_prefix_cmd ("set", class_vars, set_command, _("\
2428 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2429 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2430 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2431 with $), a register (a few standard names starting with $), or an actual\n\
2432 variable in the program being debugged. EXP is any valid expression.\n\
2433 Use \"set variable\" for variables with names identical to set subcommands.\n\
2434 \n\
2435 With a subcommand, this command modifies parts of the gdb environment.\n\
2436 You can see these environment settings with the \"show\" command."),
2437 &setlist, "set ", 1, &cmdlist);
2438 if (dbx_commands)
2439 add_com ("assign", class_vars, set_command, _("\
2440 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2441 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2442 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2443 with $), a register (a few standard names starting with $), or an actual\n\
2444 variable in the program being debugged. EXP is any valid expression.\n\
2445 Use \"set variable\" for variables with names identical to set subcommands.\n\
2446 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2447 You can see these environment settings with the \"show\" command."));
2448
2449 /* "call" is the same as "set", but handy for dbx users to call fns. */
2450 c = add_com ("call", class_vars, call_command, _("\
2451 Call a function in the program.\n\
2452 The argument is the function name and arguments, in the notation of the\n\
2453 current working language. The result is printed and saved in the value\n\
2454 history, if it is not void."));
2455 set_cmd_completer (c, expression_completer);
2456
2457 add_cmd ("variable", class_vars, set_command, _("\
2458 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2459 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2460 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2461 with $), a register (a few standard names starting with $), or an actual\n\
2462 variable in the program being debugged. EXP is any valid expression.\n\
2463 This may usually be abbreviated to simply \"set\"."),
2464 &setlist);
2465
2466 c = add_com ("print", class_vars, print_command, _("\
2467 Print value of expression EXP.\n\
2468 Variables accessible are those of the lexical environment of the selected\n\
2469 stack frame, plus all those whose scope is global or an entire file.\n\
2470 \n\
2471 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2472 $$NUM refers to NUM'th value back from the last one.\n\
2473 Names starting with $ refer to registers (with the values they would have\n\
2474 if the program were to return to the stack frame now selected, restoring\n\
2475 all registers saved by frames farther in) or else to debugger\n\
2476 \"convenience\" variables (any such name not a known register).\n\
2477 Use assignment expressions to give values to convenience variables.\n\
2478 \n\
2479 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2480 @ is a binary operator for treating consecutive data objects\n\
2481 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2482 element is FOO, whose second element is stored in the space following\n\
2483 where FOO is stored, etc. FOO must be an expression whose value\n\
2484 resides in memory.\n\
2485 \n\
2486 EXP may be preceded with /FMT, where FMT is a format letter\n\
2487 but no count or size letter (see \"x\" command)."));
2488 set_cmd_completer (c, expression_completer);
2489 add_com_alias ("p", "print", class_vars, 1);
2490
2491 c = add_com ("inspect", class_vars, inspect_command, _("\
2492 Same as \"print\" command, except that if you are running in the epoch\n\
2493 environment, the value is printed in its own window."));
2494 set_cmd_completer (c, expression_completer);
2495
2496 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
2497 &max_symbolic_offset, _("\
2498 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2499 Show the largest offset that will be printed in <symbol+1234> form."), NULL,
2500 NULL,
2501 show_max_symbolic_offset,
2502 &setprintlist, &showprintlist);
2503 add_setshow_boolean_cmd ("symbol-filename", no_class,
2504 &print_symbol_filename, _("\
2505 Set printing of source filename and line number with <symbol>."), _("\
2506 Show printing of source filename and line number with <symbol>."), NULL,
2507 NULL,
2508 show_print_symbol_filename,
2509 &setprintlist, &showprintlist);
2510
2511 /* For examine/instruction a single byte quantity is specified as
2512 the data. This avoids problems with value_at_lazy() requiring a
2513 valid data type (and rejecting VOID). */
2514 examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
2515
2516 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2517 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2518 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2519 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);
2520
2521 }
This page took 0.222103 seconds and 5 git commands to generate.