Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Print values for GNU debugger GDB. |
e2ad119d | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 | 4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
0fb0cc75 | 5 | 2008, 2009 Free Software Foundation, Inc. |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include "gdb_string.h" | |
24 | #include "frame.h" | |
25 | #include "symtab.h" | |
26 | #include "gdbtypes.h" | |
27 | #include "value.h" | |
28 | #include "language.h" | |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "target.h" | |
33 | #include "breakpoint.h" | |
34 | #include "demangle.h" | |
35 | #include "valprint.h" | |
36 | #include "annotate.h" | |
c5aa993b JM |
37 | #include "symfile.h" /* for overlay functions */ |
38 | #include "objfiles.h" /* ditto */ | |
c94fdfd0 | 39 | #include "completer.h" /* for completion functions */ |
8b93c638 | 40 | #include "ui-out.h" |
261397f8 | 41 | #include "gdb_assert.h" |
fe898f56 | 42 | #include "block.h" |
92bf2b80 | 43 | #include "disasm.h" |
1a619819 | 44 | #include "dfp.h" |
79a45b7d | 45 | #include "valprint.h" |
c906108c | 46 | |
6a83354a AC |
47 | #ifdef TUI |
48 | #include "tui/tui.h" /* For tui_active et.al. */ | |
49 | #endif | |
50 | ||
06be140c | 51 | #if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG) |
09d71d23 AS |
52 | # define USE_PRINTF_I64 1 |
53 | # define PRINTF_HAS_LONG_LONG | |
54 | #else | |
55 | # define USE_PRINTF_I64 0 | |
56 | #endif | |
57 | ||
c906108c | 58 | extern int asm_demangle; /* Whether to demangle syms in asm printouts */ |
c906108c SS |
59 | |
60 | struct format_data | |
c5aa993b JM |
61 | { |
62 | int count; | |
63 | char format; | |
64 | char size; | |
65 | }; | |
c906108c SS |
66 | |
67 | /* Last specified output format. */ | |
68 | ||
69 | static char last_format = 'x'; | |
70 | ||
71 | /* Last specified examination size. 'b', 'h', 'w' or `q'. */ | |
72 | ||
73 | static char last_size = 'w'; | |
74 | ||
75 | /* Default address to examine next. */ | |
76 | ||
77 | static CORE_ADDR next_address; | |
78 | ||
a4642986 MR |
79 | /* Number of delay instructions following current disassembled insn. */ |
80 | ||
81 | static int branch_delay_insns; | |
82 | ||
c906108c SS |
83 | /* Last address examined. */ |
84 | ||
85 | static CORE_ADDR last_examine_address; | |
86 | ||
87 | /* Contents of last address examined. | |
88 | This is not valid past the end of the `x' command! */ | |
89 | ||
3d6d86c6 | 90 | static struct value *last_examine_value; |
c906108c SS |
91 | |
92 | /* Largest offset between a symbolic value and an address, that will be | |
93 | printed as `0x1234 <symbol+offset>'. */ | |
94 | ||
95 | static unsigned int max_symbolic_offset = UINT_MAX; | |
920d2a44 AC |
96 | static void |
97 | show_max_symbolic_offset (struct ui_file *file, int from_tty, | |
98 | struct cmd_list_element *c, const char *value) | |
99 | { | |
100 | fprintf_filtered (file, _("\ | |
101 | The largest offset that will be printed in <symbol+1234> form is %s.\n"), | |
102 | value); | |
103 | } | |
c906108c SS |
104 | |
105 | /* Append the source filename and linenumber of the symbol when | |
106 | printing a symbolic value as `<symbol at filename:linenum>' if set. */ | |
107 | static int print_symbol_filename = 0; | |
920d2a44 AC |
108 | static void |
109 | show_print_symbol_filename (struct ui_file *file, int from_tty, | |
110 | struct cmd_list_element *c, const char *value) | |
111 | { | |
112 | fprintf_filtered (file, _("\ | |
113 | Printing of source filename and line number with <symbol> is %s.\n"), | |
114 | value); | |
115 | } | |
c906108c SS |
116 | |
117 | /* Number of auto-display expression currently being displayed. | |
118 | So that we can disable it if we get an error or a signal within it. | |
119 | -1 when not doing one. */ | |
120 | ||
121 | int current_display_number; | |
122 | ||
c906108c | 123 | struct display |
c5aa993b JM |
124 | { |
125 | /* Chain link to next auto-display item. */ | |
126 | struct display *next; | |
fa8a61dc TT |
127 | /* The expression as the user typed it. */ |
128 | char *exp_string; | |
c5aa993b JM |
129 | /* Expression to be evaluated and displayed. */ |
130 | struct expression *exp; | |
131 | /* Item number of this auto-display item. */ | |
132 | int number; | |
133 | /* Display format specified. */ | |
134 | struct format_data format; | |
135 | /* Innermost block required by this expression when evaluated */ | |
136 | struct block *block; | |
137 | /* Status of this display (enabled or disabled) */ | |
b5de0fa7 | 138 | int enabled_p; |
c5aa993b | 139 | }; |
c906108c SS |
140 | |
141 | /* Chain of expressions whose values should be displayed | |
142 | automatically each time the program stops. */ | |
143 | ||
144 | static struct display *display_chain; | |
145 | ||
146 | static int display_number; | |
147 | ||
148 | /* Prototypes for exported functions. */ | |
149 | ||
a14ed312 | 150 | void output_command (char *, int); |
c906108c | 151 | |
a14ed312 | 152 | void _initialize_printcmd (void); |
c906108c SS |
153 | |
154 | /* Prototypes for local functions. */ | |
155 | ||
a14ed312 | 156 | static void do_one_display (struct display *); |
c906108c | 157 | \f |
c5aa993b | 158 | |
c906108c SS |
159 | /* Decode a format specification. *STRING_PTR should point to it. |
160 | OFORMAT and OSIZE are used as defaults for the format and size | |
161 | if none are given in the format specification. | |
162 | If OSIZE is zero, then the size field of the returned value | |
163 | should be set only if a size is explicitly specified by the | |
164 | user. | |
165 | The structure returned describes all the data | |
166 | found in the specification. In addition, *STRING_PTR is advanced | |
167 | past the specification and past all whitespace following it. */ | |
168 | ||
169 | static struct format_data | |
fba45db2 | 170 | decode_format (char **string_ptr, int oformat, int osize) |
c906108c SS |
171 | { |
172 | struct format_data val; | |
52f0bd74 | 173 | char *p = *string_ptr; |
c906108c SS |
174 | |
175 | val.format = '?'; | |
176 | val.size = '?'; | |
177 | val.count = 1; | |
178 | ||
179 | if (*p >= '0' && *p <= '9') | |
180 | val.count = atoi (p); | |
c5aa993b JM |
181 | while (*p >= '0' && *p <= '9') |
182 | p++; | |
c906108c SS |
183 | |
184 | /* Now process size or format letters that follow. */ | |
185 | ||
186 | while (1) | |
187 | { | |
188 | if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g') | |
189 | val.size = *p++; | |
190 | else if (*p >= 'a' && *p <= 'z') | |
191 | val.format = *p++; | |
192 | else | |
193 | break; | |
194 | } | |
195 | ||
c5aa993b JM |
196 | while (*p == ' ' || *p == '\t') |
197 | p++; | |
c906108c SS |
198 | *string_ptr = p; |
199 | ||
200 | /* Set defaults for format and size if not specified. */ | |
201 | if (val.format == '?') | |
202 | { | |
203 | if (val.size == '?') | |
204 | { | |
205 | /* Neither has been specified. */ | |
206 | val.format = oformat; | |
207 | val.size = osize; | |
208 | } | |
209 | else | |
210 | /* If a size is specified, any format makes a reasonable | |
211 | default except 'i'. */ | |
212 | val.format = oformat == 'i' ? 'x' : oformat; | |
213 | } | |
214 | else if (val.size == '?') | |
215 | switch (val.format) | |
216 | { | |
217 | case 'a': | |
218 | case 's': | |
219 | /* Pick the appropriate size for an address. */ | |
819844ad | 220 | if (gdbarch_ptr_bit (current_gdbarch) == 64) |
c906108c | 221 | val.size = osize ? 'g' : osize; |
819844ad | 222 | else if (gdbarch_ptr_bit (current_gdbarch) == 32) |
c906108c | 223 | val.size = osize ? 'w' : osize; |
819844ad | 224 | else if (gdbarch_ptr_bit (current_gdbarch) == 16) |
c906108c SS |
225 | val.size = osize ? 'h' : osize; |
226 | else | |
819844ad | 227 | /* Bad value for gdbarch_ptr_bit. */ |
675dcf4f MK |
228 | internal_error (__FILE__, __LINE__, |
229 | _("failed internal consistency check")); | |
c906108c SS |
230 | break; |
231 | case 'f': | |
232 | /* Floating point has to be word or giantword. */ | |
233 | if (osize == 'w' || osize == 'g') | |
234 | val.size = osize; | |
235 | else | |
236 | /* Default it to giantword if the last used size is not | |
237 | appropriate. */ | |
238 | val.size = osize ? 'g' : osize; | |
239 | break; | |
240 | case 'c': | |
241 | /* Characters default to one byte. */ | |
242 | val.size = osize ? 'b' : osize; | |
243 | break; | |
244 | default: | |
245 | /* The default is the size most recently specified. */ | |
246 | val.size = osize; | |
247 | } | |
248 | ||
249 | return val; | |
250 | } | |
251 | \f | |
79a45b7d | 252 | /* Print value VAL on stream according to OPTIONS. |
c906108c | 253 | Do not end with a newline. |
c906108c | 254 | SIZE is the letter for the size of datum being printed. |
ea37ba09 DJ |
255 | This is used to pad hex numbers so they line up. SIZE is 0 |
256 | for print / output and set for examine. */ | |
c906108c SS |
257 | |
258 | static void | |
79a45b7d TT |
259 | print_formatted (struct value *val, int size, |
260 | const struct value_print_options *options, | |
fba45db2 | 261 | struct ui_file *stream) |
c906108c | 262 | { |
df407dfe | 263 | struct type *type = check_typedef (value_type (val)); |
c906108c SS |
264 | int len = TYPE_LENGTH (type); |
265 | ||
266 | if (VALUE_LVAL (val) == lval_memory) | |
675dcf4f | 267 | next_address = VALUE_ADDRESS (val) + len; |
c906108c | 268 | |
ea37ba09 | 269 | if (size) |
c906108c | 270 | { |
79a45b7d | 271 | switch (options->format) |
ea37ba09 DJ |
272 | { |
273 | case 's': | |
274 | /* FIXME: Need to handle wchar_t's here... */ | |
275 | next_address = VALUE_ADDRESS (val) | |
79a45b7d TT |
276 | + val_print_string (VALUE_ADDRESS (val), -1, 1, stream, |
277 | options); | |
ea37ba09 | 278 | return; |
c906108c | 279 | |
ea37ba09 DJ |
280 | case 'i': |
281 | /* We often wrap here if there are long symbolic names. */ | |
282 | wrap_here (" "); | |
283 | next_address = (VALUE_ADDRESS (val) | |
284 | + gdb_print_insn (VALUE_ADDRESS (val), stream, | |
285 | &branch_delay_insns)); | |
286 | return; | |
287 | } | |
c906108c | 288 | } |
ea37ba09 | 289 | |
79a45b7d | 290 | if (options->format == 0 || options->format == 's' |
4e885b20 | 291 | || TYPE_CODE (type) == TYPE_CODE_REF |
ea37ba09 DJ |
292 | || TYPE_CODE (type) == TYPE_CODE_ARRAY |
293 | || TYPE_CODE (type) == TYPE_CODE_STRING | |
294 | || TYPE_CODE (type) == TYPE_CODE_STRUCT | |
295 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
296 | || TYPE_CODE (type) == TYPE_CODE_NAMESPACE) | |
79a45b7d | 297 | value_print (val, stream, options); |
ea37ba09 DJ |
298 | else |
299 | /* User specified format, so don't look to the the type to | |
300 | tell us what to do. */ | |
301 | print_scalar_formatted (value_contents (val), type, | |
79a45b7d | 302 | options, size, stream); |
c906108c SS |
303 | } |
304 | ||
b806fb9a UW |
305 | /* Return builtin floating point type of same length as TYPE. |
306 | If no such type is found, return TYPE itself. */ | |
307 | static struct type * | |
308 | float_type_from_length (struct gdbarch *gdbarch, struct type *type) | |
309 | { | |
310 | const struct builtin_type *builtin = builtin_type (gdbarch); | |
311 | unsigned int len = TYPE_LENGTH (type); | |
312 | ||
313 | if (len == TYPE_LENGTH (builtin->builtin_float)) | |
314 | type = builtin->builtin_float; | |
315 | else if (len == TYPE_LENGTH (builtin->builtin_double)) | |
316 | type = builtin->builtin_double; | |
317 | else if (len == TYPE_LENGTH (builtin->builtin_long_double)) | |
318 | type = builtin->builtin_long_double; | |
319 | ||
320 | return type; | |
321 | } | |
322 | ||
c906108c | 323 | /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR, |
79a45b7d TT |
324 | according to OPTIONS and SIZE on STREAM. |
325 | Formats s and i are not supported at this level. | |
c906108c SS |
326 | |
327 | This is how the elements of an array or structure are printed | |
328 | with a format. */ | |
329 | ||
330 | void | |
366b1cbf | 331 | print_scalar_formatted (const void *valaddr, struct type *type, |
79a45b7d TT |
332 | const struct value_print_options *options, |
333 | int size, struct ui_file *stream) | |
c906108c | 334 | { |
81cb7cc9 | 335 | LONGEST val_long = 0; |
c906108c | 336 | unsigned int len = TYPE_LENGTH (type); |
d44e8473 | 337 | enum bfd_endian byte_order = gdbarch_byte_order (current_gdbarch); |
c906108c | 338 | |
ea37ba09 DJ |
339 | /* If we get here with a string format, try again without it. Go |
340 | all the way back to the language printers, which may call us | |
341 | again. */ | |
79a45b7d | 342 | if (options->format == 's') |
ea37ba09 | 343 | { |
79a45b7d TT |
344 | struct value_print_options opts = *options; |
345 | opts.format = 0; | |
346 | opts.deref_ref = 0; | |
347 | val_print (type, valaddr, 0, 0, stream, 0, &opts, | |
d8ca156b | 348 | current_language); |
ea37ba09 DJ |
349 | return; |
350 | } | |
351 | ||
6b9acc27 JJ |
352 | if (len > sizeof(LONGEST) && |
353 | (TYPE_CODE (type) == TYPE_CODE_INT | |
354 | || TYPE_CODE (type) == TYPE_CODE_ENUM)) | |
355 | { | |
79a45b7d | 356 | switch (options->format) |
6b9acc27 JJ |
357 | { |
358 | case 'o': | |
d44e8473 | 359 | print_octal_chars (stream, valaddr, len, byte_order); |
6b9acc27 JJ |
360 | return; |
361 | case 'u': | |
362 | case 'd': | |
d44e8473 | 363 | print_decimal_chars (stream, valaddr, len, byte_order); |
6b9acc27 JJ |
364 | return; |
365 | case 't': | |
d44e8473 | 366 | print_binary_chars (stream, valaddr, len, byte_order); |
6b9acc27 JJ |
367 | return; |
368 | case 'x': | |
d44e8473 | 369 | print_hex_chars (stream, valaddr, len, byte_order); |
6b9acc27 JJ |
370 | return; |
371 | case 'c': | |
d44e8473 | 372 | print_char_chars (stream, valaddr, len, byte_order); |
6b9acc27 JJ |
373 | return; |
374 | default: | |
375 | break; | |
376 | }; | |
377 | } | |
378 | ||
79a45b7d | 379 | if (options->format != 'f') |
c906108c SS |
380 | val_long = unpack_long (type, valaddr); |
381 | ||
ef166cf4 | 382 | /* If the value is a pointer, and pointers and addresses are not the |
d0aee0c4 | 383 | same, then at this point, the value's length (in target bytes) is |
17a912b6 | 384 | gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */ |
ef166cf4 | 385 | if (TYPE_CODE (type) == TYPE_CODE_PTR) |
17a912b6 | 386 | len = gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT; |
ef166cf4 | 387 | |
c906108c SS |
388 | /* If we are printing it as unsigned, truncate it in case it is actually |
389 | a negative signed value (e.g. "print/u (short)-1" should print 65535 | |
390 | (if shorts are 16 bits) instead of 4294967295). */ | |
79a45b7d | 391 | if (options->format != 'd') |
c906108c SS |
392 | { |
393 | if (len < sizeof (LONGEST)) | |
394 | val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1; | |
395 | } | |
396 | ||
79a45b7d | 397 | switch (options->format) |
c906108c SS |
398 | { |
399 | case 'x': | |
400 | if (!size) | |
401 | { | |
675dcf4f | 402 | /* No size specified, like in print. Print varying # of digits. */ |
c906108c SS |
403 | print_longest (stream, 'x', 1, val_long); |
404 | } | |
405 | else | |
406 | switch (size) | |
407 | { | |
408 | case 'b': | |
409 | case 'h': | |
410 | case 'w': | |
411 | case 'g': | |
412 | print_longest (stream, size, 1, val_long); | |
413 | break; | |
414 | default: | |
8a3fe4f8 | 415 | error (_("Undefined output size \"%c\"."), size); |
c906108c SS |
416 | } |
417 | break; | |
418 | ||
419 | case 'd': | |
420 | print_longest (stream, 'd', 1, val_long); | |
421 | break; | |
422 | ||
423 | case 'u': | |
424 | print_longest (stream, 'u', 0, val_long); | |
425 | break; | |
426 | ||
427 | case 'o': | |
428 | if (val_long) | |
429 | print_longest (stream, 'o', 1, val_long); | |
430 | else | |
431 | fprintf_filtered (stream, "0"); | |
432 | break; | |
433 | ||
434 | case 'a': | |
593de6a6 | 435 | { |
593de6a6 | 436 | CORE_ADDR addr = unpack_pointer (type, valaddr); |
593de6a6 PS |
437 | print_address (addr, stream); |
438 | } | |
c906108c SS |
439 | break; |
440 | ||
441 | case 'c': | |
79a45b7d TT |
442 | { |
443 | struct value_print_options opts = *options; | |
444 | opts.format = 0; | |
445 | if (TYPE_UNSIGNED (type)) | |
446 | value_print (value_from_longest (builtin_type_true_unsigned_char, | |
447 | val_long), | |
448 | stream, &opts); | |
449 | else | |
450 | value_print (value_from_longest (builtin_type_true_char, val_long), | |
451 | stream, &opts); | |
452 | } | |
c906108c SS |
453 | break; |
454 | ||
455 | case 'f': | |
b806fb9a | 456 | type = float_type_from_length (current_gdbarch, type); |
c906108c SS |
457 | print_floating (valaddr, type, stream); |
458 | break; | |
459 | ||
460 | case 0: | |
675dcf4f MK |
461 | internal_error (__FILE__, __LINE__, |
462 | _("failed internal consistency check")); | |
c906108c SS |
463 | |
464 | case 't': | |
465 | /* Binary; 't' stands for "two". */ | |
466 | { | |
c5aa993b JM |
467 | char bits[8 * (sizeof val_long) + 1]; |
468 | char buf[8 * (sizeof val_long) + 32]; | |
c906108c SS |
469 | char *cp = bits; |
470 | int width; | |
471 | ||
c5aa993b JM |
472 | if (!size) |
473 | width = 8 * (sizeof val_long); | |
474 | else | |
475 | switch (size) | |
c906108c SS |
476 | { |
477 | case 'b': | |
478 | width = 8; | |
479 | break; | |
480 | case 'h': | |
481 | width = 16; | |
482 | break; | |
483 | case 'w': | |
484 | width = 32; | |
485 | break; | |
486 | case 'g': | |
487 | width = 64; | |
488 | break; | |
489 | default: | |
8a3fe4f8 | 490 | error (_("Undefined output size \"%c\"."), size); |
c906108c SS |
491 | } |
492 | ||
c5aa993b JM |
493 | bits[width] = '\0'; |
494 | while (width-- > 0) | |
495 | { | |
496 | bits[width] = (val_long & 1) ? '1' : '0'; | |
497 | val_long >>= 1; | |
498 | } | |
c906108c SS |
499 | if (!size) |
500 | { | |
501 | while (*cp && *cp == '0') | |
502 | cp++; | |
503 | if (*cp == '\0') | |
504 | cp--; | |
505 | } | |
bb599908 | 506 | strcpy (buf, cp); |
306d9ac5 | 507 | fputs_filtered (buf, stream); |
c906108c SS |
508 | } |
509 | break; | |
510 | ||
511 | default: | |
79a45b7d | 512 | error (_("Undefined output format \"%c\"."), options->format); |
c906108c SS |
513 | } |
514 | } | |
515 | ||
516 | /* Specify default address for `x' command. | |
675dcf4f | 517 | The `info lines' command uses this. */ |
c906108c SS |
518 | |
519 | void | |
8b9b9e1a | 520 | set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr) |
c906108c | 521 | { |
8b9b9e1a UW |
522 | struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr; |
523 | ||
c906108c SS |
524 | next_address = addr; |
525 | ||
526 | /* Make address available to the user as $_. */ | |
527 | set_internalvar (lookup_internalvar ("_"), | |
8b9b9e1a | 528 | value_from_pointer (ptr_type, addr)); |
c906108c SS |
529 | } |
530 | ||
531 | /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM, | |
532 | after LEADIN. Print nothing if no symbolic name is found nearby. | |
533 | Optionally also print source file and line number, if available. | |
534 | DO_DEMANGLE controls whether to print a symbol in its native "raw" form, | |
535 | or to interpret it as a possible C++ name and convert it back to source | |
536 | form. However note that DO_DEMANGLE can be overridden by the specific | |
537 | settings of the demangle and asm_demangle variables. */ | |
538 | ||
539 | void | |
675dcf4f MK |
540 | print_address_symbolic (CORE_ADDR addr, struct ui_file *stream, |
541 | int do_demangle, char *leadin) | |
dfcd3bfb JM |
542 | { |
543 | char *name = NULL; | |
544 | char *filename = NULL; | |
545 | int unmapped = 0; | |
546 | int offset = 0; | |
547 | int line = 0; | |
548 | ||
675dcf4f | 549 | /* Throw away both name and filename. */ |
2f9429ae AC |
550 | struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name); |
551 | make_cleanup (free_current_contents, &filename); | |
dfcd3bfb | 552 | |
675dcf4f MK |
553 | if (build_address_symbolic (addr, do_demangle, &name, &offset, |
554 | &filename, &line, &unmapped)) | |
2f9429ae AC |
555 | { |
556 | do_cleanups (cleanup_chain); | |
557 | return; | |
558 | } | |
dfcd3bfb JM |
559 | |
560 | fputs_filtered (leadin, stream); | |
561 | if (unmapped) | |
562 | fputs_filtered ("<*", stream); | |
563 | else | |
564 | fputs_filtered ("<", stream); | |
565 | fputs_filtered (name, stream); | |
566 | if (offset != 0) | |
567 | fprintf_filtered (stream, "+%u", (unsigned int) offset); | |
568 | ||
569 | /* Append source filename and line number if desired. Give specific | |
570 | line # of this addr, if we have it; else line # of the nearest symbol. */ | |
571 | if (print_symbol_filename && filename != NULL) | |
572 | { | |
573 | if (line != -1) | |
574 | fprintf_filtered (stream, " at %s:%d", filename, line); | |
575 | else | |
576 | fprintf_filtered (stream, " in %s", filename); | |
577 | } | |
578 | if (unmapped) | |
579 | fputs_filtered ("*>", stream); | |
580 | else | |
581 | fputs_filtered (">", stream); | |
582 | ||
583 | do_cleanups (cleanup_chain); | |
584 | } | |
585 | ||
586 | /* Given an address ADDR return all the elements needed to print the | |
587 | address in a symbolic form. NAME can be mangled or not depending | |
588 | on DO_DEMANGLE (and also on the asm_demangle global variable, | |
589 | manipulated via ''set print asm-demangle''). Return 0 in case of | |
590 | success, when all the info in the OUT paramters is valid. Return 1 | |
591 | otherwise. */ | |
592 | int | |
593 | build_address_symbolic (CORE_ADDR addr, /* IN */ | |
594 | int do_demangle, /* IN */ | |
595 | char **name, /* OUT */ | |
596 | int *offset, /* OUT */ | |
597 | char **filename, /* OUT */ | |
598 | int *line, /* OUT */ | |
599 | int *unmapped) /* OUT */ | |
c906108c SS |
600 | { |
601 | struct minimal_symbol *msymbol; | |
602 | struct symbol *symbol; | |
c906108c | 603 | CORE_ADDR name_location = 0; |
714835d5 | 604 | struct obj_section *section = NULL; |
dfcd3bfb JM |
605 | char *name_temp = ""; |
606 | ||
675dcf4f | 607 | /* Let's say it is unmapped. */ |
dfcd3bfb | 608 | *unmapped = 0; |
c906108c | 609 | |
dfcd3bfb | 610 | /* Determine if the address is in an overlay, and whether it is |
675dcf4f | 611 | mapped. */ |
c906108c SS |
612 | if (overlay_debugging) |
613 | { | |
614 | section = find_pc_overlay (addr); | |
615 | if (pc_in_unmapped_range (addr, section)) | |
616 | { | |
dfcd3bfb | 617 | *unmapped = 1; |
c906108c SS |
618 | addr = overlay_mapped_address (addr, section); |
619 | } | |
620 | } | |
621 | ||
c906108c SS |
622 | /* First try to find the address in the symbol table, then |
623 | in the minsyms. Take the closest one. */ | |
624 | ||
625 | /* This is defective in the sense that it only finds text symbols. So | |
626 | really this is kind of pointless--we should make sure that the | |
627 | minimal symbols have everything we need (by changing that we could | |
628 | save some memory, but for many debug format--ELF/DWARF or | |
629 | anything/stabs--it would be inconvenient to eliminate those minimal | |
630 | symbols anyway). */ | |
631 | msymbol = lookup_minimal_symbol_by_pc_section (addr, section); | |
632 | symbol = find_pc_sect_function (addr, section); | |
633 | ||
634 | if (symbol) | |
635 | { | |
636 | name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)); | |
406fc7fb | 637 | if (do_demangle || asm_demangle) |
de5ad195 | 638 | name_temp = SYMBOL_PRINT_NAME (symbol); |
c906108c | 639 | else |
3567439c | 640 | name_temp = SYMBOL_LINKAGE_NAME (symbol); |
c906108c SS |
641 | } |
642 | ||
643 | if (msymbol != NULL) | |
644 | { | |
645 | if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL) | |
646 | { | |
647 | /* The msymbol is closer to the address than the symbol; | |
648 | use the msymbol instead. */ | |
649 | symbol = 0; | |
c906108c | 650 | name_location = SYMBOL_VALUE_ADDRESS (msymbol); |
406fc7fb | 651 | if (do_demangle || asm_demangle) |
de5ad195 | 652 | name_temp = SYMBOL_PRINT_NAME (msymbol); |
c906108c | 653 | else |
3567439c | 654 | name_temp = SYMBOL_LINKAGE_NAME (msymbol); |
c906108c SS |
655 | } |
656 | } | |
657 | if (symbol == NULL && msymbol == NULL) | |
dfcd3bfb | 658 | return 1; |
c906108c | 659 | |
c906108c SS |
660 | /* If the nearest symbol is too far away, don't print anything symbolic. */ |
661 | ||
662 | /* For when CORE_ADDR is larger than unsigned int, we do math in | |
663 | CORE_ADDR. But when we detect unsigned wraparound in the | |
664 | CORE_ADDR math, we ignore this test and print the offset, | |
665 | because addr+max_symbolic_offset has wrapped through the end | |
666 | of the address space back to the beginning, giving bogus comparison. */ | |
667 | if (addr > name_location + max_symbolic_offset | |
668 | && name_location + max_symbolic_offset > name_location) | |
dfcd3bfb | 669 | return 1; |
c906108c | 670 | |
dfcd3bfb JM |
671 | *offset = addr - name_location; |
672 | ||
673 | *name = xstrdup (name_temp); | |
c906108c | 674 | |
c906108c SS |
675 | if (print_symbol_filename) |
676 | { | |
677 | struct symtab_and_line sal; | |
678 | ||
679 | sal = find_pc_sect_line (addr, section, 0); | |
680 | ||
681 | if (sal.symtab) | |
dfcd3bfb JM |
682 | { |
683 | *filename = xstrdup (sal.symtab->filename); | |
684 | *line = sal.line; | |
685 | } | |
c906108c | 686 | } |
dfcd3bfb | 687 | return 0; |
c906108c SS |
688 | } |
689 | ||
c906108c SS |
690 | |
691 | /* Print address ADDR symbolically on STREAM. | |
692 | First print it as a number. Then perhaps print | |
693 | <SYMBOL + OFFSET> after the number. */ | |
694 | ||
695 | void | |
fba45db2 | 696 | print_address (CORE_ADDR addr, struct ui_file *stream) |
c906108c | 697 | { |
ed49a04f | 698 | fputs_filtered (paddress (addr), stream); |
c906108c SS |
699 | print_address_symbolic (addr, stream, asm_demangle, " "); |
700 | } | |
701 | ||
702 | /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE | |
703 | controls whether to print the symbolic name "raw" or demangled. | |
704 | Global setting "addressprint" controls whether to print hex address | |
705 | or not. */ | |
706 | ||
707 | void | |
675dcf4f MK |
708 | print_address_demangle (CORE_ADDR addr, struct ui_file *stream, |
709 | int do_demangle) | |
c906108c | 710 | { |
79a45b7d TT |
711 | struct value_print_options opts; |
712 | get_user_print_options (&opts); | |
c906108c SS |
713 | if (addr == 0) |
714 | { | |
715 | fprintf_filtered (stream, "0"); | |
716 | } | |
79a45b7d | 717 | else if (opts.addressprint) |
c906108c | 718 | { |
ed49a04f | 719 | fputs_filtered (paddress (addr), stream); |
c906108c SS |
720 | print_address_symbolic (addr, stream, do_demangle, " "); |
721 | } | |
722 | else | |
723 | { | |
724 | print_address_symbolic (addr, stream, do_demangle, ""); | |
725 | } | |
726 | } | |
727 | \f | |
728 | ||
729 | /* These are the types that $__ will get after an examine command of one | |
730 | of these sizes. */ | |
731 | ||
732 | static struct type *examine_i_type; | |
733 | ||
734 | static struct type *examine_b_type; | |
735 | static struct type *examine_h_type; | |
736 | static struct type *examine_w_type; | |
737 | static struct type *examine_g_type; | |
738 | ||
739 | /* Examine data at address ADDR in format FMT. | |
740 | Fetch it from memory and print on gdb_stdout. */ | |
741 | ||
742 | static void | |
00a4c844 | 743 | do_examine (struct format_data fmt, CORE_ADDR addr) |
c906108c | 744 | { |
52f0bd74 AC |
745 | char format = 0; |
746 | char size; | |
747 | int count = 1; | |
c906108c | 748 | struct type *val_type = NULL; |
52f0bd74 AC |
749 | int i; |
750 | int maxelts; | |
79a45b7d | 751 | struct value_print_options opts; |
c906108c SS |
752 | |
753 | format = fmt.format; | |
754 | size = fmt.size; | |
755 | count = fmt.count; | |
756 | next_address = addr; | |
c906108c SS |
757 | |
758 | /* String or instruction format implies fetch single bytes | |
759 | regardless of the specified size. */ | |
760 | if (format == 's' || format == 'i') | |
761 | size = 'b'; | |
762 | ||
763 | if (format == 'i') | |
764 | val_type = examine_i_type; | |
765 | else if (size == 'b') | |
766 | val_type = examine_b_type; | |
767 | else if (size == 'h') | |
768 | val_type = examine_h_type; | |
769 | else if (size == 'w') | |
770 | val_type = examine_w_type; | |
771 | else if (size == 'g') | |
772 | val_type = examine_g_type; | |
773 | ||
774 | maxelts = 8; | |
775 | if (size == 'w') | |
776 | maxelts = 4; | |
777 | if (size == 'g') | |
778 | maxelts = 2; | |
779 | if (format == 's' || format == 'i') | |
780 | maxelts = 1; | |
781 | ||
79a45b7d TT |
782 | get_formatted_print_options (&opts, format); |
783 | ||
c906108c SS |
784 | /* Print as many objects as specified in COUNT, at most maxelts per line, |
785 | with the address of the next one at the start of each line. */ | |
786 | ||
787 | while (count > 0) | |
788 | { | |
789 | QUIT; | |
790 | print_address (next_address, gdb_stdout); | |
791 | printf_filtered (":"); | |
792 | for (i = maxelts; | |
793 | i > 0 && count > 0; | |
794 | i--, count--) | |
795 | { | |
796 | printf_filtered ("\t"); | |
797 | /* Note that print_formatted sets next_address for the next | |
798 | object. */ | |
799 | last_examine_address = next_address; | |
800 | ||
801 | if (last_examine_value) | |
802 | value_free (last_examine_value); | |
803 | ||
804 | /* The value to be displayed is not fetched greedily. | |
5d51a2db MR |
805 | Instead, to avoid the possibility of a fetched value not |
806 | being used, its retrieval is delayed until the print code | |
c5aa993b JM |
807 | uses it. When examining an instruction stream, the |
808 | disassembler will perform its own memory fetch using just | |
809 | the address stored in LAST_EXAMINE_VALUE. FIXME: Should | |
810 | the disassembler be modified so that LAST_EXAMINE_VALUE | |
811 | is left with the byte sequence from the last complete | |
812 | instruction fetched from memory? */ | |
00a4c844 | 813 | last_examine_value = value_at_lazy (val_type, next_address); |
c906108c SS |
814 | |
815 | if (last_examine_value) | |
816 | release_value (last_examine_value); | |
817 | ||
79a45b7d | 818 | print_formatted (last_examine_value, size, &opts, gdb_stdout); |
a4642986 MR |
819 | |
820 | /* Display any branch delay slots following the final insn. */ | |
821 | if (format == 'i' && count == 1) | |
822 | count += branch_delay_insns; | |
c906108c SS |
823 | } |
824 | printf_filtered ("\n"); | |
825 | gdb_flush (gdb_stdout); | |
826 | } | |
827 | } | |
828 | \f | |
829 | static void | |
fba45db2 | 830 | validate_format (struct format_data fmt, char *cmdname) |
c906108c SS |
831 | { |
832 | if (fmt.size != 0) | |
8a3fe4f8 | 833 | error (_("Size letters are meaningless in \"%s\" command."), cmdname); |
c906108c | 834 | if (fmt.count != 1) |
8a3fe4f8 | 835 | error (_("Item count other than 1 is meaningless in \"%s\" command."), |
c906108c | 836 | cmdname); |
ea37ba09 | 837 | if (fmt.format == 'i') |
8a3fe4f8 | 838 | error (_("Format letter \"%c\" is meaningless in \"%s\" command."), |
c906108c SS |
839 | fmt.format, cmdname); |
840 | } | |
841 | ||
675dcf4f | 842 | /* Evaluate string EXP as an expression in the current language and |
c5aa993b | 843 | print the resulting value. EXP may contain a format specifier as the |
675dcf4f | 844 | first argument ("/x myvar" for example, to print myvar in hex). */ |
c906108c SS |
845 | |
846 | static void | |
fba45db2 | 847 | print_command_1 (char *exp, int inspect, int voidprint) |
c906108c SS |
848 | { |
849 | struct expression *expr; | |
52f0bd74 AC |
850 | struct cleanup *old_chain = 0; |
851 | char format = 0; | |
3d6d86c6 | 852 | struct value *val; |
c906108c SS |
853 | struct format_data fmt; |
854 | int cleanup = 0; | |
855 | ||
c906108c SS |
856 | if (exp && *exp == '/') |
857 | { | |
858 | exp++; | |
859 | fmt = decode_format (&exp, last_format, 0); | |
860 | validate_format (fmt, "print"); | |
861 | last_format = format = fmt.format; | |
862 | } | |
863 | else | |
864 | { | |
865 | fmt.count = 1; | |
866 | fmt.format = 0; | |
867 | fmt.size = 0; | |
868 | } | |
869 | ||
870 | if (exp && *exp) | |
871 | { | |
c906108c SS |
872 | struct type *type; |
873 | expr = parse_expression (exp); | |
c13c43fd | 874 | old_chain = make_cleanup (free_current_contents, &expr); |
c906108c SS |
875 | cleanup = 1; |
876 | val = evaluate_expression (expr); | |
c906108c SS |
877 | } |
878 | else | |
879 | val = access_value_history (0); | |
880 | ||
df407dfe AC |
881 | if (voidprint || (val && value_type (val) && |
882 | TYPE_CODE (value_type (val)) != TYPE_CODE_VOID)) | |
c906108c | 883 | { |
79a45b7d | 884 | struct value_print_options opts; |
c906108c SS |
885 | int histindex = record_latest_value (val); |
886 | ||
887 | if (histindex >= 0) | |
df407dfe | 888 | annotate_value_history_begin (histindex, value_type (val)); |
c906108c | 889 | else |
df407dfe | 890 | annotate_value_begin (value_type (val)); |
c906108c SS |
891 | |
892 | if (inspect) | |
675dcf4f MK |
893 | printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", |
894 | exp, histindex); | |
c5aa993b JM |
895 | else if (histindex >= 0) |
896 | printf_filtered ("$%d = ", histindex); | |
c906108c SS |
897 | |
898 | if (histindex >= 0) | |
899 | annotate_value_history_value (); | |
900 | ||
79a45b7d TT |
901 | get_formatted_print_options (&opts, format); |
902 | opts.inspect_it = inspect; | |
903 | ||
904 | print_formatted (val, fmt.size, &opts, gdb_stdout); | |
c906108c SS |
905 | printf_filtered ("\n"); |
906 | ||
907 | if (histindex >= 0) | |
908 | annotate_value_history_end (); | |
909 | else | |
910 | annotate_value_end (); | |
911 | ||
912 | if (inspect) | |
c5aa993b | 913 | printf_unfiltered ("\") )\030"); |
c906108c SS |
914 | } |
915 | ||
916 | if (cleanup) | |
917 | do_cleanups (old_chain); | |
c906108c SS |
918 | } |
919 | ||
c906108c | 920 | static void |
fba45db2 | 921 | print_command (char *exp, int from_tty) |
c906108c SS |
922 | { |
923 | print_command_1 (exp, 0, 1); | |
924 | } | |
925 | ||
675dcf4f | 926 | /* Same as print, except in epoch, it gets its own window. */ |
c906108c | 927 | static void |
fba45db2 | 928 | inspect_command (char *exp, int from_tty) |
c906108c SS |
929 | { |
930 | extern int epoch_interface; | |
931 | ||
932 | print_command_1 (exp, epoch_interface, 1); | |
933 | } | |
934 | ||
675dcf4f | 935 | /* Same as print, except it doesn't print void results. */ |
c906108c | 936 | static void |
fba45db2 | 937 | call_command (char *exp, int from_tty) |
c906108c SS |
938 | { |
939 | print_command_1 (exp, 0, 0); | |
940 | } | |
941 | ||
c906108c | 942 | void |
fba45db2 | 943 | output_command (char *exp, int from_tty) |
c906108c SS |
944 | { |
945 | struct expression *expr; | |
52f0bd74 AC |
946 | struct cleanup *old_chain; |
947 | char format = 0; | |
3d6d86c6 | 948 | struct value *val; |
c906108c | 949 | struct format_data fmt; |
79a45b7d | 950 | struct value_print_options opts; |
c906108c | 951 | |
777ea8f1 DJ |
952 | fmt.size = 0; |
953 | ||
c906108c SS |
954 | if (exp && *exp == '/') |
955 | { | |
956 | exp++; | |
957 | fmt = decode_format (&exp, 0, 0); | |
958 | validate_format (fmt, "output"); | |
959 | format = fmt.format; | |
960 | } | |
961 | ||
962 | expr = parse_expression (exp); | |
c13c43fd | 963 | old_chain = make_cleanup (free_current_contents, &expr); |
c906108c SS |
964 | |
965 | val = evaluate_expression (expr); | |
966 | ||
df407dfe | 967 | annotate_value_begin (value_type (val)); |
c906108c | 968 | |
79a45b7d TT |
969 | get_formatted_print_options (&opts, format); |
970 | print_formatted (val, fmt.size, &opts, gdb_stdout); | |
c906108c SS |
971 | |
972 | annotate_value_end (); | |
973 | ||
2acceee2 JM |
974 | wrap_here (""); |
975 | gdb_flush (gdb_stdout); | |
976 | ||
c906108c SS |
977 | do_cleanups (old_chain); |
978 | } | |
979 | ||
c906108c | 980 | static void |
fba45db2 | 981 | set_command (char *exp, int from_tty) |
c906108c SS |
982 | { |
983 | struct expression *expr = parse_expression (exp); | |
52f0bd74 | 984 | struct cleanup *old_chain = |
c13c43fd | 985 | make_cleanup (free_current_contents, &expr); |
c906108c SS |
986 | evaluate_expression (expr); |
987 | do_cleanups (old_chain); | |
988 | } | |
989 | ||
c906108c | 990 | static void |
fba45db2 | 991 | sym_info (char *arg, int from_tty) |
c906108c SS |
992 | { |
993 | struct minimal_symbol *msymbol; | |
c5aa993b JM |
994 | struct objfile *objfile; |
995 | struct obj_section *osect; | |
c5aa993b JM |
996 | CORE_ADDR addr, sect_addr; |
997 | int matches = 0; | |
998 | unsigned int offset; | |
c906108c SS |
999 | |
1000 | if (!arg) | |
e2e0b3e5 | 1001 | error_no_arg (_("address")); |
c906108c SS |
1002 | |
1003 | addr = parse_and_eval_address (arg); | |
1004 | ALL_OBJSECTIONS (objfile, osect) | |
c5aa993b | 1005 | { |
94277a38 DJ |
1006 | /* Only process each object file once, even if there's a separate |
1007 | debug file. */ | |
1008 | if (objfile->separate_debug_objfile_backlink) | |
1009 | continue; | |
1010 | ||
714835d5 | 1011 | sect_addr = overlay_mapped_address (addr, osect); |
c906108c | 1012 | |
f1f6aadf PA |
1013 | if (obj_section_addr (osect) <= sect_addr |
1014 | && sect_addr < obj_section_endaddr (osect) | |
714835d5 | 1015 | && (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, osect))) |
c5aa993b | 1016 | { |
c14c28ba | 1017 | const char *obj_name, *mapped, *sec_name, *msym_name; |
e2fd701e DE |
1018 | char *loc_string; |
1019 | struct cleanup *old_chain; | |
c14c28ba | 1020 | |
c5aa993b JM |
1021 | matches = 1; |
1022 | offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol); | |
c14c28ba PP |
1023 | mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped"); |
1024 | sec_name = osect->the_bfd_section->name; | |
1025 | msym_name = SYMBOL_PRINT_NAME (msymbol); | |
1026 | ||
e2fd701e DE |
1027 | /* Don't print the offset if it is zero. |
1028 | We assume there's no need to handle i18n of "sym + offset". */ | |
1029 | if (offset) | |
1030 | xasprintf (&loc_string, "%s + %u", msym_name, offset); | |
1031 | else | |
1032 | xasprintf (&loc_string, "%s", msym_name); | |
1033 | ||
1034 | /* Use a cleanup to free loc_string in case the user quits | |
1035 | a pagination request inside printf_filtered. */ | |
1036 | old_chain = make_cleanup (xfree, loc_string); | |
1037 | ||
c14c28ba PP |
1038 | gdb_assert (osect->objfile && osect->objfile->name); |
1039 | obj_name = osect->objfile->name; | |
1040 | ||
1041 | if (MULTI_OBJFILE_P ()) | |
1042 | if (pc_in_unmapped_range (addr, osect)) | |
1043 | if (section_is_overlay (osect)) | |
e2fd701e | 1044 | printf_filtered (_("%s in load address range of " |
c14c28ba | 1045 | "%s overlay section %s of %s\n"), |
e2fd701e | 1046 | loc_string, mapped, sec_name, obj_name); |
c14c28ba | 1047 | else |
e2fd701e | 1048 | printf_filtered (_("%s in load address range of " |
c14c28ba | 1049 | "section %s of %s\n"), |
e2fd701e | 1050 | loc_string, sec_name, obj_name); |
c14c28ba PP |
1051 | else |
1052 | if (section_is_overlay (osect)) | |
e2fd701e DE |
1053 | printf_filtered (_("%s in %s overlay section %s of %s\n"), |
1054 | loc_string, mapped, sec_name, obj_name); | |
c14c28ba | 1055 | else |
e2fd701e DE |
1056 | printf_filtered (_("%s in section %s of %s\n"), |
1057 | loc_string, sec_name, obj_name); | |
c5aa993b | 1058 | else |
c14c28ba PP |
1059 | if (pc_in_unmapped_range (addr, osect)) |
1060 | if (section_is_overlay (osect)) | |
e2fd701e | 1061 | printf_filtered (_("%s in load address range of %s overlay " |
c14c28ba | 1062 | "section %s\n"), |
e2fd701e | 1063 | loc_string, mapped, sec_name); |
c14c28ba | 1064 | else |
e2fd701e DE |
1065 | printf_filtered (_("%s in load address range of section %s\n"), |
1066 | loc_string, sec_name); | |
c14c28ba PP |
1067 | else |
1068 | if (section_is_overlay (osect)) | |
e2fd701e DE |
1069 | printf_filtered (_("%s in %s overlay section %s\n"), |
1070 | loc_string, mapped, sec_name); | |
c14c28ba | 1071 | else |
e2fd701e DE |
1072 | printf_filtered (_("%s in section %s\n"), |
1073 | loc_string, sec_name); | |
1074 | ||
1075 | do_cleanups (old_chain); | |
c5aa993b JM |
1076 | } |
1077 | } | |
c906108c | 1078 | if (matches == 0) |
a3f17187 | 1079 | printf_filtered (_("No symbol matches %s.\n"), arg); |
c906108c SS |
1080 | } |
1081 | ||
c906108c | 1082 | static void |
fba45db2 | 1083 | address_info (char *exp, int from_tty) |
c906108c | 1084 | { |
52f0bd74 AC |
1085 | struct symbol *sym; |
1086 | struct minimal_symbol *msymbol; | |
1087 | long val; | |
714835d5 | 1088 | struct obj_section *section; |
c906108c SS |
1089 | CORE_ADDR load_addr; |
1090 | int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero | |
1091 | if exp is a field of `this'. */ | |
1092 | ||
1093 | if (exp == 0) | |
8a3fe4f8 | 1094 | error (_("Argument required.")); |
c906108c | 1095 | |
176620f1 | 1096 | sym = lookup_symbol (exp, get_selected_block (0), VAR_DOMAIN, |
2570f2b7 | 1097 | &is_a_field_of_this); |
c906108c SS |
1098 | if (sym == NULL) |
1099 | { | |
1100 | if (is_a_field_of_this) | |
1101 | { | |
1102 | printf_filtered ("Symbol \""); | |
1103 | fprintf_symbol_filtered (gdb_stdout, exp, | |
1104 | current_language->la_language, DMGL_ANSI); | |
e2b23ee9 AF |
1105 | printf_filtered ("\" is a field of the local class variable "); |
1106 | if (current_language->la_language == language_objc) | |
2625d86c | 1107 | printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */ |
e2b23ee9 | 1108 | else |
2625d86c | 1109 | printf_filtered ("`this'\n"); |
c906108c SS |
1110 | return; |
1111 | } | |
1112 | ||
1113 | msymbol = lookup_minimal_symbol (exp, NULL, NULL); | |
1114 | ||
1115 | if (msymbol != NULL) | |
1116 | { | |
1117 | load_addr = SYMBOL_VALUE_ADDRESS (msymbol); | |
1118 | ||
1119 | printf_filtered ("Symbol \""); | |
1120 | fprintf_symbol_filtered (gdb_stdout, exp, | |
1121 | current_language->la_language, DMGL_ANSI); | |
1122 | printf_filtered ("\" is at "); | |
ed49a04f | 1123 | fputs_filtered (paddress (load_addr), gdb_stdout); |
c906108c | 1124 | printf_filtered (" in a file compiled without debugging"); |
714835d5 | 1125 | section = SYMBOL_OBJ_SECTION (msymbol); |
c906108c SS |
1126 | if (section_is_overlay (section)) |
1127 | { | |
1128 | load_addr = overlay_unmapped_address (load_addr, section); | |
1129 | printf_filtered (",\n -- loaded at "); | |
ed49a04f | 1130 | fputs_filtered (paddress (load_addr), gdb_stdout); |
714835d5 UW |
1131 | printf_filtered (" in overlay section %s", |
1132 | section->the_bfd_section->name); | |
c906108c SS |
1133 | } |
1134 | printf_filtered (".\n"); | |
1135 | } | |
1136 | else | |
8a3fe4f8 | 1137 | error (_("No symbol \"%s\" in current context."), exp); |
c906108c SS |
1138 | return; |
1139 | } | |
1140 | ||
1141 | printf_filtered ("Symbol \""); | |
3567439c | 1142 | fprintf_symbol_filtered (gdb_stdout, SYMBOL_PRINT_NAME (sym), |
c906108c SS |
1143 | current_language->la_language, DMGL_ANSI); |
1144 | printf_filtered ("\" is "); | |
c5aa993b | 1145 | val = SYMBOL_VALUE (sym); |
714835d5 | 1146 | section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
1147 | |
1148 | switch (SYMBOL_CLASS (sym)) | |
1149 | { | |
1150 | case LOC_CONST: | |
1151 | case LOC_CONST_BYTES: | |
1152 | printf_filtered ("constant"); | |
1153 | break; | |
1154 | ||
1155 | case LOC_LABEL: | |
1156 | printf_filtered ("a label at address "); | |
ed49a04f MD |
1157 | fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)), |
1158 | gdb_stdout); | |
c906108c SS |
1159 | if (section_is_overlay (section)) |
1160 | { | |
1161 | load_addr = overlay_unmapped_address (load_addr, section); | |
1162 | printf_filtered (",\n -- loaded at "); | |
ed49a04f | 1163 | fputs_filtered (paddress (load_addr), gdb_stdout); |
714835d5 UW |
1164 | printf_filtered (" in overlay section %s", |
1165 | section->the_bfd_section->name); | |
c906108c SS |
1166 | } |
1167 | break; | |
1168 | ||
4c2df51b | 1169 | case LOC_COMPUTED: |
a67af2b9 AC |
1170 | /* FIXME: cagney/2004-01-26: It should be possible to |
1171 | unconditionally call the SYMBOL_OPS method when available. | |
d3efc286 | 1172 | Unfortunately DWARF 2 stores the frame-base (instead of the |
a67af2b9 AC |
1173 | function) location in a function's symbol. Oops! For the |
1174 | moment enable this when/where applicable. */ | |
1175 | SYMBOL_OPS (sym)->describe_location (sym, gdb_stdout); | |
4c2df51b DJ |
1176 | break; |
1177 | ||
c906108c | 1178 | case LOC_REGISTER: |
2a2d4dc3 AS |
1179 | if (SYMBOL_IS_ARGUMENT (sym)) |
1180 | printf_filtered (_("an argument in register %s"), | |
1181 | gdbarch_register_name (current_gdbarch, val)); | |
1182 | else | |
1183 | printf_filtered (_("a variable in register %s"), | |
c9f4d572 | 1184 | gdbarch_register_name (current_gdbarch, val)); |
c906108c SS |
1185 | break; |
1186 | ||
1187 | case LOC_STATIC: | |
a3f17187 | 1188 | printf_filtered (_("static storage at address ")); |
ed49a04f MD |
1189 | fputs_filtered (paddress (load_addr = SYMBOL_VALUE_ADDRESS (sym)), |
1190 | gdb_stdout); | |
c906108c SS |
1191 | if (section_is_overlay (section)) |
1192 | { | |
1193 | load_addr = overlay_unmapped_address (load_addr, section); | |
a3f17187 | 1194 | printf_filtered (_(",\n -- loaded at ")); |
ed49a04f | 1195 | fputs_filtered (paddress (load_addr), gdb_stdout); |
714835d5 UW |
1196 | printf_filtered (_(" in overlay section %s"), |
1197 | section->the_bfd_section->name); | |
c906108c SS |
1198 | } |
1199 | break; | |
1200 | ||
c906108c | 1201 | case LOC_REGPARM_ADDR: |
675dcf4f | 1202 | printf_filtered (_("address of an argument in register %s"), |
c9f4d572 | 1203 | gdbarch_register_name (current_gdbarch, val)); |
c906108c SS |
1204 | break; |
1205 | ||
1206 | case LOC_ARG: | |
a3f17187 | 1207 | printf_filtered (_("an argument at offset %ld"), val); |
c906108c SS |
1208 | break; |
1209 | ||
c906108c | 1210 | case LOC_LOCAL: |
a3f17187 | 1211 | printf_filtered (_("a local variable at frame offset %ld"), val); |
c906108c SS |
1212 | break; |
1213 | ||
1214 | case LOC_REF_ARG: | |
a3f17187 | 1215 | printf_filtered (_("a reference argument at offset %ld"), val); |
c906108c SS |
1216 | break; |
1217 | ||
c906108c | 1218 | case LOC_TYPEDEF: |
a3f17187 | 1219 | printf_filtered (_("a typedef")); |
c906108c SS |
1220 | break; |
1221 | ||
1222 | case LOC_BLOCK: | |
a3f17187 | 1223 | printf_filtered (_("a function at address ")); |
675dcf4f | 1224 | load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); |
ed49a04f | 1225 | fputs_filtered (paddress (load_addr), gdb_stdout); |
c906108c SS |
1226 | if (section_is_overlay (section)) |
1227 | { | |
1228 | load_addr = overlay_unmapped_address (load_addr, section); | |
a3f17187 | 1229 | printf_filtered (_(",\n -- loaded at ")); |
ed49a04f | 1230 | fputs_filtered (paddress (load_addr), gdb_stdout); |
714835d5 UW |
1231 | printf_filtered (_(" in overlay section %s"), |
1232 | section->the_bfd_section->name); | |
c906108c SS |
1233 | } |
1234 | break; | |
1235 | ||
1236 | case LOC_UNRESOLVED: | |
1237 | { | |
1238 | struct minimal_symbol *msym; | |
1239 | ||
3567439c | 1240 | msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), NULL, NULL); |
c906108c SS |
1241 | if (msym == NULL) |
1242 | printf_filtered ("unresolved"); | |
1243 | else | |
1244 | { | |
714835d5 | 1245 | section = SYMBOL_OBJ_SECTION (msym); |
675dcf4f | 1246 | load_addr = SYMBOL_VALUE_ADDRESS (msym); |
e0740f77 JK |
1247 | |
1248 | if (section | |
1249 | && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0) | |
1250 | printf_filtered (_("a thread-local variable at offset %s " | |
1251 | "in the thread-local storage for `%s'"), | |
1252 | paddr_nz (load_addr), section->objfile->name); | |
1253 | else | |
c906108c | 1254 | { |
e0740f77 | 1255 | printf_filtered (_("static storage at address ")); |
ed49a04f | 1256 | fputs_filtered (paddress (load_addr), gdb_stdout); |
e0740f77 JK |
1257 | if (section_is_overlay (section)) |
1258 | { | |
1259 | load_addr = overlay_unmapped_address (load_addr, section); | |
1260 | printf_filtered (_(",\n -- loaded at ")); | |
1261 | fputs_filtered (paddress (load_addr), gdb_stdout); | |
1262 | printf_filtered (_(" in overlay section %s"), | |
1263 | section->the_bfd_section->name); | |
1264 | } | |
c906108c SS |
1265 | } |
1266 | } | |
1267 | } | |
1268 | break; | |
1269 | ||
c906108c | 1270 | case LOC_OPTIMIZED_OUT: |
a3f17187 | 1271 | printf_filtered (_("optimized out")); |
c906108c | 1272 | break; |
c5aa993b | 1273 | |
c906108c | 1274 | default: |
a3f17187 | 1275 | printf_filtered (_("of unknown (botched) type")); |
c906108c SS |
1276 | break; |
1277 | } | |
1278 | printf_filtered (".\n"); | |
1279 | } | |
1280 | \f | |
675dcf4f MK |
1281 | |
1282 | static void | |
fba45db2 | 1283 | x_command (char *exp, int from_tty) |
c906108c SS |
1284 | { |
1285 | struct expression *expr; | |
1286 | struct format_data fmt; | |
1287 | struct cleanup *old_chain; | |
1288 | struct value *val; | |
1289 | ||
1290 | fmt.format = last_format; | |
1291 | fmt.size = last_size; | |
1292 | fmt.count = 1; | |
1293 | ||
1294 | if (exp && *exp == '/') | |
1295 | { | |
1296 | exp++; | |
1297 | fmt = decode_format (&exp, last_format, last_size); | |
1298 | } | |
1299 | ||
1300 | /* If we have an expression, evaluate it and use it as the address. */ | |
1301 | ||
1302 | if (exp != 0 && *exp != 0) | |
1303 | { | |
1304 | expr = parse_expression (exp); | |
675dcf4f MK |
1305 | /* Cause expression not to be there any more if this command is |
1306 | repeated with Newline. But don't clobber a user-defined | |
1307 | command's definition. */ | |
c906108c SS |
1308 | if (from_tty) |
1309 | *exp = 0; | |
c13c43fd | 1310 | old_chain = make_cleanup (free_current_contents, &expr); |
c906108c | 1311 | val = evaluate_expression (expr); |
df407dfe | 1312 | if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF) |
c906108c SS |
1313 | val = value_ind (val); |
1314 | /* In rvalue contexts, such as this, functions are coerced into | |
c5aa993b | 1315 | pointers to functions. This makes "x/i main" work. */ |
c0d8fd9a | 1316 | if (/* last_format == 'i' && */ |
df407dfe | 1317 | TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC |
c5aa993b | 1318 | && VALUE_LVAL (val) == lval_memory) |
c906108c SS |
1319 | next_address = VALUE_ADDRESS (val); |
1320 | else | |
1aa20aa8 | 1321 | next_address = value_as_address (val); |
c906108c SS |
1322 | do_cleanups (old_chain); |
1323 | } | |
1324 | ||
00a4c844 | 1325 | do_examine (fmt, next_address); |
c906108c | 1326 | |
675dcf4f MK |
1327 | /* If the examine succeeds, we remember its size and format for next |
1328 | time. */ | |
c906108c SS |
1329 | last_size = fmt.size; |
1330 | last_format = fmt.format; | |
1331 | ||
1332 | /* Set a couple of internal variables if appropriate. */ | |
1333 | if (last_examine_value) | |
1334 | { | |
1335 | /* Make last address examined available to the user as $_. Use | |
c5aa993b | 1336 | the correct pointer type. */ |
4478b372 | 1337 | struct type *pointer_type |
df407dfe | 1338 | = lookup_pointer_type (value_type (last_examine_value)); |
c906108c | 1339 | set_internalvar (lookup_internalvar ("_"), |
4478b372 JB |
1340 | value_from_pointer (pointer_type, |
1341 | last_examine_address)); | |
c5aa993b | 1342 | |
675dcf4f MK |
1343 | /* Make contents of last address examined available to the user |
1344 | as $__. If the last value has not been fetched from memory | |
1345 | then don't fetch it now; instead mark it by voiding the $__ | |
1346 | variable. */ | |
d69fe07e | 1347 | if (value_lazy (last_examine_value)) |
c906108c SS |
1348 | set_internalvar (lookup_internalvar ("__"), |
1349 | allocate_value (builtin_type_void)); | |
1350 | else | |
1351 | set_internalvar (lookup_internalvar ("__"), last_examine_value); | |
1352 | } | |
1353 | } | |
c906108c | 1354 | \f |
c5aa993b | 1355 | |
c906108c SS |
1356 | /* Add an expression to the auto-display chain. |
1357 | Specify the expression. */ | |
1358 | ||
1359 | static void | |
fba45db2 | 1360 | display_command (char *exp, int from_tty) |
c906108c SS |
1361 | { |
1362 | struct format_data fmt; | |
52f0bd74 AC |
1363 | struct expression *expr; |
1364 | struct display *new; | |
c906108c SS |
1365 | int display_it = 1; |
1366 | ||
1367 | #if defined(TUI) | |
021e7609 AC |
1368 | /* NOTE: cagney/2003-02-13 The `tui_active' was previously |
1369 | `tui_version'. */ | |
fd33e6cb | 1370 | if (tui_active && exp != NULL && *exp == '$') |
080ce8c0 | 1371 | display_it = (tui_set_layout_for_display_command (exp) == TUI_FAILURE); |
c906108c SS |
1372 | #endif |
1373 | ||
1374 | if (display_it) | |
1375 | { | |
1376 | if (exp == 0) | |
1377 | { | |
1378 | do_displays (); | |
1379 | return; | |
1380 | } | |
1381 | ||
1382 | if (*exp == '/') | |
1383 | { | |
1384 | exp++; | |
1385 | fmt = decode_format (&exp, 0, 0); | |
1386 | if (fmt.size && fmt.format == 0) | |
1387 | fmt.format = 'x'; | |
1388 | if (fmt.format == 'i' || fmt.format == 's') | |
1389 | fmt.size = 'b'; | |
1390 | } | |
1391 | else | |
1392 | { | |
1393 | fmt.format = 0; | |
1394 | fmt.size = 0; | |
1395 | fmt.count = 0; | |
1396 | } | |
1397 | ||
1398 | innermost_block = 0; | |
1399 | expr = parse_expression (exp); | |
1400 | ||
1401 | new = (struct display *) xmalloc (sizeof (struct display)); | |
1402 | ||
fa8a61dc | 1403 | new->exp_string = xstrdup (exp); |
c906108c SS |
1404 | new->exp = expr; |
1405 | new->block = innermost_block; | |
1406 | new->next = display_chain; | |
1407 | new->number = ++display_number; | |
1408 | new->format = fmt; | |
b5de0fa7 | 1409 | new->enabled_p = 1; |
c906108c SS |
1410 | display_chain = new; |
1411 | ||
1412 | if (from_tty && target_has_execution) | |
1413 | do_one_display (new); | |
1414 | ||
1415 | dont_repeat (); | |
1416 | } | |
1417 | } | |
1418 | ||
1419 | static void | |
fba45db2 | 1420 | free_display (struct display *d) |
c906108c | 1421 | { |
fa8a61dc | 1422 | xfree (d->exp_string); |
b8c9b27d KB |
1423 | xfree (d->exp); |
1424 | xfree (d); | |
c906108c SS |
1425 | } |
1426 | ||
675dcf4f MK |
1427 | /* Clear out the display_chain. Done when new symtabs are loaded, |
1428 | since this invalidates the types stored in many expressions. */ | |
c906108c SS |
1429 | |
1430 | void | |
fba45db2 | 1431 | clear_displays (void) |
c906108c | 1432 | { |
52f0bd74 | 1433 | struct display *d; |
c906108c SS |
1434 | |
1435 | while ((d = display_chain) != NULL) | |
1436 | { | |
c906108c | 1437 | display_chain = d->next; |
fa8a61dc | 1438 | free_display (d); |
c906108c SS |
1439 | } |
1440 | } | |
1441 | ||
1442 | /* Delete the auto-display number NUM. */ | |
1443 | ||
1444 | static void | |
fba45db2 | 1445 | delete_display (int num) |
c906108c | 1446 | { |
52f0bd74 | 1447 | struct display *d1, *d; |
c906108c SS |
1448 | |
1449 | if (!display_chain) | |
8a3fe4f8 | 1450 | error (_("No display number %d."), num); |
c906108c SS |
1451 | |
1452 | if (display_chain->number == num) | |
1453 | { | |
1454 | d1 = display_chain; | |
1455 | display_chain = d1->next; | |
1456 | free_display (d1); | |
1457 | } | |
1458 | else | |
c5aa993b | 1459 | for (d = display_chain;; d = d->next) |
c906108c SS |
1460 | { |
1461 | if (d->next == 0) | |
8a3fe4f8 | 1462 | error (_("No display number %d."), num); |
c906108c SS |
1463 | if (d->next->number == num) |
1464 | { | |
1465 | d1 = d->next; | |
1466 | d->next = d1->next; | |
1467 | free_display (d1); | |
1468 | break; | |
1469 | } | |
1470 | } | |
1471 | } | |
1472 | ||
1473 | /* Delete some values from the auto-display chain. | |
1474 | Specify the element numbers. */ | |
1475 | ||
1476 | static void | |
fba45db2 | 1477 | undisplay_command (char *args, int from_tty) |
c906108c | 1478 | { |
52f0bd74 AC |
1479 | char *p = args; |
1480 | char *p1; | |
1481 | int num; | |
c906108c SS |
1482 | |
1483 | if (args == 0) | |
1484 | { | |
1485 | if (query ("Delete all auto-display expressions? ")) | |
1486 | clear_displays (); | |
1487 | dont_repeat (); | |
1488 | return; | |
1489 | } | |
1490 | ||
1491 | while (*p) | |
1492 | { | |
1493 | p1 = p; | |
c5aa993b JM |
1494 | while (*p1 >= '0' && *p1 <= '9') |
1495 | p1++; | |
c906108c | 1496 | if (*p1 && *p1 != ' ' && *p1 != '\t') |
8a3fe4f8 | 1497 | error (_("Arguments must be display numbers.")); |
c906108c SS |
1498 | |
1499 | num = atoi (p); | |
1500 | ||
1501 | delete_display (num); | |
1502 | ||
1503 | p = p1; | |
c5aa993b JM |
1504 | while (*p == ' ' || *p == '\t') |
1505 | p++; | |
c906108c SS |
1506 | } |
1507 | dont_repeat (); | |
1508 | } | |
1509 | ||
1510 | /* Display a single auto-display. | |
1511 | Do nothing if the display cannot be printed in the current context, | |
1512 | or if the display is disabled. */ | |
1513 | ||
1514 | static void | |
fba45db2 | 1515 | do_one_display (struct display *d) |
c906108c SS |
1516 | { |
1517 | int within_current_scope; | |
1518 | ||
b5de0fa7 | 1519 | if (d->enabled_p == 0) |
c906108c SS |
1520 | return; |
1521 | ||
1522 | if (d->block) | |
ae767bfb | 1523 | within_current_scope = contained_in (get_selected_block (0), d->block); |
c906108c SS |
1524 | else |
1525 | within_current_scope = 1; | |
1526 | if (!within_current_scope) | |
1527 | return; | |
1528 | ||
1529 | current_display_number = d->number; | |
1530 | ||
1531 | annotate_display_begin (); | |
1532 | printf_filtered ("%d", d->number); | |
1533 | annotate_display_number_end (); | |
1534 | printf_filtered (": "); | |
1535 | if (d->format.size) | |
1536 | { | |
1537 | CORE_ADDR addr; | |
3d6d86c6 | 1538 | struct value *val; |
c906108c SS |
1539 | |
1540 | annotate_display_format (); | |
1541 | ||
1542 | printf_filtered ("x/"); | |
1543 | if (d->format.count != 1) | |
1544 | printf_filtered ("%d", d->format.count); | |
1545 | printf_filtered ("%c", d->format.format); | |
1546 | if (d->format.format != 'i' && d->format.format != 's') | |
1547 | printf_filtered ("%c", d->format.size); | |
1548 | printf_filtered (" "); | |
1549 | ||
1550 | annotate_display_expression (); | |
1551 | ||
fa8a61dc | 1552 | puts_filtered (d->exp_string); |
c906108c SS |
1553 | annotate_display_expression_end (); |
1554 | ||
6a2eb474 | 1555 | if (d->format.count != 1 || d->format.format == 'i') |
c906108c SS |
1556 | printf_filtered ("\n"); |
1557 | else | |
1558 | printf_filtered (" "); | |
c5aa993b | 1559 | |
c906108c | 1560 | val = evaluate_expression (d->exp); |
1aa20aa8 | 1561 | addr = value_as_address (val); |
c906108c | 1562 | if (d->format.format == 'i') |
bf6ae464 | 1563 | addr = gdbarch_addr_bits_remove (current_gdbarch, addr); |
c906108c SS |
1564 | |
1565 | annotate_display_value (); | |
1566 | ||
00a4c844 | 1567 | do_examine (d->format, addr); |
c906108c SS |
1568 | } |
1569 | else | |
1570 | { | |
79a45b7d TT |
1571 | struct value_print_options opts; |
1572 | ||
c906108c SS |
1573 | annotate_display_format (); |
1574 | ||
1575 | if (d->format.format) | |
1576 | printf_filtered ("/%c ", d->format.format); | |
1577 | ||
1578 | annotate_display_expression (); | |
1579 | ||
fa8a61dc | 1580 | puts_filtered (d->exp_string); |
c906108c SS |
1581 | annotate_display_expression_end (); |
1582 | ||
1583 | printf_filtered (" = "); | |
1584 | ||
1585 | annotate_display_expression (); | |
1586 | ||
79a45b7d | 1587 | get_formatted_print_options (&opts, d->format.format); |
c906108c | 1588 | print_formatted (evaluate_expression (d->exp), |
79a45b7d | 1589 | d->format.size, &opts, gdb_stdout); |
c906108c SS |
1590 | printf_filtered ("\n"); |
1591 | } | |
1592 | ||
1593 | annotate_display_end (); | |
1594 | ||
1595 | gdb_flush (gdb_stdout); | |
1596 | current_display_number = -1; | |
1597 | } | |
1598 | ||
1599 | /* Display all of the values on the auto-display chain which can be | |
1600 | evaluated in the current scope. */ | |
1601 | ||
1602 | void | |
fba45db2 | 1603 | do_displays (void) |
c906108c | 1604 | { |
52f0bd74 | 1605 | struct display *d; |
c906108c SS |
1606 | |
1607 | for (d = display_chain; d; d = d->next) | |
1608 | do_one_display (d); | |
1609 | } | |
1610 | ||
1611 | /* Delete the auto-display which we were in the process of displaying. | |
1612 | This is done when there is an error or a signal. */ | |
1613 | ||
1614 | void | |
fba45db2 | 1615 | disable_display (int num) |
c906108c | 1616 | { |
52f0bd74 | 1617 | struct display *d; |
c906108c SS |
1618 | |
1619 | for (d = display_chain; d; d = d->next) | |
1620 | if (d->number == num) | |
1621 | { | |
b5de0fa7 | 1622 | d->enabled_p = 0; |
c906108c SS |
1623 | return; |
1624 | } | |
a3f17187 | 1625 | printf_unfiltered (_("No display number %d.\n"), num); |
c906108c | 1626 | } |
c5aa993b | 1627 | |
c906108c | 1628 | void |
fba45db2 | 1629 | disable_current_display (void) |
c906108c SS |
1630 | { |
1631 | if (current_display_number >= 0) | |
1632 | { | |
1633 | disable_display (current_display_number); | |
675dcf4f MK |
1634 | fprintf_unfiltered (gdb_stderr, _("\ |
1635 | Disabling display %d to avoid infinite recursion.\n"), | |
c5aa993b | 1636 | current_display_number); |
c906108c SS |
1637 | } |
1638 | current_display_number = -1; | |
1639 | } | |
1640 | ||
1641 | static void | |
fba45db2 | 1642 | display_info (char *ignore, int from_tty) |
c906108c | 1643 | { |
52f0bd74 | 1644 | struct display *d; |
c906108c SS |
1645 | |
1646 | if (!display_chain) | |
a3f17187 | 1647 | printf_unfiltered (_("There are no auto-display expressions now.\n")); |
c906108c | 1648 | else |
a3f17187 AC |
1649 | printf_filtered (_("Auto-display expressions now in effect:\n\ |
1650 | Num Enb Expression\n")); | |
c906108c SS |
1651 | |
1652 | for (d = display_chain; d; d = d->next) | |
1653 | { | |
b5de0fa7 | 1654 | printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]); |
c906108c SS |
1655 | if (d->format.size) |
1656 | printf_filtered ("/%d%c%c ", d->format.count, d->format.size, | |
c5aa993b | 1657 | d->format.format); |
c906108c SS |
1658 | else if (d->format.format) |
1659 | printf_filtered ("/%c ", d->format.format); | |
fa8a61dc | 1660 | puts_filtered (d->exp_string); |
ae767bfb | 1661 | if (d->block && !contained_in (get_selected_block (0), d->block)) |
a3f17187 | 1662 | printf_filtered (_(" (cannot be evaluated in the current context)")); |
c906108c SS |
1663 | printf_filtered ("\n"); |
1664 | gdb_flush (gdb_stdout); | |
1665 | } | |
1666 | } | |
1667 | ||
1668 | static void | |
fba45db2 | 1669 | enable_display (char *args, int from_tty) |
c906108c | 1670 | { |
52f0bd74 AC |
1671 | char *p = args; |
1672 | char *p1; | |
1673 | int num; | |
1674 | struct display *d; | |
c906108c SS |
1675 | |
1676 | if (p == 0) | |
1677 | { | |
1678 | for (d = display_chain; d; d = d->next) | |
b5de0fa7 | 1679 | d->enabled_p = 1; |
c906108c SS |
1680 | } |
1681 | else | |
1682 | while (*p) | |
1683 | { | |
1684 | p1 = p; | |
1685 | while (*p1 >= '0' && *p1 <= '9') | |
1686 | p1++; | |
1687 | if (*p1 && *p1 != ' ' && *p1 != '\t') | |
8a3fe4f8 | 1688 | error (_("Arguments must be display numbers.")); |
c5aa993b | 1689 | |
c906108c | 1690 | num = atoi (p); |
c5aa993b | 1691 | |
c906108c SS |
1692 | for (d = display_chain; d; d = d->next) |
1693 | if (d->number == num) | |
1694 | { | |
b5de0fa7 | 1695 | d->enabled_p = 1; |
c906108c SS |
1696 | goto win; |
1697 | } | |
a3f17187 | 1698 | printf_unfiltered (_("No display number %d.\n"), num); |
c906108c SS |
1699 | win: |
1700 | p = p1; | |
1701 | while (*p == ' ' || *p == '\t') | |
1702 | p++; | |
1703 | } | |
1704 | } | |
1705 | ||
c906108c | 1706 | static void |
fba45db2 | 1707 | disable_display_command (char *args, int from_tty) |
c906108c | 1708 | { |
52f0bd74 AC |
1709 | char *p = args; |
1710 | char *p1; | |
1711 | struct display *d; | |
c906108c SS |
1712 | |
1713 | if (p == 0) | |
1714 | { | |
1715 | for (d = display_chain; d; d = d->next) | |
b5de0fa7 | 1716 | d->enabled_p = 0; |
c906108c SS |
1717 | } |
1718 | else | |
1719 | while (*p) | |
1720 | { | |
1721 | p1 = p; | |
1722 | while (*p1 >= '0' && *p1 <= '9') | |
1723 | p1++; | |
1724 | if (*p1 && *p1 != ' ' && *p1 != '\t') | |
8a3fe4f8 | 1725 | error (_("Arguments must be display numbers.")); |
c5aa993b | 1726 | |
c906108c SS |
1727 | disable_display (atoi (p)); |
1728 | ||
1729 | p = p1; | |
1730 | while (*p == ' ' || *p == '\t') | |
1731 | p++; | |
1732 | } | |
1733 | } | |
c906108c | 1734 | \f |
c5aa993b | 1735 | |
675dcf4f | 1736 | /* Print the value in stack frame FRAME of a variable specified by a |
aad95b57 TT |
1737 | struct symbol. NAME is the name to print; if NULL then VAR's print |
1738 | name will be used. STREAM is the ui_file on which to print the | |
1739 | value. INDENT specifies the number of indent levels to print | |
1740 | before printing the variable name. */ | |
c906108c SS |
1741 | |
1742 | void | |
aad95b57 TT |
1743 | print_variable_and_value (const char *name, struct symbol *var, |
1744 | struct frame_info *frame, | |
1745 | struct ui_file *stream, int indent) | |
c906108c | 1746 | { |
aad95b57 | 1747 | struct value *val; |
79a45b7d | 1748 | struct value_print_options opts; |
c906108c | 1749 | |
aad95b57 TT |
1750 | if (!name) |
1751 | name = SYMBOL_PRINT_NAME (var); | |
1752 | ||
1753 | fprintf_filtered (stream, "%s%s = ", n_spaces (2 * indent), name); | |
1754 | ||
1755 | val = read_var_value (var, frame); | |
79a45b7d | 1756 | get_user_print_options (&opts); |
aad95b57 TT |
1757 | common_val_print (val, stream, indent, &opts, current_language); |
1758 | fprintf_filtered (stream, "\n"); | |
c906108c SS |
1759 | } |
1760 | ||
c906108c | 1761 | static void |
fba45db2 | 1762 | printf_command (char *arg, int from_tty) |
c906108c | 1763 | { |
52f0bd74 AC |
1764 | char *f = NULL; |
1765 | char *s = arg; | |
c906108c | 1766 | char *string = NULL; |
3d6d86c6 | 1767 | struct value **val_args; |
c906108c SS |
1768 | char *substrings; |
1769 | char *current_substring; | |
1770 | int nargs = 0; | |
1771 | int allocated_args = 20; | |
1772 | struct cleanup *old_cleanups; | |
1773 | ||
675dcf4f | 1774 | val_args = xmalloc (allocated_args * sizeof (struct value *)); |
c13c43fd | 1775 | old_cleanups = make_cleanup (free_current_contents, &val_args); |
c906108c SS |
1776 | |
1777 | if (s == 0) | |
e2e0b3e5 | 1778 | error_no_arg (_("format-control string and values to print")); |
c906108c SS |
1779 | |
1780 | /* Skip white space before format string */ | |
c5aa993b JM |
1781 | while (*s == ' ' || *s == '\t') |
1782 | s++; | |
c906108c | 1783 | |
675dcf4f | 1784 | /* A format string should follow, enveloped in double quotes. */ |
c906108c | 1785 | if (*s++ != '"') |
8a3fe4f8 | 1786 | error (_("Bad format string, missing '\"'.")); |
c906108c SS |
1787 | |
1788 | /* Parse the format-control string and copy it into the string STRING, | |
1789 | processing some kinds of escape sequence. */ | |
1790 | ||
1791 | f = string = (char *) alloca (strlen (s) + 1); | |
1792 | ||
1793 | while (*s != '"') | |
1794 | { | |
1795 | int c = *s++; | |
1796 | switch (c) | |
1797 | { | |
1798 | case '\0': | |
8a3fe4f8 | 1799 | error (_("Bad format string, non-terminated '\"'.")); |
c906108c SS |
1800 | |
1801 | case '\\': | |
1802 | switch (c = *s++) | |
1803 | { | |
1804 | case '\\': | |
1805 | *f++ = '\\'; | |
1806 | break; | |
1807 | case 'a': | |
c906108c | 1808 | *f++ = '\a'; |
c906108c SS |
1809 | break; |
1810 | case 'b': | |
1811 | *f++ = '\b'; | |
1812 | break; | |
1813 | case 'f': | |
1814 | *f++ = '\f'; | |
1815 | break; | |
1816 | case 'n': | |
1817 | *f++ = '\n'; | |
1818 | break; | |
1819 | case 'r': | |
1820 | *f++ = '\r'; | |
1821 | break; | |
1822 | case 't': | |
1823 | *f++ = '\t'; | |
1824 | break; | |
1825 | case 'v': | |
1826 | *f++ = '\v'; | |
1827 | break; | |
1828 | case '"': | |
1829 | *f++ = '"'; | |
1830 | break; | |
1831 | default: | |
1832 | /* ??? TODO: handle other escape sequences */ | |
8a3fe4f8 | 1833 | error (_("Unrecognized escape character \\%c in format string."), |
c906108c SS |
1834 | c); |
1835 | } | |
1836 | break; | |
1837 | ||
1838 | default: | |
1839 | *f++ = c; | |
1840 | } | |
1841 | } | |
1842 | ||
1843 | /* Skip over " and following space and comma. */ | |
1844 | s++; | |
1845 | *f++ = '\0'; | |
c5aa993b JM |
1846 | while (*s == ' ' || *s == '\t') |
1847 | s++; | |
c906108c SS |
1848 | |
1849 | if (*s != ',' && *s != 0) | |
8a3fe4f8 | 1850 | error (_("Invalid argument syntax")); |
c906108c | 1851 | |
c5aa993b JM |
1852 | if (*s == ',') |
1853 | s++; | |
1854 | while (*s == ' ' || *s == '\t') | |
1855 | s++; | |
c906108c SS |
1856 | |
1857 | /* Need extra space for the '\0's. Doubling the size is sufficient. */ | |
1858 | substrings = alloca (strlen (string) * 2); | |
1859 | current_substring = substrings; | |
1860 | ||
1861 | { | |
1862 | /* Now scan the string for %-specs and see what kinds of args they want. | |
1863 | argclass[I] classifies the %-specs so we can give printf_filtered | |
1864 | something of the right size. */ | |
1865 | ||
c5aa993b JM |
1866 | enum argclass |
1867 | { | |
46e9880c | 1868 | int_arg, long_arg, long_long_arg, ptr_arg, string_arg, |
1a619819 | 1869 | double_arg, long_double_arg, decfloat_arg |
c5aa993b | 1870 | }; |
c906108c SS |
1871 | enum argclass *argclass; |
1872 | enum argclass this_argclass; | |
1873 | char *last_arg; | |
1874 | int nargs_wanted; | |
c906108c SS |
1875 | int i; |
1876 | ||
1877 | argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass); | |
1878 | nargs_wanted = 0; | |
1879 | f = string; | |
1880 | last_arg = string; | |
1881 | while (*f) | |
1882 | if (*f++ == '%') | |
1883 | { | |
46e9880c DJ |
1884 | int seen_hash = 0, seen_zero = 0, lcount = 0, seen_prec = 0; |
1885 | int seen_space = 0, seen_plus = 0; | |
0aea4bf3 LM |
1886 | int seen_big_l = 0, seen_h = 0, seen_big_h = 0; |
1887 | int seen_big_d = 0, seen_double_big_d = 0; | |
46e9880c DJ |
1888 | int bad = 0; |
1889 | ||
1890 | /* Check the validity of the format specifier, and work | |
1891 | out what argument it expects. We only accept C89 | |
1892 | format strings, with the exception of long long (which | |
1893 | we autoconf for). */ | |
1894 | ||
1895 | /* Skip over "%%". */ | |
1896 | if (*f == '%') | |
c906108c | 1897 | { |
c906108c | 1898 | f++; |
46e9880c | 1899 | continue; |
c906108c | 1900 | } |
46e9880c DJ |
1901 | |
1902 | /* The first part of a format specifier is a set of flag | |
1903 | characters. */ | |
1904 | while (strchr ("0-+ #", *f)) | |
1905 | { | |
1906 | if (*f == '#') | |
1907 | seen_hash = 1; | |
1908 | else if (*f == '0') | |
1909 | seen_zero = 1; | |
1910 | else if (*f == ' ') | |
1911 | seen_space = 1; | |
1912 | else if (*f == '+') | |
1913 | seen_plus = 1; | |
1914 | f++; | |
1915 | } | |
1916 | ||
1917 | /* The next part of a format specifier is a width. */ | |
1918 | while (strchr ("0123456789", *f)) | |
1919 | f++; | |
1920 | ||
1921 | /* The next part of a format specifier is a precision. */ | |
1922 | if (*f == '.') | |
1923 | { | |
1924 | seen_prec = 1; | |
1925 | f++; | |
1926 | while (strchr ("0123456789", *f)) | |
1927 | f++; | |
1928 | } | |
1929 | ||
1930 | /* The next part of a format specifier is a length modifier. */ | |
1931 | if (*f == 'h') | |
1932 | { | |
1933 | seen_h = 1; | |
1934 | f++; | |
1935 | } | |
1936 | else if (*f == 'l') | |
1937 | { | |
1938 | f++; | |
1939 | lcount++; | |
1940 | if (*f == 'l') | |
1941 | { | |
1942 | f++; | |
1943 | lcount++; | |
1944 | } | |
1945 | } | |
1946 | else if (*f == 'L') | |
1947 | { | |
1948 | seen_big_l = 1; | |
1949 | f++; | |
1950 | } | |
0aea4bf3 LM |
1951 | /* Decimal32 modifier. */ |
1952 | else if (*f == 'H') | |
1953 | { | |
1954 | seen_big_h = 1; | |
1955 | f++; | |
1956 | } | |
1957 | /* Decimal64 and Decimal128 modifiers. */ | |
1958 | else if (*f == 'D') | |
1959 | { | |
1960 | f++; | |
1961 | ||
1962 | /* Check for a Decimal128. */ | |
1963 | if (*f == 'D') | |
1964 | { | |
1965 | f++; | |
1966 | seen_double_big_d = 1; | |
1967 | } | |
1968 | else | |
1969 | seen_big_d = 1; | |
1970 | } | |
46e9880c | 1971 | |
c906108c SS |
1972 | switch (*f) |
1973 | { | |
46e9880c DJ |
1974 | case 'u': |
1975 | if (seen_hash) | |
1976 | bad = 1; | |
1977 | /* FALLTHROUGH */ | |
1978 | ||
1979 | case 'o': | |
1980 | case 'x': | |
1981 | case 'X': | |
1982 | if (seen_space || seen_plus) | |
1983 | bad = 1; | |
1984 | /* FALLTHROUGH */ | |
1985 | ||
1986 | case 'd': | |
1987 | case 'i': | |
1988 | if (lcount == 0) | |
1989 | this_argclass = int_arg; | |
1990 | else if (lcount == 1) | |
1991 | this_argclass = long_arg; | |
1992 | else | |
1993 | this_argclass = long_long_arg; | |
1994 | ||
1995 | if (seen_big_l) | |
1996 | bad = 1; | |
1997 | break; | |
1998 | ||
1999 | case 'c': | |
2000 | this_argclass = int_arg; | |
2001 | if (lcount || seen_h || seen_big_l) | |
2002 | bad = 1; | |
2003 | if (seen_prec || seen_zero || seen_space || seen_plus) | |
2004 | bad = 1; | |
2005 | break; | |
2006 | ||
2007 | case 'p': | |
2008 | this_argclass = ptr_arg; | |
2009 | if (lcount || seen_h || seen_big_l) | |
2010 | bad = 1; | |
2011 | if (seen_prec || seen_zero || seen_space || seen_plus) | |
2012 | bad = 1; | |
2013 | break; | |
2014 | ||
c906108c SS |
2015 | case 's': |
2016 | this_argclass = string_arg; | |
46e9880c DJ |
2017 | if (lcount || seen_h || seen_big_l) |
2018 | bad = 1; | |
2019 | if (seen_zero || seen_space || seen_plus) | |
2020 | bad = 1; | |
c906108c SS |
2021 | break; |
2022 | ||
2023 | case 'e': | |
2024 | case 'f': | |
2025 | case 'g': | |
46e9880c DJ |
2026 | case 'E': |
2027 | case 'G': | |
0aea4bf3 LM |
2028 | if (seen_big_h || seen_big_d || seen_double_big_d) |
2029 | this_argclass = decfloat_arg; | |
2030 | else if (seen_big_l) | |
46e9880c DJ |
2031 | this_argclass = long_double_arg; |
2032 | else | |
2033 | this_argclass = double_arg; | |
2034 | ||
2035 | if (lcount || seen_h) | |
2036 | bad = 1; | |
c906108c SS |
2037 | break; |
2038 | ||
2039 | case '*': | |
8a3fe4f8 | 2040 | error (_("`*' not supported for precision or width in printf")); |
c906108c SS |
2041 | |
2042 | case 'n': | |
8a3fe4f8 | 2043 | error (_("Format specifier `n' not supported in printf")); |
c906108c | 2044 | |
46e9880c DJ |
2045 | case '\0': |
2046 | error (_("Incomplete format specifier at end of format string")); | |
c906108c SS |
2047 | |
2048 | default: | |
46e9880c | 2049 | error (_("Unrecognized format specifier '%c' in printf"), *f); |
c906108c | 2050 | } |
46e9880c DJ |
2051 | |
2052 | if (bad) | |
2053 | error (_("Inappropriate modifiers to format specifier '%c' in printf"), | |
2054 | *f); | |
2055 | ||
c906108c | 2056 | f++; |
09d71d23 AS |
2057 | |
2058 | if (lcount > 1 && USE_PRINTF_I64) | |
2059 | { | |
2060 | /* Windows' printf does support long long, but not the usual way. | |
2061 | Convert %lld to %I64d. */ | |
2062 | int length_before_ll = f - last_arg - 1 - lcount; | |
2063 | strncpy (current_substring, last_arg, length_before_ll); | |
2064 | strcpy (current_substring + length_before_ll, "I64"); | |
2065 | current_substring[length_before_ll + 3] = | |
2066 | last_arg[length_before_ll + lcount]; | |
2067 | current_substring += length_before_ll + 4; | |
2068 | } | |
2069 | else | |
2070 | { | |
2071 | strncpy (current_substring, last_arg, f - last_arg); | |
2072 | current_substring += f - last_arg; | |
2073 | } | |
46e9880c DJ |
2074 | *current_substring++ = '\0'; |
2075 | last_arg = f; | |
2076 | argclass[nargs_wanted++] = this_argclass; | |
c906108c SS |
2077 | } |
2078 | ||
2079 | /* Now, parse all arguments and evaluate them. | |
2080 | Store the VALUEs in VAL_ARGS. */ | |
2081 | ||
2082 | while (*s != '\0') | |
2083 | { | |
2084 | char *s1; | |
2085 | if (nargs == allocated_args) | |
f976f6d4 AC |
2086 | val_args = (struct value **) xrealloc ((char *) val_args, |
2087 | (allocated_args *= 2) | |
2088 | * sizeof (struct value *)); | |
c906108c SS |
2089 | s1 = s; |
2090 | val_args[nargs] = parse_to_comma_and_eval (&s1); | |
c5aa993b | 2091 | |
c906108c SS |
2092 | nargs++; |
2093 | s = s1; | |
2094 | if (*s == ',') | |
2095 | s++; | |
2096 | } | |
c5aa993b | 2097 | |
c906108c | 2098 | if (nargs != nargs_wanted) |
8a3fe4f8 | 2099 | error (_("Wrong number of arguments for specified format-string")); |
c906108c SS |
2100 | |
2101 | /* Now actually print them. */ | |
2102 | current_substring = substrings; | |
2103 | for (i = 0; i < nargs; i++) | |
2104 | { | |
2105 | switch (argclass[i]) | |
2106 | { | |
2107 | case string_arg: | |
2108 | { | |
777ea8f1 | 2109 | gdb_byte *str; |
c906108c SS |
2110 | CORE_ADDR tem; |
2111 | int j; | |
1aa20aa8 | 2112 | tem = value_as_address (val_args[i]); |
c906108c SS |
2113 | |
2114 | /* This is a %s argument. Find the length of the string. */ | |
c5aa993b | 2115 | for (j = 0;; j++) |
c906108c | 2116 | { |
777ea8f1 | 2117 | gdb_byte c; |
c906108c | 2118 | QUIT; |
d4b2399a | 2119 | read_memory (tem + j, &c, 1); |
c906108c SS |
2120 | if (c == 0) |
2121 | break; | |
2122 | } | |
2123 | ||
2124 | /* Copy the string contents into a string inside GDB. */ | |
777ea8f1 | 2125 | str = (gdb_byte *) alloca (j + 1); |
7b92f6e1 MS |
2126 | if (j != 0) |
2127 | read_memory (tem, str, j); | |
c906108c SS |
2128 | str[j] = 0; |
2129 | ||
777ea8f1 | 2130 | printf_filtered (current_substring, (char *) str); |
c906108c SS |
2131 | } |
2132 | break; | |
2133 | case double_arg: | |
2134 | { | |
b806fb9a UW |
2135 | struct type *type = value_type (val_args[i]); |
2136 | DOUBLEST val; | |
2137 | int inv; | |
2138 | ||
2139 | /* If format string wants a float, unchecked-convert the value | |
2140 | to floating point of the same size. */ | |
2141 | type = float_type_from_length (current_gdbarch, type); | |
2142 | val = unpack_double (type, value_contents (val_args[i]), &inv); | |
2143 | if (inv) | |
2144 | error (_("Invalid floating value found in program.")); | |
2145 | ||
2146 | printf_filtered (current_substring, (double) val); | |
c906108c SS |
2147 | break; |
2148 | } | |
46e9880c DJ |
2149 | case long_double_arg: |
2150 | #ifdef HAVE_LONG_DOUBLE | |
2151 | { | |
b806fb9a UW |
2152 | struct type *type = value_type (val_args[i]); |
2153 | DOUBLEST val; | |
2154 | int inv; | |
2155 | ||
2156 | /* If format string wants a float, unchecked-convert the value | |
2157 | to floating point of the same size. */ | |
2158 | type = float_type_from_length (current_gdbarch, type); | |
2159 | val = unpack_double (type, value_contents (val_args[i]), &inv); | |
2160 | if (inv) | |
2161 | error (_("Invalid floating value found in program.")); | |
2162 | ||
2163 | printf_filtered (current_substring, (long double) val); | |
46e9880c DJ |
2164 | break; |
2165 | } | |
2166 | #else | |
2167 | error (_("long double not supported in printf")); | |
2168 | #endif | |
c906108c SS |
2169 | case long_long_arg: |
2170 | #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG) | |
2171 | { | |
2172 | long long val = value_as_long (val_args[i]); | |
2173 | printf_filtered (current_substring, val); | |
2174 | break; | |
2175 | } | |
2176 | #else | |
8a3fe4f8 | 2177 | error (_("long long not supported in printf")); |
c906108c SS |
2178 | #endif |
2179 | case int_arg: | |
2180 | { | |
46e9880c DJ |
2181 | int val = value_as_long (val_args[i]); |
2182 | printf_filtered (current_substring, val); | |
2183 | break; | |
2184 | } | |
2185 | case long_arg: | |
2186 | { | |
c906108c SS |
2187 | long val = value_as_long (val_args[i]); |
2188 | printf_filtered (current_substring, val); | |
2189 | break; | |
2190 | } | |
1a619819 | 2191 | |
0aea4bf3 LM |
2192 | /* Handles decimal floating values. */ |
2193 | case decfloat_arg: | |
1a619819 | 2194 | { |
0aea4bf3 | 2195 | const gdb_byte *param_ptr = value_contents (val_args[i]); |
1a619819 | 2196 | #if defined (PRINTF_HAS_DECFLOAT) |
0aea4bf3 LM |
2197 | /* If we have native support for Decimal floating |
2198 | printing, handle it here. */ | |
2199 | printf_filtered (current_substring, param_ptr); | |
1a619819 | 2200 | #else |
1a619819 LM |
2201 | |
2202 | /* As a workaround until vasprintf has native support for DFP | |
0aea4bf3 LM |
2203 | we convert the DFP values to string and print them using |
2204 | the %s format specifier. */ | |
2205 | ||
2206 | char *eos, *sos; | |
2207 | int nnull_chars = 0; | |
2208 | ||
2209 | /* Parameter data. */ | |
2210 | struct type *param_type = value_type (val_args[i]); | |
2211 | unsigned int param_len = TYPE_LENGTH (param_type); | |
2212 | ||
2213 | /* DFP output data. */ | |
2214 | struct value *dfp_value = NULL; | |
2215 | gdb_byte *dfp_ptr; | |
2216 | int dfp_len = 16; | |
2217 | gdb_byte dec[16]; | |
2218 | struct type *dfp_type = NULL; | |
2219 | char decstr[MAX_DECIMAL_STRING]; | |
1a619819 LM |
2220 | |
2221 | /* Points to the end of the string so that we can go back | |
0aea4bf3 | 2222 | and check for DFP length modifiers. */ |
1a619819 LM |
2223 | eos = current_substring + strlen (current_substring); |
2224 | ||
0aea4bf3 LM |
2225 | /* Look for the float/double format specifier. */ |
2226 | while (*eos != 'f' && *eos != 'e' && *eos != 'E' | |
2227 | && *eos != 'g' && *eos != 'G') | |
2228 | eos--; | |
2229 | ||
2230 | sos = eos; | |
2231 | ||
2232 | /* Search for the '%' char and extract the size and type of | |
2233 | the output decimal value based on its modifiers | |
2234 | (%Hf, %Df, %DDf). */ | |
2235 | while (*--sos != '%') | |
2236 | { | |
2237 | if (*sos == 'H') | |
2238 | { | |
2239 | dfp_len = 4; | |
2240 | dfp_type = builtin_type (current_gdbarch)->builtin_decfloat; | |
2241 | } | |
2242 | else if (*sos == 'D' && *(sos - 1) == 'D') | |
2243 | { | |
2244 | dfp_len = 16; | |
2245 | dfp_type = builtin_type (current_gdbarch)->builtin_declong; | |
2246 | sos--; | |
2247 | } | |
2248 | else | |
2249 | { | |
2250 | dfp_len = 8; | |
2251 | dfp_type = builtin_type (current_gdbarch)->builtin_decdouble; | |
2252 | } | |
2253 | } | |
2254 | ||
2255 | /* Replace %Hf, %Df and %DDf with %s's. */ | |
2256 | *++sos = 's'; | |
2257 | ||
2258 | /* Go through the whole format string and pull the correct | |
2259 | number of chars back to compensate for the change in the | |
2260 | format specifier. */ | |
2261 | while (nnull_chars < nargs - i) | |
2262 | { | |
2263 | if (*eos == '\0') | |
2264 | nnull_chars++; | |
2265 | ||
2266 | *++sos = *++eos; | |
2267 | } | |
2268 | ||
2269 | /* Conversion between different DFP types. */ | |
2270 | if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT) | |
2271 | decimal_convert (param_ptr, param_len, dec, dfp_len); | |
2272 | else | |
2273 | /* If this is a non-trivial conversion, just output 0. | |
2274 | A correct converted value can be displayed by explicitly | |
2275 | casting to a DFP type. */ | |
2276 | decimal_from_string (dec, dfp_len, "0"); | |
2277 | ||
2278 | dfp_value = value_from_decfloat (dfp_type, dec); | |
2279 | ||
2280 | dfp_ptr = (gdb_byte *) value_contents (dfp_value); | |
2281 | ||
2282 | decimal_to_string (dfp_ptr, dfp_len, decstr); | |
1a619819 LM |
2283 | |
2284 | /* Print the DFP value. */ | |
2285 | printf_filtered (current_substring, decstr); | |
0aea4bf3 | 2286 | |
1a619819 LM |
2287 | break; |
2288 | #endif | |
2289 | } | |
2290 | ||
2025a643 DJ |
2291 | case ptr_arg: |
2292 | { | |
2293 | /* We avoid the host's %p because pointers are too | |
2294 | likely to be the wrong size. The only interesting | |
2295 | modifier for %p is a width; extract that, and then | |
2296 | handle %p as glibc would: %#x or a literal "(nil)". */ | |
2297 | ||
2298 | char *p, *fmt, *fmt_p; | |
2299 | #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG) | |
2300 | long long val = value_as_long (val_args[i]); | |
2301 | #else | |
2302 | long val = value_as_long (val_args[i]); | |
2303 | #endif | |
2304 | ||
2305 | fmt = alloca (strlen (current_substring) + 5); | |
2306 | ||
2307 | /* Copy up to the leading %. */ | |
2308 | p = current_substring; | |
2309 | fmt_p = fmt; | |
2310 | while (*p) | |
2311 | { | |
2312 | int is_percent = (*p == '%'); | |
2313 | *fmt_p++ = *p++; | |
2314 | if (is_percent) | |
2315 | { | |
2316 | if (*p == '%') | |
2317 | *fmt_p++ = *p++; | |
2318 | else | |
2319 | break; | |
2320 | } | |
2321 | } | |
2322 | ||
2323 | if (val != 0) | |
2324 | *fmt_p++ = '#'; | |
2325 | ||
2326 | /* Copy any width. */ | |
2327 | while (*p >= '0' && *p < '9') | |
2328 | *fmt_p++ = *p++; | |
2329 | ||
2330 | gdb_assert (*p == 'p' && *(p + 1) == '\0'); | |
2331 | if (val != 0) | |
2332 | { | |
2333 | #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG) | |
2334 | *fmt_p++ = 'l'; | |
2335 | #endif | |
2336 | *fmt_p++ = 'l'; | |
2337 | *fmt_p++ = 'x'; | |
2338 | *fmt_p++ = '\0'; | |
2339 | printf_filtered (fmt, val); | |
2340 | } | |
2341 | else | |
2342 | { | |
2343 | *fmt_p++ = 's'; | |
2344 | *fmt_p++ = '\0'; | |
2345 | printf_filtered (fmt, "(nil)"); | |
2346 | } | |
2347 | ||
2348 | break; | |
2349 | } | |
675dcf4f MK |
2350 | default: |
2351 | internal_error (__FILE__, __LINE__, | |
2025a643 | 2352 | _("failed internal consistency check")); |
c906108c SS |
2353 | } |
2354 | /* Skip to the next substring. */ | |
2355 | current_substring += strlen (current_substring) + 1; | |
2356 | } | |
2357 | /* Print the portion of the format string after the last argument. */ | |
306d9ac5 | 2358 | puts_filtered (last_arg); |
c906108c SS |
2359 | } |
2360 | do_cleanups (old_cleanups); | |
2361 | } | |
c906108c | 2362 | |
c906108c | 2363 | void |
fba45db2 | 2364 | _initialize_printcmd (void) |
c906108c | 2365 | { |
c94fdfd0 EZ |
2366 | struct cmd_list_element *c; |
2367 | ||
c906108c SS |
2368 | current_display_number = -1; |
2369 | ||
2370 | add_info ("address", address_info, | |
1bedd215 | 2371 | _("Describe where symbol SYM is stored.")); |
c906108c | 2372 | |
1bedd215 AC |
2373 | add_info ("symbol", sym_info, _("\ |
2374 | Describe what symbol is at location ADDR.\n\ | |
2375 | Only for symbols with fixed locations (global or static scope).")); | |
c906108c | 2376 | |
1bedd215 AC |
2377 | add_com ("x", class_vars, x_command, _("\ |
2378 | Examine memory: x/FMT ADDRESS.\n\ | |
c906108c SS |
2379 | ADDRESS is an expression for the memory address to examine.\n\ |
2380 | FMT is a repeat count followed by a format letter and a size letter.\n\ | |
2381 | Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\ | |
1bedd215 AC |
2382 | t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\ |
2383 | Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\ | |
c906108c SS |
2384 | The specified number of objects of the specified size are printed\n\ |
2385 | according to the format.\n\n\ | |
2386 | Defaults for format and size letters are those previously used.\n\ | |
2387 | Default count is 1. Default address is following last thing printed\n\ | |
1bedd215 | 2388 | with this command or \"print\".")); |
c906108c | 2389 | |
c906108c SS |
2390 | #if 0 |
2391 | add_com ("whereis", class_vars, whereis_command, | |
1bedd215 | 2392 | _("Print line number and file of definition of variable.")); |
c906108c | 2393 | #endif |
c5aa993b | 2394 | |
1bedd215 AC |
2395 | add_info ("display", display_info, _("\ |
2396 | Expressions to display when program stops, with code numbers.")); | |
c906108c | 2397 | |
1a966eab AC |
2398 | add_cmd ("undisplay", class_vars, undisplay_command, _("\ |
2399 | Cancel some expressions to be displayed when program stops.\n\ | |
c906108c SS |
2400 | Arguments are the code numbers of the expressions to stop displaying.\n\ |
2401 | No argument means cancel all automatic-display expressions.\n\ | |
2402 | \"delete display\" has the same effect as this command.\n\ | |
1a966eab | 2403 | Do \"info display\" to see current list of code numbers."), |
c5aa993b | 2404 | &cmdlist); |
c906108c | 2405 | |
1bedd215 AC |
2406 | add_com ("display", class_vars, display_command, _("\ |
2407 | Print value of expression EXP each time the program stops.\n\ | |
c906108c SS |
2408 | /FMT may be used before EXP as in the \"print\" command.\n\ |
2409 | /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\ | |
2410 | as in the \"x\" command, and then EXP is used to get the address to examine\n\ | |
2411 | and examining is done as in the \"x\" command.\n\n\ | |
2412 | With no argument, display all currently requested auto-display expressions.\n\ | |
1bedd215 | 2413 | Use \"undisplay\" to cancel display requests previously made.")); |
c906108c | 2414 | |
1a966eab AC |
2415 | add_cmd ("display", class_vars, enable_display, _("\ |
2416 | Enable some expressions to be displayed when program stops.\n\ | |
c906108c SS |
2417 | Arguments are the code numbers of the expressions to resume displaying.\n\ |
2418 | No argument means enable all automatic-display expressions.\n\ | |
1a966eab | 2419 | Do \"info display\" to see current list of code numbers."), &enablelist); |
c906108c | 2420 | |
1a966eab AC |
2421 | add_cmd ("display", class_vars, disable_display_command, _("\ |
2422 | Disable some expressions to be displayed when program stops.\n\ | |
c906108c SS |
2423 | Arguments are the code numbers of the expressions to stop displaying.\n\ |
2424 | No argument means disable all automatic-display expressions.\n\ | |
1a966eab | 2425 | Do \"info display\" to see current list of code numbers."), &disablelist); |
c906108c | 2426 | |
1a966eab AC |
2427 | add_cmd ("display", class_vars, undisplay_command, _("\ |
2428 | Cancel some expressions to be displayed when program stops.\n\ | |
c906108c SS |
2429 | Arguments are the code numbers of the expressions to stop displaying.\n\ |
2430 | No argument means cancel all automatic-display expressions.\n\ | |
1a966eab | 2431 | Do \"info display\" to see current list of code numbers."), &deletelist); |
c906108c | 2432 | |
1bedd215 AC |
2433 | add_com ("printf", class_vars, printf_command, _("\ |
2434 | printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
2435 | This is useful for formatted output in user-defined commands.")); | |
c906108c | 2436 | |
1bedd215 AC |
2437 | add_com ("output", class_vars, output_command, _("\ |
2438 | Like \"print\" but don't put in value history and don't print newline.\n\ | |
2439 | This is useful in user-defined commands.")); | |
c906108c | 2440 | |
1bedd215 AC |
2441 | add_prefix_cmd ("set", class_vars, set_command, _("\ |
2442 | Evaluate expression EXP and assign result to variable VAR, using assignment\n\ | |
c906108c SS |
2443 | syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ |
2444 | example). VAR may be a debugger \"convenience\" variable (names starting\n\ | |
2445 | with $), a register (a few standard names starting with $), or an actual\n\ | |
1bedd215 AC |
2446 | variable in the program being debugged. EXP is any valid expression.\n\ |
2447 | Use \"set variable\" for variables with names identical to set subcommands.\n\ | |
2448 | \n\ | |
2449 | With a subcommand, this command modifies parts of the gdb environment.\n\ | |
2450 | You can see these environment settings with the \"show\" command."), | |
c5aa993b | 2451 | &setlist, "set ", 1, &cmdlist); |
c906108c | 2452 | if (dbx_commands) |
1bedd215 AC |
2453 | add_com ("assign", class_vars, set_command, _("\ |
2454 | Evaluate expression EXP and assign result to variable VAR, using assignment\n\ | |
c906108c SS |
2455 | syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ |
2456 | example). VAR may be a debugger \"convenience\" variable (names starting\n\ | |
2457 | with $), a register (a few standard names starting with $), or an actual\n\ | |
1bedd215 AC |
2458 | variable in the program being debugged. EXP is any valid expression.\n\ |
2459 | Use \"set variable\" for variables with names identical to set subcommands.\n\ | |
c906108c | 2460 | \nWith a subcommand, this command modifies parts of the gdb environment.\n\ |
1bedd215 | 2461 | You can see these environment settings with the \"show\" command.")); |
c906108c SS |
2462 | |
2463 | /* "call" is the same as "set", but handy for dbx users to call fns. */ | |
1bedd215 AC |
2464 | c = add_com ("call", class_vars, call_command, _("\ |
2465 | Call a function in the program.\n\ | |
c906108c SS |
2466 | The argument is the function name and arguments, in the notation of the\n\ |
2467 | current working language. The result is printed and saved in the value\n\ | |
1bedd215 | 2468 | history, if it is not void.")); |
65d12d83 | 2469 | set_cmd_completer (c, expression_completer); |
c906108c | 2470 | |
1a966eab AC |
2471 | add_cmd ("variable", class_vars, set_command, _("\ |
2472 | Evaluate expression EXP and assign result to variable VAR, using assignment\n\ | |
c906108c SS |
2473 | syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ |
2474 | example). VAR may be a debugger \"convenience\" variable (names starting\n\ | |
2475 | with $), a register (a few standard names starting with $), or an actual\n\ | |
2476 | variable in the program being debugged. EXP is any valid expression.\n\ | |
1a966eab | 2477 | This may usually be abbreviated to simply \"set\"."), |
c5aa993b | 2478 | &setlist); |
c906108c | 2479 | |
1bedd215 AC |
2480 | c = add_com ("print", class_vars, print_command, _("\ |
2481 | Print value of expression EXP.\n\ | |
c906108c SS |
2482 | Variables accessible are those of the lexical environment of the selected\n\ |
2483 | stack frame, plus all those whose scope is global or an entire file.\n\ | |
2484 | \n\ | |
2485 | $NUM gets previous value number NUM. $ and $$ are the last two values.\n\ | |
2486 | $$NUM refers to NUM'th value back from the last one.\n\ | |
1bedd215 AC |
2487 | Names starting with $ refer to registers (with the values they would have\n\ |
2488 | if the program were to return to the stack frame now selected, restoring\n\ | |
c906108c SS |
2489 | all registers saved by frames farther in) or else to debugger\n\ |
2490 | \"convenience\" variables (any such name not a known register).\n\ | |
1bedd215 AC |
2491 | Use assignment expressions to give values to convenience variables.\n\ |
2492 | \n\ | |
c906108c SS |
2493 | {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\ |
2494 | @ is a binary operator for treating consecutive data objects\n\ | |
2495 | anywhere in memory as an array. FOO@NUM gives an array whose first\n\ | |
2496 | element is FOO, whose second element is stored in the space following\n\ | |
2497 | where FOO is stored, etc. FOO must be an expression whose value\n\ | |
1bedd215 AC |
2498 | resides in memory.\n\ |
2499 | \n\ | |
c906108c | 2500 | EXP may be preceded with /FMT, where FMT is a format letter\n\ |
1bedd215 | 2501 | but no count or size letter (see \"x\" command).")); |
65d12d83 | 2502 | set_cmd_completer (c, expression_completer); |
c906108c SS |
2503 | add_com_alias ("p", "print", class_vars, 1); |
2504 | ||
1bedd215 AC |
2505 | c = add_com ("inspect", class_vars, inspect_command, _("\ |
2506 | Same as \"print\" command, except that if you are running in the epoch\n\ | |
2507 | environment, the value is printed in its own window.")); | |
65d12d83 | 2508 | set_cmd_completer (c, expression_completer); |
c906108c | 2509 | |
35096d9d AC |
2510 | add_setshow_uinteger_cmd ("max-symbolic-offset", no_class, |
2511 | &max_symbolic_offset, _("\ | |
2512 | Set the largest offset that will be printed in <symbol+1234> form."), _("\ | |
2513 | Show the largest offset that will be printed in <symbol+1234> form."), NULL, | |
2514 | NULL, | |
920d2a44 | 2515 | show_max_symbolic_offset, |
35096d9d | 2516 | &setprintlist, &showprintlist); |
5bf193a2 AC |
2517 | add_setshow_boolean_cmd ("symbol-filename", no_class, |
2518 | &print_symbol_filename, _("\ | |
2519 | Set printing of source filename and line number with <symbol>."), _("\ | |
2520 | Show printing of source filename and line number with <symbol>."), NULL, | |
2521 | NULL, | |
920d2a44 | 2522 | show_print_symbol_filename, |
5bf193a2 | 2523 | &setprintlist, &showprintlist); |
c906108c SS |
2524 | |
2525 | /* For examine/instruction a single byte quantity is specified as | |
2526 | the data. This avoids problems with value_at_lazy() requiring a | |
2527 | valid data type (and rejecting VOID). */ | |
2528 | examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL); | |
2529 | ||
2530 | examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL); | |
2531 | examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL); | |
2532 | examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL); | |
2533 | examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL); | |
2534 | ||
2535 | } |