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