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