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