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