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