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