* symtab.h (enum address_class): Remove LOC_BASEREG and
[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 asection *section;
1045 CORE_ADDR load_addr;
1046 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
1047 if exp is a field of `this'. */
1048
1049 if (exp == 0)
1050 error (_("Argument required."));
1051
1052 sym = lookup_symbol (exp, get_selected_block (0), VAR_DOMAIN,
1053 &is_a_field_of_this);
1054 if (sym == NULL)
1055 {
1056 if (is_a_field_of_this)
1057 {
1058 printf_filtered ("Symbol \"");
1059 fprintf_symbol_filtered (gdb_stdout, exp,
1060 current_language->la_language, DMGL_ANSI);
1061 printf_filtered ("\" is a field of the local class variable ");
1062 if (current_language->la_language == language_objc)
1063 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
1064 else
1065 printf_filtered ("`this'\n");
1066 return;
1067 }
1068
1069 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1070
1071 if (msymbol != NULL)
1072 {
1073 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1074
1075 printf_filtered ("Symbol \"");
1076 fprintf_symbol_filtered (gdb_stdout, exp,
1077 current_language->la_language, DMGL_ANSI);
1078 printf_filtered ("\" is at ");
1079 fputs_filtered (paddress (load_addr), gdb_stdout);
1080 printf_filtered (" in a file compiled without debugging");
1081 section = SYMBOL_BFD_SECTION (msymbol);
1082 if (section_is_overlay (section))
1083 {
1084 load_addr = overlay_unmapped_address (load_addr, section);
1085 printf_filtered (",\n -- loaded at ");
1086 fputs_filtered (paddress (load_addr), gdb_stdout);
1087 printf_filtered (" in overlay section %s", section->name);
1088 }
1089 printf_filtered (".\n");
1090 }
1091 else
1092 error (_("No symbol \"%s\" in current context."), exp);
1093 return;
1094 }
1095
1096 printf_filtered ("Symbol \"");
1097 fprintf_symbol_filtered (gdb_stdout, DEPRECATED_SYMBOL_NAME (sym),
1098 current_language->la_language, DMGL_ANSI);
1099 printf_filtered ("\" is ");
1100 val = SYMBOL_VALUE (sym);
1101 section = SYMBOL_BFD_SECTION (sym);
1102
1103 switch (SYMBOL_CLASS (sym))
1104 {
1105 case LOC_CONST:
1106 case LOC_CONST_BYTES:
1107 printf_filtered ("constant");
1108 break;
1109
1110 case LOC_LABEL:
1111 printf_filtered ("a label at address ");
1112 fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)),
1113 gdb_stdout);
1114 if (section_is_overlay (section))
1115 {
1116 load_addr = overlay_unmapped_address (load_addr, section);
1117 printf_filtered (",\n -- loaded at ");
1118 fputs_filtered (paddress (load_addr), gdb_stdout);
1119 printf_filtered (" in overlay section %s", section->name);
1120 }
1121 break;
1122
1123 case LOC_COMPUTED:
1124 case LOC_COMPUTED_ARG:
1125 /* FIXME: cagney/2004-01-26: It should be possible to
1126 unconditionally call the SYMBOL_OPS method when available.
1127 Unfortunately DWARF 2 stores the frame-base (instead of the
1128 function) location in a function's symbol. Oops! For the
1129 moment enable this when/where applicable. */
1130 SYMBOL_OPS (sym)->describe_location (sym, gdb_stdout);
1131 break;
1132
1133 case LOC_REGISTER:
1134 printf_filtered (_("a variable in register %s"),
1135 gdbarch_register_name (current_gdbarch, val));
1136 break;
1137
1138 case LOC_STATIC:
1139 printf_filtered (_("static storage at address "));
1140 fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)),
1141 gdb_stdout);
1142 if (section_is_overlay (section))
1143 {
1144 load_addr = overlay_unmapped_address (load_addr, section);
1145 printf_filtered (_(",\n -- loaded at "));
1146 fputs_filtered (paddress (load_addr), gdb_stdout);
1147 printf_filtered (_(" in overlay section %s"), section->name);
1148 }
1149 break;
1150
1151 case LOC_REGPARM:
1152 printf_filtered (_("an argument in register %s"),
1153 gdbarch_register_name (current_gdbarch, val));
1154 break;
1155
1156 case LOC_REGPARM_ADDR:
1157 printf_filtered (_("address of an argument in register %s"),
1158 gdbarch_register_name (current_gdbarch, val));
1159 break;
1160
1161 case LOC_ARG:
1162 printf_filtered (_("an argument at offset %ld"), val);
1163 break;
1164
1165 case LOC_LOCAL:
1166 printf_filtered (_("a local variable at frame offset %ld"), val);
1167 break;
1168
1169 case LOC_REF_ARG:
1170 printf_filtered (_("a reference argument at offset %ld"), val);
1171 break;
1172
1173 case LOC_TYPEDEF:
1174 printf_filtered (_("a typedef"));
1175 break;
1176
1177 case LOC_BLOCK:
1178 printf_filtered (_("a function at address "));
1179 load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1180 fputs_filtered (paddress (load_addr), gdb_stdout);
1181 if (section_is_overlay (section))
1182 {
1183 load_addr = overlay_unmapped_address (load_addr, section);
1184 printf_filtered (_(",\n -- loaded at "));
1185 fputs_filtered (paddress (load_addr), gdb_stdout);
1186 printf_filtered (_(" in overlay section %s"), section->name);
1187 }
1188 break;
1189
1190 case LOC_UNRESOLVED:
1191 {
1192 struct minimal_symbol *msym;
1193
1194 msym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym), NULL, NULL);
1195 if (msym == NULL)
1196 printf_filtered ("unresolved");
1197 else
1198 {
1199 section = SYMBOL_BFD_SECTION (msym);
1200 printf_filtered (_("static storage at address "));
1201 load_addr = SYMBOL_VALUE_ADDRESS (msym);
1202 fputs_filtered (paddress (load_addr), gdb_stdout);
1203 if (section_is_overlay (section))
1204 {
1205 load_addr = overlay_unmapped_address (load_addr, section);
1206 printf_filtered (_(",\n -- loaded at "));
1207 fputs_filtered (paddress (load_addr), gdb_stdout);
1208 printf_filtered (_(" in overlay section %s"), section->name);
1209 }
1210 }
1211 }
1212 break;
1213
1214 case LOC_OPTIMIZED_OUT:
1215 printf_filtered (_("optimized out"));
1216 break;
1217
1218 default:
1219 printf_filtered (_("of unknown (botched) type"));
1220 break;
1221 }
1222 printf_filtered (".\n");
1223 }
1224 \f
1225
1226 static void
1227 x_command (char *exp, int from_tty)
1228 {
1229 struct expression *expr;
1230 struct format_data fmt;
1231 struct cleanup *old_chain;
1232 struct value *val;
1233
1234 fmt.format = last_format;
1235 fmt.size = last_size;
1236 fmt.count = 1;
1237
1238 if (exp && *exp == '/')
1239 {
1240 exp++;
1241 fmt = decode_format (&exp, last_format, last_size);
1242 }
1243
1244 /* If we have an expression, evaluate it and use it as the address. */
1245
1246 if (exp != 0 && *exp != 0)
1247 {
1248 expr = parse_expression (exp);
1249 /* Cause expression not to be there any more if this command is
1250 repeated with Newline. But don't clobber a user-defined
1251 command's definition. */
1252 if (from_tty)
1253 *exp = 0;
1254 old_chain = make_cleanup (free_current_contents, &expr);
1255 val = evaluate_expression (expr);
1256 if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
1257 val = value_ind (val);
1258 /* In rvalue contexts, such as this, functions are coerced into
1259 pointers to functions. This makes "x/i main" work. */
1260 if (/* last_format == 'i' && */
1261 TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
1262 && VALUE_LVAL (val) == lval_memory)
1263 next_address = VALUE_ADDRESS (val);
1264 else
1265 next_address = value_as_address (val);
1266 do_cleanups (old_chain);
1267 }
1268
1269 do_examine (fmt, next_address);
1270
1271 /* If the examine succeeds, we remember its size and format for next
1272 time. */
1273 last_size = fmt.size;
1274 last_format = fmt.format;
1275
1276 /* Set a couple of internal variables if appropriate. */
1277 if (last_examine_value)
1278 {
1279 /* Make last address examined available to the user as $_. Use
1280 the correct pointer type. */
1281 struct type *pointer_type
1282 = lookup_pointer_type (value_type (last_examine_value));
1283 set_internalvar (lookup_internalvar ("_"),
1284 value_from_pointer (pointer_type,
1285 last_examine_address));
1286
1287 /* Make contents of last address examined available to the user
1288 as $__. If the last value has not been fetched from memory
1289 then don't fetch it now; instead mark it by voiding the $__
1290 variable. */
1291 if (value_lazy (last_examine_value))
1292 set_internalvar (lookup_internalvar ("__"),
1293 allocate_value (builtin_type_void));
1294 else
1295 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1296 }
1297 }
1298 \f
1299
1300 /* Add an expression to the auto-display chain.
1301 Specify the expression. */
1302
1303 static void
1304 display_command (char *exp, int from_tty)
1305 {
1306 struct format_data fmt;
1307 struct expression *expr;
1308 struct display *new;
1309 int display_it = 1;
1310
1311 #if defined(TUI)
1312 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1313 `tui_version'. */
1314 if (tui_active && exp != NULL && *exp == '$')
1315 display_it = (tui_set_layout_for_display_command (exp) == TUI_FAILURE);
1316 #endif
1317
1318 if (display_it)
1319 {
1320 if (exp == 0)
1321 {
1322 do_displays ();
1323 return;
1324 }
1325
1326 if (*exp == '/')
1327 {
1328 exp++;
1329 fmt = decode_format (&exp, 0, 0);
1330 if (fmt.size && fmt.format == 0)
1331 fmt.format = 'x';
1332 if (fmt.format == 'i' || fmt.format == 's')
1333 fmt.size = 'b';
1334 }
1335 else
1336 {
1337 fmt.format = 0;
1338 fmt.size = 0;
1339 fmt.count = 0;
1340 }
1341
1342 innermost_block = 0;
1343 expr = parse_expression (exp);
1344
1345 new = (struct display *) xmalloc (sizeof (struct display));
1346
1347 new->exp = expr;
1348 new->block = innermost_block;
1349 new->next = display_chain;
1350 new->number = ++display_number;
1351 new->format = fmt;
1352 new->enabled_p = 1;
1353 display_chain = new;
1354
1355 if (from_tty && target_has_execution)
1356 do_one_display (new);
1357
1358 dont_repeat ();
1359 }
1360 }
1361
1362 static void
1363 free_display (struct display *d)
1364 {
1365 xfree (d->exp);
1366 xfree (d);
1367 }
1368
1369 /* Clear out the display_chain. Done when new symtabs are loaded,
1370 since this invalidates the types stored in many expressions. */
1371
1372 void
1373 clear_displays (void)
1374 {
1375 struct display *d;
1376
1377 while ((d = display_chain) != NULL)
1378 {
1379 xfree (d->exp);
1380 display_chain = d->next;
1381 xfree (d);
1382 }
1383 }
1384
1385 /* Delete the auto-display number NUM. */
1386
1387 static void
1388 delete_display (int num)
1389 {
1390 struct display *d1, *d;
1391
1392 if (!display_chain)
1393 error (_("No display number %d."), num);
1394
1395 if (display_chain->number == num)
1396 {
1397 d1 = display_chain;
1398 display_chain = d1->next;
1399 free_display (d1);
1400 }
1401 else
1402 for (d = display_chain;; d = d->next)
1403 {
1404 if (d->next == 0)
1405 error (_("No display number %d."), num);
1406 if (d->next->number == num)
1407 {
1408 d1 = d->next;
1409 d->next = d1->next;
1410 free_display (d1);
1411 break;
1412 }
1413 }
1414 }
1415
1416 /* Delete some values from the auto-display chain.
1417 Specify the element numbers. */
1418
1419 static void
1420 undisplay_command (char *args, int from_tty)
1421 {
1422 char *p = args;
1423 char *p1;
1424 int num;
1425
1426 if (args == 0)
1427 {
1428 if (query ("Delete all auto-display expressions? "))
1429 clear_displays ();
1430 dont_repeat ();
1431 return;
1432 }
1433
1434 while (*p)
1435 {
1436 p1 = p;
1437 while (*p1 >= '0' && *p1 <= '9')
1438 p1++;
1439 if (*p1 && *p1 != ' ' && *p1 != '\t')
1440 error (_("Arguments must be display numbers."));
1441
1442 num = atoi (p);
1443
1444 delete_display (num);
1445
1446 p = p1;
1447 while (*p == ' ' || *p == '\t')
1448 p++;
1449 }
1450 dont_repeat ();
1451 }
1452
1453 /* Display a single auto-display.
1454 Do nothing if the display cannot be printed in the current context,
1455 or if the display is disabled. */
1456
1457 static void
1458 do_one_display (struct display *d)
1459 {
1460 int within_current_scope;
1461
1462 if (d->enabled_p == 0)
1463 return;
1464
1465 if (d->block)
1466 within_current_scope = contained_in (get_selected_block (0), d->block);
1467 else
1468 within_current_scope = 1;
1469 if (!within_current_scope)
1470 return;
1471
1472 current_display_number = d->number;
1473
1474 annotate_display_begin ();
1475 printf_filtered ("%d", d->number);
1476 annotate_display_number_end ();
1477 printf_filtered (": ");
1478 if (d->format.size)
1479 {
1480 CORE_ADDR addr;
1481 struct value *val;
1482
1483 annotate_display_format ();
1484
1485 printf_filtered ("x/");
1486 if (d->format.count != 1)
1487 printf_filtered ("%d", d->format.count);
1488 printf_filtered ("%c", d->format.format);
1489 if (d->format.format != 'i' && d->format.format != 's')
1490 printf_filtered ("%c", d->format.size);
1491 printf_filtered (" ");
1492
1493 annotate_display_expression ();
1494
1495 print_expression (d->exp, gdb_stdout);
1496 annotate_display_expression_end ();
1497
1498 if (d->format.count != 1 || d->format.format == 'i')
1499 printf_filtered ("\n");
1500 else
1501 printf_filtered (" ");
1502
1503 val = evaluate_expression (d->exp);
1504 addr = value_as_address (val);
1505 if (d->format.format == 'i')
1506 addr = gdbarch_addr_bits_remove (current_gdbarch, addr);
1507
1508 annotate_display_value ();
1509
1510 do_examine (d->format, addr);
1511 }
1512 else
1513 {
1514 annotate_display_format ();
1515
1516 if (d->format.format)
1517 printf_filtered ("/%c ", d->format.format);
1518
1519 annotate_display_expression ();
1520
1521 print_expression (d->exp, gdb_stdout);
1522 annotate_display_expression_end ();
1523
1524 printf_filtered (" = ");
1525
1526 annotate_display_expression ();
1527
1528 print_formatted (evaluate_expression (d->exp),
1529 d->format.format, d->format.size, gdb_stdout);
1530 printf_filtered ("\n");
1531 }
1532
1533 annotate_display_end ();
1534
1535 gdb_flush (gdb_stdout);
1536 current_display_number = -1;
1537 }
1538
1539 /* Display all of the values on the auto-display chain which can be
1540 evaluated in the current scope. */
1541
1542 void
1543 do_displays (void)
1544 {
1545 struct display *d;
1546
1547 for (d = display_chain; d; d = d->next)
1548 do_one_display (d);
1549 }
1550
1551 /* Delete the auto-display which we were in the process of displaying.
1552 This is done when there is an error or a signal. */
1553
1554 void
1555 disable_display (int num)
1556 {
1557 struct display *d;
1558
1559 for (d = display_chain; d; d = d->next)
1560 if (d->number == num)
1561 {
1562 d->enabled_p = 0;
1563 return;
1564 }
1565 printf_unfiltered (_("No display number %d.\n"), num);
1566 }
1567
1568 void
1569 disable_current_display (void)
1570 {
1571 if (current_display_number >= 0)
1572 {
1573 disable_display (current_display_number);
1574 fprintf_unfiltered (gdb_stderr, _("\
1575 Disabling display %d to avoid infinite recursion.\n"),
1576 current_display_number);
1577 }
1578 current_display_number = -1;
1579 }
1580
1581 static void
1582 display_info (char *ignore, int from_tty)
1583 {
1584 struct display *d;
1585
1586 if (!display_chain)
1587 printf_unfiltered (_("There are no auto-display expressions now.\n"));
1588 else
1589 printf_filtered (_("Auto-display expressions now in effect:\n\
1590 Num Enb Expression\n"));
1591
1592 for (d = display_chain; d; d = d->next)
1593 {
1594 printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]);
1595 if (d->format.size)
1596 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1597 d->format.format);
1598 else if (d->format.format)
1599 printf_filtered ("/%c ", d->format.format);
1600 print_expression (d->exp, gdb_stdout);
1601 if (d->block && !contained_in (get_selected_block (0), d->block))
1602 printf_filtered (_(" (cannot be evaluated in the current context)"));
1603 printf_filtered ("\n");
1604 gdb_flush (gdb_stdout);
1605 }
1606 }
1607
1608 static void
1609 enable_display (char *args, int from_tty)
1610 {
1611 char *p = args;
1612 char *p1;
1613 int num;
1614 struct display *d;
1615
1616 if (p == 0)
1617 {
1618 for (d = display_chain; d; d = d->next)
1619 d->enabled_p = 1;
1620 }
1621 else
1622 while (*p)
1623 {
1624 p1 = p;
1625 while (*p1 >= '0' && *p1 <= '9')
1626 p1++;
1627 if (*p1 && *p1 != ' ' && *p1 != '\t')
1628 error (_("Arguments must be display numbers."));
1629
1630 num = atoi (p);
1631
1632 for (d = display_chain; d; d = d->next)
1633 if (d->number == num)
1634 {
1635 d->enabled_p = 1;
1636 goto win;
1637 }
1638 printf_unfiltered (_("No display number %d.\n"), num);
1639 win:
1640 p = p1;
1641 while (*p == ' ' || *p == '\t')
1642 p++;
1643 }
1644 }
1645
1646 static void
1647 disable_display_command (char *args, int from_tty)
1648 {
1649 char *p = args;
1650 char *p1;
1651 struct display *d;
1652
1653 if (p == 0)
1654 {
1655 for (d = display_chain; d; d = d->next)
1656 d->enabled_p = 0;
1657 }
1658 else
1659 while (*p)
1660 {
1661 p1 = p;
1662 while (*p1 >= '0' && *p1 <= '9')
1663 p1++;
1664 if (*p1 && *p1 != ' ' && *p1 != '\t')
1665 error (_("Arguments must be display numbers."));
1666
1667 disable_display (atoi (p));
1668
1669 p = p1;
1670 while (*p == ' ' || *p == '\t')
1671 p++;
1672 }
1673 }
1674 \f
1675
1676 /* Print the value in stack frame FRAME of a variable specified by a
1677 struct symbol. */
1678
1679 void
1680 print_variable_value (struct symbol *var, struct frame_info *frame,
1681 struct ui_file *stream)
1682 {
1683 struct value *val = read_var_value (var, frame);
1684
1685 value_print (val, stream, 0, Val_pretty_default);
1686 }
1687
1688 static void
1689 printf_command (char *arg, int from_tty)
1690 {
1691 char *f = NULL;
1692 char *s = arg;
1693 char *string = NULL;
1694 struct value **val_args;
1695 char *substrings;
1696 char *current_substring;
1697 int nargs = 0;
1698 int allocated_args = 20;
1699 struct cleanup *old_cleanups;
1700
1701 val_args = xmalloc (allocated_args * sizeof (struct value *));
1702 old_cleanups = make_cleanup (free_current_contents, &val_args);
1703
1704 if (s == 0)
1705 error_no_arg (_("format-control string and values to print"));
1706
1707 /* Skip white space before format string */
1708 while (*s == ' ' || *s == '\t')
1709 s++;
1710
1711 /* A format string should follow, enveloped in double quotes. */
1712 if (*s++ != '"')
1713 error (_("Bad format string, missing '\"'."));
1714
1715 /* Parse the format-control string and copy it into the string STRING,
1716 processing some kinds of escape sequence. */
1717
1718 f = string = (char *) alloca (strlen (s) + 1);
1719
1720 while (*s != '"')
1721 {
1722 int c = *s++;
1723 switch (c)
1724 {
1725 case '\0':
1726 error (_("Bad format string, non-terminated '\"'."));
1727
1728 case '\\':
1729 switch (c = *s++)
1730 {
1731 case '\\':
1732 *f++ = '\\';
1733 break;
1734 case 'a':
1735 *f++ = '\a';
1736 break;
1737 case 'b':
1738 *f++ = '\b';
1739 break;
1740 case 'f':
1741 *f++ = '\f';
1742 break;
1743 case 'n':
1744 *f++ = '\n';
1745 break;
1746 case 'r':
1747 *f++ = '\r';
1748 break;
1749 case 't':
1750 *f++ = '\t';
1751 break;
1752 case 'v':
1753 *f++ = '\v';
1754 break;
1755 case '"':
1756 *f++ = '"';
1757 break;
1758 default:
1759 /* ??? TODO: handle other escape sequences */
1760 error (_("Unrecognized escape character \\%c in format string."),
1761 c);
1762 }
1763 break;
1764
1765 default:
1766 *f++ = c;
1767 }
1768 }
1769
1770 /* Skip over " and following space and comma. */
1771 s++;
1772 *f++ = '\0';
1773 while (*s == ' ' || *s == '\t')
1774 s++;
1775
1776 if (*s != ',' && *s != 0)
1777 error (_("Invalid argument syntax"));
1778
1779 if (*s == ',')
1780 s++;
1781 while (*s == ' ' || *s == '\t')
1782 s++;
1783
1784 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1785 substrings = alloca (strlen (string) * 2);
1786 current_substring = substrings;
1787
1788 {
1789 /* Now scan the string for %-specs and see what kinds of args they want.
1790 argclass[I] classifies the %-specs so we can give printf_filtered
1791 something of the right size. */
1792
1793 enum argclass
1794 {
1795 int_arg, long_arg, long_long_arg, ptr_arg, string_arg,
1796 double_arg, long_double_arg, decfloat_arg
1797 };
1798 enum argclass *argclass;
1799 enum argclass this_argclass;
1800 char *last_arg;
1801 int nargs_wanted;
1802 int i;
1803
1804 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1805 nargs_wanted = 0;
1806 f = string;
1807 last_arg = string;
1808 while (*f)
1809 if (*f++ == '%')
1810 {
1811 int seen_hash = 0, seen_zero = 0, lcount = 0, seen_prec = 0;
1812 int seen_space = 0, seen_plus = 0;
1813 int seen_big_l = 0, seen_h = 0, seen_big_h = 0;
1814 int seen_big_d = 0, seen_double_big_d = 0;
1815 int bad = 0;
1816
1817 /* Check the validity of the format specifier, and work
1818 out what argument it expects. We only accept C89
1819 format strings, with the exception of long long (which
1820 we autoconf for). */
1821
1822 /* Skip over "%%". */
1823 if (*f == '%')
1824 {
1825 f++;
1826 continue;
1827 }
1828
1829 /* The first part of a format specifier is a set of flag
1830 characters. */
1831 while (strchr ("0-+ #", *f))
1832 {
1833 if (*f == '#')
1834 seen_hash = 1;
1835 else if (*f == '0')
1836 seen_zero = 1;
1837 else if (*f == ' ')
1838 seen_space = 1;
1839 else if (*f == '+')
1840 seen_plus = 1;
1841 f++;
1842 }
1843
1844 /* The next part of a format specifier is a width. */
1845 while (strchr ("0123456789", *f))
1846 f++;
1847
1848 /* The next part of a format specifier is a precision. */
1849 if (*f == '.')
1850 {
1851 seen_prec = 1;
1852 f++;
1853 while (strchr ("0123456789", *f))
1854 f++;
1855 }
1856
1857 /* The next part of a format specifier is a length modifier. */
1858 if (*f == 'h')
1859 {
1860 seen_h = 1;
1861 f++;
1862 }
1863 else if (*f == 'l')
1864 {
1865 f++;
1866 lcount++;
1867 if (*f == 'l')
1868 {
1869 f++;
1870 lcount++;
1871 }
1872 }
1873 else if (*f == 'L')
1874 {
1875 seen_big_l = 1;
1876 f++;
1877 }
1878 /* Decimal32 modifier. */
1879 else if (*f == 'H')
1880 {
1881 seen_big_h = 1;
1882 f++;
1883 }
1884 /* Decimal64 and Decimal128 modifiers. */
1885 else if (*f == 'D')
1886 {
1887 f++;
1888
1889 /* Check for a Decimal128. */
1890 if (*f == 'D')
1891 {
1892 f++;
1893 seen_double_big_d = 1;
1894 }
1895 else
1896 seen_big_d = 1;
1897 }
1898
1899 switch (*f)
1900 {
1901 case 'u':
1902 if (seen_hash)
1903 bad = 1;
1904 /* FALLTHROUGH */
1905
1906 case 'o':
1907 case 'x':
1908 case 'X':
1909 if (seen_space || seen_plus)
1910 bad = 1;
1911 /* FALLTHROUGH */
1912
1913 case 'd':
1914 case 'i':
1915 if (lcount == 0)
1916 this_argclass = int_arg;
1917 else if (lcount == 1)
1918 this_argclass = long_arg;
1919 else
1920 this_argclass = long_long_arg;
1921
1922 if (seen_big_l)
1923 bad = 1;
1924 break;
1925
1926 case 'c':
1927 this_argclass = int_arg;
1928 if (lcount || seen_h || seen_big_l)
1929 bad = 1;
1930 if (seen_prec || seen_zero || seen_space || seen_plus)
1931 bad = 1;
1932 break;
1933
1934 case 'p':
1935 this_argclass = ptr_arg;
1936 if (lcount || seen_h || seen_big_l)
1937 bad = 1;
1938 if (seen_prec || seen_zero || seen_space || seen_plus)
1939 bad = 1;
1940 break;
1941
1942 case 's':
1943 this_argclass = string_arg;
1944 if (lcount || seen_h || seen_big_l)
1945 bad = 1;
1946 if (seen_zero || seen_space || seen_plus)
1947 bad = 1;
1948 break;
1949
1950 case 'e':
1951 case 'f':
1952 case 'g':
1953 case 'E':
1954 case 'G':
1955 if (seen_big_h || seen_big_d || seen_double_big_d)
1956 this_argclass = decfloat_arg;
1957 else if (seen_big_l)
1958 this_argclass = long_double_arg;
1959 else
1960 this_argclass = double_arg;
1961
1962 if (lcount || seen_h)
1963 bad = 1;
1964 break;
1965
1966 case '*':
1967 error (_("`*' not supported for precision or width in printf"));
1968
1969 case 'n':
1970 error (_("Format specifier `n' not supported in printf"));
1971
1972 case '\0':
1973 error (_("Incomplete format specifier at end of format string"));
1974
1975 default:
1976 error (_("Unrecognized format specifier '%c' in printf"), *f);
1977 }
1978
1979 if (bad)
1980 error (_("Inappropriate modifiers to format specifier '%c' in printf"),
1981 *f);
1982
1983 f++;
1984
1985 if (lcount > 1 && USE_PRINTF_I64)
1986 {
1987 /* Windows' printf does support long long, but not the usual way.
1988 Convert %lld to %I64d. */
1989 int length_before_ll = f - last_arg - 1 - lcount;
1990 strncpy (current_substring, last_arg, length_before_ll);
1991 strcpy (current_substring + length_before_ll, "I64");
1992 current_substring[length_before_ll + 3] =
1993 last_arg[length_before_ll + lcount];
1994 current_substring += length_before_ll + 4;
1995 }
1996 else
1997 {
1998 strncpy (current_substring, last_arg, f - last_arg);
1999 current_substring += f - last_arg;
2000 }
2001 *current_substring++ = '\0';
2002 last_arg = f;
2003 argclass[nargs_wanted++] = this_argclass;
2004 }
2005
2006 /* Now, parse all arguments and evaluate them.
2007 Store the VALUEs in VAL_ARGS. */
2008
2009 while (*s != '\0')
2010 {
2011 char *s1;
2012 if (nargs == allocated_args)
2013 val_args = (struct value **) xrealloc ((char *) val_args,
2014 (allocated_args *= 2)
2015 * sizeof (struct value *));
2016 s1 = s;
2017 val_args[nargs] = parse_to_comma_and_eval (&s1);
2018
2019 /* If format string wants a float, unchecked-convert the value to
2020 floating point of the same size */
2021
2022 if (argclass[nargs] == double_arg)
2023 {
2024 struct type *type = value_type (val_args[nargs]);
2025 if (TYPE_LENGTH (type) == sizeof (float))
2026 deprecated_set_value_type (val_args[nargs], builtin_type_float);
2027 if (TYPE_LENGTH (type) == sizeof (double))
2028 deprecated_set_value_type (val_args[nargs], builtin_type_double);
2029 }
2030 nargs++;
2031 s = s1;
2032 if (*s == ',')
2033 s++;
2034 }
2035
2036 if (nargs != nargs_wanted)
2037 error (_("Wrong number of arguments for specified format-string"));
2038
2039 /* Now actually print them. */
2040 current_substring = substrings;
2041 for (i = 0; i < nargs; i++)
2042 {
2043 switch (argclass[i])
2044 {
2045 case string_arg:
2046 {
2047 gdb_byte *str;
2048 CORE_ADDR tem;
2049 int j;
2050 tem = value_as_address (val_args[i]);
2051
2052 /* This is a %s argument. Find the length of the string. */
2053 for (j = 0;; j++)
2054 {
2055 gdb_byte c;
2056 QUIT;
2057 read_memory (tem + j, &c, 1);
2058 if (c == 0)
2059 break;
2060 }
2061
2062 /* Copy the string contents into a string inside GDB. */
2063 str = (gdb_byte *) alloca (j + 1);
2064 if (j != 0)
2065 read_memory (tem, str, j);
2066 str[j] = 0;
2067
2068 printf_filtered (current_substring, (char *) str);
2069 }
2070 break;
2071 case double_arg:
2072 {
2073 double val = value_as_double (val_args[i]);
2074 printf_filtered (current_substring, val);
2075 break;
2076 }
2077 case long_double_arg:
2078 #ifdef HAVE_LONG_DOUBLE
2079 {
2080 long double val = value_as_double (val_args[i]);
2081 printf_filtered (current_substring, val);
2082 break;
2083 }
2084 #else
2085 error (_("long double not supported in printf"));
2086 #endif
2087 case long_long_arg:
2088 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2089 {
2090 long long val = value_as_long (val_args[i]);
2091 printf_filtered (current_substring, val);
2092 break;
2093 }
2094 #else
2095 error (_("long long not supported in printf"));
2096 #endif
2097 case int_arg:
2098 {
2099 int val = value_as_long (val_args[i]);
2100 printf_filtered (current_substring, val);
2101 break;
2102 }
2103 case long_arg:
2104 {
2105 long val = value_as_long (val_args[i]);
2106 printf_filtered (current_substring, val);
2107 break;
2108 }
2109
2110 /* Handles decimal floating values. */
2111 case decfloat_arg:
2112 {
2113 const gdb_byte *param_ptr = value_contents (val_args[i]);
2114 #if defined (PRINTF_HAS_DECFLOAT)
2115 /* If we have native support for Decimal floating
2116 printing, handle it here. */
2117 printf_filtered (current_substring, param_ptr);
2118 #else
2119
2120 /* As a workaround until vasprintf has native support for DFP
2121 we convert the DFP values to string and print them using
2122 the %s format specifier. */
2123
2124 char *eos, *sos;
2125 int nnull_chars = 0;
2126
2127 /* Parameter data. */
2128 struct type *param_type = value_type (val_args[i]);
2129 unsigned int param_len = TYPE_LENGTH (param_type);
2130
2131 /* DFP output data. */
2132 struct value *dfp_value = NULL;
2133 gdb_byte *dfp_ptr;
2134 int dfp_len = 16;
2135 gdb_byte dec[16];
2136 struct type *dfp_type = NULL;
2137 char decstr[MAX_DECIMAL_STRING];
2138
2139 /* Points to the end of the string so that we can go back
2140 and check for DFP length modifiers. */
2141 eos = current_substring + strlen (current_substring);
2142
2143 /* Look for the float/double format specifier. */
2144 while (*eos != 'f' && *eos != 'e' && *eos != 'E'
2145 && *eos != 'g' && *eos != 'G')
2146 eos--;
2147
2148 sos = eos;
2149
2150 /* Search for the '%' char and extract the size and type of
2151 the output decimal value based on its modifiers
2152 (%Hf, %Df, %DDf). */
2153 while (*--sos != '%')
2154 {
2155 if (*sos == 'H')
2156 {
2157 dfp_len = 4;
2158 dfp_type = builtin_type (current_gdbarch)->builtin_decfloat;
2159 }
2160 else if (*sos == 'D' && *(sos - 1) == 'D')
2161 {
2162 dfp_len = 16;
2163 dfp_type = builtin_type (current_gdbarch)->builtin_declong;
2164 sos--;
2165 }
2166 else
2167 {
2168 dfp_len = 8;
2169 dfp_type = builtin_type (current_gdbarch)->builtin_decdouble;
2170 }
2171 }
2172
2173 /* Replace %Hf, %Df and %DDf with %s's. */
2174 *++sos = 's';
2175
2176 /* Go through the whole format string and pull the correct
2177 number of chars back to compensate for the change in the
2178 format specifier. */
2179 while (nnull_chars < nargs - i)
2180 {
2181 if (*eos == '\0')
2182 nnull_chars++;
2183
2184 *++sos = *++eos;
2185 }
2186
2187 /* Conversion between different DFP types. */
2188 if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT)
2189 decimal_convert (param_ptr, param_len, dec, dfp_len);
2190 else
2191 /* If this is a non-trivial conversion, just output 0.
2192 A correct converted value can be displayed by explicitly
2193 casting to a DFP type. */
2194 decimal_from_string (dec, dfp_len, "0");
2195
2196 dfp_value = value_from_decfloat (dfp_type, dec);
2197
2198 dfp_ptr = (gdb_byte *) value_contents (dfp_value);
2199
2200 decimal_to_string (dfp_ptr, dfp_len, decstr);
2201
2202 /* Print the DFP value. */
2203 printf_filtered (current_substring, decstr);
2204
2205 break;
2206 #endif
2207 }
2208
2209 case ptr_arg:
2210 {
2211 /* We avoid the host's %p because pointers are too
2212 likely to be the wrong size. The only interesting
2213 modifier for %p is a width; extract that, and then
2214 handle %p as glibc would: %#x or a literal "(nil)". */
2215
2216 char *p, *fmt, *fmt_p;
2217 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2218 long long val = value_as_long (val_args[i]);
2219 #else
2220 long val = value_as_long (val_args[i]);
2221 #endif
2222
2223 fmt = alloca (strlen (current_substring) + 5);
2224
2225 /* Copy up to the leading %. */
2226 p = current_substring;
2227 fmt_p = fmt;
2228 while (*p)
2229 {
2230 int is_percent = (*p == '%');
2231 *fmt_p++ = *p++;
2232 if (is_percent)
2233 {
2234 if (*p == '%')
2235 *fmt_p++ = *p++;
2236 else
2237 break;
2238 }
2239 }
2240
2241 if (val != 0)
2242 *fmt_p++ = '#';
2243
2244 /* Copy any width. */
2245 while (*p >= '0' && *p < '9')
2246 *fmt_p++ = *p++;
2247
2248 gdb_assert (*p == 'p' && *(p + 1) == '\0');
2249 if (val != 0)
2250 {
2251 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
2252 *fmt_p++ = 'l';
2253 #endif
2254 *fmt_p++ = 'l';
2255 *fmt_p++ = 'x';
2256 *fmt_p++ = '\0';
2257 printf_filtered (fmt, val);
2258 }
2259 else
2260 {
2261 *fmt_p++ = 's';
2262 *fmt_p++ = '\0';
2263 printf_filtered (fmt, "(nil)");
2264 }
2265
2266 break;
2267 }
2268 default:
2269 internal_error (__FILE__, __LINE__,
2270 _("failed internal consistency check"));
2271 }
2272 /* Skip to the next substring. */
2273 current_substring += strlen (current_substring) + 1;
2274 }
2275 /* Print the portion of the format string after the last argument. */
2276 puts_filtered (last_arg);
2277 }
2278 do_cleanups (old_cleanups);
2279 }
2280
2281 void
2282 _initialize_printcmd (void)
2283 {
2284 struct cmd_list_element *c;
2285
2286 current_display_number = -1;
2287
2288 add_info ("address", address_info,
2289 _("Describe where symbol SYM is stored."));
2290
2291 add_info ("symbol", sym_info, _("\
2292 Describe what symbol is at location ADDR.\n\
2293 Only for symbols with fixed locations (global or static scope)."));
2294
2295 add_com ("x", class_vars, x_command, _("\
2296 Examine memory: x/FMT ADDRESS.\n\
2297 ADDRESS is an expression for the memory address to examine.\n\
2298 FMT is a repeat count followed by a format letter and a size letter.\n\
2299 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2300 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
2301 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
2302 The specified number of objects of the specified size are printed\n\
2303 according to the format.\n\n\
2304 Defaults for format and size letters are those previously used.\n\
2305 Default count is 1. Default address is following last thing printed\n\
2306 with this command or \"print\"."));
2307
2308 #if 0
2309 add_com ("whereis", class_vars, whereis_command,
2310 _("Print line number and file of definition of variable."));
2311 #endif
2312
2313 add_info ("display", display_info, _("\
2314 Expressions to display when program stops, with code numbers."));
2315
2316 add_cmd ("undisplay", class_vars, undisplay_command, _("\
2317 Cancel some expressions to be displayed when program stops.\n\
2318 Arguments are the code numbers of the expressions to stop displaying.\n\
2319 No argument means cancel all automatic-display expressions.\n\
2320 \"delete display\" has the same effect as this command.\n\
2321 Do \"info display\" to see current list of code numbers."),
2322 &cmdlist);
2323
2324 add_com ("display", class_vars, display_command, _("\
2325 Print value of expression EXP each time the program stops.\n\
2326 /FMT may be used before EXP as in the \"print\" command.\n\
2327 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2328 as in the \"x\" command, and then EXP is used to get the address to examine\n\
2329 and examining is done as in the \"x\" command.\n\n\
2330 With no argument, display all currently requested auto-display expressions.\n\
2331 Use \"undisplay\" to cancel display requests previously made."));
2332
2333 add_cmd ("display", class_vars, enable_display, _("\
2334 Enable some expressions to be displayed when program stops.\n\
2335 Arguments are the code numbers of the expressions to resume displaying.\n\
2336 No argument means enable all automatic-display expressions.\n\
2337 Do \"info display\" to see current list of code numbers."), &enablelist);
2338
2339 add_cmd ("display", class_vars, disable_display_command, _("\
2340 Disable some expressions to be displayed when program stops.\n\
2341 Arguments are the code numbers of the expressions to stop displaying.\n\
2342 No argument means disable all automatic-display expressions.\n\
2343 Do \"info display\" to see current list of code numbers."), &disablelist);
2344
2345 add_cmd ("display", class_vars, undisplay_command, _("\
2346 Cancel some expressions to be displayed when program stops.\n\
2347 Arguments are the code numbers of the expressions to stop displaying.\n\
2348 No argument means cancel all automatic-display expressions.\n\
2349 Do \"info display\" to see current list of code numbers."), &deletelist);
2350
2351 add_com ("printf", class_vars, printf_command, _("\
2352 printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2353 This is useful for formatted output in user-defined commands."));
2354
2355 add_com ("output", class_vars, output_command, _("\
2356 Like \"print\" but don't put in value history and don't print newline.\n\
2357 This is useful in user-defined commands."));
2358
2359 add_prefix_cmd ("set", class_vars, set_command, _("\
2360 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2361 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2362 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2363 with $), a register (a few standard names starting with $), or an actual\n\
2364 variable in the program being debugged. EXP is any valid expression.\n\
2365 Use \"set variable\" for variables with names identical to set subcommands.\n\
2366 \n\
2367 With a subcommand, this command modifies parts of the gdb environment.\n\
2368 You can see these environment settings with the \"show\" command."),
2369 &setlist, "set ", 1, &cmdlist);
2370 if (dbx_commands)
2371 add_com ("assign", class_vars, set_command, _("\
2372 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2373 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2374 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2375 with $), a register (a few standard names starting with $), or an actual\n\
2376 variable in the program being debugged. EXP is any valid expression.\n\
2377 Use \"set variable\" for variables with names identical to set subcommands.\n\
2378 \nWith a subcommand, this command modifies parts of the gdb environment.\n\
2379 You can see these environment settings with the \"show\" command."));
2380
2381 /* "call" is the same as "set", but handy for dbx users to call fns. */
2382 c = add_com ("call", class_vars, call_command, _("\
2383 Call a function in the program.\n\
2384 The argument is the function name and arguments, in the notation of the\n\
2385 current working language. The result is printed and saved in the value\n\
2386 history, if it is not void."));
2387 set_cmd_completer (c, location_completer);
2388
2389 add_cmd ("variable", class_vars, set_command, _("\
2390 Evaluate expression EXP and assign result to variable VAR, using assignment\n\
2391 syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2392 example). VAR may be a debugger \"convenience\" variable (names starting\n\
2393 with $), a register (a few standard names starting with $), or an actual\n\
2394 variable in the program being debugged. EXP is any valid expression.\n\
2395 This may usually be abbreviated to simply \"set\"."),
2396 &setlist);
2397
2398 c = add_com ("print", class_vars, print_command, _("\
2399 Print value of expression EXP.\n\
2400 Variables accessible are those of the lexical environment of the selected\n\
2401 stack frame, plus all those whose scope is global or an entire file.\n\
2402 \n\
2403 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2404 $$NUM refers to NUM'th value back from the last one.\n\
2405 Names starting with $ refer to registers (with the values they would have\n\
2406 if the program were to return to the stack frame now selected, restoring\n\
2407 all registers saved by frames farther in) or else to debugger\n\
2408 \"convenience\" variables (any such name not a known register).\n\
2409 Use assignment expressions to give values to convenience variables.\n\
2410 \n\
2411 {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2412 @ is a binary operator for treating consecutive data objects\n\
2413 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2414 element is FOO, whose second element is stored in the space following\n\
2415 where FOO is stored, etc. FOO must be an expression whose value\n\
2416 resides in memory.\n\
2417 \n\
2418 EXP may be preceded with /FMT, where FMT is a format letter\n\
2419 but no count or size letter (see \"x\" command)."));
2420 set_cmd_completer (c, location_completer);
2421 add_com_alias ("p", "print", class_vars, 1);
2422
2423 c = add_com ("inspect", class_vars, inspect_command, _("\
2424 Same as \"print\" command, except that if you are running in the epoch\n\
2425 environment, the value is printed in its own window."));
2426 set_cmd_completer (c, location_completer);
2427
2428 add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
2429 &max_symbolic_offset, _("\
2430 Set the largest offset that will be printed in <symbol+1234> form."), _("\
2431 Show the largest offset that will be printed in <symbol+1234> form."), NULL,
2432 NULL,
2433 show_max_symbolic_offset,
2434 &setprintlist, &showprintlist);
2435 add_setshow_boolean_cmd ("symbol-filename", no_class,
2436 &print_symbol_filename, _("\
2437 Set printing of source filename and line number with <symbol>."), _("\
2438 Show printing of source filename and line number with <symbol>."), NULL,
2439 NULL,
2440 show_print_symbol_filename,
2441 &setprintlist, &showprintlist);
2442
2443 /* For examine/instruction a single byte quantity is specified as
2444 the data. This avoids problems with value_at_lazy() requiring a
2445 valid data type (and rejecting VOID). */
2446 examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
2447
2448 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2449 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2450 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2451 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);
2452
2453 }