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