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