gdb-3.4
[deliverable/binutils-gdb.git] / gdb / printcmd.c
1 /* Print values for GNU debugger GDB.
2 Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 GDB is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
9 any later version.
10
11 GDB is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GDB; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include <stdio.h>
21 #include "defs.h"
22 #include "param.h"
23 #include "frame.h"
24 #include "symtab.h"
25 #include "value.h"
26 #include "expression.h"
27
28 struct format_data
29 {
30 int count;
31 char format;
32 char size;
33 };
34
35 /* Last specified output format. */
36
37 static char last_format = 'x';
38
39 /* Last specified examination size. 'b', 'h', 'w' or `q'. */
40
41 static char last_size = 'w';
42
43 /* Default address to examine next. */
44
45 static CORE_ADDR next_address;
46
47 /* Last address examined. */
48
49 static CORE_ADDR last_examine_address;
50
51 /* Contents of last address examined.
52 This is not valid past the end of the `x' command! */
53
54 static value last_examine_value;
55
56 /* Number of auto-display expression currently being displayed.
57 So that we can deleted it if we get an error or a signal within it.
58 -1 when not doing one. */
59
60 int current_display_number;
61
62 static void do_one_display ();
63
64 void do_displays ();
65 void print_address ();
66 void print_scalar_formatted ();
67
68 \f
69 /* Decode a format specification. *STRING_PTR should point to it.
70 OFORMAT and OSIZE are used as defaults for the format and size
71 if none are given in the format specification.
72 If OSIZE is zero, then the size field of the returned value
73 should be set only if a size is explicitly specified by the
74 user.
75 The structure returned describes all the data
76 found in the specification. In addition, *STRING_PTR is advanced
77 past the specification and past all whitespace following it. */
78
79 struct format_data
80 decode_format (string_ptr, oformat, osize)
81 char **string_ptr;
82 char oformat;
83 char osize;
84 {
85 struct format_data val;
86 register char *p = *string_ptr;
87
88 val.format = '?';
89 val.size = '?';
90 val.count = 1;
91
92 if (*p >= '0' && *p <= '9')
93 val.count = atoi (p);
94 while (*p >= '0' && *p <= '9') p++;
95
96 /* Now process size or format letters that follow. */
97
98 while (1)
99 {
100 if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
101 val.size = *p++;
102 #ifdef LONG_LONG
103 else if (*p == 'l')
104 {
105 val.size = 'g';
106 p++;
107 }
108 #endif
109 else if (*p >= 'a' && *p <= 'z')
110 val.format = *p++;
111 else
112 break;
113 }
114
115 #ifndef LONG_LONG
116 /* Make sure 'g' size is not used on integer types.
117 Well, actually, we can handle hex. */
118 if (val.size == 'g' && val.format != 'f' && val.format != 'x')
119 val.size = 'w';
120 #endif
121
122 while (*p == ' ' || *p == '\t') p++;
123 *string_ptr = p;
124
125 /* Set defaults for format and size if not specified. */
126 if (val.format == '?')
127 {
128 if (val.size == '?')
129 {
130 /* Neither has been specified. */
131 val.format = oformat;
132 val.size = osize;
133 }
134 else
135 /* If a size is specified, any format makes a reasonable
136 default except 'i'. */
137 val.format = oformat == 'i' ? 'x' : oformat;
138 }
139 else if (val.size == '?')
140 switch (val.format)
141 {
142 case 'a':
143 case 's':
144 /* Addresses must be words. */
145 val.size = osize ? 'w' : osize;
146 break;
147 case 'f':
148 /* Floating point has to be word or giantword. */
149 if (osize == 'w' || osize == 'g')
150 val.size = osize;
151 else
152 /* Default it to giantword if the last used size is not
153 appropriate. */
154 val.size = osize ? 'g' : osize;
155 break;
156 case 'c':
157 /* Characters default to one byte. */
158 val.size = osize ? 'b' : osize;
159 break;
160 default:
161 /* The default is the size most recently specified. */
162 val.size = osize;
163 }
164
165 return val;
166 }
167 \f
168 /* Print value VAL on stdout according to FORMAT, a letter or 0.
169 Do not end with a newline.
170 0 means print VAL according to its own type.
171 SIZE is the letter for the size of datum being printed.
172 This is used to pad hex numbers so they line up. */
173
174 static void
175 print_formatted (val, format, size)
176 register value val;
177 register char format;
178 char size;
179 {
180 int len = TYPE_LENGTH (VALUE_TYPE (val));
181
182 if (VALUE_LVAL (val) == lval_memory)
183 next_address = VALUE_ADDRESS (val) + len;
184
185 switch (format)
186 {
187 case 's':
188 next_address = VALUE_ADDRESS (val)
189 + value_print (value_addr (val), stdout, 0, Val_pretty_default);
190 break;
191
192 case 'i':
193 next_address = VALUE_ADDRESS (val)
194 + print_insn (VALUE_ADDRESS (val), stdout);
195 break;
196
197 default:
198 if (format == 0
199 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_ARRAY
200 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_STRUCT
201 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_UNION
202 || VALUE_REPEATED (val))
203 value_print (val, stdout, format, Val_pretty_default);
204 else
205 print_scalar_formatted (VALUE_CONTENTS (val), VALUE_TYPE (val),
206 format, size, stdout);
207 }
208 }
209
210 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
211 according to letters FORMAT and SIZE on STREAM.
212 FORMAT may not be zero. Formats s and i are not supported at this level.
213
214 This is how the elements of an array or structure are printed
215 with a format. */
216
217 void
218 print_scalar_formatted (valaddr, type, format, size, stream)
219 char *valaddr;
220 struct type *type;
221 char format;
222 int size;
223 FILE *stream;
224 {
225 LONGEST val_long;
226 int len = TYPE_LENGTH (type);
227
228 if (size == 'g' && sizeof (LONGEST) < 8
229 && format == 'x')
230 {
231 /* ok, we're going to have to get fancy here. Assumption: a
232 long is four bytes. */
233 unsigned long v1, v2, tmp;
234
235 v1 = unpack_long (builtin_type_long, valaddr);
236 v2 = unpack_long (builtin_type_long, valaddr + 4);
237
238 #ifdef BYTES_BIG_ENDIAN
239 #else
240 /* Little endian -- swap the two for printing */
241 tmp = v1;
242 v1 = v2;
243 v2 = tmp;
244 #endif
245
246 switch (format)
247 {
248 case 'x':
249 fprintf_filtered (stream, "0x%08x%08x", v1, v2);
250 break;
251 default:
252 error ("Output size \"g\" unimplemented for format \"%c\".",
253 format);
254 }
255 return;
256 }
257
258 val_long = unpack_long (type, valaddr);
259
260 /* If value is unsigned, truncate it in case negative. */
261 if (format != 'd')
262 {
263 if (len == sizeof (char))
264 val_long &= (1 << 8 * sizeof(char)) - 1;
265 else if (len == sizeof (short))
266 val_long &= (1 << 8 * sizeof(short)) - 1;
267 else if (len == sizeof (long))
268 val_long &= (unsigned long) - 1;
269 }
270
271 switch (format)
272 {
273 case 'x':
274 #ifdef LONG_LONG
275 if (!size)
276 size = (len < sizeof (long long) ? 'w' : 'g');
277 switch (size)
278 {
279 case 'b':
280 fprintf_filtered (stream, "0x%02llx", val_long);
281 break;
282 case 'h':
283 fprintf_filtered (stream, "0x%04llx", val_long);
284 break;
285 case 0: /* no size specified, like in print */
286 case 'w':
287 fprintf_filtered (stream, "0x%08llx", val_long);
288 break;
289 case 'g':
290 fprintf_filtered (stream, "0x%016llx", val_long);
291 break;
292 default:
293 error ("Undefined output size \"%c\".", size);
294 }
295 #else
296 switch (size)
297 {
298 case 'b':
299 fprintf_filtered (stream, "0x%02x", val_long);
300 break;
301 case 'h':
302 fprintf_filtered (stream, "0x%04x", val_long);
303 break;
304 case 0: /* no size specified, like in print */
305 case 'w':
306 fprintf_filtered (stream, "0x%08x", val_long);
307 break;
308 case 'g':
309 fprintf_filtered (stream, "0x%o16x", val_long);
310 break;
311 default:
312 error ("Undefined output size \"%c\".", size);
313 }
314 #endif /* not LONG_LONG */
315 break;
316
317 case 'd':
318 #ifdef LONG_LONG
319 fprintf_filtered (stream, "%lld", val_long);
320 #else
321 fprintf_filtered (stream, "%d", val_long);
322 #endif
323 break;
324
325 case 'u':
326 #ifdef LONG_LONG
327 fprintf_filtered (stream, "%llu", val_long);
328 #else
329 fprintf_filtered (stream, "%u", val_long);
330 #endif
331 break;
332
333 case 'o':
334 if (val_long)
335 #ifdef LONG_LONG
336 fprintf_filtered (stream, "0%llo", val_long);
337 #else
338 fprintf_filtered (stream, "0%o", val_long);
339 #endif
340 else
341 fprintf_filtered (stream, "0");
342 break;
343
344 case 'a':
345 print_address ((CORE_ADDR) val_long, stream);
346 break;
347
348 case 'c':
349 value_print (value_from_long (builtin_type_char, val_long), stream, 0,
350 Val_pretty_default);
351 break;
352
353 case 'f':
354 if (len == sizeof (float))
355 type = builtin_type_float;
356 else if (len == sizeof (double))
357 type = builtin_type_double;
358 #ifdef IEEE_FLOAT
359 if (is_nan (type, valaddr))
360 {
361 fprintf_filtered (stream, "Nan");
362 break;
363 }
364 #endif
365 {
366 double doub;
367 int inv;
368
369 doub = unpack_double (type, valaddr, &inv);
370 if (inv)
371 fprintf_filtered (stream, "Invalid float value");
372 else
373 fprintf_filtered (stream, len > 4 ? "%.16g" : "%.6g", doub);
374 }
375 break;
376
377 case 0:
378 abort ();
379
380 default:
381 error ("Undefined output format \"%c\".", format);
382 }
383 }
384
385 /* Specify default address for `x' command.
386 `info lines' uses this. */
387
388 void
389 set_next_address (addr)
390 CORE_ADDR addr;
391 {
392 next_address = addr;
393
394 /* Make address available to the user as $_. */
395 set_internalvar (lookup_internalvar ("_"),
396 value_from_long (builtin_type_int, (LONGEST) addr));
397 }
398
399 /* Print address ADDR symbolically on STREAM.
400 First print it as a number. Then perhaps print
401 <SYMBOL + OFFSET> after the number. */
402
403 void
404 print_address (addr, stream)
405 CORE_ADDR addr;
406 FILE *stream;
407 {
408 register int i = 0;
409 register char *format;
410 register struct symbol *fs;
411 char *name;
412 int name_location;
413
414 i = find_pc_partial_function (addr, &name, &name_location);
415
416 /* If nothing comes out, don't print anything symbolic. */
417
418 if (i == 0)
419 format = "0x%x";
420 else if (addr - name_location)
421 format = "0x%x <%s+%d>";
422 else
423 format = "0x%x <%s>";
424
425 fprintf_filtered (stream, format, addr, name, addr - name_location);
426 }
427 \f
428 /* Examine data at address ADDR in format FMT.
429 Fetch it from memory and print on stdout. */
430
431 static void
432 do_examine (fmt, addr)
433 struct format_data fmt;
434 CORE_ADDR addr;
435 {
436 register char format = 0;
437 register char size;
438 register int count = 1;
439 struct type *val_type;
440 register int i;
441 register int maxelts;
442
443 format = fmt.format;
444 size = fmt.size;
445 count = fmt.count;
446 next_address = addr;
447
448 /* String or instruction format implies fetch single bytes
449 regardless of the specified size. */
450 if (format == 's' || format == 'i')
451 size = 'b';
452
453 if (size == 'b')
454 val_type = builtin_type_char;
455 else if (size == 'h')
456 val_type = builtin_type_short;
457 else if (size == 'w')
458 val_type = builtin_type_long;
459 else if (size == 'g')
460 #ifndef LONG_LONG
461 val_type = builtin_type_double;
462 #else
463 val_type = builtin_type_long_long;
464 #endif
465
466 maxelts = 8;
467 if (size == 'w')
468 maxelts = 4;
469 if (size == 'g')
470 maxelts = 2;
471 if (format == 's' || format == 'i')
472 maxelts = 1;
473
474 /* Print as many objects as specified in COUNT, at most maxelts per line,
475 with the address of the next one at the start of each line. */
476
477 while (count > 0)
478 {
479 print_address (next_address, stdout);
480 printf_filtered (":");
481 for (i = maxelts;
482 i > 0 && count > 0;
483 i--, count--)
484 {
485 printf_filtered ("\t");
486 /* Note that print_formatted sets next_address for the next
487 object. */
488 last_examine_address = next_address;
489 last_examine_value = value_at (val_type, next_address);
490 print_formatted (last_examine_value, format, size);
491 }
492 printf_filtered ("\n");
493 fflush (stdout);
494 }
495 }
496 \f
497 static void
498 validate_format (fmt, cmdname)
499 struct format_data fmt;
500 char *cmdname;
501 {
502 if (fmt.size != 0)
503 error ("Size letters are meaningless in \"%s\" command.", cmdname);
504 if (fmt.count != 1)
505 error ("Item count other than 1 is meaningless in \"%s\" command.",
506 cmdname);
507 if (fmt.format == 'i' || fmt.format == 's')
508 error ("Format letter \"%c\" is meaningless in \"%s\" command.",
509 fmt.format, cmdname);
510 }
511
512 static void
513 print_command (exp)
514 char *exp;
515 {
516 struct expression *expr;
517 register struct cleanup *old_chain = 0;
518 register char format = 0;
519 register value val;
520 struct format_data fmt;
521 int histindex;
522 int cleanup = 0;
523
524 if (exp && *exp == '/')
525 {
526 exp++;
527 fmt = decode_format (&exp, last_format, 0);
528 validate_format (fmt, "print");
529 last_format = format = fmt.format;
530 }
531
532 if (exp && *exp)
533 {
534 expr = parse_c_expression (exp);
535 old_chain = make_cleanup (free_current_contents, &expr);
536 cleanup = 1;
537 val = evaluate_expression (expr);
538 }
539 else
540 val = access_value_history (0);
541
542 histindex = record_latest_value (val);
543 if (histindex >= 0) printf_filtered ("$%d = ", histindex);
544
545 print_formatted (val, format, fmt.size);
546 printf_filtered ("\n");
547
548 if (cleanup)
549 do_cleanups (old_chain);
550 }
551
552 static void
553 output_command (exp)
554 char *exp;
555 {
556 struct expression *expr;
557 register struct cleanup *old_chain;
558 register char format = 0;
559 register value val;
560 struct format_data fmt;
561
562 if (exp && *exp == '/')
563 {
564 exp++;
565 fmt = decode_format (&exp, 0, 0);
566 validate_format (fmt, "print");
567 format = fmt.format;
568 }
569
570 expr = parse_c_expression (exp);
571 old_chain = make_cleanup (free_current_contents, &expr);
572
573 val = evaluate_expression (expr);
574
575 print_formatted (val, format, fmt.size);
576
577 do_cleanups (old_chain);
578 }
579
580 static void
581 set_command (exp)
582 char *exp;
583 {
584 struct expression *expr = parse_c_expression (exp);
585 register struct cleanup *old_chain
586 = make_cleanup (free_current_contents, &expr);
587 evaluate_expression (expr);
588 do_cleanups (old_chain);
589 }
590
591 static void
592 address_info (exp)
593 char *exp;
594 {
595 register struct symbol *sym;
596 register CORE_ADDR val;
597 int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
598 if exp is a field of `this'. */
599
600 if (exp == 0)
601 error ("Argument required.");
602
603 sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
604 &is_a_field_of_this);
605 if (sym == 0)
606 {
607 register int i;
608
609 if (is_a_field_of_this)
610 {
611 printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp);
612 return;
613 }
614
615 for (i = 0; i < misc_function_count; i++)
616 if (!strcmp (misc_function_vector[i].name, exp))
617 break;
618
619 if (i < misc_function_count)
620 printf ("Symbol \"%s\" is at 0x%x in a file compiled without -g.\n",
621 exp, misc_function_vector[i].address);
622 else
623 error ("No symbol \"%s\" in current context.", exp);
624 return;
625 }
626
627 printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym));
628 val = SYMBOL_VALUE (sym);
629
630 switch (SYMBOL_CLASS (sym))
631 {
632 case LOC_CONST:
633 case LOC_CONST_BYTES:
634 printf ("constant");
635 break;
636
637 case LOC_LABEL:
638 printf ("a label at address 0x%x", val);
639 break;
640
641 case LOC_REGISTER:
642 printf ("a variable in register %s", reg_names[val]);
643 break;
644
645 case LOC_STATIC:
646 printf ("static at address 0x%x", val);
647 break;
648
649 case LOC_REGPARM:
650 printf ("an argument in register %s", reg_names[val]);
651 break;
652
653 case LOC_ARG:
654 printf ("an argument at offset %d", val);
655 break;
656
657 case LOC_LOCAL:
658 printf ("a local variable at frame offset %d", val);
659 break;
660
661 case LOC_REF_ARG:
662 printf ("a reference argument at offset %d", val);
663 break;
664
665 case LOC_TYPEDEF:
666 printf ("a typedef");
667 break;
668
669 case LOC_BLOCK:
670 printf ("a function at address 0x%x",
671 BLOCK_START (SYMBOL_BLOCK_VALUE (sym)));
672 break;
673 }
674 printf (".\n");
675 }
676 \f
677 static void
678 x_command (exp, from_tty)
679 char *exp;
680 int from_tty;
681 {
682 struct expression *expr;
683 struct format_data fmt;
684 struct cleanup *old_chain;
685 struct value *val;
686
687 fmt.format = last_format;
688 fmt.size = last_size;
689 fmt.count = 1;
690
691 if (exp && *exp == '/')
692 {
693 exp++;
694 fmt = decode_format (&exp, last_format, last_size);
695 last_size = fmt.size;
696 last_format = fmt.format;
697 }
698
699 /* If we have an expression, evaluate it and use it as the address. */
700
701 if (exp != 0 && *exp != 0)
702 {
703 expr = parse_c_expression (exp);
704 /* Cause expression not to be there any more
705 if this command is repeated with Newline.
706 But don't clobber a user-defined command's definition. */
707 if (from_tty)
708 *exp = 0;
709 old_chain = make_cleanup (free_current_contents, &expr);
710 val = evaluate_expression (expr);
711 /* In rvalue contexts, such as this, functions are coerced into
712 pointers to functions. This makes "x/i main" work. */
713 if (/* last_format == 'i'
714 && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
715 && VALUE_LVAL (val) == lval_memory)
716 next_address = VALUE_ADDRESS (val);
717 else
718 next_address = (CORE_ADDR) value_as_long (val);
719 do_cleanups (old_chain);
720 }
721
722 do_examine (fmt, next_address);
723
724 /* Set a couple of internal variables if appropriate. */
725 if (last_examine_value)
726 {
727 /* Make last address examined available to the user as $_. */
728 set_internalvar (lookup_internalvar ("_"),
729 value_from_long (builtin_type_int,
730 (LONGEST) last_examine_address));
731
732 /* Make contents of last address examined available to the user as $__.*/
733 set_internalvar (lookup_internalvar ("__"), last_examine_value);
734 }
735 }
736 \f
737 /* Commands for printing types of things. */
738
739 static void
740 whatis_command (exp)
741 char *exp;
742 {
743 struct expression *expr;
744 register value val;
745 register struct cleanup *old_chain;
746
747 if (exp)
748 {
749 expr = parse_c_expression (exp);
750 old_chain = make_cleanup (free_current_contents, &expr);
751 val = evaluate_type (expr);
752 }
753 else
754 val = access_value_history (0);
755
756 printf_filtered ("type = ");
757 /* Most of the time users do not want to see all the fields
758 in a structure. If they do they can use the "ptype" command.
759 Hence the "-1" below. */
760 type_print (VALUE_TYPE (val), "", stdout, -1);
761 printf_filtered ("\n");
762
763 if (exp)
764 do_cleanups (old_chain);
765 }
766
767 static void
768 ptype_command (typename)
769 char *typename;
770 {
771 register char *p = typename;
772 register int len;
773 extern struct block *get_current_block ();
774 register struct block *b
775 = (have_inferior_p () || have_core_file_p ()) ? get_current_block () : 0;
776 register struct type *type;
777
778 if (typename == 0)
779 error_no_arg ("type name");
780
781 while (*p && *p != ' ' && *p != '\t') p++;
782 len = p - typename;
783 while (*p == ' ' || *p == '\t') p++;
784
785 if (len == 6 && !strncmp (typename, "struct", 6))
786 type = lookup_struct (p, b);
787 else if (len == 5 && !strncmp (typename, "union", 5))
788 type = lookup_union (p, b);
789 else if (len == 4 && !strncmp (typename, "enum", 4))
790 type = lookup_enum (p, b);
791 else
792 {
793 type = lookup_typename (typename, b, 1);
794 if (type == 0)
795 {
796 register struct symbol *sym
797 = lookup_symbol (typename, b, STRUCT_NAMESPACE, 0);
798 if (sym == 0)
799 error ("No type named %s.", typename);
800 printf_filtered ("No type named %s, but there is a ",
801 typename);
802 switch (TYPE_CODE (SYMBOL_TYPE (sym)))
803 {
804 case TYPE_CODE_STRUCT:
805 printf_filtered ("struct");
806 break;
807
808 case TYPE_CODE_UNION:
809 printf_filtered ("union");
810 break;
811
812 case TYPE_CODE_ENUM:
813 printf_filtered ("enum");
814 }
815 printf_filtered (" %s. Type \"help ptype\".\n", typename);
816 type = SYMBOL_TYPE (sym);
817 }
818 }
819
820 type_print (type, "", stdout, 1);
821 printf_filtered ("\n");
822 }
823 \f
824 enum display_status {disabled, enabled};
825
826 struct display
827 {
828 /* Chain link to next auto-display item. */
829 struct display *next;
830 /* Expression to be evaluated and displayed. */
831 struct expression *exp;
832 /* Item number of this auto-display item. */
833 int number;
834 /* Display format specified. */
835 struct format_data format;
836 /* Innermost block required by this expression when evaluated */
837 struct block *block;
838 /* Status of this display (enabled or disabled) */
839 enum display_status status;
840 };
841
842 /* Chain of expressions whose values should be displayed
843 automatically each time the program stops. */
844
845 static struct display *display_chain;
846
847 static int display_number;
848
849 /* Add an expression to the auto-display chain.
850 Specify the expression. */
851
852 static void
853 display_command (exp, from_tty)
854 char *exp;
855 int from_tty;
856 {
857 struct format_data fmt;
858 register struct expression *expr;
859 register struct display *new;
860 extern struct block *innermost_block;
861
862 if (exp == 0)
863 {
864 do_displays ();
865 return;
866 }
867
868 if (*exp == '/')
869 {
870 exp++;
871 fmt = decode_format (&exp, 0, 0);
872 if (fmt.size && fmt.format == 0)
873 fmt.format = 'x';
874 if (fmt.format == 'i' || fmt.format == 's')
875 fmt.size = 'b';
876 }
877 else
878 {
879 fmt.format = 0;
880 fmt.size = 0;
881 fmt.count = 0;
882 }
883
884 innermost_block = 0;
885 expr = parse_c_expression (exp);
886
887 new = (struct display *) xmalloc (sizeof (struct display));
888
889 new->exp = expr;
890 new->block = innermost_block;
891 new->next = display_chain;
892 new->number = ++display_number;
893 new->format = fmt;
894 new->status = enabled;
895 display_chain = new;
896
897 if (from_tty && have_inferior_p ())
898 do_one_display (new);
899
900 dont_repeat ();
901 }
902
903 static void
904 free_display (d)
905 struct display *d;
906 {
907 free (d->exp);
908 free (d);
909 }
910
911 /* Clear out the display_chain.
912 Done when new symtabs are loaded, since this invalidates
913 the types stored in many expressions. */
914
915 void
916 clear_displays ()
917 {
918 register struct display *d;
919
920 while (d = display_chain)
921 {
922 free (d->exp);
923 display_chain = d->next;
924 free (d);
925 }
926 }
927
928 /* Delete the auto-display number NUM. */
929
930 void
931 delete_display (num)
932 int num;
933 {
934 register struct display *d1, *d;
935
936 if (!display_chain)
937 error ("No display number %d.", num);
938
939 if (display_chain->number == num)
940 {
941 d1 = display_chain;
942 display_chain = d1->next;
943 free_display (d1);
944 }
945 else
946 for (d = display_chain; ; d = d->next)
947 {
948 if (d->next == 0)
949 error ("No display number %d.", num);
950 if (d->next->number == num)
951 {
952 d1 = d->next;
953 d->next = d1->next;
954 free_display (d1);
955 break;
956 }
957 }
958 }
959
960 /* Delete some values from the auto-display chain.
961 Specify the element numbers. */
962
963 static void
964 undisplay_command (args)
965 char *args;
966 {
967 register char *p = args;
968 register char *p1;
969 register int num;
970 register struct display *d, *d1;
971
972 if (args == 0)
973 {
974 if (query ("Delete all auto-display expressions? "))
975 clear_displays ();
976 dont_repeat ();
977 return;
978 }
979
980 while (*p)
981 {
982 p1 = p;
983 while (*p1 >= '0' && *p1 <= '9') p1++;
984 if (*p1 && *p1 != ' ' && *p1 != '\t')
985 error ("Arguments must be display numbers.");
986
987 num = atoi (p);
988
989 delete_display (num);
990
991 p = p1;
992 while (*p == ' ' || *p == '\t') p++;
993 }
994 dont_repeat ();
995 }
996
997 /* Display a single auto-display.
998 Do nothing if the display cannot be printed in the current context,
999 or if the display is disabled. */
1000
1001 static void
1002 do_one_display (d)
1003 struct display *d;
1004 {
1005 int within_current_scope;
1006
1007 if (d->status == disabled)
1008 return;
1009
1010 if (d->block)
1011 within_current_scope = contained_in (get_selected_block (), d->block);
1012 else
1013 within_current_scope = 1;
1014 if (!within_current_scope)
1015 return;
1016
1017 current_display_number = d->number;
1018
1019 printf_filtered ("%d: ", d->number);
1020 if (d->format.size)
1021 {
1022 printf_filtered ("x/");
1023 if (d->format.count != 1)
1024 printf_filtered ("%d", d->format.count);
1025 printf_filtered ("%c", d->format.format);
1026 if (d->format.format != 'i' && d->format.format != 's')
1027 printf_filtered ("%c", d->format.size);
1028 printf_filtered (" ");
1029 print_expression (d->exp, stdout);
1030 if (d->format.count != 1)
1031 printf_filtered ("\n");
1032 else
1033 printf_filtered (" ");
1034 do_examine (d->format,
1035 (CORE_ADDR) value_as_long (evaluate_expression (d->exp)));
1036
1037 }
1038 else
1039 {
1040 if (d->format.format)
1041 printf_filtered ("/%c ", d->format.format);
1042 print_expression (d->exp, stdout);
1043 printf_filtered (" = ");
1044 print_formatted (evaluate_expression (d->exp),
1045 d->format.format, d->format.size);
1046 printf_filtered ("\n");
1047 }
1048
1049 fflush (stdout);
1050 current_display_number = -1;
1051 }
1052
1053 /* Display all of the values on the auto-display chain which can be
1054 evaluated in the current scope. */
1055
1056 void
1057 do_displays ()
1058 {
1059 register struct display *d;
1060
1061 for (d = display_chain; d; d = d->next)
1062 do_one_display (d);
1063 }
1064
1065 /* Delete the auto-display which we were in the process of displaying.
1066 This is done when there is an error or a signal. */
1067
1068 void
1069 disable_display (num)
1070 int num;
1071 {
1072 register struct display *d;
1073
1074 for (d = display_chain; d; d = d->next)
1075 if (d->number == num)
1076 {
1077 d->status = disabled;
1078 return;
1079 }
1080 printf ("No display number %d.\n", num);
1081 }
1082
1083 void
1084 disable_current_display ()
1085 {
1086 if (current_display_number >= 0)
1087 {
1088 disable_display (current_display_number);
1089 fprintf (stderr, "Disabling display %d to avoid infinite recursion.\n",
1090 current_display_number);
1091 }
1092 current_display_number = -1;
1093 }
1094
1095 static void
1096 display_info ()
1097 {
1098 register struct display *d;
1099
1100 if (!display_chain)
1101 printf ("There are no auto-display expressions now.\n");
1102 else
1103 printf_filtered ("Auto-display expressions now in effect:\n\
1104 Num Enb Expression\n");
1105
1106 for (d = display_chain; d; d = d->next)
1107 {
1108 printf_filtered ("%d: %c ", d->number, "ny"[(int)d->status]);
1109 if (d->format.size)
1110 printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
1111 d->format.format);
1112 else if (d->format.format)
1113 printf_filtered ("/%c ", d->format.format);
1114 print_expression (d->exp, stdout);
1115 if (d->block && !contained_in (get_selected_block (), d->block))
1116 printf_filtered (" (cannot be evaluated in the current context)");
1117 printf_filtered ("\n");
1118 fflush (stdout);
1119 }
1120 }
1121
1122 void
1123 enable_display (args)
1124 char *args;
1125 {
1126 register char *p = args;
1127 register char *p1;
1128 register int num;
1129 register struct display *d;
1130
1131 if (p == 0)
1132 {
1133 for (d = display_chain; d; d = d->next)
1134 d->status = enabled;
1135 }
1136 else
1137 while (*p)
1138 {
1139 p1 = p;
1140 while (*p1 >= '0' && *p1 <= '9')
1141 p1++;
1142 if (*p1 && *p1 != ' ' && *p1 != '\t')
1143 error ("Arguments must be display numbers.");
1144
1145 num = atoi (p);
1146
1147 for (d = display_chain; d; d = d->next)
1148 if (d->number == num)
1149 {
1150 d->status = enabled;
1151 goto win;
1152 }
1153 printf ("No display number %d.\n", num);
1154 win:
1155 p = p1;
1156 while (*p == ' ' || *p == '\t')
1157 p++;
1158 }
1159 }
1160
1161 void
1162 disable_display_command (args, from_tty)
1163 char *args;
1164 int from_tty;
1165 {
1166 register char *p = args;
1167 register char *p1;
1168 register int num;
1169 register struct display *d;
1170
1171 if (p == 0)
1172 {
1173 for (d = display_chain; d; d = d->next)
1174 d->status = disabled;
1175 }
1176 else
1177 while (*p)
1178 {
1179 p1 = p;
1180 while (*p1 >= '0' && *p1 <= '9')
1181 p1++;
1182 if (*p1 && *p1 != ' ' && *p1 != '\t')
1183 error ("Arguments must be display numbers.");
1184
1185 num = atoi (p);
1186
1187 disable_display (atoi (p));
1188
1189 p = p1;
1190 while (*p == ' ' || *p == '\t')
1191 p++;
1192 }
1193 }
1194
1195 \f
1196 /* Print the value in stack frame FRAME of a variable
1197 specified by a struct symbol. */
1198
1199 void
1200 print_variable_value (var, frame, stream)
1201 struct symbol *var;
1202 CORE_ADDR frame;
1203 FILE *stream;
1204 {
1205 value val = read_var_value (var, frame);
1206 value_print (val, stream, 0, Val_pretty_default);
1207 }
1208
1209 static int
1210 compare_ints (i, j)
1211 int *i, *j;
1212 {
1213 return *i - *j;
1214 }
1215
1216 /* Print the arguments of a stack frame, given the function FUNC
1217 running in that frame (as a symbol), the info on the frame,
1218 and the number of args according to the stack frame (or -1 if unknown). */
1219
1220 static void print_frame_nameless_args ();
1221
1222 void
1223 print_frame_args (func, fi, num, stream)
1224 struct symbol *func;
1225 struct frame_info *fi;
1226 int num;
1227 FILE *stream;
1228 {
1229 struct block *b;
1230 int nsyms = 0;
1231 int first = 1;
1232 register int i;
1233 register int last_regparm = 0;
1234 register struct symbol *lastsym, *sym, *nextsym;
1235 register value val;
1236 CORE_ADDR highest_offset = 0;
1237 register CORE_ADDR addr = FRAME_ARGS_ADDRESS (fi);
1238
1239 if (func)
1240 {
1241 b = SYMBOL_BLOCK_VALUE (func);
1242 nsyms = BLOCK_NSYMS (b);
1243 }
1244
1245 for (i = 0; i < nsyms; i++)
1246 {
1247 QUIT;
1248 sym = BLOCK_SYM (b, i);
1249
1250 if (SYMBOL_CLASS (sym) != LOC_REGPARM
1251 && SYMBOL_CLASS (sym) != LOC_ARG
1252 && SYMBOL_CLASS (sym) != LOC_REF_ARG)
1253 continue;
1254
1255 /* Print the next arg. */
1256 if (SYMBOL_CLASS (sym) == LOC_REGPARM)
1257 val = value_from_register (SYMBOL_TYPE (sym),
1258 SYMBOL_VALUE (sym),
1259 FRAME_INFO_ID (fi));
1260 else
1261 {
1262 int current_offset = SYMBOL_VALUE (sym);
1263 int arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
1264
1265 if (SYMBOL_CLASS (sym) == LOC_REF_ARG)
1266 val = value_at (SYMBOL_TYPE (sym),
1267 read_memory_integer (addr + current_offset,
1268 sizeof (CORE_ADDR)));
1269 else
1270 val = value_at (SYMBOL_TYPE (sym), addr + current_offset);
1271
1272 /* Round up address of next arg to multiple of size of int. */
1273 current_offset
1274 = (((current_offset + sizeof (int) - 1) / sizeof (int))
1275 * sizeof (int));
1276
1277 if ((current_offset
1278 + (arg_size - sizeof (int) + 3) / (sizeof (int)))
1279 > highest_offset)
1280 highest_offset = current_offset;
1281 }
1282
1283 if (! first)
1284 fprintf_filtered (stream, ", ");
1285 fputs_filtered (SYMBOL_NAME (sym), stream);
1286 fputs_filtered ("=", stream);
1287 value_print (val, stream, 0, Val_no_prettyprint);
1288 first = 0;
1289 }
1290
1291 /* Don't print nameless args in situations where we don't know
1292 enough about the stack to find them. */
1293 if (num != -1)
1294 {
1295 if (i && num * sizeof (int) + FRAME_ARGS_SKIP > highest_offset)
1296 print_frame_nameless_args (addr,
1297 highest_offset + sizeof (int),
1298 num * sizeof (int) + FRAME_ARGS_SKIP,
1299 stream);
1300 else
1301 print_frame_nameless_args (addr, FRAME_ARGS_SKIP,
1302 num * sizeof (int) + FRAME_ARGS_SKIP,
1303 stream);
1304 }
1305 }
1306
1307 static void
1308 print_frame_nameless_args (argsaddr, start, end, stream)
1309 CORE_ADDR argsaddr;
1310 int start;
1311 int end;
1312 FILE *stream;
1313 {
1314 while (start < end)
1315 {
1316 QUIT;
1317 if (start != FRAME_ARGS_SKIP)
1318 fprintf_filtered (stream, ", ");
1319 #ifndef PRINT_TYPELESS_INTEGER
1320 fprintf_filtered (stream, "%d",
1321 read_memory_integer (argsaddr + start, sizeof (int)));
1322 #else
1323 PRINT_TYPELESS_INTEGER (stream, builtin_type_int,
1324 (LONGEST)
1325 read_memory_integer (argsaddr + start,
1326 sizeof (int)));
1327 #endif
1328 start += sizeof (int);
1329 }
1330 }
1331 \f
1332 static void
1333 printf_command (arg)
1334 char *arg;
1335 {
1336 register char *f;
1337 register char *s = arg;
1338 char *string;
1339 value *val_args;
1340 int nargs = 0;
1341 int allocated_args = 20;
1342 char *arg_bytes;
1343
1344 val_args = (value *) xmalloc (allocated_args * sizeof (value));
1345
1346 if (s == 0)
1347 error_no_arg ("format-control string and values to print");
1348
1349 /* Skip white space before format string */
1350 while (*s == ' ' || *s == '\t') s++;
1351
1352 /* A format string should follow, enveloped in double quotes */
1353 if (*s++ != '"')
1354 error ("Bad format string, missing '\"'.");
1355
1356 /* Parse the format-control string and copy it into the string STRING,
1357 processing some kinds of escape sequence. */
1358
1359 f = string = (char *) alloca (strlen (s) + 1);
1360 while (*s != '"')
1361 {
1362 int c = *s++;
1363 switch (c)
1364 {
1365 case '\0':
1366 error ("Bad format string, non-terminated '\"'.");
1367 /* doesn't return */
1368
1369 case '\\':
1370 switch (c = *s++)
1371 {
1372 case '\\':
1373 *f++ = '\\';
1374 break;
1375 case 'n':
1376 *f++ = '\n';
1377 break;
1378 case 't':
1379 *f++ = '\t';
1380 break;
1381 case 'r':
1382 *f++ = '\r';
1383 break;
1384 case '"':
1385 *f++ = '"';
1386 break;
1387 default:
1388 /* ??? TODO: handle other escape sequences */
1389 error ("Unrecognized \\ escape character in format string.");
1390 }
1391 break;
1392
1393 default:
1394 *f++ = c;
1395 }
1396 }
1397
1398 /* Skip over " and following space and comma. */
1399 s++;
1400 *f++ = '\0';
1401 while (*s == ' ' || *s == '\t') s++;
1402
1403 if (*s != ',' && *s != 0)
1404 error ("Invalid argument syntax");
1405
1406 if (*s == ',') s++;
1407 while (*s == ' ' || *s == '\t') s++;
1408
1409 {
1410 /* Now scan the string for %-specs and see what kinds of args they want.
1411 argclass[I] classifies the %-specs so we can give vprintf something
1412 of the right size. */
1413
1414 enum argclass {int_arg, string_arg, double_arg, long_long_arg};
1415 enum argclass *argclass;
1416 int nargs_wanted;
1417 int argindex;
1418 int lcount;
1419 int i;
1420
1421 argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
1422 nargs_wanted = 0;
1423 f = string;
1424 while (*f)
1425 if (*f++ == '%')
1426 {
1427 lcount = 0;
1428 while (index ("0123456789.hlL-+ #", *f))
1429 {
1430 if (*f == 'l' || *f == 'L')
1431 lcount++;
1432 f++;
1433 }
1434 if (*f == 's')
1435 argclass[nargs_wanted++] = string_arg;
1436 else if (*f == 'e' || *f == 'f' || *f == 'g')
1437 argclass[nargs_wanted++] = double_arg;
1438 else if (lcount > 1)
1439 argclass[nargs_wanted++] = long_long_arg;
1440 else if (*f != '%')
1441 argclass[nargs_wanted++] = int_arg;
1442 f++;
1443 }
1444
1445 /* Now, parse all arguments and evaluate them.
1446 Store the VALUEs in VAL_ARGS. */
1447
1448 while (*s != '\0')
1449 {
1450 char *s1;
1451 if (nargs == allocated_args)
1452 val_args = (value *) xrealloc (val_args,
1453 (allocated_args *= 2)
1454 * sizeof (value));
1455 s1 = s;
1456 val_args[nargs] = parse_to_comma_and_eval (&s1);
1457
1458 /* If format string wants a float, unchecked-convert the value to
1459 floating point of the same size */
1460
1461 if (argclass[nargs] == double_arg)
1462 {
1463 if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (float))
1464 VALUE_TYPE (val_args[nargs]) = builtin_type_float;
1465 if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (double))
1466 VALUE_TYPE (val_args[nargs]) = builtin_type_double;
1467 }
1468 nargs++;
1469 s = s1;
1470 if (*s == ',')
1471 s++;
1472 }
1473
1474 if (nargs != nargs_wanted)
1475 error ("Wrong number of arguments for specified format-string");
1476
1477 /* Now lay out an argument-list containing the arguments
1478 as doubles, integers and C pointers. */
1479
1480 arg_bytes = (char *) alloca (sizeof (double) * nargs);
1481 argindex = 0;
1482 for (i = 0; i < nargs; i++)
1483 {
1484 if (argclass[i] == string_arg)
1485 {
1486 char *str;
1487 int tem, j;
1488 tem = value_as_long (val_args[i]);
1489
1490 /* This is a %s argument. Find the length of the string. */
1491 for (j = 0; ; j++)
1492 {
1493 char c;
1494 QUIT;
1495 read_memory (tem + j, &c, 1);
1496 if (c == 0)
1497 break;
1498 }
1499
1500 /* Copy the string contents into a string inside GDB. */
1501 str = (char *) alloca (j + 1);
1502 read_memory (tem, str, j);
1503 str[j] = 0;
1504
1505 /* Pass address of internal copy as the arg to vprintf. */
1506 *((int *) &arg_bytes[argindex]) = (int) str;
1507 argindex += sizeof (int);
1508 }
1509 else if (VALUE_TYPE (val_args[i])->code == TYPE_CODE_FLT)
1510 {
1511 *((double *) &arg_bytes[argindex]) = value_as_double (val_args[i]);
1512 argindex += sizeof (double);
1513 }
1514 else
1515 #ifdef LONG_LONG
1516 if (argclass[i] == long_long_arg)
1517 {
1518 *(long long *) &arg_bytes[argindex] = value_as_long (val_args[i]);
1519 argindex += sizeof (long long);
1520 }
1521 else
1522 #endif
1523 {
1524 *((int *) &arg_bytes[argindex]) = value_as_long (val_args[i]);
1525 argindex += sizeof (int);
1526 }
1527 }
1528 }
1529 vprintf (string, arg_bytes);
1530 }
1531 \f
1532 /* Helper function for asdump_command. Finds the bounds of a function
1533 for a specified section of text. PC is an address within the
1534 function which you want bounds for; *LOW and *HIGH are set to the
1535 beginning (inclusive) and end (exclusive) of the function. This
1536 function returns 1 on success and 0 on failure. */
1537
1538 static int
1539 containing_function_bounds (pc, low, high)
1540 CORE_ADDR pc, *low, *high;
1541 {
1542 int scan;
1543
1544 if (!find_pc_partial_function (pc, 0, low))
1545 return 0;
1546
1547 scan = *low;
1548 do {
1549 scan++;
1550 if (!find_pc_partial_function (scan, 0, high))
1551 return 0;
1552 } while (*low == *high);
1553
1554 return 1;
1555 }
1556
1557 /* Dump a specified section of assembly code. With no command line
1558 arguments, this command will dump the assembly code for the
1559 function surrounding the pc value in the selected frame. With one
1560 argument, it will dump the assembly code surrounding that pc value.
1561 Two arguments are interpeted as bounds within which to dump
1562 assembly. */
1563
1564 static void
1565 disassemble_command (arg, from_tty)
1566 char *arg;
1567 int from_tty;
1568 {
1569 CORE_ADDR low, high;
1570 CORE_ADDR pc;
1571 char *space_index;
1572
1573 if (!arg)
1574 {
1575 if (!selected_frame)
1576 error ("No frame selected.\n");
1577
1578 pc = get_frame_pc (selected_frame);
1579 if (!containing_function_bounds (pc, &low, &high))
1580 error ("No function contains pc specified by selected frame.\n");
1581 }
1582 else if (!(space_index = (char *) index (arg, ' ')))
1583 {
1584 /* One argument. */
1585 pc = parse_and_eval_address (arg);
1586 if (!containing_function_bounds (pc, &low, &high))
1587 error ("No function contains specified pc.\n");
1588 }
1589 else
1590 {
1591 /* Two arguments. */
1592 *space_index = '\0';
1593 low = parse_and_eval_address (arg);
1594 high = parse_and_eval_address (space_index + 1);
1595 }
1596
1597 printf_filtered ("Dump of assembler code ");
1598 if (!space_index)
1599 {
1600 char *name;
1601 find_pc_partial_function (pc, &name, 0);
1602 printf_filtered ("for function %s:\n", name);
1603 }
1604 else
1605 printf_filtered ("from 0x%x to 0x%x:\n", low, high);
1606
1607 /* Dump the specified range. */
1608 for (pc = low; pc < high; )
1609 {
1610 QUIT;
1611 print_address (pc, stdout);
1612 printf_filtered (":\t");
1613 pc += print_insn (pc, stdout);
1614 printf_filtered ("\n");
1615 }
1616 printf_filtered ("End of assembler dump.\n");
1617 fflush (stdout);
1618 }
1619
1620 \f
1621 extern struct cmd_list_element *enablelist, *disablelist, *deletelist;
1622 extern struct cmd_list_element *cmdlist, *setlist;
1623
1624 void
1625 _initialize_printcmd ()
1626 {
1627 current_display_number = -1;
1628
1629 add_info ("address", address_info,
1630 "Describe where variable VAR is stored.");
1631
1632 add_com ("x", class_vars, x_command,
1633 "Examine memory: x/FMT ADDRESS.\n\
1634 ADDRESS is an expression for the memory address to examine.\n\
1635 FMT is a repeat count followed by a format letter and a size letter.\n\
1636 Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
1637 f(float), a(address), i(instruction), c(char) and s(string).\n\
1638 Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
1639 g is meaningful only with f, for type double.\n\
1640 The specified number of objects of the specified size are printed\n\
1641 according to the format.\n\n\
1642 Defaults for format and size letters are those previously used.\n\
1643 Default count is 1. Default address is following last thing printed\n\
1644 with this command or \"print\".");
1645
1646 add_com ("disassemble", class_vars, disassemble_command,
1647 "Disassemble a specified section of memory.\n\
1648 Default is the function surrounding the pc of the selected frame.\n\
1649 With a single argument, the function surrounding that address is dumped.\n\
1650 Two arguments are taken as a range of memory to dump.");
1651
1652 add_com ("ptype", class_vars, ptype_command,
1653 "Print definition of type TYPE.\n\
1654 Argument may be a type name defined by typedef, or \"struct STRUCTNAME\"\n\
1655 or \"union UNIONNAME\" or \"enum ENUMNAME\".\n\
1656 The selected stack frame's lexical context is used to look up the name.");
1657
1658 add_com ("whatis", class_vars, whatis_command,
1659 "Print data type of expression EXP.");
1660
1661 add_info ("display", display_info,
1662 "Expressions to display when program stops, with code numbers.");
1663
1664 add_cmd ("undisplay", class_vars, undisplay_command,
1665 "Cancel some expressions to be displayed when program stops.\n\
1666 Arguments are the code numbers of the expressions to stop displaying.\n\
1667 No argument means cancel all automatic-display expressions.\n\
1668 \"delete display\" has the same effect as this command.\n\
1669 Do \"info display\" to see current list of code numbers.",
1670 &cmdlist);
1671
1672 add_com ("display", class_vars, display_command,
1673 "Print value of expression EXP each time the program stops.\n\
1674 /FMT may be used before EXP as in the \"print\" command.\n\
1675 /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
1676 as in the \"x\" command, and then EXP is used to get the address to examine\n\
1677 and examining is done as in the \"x\" command.\n\n\
1678 With no argument, display all currently requested auto-display expressions.\n\
1679 Use \"undisplay\" to cancel display requests previously made.");
1680
1681 add_cmd ("display", class_vars, enable_display,
1682 "Enable some expressions to be displayed when program stops.\n\
1683 Arguments are the code numbers of the expressions to resume displaying.\n\
1684 No argument means enable all automatic-display expressions.\n\
1685 Do \"info display\" to see current list of code numbers.", &enablelist);
1686
1687 add_cmd ("display", class_vars, disable_display_command,
1688 "Disable some expressions to be displayed when program stops.\n\
1689 Arguments are the code numbers of the expressions to stop displaying.\n\
1690 No argument means disable all automatic-display expressions.\n\
1691 Do \"info display\" to see current list of code numbers.", &disablelist);
1692
1693 add_cmd ("display", class_vars, undisplay_command,
1694 "Cancel some expressions to be displayed when program stops.\n\
1695 Arguments are the code numbers of the expressions to stop displaying.\n\
1696 No argument means cancel all automatic-display expressions.\n\
1697 Do \"info display\" to see current list of code numbers.", &deletelist);
1698
1699 add_com ("printf", class_vars, printf_command,
1700 "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
1701 This is useful for formatted output in user-defined commands.");
1702 add_com ("output", class_vars, output_command,
1703 "Like \"print\" but don't put in value history and don't print newline.\n\
1704 This is useful in user-defined commands.");
1705
1706 add_prefix_cmd ("set", class_vars, set_command,
1707 "Perform an assignment VAR = EXP.\n\
1708 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
1709 (names starting with $), a register (a few standard names starting with $),\n\
1710 or an actual variable in the program being debugged. EXP is any expression.\n\
1711 Use \"set variable\" for variables with names identical to set subcommands.\n\
1712 \nWith a subcommand, this command modifies parts of the gdb environment",
1713 &setlist, "set ", 1, &cmdlist);
1714
1715 add_cmd ("variable", class_vars, set_command,
1716 "Perform an assignment VAR = EXP.\n\
1717 You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\
1718 (names starting with $), a register (a few standard names starting with $),\n\
1719 or an actual variable in the program being debugged. EXP is any expression.\n\
1720 This may usually be abbreviated to simply \"set\".",
1721 &setlist);
1722
1723 add_com ("print", class_vars, print_command,
1724 concat ("Print value of expression EXP.\n\
1725 Variables accessible are those of the lexical environment of the selected\n\
1726 stack frame, plus all those whose scope is global or an entire file.\n\
1727 \n\
1728 $NUM gets previous value number NUM. $ and $$ are the last two values.\n\
1729 $$NUM refers to NUM'th value back from the last one.\n\
1730 Names starting with $ refer to registers (with the values they would have\n\
1731 if the program were to return to the stack frame now selected, restoring\n\
1732 all registers saved by frames farther in) or else to debugger\n\
1733 \"convenience\" variables (any such name not a known register).\n\
1734 Use assignment expressions to give values to convenience variables.\n",
1735 "\n\
1736 \{TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
1737 @ is a binary operator for treating consecutive data objects\n\
1738 anywhere in memory as an array. FOO@NUM gives an array whose first\n\
1739 element is FOO, whose second element is stored in the space following\n\
1740 where FOO is stored, etc. FOO must be an expression whose value\n\
1741 resides in memory.\n",
1742 "\n\
1743 EXP may be preceded with /FMT, where FMT is a format letter\n\
1744 but no count or size letter (see \"x\" command)."));
1745 add_com_alias ("p", "print", class_vars, 1);
1746 }
This page took 0.081925 seconds and 5 git commands to generate.