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