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