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