1*5796c8dcSSimon Schubert /* Print values for GNU debugger GDB. 2*5796c8dcSSimon Schubert 3*5796c8dcSSimon Schubert Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 4*5796c8dcSSimon Schubert 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 5*5796c8dcSSimon Schubert 2008, 2009 Free Software Foundation, Inc. 6*5796c8dcSSimon Schubert 7*5796c8dcSSimon Schubert This file is part of GDB. 8*5796c8dcSSimon Schubert 9*5796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 10*5796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 11*5796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 12*5796c8dcSSimon Schubert (at your option) any later version. 13*5796c8dcSSimon Schubert 14*5796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 15*5796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 16*5796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*5796c8dcSSimon Schubert GNU General Public License for more details. 18*5796c8dcSSimon Schubert 19*5796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 20*5796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 21*5796c8dcSSimon Schubert 22*5796c8dcSSimon Schubert #include "defs.h" 23*5796c8dcSSimon Schubert #include "gdb_string.h" 24*5796c8dcSSimon Schubert #include "frame.h" 25*5796c8dcSSimon Schubert #include "symtab.h" 26*5796c8dcSSimon Schubert #include "gdbtypes.h" 27*5796c8dcSSimon Schubert #include "value.h" 28*5796c8dcSSimon Schubert #include "language.h" 29*5796c8dcSSimon Schubert #include "expression.h" 30*5796c8dcSSimon Schubert #include "gdbcore.h" 31*5796c8dcSSimon Schubert #include "gdbcmd.h" 32*5796c8dcSSimon Schubert #include "target.h" 33*5796c8dcSSimon Schubert #include "breakpoint.h" 34*5796c8dcSSimon Schubert #include "demangle.h" 35*5796c8dcSSimon Schubert #include "valprint.h" 36*5796c8dcSSimon Schubert #include "annotate.h" 37*5796c8dcSSimon Schubert #include "symfile.h" /* for overlay functions */ 38*5796c8dcSSimon Schubert #include "objfiles.h" /* ditto */ 39*5796c8dcSSimon Schubert #include "completer.h" /* for completion functions */ 40*5796c8dcSSimon Schubert #include "ui-out.h" 41*5796c8dcSSimon Schubert #include "gdb_assert.h" 42*5796c8dcSSimon Schubert #include "block.h" 43*5796c8dcSSimon Schubert #include "disasm.h" 44*5796c8dcSSimon Schubert #include "dfp.h" 45*5796c8dcSSimon Schubert #include "valprint.h" 46*5796c8dcSSimon Schubert #include "exceptions.h" 47*5796c8dcSSimon Schubert #include "observer.h" 48*5796c8dcSSimon Schubert #include "solist.h" 49*5796c8dcSSimon Schubert #include "solib.h" 50*5796c8dcSSimon Schubert #include "parser-defs.h" 51*5796c8dcSSimon Schubert #include "charset.h" 52*5796c8dcSSimon Schubert 53*5796c8dcSSimon Schubert #ifdef TUI 54*5796c8dcSSimon Schubert #include "tui/tui.h" /* For tui_active et.al. */ 55*5796c8dcSSimon Schubert #endif 56*5796c8dcSSimon Schubert 57*5796c8dcSSimon Schubert #if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG) 58*5796c8dcSSimon Schubert # define USE_PRINTF_I64 1 59*5796c8dcSSimon Schubert # define PRINTF_HAS_LONG_LONG 60*5796c8dcSSimon Schubert #else 61*5796c8dcSSimon Schubert # define USE_PRINTF_I64 0 62*5796c8dcSSimon Schubert #endif 63*5796c8dcSSimon Schubert 64*5796c8dcSSimon Schubert extern int asm_demangle; /* Whether to demangle syms in asm printouts */ 65*5796c8dcSSimon Schubert 66*5796c8dcSSimon Schubert struct format_data 67*5796c8dcSSimon Schubert { 68*5796c8dcSSimon Schubert int count; 69*5796c8dcSSimon Schubert char format; 70*5796c8dcSSimon Schubert char size; 71*5796c8dcSSimon Schubert 72*5796c8dcSSimon Schubert /* True if the value should be printed raw -- that is, bypassing 73*5796c8dcSSimon Schubert python-based formatters. */ 74*5796c8dcSSimon Schubert unsigned char raw; 75*5796c8dcSSimon Schubert }; 76*5796c8dcSSimon Schubert 77*5796c8dcSSimon Schubert /* Last specified output format. */ 78*5796c8dcSSimon Schubert 79*5796c8dcSSimon Schubert static char last_format = 0; 80*5796c8dcSSimon Schubert 81*5796c8dcSSimon Schubert /* Last specified examination size. 'b', 'h', 'w' or `q'. */ 82*5796c8dcSSimon Schubert 83*5796c8dcSSimon Schubert static char last_size = 'w'; 84*5796c8dcSSimon Schubert 85*5796c8dcSSimon Schubert /* Default address to examine next, and associated architecture. */ 86*5796c8dcSSimon Schubert 87*5796c8dcSSimon Schubert static struct gdbarch *next_gdbarch; 88*5796c8dcSSimon Schubert static CORE_ADDR next_address; 89*5796c8dcSSimon Schubert 90*5796c8dcSSimon Schubert /* Number of delay instructions following current disassembled insn. */ 91*5796c8dcSSimon Schubert 92*5796c8dcSSimon Schubert static int branch_delay_insns; 93*5796c8dcSSimon Schubert 94*5796c8dcSSimon Schubert /* Last address examined. */ 95*5796c8dcSSimon Schubert 96*5796c8dcSSimon Schubert static CORE_ADDR last_examine_address; 97*5796c8dcSSimon Schubert 98*5796c8dcSSimon Schubert /* Contents of last address examined. 99*5796c8dcSSimon Schubert This is not valid past the end of the `x' command! */ 100*5796c8dcSSimon Schubert 101*5796c8dcSSimon Schubert static struct value *last_examine_value; 102*5796c8dcSSimon Schubert 103*5796c8dcSSimon Schubert /* Largest offset between a symbolic value and an address, that will be 104*5796c8dcSSimon Schubert printed as `0x1234 <symbol+offset>'. */ 105*5796c8dcSSimon Schubert 106*5796c8dcSSimon Schubert static unsigned int max_symbolic_offset = UINT_MAX; 107*5796c8dcSSimon Schubert static void 108*5796c8dcSSimon Schubert show_max_symbolic_offset (struct ui_file *file, int from_tty, 109*5796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 110*5796c8dcSSimon Schubert { 111*5796c8dcSSimon Schubert fprintf_filtered (file, _("\ 112*5796c8dcSSimon Schubert The largest offset that will be printed in <symbol+1234> form is %s.\n"), 113*5796c8dcSSimon Schubert value); 114*5796c8dcSSimon Schubert } 115*5796c8dcSSimon Schubert 116*5796c8dcSSimon Schubert /* Append the source filename and linenumber of the symbol when 117*5796c8dcSSimon Schubert printing a symbolic value as `<symbol at filename:linenum>' if set. */ 118*5796c8dcSSimon Schubert static int print_symbol_filename = 0; 119*5796c8dcSSimon Schubert static void 120*5796c8dcSSimon Schubert show_print_symbol_filename (struct ui_file *file, int from_tty, 121*5796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 122*5796c8dcSSimon Schubert { 123*5796c8dcSSimon Schubert fprintf_filtered (file, _("\ 124*5796c8dcSSimon Schubert Printing of source filename and line number with <symbol> is %s.\n"), 125*5796c8dcSSimon Schubert value); 126*5796c8dcSSimon Schubert } 127*5796c8dcSSimon Schubert 128*5796c8dcSSimon Schubert /* Number of auto-display expression currently being displayed. 129*5796c8dcSSimon Schubert So that we can disable it if we get an error or a signal within it. 130*5796c8dcSSimon Schubert -1 when not doing one. */ 131*5796c8dcSSimon Schubert 132*5796c8dcSSimon Schubert int current_display_number; 133*5796c8dcSSimon Schubert 134*5796c8dcSSimon Schubert struct display 135*5796c8dcSSimon Schubert { 136*5796c8dcSSimon Schubert /* Chain link to next auto-display item. */ 137*5796c8dcSSimon Schubert struct display *next; 138*5796c8dcSSimon Schubert /* The expression as the user typed it. */ 139*5796c8dcSSimon Schubert char *exp_string; 140*5796c8dcSSimon Schubert /* Expression to be evaluated and displayed. */ 141*5796c8dcSSimon Schubert struct expression *exp; 142*5796c8dcSSimon Schubert /* Item number of this auto-display item. */ 143*5796c8dcSSimon Schubert int number; 144*5796c8dcSSimon Schubert /* Display format specified. */ 145*5796c8dcSSimon Schubert struct format_data format; 146*5796c8dcSSimon Schubert /* Innermost block required by this expression when evaluated */ 147*5796c8dcSSimon Schubert struct block *block; 148*5796c8dcSSimon Schubert /* Status of this display (enabled or disabled) */ 149*5796c8dcSSimon Schubert int enabled_p; 150*5796c8dcSSimon Schubert }; 151*5796c8dcSSimon Schubert 152*5796c8dcSSimon Schubert /* Chain of expressions whose values should be displayed 153*5796c8dcSSimon Schubert automatically each time the program stops. */ 154*5796c8dcSSimon Schubert 155*5796c8dcSSimon Schubert static struct display *display_chain; 156*5796c8dcSSimon Schubert 157*5796c8dcSSimon Schubert static int display_number; 158*5796c8dcSSimon Schubert 159*5796c8dcSSimon Schubert /* Prototypes for exported functions. */ 160*5796c8dcSSimon Schubert 161*5796c8dcSSimon Schubert void output_command (char *, int); 162*5796c8dcSSimon Schubert 163*5796c8dcSSimon Schubert void _initialize_printcmd (void); 164*5796c8dcSSimon Schubert 165*5796c8dcSSimon Schubert /* Prototypes for local functions. */ 166*5796c8dcSSimon Schubert 167*5796c8dcSSimon Schubert static void do_one_display (struct display *); 168*5796c8dcSSimon Schubert 169*5796c8dcSSimon Schubert 170*5796c8dcSSimon Schubert /* Decode a format specification. *STRING_PTR should point to it. 171*5796c8dcSSimon Schubert OFORMAT and OSIZE are used as defaults for the format and size 172*5796c8dcSSimon Schubert if none are given in the format specification. 173*5796c8dcSSimon Schubert If OSIZE is zero, then the size field of the returned value 174*5796c8dcSSimon Schubert should be set only if a size is explicitly specified by the 175*5796c8dcSSimon Schubert user. 176*5796c8dcSSimon Schubert The structure returned describes all the data 177*5796c8dcSSimon Schubert found in the specification. In addition, *STRING_PTR is advanced 178*5796c8dcSSimon Schubert past the specification and past all whitespace following it. */ 179*5796c8dcSSimon Schubert 180*5796c8dcSSimon Schubert static struct format_data 181*5796c8dcSSimon Schubert decode_format (char **string_ptr, int oformat, int osize) 182*5796c8dcSSimon Schubert { 183*5796c8dcSSimon Schubert struct format_data val; 184*5796c8dcSSimon Schubert char *p = *string_ptr; 185*5796c8dcSSimon Schubert 186*5796c8dcSSimon Schubert val.format = '?'; 187*5796c8dcSSimon Schubert val.size = '?'; 188*5796c8dcSSimon Schubert val.count = 1; 189*5796c8dcSSimon Schubert val.raw = 0; 190*5796c8dcSSimon Schubert 191*5796c8dcSSimon Schubert if (*p >= '0' && *p <= '9') 192*5796c8dcSSimon Schubert val.count = atoi (p); 193*5796c8dcSSimon Schubert while (*p >= '0' && *p <= '9') 194*5796c8dcSSimon Schubert p++; 195*5796c8dcSSimon Schubert 196*5796c8dcSSimon Schubert /* Now process size or format letters that follow. */ 197*5796c8dcSSimon Schubert 198*5796c8dcSSimon Schubert while (1) 199*5796c8dcSSimon Schubert { 200*5796c8dcSSimon Schubert if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g') 201*5796c8dcSSimon Schubert val.size = *p++; 202*5796c8dcSSimon Schubert else if (*p == 'r') 203*5796c8dcSSimon Schubert { 204*5796c8dcSSimon Schubert val.raw = 1; 205*5796c8dcSSimon Schubert p++; 206*5796c8dcSSimon Schubert } 207*5796c8dcSSimon Schubert else if (*p >= 'a' && *p <= 'z') 208*5796c8dcSSimon Schubert val.format = *p++; 209*5796c8dcSSimon Schubert else 210*5796c8dcSSimon Schubert break; 211*5796c8dcSSimon Schubert } 212*5796c8dcSSimon Schubert 213*5796c8dcSSimon Schubert while (*p == ' ' || *p == '\t') 214*5796c8dcSSimon Schubert p++; 215*5796c8dcSSimon Schubert *string_ptr = p; 216*5796c8dcSSimon Schubert 217*5796c8dcSSimon Schubert /* Set defaults for format and size if not specified. */ 218*5796c8dcSSimon Schubert if (val.format == '?') 219*5796c8dcSSimon Schubert { 220*5796c8dcSSimon Schubert if (val.size == '?') 221*5796c8dcSSimon Schubert { 222*5796c8dcSSimon Schubert /* Neither has been specified. */ 223*5796c8dcSSimon Schubert val.format = oformat; 224*5796c8dcSSimon Schubert val.size = osize; 225*5796c8dcSSimon Schubert } 226*5796c8dcSSimon Schubert else 227*5796c8dcSSimon Schubert /* If a size is specified, any format makes a reasonable 228*5796c8dcSSimon Schubert default except 'i'. */ 229*5796c8dcSSimon Schubert val.format = oformat == 'i' ? 'x' : oformat; 230*5796c8dcSSimon Schubert } 231*5796c8dcSSimon Schubert else if (val.size == '?') 232*5796c8dcSSimon Schubert switch (val.format) 233*5796c8dcSSimon Schubert { 234*5796c8dcSSimon Schubert case 'a': 235*5796c8dcSSimon Schubert /* Pick the appropriate size for an address. This is deferred 236*5796c8dcSSimon Schubert until do_examine when we know the actual architecture to use. 237*5796c8dcSSimon Schubert A special size value of 'a' is used to indicate this case. */ 238*5796c8dcSSimon Schubert val.size = osize ? 'a' : osize; 239*5796c8dcSSimon Schubert break; 240*5796c8dcSSimon Schubert case 'f': 241*5796c8dcSSimon Schubert /* Floating point has to be word or giantword. */ 242*5796c8dcSSimon Schubert if (osize == 'w' || osize == 'g') 243*5796c8dcSSimon Schubert val.size = osize; 244*5796c8dcSSimon Schubert else 245*5796c8dcSSimon Schubert /* Default it to giantword if the last used size is not 246*5796c8dcSSimon Schubert appropriate. */ 247*5796c8dcSSimon Schubert val.size = osize ? 'g' : osize; 248*5796c8dcSSimon Schubert break; 249*5796c8dcSSimon Schubert case 'c': 250*5796c8dcSSimon Schubert /* Characters default to one byte. */ 251*5796c8dcSSimon Schubert val.size = osize ? 'b' : osize; 252*5796c8dcSSimon Schubert break; 253*5796c8dcSSimon Schubert default: 254*5796c8dcSSimon Schubert /* The default is the size most recently specified. */ 255*5796c8dcSSimon Schubert val.size = osize; 256*5796c8dcSSimon Schubert } 257*5796c8dcSSimon Schubert 258*5796c8dcSSimon Schubert return val; 259*5796c8dcSSimon Schubert } 260*5796c8dcSSimon Schubert 261*5796c8dcSSimon Schubert /* Print value VAL on stream according to OPTIONS. 262*5796c8dcSSimon Schubert Do not end with a newline. 263*5796c8dcSSimon Schubert SIZE is the letter for the size of datum being printed. 264*5796c8dcSSimon Schubert This is used to pad hex numbers so they line up. SIZE is 0 265*5796c8dcSSimon Schubert for print / output and set for examine. */ 266*5796c8dcSSimon Schubert 267*5796c8dcSSimon Schubert static void 268*5796c8dcSSimon Schubert print_formatted (struct value *val, int size, 269*5796c8dcSSimon Schubert const struct value_print_options *options, 270*5796c8dcSSimon Schubert struct ui_file *stream) 271*5796c8dcSSimon Schubert { 272*5796c8dcSSimon Schubert struct type *type = check_typedef (value_type (val)); 273*5796c8dcSSimon Schubert int len = TYPE_LENGTH (type); 274*5796c8dcSSimon Schubert 275*5796c8dcSSimon Schubert if (VALUE_LVAL (val) == lval_memory) 276*5796c8dcSSimon Schubert next_address = value_address (val) + len; 277*5796c8dcSSimon Schubert 278*5796c8dcSSimon Schubert if (size) 279*5796c8dcSSimon Schubert { 280*5796c8dcSSimon Schubert switch (options->format) 281*5796c8dcSSimon Schubert { 282*5796c8dcSSimon Schubert case 's': 283*5796c8dcSSimon Schubert { 284*5796c8dcSSimon Schubert struct type *elttype = value_type (val); 285*5796c8dcSSimon Schubert next_address = (value_address (val) 286*5796c8dcSSimon Schubert + val_print_string (elttype, 287*5796c8dcSSimon Schubert value_address (val), -1, 288*5796c8dcSSimon Schubert stream, options)); 289*5796c8dcSSimon Schubert } 290*5796c8dcSSimon Schubert return; 291*5796c8dcSSimon Schubert 292*5796c8dcSSimon Schubert case 'i': 293*5796c8dcSSimon Schubert /* We often wrap here if there are long symbolic names. */ 294*5796c8dcSSimon Schubert wrap_here (" "); 295*5796c8dcSSimon Schubert next_address = (value_address (val) 296*5796c8dcSSimon Schubert + gdb_print_insn (get_type_arch (type), 297*5796c8dcSSimon Schubert value_address (val), stream, 298*5796c8dcSSimon Schubert &branch_delay_insns)); 299*5796c8dcSSimon Schubert return; 300*5796c8dcSSimon Schubert } 301*5796c8dcSSimon Schubert } 302*5796c8dcSSimon Schubert 303*5796c8dcSSimon Schubert if (options->format == 0 || options->format == 's' 304*5796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_REF 305*5796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_ARRAY 306*5796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_STRING 307*5796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_STRUCT 308*5796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_UNION 309*5796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_NAMESPACE) 310*5796c8dcSSimon Schubert value_print (val, stream, options); 311*5796c8dcSSimon Schubert else 312*5796c8dcSSimon Schubert /* User specified format, so don't look to the the type to 313*5796c8dcSSimon Schubert tell us what to do. */ 314*5796c8dcSSimon Schubert print_scalar_formatted (value_contents (val), type, 315*5796c8dcSSimon Schubert options, size, stream); 316*5796c8dcSSimon Schubert } 317*5796c8dcSSimon Schubert 318*5796c8dcSSimon Schubert /* Return builtin floating point type of same length as TYPE. 319*5796c8dcSSimon Schubert If no such type is found, return TYPE itself. */ 320*5796c8dcSSimon Schubert static struct type * 321*5796c8dcSSimon Schubert float_type_from_length (struct type *type) 322*5796c8dcSSimon Schubert { 323*5796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (type); 324*5796c8dcSSimon Schubert const struct builtin_type *builtin = builtin_type (gdbarch); 325*5796c8dcSSimon Schubert unsigned int len = TYPE_LENGTH (type); 326*5796c8dcSSimon Schubert 327*5796c8dcSSimon Schubert if (len == TYPE_LENGTH (builtin->builtin_float)) 328*5796c8dcSSimon Schubert type = builtin->builtin_float; 329*5796c8dcSSimon Schubert else if (len == TYPE_LENGTH (builtin->builtin_double)) 330*5796c8dcSSimon Schubert type = builtin->builtin_double; 331*5796c8dcSSimon Schubert else if (len == TYPE_LENGTH (builtin->builtin_long_double)) 332*5796c8dcSSimon Schubert type = builtin->builtin_long_double; 333*5796c8dcSSimon Schubert 334*5796c8dcSSimon Schubert return type; 335*5796c8dcSSimon Schubert } 336*5796c8dcSSimon Schubert 337*5796c8dcSSimon Schubert /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR, 338*5796c8dcSSimon Schubert according to OPTIONS and SIZE on STREAM. 339*5796c8dcSSimon Schubert Formats s and i are not supported at this level. 340*5796c8dcSSimon Schubert 341*5796c8dcSSimon Schubert This is how the elements of an array or structure are printed 342*5796c8dcSSimon Schubert with a format. */ 343*5796c8dcSSimon Schubert 344*5796c8dcSSimon Schubert void 345*5796c8dcSSimon Schubert print_scalar_formatted (const void *valaddr, struct type *type, 346*5796c8dcSSimon Schubert const struct value_print_options *options, 347*5796c8dcSSimon Schubert int size, struct ui_file *stream) 348*5796c8dcSSimon Schubert { 349*5796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (type); 350*5796c8dcSSimon Schubert LONGEST val_long = 0; 351*5796c8dcSSimon Schubert unsigned int len = TYPE_LENGTH (type); 352*5796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 353*5796c8dcSSimon Schubert 354*5796c8dcSSimon Schubert /* If we get here with a string format, try again without it. Go 355*5796c8dcSSimon Schubert all the way back to the language printers, which may call us 356*5796c8dcSSimon Schubert again. */ 357*5796c8dcSSimon Schubert if (options->format == 's') 358*5796c8dcSSimon Schubert { 359*5796c8dcSSimon Schubert struct value_print_options opts = *options; 360*5796c8dcSSimon Schubert opts.format = 0; 361*5796c8dcSSimon Schubert opts.deref_ref = 0; 362*5796c8dcSSimon Schubert val_print (type, valaddr, 0, 0, stream, 0, &opts, 363*5796c8dcSSimon Schubert current_language); 364*5796c8dcSSimon Schubert return; 365*5796c8dcSSimon Schubert } 366*5796c8dcSSimon Schubert 367*5796c8dcSSimon Schubert if (len > sizeof(LONGEST) && 368*5796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_INT 369*5796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_ENUM)) 370*5796c8dcSSimon Schubert { 371*5796c8dcSSimon Schubert switch (options->format) 372*5796c8dcSSimon Schubert { 373*5796c8dcSSimon Schubert case 'o': 374*5796c8dcSSimon Schubert print_octal_chars (stream, valaddr, len, byte_order); 375*5796c8dcSSimon Schubert return; 376*5796c8dcSSimon Schubert case 'u': 377*5796c8dcSSimon Schubert case 'd': 378*5796c8dcSSimon Schubert print_decimal_chars (stream, valaddr, len, byte_order); 379*5796c8dcSSimon Schubert return; 380*5796c8dcSSimon Schubert case 't': 381*5796c8dcSSimon Schubert print_binary_chars (stream, valaddr, len, byte_order); 382*5796c8dcSSimon Schubert return; 383*5796c8dcSSimon Schubert case 'x': 384*5796c8dcSSimon Schubert print_hex_chars (stream, valaddr, len, byte_order); 385*5796c8dcSSimon Schubert return; 386*5796c8dcSSimon Schubert case 'c': 387*5796c8dcSSimon Schubert print_char_chars (stream, type, valaddr, len, byte_order); 388*5796c8dcSSimon Schubert return; 389*5796c8dcSSimon Schubert default: 390*5796c8dcSSimon Schubert break; 391*5796c8dcSSimon Schubert }; 392*5796c8dcSSimon Schubert } 393*5796c8dcSSimon Schubert 394*5796c8dcSSimon Schubert if (options->format != 'f') 395*5796c8dcSSimon Schubert val_long = unpack_long (type, valaddr); 396*5796c8dcSSimon Schubert 397*5796c8dcSSimon Schubert /* If the value is a pointer, and pointers and addresses are not the 398*5796c8dcSSimon Schubert same, then at this point, the value's length (in target bytes) is 399*5796c8dcSSimon Schubert gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */ 400*5796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_PTR) 401*5796c8dcSSimon Schubert len = gdbarch_addr_bit (gdbarch) / TARGET_CHAR_BIT; 402*5796c8dcSSimon Schubert 403*5796c8dcSSimon Schubert /* If we are printing it as unsigned, truncate it in case it is actually 404*5796c8dcSSimon Schubert a negative signed value (e.g. "print/u (short)-1" should print 65535 405*5796c8dcSSimon Schubert (if shorts are 16 bits) instead of 4294967295). */ 406*5796c8dcSSimon Schubert if (options->format != 'd' || TYPE_UNSIGNED (type)) 407*5796c8dcSSimon Schubert { 408*5796c8dcSSimon Schubert if (len < sizeof (LONGEST)) 409*5796c8dcSSimon Schubert val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1; 410*5796c8dcSSimon Schubert } 411*5796c8dcSSimon Schubert 412*5796c8dcSSimon Schubert switch (options->format) 413*5796c8dcSSimon Schubert { 414*5796c8dcSSimon Schubert case 'x': 415*5796c8dcSSimon Schubert if (!size) 416*5796c8dcSSimon Schubert { 417*5796c8dcSSimon Schubert /* No size specified, like in print. Print varying # of digits. */ 418*5796c8dcSSimon Schubert print_longest (stream, 'x', 1, val_long); 419*5796c8dcSSimon Schubert } 420*5796c8dcSSimon Schubert else 421*5796c8dcSSimon Schubert switch (size) 422*5796c8dcSSimon Schubert { 423*5796c8dcSSimon Schubert case 'b': 424*5796c8dcSSimon Schubert case 'h': 425*5796c8dcSSimon Schubert case 'w': 426*5796c8dcSSimon Schubert case 'g': 427*5796c8dcSSimon Schubert print_longest (stream, size, 1, val_long); 428*5796c8dcSSimon Schubert break; 429*5796c8dcSSimon Schubert default: 430*5796c8dcSSimon Schubert error (_("Undefined output size \"%c\"."), size); 431*5796c8dcSSimon Schubert } 432*5796c8dcSSimon Schubert break; 433*5796c8dcSSimon Schubert 434*5796c8dcSSimon Schubert case 'd': 435*5796c8dcSSimon Schubert print_longest (stream, 'd', 1, val_long); 436*5796c8dcSSimon Schubert break; 437*5796c8dcSSimon Schubert 438*5796c8dcSSimon Schubert case 'u': 439*5796c8dcSSimon Schubert print_longest (stream, 'u', 0, val_long); 440*5796c8dcSSimon Schubert break; 441*5796c8dcSSimon Schubert 442*5796c8dcSSimon Schubert case 'o': 443*5796c8dcSSimon Schubert if (val_long) 444*5796c8dcSSimon Schubert print_longest (stream, 'o', 1, val_long); 445*5796c8dcSSimon Schubert else 446*5796c8dcSSimon Schubert fprintf_filtered (stream, "0"); 447*5796c8dcSSimon Schubert break; 448*5796c8dcSSimon Schubert 449*5796c8dcSSimon Schubert case 'a': 450*5796c8dcSSimon Schubert { 451*5796c8dcSSimon Schubert CORE_ADDR addr = unpack_pointer (type, valaddr); 452*5796c8dcSSimon Schubert print_address (gdbarch, addr, stream); 453*5796c8dcSSimon Schubert } 454*5796c8dcSSimon Schubert break; 455*5796c8dcSSimon Schubert 456*5796c8dcSSimon Schubert case 'c': 457*5796c8dcSSimon Schubert { 458*5796c8dcSSimon Schubert struct value_print_options opts = *options; 459*5796c8dcSSimon Schubert opts.format = 0; 460*5796c8dcSSimon Schubert 461*5796c8dcSSimon Schubert if (TYPE_UNSIGNED (type)) 462*5796c8dcSSimon Schubert type = builtin_type (gdbarch)->builtin_true_unsigned_char; 463*5796c8dcSSimon Schubert else 464*5796c8dcSSimon Schubert type = builtin_type (gdbarch)->builtin_true_char; 465*5796c8dcSSimon Schubert 466*5796c8dcSSimon Schubert value_print (value_from_longest (type, val_long), stream, &opts); 467*5796c8dcSSimon Schubert } 468*5796c8dcSSimon Schubert break; 469*5796c8dcSSimon Schubert 470*5796c8dcSSimon Schubert case 'f': 471*5796c8dcSSimon Schubert type = float_type_from_length (type); 472*5796c8dcSSimon Schubert print_floating (valaddr, type, stream); 473*5796c8dcSSimon Schubert break; 474*5796c8dcSSimon Schubert 475*5796c8dcSSimon Schubert case 0: 476*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 477*5796c8dcSSimon Schubert _("failed internal consistency check")); 478*5796c8dcSSimon Schubert 479*5796c8dcSSimon Schubert case 't': 480*5796c8dcSSimon Schubert /* Binary; 't' stands for "two". */ 481*5796c8dcSSimon Schubert { 482*5796c8dcSSimon Schubert char bits[8 * (sizeof val_long) + 1]; 483*5796c8dcSSimon Schubert char buf[8 * (sizeof val_long) + 32]; 484*5796c8dcSSimon Schubert char *cp = bits; 485*5796c8dcSSimon Schubert int width; 486*5796c8dcSSimon Schubert 487*5796c8dcSSimon Schubert if (!size) 488*5796c8dcSSimon Schubert width = 8 * (sizeof val_long); 489*5796c8dcSSimon Schubert else 490*5796c8dcSSimon Schubert switch (size) 491*5796c8dcSSimon Schubert { 492*5796c8dcSSimon Schubert case 'b': 493*5796c8dcSSimon Schubert width = 8; 494*5796c8dcSSimon Schubert break; 495*5796c8dcSSimon Schubert case 'h': 496*5796c8dcSSimon Schubert width = 16; 497*5796c8dcSSimon Schubert break; 498*5796c8dcSSimon Schubert case 'w': 499*5796c8dcSSimon Schubert width = 32; 500*5796c8dcSSimon Schubert break; 501*5796c8dcSSimon Schubert case 'g': 502*5796c8dcSSimon Schubert width = 64; 503*5796c8dcSSimon Schubert break; 504*5796c8dcSSimon Schubert default: 505*5796c8dcSSimon Schubert error (_("Undefined output size \"%c\"."), size); 506*5796c8dcSSimon Schubert } 507*5796c8dcSSimon Schubert 508*5796c8dcSSimon Schubert bits[width] = '\0'; 509*5796c8dcSSimon Schubert while (width-- > 0) 510*5796c8dcSSimon Schubert { 511*5796c8dcSSimon Schubert bits[width] = (val_long & 1) ? '1' : '0'; 512*5796c8dcSSimon Schubert val_long >>= 1; 513*5796c8dcSSimon Schubert } 514*5796c8dcSSimon Schubert if (!size) 515*5796c8dcSSimon Schubert { 516*5796c8dcSSimon Schubert while (*cp && *cp == '0') 517*5796c8dcSSimon Schubert cp++; 518*5796c8dcSSimon Schubert if (*cp == '\0') 519*5796c8dcSSimon Schubert cp--; 520*5796c8dcSSimon Schubert } 521*5796c8dcSSimon Schubert strcpy (buf, cp); 522*5796c8dcSSimon Schubert fputs_filtered (buf, stream); 523*5796c8dcSSimon Schubert } 524*5796c8dcSSimon Schubert break; 525*5796c8dcSSimon Schubert 526*5796c8dcSSimon Schubert default: 527*5796c8dcSSimon Schubert error (_("Undefined output format \"%c\"."), options->format); 528*5796c8dcSSimon Schubert } 529*5796c8dcSSimon Schubert } 530*5796c8dcSSimon Schubert 531*5796c8dcSSimon Schubert /* Specify default address for `x' command. 532*5796c8dcSSimon Schubert The `info lines' command uses this. */ 533*5796c8dcSSimon Schubert 534*5796c8dcSSimon Schubert void 535*5796c8dcSSimon Schubert set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr) 536*5796c8dcSSimon Schubert { 537*5796c8dcSSimon Schubert struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr; 538*5796c8dcSSimon Schubert 539*5796c8dcSSimon Schubert next_gdbarch = gdbarch; 540*5796c8dcSSimon Schubert next_address = addr; 541*5796c8dcSSimon Schubert 542*5796c8dcSSimon Schubert /* Make address available to the user as $_. */ 543*5796c8dcSSimon Schubert set_internalvar (lookup_internalvar ("_"), 544*5796c8dcSSimon Schubert value_from_pointer (ptr_type, addr)); 545*5796c8dcSSimon Schubert } 546*5796c8dcSSimon Schubert 547*5796c8dcSSimon Schubert /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM, 548*5796c8dcSSimon Schubert after LEADIN. Print nothing if no symbolic name is found nearby. 549*5796c8dcSSimon Schubert Optionally also print source file and line number, if available. 550*5796c8dcSSimon Schubert DO_DEMANGLE controls whether to print a symbol in its native "raw" form, 551*5796c8dcSSimon Schubert or to interpret it as a possible C++ name and convert it back to source 552*5796c8dcSSimon Schubert form. However note that DO_DEMANGLE can be overridden by the specific 553*5796c8dcSSimon Schubert settings of the demangle and asm_demangle variables. */ 554*5796c8dcSSimon Schubert 555*5796c8dcSSimon Schubert void 556*5796c8dcSSimon Schubert print_address_symbolic (CORE_ADDR addr, struct ui_file *stream, 557*5796c8dcSSimon Schubert int do_demangle, char *leadin) 558*5796c8dcSSimon Schubert { 559*5796c8dcSSimon Schubert char *name = NULL; 560*5796c8dcSSimon Schubert char *filename = NULL; 561*5796c8dcSSimon Schubert int unmapped = 0; 562*5796c8dcSSimon Schubert int offset = 0; 563*5796c8dcSSimon Schubert int line = 0; 564*5796c8dcSSimon Schubert 565*5796c8dcSSimon Schubert /* Throw away both name and filename. */ 566*5796c8dcSSimon Schubert struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name); 567*5796c8dcSSimon Schubert make_cleanup (free_current_contents, &filename); 568*5796c8dcSSimon Schubert 569*5796c8dcSSimon Schubert if (build_address_symbolic (addr, do_demangle, &name, &offset, 570*5796c8dcSSimon Schubert &filename, &line, &unmapped)) 571*5796c8dcSSimon Schubert { 572*5796c8dcSSimon Schubert do_cleanups (cleanup_chain); 573*5796c8dcSSimon Schubert return; 574*5796c8dcSSimon Schubert } 575*5796c8dcSSimon Schubert 576*5796c8dcSSimon Schubert fputs_filtered (leadin, stream); 577*5796c8dcSSimon Schubert if (unmapped) 578*5796c8dcSSimon Schubert fputs_filtered ("<*", stream); 579*5796c8dcSSimon Schubert else 580*5796c8dcSSimon Schubert fputs_filtered ("<", stream); 581*5796c8dcSSimon Schubert fputs_filtered (name, stream); 582*5796c8dcSSimon Schubert if (offset != 0) 583*5796c8dcSSimon Schubert fprintf_filtered (stream, "+%u", (unsigned int) offset); 584*5796c8dcSSimon Schubert 585*5796c8dcSSimon Schubert /* Append source filename and line number if desired. Give specific 586*5796c8dcSSimon Schubert line # of this addr, if we have it; else line # of the nearest symbol. */ 587*5796c8dcSSimon Schubert if (print_symbol_filename && filename != NULL) 588*5796c8dcSSimon Schubert { 589*5796c8dcSSimon Schubert if (line != -1) 590*5796c8dcSSimon Schubert fprintf_filtered (stream, " at %s:%d", filename, line); 591*5796c8dcSSimon Schubert else 592*5796c8dcSSimon Schubert fprintf_filtered (stream, " in %s", filename); 593*5796c8dcSSimon Schubert } 594*5796c8dcSSimon Schubert if (unmapped) 595*5796c8dcSSimon Schubert fputs_filtered ("*>", stream); 596*5796c8dcSSimon Schubert else 597*5796c8dcSSimon Schubert fputs_filtered (">", stream); 598*5796c8dcSSimon Schubert 599*5796c8dcSSimon Schubert do_cleanups (cleanup_chain); 600*5796c8dcSSimon Schubert } 601*5796c8dcSSimon Schubert 602*5796c8dcSSimon Schubert /* Given an address ADDR return all the elements needed to print the 603*5796c8dcSSimon Schubert address in a symbolic form. NAME can be mangled or not depending 604*5796c8dcSSimon Schubert on DO_DEMANGLE (and also on the asm_demangle global variable, 605*5796c8dcSSimon Schubert manipulated via ''set print asm-demangle''). Return 0 in case of 606*5796c8dcSSimon Schubert success, when all the info in the OUT paramters is valid. Return 1 607*5796c8dcSSimon Schubert otherwise. */ 608*5796c8dcSSimon Schubert int 609*5796c8dcSSimon Schubert build_address_symbolic (CORE_ADDR addr, /* IN */ 610*5796c8dcSSimon Schubert int do_demangle, /* IN */ 611*5796c8dcSSimon Schubert char **name, /* OUT */ 612*5796c8dcSSimon Schubert int *offset, /* OUT */ 613*5796c8dcSSimon Schubert char **filename, /* OUT */ 614*5796c8dcSSimon Schubert int *line, /* OUT */ 615*5796c8dcSSimon Schubert int *unmapped) /* OUT */ 616*5796c8dcSSimon Schubert { 617*5796c8dcSSimon Schubert struct minimal_symbol *msymbol; 618*5796c8dcSSimon Schubert struct symbol *symbol; 619*5796c8dcSSimon Schubert CORE_ADDR name_location = 0; 620*5796c8dcSSimon Schubert struct obj_section *section = NULL; 621*5796c8dcSSimon Schubert char *name_temp = ""; 622*5796c8dcSSimon Schubert 623*5796c8dcSSimon Schubert /* Let's say it is mapped (not unmapped). */ 624*5796c8dcSSimon Schubert *unmapped = 0; 625*5796c8dcSSimon Schubert 626*5796c8dcSSimon Schubert /* Determine if the address is in an overlay, and whether it is 627*5796c8dcSSimon Schubert mapped. */ 628*5796c8dcSSimon Schubert if (overlay_debugging) 629*5796c8dcSSimon Schubert { 630*5796c8dcSSimon Schubert section = find_pc_overlay (addr); 631*5796c8dcSSimon Schubert if (pc_in_unmapped_range (addr, section)) 632*5796c8dcSSimon Schubert { 633*5796c8dcSSimon Schubert *unmapped = 1; 634*5796c8dcSSimon Schubert addr = overlay_mapped_address (addr, section); 635*5796c8dcSSimon Schubert } 636*5796c8dcSSimon Schubert } 637*5796c8dcSSimon Schubert 638*5796c8dcSSimon Schubert /* First try to find the address in the symbol table, then 639*5796c8dcSSimon Schubert in the minsyms. Take the closest one. */ 640*5796c8dcSSimon Schubert 641*5796c8dcSSimon Schubert /* This is defective in the sense that it only finds text symbols. So 642*5796c8dcSSimon Schubert really this is kind of pointless--we should make sure that the 643*5796c8dcSSimon Schubert minimal symbols have everything we need (by changing that we could 644*5796c8dcSSimon Schubert save some memory, but for many debug format--ELF/DWARF or 645*5796c8dcSSimon Schubert anything/stabs--it would be inconvenient to eliminate those minimal 646*5796c8dcSSimon Schubert symbols anyway). */ 647*5796c8dcSSimon Schubert msymbol = lookup_minimal_symbol_by_pc_section (addr, section); 648*5796c8dcSSimon Schubert symbol = find_pc_sect_function (addr, section); 649*5796c8dcSSimon Schubert 650*5796c8dcSSimon Schubert if (symbol) 651*5796c8dcSSimon Schubert { 652*5796c8dcSSimon Schubert name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)); 653*5796c8dcSSimon Schubert if (do_demangle || asm_demangle) 654*5796c8dcSSimon Schubert name_temp = SYMBOL_PRINT_NAME (symbol); 655*5796c8dcSSimon Schubert else 656*5796c8dcSSimon Schubert name_temp = SYMBOL_LINKAGE_NAME (symbol); 657*5796c8dcSSimon Schubert } 658*5796c8dcSSimon Schubert 659*5796c8dcSSimon Schubert if (msymbol != NULL) 660*5796c8dcSSimon Schubert { 661*5796c8dcSSimon Schubert if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL) 662*5796c8dcSSimon Schubert { 663*5796c8dcSSimon Schubert /* The msymbol is closer to the address than the symbol; 664*5796c8dcSSimon Schubert use the msymbol instead. */ 665*5796c8dcSSimon Schubert symbol = 0; 666*5796c8dcSSimon Schubert name_location = SYMBOL_VALUE_ADDRESS (msymbol); 667*5796c8dcSSimon Schubert if (do_demangle || asm_demangle) 668*5796c8dcSSimon Schubert name_temp = SYMBOL_PRINT_NAME (msymbol); 669*5796c8dcSSimon Schubert else 670*5796c8dcSSimon Schubert name_temp = SYMBOL_LINKAGE_NAME (msymbol); 671*5796c8dcSSimon Schubert } 672*5796c8dcSSimon Schubert } 673*5796c8dcSSimon Schubert if (symbol == NULL && msymbol == NULL) 674*5796c8dcSSimon Schubert return 1; 675*5796c8dcSSimon Schubert 676*5796c8dcSSimon Schubert /* If the nearest symbol is too far away, don't print anything symbolic. */ 677*5796c8dcSSimon Schubert 678*5796c8dcSSimon Schubert /* For when CORE_ADDR is larger than unsigned int, we do math in 679*5796c8dcSSimon Schubert CORE_ADDR. But when we detect unsigned wraparound in the 680*5796c8dcSSimon Schubert CORE_ADDR math, we ignore this test and print the offset, 681*5796c8dcSSimon Schubert because addr+max_symbolic_offset has wrapped through the end 682*5796c8dcSSimon Schubert of the address space back to the beginning, giving bogus comparison. */ 683*5796c8dcSSimon Schubert if (addr > name_location + max_symbolic_offset 684*5796c8dcSSimon Schubert && name_location + max_symbolic_offset > name_location) 685*5796c8dcSSimon Schubert return 1; 686*5796c8dcSSimon Schubert 687*5796c8dcSSimon Schubert *offset = addr - name_location; 688*5796c8dcSSimon Schubert 689*5796c8dcSSimon Schubert *name = xstrdup (name_temp); 690*5796c8dcSSimon Schubert 691*5796c8dcSSimon Schubert if (print_symbol_filename) 692*5796c8dcSSimon Schubert { 693*5796c8dcSSimon Schubert struct symtab_and_line sal; 694*5796c8dcSSimon Schubert 695*5796c8dcSSimon Schubert sal = find_pc_sect_line (addr, section, 0); 696*5796c8dcSSimon Schubert 697*5796c8dcSSimon Schubert if (sal.symtab) 698*5796c8dcSSimon Schubert { 699*5796c8dcSSimon Schubert *filename = xstrdup (sal.symtab->filename); 700*5796c8dcSSimon Schubert *line = sal.line; 701*5796c8dcSSimon Schubert } 702*5796c8dcSSimon Schubert } 703*5796c8dcSSimon Schubert return 0; 704*5796c8dcSSimon Schubert } 705*5796c8dcSSimon Schubert 706*5796c8dcSSimon Schubert 707*5796c8dcSSimon Schubert /* Print address ADDR symbolically on STREAM. 708*5796c8dcSSimon Schubert First print it as a number. Then perhaps print 709*5796c8dcSSimon Schubert <SYMBOL + OFFSET> after the number. */ 710*5796c8dcSSimon Schubert 711*5796c8dcSSimon Schubert void 712*5796c8dcSSimon Schubert print_address (struct gdbarch *gdbarch, 713*5796c8dcSSimon Schubert CORE_ADDR addr, struct ui_file *stream) 714*5796c8dcSSimon Schubert { 715*5796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, addr), stream); 716*5796c8dcSSimon Schubert print_address_symbolic (addr, stream, asm_demangle, " "); 717*5796c8dcSSimon Schubert } 718*5796c8dcSSimon Schubert 719*5796c8dcSSimon Schubert /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE 720*5796c8dcSSimon Schubert controls whether to print the symbolic name "raw" or demangled. 721*5796c8dcSSimon Schubert Global setting "addressprint" controls whether to print hex address 722*5796c8dcSSimon Schubert or not. */ 723*5796c8dcSSimon Schubert 724*5796c8dcSSimon Schubert void 725*5796c8dcSSimon Schubert print_address_demangle (struct gdbarch *gdbarch, CORE_ADDR addr, 726*5796c8dcSSimon Schubert struct ui_file *stream, int do_demangle) 727*5796c8dcSSimon Schubert { 728*5796c8dcSSimon Schubert struct value_print_options opts; 729*5796c8dcSSimon Schubert get_user_print_options (&opts); 730*5796c8dcSSimon Schubert if (addr == 0) 731*5796c8dcSSimon Schubert { 732*5796c8dcSSimon Schubert fprintf_filtered (stream, "0"); 733*5796c8dcSSimon Schubert } 734*5796c8dcSSimon Schubert else if (opts.addressprint) 735*5796c8dcSSimon Schubert { 736*5796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, addr), stream); 737*5796c8dcSSimon Schubert print_address_symbolic (addr, stream, do_demangle, " "); 738*5796c8dcSSimon Schubert } 739*5796c8dcSSimon Schubert else 740*5796c8dcSSimon Schubert { 741*5796c8dcSSimon Schubert print_address_symbolic (addr, stream, do_demangle, ""); 742*5796c8dcSSimon Schubert } 743*5796c8dcSSimon Schubert } 744*5796c8dcSSimon Schubert 745*5796c8dcSSimon Schubert 746*5796c8dcSSimon Schubert /* Examine data at address ADDR in format FMT. 747*5796c8dcSSimon Schubert Fetch it from memory and print on gdb_stdout. */ 748*5796c8dcSSimon Schubert 749*5796c8dcSSimon Schubert static void 750*5796c8dcSSimon Schubert do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr) 751*5796c8dcSSimon Schubert { 752*5796c8dcSSimon Schubert char format = 0; 753*5796c8dcSSimon Schubert char size; 754*5796c8dcSSimon Schubert int count = 1; 755*5796c8dcSSimon Schubert struct type *val_type = NULL; 756*5796c8dcSSimon Schubert int i; 757*5796c8dcSSimon Schubert int maxelts; 758*5796c8dcSSimon Schubert struct value_print_options opts; 759*5796c8dcSSimon Schubert 760*5796c8dcSSimon Schubert format = fmt.format; 761*5796c8dcSSimon Schubert size = fmt.size; 762*5796c8dcSSimon Schubert count = fmt.count; 763*5796c8dcSSimon Schubert next_gdbarch = gdbarch; 764*5796c8dcSSimon Schubert next_address = addr; 765*5796c8dcSSimon Schubert 766*5796c8dcSSimon Schubert /* String or instruction format implies fetch single bytes 767*5796c8dcSSimon Schubert regardless of the specified size. */ 768*5796c8dcSSimon Schubert if (format == 's' || format == 'i') 769*5796c8dcSSimon Schubert size = 'b'; 770*5796c8dcSSimon Schubert 771*5796c8dcSSimon Schubert if (size == 'a') 772*5796c8dcSSimon Schubert { 773*5796c8dcSSimon Schubert /* Pick the appropriate size for an address. */ 774*5796c8dcSSimon Schubert if (gdbarch_ptr_bit (next_gdbarch) == 64) 775*5796c8dcSSimon Schubert size = 'g'; 776*5796c8dcSSimon Schubert else if (gdbarch_ptr_bit (next_gdbarch) == 32) 777*5796c8dcSSimon Schubert size = 'w'; 778*5796c8dcSSimon Schubert else if (gdbarch_ptr_bit (next_gdbarch) == 16) 779*5796c8dcSSimon Schubert size = 'h'; 780*5796c8dcSSimon Schubert else 781*5796c8dcSSimon Schubert /* Bad value for gdbarch_ptr_bit. */ 782*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 783*5796c8dcSSimon Schubert _("failed internal consistency check")); 784*5796c8dcSSimon Schubert } 785*5796c8dcSSimon Schubert 786*5796c8dcSSimon Schubert if (size == 'b') 787*5796c8dcSSimon Schubert val_type = builtin_type (next_gdbarch)->builtin_int8; 788*5796c8dcSSimon Schubert else if (size == 'h') 789*5796c8dcSSimon Schubert val_type = builtin_type (next_gdbarch)->builtin_int16; 790*5796c8dcSSimon Schubert else if (size == 'w') 791*5796c8dcSSimon Schubert val_type = builtin_type (next_gdbarch)->builtin_int32; 792*5796c8dcSSimon Schubert else if (size == 'g') 793*5796c8dcSSimon Schubert val_type = builtin_type (next_gdbarch)->builtin_int64; 794*5796c8dcSSimon Schubert 795*5796c8dcSSimon Schubert maxelts = 8; 796*5796c8dcSSimon Schubert if (size == 'w') 797*5796c8dcSSimon Schubert maxelts = 4; 798*5796c8dcSSimon Schubert if (size == 'g') 799*5796c8dcSSimon Schubert maxelts = 2; 800*5796c8dcSSimon Schubert if (format == 's' || format == 'i') 801*5796c8dcSSimon Schubert maxelts = 1; 802*5796c8dcSSimon Schubert 803*5796c8dcSSimon Schubert get_formatted_print_options (&opts, format); 804*5796c8dcSSimon Schubert 805*5796c8dcSSimon Schubert /* Print as many objects as specified in COUNT, at most maxelts per line, 806*5796c8dcSSimon Schubert with the address of the next one at the start of each line. */ 807*5796c8dcSSimon Schubert 808*5796c8dcSSimon Schubert while (count > 0) 809*5796c8dcSSimon Schubert { 810*5796c8dcSSimon Schubert QUIT; 811*5796c8dcSSimon Schubert print_address (next_gdbarch, next_address, gdb_stdout); 812*5796c8dcSSimon Schubert printf_filtered (":"); 813*5796c8dcSSimon Schubert for (i = maxelts; 814*5796c8dcSSimon Schubert i > 0 && count > 0; 815*5796c8dcSSimon Schubert i--, count--) 816*5796c8dcSSimon Schubert { 817*5796c8dcSSimon Schubert printf_filtered ("\t"); 818*5796c8dcSSimon Schubert /* Note that print_formatted sets next_address for the next 819*5796c8dcSSimon Schubert object. */ 820*5796c8dcSSimon Schubert last_examine_address = next_address; 821*5796c8dcSSimon Schubert 822*5796c8dcSSimon Schubert if (last_examine_value) 823*5796c8dcSSimon Schubert value_free (last_examine_value); 824*5796c8dcSSimon Schubert 825*5796c8dcSSimon Schubert /* The value to be displayed is not fetched greedily. 826*5796c8dcSSimon Schubert Instead, to avoid the possibility of a fetched value not 827*5796c8dcSSimon Schubert being used, its retrieval is delayed until the print code 828*5796c8dcSSimon Schubert uses it. When examining an instruction stream, the 829*5796c8dcSSimon Schubert disassembler will perform its own memory fetch using just 830*5796c8dcSSimon Schubert the address stored in LAST_EXAMINE_VALUE. FIXME: Should 831*5796c8dcSSimon Schubert the disassembler be modified so that LAST_EXAMINE_VALUE 832*5796c8dcSSimon Schubert is left with the byte sequence from the last complete 833*5796c8dcSSimon Schubert instruction fetched from memory? */ 834*5796c8dcSSimon Schubert last_examine_value = value_at_lazy (val_type, next_address); 835*5796c8dcSSimon Schubert 836*5796c8dcSSimon Schubert if (last_examine_value) 837*5796c8dcSSimon Schubert release_value (last_examine_value); 838*5796c8dcSSimon Schubert 839*5796c8dcSSimon Schubert print_formatted (last_examine_value, size, &opts, gdb_stdout); 840*5796c8dcSSimon Schubert 841*5796c8dcSSimon Schubert /* Display any branch delay slots following the final insn. */ 842*5796c8dcSSimon Schubert if (format == 'i' && count == 1) 843*5796c8dcSSimon Schubert count += branch_delay_insns; 844*5796c8dcSSimon Schubert } 845*5796c8dcSSimon Schubert printf_filtered ("\n"); 846*5796c8dcSSimon Schubert gdb_flush (gdb_stdout); 847*5796c8dcSSimon Schubert } 848*5796c8dcSSimon Schubert } 849*5796c8dcSSimon Schubert 850*5796c8dcSSimon Schubert static void 851*5796c8dcSSimon Schubert validate_format (struct format_data fmt, char *cmdname) 852*5796c8dcSSimon Schubert { 853*5796c8dcSSimon Schubert if (fmt.size != 0) 854*5796c8dcSSimon Schubert error (_("Size letters are meaningless in \"%s\" command."), cmdname); 855*5796c8dcSSimon Schubert if (fmt.count != 1) 856*5796c8dcSSimon Schubert error (_("Item count other than 1 is meaningless in \"%s\" command."), 857*5796c8dcSSimon Schubert cmdname); 858*5796c8dcSSimon Schubert if (fmt.format == 'i') 859*5796c8dcSSimon Schubert error (_("Format letter \"%c\" is meaningless in \"%s\" command."), 860*5796c8dcSSimon Schubert fmt.format, cmdname); 861*5796c8dcSSimon Schubert } 862*5796c8dcSSimon Schubert 863*5796c8dcSSimon Schubert /* Evaluate string EXP as an expression in the current language and 864*5796c8dcSSimon Schubert print the resulting value. EXP may contain a format specifier as the 865*5796c8dcSSimon Schubert first argument ("/x myvar" for example, to print myvar in hex). */ 866*5796c8dcSSimon Schubert 867*5796c8dcSSimon Schubert static void 868*5796c8dcSSimon Schubert print_command_1 (char *exp, int inspect, int voidprint) 869*5796c8dcSSimon Schubert { 870*5796c8dcSSimon Schubert struct expression *expr; 871*5796c8dcSSimon Schubert struct cleanup *old_chain = 0; 872*5796c8dcSSimon Schubert char format = 0; 873*5796c8dcSSimon Schubert struct value *val; 874*5796c8dcSSimon Schubert struct format_data fmt; 875*5796c8dcSSimon Schubert int cleanup = 0; 876*5796c8dcSSimon Schubert 877*5796c8dcSSimon Schubert if (exp && *exp == '/') 878*5796c8dcSSimon Schubert { 879*5796c8dcSSimon Schubert exp++; 880*5796c8dcSSimon Schubert fmt = decode_format (&exp, last_format, 0); 881*5796c8dcSSimon Schubert validate_format (fmt, "print"); 882*5796c8dcSSimon Schubert last_format = format = fmt.format; 883*5796c8dcSSimon Schubert } 884*5796c8dcSSimon Schubert else 885*5796c8dcSSimon Schubert { 886*5796c8dcSSimon Schubert fmt.count = 1; 887*5796c8dcSSimon Schubert fmt.format = 0; 888*5796c8dcSSimon Schubert fmt.size = 0; 889*5796c8dcSSimon Schubert fmt.raw = 0; 890*5796c8dcSSimon Schubert } 891*5796c8dcSSimon Schubert 892*5796c8dcSSimon Schubert if (exp && *exp) 893*5796c8dcSSimon Schubert { 894*5796c8dcSSimon Schubert struct type *type; 895*5796c8dcSSimon Schubert expr = parse_expression (exp); 896*5796c8dcSSimon Schubert old_chain = make_cleanup (free_current_contents, &expr); 897*5796c8dcSSimon Schubert cleanup = 1; 898*5796c8dcSSimon Schubert val = evaluate_expression (expr); 899*5796c8dcSSimon Schubert } 900*5796c8dcSSimon Schubert else 901*5796c8dcSSimon Schubert val = access_value_history (0); 902*5796c8dcSSimon Schubert 903*5796c8dcSSimon Schubert if (voidprint || (val && value_type (val) && 904*5796c8dcSSimon Schubert TYPE_CODE (value_type (val)) != TYPE_CODE_VOID)) 905*5796c8dcSSimon Schubert { 906*5796c8dcSSimon Schubert struct value_print_options opts; 907*5796c8dcSSimon Schubert int histindex = record_latest_value (val); 908*5796c8dcSSimon Schubert 909*5796c8dcSSimon Schubert if (histindex >= 0) 910*5796c8dcSSimon Schubert annotate_value_history_begin (histindex, value_type (val)); 911*5796c8dcSSimon Schubert else 912*5796c8dcSSimon Schubert annotate_value_begin (value_type (val)); 913*5796c8dcSSimon Schubert 914*5796c8dcSSimon Schubert if (inspect) 915*5796c8dcSSimon Schubert printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", 916*5796c8dcSSimon Schubert exp, histindex); 917*5796c8dcSSimon Schubert else if (histindex >= 0) 918*5796c8dcSSimon Schubert printf_filtered ("$%d = ", histindex); 919*5796c8dcSSimon Schubert 920*5796c8dcSSimon Schubert if (histindex >= 0) 921*5796c8dcSSimon Schubert annotate_value_history_value (); 922*5796c8dcSSimon Schubert 923*5796c8dcSSimon Schubert get_formatted_print_options (&opts, format); 924*5796c8dcSSimon Schubert opts.inspect_it = inspect; 925*5796c8dcSSimon Schubert opts.raw = fmt.raw; 926*5796c8dcSSimon Schubert 927*5796c8dcSSimon Schubert print_formatted (val, fmt.size, &opts, gdb_stdout); 928*5796c8dcSSimon Schubert printf_filtered ("\n"); 929*5796c8dcSSimon Schubert 930*5796c8dcSSimon Schubert if (histindex >= 0) 931*5796c8dcSSimon Schubert annotate_value_history_end (); 932*5796c8dcSSimon Schubert else 933*5796c8dcSSimon Schubert annotate_value_end (); 934*5796c8dcSSimon Schubert 935*5796c8dcSSimon Schubert if (inspect) 936*5796c8dcSSimon Schubert printf_unfiltered ("\") )\030"); 937*5796c8dcSSimon Schubert } 938*5796c8dcSSimon Schubert 939*5796c8dcSSimon Schubert if (cleanup) 940*5796c8dcSSimon Schubert do_cleanups (old_chain); 941*5796c8dcSSimon Schubert } 942*5796c8dcSSimon Schubert 943*5796c8dcSSimon Schubert static void 944*5796c8dcSSimon Schubert print_command (char *exp, int from_tty) 945*5796c8dcSSimon Schubert { 946*5796c8dcSSimon Schubert print_command_1 (exp, 0, 1); 947*5796c8dcSSimon Schubert } 948*5796c8dcSSimon Schubert 949*5796c8dcSSimon Schubert /* Same as print, except in epoch, it gets its own window. */ 950*5796c8dcSSimon Schubert static void 951*5796c8dcSSimon Schubert inspect_command (char *exp, int from_tty) 952*5796c8dcSSimon Schubert { 953*5796c8dcSSimon Schubert extern int epoch_interface; 954*5796c8dcSSimon Schubert 955*5796c8dcSSimon Schubert print_command_1 (exp, epoch_interface, 1); 956*5796c8dcSSimon Schubert } 957*5796c8dcSSimon Schubert 958*5796c8dcSSimon Schubert /* Same as print, except it doesn't print void results. */ 959*5796c8dcSSimon Schubert static void 960*5796c8dcSSimon Schubert call_command (char *exp, int from_tty) 961*5796c8dcSSimon Schubert { 962*5796c8dcSSimon Schubert print_command_1 (exp, 0, 0); 963*5796c8dcSSimon Schubert } 964*5796c8dcSSimon Schubert 965*5796c8dcSSimon Schubert void 966*5796c8dcSSimon Schubert output_command (char *exp, int from_tty) 967*5796c8dcSSimon Schubert { 968*5796c8dcSSimon Schubert struct expression *expr; 969*5796c8dcSSimon Schubert struct cleanup *old_chain; 970*5796c8dcSSimon Schubert char format = 0; 971*5796c8dcSSimon Schubert struct value *val; 972*5796c8dcSSimon Schubert struct format_data fmt; 973*5796c8dcSSimon Schubert struct value_print_options opts; 974*5796c8dcSSimon Schubert 975*5796c8dcSSimon Schubert fmt.size = 0; 976*5796c8dcSSimon Schubert fmt.raw = 0; 977*5796c8dcSSimon Schubert 978*5796c8dcSSimon Schubert if (exp && *exp == '/') 979*5796c8dcSSimon Schubert { 980*5796c8dcSSimon Schubert exp++; 981*5796c8dcSSimon Schubert fmt = decode_format (&exp, 0, 0); 982*5796c8dcSSimon Schubert validate_format (fmt, "output"); 983*5796c8dcSSimon Schubert format = fmt.format; 984*5796c8dcSSimon Schubert } 985*5796c8dcSSimon Schubert 986*5796c8dcSSimon Schubert expr = parse_expression (exp); 987*5796c8dcSSimon Schubert old_chain = make_cleanup (free_current_contents, &expr); 988*5796c8dcSSimon Schubert 989*5796c8dcSSimon Schubert val = evaluate_expression (expr); 990*5796c8dcSSimon Schubert 991*5796c8dcSSimon Schubert annotate_value_begin (value_type (val)); 992*5796c8dcSSimon Schubert 993*5796c8dcSSimon Schubert get_formatted_print_options (&opts, format); 994*5796c8dcSSimon Schubert opts.raw = fmt.raw; 995*5796c8dcSSimon Schubert print_formatted (val, fmt.size, &opts, gdb_stdout); 996*5796c8dcSSimon Schubert 997*5796c8dcSSimon Schubert annotate_value_end (); 998*5796c8dcSSimon Schubert 999*5796c8dcSSimon Schubert wrap_here (""); 1000*5796c8dcSSimon Schubert gdb_flush (gdb_stdout); 1001*5796c8dcSSimon Schubert 1002*5796c8dcSSimon Schubert do_cleanups (old_chain); 1003*5796c8dcSSimon Schubert } 1004*5796c8dcSSimon Schubert 1005*5796c8dcSSimon Schubert static void 1006*5796c8dcSSimon Schubert set_command (char *exp, int from_tty) 1007*5796c8dcSSimon Schubert { 1008*5796c8dcSSimon Schubert struct expression *expr = parse_expression (exp); 1009*5796c8dcSSimon Schubert struct cleanup *old_chain = 1010*5796c8dcSSimon Schubert make_cleanup (free_current_contents, &expr); 1011*5796c8dcSSimon Schubert evaluate_expression (expr); 1012*5796c8dcSSimon Schubert do_cleanups (old_chain); 1013*5796c8dcSSimon Schubert } 1014*5796c8dcSSimon Schubert 1015*5796c8dcSSimon Schubert static void 1016*5796c8dcSSimon Schubert sym_info (char *arg, int from_tty) 1017*5796c8dcSSimon Schubert { 1018*5796c8dcSSimon Schubert struct minimal_symbol *msymbol; 1019*5796c8dcSSimon Schubert struct objfile *objfile; 1020*5796c8dcSSimon Schubert struct obj_section *osect; 1021*5796c8dcSSimon Schubert CORE_ADDR addr, sect_addr; 1022*5796c8dcSSimon Schubert int matches = 0; 1023*5796c8dcSSimon Schubert unsigned int offset; 1024*5796c8dcSSimon Schubert 1025*5796c8dcSSimon Schubert if (!arg) 1026*5796c8dcSSimon Schubert error_no_arg (_("address")); 1027*5796c8dcSSimon Schubert 1028*5796c8dcSSimon Schubert addr = parse_and_eval_address (arg); 1029*5796c8dcSSimon Schubert ALL_OBJSECTIONS (objfile, osect) 1030*5796c8dcSSimon Schubert { 1031*5796c8dcSSimon Schubert /* Only process each object file once, even if there's a separate 1032*5796c8dcSSimon Schubert debug file. */ 1033*5796c8dcSSimon Schubert if (objfile->separate_debug_objfile_backlink) 1034*5796c8dcSSimon Schubert continue; 1035*5796c8dcSSimon Schubert 1036*5796c8dcSSimon Schubert sect_addr = overlay_mapped_address (addr, osect); 1037*5796c8dcSSimon Schubert 1038*5796c8dcSSimon Schubert if (obj_section_addr (osect) <= sect_addr 1039*5796c8dcSSimon Schubert && sect_addr < obj_section_endaddr (osect) 1040*5796c8dcSSimon Schubert && (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, osect))) 1041*5796c8dcSSimon Schubert { 1042*5796c8dcSSimon Schubert const char *obj_name, *mapped, *sec_name, *msym_name; 1043*5796c8dcSSimon Schubert char *loc_string; 1044*5796c8dcSSimon Schubert struct cleanup *old_chain; 1045*5796c8dcSSimon Schubert 1046*5796c8dcSSimon Schubert matches = 1; 1047*5796c8dcSSimon Schubert offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol); 1048*5796c8dcSSimon Schubert mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped"); 1049*5796c8dcSSimon Schubert sec_name = osect->the_bfd_section->name; 1050*5796c8dcSSimon Schubert msym_name = SYMBOL_PRINT_NAME (msymbol); 1051*5796c8dcSSimon Schubert 1052*5796c8dcSSimon Schubert /* Don't print the offset if it is zero. 1053*5796c8dcSSimon Schubert We assume there's no need to handle i18n of "sym + offset". */ 1054*5796c8dcSSimon Schubert if (offset) 1055*5796c8dcSSimon Schubert loc_string = xstrprintf ("%s + %u", msym_name, offset); 1056*5796c8dcSSimon Schubert else 1057*5796c8dcSSimon Schubert loc_string = xstrprintf ("%s", msym_name); 1058*5796c8dcSSimon Schubert 1059*5796c8dcSSimon Schubert /* Use a cleanup to free loc_string in case the user quits 1060*5796c8dcSSimon Schubert a pagination request inside printf_filtered. */ 1061*5796c8dcSSimon Schubert old_chain = make_cleanup (xfree, loc_string); 1062*5796c8dcSSimon Schubert 1063*5796c8dcSSimon Schubert gdb_assert (osect->objfile && osect->objfile->name); 1064*5796c8dcSSimon Schubert obj_name = osect->objfile->name; 1065*5796c8dcSSimon Schubert 1066*5796c8dcSSimon Schubert if (MULTI_OBJFILE_P ()) 1067*5796c8dcSSimon Schubert if (pc_in_unmapped_range (addr, osect)) 1068*5796c8dcSSimon Schubert if (section_is_overlay (osect)) 1069*5796c8dcSSimon Schubert printf_filtered (_("%s in load address range of " 1070*5796c8dcSSimon Schubert "%s overlay section %s of %s\n"), 1071*5796c8dcSSimon Schubert loc_string, mapped, sec_name, obj_name); 1072*5796c8dcSSimon Schubert else 1073*5796c8dcSSimon Schubert printf_filtered (_("%s in load address range of " 1074*5796c8dcSSimon Schubert "section %s of %s\n"), 1075*5796c8dcSSimon Schubert loc_string, sec_name, obj_name); 1076*5796c8dcSSimon Schubert else 1077*5796c8dcSSimon Schubert if (section_is_overlay (osect)) 1078*5796c8dcSSimon Schubert printf_filtered (_("%s in %s overlay section %s of %s\n"), 1079*5796c8dcSSimon Schubert loc_string, mapped, sec_name, obj_name); 1080*5796c8dcSSimon Schubert else 1081*5796c8dcSSimon Schubert printf_filtered (_("%s in section %s of %s\n"), 1082*5796c8dcSSimon Schubert loc_string, sec_name, obj_name); 1083*5796c8dcSSimon Schubert else 1084*5796c8dcSSimon Schubert if (pc_in_unmapped_range (addr, osect)) 1085*5796c8dcSSimon Schubert if (section_is_overlay (osect)) 1086*5796c8dcSSimon Schubert printf_filtered (_("%s in load address range of %s overlay " 1087*5796c8dcSSimon Schubert "section %s\n"), 1088*5796c8dcSSimon Schubert loc_string, mapped, sec_name); 1089*5796c8dcSSimon Schubert else 1090*5796c8dcSSimon Schubert printf_filtered (_("%s in load address range of section %s\n"), 1091*5796c8dcSSimon Schubert loc_string, sec_name); 1092*5796c8dcSSimon Schubert else 1093*5796c8dcSSimon Schubert if (section_is_overlay (osect)) 1094*5796c8dcSSimon Schubert printf_filtered (_("%s in %s overlay section %s\n"), 1095*5796c8dcSSimon Schubert loc_string, mapped, sec_name); 1096*5796c8dcSSimon Schubert else 1097*5796c8dcSSimon Schubert printf_filtered (_("%s in section %s\n"), 1098*5796c8dcSSimon Schubert loc_string, sec_name); 1099*5796c8dcSSimon Schubert 1100*5796c8dcSSimon Schubert do_cleanups (old_chain); 1101*5796c8dcSSimon Schubert } 1102*5796c8dcSSimon Schubert } 1103*5796c8dcSSimon Schubert if (matches == 0) 1104*5796c8dcSSimon Schubert printf_filtered (_("No symbol matches %s.\n"), arg); 1105*5796c8dcSSimon Schubert } 1106*5796c8dcSSimon Schubert 1107*5796c8dcSSimon Schubert static void 1108*5796c8dcSSimon Schubert address_info (char *exp, int from_tty) 1109*5796c8dcSSimon Schubert { 1110*5796c8dcSSimon Schubert struct gdbarch *gdbarch; 1111*5796c8dcSSimon Schubert int regno; 1112*5796c8dcSSimon Schubert struct symbol *sym; 1113*5796c8dcSSimon Schubert struct minimal_symbol *msymbol; 1114*5796c8dcSSimon Schubert long val; 1115*5796c8dcSSimon Schubert struct obj_section *section; 1116*5796c8dcSSimon Schubert CORE_ADDR load_addr; 1117*5796c8dcSSimon Schubert int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero 1118*5796c8dcSSimon Schubert if exp is a field of `this'. */ 1119*5796c8dcSSimon Schubert 1120*5796c8dcSSimon Schubert if (exp == 0) 1121*5796c8dcSSimon Schubert error (_("Argument required.")); 1122*5796c8dcSSimon Schubert 1123*5796c8dcSSimon Schubert sym = lookup_symbol (exp, get_selected_block (0), VAR_DOMAIN, 1124*5796c8dcSSimon Schubert &is_a_field_of_this); 1125*5796c8dcSSimon Schubert if (sym == NULL) 1126*5796c8dcSSimon Schubert { 1127*5796c8dcSSimon Schubert if (is_a_field_of_this) 1128*5796c8dcSSimon Schubert { 1129*5796c8dcSSimon Schubert printf_filtered ("Symbol \""); 1130*5796c8dcSSimon Schubert fprintf_symbol_filtered (gdb_stdout, exp, 1131*5796c8dcSSimon Schubert current_language->la_language, DMGL_ANSI); 1132*5796c8dcSSimon Schubert printf_filtered ("\" is a field of the local class variable "); 1133*5796c8dcSSimon Schubert if (current_language->la_language == language_objc) 1134*5796c8dcSSimon Schubert printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */ 1135*5796c8dcSSimon Schubert else 1136*5796c8dcSSimon Schubert printf_filtered ("`this'\n"); 1137*5796c8dcSSimon Schubert return; 1138*5796c8dcSSimon Schubert } 1139*5796c8dcSSimon Schubert 1140*5796c8dcSSimon Schubert msymbol = lookup_minimal_symbol (exp, NULL, NULL); 1141*5796c8dcSSimon Schubert 1142*5796c8dcSSimon Schubert if (msymbol != NULL) 1143*5796c8dcSSimon Schubert { 1144*5796c8dcSSimon Schubert gdbarch = get_objfile_arch (msymbol_objfile (msymbol)); 1145*5796c8dcSSimon Schubert load_addr = SYMBOL_VALUE_ADDRESS (msymbol); 1146*5796c8dcSSimon Schubert 1147*5796c8dcSSimon Schubert printf_filtered ("Symbol \""); 1148*5796c8dcSSimon Schubert fprintf_symbol_filtered (gdb_stdout, exp, 1149*5796c8dcSSimon Schubert current_language->la_language, DMGL_ANSI); 1150*5796c8dcSSimon Schubert printf_filtered ("\" is at "); 1151*5796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 1152*5796c8dcSSimon Schubert printf_filtered (" in a file compiled without debugging"); 1153*5796c8dcSSimon Schubert section = SYMBOL_OBJ_SECTION (msymbol); 1154*5796c8dcSSimon Schubert if (section_is_overlay (section)) 1155*5796c8dcSSimon Schubert { 1156*5796c8dcSSimon Schubert load_addr = overlay_unmapped_address (load_addr, section); 1157*5796c8dcSSimon Schubert printf_filtered (",\n -- loaded at "); 1158*5796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 1159*5796c8dcSSimon Schubert printf_filtered (" in overlay section %s", 1160*5796c8dcSSimon Schubert section->the_bfd_section->name); 1161*5796c8dcSSimon Schubert } 1162*5796c8dcSSimon Schubert printf_filtered (".\n"); 1163*5796c8dcSSimon Schubert } 1164*5796c8dcSSimon Schubert else 1165*5796c8dcSSimon Schubert error (_("No symbol \"%s\" in current context."), exp); 1166*5796c8dcSSimon Schubert return; 1167*5796c8dcSSimon Schubert } 1168*5796c8dcSSimon Schubert 1169*5796c8dcSSimon Schubert printf_filtered ("Symbol \""); 1170*5796c8dcSSimon Schubert fprintf_symbol_filtered (gdb_stdout, SYMBOL_PRINT_NAME (sym), 1171*5796c8dcSSimon Schubert current_language->la_language, DMGL_ANSI); 1172*5796c8dcSSimon Schubert printf_filtered ("\" is "); 1173*5796c8dcSSimon Schubert val = SYMBOL_VALUE (sym); 1174*5796c8dcSSimon Schubert section = SYMBOL_OBJ_SECTION (sym); 1175*5796c8dcSSimon Schubert gdbarch = get_objfile_arch (SYMBOL_SYMTAB (sym)->objfile); 1176*5796c8dcSSimon Schubert 1177*5796c8dcSSimon Schubert switch (SYMBOL_CLASS (sym)) 1178*5796c8dcSSimon Schubert { 1179*5796c8dcSSimon Schubert case LOC_CONST: 1180*5796c8dcSSimon Schubert case LOC_CONST_BYTES: 1181*5796c8dcSSimon Schubert printf_filtered ("constant"); 1182*5796c8dcSSimon Schubert break; 1183*5796c8dcSSimon Schubert 1184*5796c8dcSSimon Schubert case LOC_LABEL: 1185*5796c8dcSSimon Schubert printf_filtered ("a label at address "); 1186*5796c8dcSSimon Schubert load_addr = SYMBOL_VALUE_ADDRESS (sym); 1187*5796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 1188*5796c8dcSSimon Schubert if (section_is_overlay (section)) 1189*5796c8dcSSimon Schubert { 1190*5796c8dcSSimon Schubert load_addr = overlay_unmapped_address (load_addr, section); 1191*5796c8dcSSimon Schubert printf_filtered (",\n -- loaded at "); 1192*5796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 1193*5796c8dcSSimon Schubert printf_filtered (" in overlay section %s", 1194*5796c8dcSSimon Schubert section->the_bfd_section->name); 1195*5796c8dcSSimon Schubert } 1196*5796c8dcSSimon Schubert break; 1197*5796c8dcSSimon Schubert 1198*5796c8dcSSimon Schubert case LOC_COMPUTED: 1199*5796c8dcSSimon Schubert /* FIXME: cagney/2004-01-26: It should be possible to 1200*5796c8dcSSimon Schubert unconditionally call the SYMBOL_COMPUTED_OPS method when available. 1201*5796c8dcSSimon Schubert Unfortunately DWARF 2 stores the frame-base (instead of the 1202*5796c8dcSSimon Schubert function) location in a function's symbol. Oops! For the 1203*5796c8dcSSimon Schubert moment enable this when/where applicable. */ 1204*5796c8dcSSimon Schubert SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, gdb_stdout); 1205*5796c8dcSSimon Schubert break; 1206*5796c8dcSSimon Schubert 1207*5796c8dcSSimon Schubert case LOC_REGISTER: 1208*5796c8dcSSimon Schubert /* GDBARCH is the architecture associated with the objfile the symbol 1209*5796c8dcSSimon Schubert is defined in; the target architecture may be different, and may 1210*5796c8dcSSimon Schubert provide additional registers. However, we do not know the target 1211*5796c8dcSSimon Schubert architecture at this point. We assume the objfile architecture 1212*5796c8dcSSimon Schubert will contain all the standard registers that occur in debug info 1213*5796c8dcSSimon Schubert in that objfile. */ 1214*5796c8dcSSimon Schubert regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); 1215*5796c8dcSSimon Schubert 1216*5796c8dcSSimon Schubert if (SYMBOL_IS_ARGUMENT (sym)) 1217*5796c8dcSSimon Schubert printf_filtered (_("an argument in register %s"), 1218*5796c8dcSSimon Schubert gdbarch_register_name (gdbarch, regno)); 1219*5796c8dcSSimon Schubert else 1220*5796c8dcSSimon Schubert printf_filtered (_("a variable in register %s"), 1221*5796c8dcSSimon Schubert gdbarch_register_name (gdbarch, regno)); 1222*5796c8dcSSimon Schubert break; 1223*5796c8dcSSimon Schubert 1224*5796c8dcSSimon Schubert case LOC_STATIC: 1225*5796c8dcSSimon Schubert printf_filtered (_("static storage at address ")); 1226*5796c8dcSSimon Schubert load_addr = SYMBOL_VALUE_ADDRESS (sym); 1227*5796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 1228*5796c8dcSSimon Schubert if (section_is_overlay (section)) 1229*5796c8dcSSimon Schubert { 1230*5796c8dcSSimon Schubert load_addr = overlay_unmapped_address (load_addr, section); 1231*5796c8dcSSimon Schubert printf_filtered (_(",\n -- loaded at ")); 1232*5796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 1233*5796c8dcSSimon Schubert printf_filtered (_(" in overlay section %s"), 1234*5796c8dcSSimon Schubert section->the_bfd_section->name); 1235*5796c8dcSSimon Schubert } 1236*5796c8dcSSimon Schubert break; 1237*5796c8dcSSimon Schubert 1238*5796c8dcSSimon Schubert case LOC_REGPARM_ADDR: 1239*5796c8dcSSimon Schubert /* Note comment at LOC_REGISTER. */ 1240*5796c8dcSSimon Schubert regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); 1241*5796c8dcSSimon Schubert printf_filtered (_("address of an argument in register %s"), 1242*5796c8dcSSimon Schubert gdbarch_register_name (gdbarch, regno)); 1243*5796c8dcSSimon Schubert break; 1244*5796c8dcSSimon Schubert 1245*5796c8dcSSimon Schubert case LOC_ARG: 1246*5796c8dcSSimon Schubert printf_filtered (_("an argument at offset %ld"), val); 1247*5796c8dcSSimon Schubert break; 1248*5796c8dcSSimon Schubert 1249*5796c8dcSSimon Schubert case LOC_LOCAL: 1250*5796c8dcSSimon Schubert printf_filtered (_("a local variable at frame offset %ld"), val); 1251*5796c8dcSSimon Schubert break; 1252*5796c8dcSSimon Schubert 1253*5796c8dcSSimon Schubert case LOC_REF_ARG: 1254*5796c8dcSSimon Schubert printf_filtered (_("a reference argument at offset %ld"), val); 1255*5796c8dcSSimon Schubert break; 1256*5796c8dcSSimon Schubert 1257*5796c8dcSSimon Schubert case LOC_TYPEDEF: 1258*5796c8dcSSimon Schubert printf_filtered (_("a typedef")); 1259*5796c8dcSSimon Schubert break; 1260*5796c8dcSSimon Schubert 1261*5796c8dcSSimon Schubert case LOC_BLOCK: 1262*5796c8dcSSimon Schubert printf_filtered (_("a function at address ")); 1263*5796c8dcSSimon Schubert load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); 1264*5796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 1265*5796c8dcSSimon Schubert if (section_is_overlay (section)) 1266*5796c8dcSSimon Schubert { 1267*5796c8dcSSimon Schubert load_addr = overlay_unmapped_address (load_addr, section); 1268*5796c8dcSSimon Schubert printf_filtered (_(",\n -- loaded at ")); 1269*5796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 1270*5796c8dcSSimon Schubert printf_filtered (_(" in overlay section %s"), 1271*5796c8dcSSimon Schubert section->the_bfd_section->name); 1272*5796c8dcSSimon Schubert } 1273*5796c8dcSSimon Schubert break; 1274*5796c8dcSSimon Schubert 1275*5796c8dcSSimon Schubert case LOC_UNRESOLVED: 1276*5796c8dcSSimon Schubert { 1277*5796c8dcSSimon Schubert struct minimal_symbol *msym; 1278*5796c8dcSSimon Schubert 1279*5796c8dcSSimon Schubert msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), NULL, NULL); 1280*5796c8dcSSimon Schubert if (msym == NULL) 1281*5796c8dcSSimon Schubert printf_filtered ("unresolved"); 1282*5796c8dcSSimon Schubert else 1283*5796c8dcSSimon Schubert { 1284*5796c8dcSSimon Schubert section = SYMBOL_OBJ_SECTION (msym); 1285*5796c8dcSSimon Schubert load_addr = SYMBOL_VALUE_ADDRESS (msym); 1286*5796c8dcSSimon Schubert 1287*5796c8dcSSimon Schubert if (section 1288*5796c8dcSSimon Schubert && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0) 1289*5796c8dcSSimon Schubert printf_filtered (_("a thread-local variable at offset %s " 1290*5796c8dcSSimon Schubert "in the thread-local storage for `%s'"), 1291*5796c8dcSSimon Schubert paddress (gdbarch, load_addr), 1292*5796c8dcSSimon Schubert section->objfile->name); 1293*5796c8dcSSimon Schubert else 1294*5796c8dcSSimon Schubert { 1295*5796c8dcSSimon Schubert printf_filtered (_("static storage at address ")); 1296*5796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 1297*5796c8dcSSimon Schubert if (section_is_overlay (section)) 1298*5796c8dcSSimon Schubert { 1299*5796c8dcSSimon Schubert load_addr = overlay_unmapped_address (load_addr, section); 1300*5796c8dcSSimon Schubert printf_filtered (_(",\n -- loaded at ")); 1301*5796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 1302*5796c8dcSSimon Schubert printf_filtered (_(" in overlay section %s"), 1303*5796c8dcSSimon Schubert section->the_bfd_section->name); 1304*5796c8dcSSimon Schubert } 1305*5796c8dcSSimon Schubert } 1306*5796c8dcSSimon Schubert } 1307*5796c8dcSSimon Schubert } 1308*5796c8dcSSimon Schubert break; 1309*5796c8dcSSimon Schubert 1310*5796c8dcSSimon Schubert case LOC_OPTIMIZED_OUT: 1311*5796c8dcSSimon Schubert printf_filtered (_("optimized out")); 1312*5796c8dcSSimon Schubert break; 1313*5796c8dcSSimon Schubert 1314*5796c8dcSSimon Schubert default: 1315*5796c8dcSSimon Schubert printf_filtered (_("of unknown (botched) type")); 1316*5796c8dcSSimon Schubert break; 1317*5796c8dcSSimon Schubert } 1318*5796c8dcSSimon Schubert printf_filtered (".\n"); 1319*5796c8dcSSimon Schubert } 1320*5796c8dcSSimon Schubert 1321*5796c8dcSSimon Schubert 1322*5796c8dcSSimon Schubert static void 1323*5796c8dcSSimon Schubert x_command (char *exp, int from_tty) 1324*5796c8dcSSimon Schubert { 1325*5796c8dcSSimon Schubert struct expression *expr; 1326*5796c8dcSSimon Schubert struct format_data fmt; 1327*5796c8dcSSimon Schubert struct cleanup *old_chain; 1328*5796c8dcSSimon Schubert struct value *val; 1329*5796c8dcSSimon Schubert 1330*5796c8dcSSimon Schubert fmt.format = last_format ? last_format : 'x'; 1331*5796c8dcSSimon Schubert fmt.size = last_size; 1332*5796c8dcSSimon Schubert fmt.count = 1; 1333*5796c8dcSSimon Schubert fmt.raw = 0; 1334*5796c8dcSSimon Schubert 1335*5796c8dcSSimon Schubert if (exp && *exp == '/') 1336*5796c8dcSSimon Schubert { 1337*5796c8dcSSimon Schubert exp++; 1338*5796c8dcSSimon Schubert fmt = decode_format (&exp, last_format, last_size); 1339*5796c8dcSSimon Schubert } 1340*5796c8dcSSimon Schubert 1341*5796c8dcSSimon Schubert /* If we have an expression, evaluate it and use it as the address. */ 1342*5796c8dcSSimon Schubert 1343*5796c8dcSSimon Schubert if (exp != 0 && *exp != 0) 1344*5796c8dcSSimon Schubert { 1345*5796c8dcSSimon Schubert expr = parse_expression (exp); 1346*5796c8dcSSimon Schubert /* Cause expression not to be there any more if this command is 1347*5796c8dcSSimon Schubert repeated with Newline. But don't clobber a user-defined 1348*5796c8dcSSimon Schubert command's definition. */ 1349*5796c8dcSSimon Schubert if (from_tty) 1350*5796c8dcSSimon Schubert *exp = 0; 1351*5796c8dcSSimon Schubert old_chain = make_cleanup (free_current_contents, &expr); 1352*5796c8dcSSimon Schubert val = evaluate_expression (expr); 1353*5796c8dcSSimon Schubert if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF) 1354*5796c8dcSSimon Schubert val = value_ind (val); 1355*5796c8dcSSimon Schubert /* In rvalue contexts, such as this, functions are coerced into 1356*5796c8dcSSimon Schubert pointers to functions. This makes "x/i main" work. */ 1357*5796c8dcSSimon Schubert if (/* last_format == 'i' && */ 1358*5796c8dcSSimon Schubert TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC 1359*5796c8dcSSimon Schubert && VALUE_LVAL (val) == lval_memory) 1360*5796c8dcSSimon Schubert next_address = value_address (val); 1361*5796c8dcSSimon Schubert else 1362*5796c8dcSSimon Schubert next_address = value_as_address (val); 1363*5796c8dcSSimon Schubert 1364*5796c8dcSSimon Schubert next_gdbarch = expr->gdbarch; 1365*5796c8dcSSimon Schubert do_cleanups (old_chain); 1366*5796c8dcSSimon Schubert } 1367*5796c8dcSSimon Schubert 1368*5796c8dcSSimon Schubert if (!next_gdbarch) 1369*5796c8dcSSimon Schubert error_no_arg (_("starting display address")); 1370*5796c8dcSSimon Schubert 1371*5796c8dcSSimon Schubert do_examine (fmt, next_gdbarch, next_address); 1372*5796c8dcSSimon Schubert 1373*5796c8dcSSimon Schubert /* If the examine succeeds, we remember its size and format for next 1374*5796c8dcSSimon Schubert time. */ 1375*5796c8dcSSimon Schubert last_size = fmt.size; 1376*5796c8dcSSimon Schubert last_format = fmt.format; 1377*5796c8dcSSimon Schubert 1378*5796c8dcSSimon Schubert /* Set a couple of internal variables if appropriate. */ 1379*5796c8dcSSimon Schubert if (last_examine_value) 1380*5796c8dcSSimon Schubert { 1381*5796c8dcSSimon Schubert /* Make last address examined available to the user as $_. Use 1382*5796c8dcSSimon Schubert the correct pointer type. */ 1383*5796c8dcSSimon Schubert struct type *pointer_type 1384*5796c8dcSSimon Schubert = lookup_pointer_type (value_type (last_examine_value)); 1385*5796c8dcSSimon Schubert set_internalvar (lookup_internalvar ("_"), 1386*5796c8dcSSimon Schubert value_from_pointer (pointer_type, 1387*5796c8dcSSimon Schubert last_examine_address)); 1388*5796c8dcSSimon Schubert 1389*5796c8dcSSimon Schubert /* Make contents of last address examined available to the user 1390*5796c8dcSSimon Schubert as $__. If the last value has not been fetched from memory 1391*5796c8dcSSimon Schubert then don't fetch it now; instead mark it by voiding the $__ 1392*5796c8dcSSimon Schubert variable. */ 1393*5796c8dcSSimon Schubert if (value_lazy (last_examine_value)) 1394*5796c8dcSSimon Schubert clear_internalvar (lookup_internalvar ("__")); 1395*5796c8dcSSimon Schubert else 1396*5796c8dcSSimon Schubert set_internalvar (lookup_internalvar ("__"), last_examine_value); 1397*5796c8dcSSimon Schubert } 1398*5796c8dcSSimon Schubert } 1399*5796c8dcSSimon Schubert 1400*5796c8dcSSimon Schubert 1401*5796c8dcSSimon Schubert /* Add an expression to the auto-display chain. 1402*5796c8dcSSimon Schubert Specify the expression. */ 1403*5796c8dcSSimon Schubert 1404*5796c8dcSSimon Schubert static void 1405*5796c8dcSSimon Schubert display_command (char *exp, int from_tty) 1406*5796c8dcSSimon Schubert { 1407*5796c8dcSSimon Schubert struct format_data fmt; 1408*5796c8dcSSimon Schubert struct expression *expr; 1409*5796c8dcSSimon Schubert struct display *new; 1410*5796c8dcSSimon Schubert int display_it = 1; 1411*5796c8dcSSimon Schubert 1412*5796c8dcSSimon Schubert #if defined(TUI) 1413*5796c8dcSSimon Schubert /* NOTE: cagney/2003-02-13 The `tui_active' was previously 1414*5796c8dcSSimon Schubert `tui_version'. */ 1415*5796c8dcSSimon Schubert if (tui_active && exp != NULL && *exp == '$') 1416*5796c8dcSSimon Schubert display_it = (tui_set_layout_for_display_command (exp) == TUI_FAILURE); 1417*5796c8dcSSimon Schubert #endif 1418*5796c8dcSSimon Schubert 1419*5796c8dcSSimon Schubert if (display_it) 1420*5796c8dcSSimon Schubert { 1421*5796c8dcSSimon Schubert if (exp == 0) 1422*5796c8dcSSimon Schubert { 1423*5796c8dcSSimon Schubert do_displays (); 1424*5796c8dcSSimon Schubert return; 1425*5796c8dcSSimon Schubert } 1426*5796c8dcSSimon Schubert 1427*5796c8dcSSimon Schubert if (*exp == '/') 1428*5796c8dcSSimon Schubert { 1429*5796c8dcSSimon Schubert exp++; 1430*5796c8dcSSimon Schubert fmt = decode_format (&exp, 0, 0); 1431*5796c8dcSSimon Schubert if (fmt.size && fmt.format == 0) 1432*5796c8dcSSimon Schubert fmt.format = 'x'; 1433*5796c8dcSSimon Schubert if (fmt.format == 'i' || fmt.format == 's') 1434*5796c8dcSSimon Schubert fmt.size = 'b'; 1435*5796c8dcSSimon Schubert } 1436*5796c8dcSSimon Schubert else 1437*5796c8dcSSimon Schubert { 1438*5796c8dcSSimon Schubert fmt.format = 0; 1439*5796c8dcSSimon Schubert fmt.size = 0; 1440*5796c8dcSSimon Schubert fmt.count = 0; 1441*5796c8dcSSimon Schubert fmt.raw = 0; 1442*5796c8dcSSimon Schubert } 1443*5796c8dcSSimon Schubert 1444*5796c8dcSSimon Schubert innermost_block = NULL; 1445*5796c8dcSSimon Schubert expr = parse_expression (exp); 1446*5796c8dcSSimon Schubert 1447*5796c8dcSSimon Schubert new = (struct display *) xmalloc (sizeof (struct display)); 1448*5796c8dcSSimon Schubert 1449*5796c8dcSSimon Schubert new->exp_string = xstrdup (exp); 1450*5796c8dcSSimon Schubert new->exp = expr; 1451*5796c8dcSSimon Schubert new->block = innermost_block; 1452*5796c8dcSSimon Schubert new->next = display_chain; 1453*5796c8dcSSimon Schubert new->number = ++display_number; 1454*5796c8dcSSimon Schubert new->format = fmt; 1455*5796c8dcSSimon Schubert new->enabled_p = 1; 1456*5796c8dcSSimon Schubert display_chain = new; 1457*5796c8dcSSimon Schubert 1458*5796c8dcSSimon Schubert if (from_tty && target_has_execution) 1459*5796c8dcSSimon Schubert do_one_display (new); 1460*5796c8dcSSimon Schubert 1461*5796c8dcSSimon Schubert dont_repeat (); 1462*5796c8dcSSimon Schubert } 1463*5796c8dcSSimon Schubert } 1464*5796c8dcSSimon Schubert 1465*5796c8dcSSimon Schubert static void 1466*5796c8dcSSimon Schubert free_display (struct display *d) 1467*5796c8dcSSimon Schubert { 1468*5796c8dcSSimon Schubert xfree (d->exp_string); 1469*5796c8dcSSimon Schubert xfree (d->exp); 1470*5796c8dcSSimon Schubert xfree (d); 1471*5796c8dcSSimon Schubert } 1472*5796c8dcSSimon Schubert 1473*5796c8dcSSimon Schubert /* Clear out the display_chain. Done when new symtabs are loaded, 1474*5796c8dcSSimon Schubert since this invalidates the types stored in many expressions. */ 1475*5796c8dcSSimon Schubert 1476*5796c8dcSSimon Schubert void 1477*5796c8dcSSimon Schubert clear_displays (void) 1478*5796c8dcSSimon Schubert { 1479*5796c8dcSSimon Schubert struct display *d; 1480*5796c8dcSSimon Schubert 1481*5796c8dcSSimon Schubert while ((d = display_chain) != NULL) 1482*5796c8dcSSimon Schubert { 1483*5796c8dcSSimon Schubert display_chain = d->next; 1484*5796c8dcSSimon Schubert free_display (d); 1485*5796c8dcSSimon Schubert } 1486*5796c8dcSSimon Schubert } 1487*5796c8dcSSimon Schubert 1488*5796c8dcSSimon Schubert /* Delete the auto-display number NUM. */ 1489*5796c8dcSSimon Schubert 1490*5796c8dcSSimon Schubert static void 1491*5796c8dcSSimon Schubert delete_display (int num) 1492*5796c8dcSSimon Schubert { 1493*5796c8dcSSimon Schubert struct display *d1, *d; 1494*5796c8dcSSimon Schubert 1495*5796c8dcSSimon Schubert if (!display_chain) 1496*5796c8dcSSimon Schubert error (_("No display number %d."), num); 1497*5796c8dcSSimon Schubert 1498*5796c8dcSSimon Schubert if (display_chain->number == num) 1499*5796c8dcSSimon Schubert { 1500*5796c8dcSSimon Schubert d1 = display_chain; 1501*5796c8dcSSimon Schubert display_chain = d1->next; 1502*5796c8dcSSimon Schubert free_display (d1); 1503*5796c8dcSSimon Schubert } 1504*5796c8dcSSimon Schubert else 1505*5796c8dcSSimon Schubert for (d = display_chain;; d = d->next) 1506*5796c8dcSSimon Schubert { 1507*5796c8dcSSimon Schubert if (d->next == 0) 1508*5796c8dcSSimon Schubert error (_("No display number %d."), num); 1509*5796c8dcSSimon Schubert if (d->next->number == num) 1510*5796c8dcSSimon Schubert { 1511*5796c8dcSSimon Schubert d1 = d->next; 1512*5796c8dcSSimon Schubert d->next = d1->next; 1513*5796c8dcSSimon Schubert free_display (d1); 1514*5796c8dcSSimon Schubert break; 1515*5796c8dcSSimon Schubert } 1516*5796c8dcSSimon Schubert } 1517*5796c8dcSSimon Schubert } 1518*5796c8dcSSimon Schubert 1519*5796c8dcSSimon Schubert /* Delete some values from the auto-display chain. 1520*5796c8dcSSimon Schubert Specify the element numbers. */ 1521*5796c8dcSSimon Schubert 1522*5796c8dcSSimon Schubert static void 1523*5796c8dcSSimon Schubert undisplay_command (char *args, int from_tty) 1524*5796c8dcSSimon Schubert { 1525*5796c8dcSSimon Schubert char *p = args; 1526*5796c8dcSSimon Schubert char *p1; 1527*5796c8dcSSimon Schubert int num; 1528*5796c8dcSSimon Schubert 1529*5796c8dcSSimon Schubert if (args == 0) 1530*5796c8dcSSimon Schubert { 1531*5796c8dcSSimon Schubert if (query (_("Delete all auto-display expressions? "))) 1532*5796c8dcSSimon Schubert clear_displays (); 1533*5796c8dcSSimon Schubert dont_repeat (); 1534*5796c8dcSSimon Schubert return; 1535*5796c8dcSSimon Schubert } 1536*5796c8dcSSimon Schubert 1537*5796c8dcSSimon Schubert while (*p) 1538*5796c8dcSSimon Schubert { 1539*5796c8dcSSimon Schubert p1 = p; 1540*5796c8dcSSimon Schubert while (*p1 >= '0' && *p1 <= '9') 1541*5796c8dcSSimon Schubert p1++; 1542*5796c8dcSSimon Schubert if (*p1 && *p1 != ' ' && *p1 != '\t') 1543*5796c8dcSSimon Schubert error (_("Arguments must be display numbers.")); 1544*5796c8dcSSimon Schubert 1545*5796c8dcSSimon Schubert num = atoi (p); 1546*5796c8dcSSimon Schubert 1547*5796c8dcSSimon Schubert delete_display (num); 1548*5796c8dcSSimon Schubert 1549*5796c8dcSSimon Schubert p = p1; 1550*5796c8dcSSimon Schubert while (*p == ' ' || *p == '\t') 1551*5796c8dcSSimon Schubert p++; 1552*5796c8dcSSimon Schubert } 1553*5796c8dcSSimon Schubert dont_repeat (); 1554*5796c8dcSSimon Schubert } 1555*5796c8dcSSimon Schubert 1556*5796c8dcSSimon Schubert /* Display a single auto-display. 1557*5796c8dcSSimon Schubert Do nothing if the display cannot be printed in the current context, 1558*5796c8dcSSimon Schubert or if the display is disabled. */ 1559*5796c8dcSSimon Schubert 1560*5796c8dcSSimon Schubert static void 1561*5796c8dcSSimon Schubert do_one_display (struct display *d) 1562*5796c8dcSSimon Schubert { 1563*5796c8dcSSimon Schubert int within_current_scope; 1564*5796c8dcSSimon Schubert 1565*5796c8dcSSimon Schubert if (d->enabled_p == 0) 1566*5796c8dcSSimon Schubert return; 1567*5796c8dcSSimon Schubert 1568*5796c8dcSSimon Schubert if (d->exp == NULL) 1569*5796c8dcSSimon Schubert { 1570*5796c8dcSSimon Schubert volatile struct gdb_exception ex; 1571*5796c8dcSSimon Schubert TRY_CATCH (ex, RETURN_MASK_ALL) 1572*5796c8dcSSimon Schubert { 1573*5796c8dcSSimon Schubert innermost_block = NULL; 1574*5796c8dcSSimon Schubert d->exp = parse_expression (d->exp_string); 1575*5796c8dcSSimon Schubert d->block = innermost_block; 1576*5796c8dcSSimon Schubert } 1577*5796c8dcSSimon Schubert if (ex.reason < 0) 1578*5796c8dcSSimon Schubert { 1579*5796c8dcSSimon Schubert /* Can't re-parse the expression. Disable this display item. */ 1580*5796c8dcSSimon Schubert d->enabled_p = 0; 1581*5796c8dcSSimon Schubert warning (_("Unable to display \"%s\": %s"), 1582*5796c8dcSSimon Schubert d->exp_string, ex.message); 1583*5796c8dcSSimon Schubert return; 1584*5796c8dcSSimon Schubert } 1585*5796c8dcSSimon Schubert } 1586*5796c8dcSSimon Schubert 1587*5796c8dcSSimon Schubert if (d->block) 1588*5796c8dcSSimon Schubert within_current_scope = contained_in (get_selected_block (0), d->block); 1589*5796c8dcSSimon Schubert else 1590*5796c8dcSSimon Schubert within_current_scope = 1; 1591*5796c8dcSSimon Schubert if (!within_current_scope) 1592*5796c8dcSSimon Schubert return; 1593*5796c8dcSSimon Schubert 1594*5796c8dcSSimon Schubert current_display_number = d->number; 1595*5796c8dcSSimon Schubert 1596*5796c8dcSSimon Schubert annotate_display_begin (); 1597*5796c8dcSSimon Schubert printf_filtered ("%d", d->number); 1598*5796c8dcSSimon Schubert annotate_display_number_end (); 1599*5796c8dcSSimon Schubert printf_filtered (": "); 1600*5796c8dcSSimon Schubert if (d->format.size) 1601*5796c8dcSSimon Schubert { 1602*5796c8dcSSimon Schubert CORE_ADDR addr; 1603*5796c8dcSSimon Schubert struct value *val; 1604*5796c8dcSSimon Schubert 1605*5796c8dcSSimon Schubert annotate_display_format (); 1606*5796c8dcSSimon Schubert 1607*5796c8dcSSimon Schubert printf_filtered ("x/"); 1608*5796c8dcSSimon Schubert if (d->format.count != 1) 1609*5796c8dcSSimon Schubert printf_filtered ("%d", d->format.count); 1610*5796c8dcSSimon Schubert printf_filtered ("%c", d->format.format); 1611*5796c8dcSSimon Schubert if (d->format.format != 'i' && d->format.format != 's') 1612*5796c8dcSSimon Schubert printf_filtered ("%c", d->format.size); 1613*5796c8dcSSimon Schubert printf_filtered (" "); 1614*5796c8dcSSimon Schubert 1615*5796c8dcSSimon Schubert annotate_display_expression (); 1616*5796c8dcSSimon Schubert 1617*5796c8dcSSimon Schubert puts_filtered (d->exp_string); 1618*5796c8dcSSimon Schubert annotate_display_expression_end (); 1619*5796c8dcSSimon Schubert 1620*5796c8dcSSimon Schubert if (d->format.count != 1 || d->format.format == 'i') 1621*5796c8dcSSimon Schubert printf_filtered ("\n"); 1622*5796c8dcSSimon Schubert else 1623*5796c8dcSSimon Schubert printf_filtered (" "); 1624*5796c8dcSSimon Schubert 1625*5796c8dcSSimon Schubert val = evaluate_expression (d->exp); 1626*5796c8dcSSimon Schubert addr = value_as_address (val); 1627*5796c8dcSSimon Schubert if (d->format.format == 'i') 1628*5796c8dcSSimon Schubert addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr); 1629*5796c8dcSSimon Schubert 1630*5796c8dcSSimon Schubert annotate_display_value (); 1631*5796c8dcSSimon Schubert 1632*5796c8dcSSimon Schubert do_examine (d->format, d->exp->gdbarch, addr); 1633*5796c8dcSSimon Schubert } 1634*5796c8dcSSimon Schubert else 1635*5796c8dcSSimon Schubert { 1636*5796c8dcSSimon Schubert struct value_print_options opts; 1637*5796c8dcSSimon Schubert 1638*5796c8dcSSimon Schubert annotate_display_format (); 1639*5796c8dcSSimon Schubert 1640*5796c8dcSSimon Schubert if (d->format.format) 1641*5796c8dcSSimon Schubert printf_filtered ("/%c ", d->format.format); 1642*5796c8dcSSimon Schubert 1643*5796c8dcSSimon Schubert annotate_display_expression (); 1644*5796c8dcSSimon Schubert 1645*5796c8dcSSimon Schubert puts_filtered (d->exp_string); 1646*5796c8dcSSimon Schubert annotate_display_expression_end (); 1647*5796c8dcSSimon Schubert 1648*5796c8dcSSimon Schubert printf_filtered (" = "); 1649*5796c8dcSSimon Schubert 1650*5796c8dcSSimon Schubert annotate_display_expression (); 1651*5796c8dcSSimon Schubert 1652*5796c8dcSSimon Schubert get_formatted_print_options (&opts, d->format.format); 1653*5796c8dcSSimon Schubert opts.raw = d->format.raw; 1654*5796c8dcSSimon Schubert print_formatted (evaluate_expression (d->exp), 1655*5796c8dcSSimon Schubert d->format.size, &opts, gdb_stdout); 1656*5796c8dcSSimon Schubert printf_filtered ("\n"); 1657*5796c8dcSSimon Schubert } 1658*5796c8dcSSimon Schubert 1659*5796c8dcSSimon Schubert annotate_display_end (); 1660*5796c8dcSSimon Schubert 1661*5796c8dcSSimon Schubert gdb_flush (gdb_stdout); 1662*5796c8dcSSimon Schubert current_display_number = -1; 1663*5796c8dcSSimon Schubert } 1664*5796c8dcSSimon Schubert 1665*5796c8dcSSimon Schubert /* Display all of the values on the auto-display chain which can be 1666*5796c8dcSSimon Schubert evaluated in the current scope. */ 1667*5796c8dcSSimon Schubert 1668*5796c8dcSSimon Schubert void 1669*5796c8dcSSimon Schubert do_displays (void) 1670*5796c8dcSSimon Schubert { 1671*5796c8dcSSimon Schubert struct display *d; 1672*5796c8dcSSimon Schubert 1673*5796c8dcSSimon Schubert for (d = display_chain; d; d = d->next) 1674*5796c8dcSSimon Schubert do_one_display (d); 1675*5796c8dcSSimon Schubert } 1676*5796c8dcSSimon Schubert 1677*5796c8dcSSimon Schubert /* Delete the auto-display which we were in the process of displaying. 1678*5796c8dcSSimon Schubert This is done when there is an error or a signal. */ 1679*5796c8dcSSimon Schubert 1680*5796c8dcSSimon Schubert void 1681*5796c8dcSSimon Schubert disable_display (int num) 1682*5796c8dcSSimon Schubert { 1683*5796c8dcSSimon Schubert struct display *d; 1684*5796c8dcSSimon Schubert 1685*5796c8dcSSimon Schubert for (d = display_chain; d; d = d->next) 1686*5796c8dcSSimon Schubert if (d->number == num) 1687*5796c8dcSSimon Schubert { 1688*5796c8dcSSimon Schubert d->enabled_p = 0; 1689*5796c8dcSSimon Schubert return; 1690*5796c8dcSSimon Schubert } 1691*5796c8dcSSimon Schubert printf_unfiltered (_("No display number %d.\n"), num); 1692*5796c8dcSSimon Schubert } 1693*5796c8dcSSimon Schubert 1694*5796c8dcSSimon Schubert void 1695*5796c8dcSSimon Schubert disable_current_display (void) 1696*5796c8dcSSimon Schubert { 1697*5796c8dcSSimon Schubert if (current_display_number >= 0) 1698*5796c8dcSSimon Schubert { 1699*5796c8dcSSimon Schubert disable_display (current_display_number); 1700*5796c8dcSSimon Schubert fprintf_unfiltered (gdb_stderr, _("\ 1701*5796c8dcSSimon Schubert Disabling display %d to avoid infinite recursion.\n"), 1702*5796c8dcSSimon Schubert current_display_number); 1703*5796c8dcSSimon Schubert } 1704*5796c8dcSSimon Schubert current_display_number = -1; 1705*5796c8dcSSimon Schubert } 1706*5796c8dcSSimon Schubert 1707*5796c8dcSSimon Schubert static void 1708*5796c8dcSSimon Schubert display_info (char *ignore, int from_tty) 1709*5796c8dcSSimon Schubert { 1710*5796c8dcSSimon Schubert struct display *d; 1711*5796c8dcSSimon Schubert 1712*5796c8dcSSimon Schubert if (!display_chain) 1713*5796c8dcSSimon Schubert printf_unfiltered (_("There are no auto-display expressions now.\n")); 1714*5796c8dcSSimon Schubert else 1715*5796c8dcSSimon Schubert printf_filtered (_("Auto-display expressions now in effect:\n\ 1716*5796c8dcSSimon Schubert Num Enb Expression\n")); 1717*5796c8dcSSimon Schubert 1718*5796c8dcSSimon Schubert for (d = display_chain; d; d = d->next) 1719*5796c8dcSSimon Schubert { 1720*5796c8dcSSimon Schubert printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]); 1721*5796c8dcSSimon Schubert if (d->format.size) 1722*5796c8dcSSimon Schubert printf_filtered ("/%d%c%c ", d->format.count, d->format.size, 1723*5796c8dcSSimon Schubert d->format.format); 1724*5796c8dcSSimon Schubert else if (d->format.format) 1725*5796c8dcSSimon Schubert printf_filtered ("/%c ", d->format.format); 1726*5796c8dcSSimon Schubert puts_filtered (d->exp_string); 1727*5796c8dcSSimon Schubert if (d->block && !contained_in (get_selected_block (0), d->block)) 1728*5796c8dcSSimon Schubert printf_filtered (_(" (cannot be evaluated in the current context)")); 1729*5796c8dcSSimon Schubert printf_filtered ("\n"); 1730*5796c8dcSSimon Schubert gdb_flush (gdb_stdout); 1731*5796c8dcSSimon Schubert } 1732*5796c8dcSSimon Schubert } 1733*5796c8dcSSimon Schubert 1734*5796c8dcSSimon Schubert static void 1735*5796c8dcSSimon Schubert enable_display (char *args, int from_tty) 1736*5796c8dcSSimon Schubert { 1737*5796c8dcSSimon Schubert char *p = args; 1738*5796c8dcSSimon Schubert char *p1; 1739*5796c8dcSSimon Schubert int num; 1740*5796c8dcSSimon Schubert struct display *d; 1741*5796c8dcSSimon Schubert 1742*5796c8dcSSimon Schubert if (p == 0) 1743*5796c8dcSSimon Schubert { 1744*5796c8dcSSimon Schubert for (d = display_chain; d; d = d->next) 1745*5796c8dcSSimon Schubert d->enabled_p = 1; 1746*5796c8dcSSimon Schubert } 1747*5796c8dcSSimon Schubert else 1748*5796c8dcSSimon Schubert while (*p) 1749*5796c8dcSSimon Schubert { 1750*5796c8dcSSimon Schubert p1 = p; 1751*5796c8dcSSimon Schubert while (*p1 >= '0' && *p1 <= '9') 1752*5796c8dcSSimon Schubert p1++; 1753*5796c8dcSSimon Schubert if (*p1 && *p1 != ' ' && *p1 != '\t') 1754*5796c8dcSSimon Schubert error (_("Arguments must be display numbers.")); 1755*5796c8dcSSimon Schubert 1756*5796c8dcSSimon Schubert num = atoi (p); 1757*5796c8dcSSimon Schubert 1758*5796c8dcSSimon Schubert for (d = display_chain; d; d = d->next) 1759*5796c8dcSSimon Schubert if (d->number == num) 1760*5796c8dcSSimon Schubert { 1761*5796c8dcSSimon Schubert d->enabled_p = 1; 1762*5796c8dcSSimon Schubert goto win; 1763*5796c8dcSSimon Schubert } 1764*5796c8dcSSimon Schubert printf_unfiltered (_("No display number %d.\n"), num); 1765*5796c8dcSSimon Schubert win: 1766*5796c8dcSSimon Schubert p = p1; 1767*5796c8dcSSimon Schubert while (*p == ' ' || *p == '\t') 1768*5796c8dcSSimon Schubert p++; 1769*5796c8dcSSimon Schubert } 1770*5796c8dcSSimon Schubert } 1771*5796c8dcSSimon Schubert 1772*5796c8dcSSimon Schubert static void 1773*5796c8dcSSimon Schubert disable_display_command (char *args, int from_tty) 1774*5796c8dcSSimon Schubert { 1775*5796c8dcSSimon Schubert char *p = args; 1776*5796c8dcSSimon Schubert char *p1; 1777*5796c8dcSSimon Schubert struct display *d; 1778*5796c8dcSSimon Schubert 1779*5796c8dcSSimon Schubert if (p == 0) 1780*5796c8dcSSimon Schubert { 1781*5796c8dcSSimon Schubert for (d = display_chain; d; d = d->next) 1782*5796c8dcSSimon Schubert d->enabled_p = 0; 1783*5796c8dcSSimon Schubert } 1784*5796c8dcSSimon Schubert else 1785*5796c8dcSSimon Schubert while (*p) 1786*5796c8dcSSimon Schubert { 1787*5796c8dcSSimon Schubert p1 = p; 1788*5796c8dcSSimon Schubert while (*p1 >= '0' && *p1 <= '9') 1789*5796c8dcSSimon Schubert p1++; 1790*5796c8dcSSimon Schubert if (*p1 && *p1 != ' ' && *p1 != '\t') 1791*5796c8dcSSimon Schubert error (_("Arguments must be display numbers.")); 1792*5796c8dcSSimon Schubert 1793*5796c8dcSSimon Schubert disable_display (atoi (p)); 1794*5796c8dcSSimon Schubert 1795*5796c8dcSSimon Schubert p = p1; 1796*5796c8dcSSimon Schubert while (*p == ' ' || *p == '\t') 1797*5796c8dcSSimon Schubert p++; 1798*5796c8dcSSimon Schubert } 1799*5796c8dcSSimon Schubert } 1800*5796c8dcSSimon Schubert 1801*5796c8dcSSimon Schubert /* Return 1 if D uses SOLIB (and will become dangling when SOLIB 1802*5796c8dcSSimon Schubert is unloaded), otherwise return 0. */ 1803*5796c8dcSSimon Schubert 1804*5796c8dcSSimon Schubert static int 1805*5796c8dcSSimon Schubert display_uses_solib_p (const struct display *d, 1806*5796c8dcSSimon Schubert const struct so_list *solib) 1807*5796c8dcSSimon Schubert { 1808*5796c8dcSSimon Schubert int endpos; 1809*5796c8dcSSimon Schubert struct expression *const exp = d->exp; 1810*5796c8dcSSimon Schubert const union exp_element *const elts = exp->elts; 1811*5796c8dcSSimon Schubert 1812*5796c8dcSSimon Schubert if (d->block != NULL 1813*5796c8dcSSimon Schubert && solib_contains_address_p (solib, d->block->startaddr)) 1814*5796c8dcSSimon Schubert return 1; 1815*5796c8dcSSimon Schubert 1816*5796c8dcSSimon Schubert for (endpos = exp->nelts; endpos > 0; ) 1817*5796c8dcSSimon Schubert { 1818*5796c8dcSSimon Schubert int i, args, oplen = 0; 1819*5796c8dcSSimon Schubert 1820*5796c8dcSSimon Schubert exp->language_defn->la_exp_desc->operator_length (exp, endpos, 1821*5796c8dcSSimon Schubert &oplen, &args); 1822*5796c8dcSSimon Schubert gdb_assert (oplen > 0); 1823*5796c8dcSSimon Schubert 1824*5796c8dcSSimon Schubert i = endpos - oplen; 1825*5796c8dcSSimon Schubert if (elts[i].opcode == OP_VAR_VALUE) 1826*5796c8dcSSimon Schubert { 1827*5796c8dcSSimon Schubert const struct block *const block = elts[i + 1].block; 1828*5796c8dcSSimon Schubert const struct symbol *const symbol = elts[i + 2].symbol; 1829*5796c8dcSSimon Schubert const struct obj_section *const section = 1830*5796c8dcSSimon Schubert SYMBOL_OBJ_SECTION (symbol); 1831*5796c8dcSSimon Schubert 1832*5796c8dcSSimon Schubert if (block != NULL 1833*5796c8dcSSimon Schubert && solib_contains_address_p (solib, block->startaddr)) 1834*5796c8dcSSimon Schubert return 1; 1835*5796c8dcSSimon Schubert 1836*5796c8dcSSimon Schubert if (section && section->objfile == solib->objfile) 1837*5796c8dcSSimon Schubert return 1; 1838*5796c8dcSSimon Schubert } 1839*5796c8dcSSimon Schubert endpos -= oplen; 1840*5796c8dcSSimon Schubert } 1841*5796c8dcSSimon Schubert 1842*5796c8dcSSimon Schubert return 0; 1843*5796c8dcSSimon Schubert } 1844*5796c8dcSSimon Schubert 1845*5796c8dcSSimon Schubert /* display_chain items point to blocks and expressions. Some expressions in 1846*5796c8dcSSimon Schubert turn may point to symbols. 1847*5796c8dcSSimon Schubert Both symbols and blocks are obstack_alloc'd on objfile_stack, and are 1848*5796c8dcSSimon Schubert obstack_free'd when a shared library is unloaded. 1849*5796c8dcSSimon Schubert Clear pointers that are about to become dangling. 1850*5796c8dcSSimon Schubert Both .exp and .block fields will be restored next time we need to display 1851*5796c8dcSSimon Schubert an item by re-parsing .exp_string field in the new execution context. */ 1852*5796c8dcSSimon Schubert 1853*5796c8dcSSimon Schubert static void 1854*5796c8dcSSimon Schubert clear_dangling_display_expressions (struct so_list *solib) 1855*5796c8dcSSimon Schubert { 1856*5796c8dcSSimon Schubert struct display *d; 1857*5796c8dcSSimon Schubert struct objfile *objfile = NULL; 1858*5796c8dcSSimon Schubert 1859*5796c8dcSSimon Schubert for (d = display_chain; d; d = d->next) 1860*5796c8dcSSimon Schubert { 1861*5796c8dcSSimon Schubert if (d->exp && display_uses_solib_p (d, solib)) 1862*5796c8dcSSimon Schubert { 1863*5796c8dcSSimon Schubert xfree (d->exp); 1864*5796c8dcSSimon Schubert d->exp = NULL; 1865*5796c8dcSSimon Schubert d->block = NULL; 1866*5796c8dcSSimon Schubert } 1867*5796c8dcSSimon Schubert } 1868*5796c8dcSSimon Schubert } 1869*5796c8dcSSimon Schubert 1870*5796c8dcSSimon Schubert 1871*5796c8dcSSimon Schubert /* Print the value in stack frame FRAME of a variable specified by a 1872*5796c8dcSSimon Schubert struct symbol. NAME is the name to print; if NULL then VAR's print 1873*5796c8dcSSimon Schubert name will be used. STREAM is the ui_file on which to print the 1874*5796c8dcSSimon Schubert value. INDENT specifies the number of indent levels to print 1875*5796c8dcSSimon Schubert before printing the variable name. */ 1876*5796c8dcSSimon Schubert 1877*5796c8dcSSimon Schubert void 1878*5796c8dcSSimon Schubert print_variable_and_value (const char *name, struct symbol *var, 1879*5796c8dcSSimon Schubert struct frame_info *frame, 1880*5796c8dcSSimon Schubert struct ui_file *stream, int indent) 1881*5796c8dcSSimon Schubert { 1882*5796c8dcSSimon Schubert struct value *val; 1883*5796c8dcSSimon Schubert struct value_print_options opts; 1884*5796c8dcSSimon Schubert 1885*5796c8dcSSimon Schubert if (!name) 1886*5796c8dcSSimon Schubert name = SYMBOL_PRINT_NAME (var); 1887*5796c8dcSSimon Schubert 1888*5796c8dcSSimon Schubert fprintf_filtered (stream, "%s%s = ", n_spaces (2 * indent), name); 1889*5796c8dcSSimon Schubert 1890*5796c8dcSSimon Schubert val = read_var_value (var, frame); 1891*5796c8dcSSimon Schubert get_user_print_options (&opts); 1892*5796c8dcSSimon Schubert common_val_print (val, stream, indent, &opts, current_language); 1893*5796c8dcSSimon Schubert fprintf_filtered (stream, "\n"); 1894*5796c8dcSSimon Schubert } 1895*5796c8dcSSimon Schubert 1896*5796c8dcSSimon Schubert static void 1897*5796c8dcSSimon Schubert printf_command (char *arg, int from_tty) 1898*5796c8dcSSimon Schubert { 1899*5796c8dcSSimon Schubert char *f = NULL; 1900*5796c8dcSSimon Schubert char *s = arg; 1901*5796c8dcSSimon Schubert char *string = NULL; 1902*5796c8dcSSimon Schubert struct value **val_args; 1903*5796c8dcSSimon Schubert char *substrings; 1904*5796c8dcSSimon Schubert char *current_substring; 1905*5796c8dcSSimon Schubert int nargs = 0; 1906*5796c8dcSSimon Schubert int allocated_args = 20; 1907*5796c8dcSSimon Schubert struct cleanup *old_cleanups; 1908*5796c8dcSSimon Schubert 1909*5796c8dcSSimon Schubert val_args = xmalloc (allocated_args * sizeof (struct value *)); 1910*5796c8dcSSimon Schubert old_cleanups = make_cleanup (free_current_contents, &val_args); 1911*5796c8dcSSimon Schubert 1912*5796c8dcSSimon Schubert if (s == 0) 1913*5796c8dcSSimon Schubert error_no_arg (_("format-control string and values to print")); 1914*5796c8dcSSimon Schubert 1915*5796c8dcSSimon Schubert /* Skip white space before format string */ 1916*5796c8dcSSimon Schubert while (*s == ' ' || *s == '\t') 1917*5796c8dcSSimon Schubert s++; 1918*5796c8dcSSimon Schubert 1919*5796c8dcSSimon Schubert /* A format string should follow, enveloped in double quotes. */ 1920*5796c8dcSSimon Schubert if (*s++ != '"') 1921*5796c8dcSSimon Schubert error (_("Bad format string, missing '\"'.")); 1922*5796c8dcSSimon Schubert 1923*5796c8dcSSimon Schubert /* Parse the format-control string and copy it into the string STRING, 1924*5796c8dcSSimon Schubert processing some kinds of escape sequence. */ 1925*5796c8dcSSimon Schubert 1926*5796c8dcSSimon Schubert f = string = (char *) alloca (strlen (s) + 1); 1927*5796c8dcSSimon Schubert 1928*5796c8dcSSimon Schubert while (*s != '"') 1929*5796c8dcSSimon Schubert { 1930*5796c8dcSSimon Schubert int c = *s++; 1931*5796c8dcSSimon Schubert switch (c) 1932*5796c8dcSSimon Schubert { 1933*5796c8dcSSimon Schubert case '\0': 1934*5796c8dcSSimon Schubert error (_("Bad format string, non-terminated '\"'.")); 1935*5796c8dcSSimon Schubert 1936*5796c8dcSSimon Schubert case '\\': 1937*5796c8dcSSimon Schubert switch (c = *s++) 1938*5796c8dcSSimon Schubert { 1939*5796c8dcSSimon Schubert case '\\': 1940*5796c8dcSSimon Schubert *f++ = '\\'; 1941*5796c8dcSSimon Schubert break; 1942*5796c8dcSSimon Schubert case 'a': 1943*5796c8dcSSimon Schubert *f++ = '\a'; 1944*5796c8dcSSimon Schubert break; 1945*5796c8dcSSimon Schubert case 'b': 1946*5796c8dcSSimon Schubert *f++ = '\b'; 1947*5796c8dcSSimon Schubert break; 1948*5796c8dcSSimon Schubert case 'f': 1949*5796c8dcSSimon Schubert *f++ = '\f'; 1950*5796c8dcSSimon Schubert break; 1951*5796c8dcSSimon Schubert case 'n': 1952*5796c8dcSSimon Schubert *f++ = '\n'; 1953*5796c8dcSSimon Schubert break; 1954*5796c8dcSSimon Schubert case 'r': 1955*5796c8dcSSimon Schubert *f++ = '\r'; 1956*5796c8dcSSimon Schubert break; 1957*5796c8dcSSimon Schubert case 't': 1958*5796c8dcSSimon Schubert *f++ = '\t'; 1959*5796c8dcSSimon Schubert break; 1960*5796c8dcSSimon Schubert case 'v': 1961*5796c8dcSSimon Schubert *f++ = '\v'; 1962*5796c8dcSSimon Schubert break; 1963*5796c8dcSSimon Schubert case '"': 1964*5796c8dcSSimon Schubert *f++ = '"'; 1965*5796c8dcSSimon Schubert break; 1966*5796c8dcSSimon Schubert default: 1967*5796c8dcSSimon Schubert /* ??? TODO: handle other escape sequences */ 1968*5796c8dcSSimon Schubert error (_("Unrecognized escape character \\%c in format string."), 1969*5796c8dcSSimon Schubert c); 1970*5796c8dcSSimon Schubert } 1971*5796c8dcSSimon Schubert break; 1972*5796c8dcSSimon Schubert 1973*5796c8dcSSimon Schubert default: 1974*5796c8dcSSimon Schubert *f++ = c; 1975*5796c8dcSSimon Schubert } 1976*5796c8dcSSimon Schubert } 1977*5796c8dcSSimon Schubert 1978*5796c8dcSSimon Schubert /* Skip over " and following space and comma. */ 1979*5796c8dcSSimon Schubert s++; 1980*5796c8dcSSimon Schubert *f++ = '\0'; 1981*5796c8dcSSimon Schubert while (*s == ' ' || *s == '\t') 1982*5796c8dcSSimon Schubert s++; 1983*5796c8dcSSimon Schubert 1984*5796c8dcSSimon Schubert if (*s != ',' && *s != 0) 1985*5796c8dcSSimon Schubert error (_("Invalid argument syntax")); 1986*5796c8dcSSimon Schubert 1987*5796c8dcSSimon Schubert if (*s == ',') 1988*5796c8dcSSimon Schubert s++; 1989*5796c8dcSSimon Schubert while (*s == ' ' || *s == '\t') 1990*5796c8dcSSimon Schubert s++; 1991*5796c8dcSSimon Schubert 1992*5796c8dcSSimon Schubert /* Need extra space for the '\0's. Doubling the size is sufficient. */ 1993*5796c8dcSSimon Schubert substrings = alloca (strlen (string) * 2); 1994*5796c8dcSSimon Schubert current_substring = substrings; 1995*5796c8dcSSimon Schubert 1996*5796c8dcSSimon Schubert { 1997*5796c8dcSSimon Schubert /* Now scan the string for %-specs and see what kinds of args they want. 1998*5796c8dcSSimon Schubert argclass[I] classifies the %-specs so we can give printf_filtered 1999*5796c8dcSSimon Schubert something of the right size. */ 2000*5796c8dcSSimon Schubert 2001*5796c8dcSSimon Schubert enum argclass 2002*5796c8dcSSimon Schubert { 2003*5796c8dcSSimon Schubert int_arg, long_arg, long_long_arg, ptr_arg, 2004*5796c8dcSSimon Schubert string_arg, wide_string_arg, wide_char_arg, 2005*5796c8dcSSimon Schubert double_arg, long_double_arg, decfloat_arg 2006*5796c8dcSSimon Schubert }; 2007*5796c8dcSSimon Schubert enum argclass *argclass; 2008*5796c8dcSSimon Schubert enum argclass this_argclass; 2009*5796c8dcSSimon Schubert char *last_arg; 2010*5796c8dcSSimon Schubert int nargs_wanted; 2011*5796c8dcSSimon Schubert int i; 2012*5796c8dcSSimon Schubert 2013*5796c8dcSSimon Schubert argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass); 2014*5796c8dcSSimon Schubert nargs_wanted = 0; 2015*5796c8dcSSimon Schubert f = string; 2016*5796c8dcSSimon Schubert last_arg = string; 2017*5796c8dcSSimon Schubert while (*f) 2018*5796c8dcSSimon Schubert if (*f++ == '%') 2019*5796c8dcSSimon Schubert { 2020*5796c8dcSSimon Schubert int seen_hash = 0, seen_zero = 0, lcount = 0, seen_prec = 0; 2021*5796c8dcSSimon Schubert int seen_space = 0, seen_plus = 0; 2022*5796c8dcSSimon Schubert int seen_big_l = 0, seen_h = 0, seen_big_h = 0; 2023*5796c8dcSSimon Schubert int seen_big_d = 0, seen_double_big_d = 0; 2024*5796c8dcSSimon Schubert int bad = 0; 2025*5796c8dcSSimon Schubert 2026*5796c8dcSSimon Schubert /* Check the validity of the format specifier, and work 2027*5796c8dcSSimon Schubert out what argument it expects. We only accept C89 2028*5796c8dcSSimon Schubert format strings, with the exception of long long (which 2029*5796c8dcSSimon Schubert we autoconf for). */ 2030*5796c8dcSSimon Schubert 2031*5796c8dcSSimon Schubert /* Skip over "%%". */ 2032*5796c8dcSSimon Schubert if (*f == '%') 2033*5796c8dcSSimon Schubert { 2034*5796c8dcSSimon Schubert f++; 2035*5796c8dcSSimon Schubert continue; 2036*5796c8dcSSimon Schubert } 2037*5796c8dcSSimon Schubert 2038*5796c8dcSSimon Schubert /* The first part of a format specifier is a set of flag 2039*5796c8dcSSimon Schubert characters. */ 2040*5796c8dcSSimon Schubert while (strchr ("0-+ #", *f)) 2041*5796c8dcSSimon Schubert { 2042*5796c8dcSSimon Schubert if (*f == '#') 2043*5796c8dcSSimon Schubert seen_hash = 1; 2044*5796c8dcSSimon Schubert else if (*f == '0') 2045*5796c8dcSSimon Schubert seen_zero = 1; 2046*5796c8dcSSimon Schubert else if (*f == ' ') 2047*5796c8dcSSimon Schubert seen_space = 1; 2048*5796c8dcSSimon Schubert else if (*f == '+') 2049*5796c8dcSSimon Schubert seen_plus = 1; 2050*5796c8dcSSimon Schubert f++; 2051*5796c8dcSSimon Schubert } 2052*5796c8dcSSimon Schubert 2053*5796c8dcSSimon Schubert /* The next part of a format specifier is a width. */ 2054*5796c8dcSSimon Schubert while (strchr ("0123456789", *f)) 2055*5796c8dcSSimon Schubert f++; 2056*5796c8dcSSimon Schubert 2057*5796c8dcSSimon Schubert /* The next part of a format specifier is a precision. */ 2058*5796c8dcSSimon Schubert if (*f == '.') 2059*5796c8dcSSimon Schubert { 2060*5796c8dcSSimon Schubert seen_prec = 1; 2061*5796c8dcSSimon Schubert f++; 2062*5796c8dcSSimon Schubert while (strchr ("0123456789", *f)) 2063*5796c8dcSSimon Schubert f++; 2064*5796c8dcSSimon Schubert } 2065*5796c8dcSSimon Schubert 2066*5796c8dcSSimon Schubert /* The next part of a format specifier is a length modifier. */ 2067*5796c8dcSSimon Schubert if (*f == 'h') 2068*5796c8dcSSimon Schubert { 2069*5796c8dcSSimon Schubert seen_h = 1; 2070*5796c8dcSSimon Schubert f++; 2071*5796c8dcSSimon Schubert } 2072*5796c8dcSSimon Schubert else if (*f == 'l') 2073*5796c8dcSSimon Schubert { 2074*5796c8dcSSimon Schubert f++; 2075*5796c8dcSSimon Schubert lcount++; 2076*5796c8dcSSimon Schubert if (*f == 'l') 2077*5796c8dcSSimon Schubert { 2078*5796c8dcSSimon Schubert f++; 2079*5796c8dcSSimon Schubert lcount++; 2080*5796c8dcSSimon Schubert } 2081*5796c8dcSSimon Schubert } 2082*5796c8dcSSimon Schubert else if (*f == 'L') 2083*5796c8dcSSimon Schubert { 2084*5796c8dcSSimon Schubert seen_big_l = 1; 2085*5796c8dcSSimon Schubert f++; 2086*5796c8dcSSimon Schubert } 2087*5796c8dcSSimon Schubert /* Decimal32 modifier. */ 2088*5796c8dcSSimon Schubert else if (*f == 'H') 2089*5796c8dcSSimon Schubert { 2090*5796c8dcSSimon Schubert seen_big_h = 1; 2091*5796c8dcSSimon Schubert f++; 2092*5796c8dcSSimon Schubert } 2093*5796c8dcSSimon Schubert /* Decimal64 and Decimal128 modifiers. */ 2094*5796c8dcSSimon Schubert else if (*f == 'D') 2095*5796c8dcSSimon Schubert { 2096*5796c8dcSSimon Schubert f++; 2097*5796c8dcSSimon Schubert 2098*5796c8dcSSimon Schubert /* Check for a Decimal128. */ 2099*5796c8dcSSimon Schubert if (*f == 'D') 2100*5796c8dcSSimon Schubert { 2101*5796c8dcSSimon Schubert f++; 2102*5796c8dcSSimon Schubert seen_double_big_d = 1; 2103*5796c8dcSSimon Schubert } 2104*5796c8dcSSimon Schubert else 2105*5796c8dcSSimon Schubert seen_big_d = 1; 2106*5796c8dcSSimon Schubert } 2107*5796c8dcSSimon Schubert 2108*5796c8dcSSimon Schubert switch (*f) 2109*5796c8dcSSimon Schubert { 2110*5796c8dcSSimon Schubert case 'u': 2111*5796c8dcSSimon Schubert if (seen_hash) 2112*5796c8dcSSimon Schubert bad = 1; 2113*5796c8dcSSimon Schubert /* FALLTHROUGH */ 2114*5796c8dcSSimon Schubert 2115*5796c8dcSSimon Schubert case 'o': 2116*5796c8dcSSimon Schubert case 'x': 2117*5796c8dcSSimon Schubert case 'X': 2118*5796c8dcSSimon Schubert if (seen_space || seen_plus) 2119*5796c8dcSSimon Schubert bad = 1; 2120*5796c8dcSSimon Schubert /* FALLTHROUGH */ 2121*5796c8dcSSimon Schubert 2122*5796c8dcSSimon Schubert case 'd': 2123*5796c8dcSSimon Schubert case 'i': 2124*5796c8dcSSimon Schubert if (lcount == 0) 2125*5796c8dcSSimon Schubert this_argclass = int_arg; 2126*5796c8dcSSimon Schubert else if (lcount == 1) 2127*5796c8dcSSimon Schubert this_argclass = long_arg; 2128*5796c8dcSSimon Schubert else 2129*5796c8dcSSimon Schubert this_argclass = long_long_arg; 2130*5796c8dcSSimon Schubert 2131*5796c8dcSSimon Schubert if (seen_big_l) 2132*5796c8dcSSimon Schubert bad = 1; 2133*5796c8dcSSimon Schubert break; 2134*5796c8dcSSimon Schubert 2135*5796c8dcSSimon Schubert case 'c': 2136*5796c8dcSSimon Schubert this_argclass = lcount == 0 ? int_arg : wide_char_arg; 2137*5796c8dcSSimon Schubert if (lcount > 1 || seen_h || seen_big_l) 2138*5796c8dcSSimon Schubert bad = 1; 2139*5796c8dcSSimon Schubert if (seen_prec || seen_zero || seen_space || seen_plus) 2140*5796c8dcSSimon Schubert bad = 1; 2141*5796c8dcSSimon Schubert break; 2142*5796c8dcSSimon Schubert 2143*5796c8dcSSimon Schubert case 'p': 2144*5796c8dcSSimon Schubert this_argclass = ptr_arg; 2145*5796c8dcSSimon Schubert if (lcount || seen_h || seen_big_l) 2146*5796c8dcSSimon Schubert bad = 1; 2147*5796c8dcSSimon Schubert if (seen_prec || seen_zero || seen_space || seen_plus) 2148*5796c8dcSSimon Schubert bad = 1; 2149*5796c8dcSSimon Schubert break; 2150*5796c8dcSSimon Schubert 2151*5796c8dcSSimon Schubert case 's': 2152*5796c8dcSSimon Schubert this_argclass = lcount == 0 ? string_arg : wide_string_arg; 2153*5796c8dcSSimon Schubert if (lcount > 1 || seen_h || seen_big_l) 2154*5796c8dcSSimon Schubert bad = 1; 2155*5796c8dcSSimon Schubert if (seen_zero || seen_space || seen_plus) 2156*5796c8dcSSimon Schubert bad = 1; 2157*5796c8dcSSimon Schubert break; 2158*5796c8dcSSimon Schubert 2159*5796c8dcSSimon Schubert case 'e': 2160*5796c8dcSSimon Schubert case 'f': 2161*5796c8dcSSimon Schubert case 'g': 2162*5796c8dcSSimon Schubert case 'E': 2163*5796c8dcSSimon Schubert case 'G': 2164*5796c8dcSSimon Schubert if (seen_big_h || seen_big_d || seen_double_big_d) 2165*5796c8dcSSimon Schubert this_argclass = decfloat_arg; 2166*5796c8dcSSimon Schubert else if (seen_big_l) 2167*5796c8dcSSimon Schubert this_argclass = long_double_arg; 2168*5796c8dcSSimon Schubert else 2169*5796c8dcSSimon Schubert this_argclass = double_arg; 2170*5796c8dcSSimon Schubert 2171*5796c8dcSSimon Schubert if (lcount || seen_h) 2172*5796c8dcSSimon Schubert bad = 1; 2173*5796c8dcSSimon Schubert break; 2174*5796c8dcSSimon Schubert 2175*5796c8dcSSimon Schubert case '*': 2176*5796c8dcSSimon Schubert error (_("`*' not supported for precision or width in printf")); 2177*5796c8dcSSimon Schubert 2178*5796c8dcSSimon Schubert case 'n': 2179*5796c8dcSSimon Schubert error (_("Format specifier `n' not supported in printf")); 2180*5796c8dcSSimon Schubert 2181*5796c8dcSSimon Schubert case '\0': 2182*5796c8dcSSimon Schubert error (_("Incomplete format specifier at end of format string")); 2183*5796c8dcSSimon Schubert 2184*5796c8dcSSimon Schubert default: 2185*5796c8dcSSimon Schubert error (_("Unrecognized format specifier '%c' in printf"), *f); 2186*5796c8dcSSimon Schubert } 2187*5796c8dcSSimon Schubert 2188*5796c8dcSSimon Schubert if (bad) 2189*5796c8dcSSimon Schubert error (_("Inappropriate modifiers to format specifier '%c' in printf"), 2190*5796c8dcSSimon Schubert *f); 2191*5796c8dcSSimon Schubert 2192*5796c8dcSSimon Schubert f++; 2193*5796c8dcSSimon Schubert 2194*5796c8dcSSimon Schubert if (lcount > 1 && USE_PRINTF_I64) 2195*5796c8dcSSimon Schubert { 2196*5796c8dcSSimon Schubert /* Windows' printf does support long long, but not the usual way. 2197*5796c8dcSSimon Schubert Convert %lld to %I64d. */ 2198*5796c8dcSSimon Schubert int length_before_ll = f - last_arg - 1 - lcount; 2199*5796c8dcSSimon Schubert strncpy (current_substring, last_arg, length_before_ll); 2200*5796c8dcSSimon Schubert strcpy (current_substring + length_before_ll, "I64"); 2201*5796c8dcSSimon Schubert current_substring[length_before_ll + 3] = 2202*5796c8dcSSimon Schubert last_arg[length_before_ll + lcount]; 2203*5796c8dcSSimon Schubert current_substring += length_before_ll + 4; 2204*5796c8dcSSimon Schubert } 2205*5796c8dcSSimon Schubert else if (this_argclass == wide_string_arg 2206*5796c8dcSSimon Schubert || this_argclass == wide_char_arg) 2207*5796c8dcSSimon Schubert { 2208*5796c8dcSSimon Schubert /* Convert %ls or %lc to %s. */ 2209*5796c8dcSSimon Schubert int length_before_ls = f - last_arg - 2; 2210*5796c8dcSSimon Schubert strncpy (current_substring, last_arg, length_before_ls); 2211*5796c8dcSSimon Schubert strcpy (current_substring + length_before_ls, "s"); 2212*5796c8dcSSimon Schubert current_substring += length_before_ls + 2; 2213*5796c8dcSSimon Schubert } 2214*5796c8dcSSimon Schubert else 2215*5796c8dcSSimon Schubert { 2216*5796c8dcSSimon Schubert strncpy (current_substring, last_arg, f - last_arg); 2217*5796c8dcSSimon Schubert current_substring += f - last_arg; 2218*5796c8dcSSimon Schubert } 2219*5796c8dcSSimon Schubert *current_substring++ = '\0'; 2220*5796c8dcSSimon Schubert last_arg = f; 2221*5796c8dcSSimon Schubert argclass[nargs_wanted++] = this_argclass; 2222*5796c8dcSSimon Schubert } 2223*5796c8dcSSimon Schubert 2224*5796c8dcSSimon Schubert /* Now, parse all arguments and evaluate them. 2225*5796c8dcSSimon Schubert Store the VALUEs in VAL_ARGS. */ 2226*5796c8dcSSimon Schubert 2227*5796c8dcSSimon Schubert while (*s != '\0') 2228*5796c8dcSSimon Schubert { 2229*5796c8dcSSimon Schubert char *s1; 2230*5796c8dcSSimon Schubert if (nargs == allocated_args) 2231*5796c8dcSSimon Schubert val_args = (struct value **) xrealloc ((char *) val_args, 2232*5796c8dcSSimon Schubert (allocated_args *= 2) 2233*5796c8dcSSimon Schubert * sizeof (struct value *)); 2234*5796c8dcSSimon Schubert s1 = s; 2235*5796c8dcSSimon Schubert val_args[nargs] = parse_to_comma_and_eval (&s1); 2236*5796c8dcSSimon Schubert 2237*5796c8dcSSimon Schubert nargs++; 2238*5796c8dcSSimon Schubert s = s1; 2239*5796c8dcSSimon Schubert if (*s == ',') 2240*5796c8dcSSimon Schubert s++; 2241*5796c8dcSSimon Schubert } 2242*5796c8dcSSimon Schubert 2243*5796c8dcSSimon Schubert if (nargs != nargs_wanted) 2244*5796c8dcSSimon Schubert error (_("Wrong number of arguments for specified format-string")); 2245*5796c8dcSSimon Schubert 2246*5796c8dcSSimon Schubert /* Now actually print them. */ 2247*5796c8dcSSimon Schubert current_substring = substrings; 2248*5796c8dcSSimon Schubert for (i = 0; i < nargs; i++) 2249*5796c8dcSSimon Schubert { 2250*5796c8dcSSimon Schubert switch (argclass[i]) 2251*5796c8dcSSimon Schubert { 2252*5796c8dcSSimon Schubert case string_arg: 2253*5796c8dcSSimon Schubert { 2254*5796c8dcSSimon Schubert gdb_byte *str; 2255*5796c8dcSSimon Schubert CORE_ADDR tem; 2256*5796c8dcSSimon Schubert int j; 2257*5796c8dcSSimon Schubert tem = value_as_address (val_args[i]); 2258*5796c8dcSSimon Schubert 2259*5796c8dcSSimon Schubert /* This is a %s argument. Find the length of the string. */ 2260*5796c8dcSSimon Schubert for (j = 0;; j++) 2261*5796c8dcSSimon Schubert { 2262*5796c8dcSSimon Schubert gdb_byte c; 2263*5796c8dcSSimon Schubert QUIT; 2264*5796c8dcSSimon Schubert read_memory (tem + j, &c, 1); 2265*5796c8dcSSimon Schubert if (c == 0) 2266*5796c8dcSSimon Schubert break; 2267*5796c8dcSSimon Schubert } 2268*5796c8dcSSimon Schubert 2269*5796c8dcSSimon Schubert /* Copy the string contents into a string inside GDB. */ 2270*5796c8dcSSimon Schubert str = (gdb_byte *) alloca (j + 1); 2271*5796c8dcSSimon Schubert if (j != 0) 2272*5796c8dcSSimon Schubert read_memory (tem, str, j); 2273*5796c8dcSSimon Schubert str[j] = 0; 2274*5796c8dcSSimon Schubert 2275*5796c8dcSSimon Schubert printf_filtered (current_substring, (char *) str); 2276*5796c8dcSSimon Schubert } 2277*5796c8dcSSimon Schubert break; 2278*5796c8dcSSimon Schubert case wide_string_arg: 2279*5796c8dcSSimon Schubert { 2280*5796c8dcSSimon Schubert gdb_byte *str; 2281*5796c8dcSSimon Schubert CORE_ADDR tem; 2282*5796c8dcSSimon Schubert int j; 2283*5796c8dcSSimon Schubert struct gdbarch *gdbarch 2284*5796c8dcSSimon Schubert = get_type_arch (value_type (val_args[i])); 2285*5796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 2286*5796c8dcSSimon Schubert struct type *wctype = lookup_typename (current_language, gdbarch, 2287*5796c8dcSSimon Schubert "wchar_t", NULL, 0); 2288*5796c8dcSSimon Schubert int wcwidth = TYPE_LENGTH (wctype); 2289*5796c8dcSSimon Schubert gdb_byte *buf = alloca (wcwidth); 2290*5796c8dcSSimon Schubert struct obstack output; 2291*5796c8dcSSimon Schubert struct cleanup *inner_cleanup; 2292*5796c8dcSSimon Schubert 2293*5796c8dcSSimon Schubert tem = value_as_address (val_args[i]); 2294*5796c8dcSSimon Schubert 2295*5796c8dcSSimon Schubert /* This is a %s argument. Find the length of the string. */ 2296*5796c8dcSSimon Schubert for (j = 0;; j += wcwidth) 2297*5796c8dcSSimon Schubert { 2298*5796c8dcSSimon Schubert QUIT; 2299*5796c8dcSSimon Schubert read_memory (tem + j, buf, wcwidth); 2300*5796c8dcSSimon Schubert if (extract_unsigned_integer (buf, wcwidth, byte_order) == 0) 2301*5796c8dcSSimon Schubert break; 2302*5796c8dcSSimon Schubert } 2303*5796c8dcSSimon Schubert 2304*5796c8dcSSimon Schubert /* Copy the string contents into a string inside GDB. */ 2305*5796c8dcSSimon Schubert str = (gdb_byte *) alloca (j + wcwidth); 2306*5796c8dcSSimon Schubert if (j != 0) 2307*5796c8dcSSimon Schubert read_memory (tem, str, j); 2308*5796c8dcSSimon Schubert memset (&str[j], 0, wcwidth); 2309*5796c8dcSSimon Schubert 2310*5796c8dcSSimon Schubert obstack_init (&output); 2311*5796c8dcSSimon Schubert inner_cleanup = make_cleanup_obstack_free (&output); 2312*5796c8dcSSimon Schubert 2313*5796c8dcSSimon Schubert convert_between_encodings (target_wide_charset (byte_order), 2314*5796c8dcSSimon Schubert host_charset (), 2315*5796c8dcSSimon Schubert str, j, wcwidth, 2316*5796c8dcSSimon Schubert &output, translit_char); 2317*5796c8dcSSimon Schubert obstack_grow_str0 (&output, ""); 2318*5796c8dcSSimon Schubert 2319*5796c8dcSSimon Schubert printf_filtered (current_substring, obstack_base (&output)); 2320*5796c8dcSSimon Schubert do_cleanups (inner_cleanup); 2321*5796c8dcSSimon Schubert } 2322*5796c8dcSSimon Schubert break; 2323*5796c8dcSSimon Schubert case wide_char_arg: 2324*5796c8dcSSimon Schubert { 2325*5796c8dcSSimon Schubert struct gdbarch *gdbarch 2326*5796c8dcSSimon Schubert = get_type_arch (value_type (val_args[i])); 2327*5796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 2328*5796c8dcSSimon Schubert struct type *wctype = lookup_typename (current_language, gdbarch, 2329*5796c8dcSSimon Schubert "wchar_t", NULL, 0); 2330*5796c8dcSSimon Schubert struct type *valtype; 2331*5796c8dcSSimon Schubert struct obstack output; 2332*5796c8dcSSimon Schubert struct cleanup *inner_cleanup; 2333*5796c8dcSSimon Schubert const gdb_byte *bytes; 2334*5796c8dcSSimon Schubert 2335*5796c8dcSSimon Schubert valtype = value_type (val_args[i]); 2336*5796c8dcSSimon Schubert if (TYPE_LENGTH (valtype) != TYPE_LENGTH (wctype) 2337*5796c8dcSSimon Schubert || TYPE_CODE (valtype) != TYPE_CODE_INT) 2338*5796c8dcSSimon Schubert error (_("expected wchar_t argument for %%lc")); 2339*5796c8dcSSimon Schubert 2340*5796c8dcSSimon Schubert bytes = value_contents (val_args[i]); 2341*5796c8dcSSimon Schubert 2342*5796c8dcSSimon Schubert obstack_init (&output); 2343*5796c8dcSSimon Schubert inner_cleanup = make_cleanup_obstack_free (&output); 2344*5796c8dcSSimon Schubert 2345*5796c8dcSSimon Schubert convert_between_encodings (target_wide_charset (byte_order), 2346*5796c8dcSSimon Schubert host_charset (), 2347*5796c8dcSSimon Schubert bytes, TYPE_LENGTH (valtype), 2348*5796c8dcSSimon Schubert TYPE_LENGTH (valtype), 2349*5796c8dcSSimon Schubert &output, translit_char); 2350*5796c8dcSSimon Schubert obstack_grow_str0 (&output, ""); 2351*5796c8dcSSimon Schubert 2352*5796c8dcSSimon Schubert printf_filtered (current_substring, obstack_base (&output)); 2353*5796c8dcSSimon Schubert do_cleanups (inner_cleanup); 2354*5796c8dcSSimon Schubert } 2355*5796c8dcSSimon Schubert break; 2356*5796c8dcSSimon Schubert case double_arg: 2357*5796c8dcSSimon Schubert { 2358*5796c8dcSSimon Schubert struct type *type = value_type (val_args[i]); 2359*5796c8dcSSimon Schubert DOUBLEST val; 2360*5796c8dcSSimon Schubert int inv; 2361*5796c8dcSSimon Schubert 2362*5796c8dcSSimon Schubert /* If format string wants a float, unchecked-convert the value 2363*5796c8dcSSimon Schubert to floating point of the same size. */ 2364*5796c8dcSSimon Schubert type = float_type_from_length (type); 2365*5796c8dcSSimon Schubert val = unpack_double (type, value_contents (val_args[i]), &inv); 2366*5796c8dcSSimon Schubert if (inv) 2367*5796c8dcSSimon Schubert error (_("Invalid floating value found in program.")); 2368*5796c8dcSSimon Schubert 2369*5796c8dcSSimon Schubert printf_filtered (current_substring, (double) val); 2370*5796c8dcSSimon Schubert break; 2371*5796c8dcSSimon Schubert } 2372*5796c8dcSSimon Schubert case long_double_arg: 2373*5796c8dcSSimon Schubert #ifdef HAVE_LONG_DOUBLE 2374*5796c8dcSSimon Schubert { 2375*5796c8dcSSimon Schubert struct type *type = value_type (val_args[i]); 2376*5796c8dcSSimon Schubert DOUBLEST val; 2377*5796c8dcSSimon Schubert int inv; 2378*5796c8dcSSimon Schubert 2379*5796c8dcSSimon Schubert /* If format string wants a float, unchecked-convert the value 2380*5796c8dcSSimon Schubert to floating point of the same size. */ 2381*5796c8dcSSimon Schubert type = float_type_from_length (type); 2382*5796c8dcSSimon Schubert val = unpack_double (type, value_contents (val_args[i]), &inv); 2383*5796c8dcSSimon Schubert if (inv) 2384*5796c8dcSSimon Schubert error (_("Invalid floating value found in program.")); 2385*5796c8dcSSimon Schubert 2386*5796c8dcSSimon Schubert printf_filtered (current_substring, (long double) val); 2387*5796c8dcSSimon Schubert break; 2388*5796c8dcSSimon Schubert } 2389*5796c8dcSSimon Schubert #else 2390*5796c8dcSSimon Schubert error (_("long double not supported in printf")); 2391*5796c8dcSSimon Schubert #endif 2392*5796c8dcSSimon Schubert case long_long_arg: 2393*5796c8dcSSimon Schubert #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG) 2394*5796c8dcSSimon Schubert { 2395*5796c8dcSSimon Schubert long long val = value_as_long (val_args[i]); 2396*5796c8dcSSimon Schubert printf_filtered (current_substring, val); 2397*5796c8dcSSimon Schubert break; 2398*5796c8dcSSimon Schubert } 2399*5796c8dcSSimon Schubert #else 2400*5796c8dcSSimon Schubert error (_("long long not supported in printf")); 2401*5796c8dcSSimon Schubert #endif 2402*5796c8dcSSimon Schubert case int_arg: 2403*5796c8dcSSimon Schubert { 2404*5796c8dcSSimon Schubert int val = value_as_long (val_args[i]); 2405*5796c8dcSSimon Schubert printf_filtered (current_substring, val); 2406*5796c8dcSSimon Schubert break; 2407*5796c8dcSSimon Schubert } 2408*5796c8dcSSimon Schubert case long_arg: 2409*5796c8dcSSimon Schubert { 2410*5796c8dcSSimon Schubert long val = value_as_long (val_args[i]); 2411*5796c8dcSSimon Schubert printf_filtered (current_substring, val); 2412*5796c8dcSSimon Schubert break; 2413*5796c8dcSSimon Schubert } 2414*5796c8dcSSimon Schubert 2415*5796c8dcSSimon Schubert /* Handles decimal floating values. */ 2416*5796c8dcSSimon Schubert case decfloat_arg: 2417*5796c8dcSSimon Schubert { 2418*5796c8dcSSimon Schubert const gdb_byte *param_ptr = value_contents (val_args[i]); 2419*5796c8dcSSimon Schubert #if defined (PRINTF_HAS_DECFLOAT) 2420*5796c8dcSSimon Schubert /* If we have native support for Decimal floating 2421*5796c8dcSSimon Schubert printing, handle it here. */ 2422*5796c8dcSSimon Schubert printf_filtered (current_substring, param_ptr); 2423*5796c8dcSSimon Schubert #else 2424*5796c8dcSSimon Schubert 2425*5796c8dcSSimon Schubert /* As a workaround until vasprintf has native support for DFP 2426*5796c8dcSSimon Schubert we convert the DFP values to string and print them using 2427*5796c8dcSSimon Schubert the %s format specifier. */ 2428*5796c8dcSSimon Schubert 2429*5796c8dcSSimon Schubert char *eos, *sos; 2430*5796c8dcSSimon Schubert int nnull_chars = 0; 2431*5796c8dcSSimon Schubert 2432*5796c8dcSSimon Schubert /* Parameter data. */ 2433*5796c8dcSSimon Schubert struct type *param_type = value_type (val_args[i]); 2434*5796c8dcSSimon Schubert unsigned int param_len = TYPE_LENGTH (param_type); 2435*5796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (param_type); 2436*5796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 2437*5796c8dcSSimon Schubert 2438*5796c8dcSSimon Schubert /* DFP output data. */ 2439*5796c8dcSSimon Schubert struct value *dfp_value = NULL; 2440*5796c8dcSSimon Schubert gdb_byte *dfp_ptr; 2441*5796c8dcSSimon Schubert int dfp_len = 16; 2442*5796c8dcSSimon Schubert gdb_byte dec[16]; 2443*5796c8dcSSimon Schubert struct type *dfp_type = NULL; 2444*5796c8dcSSimon Schubert char decstr[MAX_DECIMAL_STRING]; 2445*5796c8dcSSimon Schubert 2446*5796c8dcSSimon Schubert /* Points to the end of the string so that we can go back 2447*5796c8dcSSimon Schubert and check for DFP length modifiers. */ 2448*5796c8dcSSimon Schubert eos = current_substring + strlen (current_substring); 2449*5796c8dcSSimon Schubert 2450*5796c8dcSSimon Schubert /* Look for the float/double format specifier. */ 2451*5796c8dcSSimon Schubert while (*eos != 'f' && *eos != 'e' && *eos != 'E' 2452*5796c8dcSSimon Schubert && *eos != 'g' && *eos != 'G') 2453*5796c8dcSSimon Schubert eos--; 2454*5796c8dcSSimon Schubert 2455*5796c8dcSSimon Schubert sos = eos; 2456*5796c8dcSSimon Schubert 2457*5796c8dcSSimon Schubert /* Search for the '%' char and extract the size and type of 2458*5796c8dcSSimon Schubert the output decimal value based on its modifiers 2459*5796c8dcSSimon Schubert (%Hf, %Df, %DDf). */ 2460*5796c8dcSSimon Schubert while (*--sos != '%') 2461*5796c8dcSSimon Schubert { 2462*5796c8dcSSimon Schubert if (*sos == 'H') 2463*5796c8dcSSimon Schubert { 2464*5796c8dcSSimon Schubert dfp_len = 4; 2465*5796c8dcSSimon Schubert dfp_type = builtin_type (gdbarch)->builtin_decfloat; 2466*5796c8dcSSimon Schubert } 2467*5796c8dcSSimon Schubert else if (*sos == 'D' && *(sos - 1) == 'D') 2468*5796c8dcSSimon Schubert { 2469*5796c8dcSSimon Schubert dfp_len = 16; 2470*5796c8dcSSimon Schubert dfp_type = builtin_type (gdbarch)->builtin_declong; 2471*5796c8dcSSimon Schubert sos--; 2472*5796c8dcSSimon Schubert } 2473*5796c8dcSSimon Schubert else 2474*5796c8dcSSimon Schubert { 2475*5796c8dcSSimon Schubert dfp_len = 8; 2476*5796c8dcSSimon Schubert dfp_type = builtin_type (gdbarch)->builtin_decdouble; 2477*5796c8dcSSimon Schubert } 2478*5796c8dcSSimon Schubert } 2479*5796c8dcSSimon Schubert 2480*5796c8dcSSimon Schubert /* Replace %Hf, %Df and %DDf with %s's. */ 2481*5796c8dcSSimon Schubert *++sos = 's'; 2482*5796c8dcSSimon Schubert 2483*5796c8dcSSimon Schubert /* Go through the whole format string and pull the correct 2484*5796c8dcSSimon Schubert number of chars back to compensate for the change in the 2485*5796c8dcSSimon Schubert format specifier. */ 2486*5796c8dcSSimon Schubert while (nnull_chars < nargs - i) 2487*5796c8dcSSimon Schubert { 2488*5796c8dcSSimon Schubert if (*eos == '\0') 2489*5796c8dcSSimon Schubert nnull_chars++; 2490*5796c8dcSSimon Schubert 2491*5796c8dcSSimon Schubert *++sos = *++eos; 2492*5796c8dcSSimon Schubert } 2493*5796c8dcSSimon Schubert 2494*5796c8dcSSimon Schubert /* Conversion between different DFP types. */ 2495*5796c8dcSSimon Schubert if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT) 2496*5796c8dcSSimon Schubert decimal_convert (param_ptr, param_len, byte_order, 2497*5796c8dcSSimon Schubert dec, dfp_len, byte_order); 2498*5796c8dcSSimon Schubert else 2499*5796c8dcSSimon Schubert /* If this is a non-trivial conversion, just output 0. 2500*5796c8dcSSimon Schubert A correct converted value can be displayed by explicitly 2501*5796c8dcSSimon Schubert casting to a DFP type. */ 2502*5796c8dcSSimon Schubert decimal_from_string (dec, dfp_len, byte_order, "0"); 2503*5796c8dcSSimon Schubert 2504*5796c8dcSSimon Schubert dfp_value = value_from_decfloat (dfp_type, dec); 2505*5796c8dcSSimon Schubert 2506*5796c8dcSSimon Schubert dfp_ptr = (gdb_byte *) value_contents (dfp_value); 2507*5796c8dcSSimon Schubert 2508*5796c8dcSSimon Schubert decimal_to_string (dfp_ptr, dfp_len, byte_order, decstr); 2509*5796c8dcSSimon Schubert 2510*5796c8dcSSimon Schubert /* Print the DFP value. */ 2511*5796c8dcSSimon Schubert printf_filtered (current_substring, decstr); 2512*5796c8dcSSimon Schubert 2513*5796c8dcSSimon Schubert break; 2514*5796c8dcSSimon Schubert #endif 2515*5796c8dcSSimon Schubert } 2516*5796c8dcSSimon Schubert 2517*5796c8dcSSimon Schubert case ptr_arg: 2518*5796c8dcSSimon Schubert { 2519*5796c8dcSSimon Schubert /* We avoid the host's %p because pointers are too 2520*5796c8dcSSimon Schubert likely to be the wrong size. The only interesting 2521*5796c8dcSSimon Schubert modifier for %p is a width; extract that, and then 2522*5796c8dcSSimon Schubert handle %p as glibc would: %#x or a literal "(nil)". */ 2523*5796c8dcSSimon Schubert 2524*5796c8dcSSimon Schubert char *p, *fmt, *fmt_p; 2525*5796c8dcSSimon Schubert #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG) 2526*5796c8dcSSimon Schubert long long val = value_as_long (val_args[i]); 2527*5796c8dcSSimon Schubert #else 2528*5796c8dcSSimon Schubert long val = value_as_long (val_args[i]); 2529*5796c8dcSSimon Schubert #endif 2530*5796c8dcSSimon Schubert 2531*5796c8dcSSimon Schubert fmt = alloca (strlen (current_substring) + 5); 2532*5796c8dcSSimon Schubert 2533*5796c8dcSSimon Schubert /* Copy up to the leading %. */ 2534*5796c8dcSSimon Schubert p = current_substring; 2535*5796c8dcSSimon Schubert fmt_p = fmt; 2536*5796c8dcSSimon Schubert while (*p) 2537*5796c8dcSSimon Schubert { 2538*5796c8dcSSimon Schubert int is_percent = (*p == '%'); 2539*5796c8dcSSimon Schubert *fmt_p++ = *p++; 2540*5796c8dcSSimon Schubert if (is_percent) 2541*5796c8dcSSimon Schubert { 2542*5796c8dcSSimon Schubert if (*p == '%') 2543*5796c8dcSSimon Schubert *fmt_p++ = *p++; 2544*5796c8dcSSimon Schubert else 2545*5796c8dcSSimon Schubert break; 2546*5796c8dcSSimon Schubert } 2547*5796c8dcSSimon Schubert } 2548*5796c8dcSSimon Schubert 2549*5796c8dcSSimon Schubert if (val != 0) 2550*5796c8dcSSimon Schubert *fmt_p++ = '#'; 2551*5796c8dcSSimon Schubert 2552*5796c8dcSSimon Schubert /* Copy any width. */ 2553*5796c8dcSSimon Schubert while (*p >= '0' && *p < '9') 2554*5796c8dcSSimon Schubert *fmt_p++ = *p++; 2555*5796c8dcSSimon Schubert 2556*5796c8dcSSimon Schubert gdb_assert (*p == 'p' && *(p + 1) == '\0'); 2557*5796c8dcSSimon Schubert if (val != 0) 2558*5796c8dcSSimon Schubert { 2559*5796c8dcSSimon Schubert #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG) 2560*5796c8dcSSimon Schubert *fmt_p++ = 'l'; 2561*5796c8dcSSimon Schubert #endif 2562*5796c8dcSSimon Schubert *fmt_p++ = 'l'; 2563*5796c8dcSSimon Schubert *fmt_p++ = 'x'; 2564*5796c8dcSSimon Schubert *fmt_p++ = '\0'; 2565*5796c8dcSSimon Schubert printf_filtered (fmt, val); 2566*5796c8dcSSimon Schubert } 2567*5796c8dcSSimon Schubert else 2568*5796c8dcSSimon Schubert { 2569*5796c8dcSSimon Schubert *fmt_p++ = 's'; 2570*5796c8dcSSimon Schubert *fmt_p++ = '\0'; 2571*5796c8dcSSimon Schubert printf_filtered (fmt, "(nil)"); 2572*5796c8dcSSimon Schubert } 2573*5796c8dcSSimon Schubert 2574*5796c8dcSSimon Schubert break; 2575*5796c8dcSSimon Schubert } 2576*5796c8dcSSimon Schubert default: 2577*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 2578*5796c8dcSSimon Schubert _("failed internal consistency check")); 2579*5796c8dcSSimon Schubert } 2580*5796c8dcSSimon Schubert /* Skip to the next substring. */ 2581*5796c8dcSSimon Schubert current_substring += strlen (current_substring) + 1; 2582*5796c8dcSSimon Schubert } 2583*5796c8dcSSimon Schubert /* Print the portion of the format string after the last argument. */ 2584*5796c8dcSSimon Schubert puts_filtered (last_arg); 2585*5796c8dcSSimon Schubert } 2586*5796c8dcSSimon Schubert do_cleanups (old_cleanups); 2587*5796c8dcSSimon Schubert } 2588*5796c8dcSSimon Schubert 2589*5796c8dcSSimon Schubert void 2590*5796c8dcSSimon Schubert _initialize_printcmd (void) 2591*5796c8dcSSimon Schubert { 2592*5796c8dcSSimon Schubert struct cmd_list_element *c; 2593*5796c8dcSSimon Schubert 2594*5796c8dcSSimon Schubert current_display_number = -1; 2595*5796c8dcSSimon Schubert 2596*5796c8dcSSimon Schubert observer_attach_solib_unloaded (clear_dangling_display_expressions); 2597*5796c8dcSSimon Schubert 2598*5796c8dcSSimon Schubert add_info ("address", address_info, 2599*5796c8dcSSimon Schubert _("Describe where symbol SYM is stored.")); 2600*5796c8dcSSimon Schubert 2601*5796c8dcSSimon Schubert add_info ("symbol", sym_info, _("\ 2602*5796c8dcSSimon Schubert Describe what symbol is at location ADDR.\n\ 2603*5796c8dcSSimon Schubert Only for symbols with fixed locations (global or static scope).")); 2604*5796c8dcSSimon Schubert 2605*5796c8dcSSimon Schubert add_com ("x", class_vars, x_command, _("\ 2606*5796c8dcSSimon Schubert Examine memory: x/FMT ADDRESS.\n\ 2607*5796c8dcSSimon Schubert ADDRESS is an expression for the memory address to examine.\n\ 2608*5796c8dcSSimon Schubert FMT is a repeat count followed by a format letter and a size letter.\n\ 2609*5796c8dcSSimon Schubert Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\ 2610*5796c8dcSSimon Schubert t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\ 2611*5796c8dcSSimon Schubert Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\ 2612*5796c8dcSSimon Schubert The specified number of objects of the specified size are printed\n\ 2613*5796c8dcSSimon Schubert according to the format.\n\n\ 2614*5796c8dcSSimon Schubert Defaults for format and size letters are those previously used.\n\ 2615*5796c8dcSSimon Schubert Default count is 1. Default address is following last thing printed\n\ 2616*5796c8dcSSimon Schubert with this command or \"print\".")); 2617*5796c8dcSSimon Schubert 2618*5796c8dcSSimon Schubert #if 0 2619*5796c8dcSSimon Schubert add_com ("whereis", class_vars, whereis_command, 2620*5796c8dcSSimon Schubert _("Print line number and file of definition of variable.")); 2621*5796c8dcSSimon Schubert #endif 2622*5796c8dcSSimon Schubert 2623*5796c8dcSSimon Schubert add_info ("display", display_info, _("\ 2624*5796c8dcSSimon Schubert Expressions to display when program stops, with code numbers.")); 2625*5796c8dcSSimon Schubert 2626*5796c8dcSSimon Schubert add_cmd ("undisplay", class_vars, undisplay_command, _("\ 2627*5796c8dcSSimon Schubert Cancel some expressions to be displayed when program stops.\n\ 2628*5796c8dcSSimon Schubert Arguments are the code numbers of the expressions to stop displaying.\n\ 2629*5796c8dcSSimon Schubert No argument means cancel all automatic-display expressions.\n\ 2630*5796c8dcSSimon Schubert \"delete display\" has the same effect as this command.\n\ 2631*5796c8dcSSimon Schubert Do \"info display\" to see current list of code numbers."), 2632*5796c8dcSSimon Schubert &cmdlist); 2633*5796c8dcSSimon Schubert 2634*5796c8dcSSimon Schubert add_com ("display", class_vars, display_command, _("\ 2635*5796c8dcSSimon Schubert Print value of expression EXP each time the program stops.\n\ 2636*5796c8dcSSimon Schubert /FMT may be used before EXP as in the \"print\" command.\n\ 2637*5796c8dcSSimon Schubert /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\ 2638*5796c8dcSSimon Schubert as in the \"x\" command, and then EXP is used to get the address to examine\n\ 2639*5796c8dcSSimon Schubert and examining is done as in the \"x\" command.\n\n\ 2640*5796c8dcSSimon Schubert With no argument, display all currently requested auto-display expressions.\n\ 2641*5796c8dcSSimon Schubert Use \"undisplay\" to cancel display requests previously made.")); 2642*5796c8dcSSimon Schubert 2643*5796c8dcSSimon Schubert add_cmd ("display", class_vars, enable_display, _("\ 2644*5796c8dcSSimon Schubert Enable some expressions to be displayed when program stops.\n\ 2645*5796c8dcSSimon Schubert Arguments are the code numbers of the expressions to resume displaying.\n\ 2646*5796c8dcSSimon Schubert No argument means enable all automatic-display expressions.\n\ 2647*5796c8dcSSimon Schubert Do \"info display\" to see current list of code numbers."), &enablelist); 2648*5796c8dcSSimon Schubert 2649*5796c8dcSSimon Schubert add_cmd ("display", class_vars, disable_display_command, _("\ 2650*5796c8dcSSimon Schubert Disable some expressions to be displayed when program stops.\n\ 2651*5796c8dcSSimon Schubert Arguments are the code numbers of the expressions to stop displaying.\n\ 2652*5796c8dcSSimon Schubert No argument means disable all automatic-display expressions.\n\ 2653*5796c8dcSSimon Schubert Do \"info display\" to see current list of code numbers."), &disablelist); 2654*5796c8dcSSimon Schubert 2655*5796c8dcSSimon Schubert add_cmd ("display", class_vars, undisplay_command, _("\ 2656*5796c8dcSSimon Schubert Cancel some expressions to be displayed when program stops.\n\ 2657*5796c8dcSSimon Schubert Arguments are the code numbers of the expressions to stop displaying.\n\ 2658*5796c8dcSSimon Schubert No argument means cancel all automatic-display expressions.\n\ 2659*5796c8dcSSimon Schubert Do \"info display\" to see current list of code numbers."), &deletelist); 2660*5796c8dcSSimon Schubert 2661*5796c8dcSSimon Schubert add_com ("printf", class_vars, printf_command, _("\ 2662*5796c8dcSSimon Schubert printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ 2663*5796c8dcSSimon Schubert This is useful for formatted output in user-defined commands.")); 2664*5796c8dcSSimon Schubert 2665*5796c8dcSSimon Schubert add_com ("output", class_vars, output_command, _("\ 2666*5796c8dcSSimon Schubert Like \"print\" but don't put in value history and don't print newline.\n\ 2667*5796c8dcSSimon Schubert This is useful in user-defined commands.")); 2668*5796c8dcSSimon Schubert 2669*5796c8dcSSimon Schubert add_prefix_cmd ("set", class_vars, set_command, _("\ 2670*5796c8dcSSimon Schubert Evaluate expression EXP and assign result to variable VAR, using assignment\n\ 2671*5796c8dcSSimon Schubert syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ 2672*5796c8dcSSimon Schubert example). VAR may be a debugger \"convenience\" variable (names starting\n\ 2673*5796c8dcSSimon Schubert with $), a register (a few standard names starting with $), or an actual\n\ 2674*5796c8dcSSimon Schubert variable in the program being debugged. EXP is any valid expression.\n\ 2675*5796c8dcSSimon Schubert Use \"set variable\" for variables with names identical to set subcommands.\n\ 2676*5796c8dcSSimon Schubert \n\ 2677*5796c8dcSSimon Schubert With a subcommand, this command modifies parts of the gdb environment.\n\ 2678*5796c8dcSSimon Schubert You can see these environment settings with the \"show\" command."), 2679*5796c8dcSSimon Schubert &setlist, "set ", 1, &cmdlist); 2680*5796c8dcSSimon Schubert if (dbx_commands) 2681*5796c8dcSSimon Schubert add_com ("assign", class_vars, set_command, _("\ 2682*5796c8dcSSimon Schubert Evaluate expression EXP and assign result to variable VAR, using assignment\n\ 2683*5796c8dcSSimon Schubert syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ 2684*5796c8dcSSimon Schubert example). VAR may be a debugger \"convenience\" variable (names starting\n\ 2685*5796c8dcSSimon Schubert with $), a register (a few standard names starting with $), or an actual\n\ 2686*5796c8dcSSimon Schubert variable in the program being debugged. EXP is any valid expression.\n\ 2687*5796c8dcSSimon Schubert Use \"set variable\" for variables with names identical to set subcommands.\n\ 2688*5796c8dcSSimon Schubert \nWith a subcommand, this command modifies parts of the gdb environment.\n\ 2689*5796c8dcSSimon Schubert You can see these environment settings with the \"show\" command.")); 2690*5796c8dcSSimon Schubert 2691*5796c8dcSSimon Schubert /* "call" is the same as "set", but handy for dbx users to call fns. */ 2692*5796c8dcSSimon Schubert c = add_com ("call", class_vars, call_command, _("\ 2693*5796c8dcSSimon Schubert Call a function in the program.\n\ 2694*5796c8dcSSimon Schubert The argument is the function name and arguments, in the notation of the\n\ 2695*5796c8dcSSimon Schubert current working language. The result is printed and saved in the value\n\ 2696*5796c8dcSSimon Schubert history, if it is not void.")); 2697*5796c8dcSSimon Schubert set_cmd_completer (c, expression_completer); 2698*5796c8dcSSimon Schubert 2699*5796c8dcSSimon Schubert add_cmd ("variable", class_vars, set_command, _("\ 2700*5796c8dcSSimon Schubert Evaluate expression EXP and assign result to variable VAR, using assignment\n\ 2701*5796c8dcSSimon Schubert syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ 2702*5796c8dcSSimon Schubert example). VAR may be a debugger \"convenience\" variable (names starting\n\ 2703*5796c8dcSSimon Schubert with $), a register (a few standard names starting with $), or an actual\n\ 2704*5796c8dcSSimon Schubert variable in the program being debugged. EXP is any valid expression.\n\ 2705*5796c8dcSSimon Schubert This may usually be abbreviated to simply \"set\"."), 2706*5796c8dcSSimon Schubert &setlist); 2707*5796c8dcSSimon Schubert 2708*5796c8dcSSimon Schubert c = add_com ("print", class_vars, print_command, _("\ 2709*5796c8dcSSimon Schubert Print value of expression EXP.\n\ 2710*5796c8dcSSimon Schubert Variables accessible are those of the lexical environment of the selected\n\ 2711*5796c8dcSSimon Schubert stack frame, plus all those whose scope is global or an entire file.\n\ 2712*5796c8dcSSimon Schubert \n\ 2713*5796c8dcSSimon Schubert $NUM gets previous value number NUM. $ and $$ are the last two values.\n\ 2714*5796c8dcSSimon Schubert $$NUM refers to NUM'th value back from the last one.\n\ 2715*5796c8dcSSimon Schubert Names starting with $ refer to registers (with the values they would have\n\ 2716*5796c8dcSSimon Schubert if the program were to return to the stack frame now selected, restoring\n\ 2717*5796c8dcSSimon Schubert all registers saved by frames farther in) or else to debugger\n\ 2718*5796c8dcSSimon Schubert \"convenience\" variables (any such name not a known register).\n\ 2719*5796c8dcSSimon Schubert Use assignment expressions to give values to convenience variables.\n\ 2720*5796c8dcSSimon Schubert \n\ 2721*5796c8dcSSimon Schubert {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\ 2722*5796c8dcSSimon Schubert @ is a binary operator for treating consecutive data objects\n\ 2723*5796c8dcSSimon Schubert anywhere in memory as an array. FOO@NUM gives an array whose first\n\ 2724*5796c8dcSSimon Schubert element is FOO, whose second element is stored in the space following\n\ 2725*5796c8dcSSimon Schubert where FOO is stored, etc. FOO must be an expression whose value\n\ 2726*5796c8dcSSimon Schubert resides in memory.\n\ 2727*5796c8dcSSimon Schubert \n\ 2728*5796c8dcSSimon Schubert EXP may be preceded with /FMT, where FMT is a format letter\n\ 2729*5796c8dcSSimon Schubert but no count or size letter (see \"x\" command).")); 2730*5796c8dcSSimon Schubert set_cmd_completer (c, expression_completer); 2731*5796c8dcSSimon Schubert add_com_alias ("p", "print", class_vars, 1); 2732*5796c8dcSSimon Schubert 2733*5796c8dcSSimon Schubert c = add_com ("inspect", class_vars, inspect_command, _("\ 2734*5796c8dcSSimon Schubert Same as \"print\" command, except that if you are running in the epoch\n\ 2735*5796c8dcSSimon Schubert environment, the value is printed in its own window.")); 2736*5796c8dcSSimon Schubert set_cmd_completer (c, expression_completer); 2737*5796c8dcSSimon Schubert 2738*5796c8dcSSimon Schubert add_setshow_uinteger_cmd ("max-symbolic-offset", no_class, 2739*5796c8dcSSimon Schubert &max_symbolic_offset, _("\ 2740*5796c8dcSSimon Schubert Set the largest offset that will be printed in <symbol+1234> form."), _("\ 2741*5796c8dcSSimon Schubert Show the largest offset that will be printed in <symbol+1234> form."), NULL, 2742*5796c8dcSSimon Schubert NULL, 2743*5796c8dcSSimon Schubert show_max_symbolic_offset, 2744*5796c8dcSSimon Schubert &setprintlist, &showprintlist); 2745*5796c8dcSSimon Schubert add_setshow_boolean_cmd ("symbol-filename", no_class, 2746*5796c8dcSSimon Schubert &print_symbol_filename, _("\ 2747*5796c8dcSSimon Schubert Set printing of source filename and line number with <symbol>."), _("\ 2748*5796c8dcSSimon Schubert Show printing of source filename and line number with <symbol>."), NULL, 2749*5796c8dcSSimon Schubert NULL, 2750*5796c8dcSSimon Schubert show_print_symbol_filename, 2751*5796c8dcSSimon Schubert &setprintlist, &showprintlist); 2752*5796c8dcSSimon Schubert } 2753