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