2005-02-14 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / printcmd.c
CommitLineData
c906108c 1/* Print values for GNU debugger GDB.
e2ad119d 2
8926118c 3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
0fd88904
AC
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
5 Free Software Foundation, Inc.
c906108c 6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
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 2 of the License, or
12 (at your option) any later version.
c906108c 13
c5aa993b
JM
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.
c906108c 18
c5aa993b
JM
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
c906108c
SS
23
24#include "defs.h"
25#include "gdb_string.h"
26#include "frame.h"
27#include "symtab.h"
28#include "gdbtypes.h"
29#include "value.h"
30#include "language.h"
31#include "expression.h"
32#include "gdbcore.h"
33#include "gdbcmd.h"
34#include "target.h"
35#include "breakpoint.h"
36#include "demangle.h"
37#include "valprint.h"
38#include "annotate.h"
c5aa993b
JM
39#include "symfile.h" /* for overlay functions */
40#include "objfiles.h" /* ditto */
c94fdfd0 41#include "completer.h" /* for completion functions */
8b93c638 42#include "ui-out.h"
261397f8 43#include "gdb_assert.h"
fe898f56 44#include "block.h"
92bf2b80 45#include "disasm.h"
c906108c 46
6a83354a
AC
47#ifdef TUI
48#include "tui/tui.h" /* For tui_active et.al. */
49#endif
50
c906108c
SS
51extern int asm_demangle; /* Whether to demangle syms in asm printouts */
52extern int addressprint; /* Whether to print hex addresses in HLL " */
53
54struct format_data
c5aa993b
JM
55 {
56 int count;
57 char format;
58 char size;
59 };
c906108c
SS
60
61/* Last specified output format. */
62
63static char last_format = 'x';
64
65/* Last specified examination size. 'b', 'h', 'w' or `q'. */
66
67static char last_size = 'w';
68
69/* Default address to examine next. */
70
71static CORE_ADDR next_address;
72
c906108c
SS
73/* Last address examined. */
74
75static CORE_ADDR last_examine_address;
76
77/* Contents of last address examined.
78 This is not valid past the end of the `x' command! */
79
3d6d86c6 80static struct value *last_examine_value;
c906108c
SS
81
82/* Largest offset between a symbolic value and an address, that will be
83 printed as `0x1234 <symbol+offset>'. */
84
85static unsigned int max_symbolic_offset = UINT_MAX;
86
87/* Append the source filename and linenumber of the symbol when
88 printing a symbolic value as `<symbol at filename:linenum>' if set. */
89static int print_symbol_filename = 0;
90
91/* Number of auto-display expression currently being displayed.
92 So that we can disable it if we get an error or a signal within it.
93 -1 when not doing one. */
94
95int current_display_number;
96
97/* Flag to low-level print routines that this value is being printed
98 in an epoch window. We'd like to pass this as a parameter, but
99 every routine would need to take it. Perhaps we can encapsulate
100 this in the I/O stream once we have GNU stdio. */
101
102int inspect_it = 0;
103
104struct display
c5aa993b
JM
105 {
106 /* Chain link to next auto-display item. */
107 struct display *next;
108 /* Expression to be evaluated and displayed. */
109 struct expression *exp;
110 /* Item number of this auto-display item. */
111 int number;
112 /* Display format specified. */
113 struct format_data format;
114 /* Innermost block required by this expression when evaluated */
115 struct block *block;
116 /* Status of this display (enabled or disabled) */
b5de0fa7 117 int enabled_p;
c5aa993b 118 };
c906108c
SS
119
120/* Chain of expressions whose values should be displayed
121 automatically each time the program stops. */
122
123static struct display *display_chain;
124
125static int display_number;
126
127/* Prototypes for exported functions. */
128
a14ed312 129void output_command (char *, int);
c906108c 130
a14ed312 131void _initialize_printcmd (void);
c906108c
SS
132
133/* Prototypes for local functions. */
134
a14ed312 135static void delete_display (int);
c906108c 136
a14ed312 137static void enable_display (char *, int);
c906108c 138
a14ed312 139static void disable_display_command (char *, int);
c906108c 140
a14ed312 141static void printf_command (char *, int);
c906108c 142
a14ed312 143static void display_info (char *, int);
c906108c 144
a14ed312 145static void do_one_display (struct display *);
c906108c 146
a14ed312 147static void undisplay_command (char *, int);
c906108c 148
a14ed312 149static void free_display (struct display *);
c906108c 150
a14ed312 151static void display_command (char *, int);
c906108c 152
a14ed312 153void x_command (char *, int);
c906108c 154
a14ed312 155static void address_info (char *, int);
c906108c 156
a14ed312 157static void set_command (char *, int);
c906108c 158
a14ed312 159static void call_command (char *, int);
c906108c 160
a14ed312 161static void inspect_command (char *, int);
c906108c 162
a14ed312 163static void print_command (char *, int);
c906108c 164
a14ed312 165static void print_command_1 (char *, int, int);
c906108c 166
a14ed312 167static void validate_format (struct format_data, char *);
c906108c 168
3d6d86c6 169static void print_formatted (struct value *, int, int, struct ui_file *);
c906108c 170
a14ed312 171static struct format_data decode_format (char **, int, int);
c906108c 172
a14ed312 173static void sym_info (char *, int);
c906108c 174\f
c5aa993b 175
c906108c
SS
176/* Decode a format specification. *STRING_PTR should point to it.
177 OFORMAT and OSIZE are used as defaults for the format and size
178 if none are given in the format specification.
179 If OSIZE is zero, then the size field of the returned value
180 should be set only if a size is explicitly specified by the
181 user.
182 The structure returned describes all the data
183 found in the specification. In addition, *STRING_PTR is advanced
184 past the specification and past all whitespace following it. */
185
186static struct format_data
fba45db2 187decode_format (char **string_ptr, int oformat, int osize)
c906108c
SS
188{
189 struct format_data val;
52f0bd74 190 char *p = *string_ptr;
c906108c
SS
191
192 val.format = '?';
193 val.size = '?';
194 val.count = 1;
195
196 if (*p >= '0' && *p <= '9')
197 val.count = atoi (p);
c5aa993b
JM
198 while (*p >= '0' && *p <= '9')
199 p++;
c906108c
SS
200
201 /* Now process size or format letters that follow. */
202
203 while (1)
204 {
205 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
206 val.size = *p++;
207 else if (*p >= 'a' && *p <= 'z')
208 val.format = *p++;
209 else
210 break;
211 }
212
c5aa993b
JM
213 while (*p == ' ' || *p == '\t')
214 p++;
c906108c
SS
215 *string_ptr = p;
216
217 /* Set defaults for format and size if not specified. */
218 if (val.format == '?')
219 {
220 if (val.size == '?')
221 {
222 /* Neither has been specified. */
223 val.format = oformat;
224 val.size = osize;
225 }
226 else
227 /* If a size is specified, any format makes a reasonable
228 default except 'i'. */
229 val.format = oformat == 'i' ? 'x' : oformat;
230 }
231 else if (val.size == '?')
232 switch (val.format)
233 {
234 case 'a':
235 case 's':
236 /* Pick the appropriate size for an address. */
237 if (TARGET_PTR_BIT == 64)
238 val.size = osize ? 'g' : osize;
239 else if (TARGET_PTR_BIT == 32)
240 val.size = osize ? 'w' : osize;
241 else if (TARGET_PTR_BIT == 16)
242 val.size = osize ? 'h' : osize;
243 else
244 /* Bad value for TARGET_PTR_BIT */
e2e0b3e5 245 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
c906108c
SS
246 break;
247 case 'f':
248 /* Floating point has to be word or giantword. */
249 if (osize == 'w' || osize == 'g')
250 val.size = osize;
251 else
252 /* Default it to giantword if the last used size is not
253 appropriate. */
254 val.size = osize ? 'g' : osize;
255 break;
256 case 'c':
257 /* Characters default to one byte. */
258 val.size = osize ? 'b' : osize;
259 break;
260 default:
261 /* The default is the size most recently specified. */
262 val.size = osize;
263 }
264
265 return val;
266}
267\f
2acceee2 268/* Print value VAL on stream according to FORMAT, a letter or 0.
c906108c
SS
269 Do not end with a newline.
270 0 means print VAL according to its own type.
271 SIZE is the letter for the size of datum being printed.
272 This is used to pad hex numbers so they line up. */
273
274static void
aa1ee363 275print_formatted (struct value *val, int format, int size,
fba45db2 276 struct ui_file *stream)
c906108c 277{
df407dfe 278 struct type *type = check_typedef (value_type (val));
c906108c
SS
279 int len = TYPE_LENGTH (type);
280
281 if (VALUE_LVAL (val) == lval_memory)
282 {
283 next_address = VALUE_ADDRESS (val) + len;
c906108c
SS
284 }
285
286 switch (format)
287 {
288 case 's':
289 /* FIXME: Need to handle wchar_t's here... */
290 next_address = VALUE_ADDRESS (val)
2acceee2 291 + val_print_string (VALUE_ADDRESS (val), -1, 1, stream);
c906108c
SS
292 break;
293
294 case 'i':
295 /* The old comment says
c5aa993b
JM
296 "Force output out, print_insn not using _filtered".
297 I'm not completely sure what that means, I suspect most print_insn
298 now do use _filtered, so I guess it's obsolete.
299 --Yes, it does filter now, and so this is obsolete. -JB */
c906108c
SS
300
301 /* We often wrap here if there are long symbolic names. */
302 wrap_here (" ");
303 next_address = VALUE_ADDRESS (val)
92bf2b80 304 + gdb_print_insn (VALUE_ADDRESS (val), stream);
c906108c
SS
305 break;
306
307 default:
308 if (format == 0
309 || TYPE_CODE (type) == TYPE_CODE_ARRAY
310 || TYPE_CODE (type) == TYPE_CODE_STRING
311 || TYPE_CODE (type) == TYPE_CODE_STRUCT
5c4e30ca
DC
312 || TYPE_CODE (type) == TYPE_CODE_UNION
313 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
c5aa993b
JM
314 /* If format is 0, use the 'natural' format for
315 * that type of value. If the type is non-scalar,
316 * we have to use language rules to print it as
317 * a series of scalars.
318 */
2acceee2 319 value_print (val, stream, format, Val_pretty_default);
c906108c 320 else
c5aa993b
JM
321 /* User specified format, so don't look to the
322 * the type to tell us what to do.
323 */
0fd88904 324 print_scalar_formatted (value_contents (val), type,
2acceee2 325 format, size, stream);
c906108c
SS
326 }
327}
328
329/* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
330 according to letters FORMAT and SIZE on STREAM.
331 FORMAT may not be zero. Formats s and i are not supported at this level.
332
333 This is how the elements of an array or structure are printed
334 with a format. */
335
336void
366b1cbf
AC
337print_scalar_formatted (const void *valaddr, struct type *type,
338 int format, int size, struct ui_file *stream)
c906108c 339{
81cb7cc9 340 LONGEST val_long = 0;
c906108c
SS
341 unsigned int len = TYPE_LENGTH (type);
342
6b9acc27
JJ
343 if (len > sizeof(LONGEST) &&
344 (TYPE_CODE (type) == TYPE_CODE_INT
345 || TYPE_CODE (type) == TYPE_CODE_ENUM))
346 {
347 switch (format)
348 {
349 case 'o':
350 print_octal_chars (stream, valaddr, len);
351 return;
352 case 'u':
353 case 'd':
354 print_decimal_chars (stream, valaddr, len);
355 return;
356 case 't':
357 print_binary_chars (stream, valaddr, len);
358 return;
359 case 'x':
360 print_hex_chars (stream, valaddr, len);
361 return;
362 case 'c':
363 print_char_chars (stream, valaddr, len);
364 return;
365 default:
366 break;
367 };
368 }
369
95051d27 370 if (format != 'f')
c906108c
SS
371 val_long = unpack_long (type, valaddr);
372
ef166cf4 373 /* If the value is a pointer, and pointers and addresses are not the
d0aee0c4
FF
374 same, then at this point, the value's length (in target bytes) is
375 TARGET_ADDR_BIT/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */
ef166cf4 376 if (TYPE_CODE (type) == TYPE_CODE_PTR)
d0aee0c4 377 len = TARGET_ADDR_BIT / TARGET_CHAR_BIT;
ef166cf4 378
c906108c
SS
379 /* If we are printing it as unsigned, truncate it in case it is actually
380 a negative signed value (e.g. "print/u (short)-1" should print 65535
381 (if shorts are 16 bits) instead of 4294967295). */
382 if (format != 'd')
383 {
384 if (len < sizeof (LONGEST))
385 val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
386 }
387
388 switch (format)
389 {
390 case 'x':
391 if (!size)
392 {
393 /* no size specified, like in print. Print varying # of digits. */
394 print_longest (stream, 'x', 1, val_long);
395 }
396 else
397 switch (size)
398 {
399 case 'b':
400 case 'h':
401 case 'w':
402 case 'g':
403 print_longest (stream, size, 1, val_long);
404 break;
405 default:
8a3fe4f8 406 error (_("Undefined output size \"%c\"."), size);
c906108c
SS
407 }
408 break;
409
410 case 'd':
411 print_longest (stream, 'd', 1, val_long);
412 break;
413
414 case 'u':
415 print_longest (stream, 'u', 0, val_long);
416 break;
417
418 case 'o':
419 if (val_long)
420 print_longest (stream, 'o', 1, val_long);
421 else
422 fprintf_filtered (stream, "0");
423 break;
424
425 case 'a':
593de6a6 426 {
593de6a6 427 CORE_ADDR addr = unpack_pointer (type, valaddr);
593de6a6
PS
428 print_address (addr, stream);
429 }
c906108c
SS
430 break;
431
432 case 'c':
9e0b60a8
JM
433 value_print (value_from_longest (builtin_type_true_char, val_long),
434 stream, 0, Val_pretty_default);
c906108c
SS
435 break;
436
437 case 'f':
f4697836 438 if (len == TYPE_LENGTH (builtin_type_float))
664cccae 439 type = builtin_type_float;
f4697836 440 else if (len == TYPE_LENGTH (builtin_type_double))
664cccae 441 type = builtin_type_double;
f4697836
JB
442 else if (len == TYPE_LENGTH (builtin_type_long_double))
443 type = builtin_type_long_double;
c906108c
SS
444 print_floating (valaddr, type, stream);
445 break;
446
447 case 0:
e2e0b3e5 448 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
c906108c
SS
449
450 case 't':
451 /* Binary; 't' stands for "two". */
452 {
c5aa993b
JM
453 char bits[8 * (sizeof val_long) + 1];
454 char buf[8 * (sizeof val_long) + 32];
c906108c
SS
455 char *cp = bits;
456 int width;
457
c5aa993b
JM
458 if (!size)
459 width = 8 * (sizeof val_long);
460 else
461 switch (size)
c906108c
SS
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:
8a3fe4f8 476 error (_("Undefined output size \"%c\"."), size);
c906108c
SS
477 }
478
c5aa993b
JM
479 bits[width] = '\0';
480 while (width-- > 0)
481 {
482 bits[width] = (val_long & 1) ? '1' : '0';
483 val_long >>= 1;
484 }
c906108c
SS
485 if (!size)
486 {
487 while (*cp && *cp == '0')
488 cp++;
489 if (*cp == '\0')
490 cp--;
491 }
bb599908 492 strcpy (buf, cp);
306d9ac5 493 fputs_filtered (buf, stream);
c906108c
SS
494 }
495 break;
496
497 default:
8a3fe4f8 498 error (_("Undefined output format \"%c\"."), format);
c906108c
SS
499 }
500}
501
502/* Specify default address for `x' command.
503 `info lines' uses this. */
504
505void
fba45db2 506set_next_address (CORE_ADDR addr)
c906108c
SS
507{
508 next_address = addr;
509
510 /* Make address available to the user as $_. */
511 set_internalvar (lookup_internalvar ("_"),
4478b372
JB
512 value_from_pointer (lookup_pointer_type (builtin_type_void),
513 addr));
c906108c
SS
514}
515
516/* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
517 after LEADIN. Print nothing if no symbolic name is found nearby.
518 Optionally also print source file and line number, if available.
519 DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
520 or to interpret it as a possible C++ name and convert it back to source
521 form. However note that DO_DEMANGLE can be overridden by the specific
522 settings of the demangle and asm_demangle variables. */
523
524void
fba45db2
KB
525print_address_symbolic (CORE_ADDR addr, struct ui_file *stream, int do_demangle,
526 char *leadin)
dfcd3bfb
JM
527{
528 char *name = NULL;
529 char *filename = NULL;
530 int unmapped = 0;
531 int offset = 0;
532 int line = 0;
533
2f9429ae
AC
534 /* throw away both name and filename */
535 struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
536 make_cleanup (free_current_contents, &filename);
dfcd3bfb
JM
537
538 if (build_address_symbolic (addr, do_demangle, &name, &offset, &filename, &line, &unmapped))
2f9429ae
AC
539 {
540 do_cleanups (cleanup_chain);
541 return;
542 }
dfcd3bfb
JM
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. */
576int
577build_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 */
c906108c
SS
584{
585 struct minimal_symbol *msymbol;
586 struct symbol *symbol;
587 struct symtab *symtab = 0;
588 CORE_ADDR name_location = 0;
c906108c 589 asection *section = 0;
dfcd3bfb
JM
590 char *name_temp = "";
591
592 /* Let's say it is unmapped. */
593 *unmapped = 0;
c906108c 594
dfcd3bfb
JM
595 /* Determine if the address is in an overlay, and whether it is
596 mapped. */
c906108c
SS
597 if (overlay_debugging)
598 {
599 section = find_pc_overlay (addr);
600 if (pc_in_unmapped_range (addr, section))
601 {
dfcd3bfb 602 *unmapped = 1;
c906108c
SS
603 addr = overlay_mapped_address (addr, section);
604 }
605 }
606
c906108c
SS
607 /* First try to find the address in the symbol table, then
608 in the minsyms. Take the closest one. */
609
610 /* This is defective in the sense that it only finds text symbols. So
611 really this is kind of pointless--we should make sure that the
612 minimal symbols have everything we need (by changing that we could
613 save some memory, but for many debug format--ELF/DWARF or
614 anything/stabs--it would be inconvenient to eliminate those minimal
615 symbols anyway). */
616 msymbol = lookup_minimal_symbol_by_pc_section (addr, section);
617 symbol = find_pc_sect_function (addr, section);
618
619 if (symbol)
620 {
621 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
406fc7fb 622 if (do_demangle || asm_demangle)
de5ad195 623 name_temp = SYMBOL_PRINT_NAME (symbol);
c906108c 624 else
22abf04a 625 name_temp = DEPRECATED_SYMBOL_NAME (symbol);
c906108c
SS
626 }
627
628 if (msymbol != NULL)
629 {
630 if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
631 {
632 /* The msymbol is closer to the address than the symbol;
633 use the msymbol instead. */
634 symbol = 0;
635 symtab = 0;
636 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
406fc7fb 637 if (do_demangle || asm_demangle)
de5ad195 638 name_temp = SYMBOL_PRINT_NAME (msymbol);
c906108c 639 else
22abf04a 640 name_temp = DEPRECATED_SYMBOL_NAME (msymbol);
c906108c
SS
641 }
642 }
643 if (symbol == NULL && msymbol == NULL)
dfcd3bfb 644 return 1;
c906108c 645
c906108c
SS
646 /* If the nearest symbol is too far away, don't print anything symbolic. */
647
648 /* For when CORE_ADDR is larger than unsigned int, we do math in
649 CORE_ADDR. But when we detect unsigned wraparound in the
650 CORE_ADDR math, we ignore this test and print the offset,
651 because addr+max_symbolic_offset has wrapped through the end
652 of the address space back to the beginning, giving bogus comparison. */
653 if (addr > name_location + max_symbolic_offset
654 && name_location + max_symbolic_offset > name_location)
dfcd3bfb 655 return 1;
c906108c 656
dfcd3bfb
JM
657 *offset = addr - name_location;
658
659 *name = xstrdup (name_temp);
c906108c 660
c906108c
SS
661 if (print_symbol_filename)
662 {
663 struct symtab_and_line sal;
664
665 sal = find_pc_sect_line (addr, section, 0);
666
667 if (sal.symtab)
dfcd3bfb
JM
668 {
669 *filename = xstrdup (sal.symtab->filename);
670 *line = sal.line;
671 }
c906108c 672 else if (symtab && symbol && symbol->line)
dfcd3bfb
JM
673 {
674 *filename = xstrdup (symtab->filename);
675 *line = symbol->line;
676 }
c906108c 677 else if (symtab)
dfcd3bfb
JM
678 {
679 *filename = xstrdup (symtab->filename);
680 *line = -1;
681 }
c906108c 682 }
dfcd3bfb 683 return 0;
c906108c
SS
684}
685
c906108c
SS
686/* Print address ADDR on STREAM. USE_LOCAL means the same thing as for
687 print_longest. */
688void
66bf4b3a
AC
689deprecated_print_address_numeric (CORE_ADDR addr, int use_local,
690 struct ui_file *stream)
c906108c 691{
66bf4b3a
AC
692 if (use_local)
693 fputs_filtered (paddress (addr), stream);
694 else
695 {
696 int addr_bit = TARGET_ADDR_BIT;
697
698 if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
699 addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
700 print_longest (stream, 'x', 0, (ULONGEST) addr);
701 }
c906108c
SS
702}
703
704/* Print address ADDR symbolically on STREAM.
705 First print it as a number. Then perhaps print
706 <SYMBOL + OFFSET> after the number. */
707
708void
fba45db2 709print_address (CORE_ADDR addr, struct ui_file *stream)
c906108c 710{
66bf4b3a 711 deprecated_print_address_numeric (addr, 1, stream);
c906108c
SS
712 print_address_symbolic (addr, stream, asm_demangle, " ");
713}
714
715/* Print address ADDR symbolically on STREAM. Parameter DEMANGLE
716 controls whether to print the symbolic name "raw" or demangled.
717 Global setting "addressprint" controls whether to print hex address
718 or not. */
719
720void
fba45db2 721print_address_demangle (CORE_ADDR addr, struct ui_file *stream, int do_demangle)
c906108c
SS
722{
723 if (addr == 0)
724 {
725 fprintf_filtered (stream, "0");
726 }
727 else if (addressprint)
728 {
66bf4b3a 729 deprecated_print_address_numeric (addr, 1, stream);
c906108c
SS
730 print_address_symbolic (addr, stream, do_demangle, " ");
731 }
732 else
733 {
734 print_address_symbolic (addr, stream, do_demangle, "");
735 }
736}
737\f
738
739/* These are the types that $__ will get after an examine command of one
740 of these sizes. */
741
742static struct type *examine_i_type;
743
744static struct type *examine_b_type;
745static struct type *examine_h_type;
746static struct type *examine_w_type;
747static struct type *examine_g_type;
748
749/* Examine data at address ADDR in format FMT.
750 Fetch it from memory and print on gdb_stdout. */
751
752static void
00a4c844 753do_examine (struct format_data fmt, CORE_ADDR addr)
c906108c 754{
52f0bd74
AC
755 char format = 0;
756 char size;
757 int count = 1;
c906108c 758 struct type *val_type = NULL;
52f0bd74
AC
759 int i;
760 int maxelts;
c906108c
SS
761
762 format = fmt.format;
763 size = fmt.size;
764 count = fmt.count;
765 next_address = addr;
c906108c
SS
766
767 /* String or instruction format implies fetch single bytes
768 regardless of the specified size. */
769 if (format == 's' || format == 'i')
770 size = 'b';
771
772 if (format == 'i')
773 val_type = examine_i_type;
774 else if (size == 'b')
775 val_type = examine_b_type;
776 else if (size == 'h')
777 val_type = examine_h_type;
778 else if (size == 'w')
779 val_type = examine_w_type;
780 else if (size == 'g')
781 val_type = examine_g_type;
782
783 maxelts = 8;
784 if (size == 'w')
785 maxelts = 4;
786 if (size == 'g')
787 maxelts = 2;
788 if (format == 's' || format == 'i')
789 maxelts = 1;
790
791 /* Print as many objects as specified in COUNT, at most maxelts per line,
792 with the address of the next one at the start of each line. */
793
794 while (count > 0)
795 {
796 QUIT;
797 print_address (next_address, gdb_stdout);
798 printf_filtered (":");
799 for (i = maxelts;
800 i > 0 && count > 0;
801 i--, count--)
802 {
803 printf_filtered ("\t");
804 /* Note that print_formatted sets next_address for the next
805 object. */
806 last_examine_address = next_address;
807
808 if (last_examine_value)
809 value_free (last_examine_value);
810
811 /* The value to be displayed is not fetched greedily.
c5aa993b
JM
812 Instead, to avoid the posibility of a fetched value not
813 being used, its retreval is delayed until the print code
814 uses it. When examining an instruction stream, the
815 disassembler will perform its own memory fetch using just
816 the address stored in LAST_EXAMINE_VALUE. FIXME: Should
817 the disassembler be modified so that LAST_EXAMINE_VALUE
818 is left with the byte sequence from the last complete
819 instruction fetched from memory? */
00a4c844 820 last_examine_value = value_at_lazy (val_type, next_address);
c906108c
SS
821
822 if (last_examine_value)
823 release_value (last_examine_value);
824
2acceee2 825 print_formatted (last_examine_value, format, size, gdb_stdout);
c906108c
SS
826 }
827 printf_filtered ("\n");
828 gdb_flush (gdb_stdout);
829 }
830}
831\f
832static void
fba45db2 833validate_format (struct format_data fmt, char *cmdname)
c906108c
SS
834{
835 if (fmt.size != 0)
8a3fe4f8 836 error (_("Size letters are meaningless in \"%s\" command."), cmdname);
c906108c 837 if (fmt.count != 1)
8a3fe4f8 838 error (_("Item count other than 1 is meaningless in \"%s\" command."),
c906108c
SS
839 cmdname);
840 if (fmt.format == 'i' || fmt.format == 's')
8a3fe4f8 841 error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
c906108c
SS
842 fmt.format, cmdname);
843}
844
845/* Evaluate string EXP as an expression in the current language and
c5aa993b
JM
846 print the resulting value. EXP may contain a format specifier as the
847 first argument ("/x myvar" for example, to print myvar in hex).
848 */
c906108c
SS
849
850static void
fba45db2 851print_command_1 (char *exp, int inspect, int voidprint)
c906108c
SS
852{
853 struct expression *expr;
52f0bd74
AC
854 struct cleanup *old_chain = 0;
855 char format = 0;
3d6d86c6 856 struct value *val;
c906108c
SS
857 struct format_data fmt;
858 int cleanup = 0;
859
860 /* Pass inspect flag to the rest of the print routines in a global (sigh). */
861 inspect_it = inspect;
862
863 if (exp && *exp == '/')
864 {
865 exp++;
866 fmt = decode_format (&exp, last_format, 0);
867 validate_format (fmt, "print");
868 last_format = format = fmt.format;
869 }
870 else
871 {
872 fmt.count = 1;
873 fmt.format = 0;
874 fmt.size = 0;
875 }
876
877 if (exp && *exp)
878 {
c906108c
SS
879 struct type *type;
880 expr = parse_expression (exp);
c13c43fd 881 old_chain = make_cleanup (free_current_contents, &expr);
c906108c
SS
882 cleanup = 1;
883 val = evaluate_expression (expr);
c906108c
SS
884 }
885 else
886 val = access_value_history (0);
887
df407dfe
AC
888 if (voidprint || (val && value_type (val) &&
889 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
c906108c
SS
890 {
891 int histindex = record_latest_value (val);
892
893 if (histindex >= 0)
df407dfe 894 annotate_value_history_begin (histindex, value_type (val));
c906108c 895 else
df407dfe 896 annotate_value_begin (value_type (val));
c906108c
SS
897
898 if (inspect)
899 printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex);
c5aa993b
JM
900 else if (histindex >= 0)
901 printf_filtered ("$%d = ", histindex);
c906108c
SS
902
903 if (histindex >= 0)
904 annotate_value_history_value ();
905
2acceee2 906 print_formatted (val, format, fmt.size, gdb_stdout);
c906108c
SS
907 printf_filtered ("\n");
908
909 if (histindex >= 0)
910 annotate_value_history_end ();
911 else
912 annotate_value_end ();
913
914 if (inspect)
c5aa993b 915 printf_unfiltered ("\") )\030");
c906108c
SS
916 }
917
918 if (cleanup)
919 do_cleanups (old_chain);
c5aa993b 920 inspect_it = 0; /* Reset print routines to normal */
c906108c
SS
921}
922
c906108c 923static void
fba45db2 924print_command (char *exp, int from_tty)
c906108c
SS
925{
926 print_command_1 (exp, 0, 1);
927}
928
929/* Same as print, except in epoch, it gets its own window */
c906108c 930static void
fba45db2 931inspect_command (char *exp, int from_tty)
c906108c
SS
932{
933 extern int epoch_interface;
934
935 print_command_1 (exp, epoch_interface, 1);
936}
937
938/* Same as print, except it doesn't print void results. */
c906108c 939static void
fba45db2 940call_command (char *exp, int from_tty)
c906108c
SS
941{
942 print_command_1 (exp, 0, 0);
943}
944
c906108c 945void
fba45db2 946output_command (char *exp, int from_tty)
c906108c
SS
947{
948 struct expression *expr;
52f0bd74
AC
949 struct cleanup *old_chain;
950 char format = 0;
3d6d86c6 951 struct value *val;
c906108c
SS
952 struct format_data fmt;
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);
c13c43fd 963 old_chain = make_cleanup (free_current_contents, &expr);
c906108c
SS
964
965 val = evaluate_expression (expr);
966
df407dfe 967 annotate_value_begin (value_type (val));
c906108c 968
2acceee2 969 print_formatted (val, format, fmt.size, gdb_stdout);
c906108c
SS
970
971 annotate_value_end ();
972
2acceee2
JM
973 wrap_here ("");
974 gdb_flush (gdb_stdout);
975
c906108c
SS
976 do_cleanups (old_chain);
977}
978
c906108c 979static void
fba45db2 980set_command (char *exp, int from_tty)
c906108c
SS
981{
982 struct expression *expr = parse_expression (exp);
52f0bd74 983 struct cleanup *old_chain =
c13c43fd 984 make_cleanup (free_current_contents, &expr);
c906108c
SS
985 evaluate_expression (expr);
986 do_cleanups (old_chain);
987}
988
c906108c 989static void
fba45db2 990sym_info (char *arg, int from_tty)
c906108c
SS
991{
992 struct minimal_symbol *msymbol;
c5aa993b
JM
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;
c906108c
SS
999
1000 if (!arg)
e2e0b3e5 1001 error_no_arg (_("address"));
c906108c
SS
1002
1003 addr = parse_and_eval_address (arg);
1004 ALL_OBJSECTIONS (objfile, osect)
c5aa993b
JM
1005 {
1006 sect = osect->the_bfd_section;
1007 sect_addr = overlay_mapped_address (addr, sect);
c906108c 1008
c5aa993b
JM
1009 if (osect->addr <= sect_addr && sect_addr < osect->endaddr &&
1010 (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect)))
1011 {
1012 matches = 1;
1013 offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
1014 if (offset)
1015 printf_filtered ("%s + %u in ",
de5ad195 1016 SYMBOL_PRINT_NAME (msymbol), offset);
c5aa993b
JM
1017 else
1018 printf_filtered ("%s in ",
de5ad195 1019 SYMBOL_PRINT_NAME (msymbol));
c5aa993b 1020 if (pc_in_unmapped_range (addr, sect))
a3f17187 1021 printf_filtered (_("load address range of "));
c5aa993b 1022 if (section_is_overlay (sect))
a3f17187 1023 printf_filtered (_("%s overlay "),
c5aa993b 1024 section_is_mapped (sect) ? "mapped" : "unmapped");
a3f17187 1025 printf_filtered (_("section %s"), sect->name);
c5aa993b
JM
1026 printf_filtered ("\n");
1027 }
1028 }
c906108c 1029 if (matches == 0)
a3f17187 1030 printf_filtered (_("No symbol matches %s.\n"), arg);
c906108c
SS
1031}
1032
c906108c 1033static void
fba45db2 1034address_info (char *exp, int from_tty)
c906108c 1035{
52f0bd74
AC
1036 struct symbol *sym;
1037 struct minimal_symbol *msymbol;
1038 long val;
1039 long basereg;
c906108c
SS
1040 asection *section;
1041 CORE_ADDR load_addr;
1042 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
1043 if exp is a field of `this'. */
1044
1045 if (exp == 0)
8a3fe4f8 1046 error (_("Argument required."));
c906108c 1047
176620f1 1048 sym = lookup_symbol (exp, get_selected_block (0), VAR_DOMAIN,
c5aa993b 1049 &is_a_field_of_this, (struct symtab **) NULL);
c906108c
SS
1050 if (sym == NULL)
1051 {
1052 if (is_a_field_of_this)
1053 {
1054 printf_filtered ("Symbol \"");
1055 fprintf_symbol_filtered (gdb_stdout, exp,
1056 current_language->la_language, DMGL_ANSI);
e2b23ee9
AF
1057 printf_filtered ("\" is a field of the local class variable ");
1058 if (current_language->la_language == language_objc)
2625d86c 1059 printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */
e2b23ee9 1060 else
2625d86c 1061 printf_filtered ("`this'\n");
c906108c
SS
1062 return;
1063 }
1064
1065 msymbol = lookup_minimal_symbol (exp, NULL, NULL);
1066
1067 if (msymbol != NULL)
1068 {
1069 load_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1070
1071 printf_filtered ("Symbol \"");
1072 fprintf_symbol_filtered (gdb_stdout, exp,
1073 current_language->la_language, DMGL_ANSI);
1074 printf_filtered ("\" is at ");
66bf4b3a 1075 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
c906108c
SS
1076 printf_filtered (" in a file compiled without debugging");
1077 section = SYMBOL_BFD_SECTION (msymbol);
1078 if (section_is_overlay (section))
1079 {
1080 load_addr = overlay_unmapped_address (load_addr, section);
1081 printf_filtered (",\n -- loaded at ");
66bf4b3a 1082 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
c906108c
SS
1083 printf_filtered (" in overlay section %s", section->name);
1084 }
1085 printf_filtered (".\n");
1086 }
1087 else
8a3fe4f8 1088 error (_("No symbol \"%s\" in current context."), exp);
c906108c
SS
1089 return;
1090 }
1091
1092 printf_filtered ("Symbol \"");
22abf04a 1093 fprintf_symbol_filtered (gdb_stdout, DEPRECATED_SYMBOL_NAME (sym),
c906108c
SS
1094 current_language->la_language, DMGL_ANSI);
1095 printf_filtered ("\" is ");
c5aa993b 1096 val = SYMBOL_VALUE (sym);
c906108c
SS
1097 basereg = SYMBOL_BASEREG (sym);
1098 section = SYMBOL_BFD_SECTION (sym);
1099
1100 switch (SYMBOL_CLASS (sym))
1101 {
1102 case LOC_CONST:
1103 case LOC_CONST_BYTES:
1104 printf_filtered ("constant");
1105 break;
1106
1107 case LOC_LABEL:
1108 printf_filtered ("a label at address ");
66bf4b3a 1109 deprecated_print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
c906108c
SS
1110 1, gdb_stdout);
1111 if (section_is_overlay (section))
1112 {
1113 load_addr = overlay_unmapped_address (load_addr, section);
1114 printf_filtered (",\n -- loaded at ");
66bf4b3a 1115 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
c906108c
SS
1116 printf_filtered (" in overlay section %s", section->name);
1117 }
1118 break;
1119
4c2df51b
DJ
1120 case LOC_COMPUTED:
1121 case LOC_COMPUTED_ARG:
a67af2b9
AC
1122 /* FIXME: cagney/2004-01-26: It should be possible to
1123 unconditionally call the SYMBOL_OPS method when available.
d3efc286 1124 Unfortunately DWARF 2 stores the frame-base (instead of the
a67af2b9
AC
1125 function) location in a function's symbol. Oops! For the
1126 moment enable this when/where applicable. */
1127 SYMBOL_OPS (sym)->describe_location (sym, gdb_stdout);
4c2df51b
DJ
1128 break;
1129
c906108c 1130 case LOC_REGISTER:
a3f17187 1131 printf_filtered (_("a variable in register %s"), REGISTER_NAME (val));
c906108c
SS
1132 break;
1133
1134 case LOC_STATIC:
a3f17187 1135 printf_filtered (_("static storage at address "));
66bf4b3a 1136 deprecated_print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
c906108c
SS
1137 1, gdb_stdout);
1138 if (section_is_overlay (section))
1139 {
1140 load_addr = overlay_unmapped_address (load_addr, section);
a3f17187 1141 printf_filtered (_(",\n -- loaded at "));
66bf4b3a 1142 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
a3f17187 1143 printf_filtered (_(" in overlay section %s"), section->name);
c906108c
SS
1144 }
1145 break;
1146
1147 case LOC_INDIRECT:
a3f17187 1148 printf_filtered (_("external global (indirect addressing), at address *("));
66bf4b3a 1149 deprecated_print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym),
c906108c
SS
1150 1, gdb_stdout);
1151 printf_filtered (")");
1152 if (section_is_overlay (section))
1153 {
1154 load_addr = overlay_unmapped_address (load_addr, section);
a3f17187 1155 printf_filtered (_(",\n -- loaded at "));
66bf4b3a 1156 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
a3f17187 1157 printf_filtered (_(" in overlay section %s"), section->name);
c906108c
SS
1158 }
1159 break;
1160
1161 case LOC_REGPARM:
a3f17187 1162 printf_filtered (_("an argument in register %s"), REGISTER_NAME (val));
c906108c
SS
1163 break;
1164
1165 case LOC_REGPARM_ADDR:
a3f17187 1166 printf_filtered (_("address of an argument in register %s"), REGISTER_NAME (val));
c906108c
SS
1167 break;
1168
1169 case LOC_ARG:
a3f17187 1170 printf_filtered (_("an argument at offset %ld"), val);
c906108c
SS
1171 break;
1172
1173 case LOC_LOCAL_ARG:
a3f17187 1174 printf_filtered (_("an argument at frame offset %ld"), val);
c906108c
SS
1175 break;
1176
1177 case LOC_LOCAL:
a3f17187 1178 printf_filtered (_("a local variable at frame offset %ld"), val);
c906108c
SS
1179 break;
1180
1181 case LOC_REF_ARG:
a3f17187 1182 printf_filtered (_("a reference argument at offset %ld"), val);
c906108c
SS
1183 break;
1184
1185 case LOC_BASEREG:
a3f17187 1186 printf_filtered (_("a variable at offset %ld from register %s"),
c5aa993b 1187 val, REGISTER_NAME (basereg));
c906108c
SS
1188 break;
1189
1190 case LOC_BASEREG_ARG:
a3f17187 1191 printf_filtered (_("an argument at offset %ld from register %s"),
c5aa993b 1192 val, REGISTER_NAME (basereg));
c906108c
SS
1193 break;
1194
1195 case LOC_TYPEDEF:
a3f17187 1196 printf_filtered (_("a typedef"));
c906108c
SS
1197 break;
1198
1199 case LOC_BLOCK:
a3f17187 1200 printf_filtered (_("a function at address "));
66bf4b3a 1201 deprecated_print_address_numeric (load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)),
c906108c 1202 1, gdb_stdout);
c906108c
SS
1203 if (section_is_overlay (section))
1204 {
1205 load_addr = overlay_unmapped_address (load_addr, section);
a3f17187 1206 printf_filtered (_(",\n -- loaded at "));
66bf4b3a 1207 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
a3f17187 1208 printf_filtered (_(" in overlay section %s"), section->name);
c906108c
SS
1209 }
1210 break;
1211
1212 case LOC_UNRESOLVED:
1213 {
1214 struct minimal_symbol *msym;
1215
22abf04a 1216 msym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym), NULL, NULL);
c906108c
SS
1217 if (msym == NULL)
1218 printf_filtered ("unresolved");
1219 else
1220 {
1221 section = SYMBOL_BFD_SECTION (msym);
a3f17187 1222 printf_filtered (_("static storage at address "));
66bf4b3a 1223 deprecated_print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (msym),
c906108c
SS
1224 1, gdb_stdout);
1225 if (section_is_overlay (section))
1226 {
1227 load_addr = overlay_unmapped_address (load_addr, section);
a3f17187 1228 printf_filtered (_(",\n -- loaded at "));
66bf4b3a 1229 deprecated_print_address_numeric (load_addr, 1, gdb_stdout);
a3f17187 1230 printf_filtered (_(" in overlay section %s"), section->name);
c906108c
SS
1231 }
1232 }
1233 }
1234 break;
1235
407caf07 1236 case LOC_HP_THREAD_LOCAL_STATIC:
c906108c 1237 printf_filtered (
c5aa993b
JM
1238 "a thread-local variable at offset %ld from the thread base register %s",
1239 val, REGISTER_NAME (basereg));
c906108c
SS
1240 break;
1241
1242 case LOC_OPTIMIZED_OUT:
a3f17187 1243 printf_filtered (_("optimized out"));
c906108c 1244 break;
c5aa993b 1245
c906108c 1246 default:
a3f17187 1247 printf_filtered (_("of unknown (botched) type"));
c906108c
SS
1248 break;
1249 }
1250 printf_filtered (".\n");
1251}
1252\f
1253void
fba45db2 1254x_command (char *exp, int from_tty)
c906108c
SS
1255{
1256 struct expression *expr;
1257 struct format_data fmt;
1258 struct cleanup *old_chain;
1259 struct value *val;
1260
1261 fmt.format = last_format;
1262 fmt.size = last_size;
1263 fmt.count = 1;
1264
1265 if (exp && *exp == '/')
1266 {
1267 exp++;
1268 fmt = decode_format (&exp, last_format, last_size);
1269 }
1270
1271 /* If we have an expression, evaluate it and use it as the address. */
1272
1273 if (exp != 0 && *exp != 0)
1274 {
1275 expr = parse_expression (exp);
1276 /* Cause expression not to be there any more
c5aa993b
JM
1277 if this command is repeated with Newline.
1278 But don't clobber a user-defined command's definition. */
c906108c
SS
1279 if (from_tty)
1280 *exp = 0;
c13c43fd 1281 old_chain = make_cleanup (free_current_contents, &expr);
c906108c 1282 val = evaluate_expression (expr);
df407dfe 1283 if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
c906108c
SS
1284 val = value_ind (val);
1285 /* In rvalue contexts, such as this, functions are coerced into
c5aa993b 1286 pointers to functions. This makes "x/i main" work. */
c0d8fd9a 1287 if (/* last_format == 'i' && */
df407dfe 1288 TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
c5aa993b 1289 && VALUE_LVAL (val) == lval_memory)
c906108c
SS
1290 next_address = VALUE_ADDRESS (val);
1291 else
1aa20aa8 1292 next_address = value_as_address (val);
c906108c
SS
1293 do_cleanups (old_chain);
1294 }
1295
00a4c844 1296 do_examine (fmt, next_address);
c906108c
SS
1297
1298 /* If the examine succeeds, we remember its size and format for next time. */
1299 last_size = fmt.size;
1300 last_format = fmt.format;
1301
1302 /* Set a couple of internal variables if appropriate. */
1303 if (last_examine_value)
1304 {
1305 /* Make last address examined available to the user as $_. Use
c5aa993b 1306 the correct pointer type. */
4478b372 1307 struct type *pointer_type
df407dfe 1308 = lookup_pointer_type (value_type (last_examine_value));
c906108c 1309 set_internalvar (lookup_internalvar ("_"),
4478b372
JB
1310 value_from_pointer (pointer_type,
1311 last_examine_address));
c5aa993b
JM
1312
1313 /* Make contents of last address examined available to the user as $__. */
c906108c
SS
1314 /* If the last value has not been fetched from memory then don't
1315 fetch it now - instead mark it by voiding the $__ variable. */
d69fe07e 1316 if (value_lazy (last_examine_value))
c906108c
SS
1317 set_internalvar (lookup_internalvar ("__"),
1318 allocate_value (builtin_type_void));
1319 else
1320 set_internalvar (lookup_internalvar ("__"), last_examine_value);
1321 }
1322}
c906108c 1323\f
c5aa993b 1324
c906108c
SS
1325/* Add an expression to the auto-display chain.
1326 Specify the expression. */
1327
1328static void
fba45db2 1329display_command (char *exp, int from_tty)
c906108c
SS
1330{
1331 struct format_data fmt;
52f0bd74
AC
1332 struct expression *expr;
1333 struct display *new;
c906108c
SS
1334 int display_it = 1;
1335
1336#if defined(TUI)
021e7609
AC
1337 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1338 `tui_version'. */
fd33e6cb 1339 if (tui_active && exp != NULL && *exp == '$')
080ce8c0 1340 display_it = (tui_set_layout_for_display_command (exp) == TUI_FAILURE);
c906108c
SS
1341#endif
1342
1343 if (display_it)
1344 {
1345 if (exp == 0)
1346 {
1347 do_displays ();
1348 return;
1349 }
1350
1351 if (*exp == '/')
1352 {
1353 exp++;
1354 fmt = decode_format (&exp, 0, 0);
1355 if (fmt.size && fmt.format == 0)
1356 fmt.format = 'x';
1357 if (fmt.format == 'i' || fmt.format == 's')
1358 fmt.size = 'b';
1359 }
1360 else
1361 {
1362 fmt.format = 0;
1363 fmt.size = 0;
1364 fmt.count = 0;
1365 }
1366
1367 innermost_block = 0;
1368 expr = parse_expression (exp);
1369
1370 new = (struct display *) xmalloc (sizeof (struct display));
1371
1372 new->exp = expr;
1373 new->block = innermost_block;
1374 new->next = display_chain;
1375 new->number = ++display_number;
1376 new->format = fmt;
b5de0fa7 1377 new->enabled_p = 1;
c906108c
SS
1378 display_chain = new;
1379
1380 if (from_tty && target_has_execution)
1381 do_one_display (new);
1382
1383 dont_repeat ();
1384 }
1385}
1386
1387static void
fba45db2 1388free_display (struct display *d)
c906108c 1389{
b8c9b27d
KB
1390 xfree (d->exp);
1391 xfree (d);
c906108c
SS
1392}
1393
1394/* Clear out the display_chain.
1395 Done when new symtabs are loaded, since this invalidates
1396 the types stored in many expressions. */
1397
1398void
fba45db2 1399clear_displays (void)
c906108c 1400{
52f0bd74 1401 struct display *d;
c906108c
SS
1402
1403 while ((d = display_chain) != NULL)
1404 {
b8c9b27d 1405 xfree (d->exp);
c906108c 1406 display_chain = d->next;
b8c9b27d 1407 xfree (d);
c906108c
SS
1408 }
1409}
1410
1411/* Delete the auto-display number NUM. */
1412
1413static void
fba45db2 1414delete_display (int num)
c906108c 1415{
52f0bd74 1416 struct display *d1, *d;
c906108c
SS
1417
1418 if (!display_chain)
8a3fe4f8 1419 error (_("No display number %d."), num);
c906108c
SS
1420
1421 if (display_chain->number == num)
1422 {
1423 d1 = display_chain;
1424 display_chain = d1->next;
1425 free_display (d1);
1426 }
1427 else
c5aa993b 1428 for (d = display_chain;; d = d->next)
c906108c
SS
1429 {
1430 if (d->next == 0)
8a3fe4f8 1431 error (_("No display number %d."), num);
c906108c
SS
1432 if (d->next->number == num)
1433 {
1434 d1 = d->next;
1435 d->next = d1->next;
1436 free_display (d1);
1437 break;
1438 }
1439 }
1440}
1441
1442/* Delete some values from the auto-display chain.
1443 Specify the element numbers. */
1444
1445static void
fba45db2 1446undisplay_command (char *args, int from_tty)
c906108c 1447{
52f0bd74
AC
1448 char *p = args;
1449 char *p1;
1450 int num;
c906108c
SS
1451
1452 if (args == 0)
1453 {
1454 if (query ("Delete all auto-display expressions? "))
1455 clear_displays ();
1456 dont_repeat ();
1457 return;
1458 }
1459
1460 while (*p)
1461 {
1462 p1 = p;
c5aa993b
JM
1463 while (*p1 >= '0' && *p1 <= '9')
1464 p1++;
c906108c 1465 if (*p1 && *p1 != ' ' && *p1 != '\t')
8a3fe4f8 1466 error (_("Arguments must be display numbers."));
c906108c
SS
1467
1468 num = atoi (p);
1469
1470 delete_display (num);
1471
1472 p = p1;
c5aa993b
JM
1473 while (*p == ' ' || *p == '\t')
1474 p++;
c906108c
SS
1475 }
1476 dont_repeat ();
1477}
1478
1479/* Display a single auto-display.
1480 Do nothing if the display cannot be printed in the current context,
1481 or if the display is disabled. */
1482
1483static void
fba45db2 1484do_one_display (struct display *d)
c906108c
SS
1485{
1486 int within_current_scope;
1487
b5de0fa7 1488 if (d->enabled_p == 0)
c906108c
SS
1489 return;
1490
1491 if (d->block)
ae767bfb 1492 within_current_scope = contained_in (get_selected_block (0), d->block);
c906108c
SS
1493 else
1494 within_current_scope = 1;
1495 if (!within_current_scope)
1496 return;
1497
1498 current_display_number = d->number;
1499
1500 annotate_display_begin ();
1501 printf_filtered ("%d", d->number);
1502 annotate_display_number_end ();
1503 printf_filtered (": ");
1504 if (d->format.size)
1505 {
1506 CORE_ADDR addr;
3d6d86c6 1507 struct value *val;
c906108c
SS
1508
1509 annotate_display_format ();
1510
1511 printf_filtered ("x/");
1512 if (d->format.count != 1)
1513 printf_filtered ("%d", d->format.count);
1514 printf_filtered ("%c", d->format.format);
1515 if (d->format.format != 'i' && d->format.format != 's')
1516 printf_filtered ("%c", d->format.size);
1517 printf_filtered (" ");
1518
1519 annotate_display_expression ();
1520
1521 print_expression (d->exp, gdb_stdout);
1522 annotate_display_expression_end ();
1523
1524 if (d->format.count != 1)
1525 printf_filtered ("\n");
1526 else
1527 printf_filtered (" ");
c5aa993b 1528
c906108c 1529 val = evaluate_expression (d->exp);
1aa20aa8 1530 addr = value_as_address (val);
c906108c
SS
1531 if (d->format.format == 'i')
1532 addr = ADDR_BITS_REMOVE (addr);
1533
1534 annotate_display_value ();
1535
00a4c844 1536 do_examine (d->format, addr);
c906108c
SS
1537 }
1538 else
1539 {
1540 annotate_display_format ();
1541
1542 if (d->format.format)
1543 printf_filtered ("/%c ", d->format.format);
1544
1545 annotate_display_expression ();
1546
1547 print_expression (d->exp, gdb_stdout);
1548 annotate_display_expression_end ();
1549
1550 printf_filtered (" = ");
1551
1552 annotate_display_expression ();
1553
1554 print_formatted (evaluate_expression (d->exp),
2acceee2 1555 d->format.format, d->format.size, gdb_stdout);
c906108c
SS
1556 printf_filtered ("\n");
1557 }
1558
1559 annotate_display_end ();
1560
1561 gdb_flush (gdb_stdout);
1562 current_display_number = -1;
1563}
1564
1565/* Display all of the values on the auto-display chain which can be
1566 evaluated in the current scope. */
1567
1568void
fba45db2 1569do_displays (void)
c906108c 1570{
52f0bd74 1571 struct display *d;
c906108c
SS
1572
1573 for (d = display_chain; d; d = d->next)
1574 do_one_display (d);
1575}
1576
1577/* Delete the auto-display which we were in the process of displaying.
1578 This is done when there is an error or a signal. */
1579
1580void
fba45db2 1581disable_display (int num)
c906108c 1582{
52f0bd74 1583 struct display *d;
c906108c
SS
1584
1585 for (d = display_chain; d; d = d->next)
1586 if (d->number == num)
1587 {
b5de0fa7 1588 d->enabled_p = 0;
c906108c
SS
1589 return;
1590 }
a3f17187 1591 printf_unfiltered (_("No display number %d.\n"), num);
c906108c 1592}
c5aa993b 1593
c906108c 1594void
fba45db2 1595disable_current_display (void)
c906108c
SS
1596{
1597 if (current_display_number >= 0)
1598 {
1599 disable_display (current_display_number);
1600 fprintf_unfiltered (gdb_stderr, "Disabling display %d to avoid infinite recursion.\n",
c5aa993b 1601 current_display_number);
c906108c
SS
1602 }
1603 current_display_number = -1;
1604}
1605
1606static void
fba45db2 1607display_info (char *ignore, int from_tty)
c906108c 1608{
52f0bd74 1609 struct display *d;
c906108c
SS
1610
1611 if (!display_chain)
a3f17187 1612 printf_unfiltered (_("There are no auto-display expressions now.\n"));
c906108c 1613 else
a3f17187
AC
1614 printf_filtered (_("Auto-display expressions now in effect:\n\
1615Num Enb Expression\n"));
c906108c
SS
1616
1617 for (d = display_chain; d; d = d->next)
1618 {
b5de0fa7 1619 printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]);
c906108c
SS
1620 if (d->format.size)
1621 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
c5aa993b 1622 d->format.format);
c906108c
SS
1623 else if (d->format.format)
1624 printf_filtered ("/%c ", d->format.format);
1625 print_expression (d->exp, gdb_stdout);
ae767bfb 1626 if (d->block && !contained_in (get_selected_block (0), d->block))
a3f17187 1627 printf_filtered (_(" (cannot be evaluated in the current context)"));
c906108c
SS
1628 printf_filtered ("\n");
1629 gdb_flush (gdb_stdout);
1630 }
1631}
1632
1633static void
fba45db2 1634enable_display (char *args, int from_tty)
c906108c 1635{
52f0bd74
AC
1636 char *p = args;
1637 char *p1;
1638 int num;
1639 struct display *d;
c906108c
SS
1640
1641 if (p == 0)
1642 {
1643 for (d = display_chain; d; d = d->next)
b5de0fa7 1644 d->enabled_p = 1;
c906108c
SS
1645 }
1646 else
1647 while (*p)
1648 {
1649 p1 = p;
1650 while (*p1 >= '0' && *p1 <= '9')
1651 p1++;
1652 if (*p1 && *p1 != ' ' && *p1 != '\t')
8a3fe4f8 1653 error (_("Arguments must be display numbers."));
c5aa993b 1654
c906108c 1655 num = atoi (p);
c5aa993b 1656
c906108c
SS
1657 for (d = display_chain; d; d = d->next)
1658 if (d->number == num)
1659 {
b5de0fa7 1660 d->enabled_p = 1;
c906108c
SS
1661 goto win;
1662 }
a3f17187 1663 printf_unfiltered (_("No display number %d.\n"), num);
c906108c
SS
1664 win:
1665 p = p1;
1666 while (*p == ' ' || *p == '\t')
1667 p++;
1668 }
1669}
1670
c906108c 1671static void
fba45db2 1672disable_display_command (char *args, int from_tty)
c906108c 1673{
52f0bd74
AC
1674 char *p = args;
1675 char *p1;
1676 struct display *d;
c906108c
SS
1677
1678 if (p == 0)
1679 {
1680 for (d = display_chain; d; d = d->next)
b5de0fa7 1681 d->enabled_p = 0;
c906108c
SS
1682 }
1683 else
1684 while (*p)
1685 {
1686 p1 = p;
1687 while (*p1 >= '0' && *p1 <= '9')
1688 p1++;
1689 if (*p1 && *p1 != ' ' && *p1 != '\t')
8a3fe4f8 1690 error (_("Arguments must be display numbers."));
c5aa993b 1691
c906108c
SS
1692 disable_display (atoi (p));
1693
1694 p = p1;
1695 while (*p == ' ' || *p == '\t')
1696 p++;
1697 }
1698}
c906108c 1699\f
c5aa993b 1700
c906108c
SS
1701/* Print the value in stack frame FRAME of a variable
1702 specified by a struct symbol. */
1703
1704void
fba45db2
KB
1705print_variable_value (struct symbol *var, struct frame_info *frame,
1706 struct ui_file *stream)
c906108c 1707{
3d6d86c6 1708 struct value *val = read_var_value (var, frame);
c906108c
SS
1709
1710 value_print (val, stream, 0, Val_pretty_default);
1711}
1712
c906108c 1713static void
fba45db2 1714printf_command (char *arg, int from_tty)
c906108c 1715{
52f0bd74
AC
1716 char *f = NULL;
1717 char *s = arg;
c906108c 1718 char *string = NULL;
3d6d86c6 1719 struct value **val_args;
c906108c
SS
1720 char *substrings;
1721 char *current_substring;
1722 int nargs = 0;
1723 int allocated_args = 20;
1724 struct cleanup *old_cleanups;
1725
f976f6d4
AC
1726 val_args = (struct value **) xmalloc (allocated_args
1727 * sizeof (struct value *));
c13c43fd 1728 old_cleanups = make_cleanup (free_current_contents, &val_args);
c906108c
SS
1729
1730 if (s == 0)
e2e0b3e5 1731 error_no_arg (_("format-control string and values to print"));
c906108c
SS
1732
1733 /* Skip white space before format string */
c5aa993b
JM
1734 while (*s == ' ' || *s == '\t')
1735 s++;
c906108c
SS
1736
1737 /* A format string should follow, enveloped in double quotes */
1738 if (*s++ != '"')
8a3fe4f8 1739 error (_("Bad format string, missing '\"'."));
c906108c
SS
1740
1741 /* Parse the format-control string and copy it into the string STRING,
1742 processing some kinds of escape sequence. */
1743
1744 f = string = (char *) alloca (strlen (s) + 1);
1745
1746 while (*s != '"')
1747 {
1748 int c = *s++;
1749 switch (c)
1750 {
1751 case '\0':
8a3fe4f8 1752 error (_("Bad format string, non-terminated '\"'."));
c906108c
SS
1753
1754 case '\\':
1755 switch (c = *s++)
1756 {
1757 case '\\':
1758 *f++ = '\\';
1759 break;
1760 case 'a':
c906108c 1761 *f++ = '\a';
c906108c
SS
1762 break;
1763 case 'b':
1764 *f++ = '\b';
1765 break;
1766 case 'f':
1767 *f++ = '\f';
1768 break;
1769 case 'n':
1770 *f++ = '\n';
1771 break;
1772 case 'r':
1773 *f++ = '\r';
1774 break;
1775 case 't':
1776 *f++ = '\t';
1777 break;
1778 case 'v':
1779 *f++ = '\v';
1780 break;
1781 case '"':
1782 *f++ = '"';
1783 break;
1784 default:
1785 /* ??? TODO: handle other escape sequences */
8a3fe4f8 1786 error (_("Unrecognized escape character \\%c in format string."),
c906108c
SS
1787 c);
1788 }
1789 break;
1790
1791 default:
1792 *f++ = c;
1793 }
1794 }
1795
1796 /* Skip over " and following space and comma. */
1797 s++;
1798 *f++ = '\0';
c5aa993b
JM
1799 while (*s == ' ' || *s == '\t')
1800 s++;
c906108c
SS
1801
1802 if (*s != ',' && *s != 0)
8a3fe4f8 1803 error (_("Invalid argument syntax"));
c906108c 1804
c5aa993b
JM
1805 if (*s == ',')
1806 s++;
1807 while (*s == ' ' || *s == '\t')
1808 s++;
c906108c
SS
1809
1810 /* Need extra space for the '\0's. Doubling the size is sufficient. */
1811 substrings = alloca (strlen (string) * 2);
1812 current_substring = substrings;
1813
1814 {
1815 /* Now scan the string for %-specs and see what kinds of args they want.
1816 argclass[I] classifies the %-specs so we can give printf_filtered
1817 something of the right size. */
1818
c5aa993b
JM
1819 enum argclass
1820 {
1821 no_arg, int_arg, string_arg, double_arg, long_long_arg
1822 };
c906108c
SS
1823 enum argclass *argclass;
1824 enum argclass this_argclass;
1825 char *last_arg;
1826 int nargs_wanted;
1827 int lcount;
1828 int i;
1829
1830 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1831 nargs_wanted = 0;
1832 f = string;
1833 last_arg = string;
1834 while (*f)
1835 if (*f++ == '%')
1836 {
1837 lcount = 0;
c5aa993b 1838 while (strchr ("0123456789.hlL-+ #", *f))
c906108c
SS
1839 {
1840 if (*f == 'l' || *f == 'L')
1841 lcount++;
1842 f++;
1843 }
1844 switch (*f)
1845 {
1846 case 's':
1847 this_argclass = string_arg;
1848 break;
1849
1850 case 'e':
1851 case 'f':
1852 case 'g':
1853 this_argclass = double_arg;
1854 break;
1855
1856 case '*':
8a3fe4f8 1857 error (_("`*' not supported for precision or width in printf"));
c906108c
SS
1858
1859 case 'n':
8a3fe4f8 1860 error (_("Format specifier `n' not supported in printf"));
c906108c
SS
1861
1862 case '%':
1863 this_argclass = no_arg;
1864 break;
1865
1866 default:
1867 if (lcount > 1)
1868 this_argclass = long_long_arg;
1869 else
1870 this_argclass = int_arg;
1871 break;
1872 }
1873 f++;
1874 if (this_argclass != no_arg)
1875 {
1876 strncpy (current_substring, last_arg, f - last_arg);
1877 current_substring += f - last_arg;
1878 *current_substring++ = '\0';
1879 last_arg = f;
1880 argclass[nargs_wanted++] = this_argclass;
1881 }
1882 }
1883
1884 /* Now, parse all arguments and evaluate them.
1885 Store the VALUEs in VAL_ARGS. */
1886
1887 while (*s != '\0')
1888 {
1889 char *s1;
1890 if (nargs == allocated_args)
f976f6d4
AC
1891 val_args = (struct value **) xrealloc ((char *) val_args,
1892 (allocated_args *= 2)
1893 * sizeof (struct value *));
c906108c
SS
1894 s1 = s;
1895 val_args[nargs] = parse_to_comma_and_eval (&s1);
c5aa993b 1896
c906108c
SS
1897 /* If format string wants a float, unchecked-convert the value to
1898 floating point of the same size */
c5aa993b 1899
c906108c
SS
1900 if (argclass[nargs] == double_arg)
1901 {
df407dfe 1902 struct type *type = value_type (val_args[nargs]);
c906108c 1903 if (TYPE_LENGTH (type) == sizeof (float))
04624583 1904 deprecated_set_value_type (val_args[nargs], builtin_type_float);
c906108c 1905 if (TYPE_LENGTH (type) == sizeof (double))
04624583 1906 deprecated_set_value_type (val_args[nargs], builtin_type_double);
c906108c
SS
1907 }
1908 nargs++;
1909 s = s1;
1910 if (*s == ',')
1911 s++;
1912 }
c5aa993b 1913
c906108c 1914 if (nargs != nargs_wanted)
8a3fe4f8 1915 error (_("Wrong number of arguments for specified format-string"));
c906108c
SS
1916
1917 /* Now actually print them. */
1918 current_substring = substrings;
1919 for (i = 0; i < nargs; i++)
1920 {
1921 switch (argclass[i])
1922 {
1923 case string_arg:
1924 {
1925 char *str;
1926 CORE_ADDR tem;
1927 int j;
1aa20aa8 1928 tem = value_as_address (val_args[i]);
c906108c
SS
1929
1930 /* This is a %s argument. Find the length of the string. */
c5aa993b 1931 for (j = 0;; j++)
c906108c
SS
1932 {
1933 char c;
1934 QUIT;
d4b2399a 1935 read_memory (tem + j, &c, 1);
c906108c
SS
1936 if (c == 0)
1937 break;
1938 }
1939
1940 /* Copy the string contents into a string inside GDB. */
1941 str = (char *) alloca (j + 1);
7b92f6e1
MS
1942 if (j != 0)
1943 read_memory (tem, str, j);
c906108c
SS
1944 str[j] = 0;
1945
1946 printf_filtered (current_substring, str);
1947 }
1948 break;
1949 case double_arg:
1950 {
1951 double val = value_as_double (val_args[i]);
1952 printf_filtered (current_substring, val);
1953 break;
1954 }
1955 case long_long_arg:
1956#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
1957 {
1958 long long val = value_as_long (val_args[i]);
1959 printf_filtered (current_substring, val);
1960 break;
1961 }
1962#else
8a3fe4f8 1963 error (_("long long not supported in printf"));
c906108c
SS
1964#endif
1965 case int_arg:
1966 {
1967 /* FIXME: there should be separate int_arg and long_arg. */
1968 long val = value_as_long (val_args[i]);
1969 printf_filtered (current_substring, val);
1970 break;
1971 }
c5aa993b 1972 default: /* purecov: deadcode */
8a3fe4f8 1973 error (_("internal error in printf_command")); /* purecov: deadcode */
c906108c
SS
1974 }
1975 /* Skip to the next substring. */
1976 current_substring += strlen (current_substring) + 1;
1977 }
1978 /* Print the portion of the format string after the last argument. */
306d9ac5 1979 puts_filtered (last_arg);
c906108c
SS
1980 }
1981 do_cleanups (old_cleanups);
1982}
c906108c 1983
c906108c 1984void
fba45db2 1985_initialize_printcmd (void)
c906108c 1986{
c94fdfd0
EZ
1987 struct cmd_list_element *c;
1988
c906108c
SS
1989 current_display_number = -1;
1990
1991 add_info ("address", address_info,
c5aa993b 1992 "Describe where symbol SYM is stored.");
c906108c 1993
c5aa993b 1994 add_info ("symbol", sym_info,
c906108c
SS
1995 "Describe what symbol is at location ADDR.\n\
1996Only for symbols with fixed locations (global or static scope).");
1997
1998 add_com ("x", class_vars, x_command,
1999 concat ("Examine memory: x/FMT ADDRESS.\n\
2000ADDRESS is an expression for the memory address to examine.\n\
2001FMT is a repeat count followed by a format letter and a size letter.\n\
2002Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
2003 t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n",
c5aa993b 2004 "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
c906108c
SS
2005The specified number of objects of the specified size are printed\n\
2006according to the format.\n\n\
2007Defaults for format and size letters are those previously used.\n\
2008Default count is 1. Default address is following last thing printed\n\
2009with this command or \"print\".", NULL));
2010
c906108c
SS
2011#if 0
2012 add_com ("whereis", class_vars, whereis_command,
2013 "Print line number and file of definition of variable.");
2014#endif
c5aa993b 2015
c906108c
SS
2016 add_info ("display", display_info,
2017 "Expressions to display when program stops, with code numbers.");
2018
1a966eab
AC
2019 add_cmd ("undisplay", class_vars, undisplay_command, _("\
2020Cancel some expressions to be displayed when program stops.\n\
c906108c
SS
2021Arguments are the code numbers of the expressions to stop displaying.\n\
2022No argument means cancel all automatic-display expressions.\n\
2023\"delete display\" has the same effect as this command.\n\
1a966eab 2024Do \"info display\" to see current list of code numbers."),
c5aa993b 2025 &cmdlist);
c906108c
SS
2026
2027 add_com ("display", class_vars, display_command,
2028 "Print value of expression EXP each time the program stops.\n\
2029/FMT may be used before EXP as in the \"print\" command.\n\
2030/FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
2031as in the \"x\" command, and then EXP is used to get the address to examine\n\
2032and examining is done as in the \"x\" command.\n\n\
2033With no argument, display all currently requested auto-display expressions.\n\
2034Use \"undisplay\" to cancel display requests previously made."
c5aa993b 2035 );
c906108c 2036
1a966eab
AC
2037 add_cmd ("display", class_vars, enable_display, _("\
2038Enable some expressions to be displayed when program stops.\n\
c906108c
SS
2039Arguments are the code numbers of the expressions to resume displaying.\n\
2040No argument means enable all automatic-display expressions.\n\
1a966eab 2041Do \"info display\" to see current list of code numbers."), &enablelist);
c906108c 2042
1a966eab
AC
2043 add_cmd ("display", class_vars, disable_display_command, _("\
2044Disable some expressions to be displayed when program stops.\n\
c906108c
SS
2045Arguments are the code numbers of the expressions to stop displaying.\n\
2046No argument means disable all automatic-display expressions.\n\
1a966eab 2047Do \"info display\" to see current list of code numbers."), &disablelist);
c906108c 2048
1a966eab
AC
2049 add_cmd ("display", class_vars, undisplay_command, _("\
2050Cancel some expressions to be displayed when program stops.\n\
c906108c
SS
2051Arguments are the code numbers of the expressions to stop displaying.\n\
2052No argument means cancel all automatic-display expressions.\n\
1a966eab 2053Do \"info display\" to see current list of code numbers."), &deletelist);
c906108c
SS
2054
2055 add_com ("printf", class_vars, printf_command,
c5aa993b 2056 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
c906108c
SS
2057This is useful for formatted output in user-defined commands.");
2058
2059 add_com ("output", class_vars, output_command,
2060 "Like \"print\" but don't put in value history and don't print newline.\n\
2061This is useful in user-defined commands.");
2062
2063 add_prefix_cmd ("set", class_vars, set_command,
c5aa993b 2064 concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\
c906108c
SS
2065syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2066example). VAR may be a debugger \"convenience\" variable (names starting\n\
2067with $), a register (a few standard names starting with $), or an actual\n\
2068variable in the program being debugged. EXP is any valid expression.\n",
c5aa993b 2069 "Use \"set variable\" for variables with names identical to set subcommands.\n\
c906108c
SS
2070\nWith a subcommand, this command modifies parts of the gdb environment.\n\
2071You can see these environment settings with the \"show\" command.", NULL),
c5aa993b 2072 &setlist, "set ", 1, &cmdlist);
c906108c 2073 if (dbx_commands)
c5aa993b 2074 add_com ("assign", class_vars, set_command, concat ("Evaluate expression \
c906108c
SS
2075EXP and assign result to variable VAR, using assignment\n\
2076syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2077example). VAR may be a debugger \"convenience\" variable (names starting\n\
2078with $), a register (a few standard names starting with $), or an actual\n\
2079variable in the program being debugged. EXP is any valid expression.\n",
c5aa993b 2080 "Use \"set variable\" for variables with names identical to set subcommands.\n\
c906108c
SS
2081\nWith a subcommand, this command modifies parts of the gdb environment.\n\
2082You can see these environment settings with the \"show\" command.", NULL));
2083
2084 /* "call" is the same as "set", but handy for dbx users to call fns. */
c94fdfd0
EZ
2085 c = add_com ("call", class_vars, call_command,
2086 "Call a function in the program.\n\
c906108c
SS
2087The argument is the function name and arguments, in the notation of the\n\
2088current working language. The result is printed and saved in the value\n\
2089history, if it is not void.");
5ba2abeb 2090 set_cmd_completer (c, location_completer);
c906108c 2091
1a966eab
AC
2092 add_cmd ("variable", class_vars, set_command, _("\
2093Evaluate expression EXP and assign result to variable VAR, using assignment\n\
c906108c
SS
2094syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
2095example). VAR may be a debugger \"convenience\" variable (names starting\n\
2096with $), a register (a few standard names starting with $), or an actual\n\
2097variable in the program being debugged. EXP is any valid expression.\n\
1a966eab 2098This may usually be abbreviated to simply \"set\"."),
c5aa993b 2099 &setlist);
c906108c 2100
c94fdfd0 2101 c = add_com ("print", class_vars, print_command,
c906108c
SS
2102 concat ("Print value of expression EXP.\n\
2103Variables accessible are those of the lexical environment of the selected\n\
2104stack frame, plus all those whose scope is global or an entire file.\n\
2105\n\
2106$NUM gets previous value number NUM. $ and $$ are the last two values.\n\
2107$$NUM refers to NUM'th value back from the last one.\n\
2108Names starting with $ refer to registers (with the values they would have\n",
c5aa993b 2109 "if the program were to return to the stack frame now selected, restoring\n\
c906108c
SS
2110all registers saved by frames farther in) or else to debugger\n\
2111\"convenience\" variables (any such name not a known register).\n\
2112Use assignment expressions to give values to convenience variables.\n",
2113 "\n\
2114{TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
2115@ is a binary operator for treating consecutive data objects\n\
2116anywhere in memory as an array. FOO@NUM gives an array whose first\n\
2117element is FOO, whose second element is stored in the space following\n\
2118where FOO is stored, etc. FOO must be an expression whose value\n\
2119resides in memory.\n",
2120 "\n\
2121EXP may be preceded with /FMT, where FMT is a format letter\n\
2122but no count or size letter (see \"x\" command).", NULL));
5ba2abeb 2123 set_cmd_completer (c, location_completer);
c906108c
SS
2124 add_com_alias ("p", "print", class_vars, 1);
2125
c94fdfd0 2126 c = add_com ("inspect", class_vars, inspect_command,
c5aa993b 2127 "Same as \"print\" command, except that if you are running in the epoch\n\
c906108c 2128environment, the value is printed in its own window.");
5ba2abeb 2129 set_cmd_completer (c, location_completer);
c906108c 2130
cb1a6d5f
AC
2131 deprecated_add_show_from_set
2132 (add_set_cmd ("max-symbolic-offset", no_class, var_uinteger,
2133 (char *) &max_symbolic_offset,
c5aa993b 2134 "Set the largest offset that will be printed in <symbol+1234> form.",
cb1a6d5f
AC
2135 &setprintlist),
2136 &showprintlist);
2137 deprecated_add_show_from_set
2138 (add_set_cmd ("symbol-filename", no_class, var_boolean,
2139 (char *) &print_symbol_filename, "\
2140Set printing of source filename and line number with <symbol>.",
2141 &setprintlist),
2142 &showprintlist);
c906108c
SS
2143
2144 /* For examine/instruction a single byte quantity is specified as
2145 the data. This avoids problems with value_at_lazy() requiring a
2146 valid data type (and rejecting VOID). */
2147 examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL);
2148
2149 examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL);
2150 examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL);
2151 examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL);
2152 examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL);
2153
2154}
This page took 0.664665 seconds and 4 git commands to generate.