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