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