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