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 | { | |
b2ccb6a4 JK |
590 | #if 0 && defined (ADDR_BITS_REMOVE) |
591 | /* This is wrong for pointer to char, in which we do want to print | |
592 | the low bits. */ | |
8f869b45 SC |
593 | fprintf_filtered (stream, local_hex_format(), ADDR_BITS_REMOVE(addr)); |
594 | #else | |
c4668207 | 595 | fprintf_filtered (stream, local_hex_format(), addr); |
8f869b45 | 596 | #endif |
36b9d39c | 597 | print_address_symbolic (addr, stream, asm_demangle, " "); |
bd5635a1 RP |
598 | } |
599 | ||
600 | /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE | |
36b9d39c JG |
601 | controls whether to print the symbolic name "raw" or demangled. |
602 | Global setting "addressprint" controls whether to print hex address | |
603 | or not. */ | |
bd5635a1 RP |
604 | |
605 | void | |
606 | print_address_demangle (addr, stream, do_demangle) | |
607 | CORE_ADDR addr; | |
608 | FILE *stream; | |
609 | int do_demangle; | |
610 | { | |
36b9d39c JG |
611 | if (addr == 0) { |
612 | fprintf_filtered (stream, "0"); | |
613 | } else if (addressprint) { | |
c4668207 | 614 | fprintf_filtered (stream, local_hex_format(), addr); |
36b9d39c JG |
615 | print_address_symbolic (addr, stream, do_demangle, " "); |
616 | } else { | |
617 | print_address_symbolic (addr, stream, do_demangle, ""); | |
618 | } | |
bd5635a1 | 619 | } |
bd5635a1 RP |
620 | \f |
621 | ||
622 | /* Examine data at address ADDR in format FMT. | |
623 | Fetch it from memory and print on stdout. */ | |
624 | ||
625 | static void | |
626 | do_examine (fmt, addr) | |
627 | struct format_data fmt; | |
628 | CORE_ADDR addr; | |
629 | { | |
630 | register char format = 0; | |
631 | register char size; | |
632 | register int count = 1; | |
633 | struct type *val_type; | |
634 | register int i; | |
635 | register int maxelts; | |
636 | ||
637 | format = fmt.format; | |
638 | size = fmt.size; | |
639 | count = fmt.count; | |
640 | next_address = addr; | |
641 | ||
642 | /* String or instruction format implies fetch single bytes | |
643 | regardless of the specified size. */ | |
644 | if (format == 's' || format == 'i') | |
645 | size = 'b'; | |
646 | ||
647 | if (size == 'b') | |
648 | val_type = builtin_type_char; | |
649 | else if (size == 'h') | |
650 | val_type = builtin_type_short; | |
651 | else if (size == 'w') | |
652 | val_type = builtin_type_long; | |
653 | else if (size == 'g') | |
6fe90fc8 | 654 | #ifndef CC_HAS_LONG_LONG |
bd5635a1 RP |
655 | val_type = builtin_type_double; |
656 | #else | |
657 | val_type = builtin_type_long_long; | |
658 | #endif | |
659 | ||
660 | maxelts = 8; | |
661 | if (size == 'w') | |
662 | maxelts = 4; | |
663 | if (size == 'g') | |
664 | maxelts = 2; | |
665 | if (format == 's' || format == 'i') | |
666 | maxelts = 1; | |
667 | ||
668 | /* Print as many objects as specified in COUNT, at most maxelts per line, | |
669 | with the address of the next one at the start of each line. */ | |
670 | ||
671 | while (count > 0) | |
672 | { | |
673 | print_address (next_address, stdout); | |
674 | printf_filtered (":"); | |
675 | for (i = maxelts; | |
676 | i > 0 && count > 0; | |
677 | i--, count--) | |
678 | { | |
679 | printf_filtered ("\t"); | |
680 | /* Note that print_formatted sets next_address for the next | |
681 | object. */ | |
682 | last_examine_address = next_address; | |
683 | last_examine_value = value_at (val_type, next_address); | |
684 | print_formatted (last_examine_value, format, size); | |
685 | } | |
686 | printf_filtered ("\n"); | |
687 | fflush (stdout); | |
688 | } | |
689 | } | |
690 | \f | |
691 | static void | |
692 | validate_format (fmt, cmdname) | |
693 | struct format_data fmt; | |
694 | char *cmdname; | |
695 | { | |
696 | if (fmt.size != 0) | |
697 | error ("Size letters are meaningless in \"%s\" command.", cmdname); | |
698 | if (fmt.count != 1) | |
699 | error ("Item count other than 1 is meaningless in \"%s\" command.", | |
700 | cmdname); | |
701 | if (fmt.format == 'i' || fmt.format == 's') | |
702 | error ("Format letter \"%c\" is meaningless in \"%s\" command.", | |
703 | fmt.format, cmdname); | |
704 | } | |
705 | ||
7dc15bb7 JG |
706 | /* Evaluate string EXP as an expression in the current language and |
707 | print the resulting value. EXP may contain a format specifier as the | |
708 | first argument ("/x myvar" for example, to print myvar in hex). | |
709 | */ | |
710 | ||
bd5635a1 RP |
711 | static void |
712 | print_command_1 (exp, inspect, voidprint) | |
713 | char *exp; | |
714 | int inspect; | |
715 | int voidprint; | |
716 | { | |
717 | struct expression *expr; | |
718 | register struct cleanup *old_chain = 0; | |
719 | register char format = 0; | |
720 | register value val; | |
721 | struct format_data fmt; | |
722 | int cleanup = 0; | |
723 | ||
724 | /* Pass inspect flag to the rest of the print routines in a global (sigh). */ | |
725 | inspect_it = inspect; | |
726 | ||
727 | if (exp && *exp == '/') | |
728 | { | |
729 | exp++; | |
730 | fmt = decode_format (&exp, last_format, 0); | |
731 | validate_format (fmt, "print"); | |
732 | last_format = format = fmt.format; | |
733 | } | |
734 | else | |
735 | { | |
736 | fmt.count = 1; | |
737 | fmt.format = 0; | |
738 | fmt.size = 0; | |
739 | } | |
740 | ||
741 | if (exp && *exp) | |
742 | { | |
3577f9b4 JK |
743 | extern int objectprint; |
744 | struct type *type; | |
c4668207 | 745 | expr = parse_expression (exp); |
bd5635a1 RP |
746 | old_chain = make_cleanup (free_current_contents, &expr); |
747 | cleanup = 1; | |
748 | val = evaluate_expression (expr); | |
3577f9b4 JK |
749 | |
750 | /* C++: figure out what type we actually want to print it as. */ | |
751 | type = VALUE_TYPE (val); | |
752 | ||
753 | if (objectprint | |
93fe4e33 | 754 | && ( TYPE_CODE (type) == TYPE_CODE_PTR |
3577f9b4 | 755 | || TYPE_CODE (type) == TYPE_CODE_REF) |
93fe4e33 JG |
756 | && ( TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT |
757 | || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION)) | |
3577f9b4 JK |
758 | { |
759 | value v; | |
760 | ||
761 | v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type)); | |
762 | if (v != 0) | |
763 | { | |
764 | val = v; | |
765 | type = VALUE_TYPE (val); | |
766 | } | |
767 | } | |
bd5635a1 RP |
768 | } |
769 | else | |
770 | val = access_value_history (0); | |
771 | ||
772 | if (voidprint || (val && VALUE_TYPE (val) && | |
773 | TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID)) | |
774 | { | |
775 | int histindex = record_latest_value (val); | |
776 | ||
777 | if (inspect) | |
778 | printf ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex); | |
779 | else | |
780 | if (histindex >= 0) printf_filtered ("$%d = ", histindex); | |
781 | ||
782 | print_formatted (val, format, fmt.size); | |
783 | printf_filtered ("\n"); | |
784 | if (inspect) | |
785 | printf("\") )\030"); | |
786 | } | |
787 | ||
788 | if (cleanup) | |
789 | do_cleanups (old_chain); | |
790 | inspect_it = 0; /* Reset print routines to normal */ | |
791 | } | |
792 | ||
e1ce8aa5 | 793 | /* ARGSUSED */ |
bd5635a1 RP |
794 | static void |
795 | print_command (exp, from_tty) | |
796 | char *exp; | |
797 | int from_tty; | |
798 | { | |
799 | print_command_1 (exp, 0, 1); | |
800 | } | |
801 | ||
802 | /* Same as print, except in epoch, it gets its own window */ | |
e1ce8aa5 | 803 | /* ARGSUSED */ |
bd5635a1 RP |
804 | static void |
805 | inspect_command (exp, from_tty) | |
806 | char *exp; | |
807 | int from_tty; | |
808 | { | |
809 | extern int epoch_interface; | |
810 | ||
811 | print_command_1 (exp, epoch_interface, 1); | |
812 | } | |
813 | ||
814 | /* Same as print, except it doesn't print void results. */ | |
e1ce8aa5 | 815 | /* ARGSUSED */ |
bd5635a1 RP |
816 | static void |
817 | call_command (exp, from_tty) | |
818 | char *exp; | |
819 | int from_tty; | |
820 | { | |
821 | print_command_1 (exp, 0, 0); | |
822 | } | |
823 | ||
e1ce8aa5 | 824 | /* ARGSUSED */ |
bd5635a1 RP |
825 | static void |
826 | output_command (exp, from_tty) | |
827 | char *exp; | |
828 | int from_tty; | |
829 | { | |
830 | struct expression *expr; | |
831 | register struct cleanup *old_chain; | |
832 | register char format = 0; | |
833 | register value val; | |
834 | struct format_data fmt; | |
835 | ||
836 | if (exp && *exp == '/') | |
837 | { | |
838 | exp++; | |
839 | fmt = decode_format (&exp, 0, 0); | |
4d38b5a8 | 840 | validate_format (fmt, "output"); |
bd5635a1 RP |
841 | format = fmt.format; |
842 | } | |
843 | ||
c4668207 | 844 | expr = parse_expression (exp); |
bd5635a1 RP |
845 | old_chain = make_cleanup (free_current_contents, &expr); |
846 | ||
847 | val = evaluate_expression (expr); | |
848 | ||
849 | print_formatted (val, format, fmt.size); | |
850 | ||
851 | do_cleanups (old_chain); | |
852 | } | |
853 | ||
e1ce8aa5 | 854 | /* ARGSUSED */ |
bd5635a1 RP |
855 | static void |
856 | set_command (exp, from_tty) | |
857 | char *exp; | |
858 | int from_tty; | |
859 | { | |
c4668207 | 860 | struct expression *expr = parse_expression (exp); |
bd5635a1 RP |
861 | register struct cleanup *old_chain |
862 | = make_cleanup (free_current_contents, &expr); | |
863 | evaluate_expression (expr); | |
864 | do_cleanups (old_chain); | |
865 | } | |
866 | ||
e1ce8aa5 | 867 | /* ARGSUSED */ |
bd5635a1 RP |
868 | static void |
869 | address_info (exp, from_tty) | |
870 | char *exp; | |
871 | int from_tty; | |
872 | { | |
873 | register struct symbol *sym; | |
93fe4e33 | 874 | register struct minimal_symbol *msymbol; |
e1ce8aa5 | 875 | register long val; |
4d38b5a8 | 876 | register long basereg; |
bd5635a1 RP |
877 | int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero |
878 | if exp is a field of `this'. */ | |
879 | ||
880 | if (exp == 0) | |
881 | error ("Argument required."); | |
882 | ||
883 | sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE, | |
884 | &is_a_field_of_this, (struct symtab **)NULL); | |
2e4964ad | 885 | if (sym == NULL) |
bd5635a1 | 886 | { |
bd5635a1 RP |
887 | if (is_a_field_of_this) |
888 | { | |
889 | printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp); | |
890 | return; | |
891 | } | |
892 | ||
93fe4e33 | 893 | msymbol = lookup_minimal_symbol (exp, (struct objfile *) NULL); |
bd5635a1 | 894 | |
93fe4e33 | 895 | if (msymbol != NULL) |
c4668207 | 896 | printf ("Symbol \"%s\" is at %s in a file compiled without debugging.\n", |
2e4964ad | 897 | exp, local_hex_string(SYMBOL_VALUE_ADDRESS (msymbol))); |
bd5635a1 RP |
898 | else |
899 | error ("No symbol \"%s\" in current context.", exp); | |
900 | return; | |
901 | } | |
902 | ||
903 | printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym)); | |
904 | val = SYMBOL_VALUE (sym); | |
4d38b5a8 | 905 | basereg = SYMBOL_BASEREG (sym); |
bd5635a1 RP |
906 | |
907 | switch (SYMBOL_CLASS (sym)) | |
908 | { | |
909 | case LOC_CONST: | |
910 | case LOC_CONST_BYTES: | |
911 | printf ("constant"); | |
912 | break; | |
913 | ||
914 | case LOC_LABEL: | |
c4668207 | 915 | printf ("a label at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym))); |
bd5635a1 RP |
916 | break; |
917 | ||
918 | case LOC_REGISTER: | |
919 | printf ("a variable in register %s", reg_names[val]); | |
920 | break; | |
921 | ||
922 | case LOC_STATIC: | |
c4668207 | 923 | printf ("static storage at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym))); |
bd5635a1 RP |
924 | break; |
925 | ||
926 | case LOC_REGPARM: | |
927 | printf ("an argument in register %s", reg_names[val]); | |
928 | break; | |
5afa2040 JK |
929 | |
930 | case LOC_REGPARM_ADDR: | |
931 | printf ("address of an argument in register %s", reg_names[val]); | |
932 | break; | |
bd5635a1 RP |
933 | |
934 | case LOC_ARG: | |
4d38b5a8 JG |
935 | if (SYMBOL_BASEREG_VALID (sym)) |
936 | { | |
937 | printf ("an argument at offset %ld from register %s", | |
938 | val, reg_names[basereg]); | |
939 | } | |
940 | else | |
941 | { | |
942 | printf ("an argument at offset %ld", val); | |
943 | } | |
bd5635a1 RP |
944 | break; |
945 | ||
946 | case LOC_LOCAL_ARG: | |
4d38b5a8 JG |
947 | if (SYMBOL_BASEREG_VALID (sym)) |
948 | { | |
949 | printf ("an argument at offset %ld from register %s", | |
950 | val, reg_names[basereg]); | |
951 | } | |
952 | else | |
953 | { | |
954 | printf ("an argument at frame offset %ld", val); | |
955 | } | |
bd5635a1 RP |
956 | break; |
957 | ||
958 | case LOC_LOCAL: | |
4d38b5a8 JG |
959 | if (SYMBOL_BASEREG_VALID (sym)) |
960 | { | |
961 | printf ("a local variable at offset %ld from register %s", | |
962 | val, reg_names[basereg]); | |
963 | } | |
964 | else | |
965 | { | |
966 | printf ("a local variable at frame offset %ld", val); | |
967 | } | |
bd5635a1 RP |
968 | break; |
969 | ||
970 | case LOC_REF_ARG: | |
e1ce8aa5 | 971 | printf ("a reference argument at offset %ld", val); |
bd5635a1 RP |
972 | break; |
973 | ||
974 | case LOC_TYPEDEF: | |
975 | printf ("a typedef"); | |
976 | break; | |
977 | ||
978 | case LOC_BLOCK: | |
c4668207 JG |
979 | printf ("a function at address %s", |
980 | local_hex_string(BLOCK_START (SYMBOL_BLOCK_VALUE (sym)))); | |
bd5635a1 RP |
981 | break; |
982 | ||
31258e4f JK |
983 | case LOC_OPTIMIZED_OUT: |
984 | printf_filtered ("optimized out"); | |
985 | break; | |
986 | ||
bd5635a1 RP |
987 | default: |
988 | printf ("of unknown (botched) type"); | |
989 | break; | |
990 | } | |
991 | printf (".\n"); | |
992 | } | |
993 | \f | |
994 | static void | |
995 | x_command (exp, from_tty) | |
996 | char *exp; | |
997 | int from_tty; | |
998 | { | |
999 | struct expression *expr; | |
1000 | struct format_data fmt; | |
1001 | struct cleanup *old_chain; | |
1002 | struct value *val; | |
1003 | ||
1004 | fmt.format = last_format; | |
1005 | fmt.size = last_size; | |
1006 | fmt.count = 1; | |
1007 | ||
1008 | if (exp && *exp == '/') | |
1009 | { | |
1010 | exp++; | |
1011 | fmt = decode_format (&exp, last_format, last_size); | |
bd5635a1 RP |
1012 | } |
1013 | ||
1014 | /* If we have an expression, evaluate it and use it as the address. */ | |
1015 | ||
1016 | if (exp != 0 && *exp != 0) | |
1017 | { | |
c4668207 | 1018 | expr = parse_expression (exp); |
bd5635a1 RP |
1019 | /* Cause expression not to be there any more |
1020 | if this command is repeated with Newline. | |
1021 | But don't clobber a user-defined command's definition. */ | |
1022 | if (from_tty) | |
1023 | *exp = 0; | |
1024 | old_chain = make_cleanup (free_current_contents, &expr); | |
1025 | val = evaluate_expression (expr); | |
3577f9b4 JK |
1026 | if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF) |
1027 | val = value_ind (val); | |
bd5635a1 RP |
1028 | /* In rvalue contexts, such as this, functions are coerced into |
1029 | pointers to functions. This makes "x/i main" work. */ | |
1030 | if (/* last_format == 'i' | |
1031 | && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC | |
1032 | && VALUE_LVAL (val) == lval_memory) | |
1033 | next_address = VALUE_ADDRESS (val); | |
1034 | else | |
e1ce8aa5 | 1035 | next_address = value_as_pointer (val); |
bd5635a1 RP |
1036 | do_cleanups (old_chain); |
1037 | } | |
1038 | ||
1039 | do_examine (fmt, next_address); | |
1040 | ||
4d38b5a8 JG |
1041 | /* If the examine succeeds, we remember its size and format for next time. */ |
1042 | last_size = fmt.size; | |
1043 | last_format = fmt.format; | |
1044 | ||
bd5635a1 RP |
1045 | /* Set a couple of internal variables if appropriate. */ |
1046 | if (last_examine_value) | |
1047 | { | |
c4668207 JG |
1048 | /* Make last address examined available to the user as $_. Use |
1049 | the correct pointer type. */ | |
bd5635a1 | 1050 | set_internalvar (lookup_internalvar ("_"), |
c4668207 JG |
1051 | value_from_longest ( |
1052 | lookup_pointer_type (VALUE_TYPE (last_examine_value)), | |
1053 | (LONGEST) last_examine_address)); | |
bd5635a1 RP |
1054 | |
1055 | /* Make contents of last address examined available to the user as $__.*/ | |
1056 | set_internalvar (lookup_internalvar ("__"), last_examine_value); | |
1057 | } | |
1058 | } | |
bd5635a1 | 1059 | |
bd5635a1 | 1060 | \f |
bd5635a1 RP |
1061 | /* Add an expression to the auto-display chain. |
1062 | Specify the expression. */ | |
1063 | ||
1064 | static void | |
1065 | display_command (exp, from_tty) | |
1066 | char *exp; | |
1067 | int from_tty; | |
1068 | { | |
1069 | struct format_data fmt; | |
1070 | register struct expression *expr; | |
1071 | register struct display *new; | |
1072 | ||
1073 | if (exp == 0) | |
1074 | { | |
1075 | do_displays (); | |
1076 | return; | |
1077 | } | |
1078 | ||
1079 | if (*exp == '/') | |
1080 | { | |
1081 | exp++; | |
1082 | fmt = decode_format (&exp, 0, 0); | |
1083 | if (fmt.size && fmt.format == 0) | |
1084 | fmt.format = 'x'; | |
1085 | if (fmt.format == 'i' || fmt.format == 's') | |
1086 | fmt.size = 'b'; | |
1087 | } | |
1088 | else | |
1089 | { | |
1090 | fmt.format = 0; | |
1091 | fmt.size = 0; | |
1092 | fmt.count = 0; | |
1093 | } | |
1094 | ||
1095 | innermost_block = 0; | |
c4668207 | 1096 | expr = parse_expression (exp); |
bd5635a1 RP |
1097 | |
1098 | new = (struct display *) xmalloc (sizeof (struct display)); | |
1099 | ||
1100 | new->exp = expr; | |
1101 | new->block = innermost_block; | |
1102 | new->next = display_chain; | |
1103 | new->number = ++display_number; | |
1104 | new->format = fmt; | |
1105 | new->status = enabled; | |
1106 | display_chain = new; | |
1107 | ||
1108 | if (from_tty && target_has_execution) | |
1109 | do_one_display (new); | |
1110 | ||
1111 | dont_repeat (); | |
1112 | } | |
1113 | ||
1114 | static void | |
1115 | free_display (d) | |
1116 | struct display *d; | |
1117 | { | |
4d38b5a8 JG |
1118 | free ((PTR)d->exp); |
1119 | free ((PTR)d); | |
bd5635a1 RP |
1120 | } |
1121 | ||
1122 | /* Clear out the display_chain. | |
1123 | Done when new symtabs are loaded, since this invalidates | |
1124 | the types stored in many expressions. */ | |
1125 | ||
1126 | void | |
1127 | clear_displays () | |
1128 | { | |
1129 | register struct display *d; | |
1130 | ||
a8a69e63 | 1131 | while ((d = display_chain) != NULL) |
bd5635a1 | 1132 | { |
4d38b5a8 | 1133 | free ((PTR)d->exp); |
bd5635a1 | 1134 | display_chain = d->next; |
4d38b5a8 | 1135 | free ((PTR)d); |
bd5635a1 RP |
1136 | } |
1137 | } | |
1138 | ||
1139 | /* Delete the auto-display number NUM. */ | |
1140 | ||
93fe4e33 | 1141 | static void |
bd5635a1 RP |
1142 | delete_display (num) |
1143 | int num; | |
1144 | { | |
1145 | register struct display *d1, *d; | |
1146 | ||
1147 | if (!display_chain) | |
1148 | error ("No display number %d.", num); | |
1149 | ||
1150 | if (display_chain->number == num) | |
1151 | { | |
1152 | d1 = display_chain; | |
1153 | display_chain = d1->next; | |
1154 | free_display (d1); | |
1155 | } | |
1156 | else | |
1157 | for (d = display_chain; ; d = d->next) | |
1158 | { | |
1159 | if (d->next == 0) | |
1160 | error ("No display number %d.", num); | |
1161 | if (d->next->number == num) | |
1162 | { | |
1163 | d1 = d->next; | |
1164 | d->next = d1->next; | |
1165 | free_display (d1); | |
1166 | break; | |
1167 | } | |
1168 | } | |
1169 | } | |
1170 | ||
1171 | /* Delete some values from the auto-display chain. | |
1172 | Specify the element numbers. */ | |
1173 | ||
1174 | static void | |
4d38b5a8 | 1175 | undisplay_command (args, from_tty) |
bd5635a1 | 1176 | char *args; |
4d38b5a8 | 1177 | int from_tty; |
bd5635a1 RP |
1178 | { |
1179 | register char *p = args; | |
1180 | register char *p1; | |
1181 | register int num; | |
1182 | ||
1183 | if (args == 0) | |
1184 | { | |
1185 | if (query ("Delete all auto-display expressions? ")) | |
1186 | clear_displays (); | |
1187 | dont_repeat (); | |
1188 | return; | |
1189 | } | |
1190 | ||
1191 | while (*p) | |
1192 | { | |
1193 | p1 = p; | |
1194 | while (*p1 >= '0' && *p1 <= '9') p1++; | |
1195 | if (*p1 && *p1 != ' ' && *p1 != '\t') | |
1196 | error ("Arguments must be display numbers."); | |
1197 | ||
1198 | num = atoi (p); | |
1199 | ||
1200 | delete_display (num); | |
1201 | ||
1202 | p = p1; | |
1203 | while (*p == ' ' || *p == '\t') p++; | |
1204 | } | |
1205 | dont_repeat (); | |
1206 | } | |
1207 | ||
1208 | /* Display a single auto-display. | |
1209 | Do nothing if the display cannot be printed in the current context, | |
1210 | or if the display is disabled. */ | |
1211 | ||
1212 | static void | |
1213 | do_one_display (d) | |
1214 | struct display *d; | |
1215 | { | |
1216 | int within_current_scope; | |
1217 | ||
1218 | if (d->status == disabled) | |
1219 | return; | |
1220 | ||
1221 | if (d->block) | |
1222 | within_current_scope = contained_in (get_selected_block (), d->block); | |
1223 | else | |
1224 | within_current_scope = 1; | |
1225 | if (!within_current_scope) | |
1226 | return; | |
1227 | ||
1228 | current_display_number = d->number; | |
1229 | ||
1230 | printf_filtered ("%d: ", d->number); | |
1231 | if (d->format.size) | |
1232 | { | |
1233 | CORE_ADDR addr; | |
1234 | ||
1235 | printf_filtered ("x/"); | |
1236 | if (d->format.count != 1) | |
1237 | printf_filtered ("%d", d->format.count); | |
1238 | printf_filtered ("%c", d->format.format); | |
1239 | if (d->format.format != 'i' && d->format.format != 's') | |
1240 | printf_filtered ("%c", d->format.size); | |
1241 | printf_filtered (" "); | |
1242 | print_expression (d->exp, stdout); | |
1243 | if (d->format.count != 1) | |
1244 | printf_filtered ("\n"); | |
1245 | else | |
1246 | printf_filtered (" "); | |
1247 | ||
e1ce8aa5 | 1248 | addr = value_as_pointer (evaluate_expression (d->exp)); |
bd5635a1 RP |
1249 | if (d->format.format == 'i') |
1250 | addr = ADDR_BITS_REMOVE (addr); | |
1251 | ||
1252 | do_examine (d->format, addr); | |
1253 | } | |
1254 | else | |
1255 | { | |
1256 | if (d->format.format) | |
1257 | printf_filtered ("/%c ", d->format.format); | |
1258 | print_expression (d->exp, stdout); | |
1259 | printf_filtered (" = "); | |
1260 | print_formatted (evaluate_expression (d->exp), | |
1261 | d->format.format, d->format.size); | |
1262 | printf_filtered ("\n"); | |
1263 | } | |
1264 | ||
1265 | fflush (stdout); | |
1266 | current_display_number = -1; | |
1267 | } | |
1268 | ||
1269 | /* Display all of the values on the auto-display chain which can be | |
1270 | evaluated in the current scope. */ | |
1271 | ||
1272 | void | |
1273 | do_displays () | |
1274 | { | |
1275 | register struct display *d; | |
1276 | ||
1277 | for (d = display_chain; d; d = d->next) | |
1278 | do_one_display (d); | |
1279 | } | |
1280 | ||
1281 | /* Delete the auto-display which we were in the process of displaying. | |
1282 | This is done when there is an error or a signal. */ | |
1283 | ||
1284 | void | |
1285 | disable_display (num) | |
1286 | int num; | |
1287 | { | |
1288 | register struct display *d; | |
1289 | ||
1290 | for (d = display_chain; d; d = d->next) | |
1291 | if (d->number == num) | |
1292 | { | |
1293 | d->status = disabled; | |
1294 | return; | |
1295 | } | |
1296 | printf ("No display number %d.\n", num); | |
1297 | } | |
1298 | ||
1299 | void | |
1300 | disable_current_display () | |
1301 | { | |
1302 | if (current_display_number >= 0) | |
1303 | { | |
1304 | disable_display (current_display_number); | |
1305 | fprintf (stderr, "Disabling display %d to avoid infinite recursion.\n", | |
1306 | current_display_number); | |
1307 | } | |
1308 | current_display_number = -1; | |
1309 | } | |
1310 | ||
1311 | static void | |
4d38b5a8 JG |
1312 | display_info (ignore, from_tty) |
1313 | char *ignore; | |
1314 | int from_tty; | |
bd5635a1 RP |
1315 | { |
1316 | register struct display *d; | |
1317 | ||
1318 | if (!display_chain) | |
1319 | printf ("There are no auto-display expressions now.\n"); | |
1320 | else | |
1321 | printf_filtered ("Auto-display expressions now in effect:\n\ | |
1322 | Num Enb Expression\n"); | |
1323 | ||
1324 | for (d = display_chain; d; d = d->next) | |
1325 | { | |
1326 | printf_filtered ("%d: %c ", d->number, "ny"[(int)d->status]); | |
1327 | if (d->format.size) | |
1328 | printf_filtered ("/%d%c%c ", d->format.count, d->format.size, | |
1329 | d->format.format); | |
1330 | else if (d->format.format) | |
1331 | printf_filtered ("/%c ", d->format.format); | |
1332 | print_expression (d->exp, stdout); | |
1333 | if (d->block && !contained_in (get_selected_block (), d->block)) | |
1334 | printf_filtered (" (cannot be evaluated in the current context)"); | |
1335 | printf_filtered ("\n"); | |
1336 | fflush (stdout); | |
1337 | } | |
1338 | } | |
1339 | ||
93fe4e33 | 1340 | static void |
4d38b5a8 | 1341 | enable_display (args, from_tty) |
bd5635a1 | 1342 | char *args; |
4d38b5a8 | 1343 | int from_tty; |
bd5635a1 RP |
1344 | { |
1345 | register char *p = args; | |
1346 | register char *p1; | |
1347 | register int num; | |
1348 | register struct display *d; | |
1349 | ||
1350 | if (p == 0) | |
1351 | { | |
1352 | for (d = display_chain; d; d = d->next) | |
1353 | d->status = enabled; | |
1354 | } | |
1355 | else | |
1356 | while (*p) | |
1357 | { | |
1358 | p1 = p; | |
1359 | while (*p1 >= '0' && *p1 <= '9') | |
1360 | p1++; | |
1361 | if (*p1 && *p1 != ' ' && *p1 != '\t') | |
1362 | error ("Arguments must be display numbers."); | |
1363 | ||
1364 | num = atoi (p); | |
1365 | ||
1366 | for (d = display_chain; d; d = d->next) | |
1367 | if (d->number == num) | |
1368 | { | |
1369 | d->status = enabled; | |
1370 | goto win; | |
1371 | } | |
1372 | printf ("No display number %d.\n", num); | |
1373 | win: | |
1374 | p = p1; | |
1375 | while (*p == ' ' || *p == '\t') | |
1376 | p++; | |
1377 | } | |
1378 | } | |
1379 | ||
e1ce8aa5 | 1380 | /* ARGSUSED */ |
93fe4e33 | 1381 | static void |
bd5635a1 RP |
1382 | disable_display_command (args, from_tty) |
1383 | char *args; | |
1384 | int from_tty; | |
1385 | { | |
1386 | register char *p = args; | |
1387 | register char *p1; | |
1388 | register struct display *d; | |
1389 | ||
1390 | if (p == 0) | |
1391 | { | |
1392 | for (d = display_chain; d; d = d->next) | |
1393 | d->status = disabled; | |
1394 | } | |
1395 | else | |
1396 | while (*p) | |
1397 | { | |
1398 | p1 = p; | |
1399 | while (*p1 >= '0' && *p1 <= '9') | |
1400 | p1++; | |
1401 | if (*p1 && *p1 != ' ' && *p1 != '\t') | |
1402 | error ("Arguments must be display numbers."); | |
1403 | ||
1404 | disable_display (atoi (p)); | |
1405 | ||
1406 | p = p1; | |
1407 | while (*p == ' ' || *p == '\t') | |
1408 | p++; | |
1409 | } | |
1410 | } | |
1411 | ||
1412 | \f | |
1413 | /* Print the value in stack frame FRAME of a variable | |
1414 | specified by a struct symbol. */ | |
1415 | ||
1416 | void | |
1417 | print_variable_value (var, frame, stream) | |
1418 | struct symbol *var; | |
1419 | FRAME frame; | |
1420 | FILE *stream; | |
1421 | { | |
1422 | value val = read_var_value (var, frame); | |
1423 | value_print (val, stream, 0, Val_pretty_default); | |
1424 | } | |
1425 | ||
1426 | /* Print the arguments of a stack frame, given the function FUNC | |
1427 | running in that frame (as a symbol), the info on the frame, | |
1428 | and the number of args according to the stack frame (or -1 if unknown). */ | |
1429 | ||
1430 | /* References here and elsewhere to "number of args according to the | |
1431 | stack frame" appear in all cases to refer to "number of ints of args | |
1432 | according to the stack frame". At least for VAX, i386, isi. */ | |
1433 | ||
1434 | void | |
1435 | print_frame_args (func, fi, num, stream) | |
1436 | struct symbol *func; | |
1437 | struct frame_info *fi; | |
1438 | int num; | |
1439 | FILE *stream; | |
1440 | { | |
1441 | struct block *b; | |
1442 | int nsyms = 0; | |
1443 | int first = 1; | |
1444 | register int i; | |
1445 | register struct symbol *sym; | |
1446 | register value val; | |
1447 | /* Offset of next stack argument beyond the one we have seen that is | |
1448 | at the highest offset. | |
1449 | -1 if we haven't come to a stack argument yet. */ | |
e1ce8aa5 | 1450 | long highest_offset = -1; |
bd5635a1 RP |
1451 | int arg_size; |
1452 | /* Number of ints of arguments that we have printed so far. */ | |
1453 | int args_printed = 0; | |
1454 | ||
1455 | if (func) | |
1456 | { | |
1457 | b = SYMBOL_BLOCK_VALUE (func); | |
1458 | nsyms = BLOCK_NSYMS (b); | |
1459 | } | |
1460 | ||
1461 | for (i = 0; i < nsyms; i++) | |
1462 | { | |
1463 | QUIT; | |
1464 | sym = BLOCK_SYM (b, i); | |
1465 | ||
c4668207 JG |
1466 | /* Keep track of the highest stack argument offset seen, and |
1467 | skip over any kinds of symbols we don't care about. */ | |
bd5635a1 RP |
1468 | |
1469 | switch (SYMBOL_CLASS (sym)) { | |
bd5635a1 RP |
1470 | case LOC_ARG: |
1471 | case LOC_REF_ARG: | |
1472 | { | |
e1ce8aa5 | 1473 | long current_offset = SYMBOL_VALUE (sym); |
bd5635a1 RP |
1474 | |
1475 | arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym)); | |
1476 | ||
1477 | /* Compute address of next argument by adding the size of | |
1478 | this argument and rounding to an int boundary. */ | |
1479 | current_offset | |
1480 | = ((current_offset + arg_size + sizeof (int) - 1) | |
1481 | & ~(sizeof (int) - 1)); | |
1482 | ||
1483 | /* If this is the highest offset seen yet, set highest_offset. */ | |
1484 | if (highest_offset == -1 | |
1485 | || (current_offset > highest_offset)) | |
1486 | highest_offset = current_offset; | |
1487 | ||
1488 | /* Add the number of ints we're about to print to args_printed. */ | |
1489 | args_printed += (arg_size + sizeof (int) - 1) / sizeof (int); | |
1490 | } | |
1491 | ||
c4668207 JG |
1492 | /* We care about types of symbols, but don't need to keep track of |
1493 | stack offsets in them. */ | |
1494 | case LOC_REGPARM: | |
5afa2040 | 1495 | case LOC_REGPARM_ADDR: |
c4668207 | 1496 | case LOC_LOCAL_ARG: |
bd5635a1 | 1497 | break; |
c4668207 JG |
1498 | |
1499 | /* Other types of symbols we just skip over. */ | |
1500 | default: | |
1501 | continue; | |
bd5635a1 RP |
1502 | } |
1503 | ||
31258e4f JK |
1504 | /* We have to look up the symbol because arguments can have |
1505 | two entries (one a parameter, one a local) and the one we | |
1506 | want is the local, which lookup_symbol will find for us. | |
1507 | This includes gcc1 (not gcc2) on the sparc when passing a | |
1508 | small structure and gcc2 when the argument type is float | |
1509 | and it is passed as a double and converted to float by | |
1510 | the prologue (in the latter case the type of the LOC_ARG | |
1511 | symbol is double and the type of the LOC_LOCAL symbol is | |
6fe90fc8 JK |
1512 | float). There are also LOC_ARG/LOC_REGISTER pairs which |
1513 | are not combined in symbol-reading. */ | |
31258e4f | 1514 | /* But if the parameter name is null, don't try it. |
a8a69e63 FF |
1515 | Null parameter names occur on the RS/6000, for traceback tables. |
1516 | FIXME, should we even print them? */ | |
1517 | ||
1518 | if (*SYMBOL_NAME (sym)) | |
31258e4f JK |
1519 | sym = lookup_symbol |
1520 | (SYMBOL_NAME (sym), | |
1521 | b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL); | |
c4668207 | 1522 | |
bd5635a1 RP |
1523 | /* Print the current arg. */ |
1524 | if (! first) | |
1525 | fprintf_filtered (stream, ", "); | |
1526 | wrap_here (" "); | |
31258e4f JK |
1527 | fprintf_symbol_filtered (stream, SYMBOL_SOURCE_NAME (sym), |
1528 | SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI); | |
bd5635a1 RP |
1529 | fputs_filtered ("=", stream); |
1530 | ||
1531 | /* Avoid value_print because it will deref ref parameters. We just | |
1532 | want to print their addresses. Print ??? for args whose address | |
d11c44f1 JG |
1533 | we do not know. We pass 2 as "recurse" to val_print because our |
1534 | standard indentation here is 4 spaces, and val_print indents | |
1535 | 2 for each recurse. */ | |
bd5635a1 RP |
1536 | val = read_var_value (sym, FRAME_INFO_ID (fi)); |
1537 | if (val) | |
1538 | val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val), | |
d11c44f1 | 1539 | stream, 0, 0, 2, Val_no_prettyprint); |
bd5635a1 RP |
1540 | else |
1541 | fputs_filtered ("???", stream); | |
1542 | first = 0; | |
1543 | } | |
1544 | ||
1545 | /* Don't print nameless args in situations where we don't know | |
1546 | enough about the stack to find them. */ | |
1547 | if (num != -1) | |
1548 | { | |
e1ce8aa5 | 1549 | long start; |
bd5635a1 RP |
1550 | |
1551 | if (highest_offset == -1) | |
1552 | start = FRAME_ARGS_SKIP; | |
1553 | else | |
1554 | start = highest_offset; | |
1555 | ||
7dc15bb7 JG |
1556 | print_frame_nameless_args (fi, start, num - args_printed, |
1557 | first, stream); | |
bd5635a1 RP |
1558 | } |
1559 | } | |
1560 | ||
1561 | /* Print nameless args on STREAM. | |
7dc15bb7 | 1562 | FI is the frameinfo for this frame, START is the offset |
bd5635a1 RP |
1563 | of the first nameless arg, and NUM is the number of nameless args to |
1564 | print. FIRST is nonzero if this is the first argument (not just | |
1565 | the first nameless arg). */ | |
1566 | static void | |
7dc15bb7 JG |
1567 | print_frame_nameless_args (fi, start, num, first, stream) |
1568 | struct frame_info *fi; | |
e1ce8aa5 | 1569 | long start; |
bd5635a1 RP |
1570 | int num; |
1571 | int first; | |
1572 | FILE *stream; | |
1573 | { | |
1574 | int i; | |
7dc15bb7 JG |
1575 | CORE_ADDR argsaddr; |
1576 | long arg_value; | |
1577 | ||
bd5635a1 RP |
1578 | for (i = 0; i < num; i++) |
1579 | { | |
1580 | QUIT; | |
7dc15bb7 JG |
1581 | #ifdef NAMELESS_ARG_VALUE |
1582 | NAMELESS_ARG_VALUE (fi, start, &arg_value); | |
1583 | #else | |
1584 | argsaddr = FRAME_ARGS_ADDRESS (fi); | |
1585 | if (!argsaddr) | |
1586 | return; | |
1587 | ||
1588 | arg_value = read_memory_integer (argsaddr + start, sizeof (int)); | |
1589 | #endif | |
1590 | ||
bd5635a1 RP |
1591 | if (!first) |
1592 | fprintf_filtered (stream, ", "); | |
7dc15bb7 JG |
1593 | |
1594 | #ifdef PRINT_NAMELESS_INTEGER | |
1595 | PRINT_NAMELESS_INTEGER (stream, arg_value); | |
bd5635a1 | 1596 | #else |
7dc15bb7 JG |
1597 | #ifdef PRINT_TYPELESS_INTEGER |
1598 | PRINT_TYPELESS_INTEGER (stream, builtin_type_int, (LONGEST) arg_value); | |
1599 | #else | |
1600 | fprintf_filtered (stream, "%d", arg_value); | |
1601 | #endif /* PRINT_TYPELESS_INTEGER */ | |
1602 | #endif /* PRINT_NAMELESS_INTEGER */ | |
bd5635a1 RP |
1603 | first = 0; |
1604 | start += sizeof (int); | |
1605 | } | |
1606 | } | |
1607 | \f | |
19bdd57f JK |
1608 | /* Make makeva* work on an __INT_VARARGS_H machine. */ |
1609 | ||
1610 | #if defined (__INT_VARARGS_H) | |
1611 | /* This is used on an 88k. Not sure whether it is used by anything else. */ | |
1612 | #define MAKEVA_END(list) \ | |
1613 | va_list retval; \ | |
1614 | retval.__va_arg = 0; \ | |
8af0de91 JK |
1615 | retval.__va_stk = (int *) (list)->aligner.arg_bytes; \ |
1616 | retval.__va_reg = (int *) (list)->aligner.arg_bytes; \ | |
19bdd57f JK |
1617 | return retval; |
1618 | #endif | |
1619 | \f | |
1620 | /* This is an interface which allows to us make a va_list. */ | |
1621 | typedef struct { | |
1622 | unsigned int nargs; | |
1623 | unsigned int max_arg_size; | |
1624 | ||
1625 | /* Current position in bytes. */ | |
1626 | unsigned int argindex; | |
1627 | ||
1ab786f4 JK |
1628 | #ifdef MAKEVA_EXTRA_INFO |
1629 | /* For host dependent information. */ | |
1630 | MAKEVA_EXTRA_INFO | |
1631 | #endif | |
1632 | ||
b2ccb6a4 JK |
1633 | /* Some systems (mips, pa) would like this to be aligned, and it never |
1634 | will hurt. */ | |
1635 | union | |
1636 | { | |
1637 | char arg_bytes[1]; | |
1638 | double force_double_align; | |
1639 | LONGEST force_long_align; | |
1640 | } aligner; | |
19bdd57f JK |
1641 | } makeva_list; |
1642 | ||
1643 | /* Tell the caller how many bytes to allocate for a makeva_list with NARGS | |
1644 | arguments and whose largest argument is MAX_ARG_SIZE bytes. This | |
1645 | way the caller can use alloca, malloc, or some other allocator. */ | |
1646 | unsigned int | |
1647 | makeva_size (nargs, max_arg_size) | |
1648 | unsigned int nargs; | |
1649 | unsigned int max_arg_size; | |
1650 | { | |
b2ccb6a4 | 1651 | return sizeof (makeva_list) + nargs * max_arg_size; |
19bdd57f JK |
1652 | } |
1653 | ||
1654 | /* Start working on LIST with NARGS arguments and whose largest | |
1655 | argument is MAX_ARG_SIZE bytes. */ | |
1656 | void | |
1657 | makeva_start (list, nargs, max_arg_size) | |
1658 | makeva_list *list; | |
1659 | unsigned int nargs; | |
1660 | unsigned int max_arg_size; | |
1661 | { | |
1662 | list->nargs = nargs; | |
1663 | list->max_arg_size = max_arg_size; | |
1664 | #if defined (MAKEVA_START) | |
1665 | MAKEVA_START (list); | |
1666 | #else | |
1667 | list->argindex = 0; | |
1668 | #endif | |
1669 | } | |
1670 | ||
1671 | /* Add ARG to LIST. */ | |
1672 | void | |
1673 | makeva_arg (list, argaddr, argsize) | |
1674 | makeva_list *list; | |
1675 | PTR argaddr; | |
1676 | unsigned int argsize; | |
1677 | { | |
1678 | #if defined (MAKEVA_ARG) | |
1679 | MAKEVA_ARG (list, argaddr, argsize); | |
1680 | #else | |
b2ccb6a4 | 1681 | memcpy (&list->aligner.arg_bytes[list->argindex], argaddr, argsize); |
19bdd57f JK |
1682 | list->argindex += argsize; |
1683 | #endif | |
1684 | } | |
1685 | ||
1686 | /* From LIST, for which makeva_arg has been called for each arg, | |
1687 | return a va_list containing the args. */ | |
1688 | va_list | |
1689 | makeva_end (list) | |
1690 | makeva_list *list; | |
1691 | { | |
1692 | #if defined (MAKEVA_END) | |
1693 | MAKEVA_END (list); | |
1694 | #else | |
1695 | /* This works if a va_list is just a pointer to the arguments. */ | |
b2ccb6a4 | 1696 | return (va_list) list->aligner.arg_bytes; |
19bdd57f JK |
1697 | #endif |
1698 | } | |
1699 | \f | |
e1ce8aa5 | 1700 | /* ARGSUSED */ |
bd5635a1 RP |
1701 | static void |
1702 | printf_command (arg, from_tty) | |
1703 | char *arg; | |
1704 | int from_tty; | |
1705 | { | |
1706 | register char *f; | |
1707 | register char *s = arg; | |
1708 | char *string; | |
1709 | value *val_args; | |
1710 | int nargs = 0; | |
1711 | int allocated_args = 20; | |
19bdd57f | 1712 | va_list args_to_vprintf; |
bd5635a1 RP |
1713 | |
1714 | val_args = (value *) xmalloc (allocated_args * sizeof (value)); | |
1715 | ||
1716 | if (s == 0) | |
1717 | error_no_arg ("format-control string and values to print"); | |
1718 | ||
1719 | /* Skip white space before format string */ | |
1720 | while (*s == ' ' || *s == '\t') s++; | |
1721 | ||
1722 | /* A format string should follow, enveloped in double quotes */ | |
1723 | if (*s++ != '"') | |
1724 | error ("Bad format string, missing '\"'."); | |
1725 | ||
1726 | /* Parse the format-control string and copy it into the string STRING, | |
1727 | processing some kinds of escape sequence. */ | |
1728 | ||
1729 | f = string = (char *) alloca (strlen (s) + 1); | |
1730 | while (*s != '"') | |
1731 | { | |
1732 | int c = *s++; | |
1733 | switch (c) | |
1734 | { | |
1735 | case '\0': | |
1736 | error ("Bad format string, non-terminated '\"'."); | |
1737 | /* doesn't return */ | |
1738 | ||
1739 | case '\\': | |
1740 | switch (c = *s++) | |
1741 | { | |
1742 | case '\\': | |
1743 | *f++ = '\\'; | |
1744 | break; | |
1745 | case 'n': | |
1746 | *f++ = '\n'; | |
1747 | break; | |
1748 | case 't': | |
1749 | *f++ = '\t'; | |
1750 | break; | |
1751 | case 'r': | |
1752 | *f++ = '\r'; | |
1753 | break; | |
1754 | case '"': | |
1755 | *f++ = '"'; | |
1756 | break; | |
1757 | default: | |
1758 | /* ??? TODO: handle other escape sequences */ | |
1759 | error ("Unrecognized \\ escape character in format string."); | |
1760 | } | |
1761 | break; | |
1762 | ||
1763 | default: | |
1764 | *f++ = c; | |
1765 | } | |
1766 | } | |
1767 | ||
1768 | /* Skip over " and following space and comma. */ | |
1769 | s++; | |
1770 | *f++ = '\0'; | |
1771 | while (*s == ' ' || *s == '\t') s++; | |
1772 | ||
1773 | if (*s != ',' && *s != 0) | |
1774 | error ("Invalid argument syntax"); | |
1775 | ||
1776 | if (*s == ',') s++; | |
1777 | while (*s == ' ' || *s == '\t') s++; | |
1778 | ||
1779 | { | |
1780 | /* Now scan the string for %-specs and see what kinds of args they want. | |
1781 | argclass[I] classifies the %-specs so we can give vprintf something | |
1782 | of the right size. */ | |
1783 | ||
1784 | enum argclass {int_arg, string_arg, double_arg, long_long_arg}; | |
1785 | enum argclass *argclass; | |
1786 | int nargs_wanted; | |
bd5635a1 RP |
1787 | int lcount; |
1788 | int i; | |
19bdd57f JK |
1789 | makeva_list *args_makeva; |
1790 | ||
bd5635a1 RP |
1791 | argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass); |
1792 | nargs_wanted = 0; | |
1793 | f = string; | |
1794 | while (*f) | |
1795 | if (*f++ == '%') | |
1796 | { | |
1797 | lcount = 0; | |
1798 | while (strchr ("0123456789.hlL-+ #", *f)) | |
1799 | { | |
1800 | if (*f == 'l' || *f == 'L') | |
1801 | lcount++; | |
1802 | f++; | |
1803 | } | |
1804 | if (*f == 's') | |
1805 | argclass[nargs_wanted++] = string_arg; | |
1806 | else if (*f == 'e' || *f == 'f' || *f == 'g') | |
1807 | argclass[nargs_wanted++] = double_arg; | |
1808 | else if (lcount > 1) | |
1809 | argclass[nargs_wanted++] = long_long_arg; | |
1810 | else if (*f != '%') | |
1811 | argclass[nargs_wanted++] = int_arg; | |
1812 | f++; | |
1813 | } | |
1814 | ||
1815 | /* Now, parse all arguments and evaluate them. | |
1816 | Store the VALUEs in VAL_ARGS. */ | |
1817 | ||
1818 | while (*s != '\0') | |
1819 | { | |
1820 | char *s1; | |
1821 | if (nargs == allocated_args) | |
93fe4e33 | 1822 | val_args = (value *) xrealloc ((char *) val_args, |
bd5635a1 RP |
1823 | (allocated_args *= 2) |
1824 | * sizeof (value)); | |
1825 | s1 = s; | |
1826 | val_args[nargs] = parse_to_comma_and_eval (&s1); | |
1827 | ||
1828 | /* If format string wants a float, unchecked-convert the value to | |
1829 | floating point of the same size */ | |
1830 | ||
1831 | if (argclass[nargs] == double_arg) | |
1832 | { | |
1833 | if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (float)) | |
1834 | VALUE_TYPE (val_args[nargs]) = builtin_type_float; | |
1835 | if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (double)) | |
1836 | VALUE_TYPE (val_args[nargs]) = builtin_type_double; | |
1837 | } | |
1838 | nargs++; | |
1839 | s = s1; | |
1840 | if (*s == ',') | |
1841 | s++; | |
1842 | } | |
1843 | ||
1844 | if (nargs != nargs_wanted) | |
1845 | error ("Wrong number of arguments for specified format-string"); | |
19bdd57f | 1846 | |
bd5635a1 RP |
1847 | /* Now lay out an argument-list containing the arguments |
1848 | as doubles, integers and C pointers. */ | |
19bdd57f JK |
1849 | |
1850 | args_makeva = (makeva_list *) | |
1851 | alloca (makeva_size (nargs, sizeof (double))); | |
1852 | makeva_start (args_makeva, nargs, sizeof (double)); | |
bd5635a1 RP |
1853 | for (i = 0; i < nargs; i++) |
1854 | { | |
1855 | if (argclass[i] == string_arg) | |
1856 | { | |
1857 | char *str; | |
e1ce8aa5 JK |
1858 | CORE_ADDR tem; |
1859 | int j; | |
1860 | tem = value_as_pointer (val_args[i]); | |
bd5635a1 RP |
1861 | |
1862 | /* This is a %s argument. Find the length of the string. */ | |
1863 | for (j = 0; ; j++) | |
1864 | { | |
1865 | char c; | |
1866 | QUIT; | |
1867 | read_memory (tem + j, &c, 1); | |
1868 | if (c == 0) | |
1869 | break; | |
1870 | } | |
1871 | ||
1872 | /* Copy the string contents into a string inside GDB. */ | |
1873 | str = (char *) alloca (j + 1); | |
1874 | read_memory (tem, str, j); | |
1875 | str[j] = 0; | |
1876 | ||
1877 | /* Pass address of internal copy as the arg to vprintf. */ | |
19bdd57f | 1878 | makeva_arg (args_makeva, &str, sizeof (str)); |
bd5635a1 RP |
1879 | } |
1880 | else if (VALUE_TYPE (val_args[i])->code == TYPE_CODE_FLT) | |
1881 | { | |
19bdd57f JK |
1882 | double val = value_as_double (val_args[i]); |
1883 | makeva_arg (args_makeva, &val, sizeof (val)); | |
bd5635a1 RP |
1884 | } |
1885 | else | |
6fe90fc8 | 1886 | #ifdef CC_HAS_LONG_LONG |
bd5635a1 RP |
1887 | if (argclass[i] == long_long_arg) |
1888 | { | |
19bdd57f JK |
1889 | long long val = value_as_long (val_args[i]); |
1890 | makeva_arg (args_makeva, &val, sizeof (val)); | |
bd5635a1 RP |
1891 | } |
1892 | else | |
1893 | #endif | |
1894 | { | |
19bdd57f JK |
1895 | long val = value_as_long (val_args[i]); |
1896 | makeva_arg (args_makeva, &val, sizeof (val)); | |
bd5635a1 RP |
1897 | } |
1898 | } | |
19bdd57f | 1899 | args_to_vprintf = makeva_end (args_makeva); |
bd5635a1 RP |
1900 | } |
1901 | ||
19bdd57f JK |
1902 | /* FIXME: We should be using vprintf_filtered, but as long as it has an |
1903 | arbitrary limit that is unacceptable. Correct fix is for vprintf_filtered | |
1904 | to scan down the format string so it knows how big a buffer it needs. | |
bd5635a1 | 1905 | |
19bdd57f JK |
1906 | But for now, just force out any pending output, so at least the output |
1907 | appears in the correct order. */ | |
1908 | wrap_here ((char *)NULL); | |
1909 | vprintf (string, args_to_vprintf); | |
bd5635a1 RP |
1910 | } |
1911 | \f | |
bd5635a1 RP |
1912 | /* Dump a specified section of assembly code. With no command line |
1913 | arguments, this command will dump the assembly code for the | |
1914 | function surrounding the pc value in the selected frame. With one | |
1915 | argument, it will dump the assembly code surrounding that pc value. | |
1916 | Two arguments are interpeted as bounds within which to dump | |
1917 | assembly. */ | |
1918 | ||
e1ce8aa5 | 1919 | /* ARGSUSED */ |
bd5635a1 RP |
1920 | static void |
1921 | disassemble_command (arg, from_tty) | |
1922 | char *arg; | |
1923 | int from_tty; | |
1924 | { | |
1925 | CORE_ADDR low, high; | |
f1ed4330 | 1926 | char *name; |
bd5635a1 RP |
1927 | CORE_ADDR pc; |
1928 | char *space_index; | |
1929 | ||
f1ed4330 | 1930 | name = NULL; |
bd5635a1 RP |
1931 | if (!arg) |
1932 | { | |
1933 | if (!selected_frame) | |
1934 | error ("No frame selected.\n"); | |
1935 | ||
1936 | pc = get_frame_pc (selected_frame); | |
f1ed4330 JK |
1937 | if (find_pc_partial_function (pc, &name, &low, &high) == 0) |
1938 | error ("No function contains program counter for selected frame.\n"); | |
bd5635a1 RP |
1939 | } |
1940 | else if (!(space_index = (char *) strchr (arg, ' '))) | |
1941 | { | |
1942 | /* One argument. */ | |
1943 | pc = parse_and_eval_address (arg); | |
f1ed4330 JK |
1944 | if (find_pc_partial_function (pc, &name, &low, &high) == 0) |
1945 | error ("No function contains specified address.\n"); | |
bd5635a1 RP |
1946 | } |
1947 | else | |
1948 | { | |
1949 | /* Two arguments. */ | |
1950 | *space_index = '\0'; | |
1951 | low = parse_and_eval_address (arg); | |
1952 | high = parse_and_eval_address (space_index + 1); | |
1953 | } | |
1954 | ||
1955 | printf_filtered ("Dump of assembler code "); | |
f1ed4330 | 1956 | if (name != NULL) |
bd5635a1 | 1957 | { |
bd5635a1 RP |
1958 | printf_filtered ("for function %s:\n", name); |
1959 | } | |
1960 | else | |
f77ad505 FF |
1961 | { |
1962 | printf_filtered ("from %s ", local_hex_string(low)); | |
1963 | printf_filtered ("to %s:\n", local_hex_string(high)); | |
1964 | } | |
bd5635a1 RP |
1965 | |
1966 | /* Dump the specified range. */ | |
1967 | for (pc = low; pc < high; ) | |
1968 | { | |
1969 | QUIT; | |
1970 | print_address (pc, stdout); | |
1971 | printf_filtered (":\t"); | |
1972 | pc += print_insn (pc, stdout); | |
1973 | printf_filtered ("\n"); | |
1974 | } | |
1975 | printf_filtered ("End of assembler dump.\n"); | |
1976 | fflush (stdout); | |
1977 | } | |
1978 | ||
1979 | \f | |
1980 | void | |
1981 | _initialize_printcmd () | |
1982 | { | |
1983 | current_display_number = -1; | |
1984 | ||
1985 | add_info ("address", address_info, | |
1986 | "Describe where variable VAR is stored."); | |
1987 | ||
1988 | add_com ("x", class_vars, x_command, | |
1989 | "Examine memory: x/FMT ADDRESS.\n\ | |
1990 | ADDRESS is an expression for the memory address to examine.\n\ | |
1991 | FMT is a repeat count followed by a format letter and a size letter.\n\ | |
1992 | Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\ | |
31258e4f | 1993 | t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\ |
bd5635a1 | 1994 | Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\ |
bd5635a1 RP |
1995 | The specified number of objects of the specified size are printed\n\ |
1996 | according to the format.\n\n\ | |
1997 | Defaults for format and size letters are those previously used.\n\ | |
1998 | Default count is 1. Default address is following last thing printed\n\ | |
1999 | with this command or \"print\"."); | |
2000 | ||
2001 | add_com ("disassemble", class_vars, disassemble_command, | |
2002 | "Disassemble a specified section of memory.\n\ | |
2003 | Default is the function surrounding the pc of the selected frame.\n\ | |
2004 | With a single argument, the function surrounding that address is dumped.\n\ | |
2005 | Two arguments are taken as a range of memory to dump."); | |
2006 | ||
bd5635a1 RP |
2007 | #if 0 |
2008 | add_com ("whereis", class_vars, whereis_command, | |
2009 | "Print line number and file of definition of variable."); | |
2010 | #endif | |
2011 | ||
2012 | add_info ("display", display_info, | |
2013 | "Expressions to display when program stops, with code numbers."); | |
2014 | ||
2015 | add_cmd ("undisplay", class_vars, undisplay_command, | |
2016 | "Cancel some expressions to be displayed when program stops.\n\ | |
2017 | Arguments are the code numbers of the expressions to stop displaying.\n\ | |
2018 | No argument means cancel all automatic-display expressions.\n\ | |
2019 | \"delete display\" has the same effect as this command.\n\ | |
2020 | Do \"info display\" to see current list of code numbers.", | |
2021 | &cmdlist); | |
2022 | ||
2023 | add_com ("display", class_vars, display_command, | |
2024 | "Print value of expression EXP each time the program stops.\n\ | |
2025 | /FMT may be used before EXP as in the \"print\" command.\n\ | |
2026 | /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\ | |
2027 | as in the \"x\" command, and then EXP is used to get the address to examine\n\ | |
2028 | and examining is done as in the \"x\" command.\n\n\ | |
2029 | With no argument, display all currently requested auto-display expressions.\n\ | |
2030 | Use \"undisplay\" to cancel display requests previously made."); | |
2031 | ||
2032 | add_cmd ("display", class_vars, enable_display, | |
2033 | "Enable some expressions to be displayed when program stops.\n\ | |
2034 | Arguments are the code numbers of the expressions to resume displaying.\n\ | |
2035 | No argument means enable all automatic-display expressions.\n\ | |
2036 | Do \"info display\" to see current list of code numbers.", &enablelist); | |
2037 | ||
2038 | add_cmd ("display", class_vars, disable_display_command, | |
2039 | "Disable some expressions to be displayed when program stops.\n\ | |
2040 | Arguments are the code numbers of the expressions to stop displaying.\n\ | |
2041 | No argument means disable all automatic-display expressions.\n\ | |
2042 | Do \"info display\" to see current list of code numbers.", &disablelist); | |
2043 | ||
2044 | add_cmd ("display", class_vars, undisplay_command, | |
2045 | "Cancel some expressions to be displayed when program stops.\n\ | |
2046 | Arguments are the code numbers of the expressions to stop displaying.\n\ | |
2047 | No argument means cancel all automatic-display expressions.\n\ | |
2048 | Do \"info display\" to see current list of code numbers.", &deletelist); | |
2049 | ||
2050 | add_com ("printf", class_vars, printf_command, | |
2051 | "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
2052 | This is useful for formatted output in user-defined commands."); | |
2053 | add_com ("output", class_vars, output_command, | |
2054 | "Like \"print\" but don't put in value history and don't print newline.\n\ | |
2055 | This is useful in user-defined commands."); | |
2056 | ||
2057 | add_prefix_cmd ("set", class_vars, set_command, | |
45fe3db4 FF |
2058 | "Evaluate expression EXP and assign result to variable VAR, using assignment\n\ |
2059 | syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ | |
2060 | example). VAR may be a debugger \"convenience\" variable (names starting\n\ | |
2061 | with $), a register (a few standard names starting with $), or an actual\n\ | |
2062 | variable in the program being debugged. EXP is any valid expression.\n\ | |
bd5635a1 RP |
2063 | Use \"set variable\" for variables with names identical to set subcommands.\n\ |
2064 | \nWith a subcommand, this command modifies parts of the gdb environment.\n\ | |
2065 | You can see these environment settings with the \"show\" command.", | |
2066 | &setlist, "set ", 1, &cmdlist); | |
2067 | ||
2068 | /* "call" is the same as "set", but handy for dbx users to call fns. */ | |
2069 | add_com ("call", class_vars, call_command, | |
6fe90fc8 | 2070 | "Call a function in the program.\n\ |
c4668207 JG |
2071 | The argument is the function name and arguments, in the notation of the\n\ |
2072 | current working language. The result is printed and saved in the value\n\ | |
2073 | history, if it is not void."); | |
bd5635a1 RP |
2074 | |
2075 | add_cmd ("variable", class_vars, set_command, | |
45fe3db4 FF |
2076 | "Evaluate expression EXP and assign result to variable VAR, using assignment\n\ |
2077 | syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ | |
2078 | example). VAR may be a debugger \"convenience\" variable (names starting\n\ | |
2079 | with $), a register (a few standard names starting with $), or an actual\n\ | |
2080 | variable in the program being debugged. EXP is any valid expression.\n\ | |
bd5635a1 RP |
2081 | This may usually be abbreviated to simply \"set\".", |
2082 | &setlist); | |
2083 | ||
2084 | add_com ("print", class_vars, print_command, | |
2085 | concat ("Print value of expression EXP.\n\ | |
2086 | Variables accessible are those of the lexical environment of the selected\n\ | |
2087 | stack frame, plus all those whose scope is global or an entire file.\n\ | |
2088 | \n\ | |
2089 | $NUM gets previous value number NUM. $ and $$ are the last two values.\n\ | |
2090 | $$NUM refers to NUM'th value back from the last one.\n\ | |
2091 | Names starting with $ refer to registers (with the values they would have\n\ | |
2092 | if the program were to return to the stack frame now selected, restoring\n\ | |
2093 | all registers saved by frames farther in) or else to debugger\n\ | |
2094 | \"convenience\" variables (any such name not a known register).\n\ | |
2095 | Use assignment expressions to give values to convenience variables.\n", | |
2096 | "\n\ | |
2097 | {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\ | |
2098 | @ is a binary operator for treating consecutive data objects\n\ | |
2099 | anywhere in memory as an array. FOO@NUM gives an array whose first\n\ | |
2100 | element is FOO, whose second element is stored in the space following\n\ | |
2101 | where FOO is stored, etc. FOO must be an expression whose value\n\ | |
2102 | resides in memory.\n", | |
2103 | "\n\ | |
2104 | EXP may be preceded with /FMT, where FMT is a format letter\n\ | |
7d9884b9 | 2105 | but no count or size letter (see \"x\" command).", NULL)); |
bd5635a1 RP |
2106 | add_com_alias ("p", "print", class_vars, 1); |
2107 | ||
2108 | add_com ("inspect", class_vars, inspect_command, | |
2109 | "Same as \"print\" command, except that if you are running in the epoch\n\ | |
2110 | environment, the value is printed in its own window."); | |
f77ad505 FF |
2111 | |
2112 | add_show_from_set ( | |
2113 | add_set_cmd ("max-symbolic-offset", no_class, var_uinteger, | |
2114 | (char *)&max_symbolic_offset, | |
2115 | "Set the largest offset that will be printed in <symbol+1234> form.", | |
2116 | &setprintlist), | |
2117 | &showprintlist); | |
b7ccd8e0 PS |
2118 | add_show_from_set ( |
2119 | add_set_cmd ("symbol-filename", no_class, var_boolean, | |
2120 | (char *)&print_symbol_filename, | |
2121 | "Set printing of source filename and line number with <symbol>.", | |
2122 | &setprintlist), | |
2123 | &showprintlist); | |
bd5635a1 | 2124 | } |