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