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