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