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