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