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