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