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