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