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