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