15796c8dcSSimon Schubert /* Print values for GNU debugger GDB. 25796c8dcSSimon Schubert 35796c8dcSSimon Schubert Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 45796c8dcSSimon Schubert 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 5*cf7f2e2dSJohn Marino 2008, 2009, 2010 Free Software Foundation, Inc. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert This file is part of GDB. 85796c8dcSSimon Schubert 95796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 105796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 115796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 125796c8dcSSimon Schubert (at your option) any later version. 135796c8dcSSimon Schubert 145796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 155796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 165796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 175796c8dcSSimon Schubert GNU General Public License for more details. 185796c8dcSSimon Schubert 195796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 205796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 215796c8dcSSimon Schubert 225796c8dcSSimon Schubert #include "defs.h" 235796c8dcSSimon Schubert #include "gdb_string.h" 245796c8dcSSimon Schubert #include "frame.h" 255796c8dcSSimon Schubert #include "symtab.h" 265796c8dcSSimon Schubert #include "gdbtypes.h" 275796c8dcSSimon Schubert #include "value.h" 285796c8dcSSimon Schubert #include "language.h" 295796c8dcSSimon Schubert #include "expression.h" 305796c8dcSSimon Schubert #include "gdbcore.h" 315796c8dcSSimon Schubert #include "gdbcmd.h" 325796c8dcSSimon Schubert #include "target.h" 335796c8dcSSimon Schubert #include "breakpoint.h" 345796c8dcSSimon Schubert #include "demangle.h" 355796c8dcSSimon Schubert #include "valprint.h" 365796c8dcSSimon Schubert #include "annotate.h" 375796c8dcSSimon Schubert #include "symfile.h" /* for overlay functions */ 385796c8dcSSimon Schubert #include "objfiles.h" /* ditto */ 395796c8dcSSimon Schubert #include "completer.h" /* for completion functions */ 405796c8dcSSimon Schubert #include "ui-out.h" 415796c8dcSSimon Schubert #include "gdb_assert.h" 425796c8dcSSimon Schubert #include "block.h" 435796c8dcSSimon Schubert #include "disasm.h" 445796c8dcSSimon Schubert #include "dfp.h" 455796c8dcSSimon Schubert #include "valprint.h" 465796c8dcSSimon Schubert #include "exceptions.h" 475796c8dcSSimon Schubert #include "observer.h" 485796c8dcSSimon Schubert #include "solist.h" 495796c8dcSSimon Schubert #include "parser-defs.h" 505796c8dcSSimon Schubert #include "charset.h" 51*cf7f2e2dSJohn Marino #include "arch-utils.h" 525796c8dcSSimon Schubert 535796c8dcSSimon Schubert #ifdef TUI 545796c8dcSSimon Schubert #include "tui/tui.h" /* For tui_active et.al. */ 555796c8dcSSimon Schubert #endif 565796c8dcSSimon Schubert 575796c8dcSSimon Schubert #if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG) 585796c8dcSSimon Schubert # define USE_PRINTF_I64 1 595796c8dcSSimon Schubert # define PRINTF_HAS_LONG_LONG 605796c8dcSSimon Schubert #else 615796c8dcSSimon Schubert # define USE_PRINTF_I64 0 625796c8dcSSimon Schubert #endif 635796c8dcSSimon Schubert 645796c8dcSSimon Schubert extern int asm_demangle; /* Whether to demangle syms in asm printouts */ 655796c8dcSSimon Schubert 665796c8dcSSimon Schubert struct format_data 675796c8dcSSimon Schubert { 685796c8dcSSimon Schubert int count; 695796c8dcSSimon Schubert char format; 705796c8dcSSimon Schubert char size; 715796c8dcSSimon Schubert 725796c8dcSSimon Schubert /* True if the value should be printed raw -- that is, bypassing 735796c8dcSSimon Schubert python-based formatters. */ 745796c8dcSSimon Schubert unsigned char raw; 755796c8dcSSimon Schubert }; 765796c8dcSSimon Schubert 775796c8dcSSimon Schubert /* Last specified output format. */ 785796c8dcSSimon Schubert 795796c8dcSSimon Schubert static char last_format = 0; 805796c8dcSSimon Schubert 815796c8dcSSimon Schubert /* Last specified examination size. 'b', 'h', 'w' or `q'. */ 825796c8dcSSimon Schubert 835796c8dcSSimon Schubert static char last_size = 'w'; 845796c8dcSSimon Schubert 855796c8dcSSimon Schubert /* Default address to examine next, and associated architecture. */ 865796c8dcSSimon Schubert 875796c8dcSSimon Schubert static struct gdbarch *next_gdbarch; 885796c8dcSSimon Schubert static CORE_ADDR next_address; 895796c8dcSSimon Schubert 905796c8dcSSimon Schubert /* Number of delay instructions following current disassembled insn. */ 915796c8dcSSimon Schubert 925796c8dcSSimon Schubert static int branch_delay_insns; 935796c8dcSSimon Schubert 945796c8dcSSimon Schubert /* Last address examined. */ 955796c8dcSSimon Schubert 965796c8dcSSimon Schubert static CORE_ADDR last_examine_address; 975796c8dcSSimon Schubert 985796c8dcSSimon Schubert /* Contents of last address examined. 995796c8dcSSimon Schubert This is not valid past the end of the `x' command! */ 1005796c8dcSSimon Schubert 1015796c8dcSSimon Schubert static struct value *last_examine_value; 1025796c8dcSSimon Schubert 1035796c8dcSSimon Schubert /* Largest offset between a symbolic value and an address, that will be 1045796c8dcSSimon Schubert printed as `0x1234 <symbol+offset>'. */ 1055796c8dcSSimon Schubert 1065796c8dcSSimon Schubert static unsigned int max_symbolic_offset = UINT_MAX; 1075796c8dcSSimon Schubert static void 1085796c8dcSSimon Schubert show_max_symbolic_offset (struct ui_file *file, int from_tty, 1095796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1105796c8dcSSimon Schubert { 1115796c8dcSSimon Schubert fprintf_filtered (file, _("\ 1125796c8dcSSimon Schubert The largest offset that will be printed in <symbol+1234> form is %s.\n"), 1135796c8dcSSimon Schubert value); 1145796c8dcSSimon Schubert } 1155796c8dcSSimon Schubert 1165796c8dcSSimon Schubert /* Append the source filename and linenumber of the symbol when 1175796c8dcSSimon Schubert printing a symbolic value as `<symbol at filename:linenum>' if set. */ 1185796c8dcSSimon Schubert static int print_symbol_filename = 0; 1195796c8dcSSimon Schubert static void 1205796c8dcSSimon Schubert show_print_symbol_filename (struct ui_file *file, int from_tty, 1215796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1225796c8dcSSimon Schubert { 1235796c8dcSSimon Schubert fprintf_filtered (file, _("\ 1245796c8dcSSimon Schubert Printing of source filename and line number with <symbol> is %s.\n"), 1255796c8dcSSimon Schubert value); 1265796c8dcSSimon Schubert } 1275796c8dcSSimon Schubert 1285796c8dcSSimon Schubert /* Number of auto-display expression currently being displayed. 1295796c8dcSSimon Schubert So that we can disable it if we get an error or a signal within it. 1305796c8dcSSimon Schubert -1 when not doing one. */ 1315796c8dcSSimon Schubert 1325796c8dcSSimon Schubert int current_display_number; 1335796c8dcSSimon Schubert 1345796c8dcSSimon Schubert struct display 1355796c8dcSSimon Schubert { 1365796c8dcSSimon Schubert /* Chain link to next auto-display item. */ 1375796c8dcSSimon Schubert struct display *next; 138*cf7f2e2dSJohn Marino 1395796c8dcSSimon Schubert /* The expression as the user typed it. */ 1405796c8dcSSimon Schubert char *exp_string; 141*cf7f2e2dSJohn Marino 1425796c8dcSSimon Schubert /* Expression to be evaluated and displayed. */ 1435796c8dcSSimon Schubert struct expression *exp; 144*cf7f2e2dSJohn Marino 1455796c8dcSSimon Schubert /* Item number of this auto-display item. */ 1465796c8dcSSimon Schubert int number; 147*cf7f2e2dSJohn Marino 1485796c8dcSSimon Schubert /* Display format specified. */ 1495796c8dcSSimon Schubert struct format_data format; 150*cf7f2e2dSJohn Marino 151*cf7f2e2dSJohn Marino /* Program space associated with `block'. */ 152*cf7f2e2dSJohn Marino struct program_space *pspace; 153*cf7f2e2dSJohn Marino 1545796c8dcSSimon Schubert /* Innermost block required by this expression when evaluated */ 1555796c8dcSSimon Schubert struct block *block; 156*cf7f2e2dSJohn Marino 1575796c8dcSSimon Schubert /* Status of this display (enabled or disabled) */ 1585796c8dcSSimon Schubert int enabled_p; 1595796c8dcSSimon Schubert }; 1605796c8dcSSimon Schubert 1615796c8dcSSimon Schubert /* Chain of expressions whose values should be displayed 1625796c8dcSSimon Schubert automatically each time the program stops. */ 1635796c8dcSSimon Schubert 1645796c8dcSSimon Schubert static struct display *display_chain; 1655796c8dcSSimon Schubert 1665796c8dcSSimon Schubert static int display_number; 1675796c8dcSSimon Schubert 1685796c8dcSSimon Schubert /* Prototypes for exported functions. */ 1695796c8dcSSimon Schubert 1705796c8dcSSimon Schubert void output_command (char *, int); 1715796c8dcSSimon Schubert 1725796c8dcSSimon Schubert void _initialize_printcmd (void); 1735796c8dcSSimon Schubert 1745796c8dcSSimon Schubert /* Prototypes for local functions. */ 1755796c8dcSSimon Schubert 1765796c8dcSSimon Schubert static void do_one_display (struct display *); 1775796c8dcSSimon Schubert 1785796c8dcSSimon Schubert 1795796c8dcSSimon Schubert /* Decode a format specification. *STRING_PTR should point to it. 1805796c8dcSSimon Schubert OFORMAT and OSIZE are used as defaults for the format and size 1815796c8dcSSimon Schubert if none are given in the format specification. 1825796c8dcSSimon Schubert If OSIZE is zero, then the size field of the returned value 1835796c8dcSSimon Schubert should be set only if a size is explicitly specified by the 1845796c8dcSSimon Schubert user. 1855796c8dcSSimon Schubert The structure returned describes all the data 1865796c8dcSSimon Schubert found in the specification. In addition, *STRING_PTR is advanced 1875796c8dcSSimon Schubert past the specification and past all whitespace following it. */ 1885796c8dcSSimon Schubert 1895796c8dcSSimon Schubert static struct format_data 1905796c8dcSSimon Schubert decode_format (char **string_ptr, int oformat, int osize) 1915796c8dcSSimon Schubert { 1925796c8dcSSimon Schubert struct format_data val; 1935796c8dcSSimon Schubert char *p = *string_ptr; 1945796c8dcSSimon Schubert 1955796c8dcSSimon Schubert val.format = '?'; 1965796c8dcSSimon Schubert val.size = '?'; 1975796c8dcSSimon Schubert val.count = 1; 1985796c8dcSSimon Schubert val.raw = 0; 1995796c8dcSSimon Schubert 2005796c8dcSSimon Schubert if (*p >= '0' && *p <= '9') 2015796c8dcSSimon Schubert val.count = atoi (p); 2025796c8dcSSimon Schubert while (*p >= '0' && *p <= '9') 2035796c8dcSSimon Schubert p++; 2045796c8dcSSimon Schubert 2055796c8dcSSimon Schubert /* Now process size or format letters that follow. */ 2065796c8dcSSimon Schubert 2075796c8dcSSimon Schubert while (1) 2085796c8dcSSimon Schubert { 2095796c8dcSSimon Schubert if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g') 2105796c8dcSSimon Schubert val.size = *p++; 2115796c8dcSSimon Schubert else if (*p == 'r') 2125796c8dcSSimon Schubert { 2135796c8dcSSimon Schubert val.raw = 1; 2145796c8dcSSimon Schubert p++; 2155796c8dcSSimon Schubert } 2165796c8dcSSimon Schubert else if (*p >= 'a' && *p <= 'z') 2175796c8dcSSimon Schubert val.format = *p++; 2185796c8dcSSimon Schubert else 2195796c8dcSSimon Schubert break; 2205796c8dcSSimon Schubert } 2215796c8dcSSimon Schubert 2225796c8dcSSimon Schubert while (*p == ' ' || *p == '\t') 2235796c8dcSSimon Schubert p++; 2245796c8dcSSimon Schubert *string_ptr = p; 2255796c8dcSSimon Schubert 2265796c8dcSSimon Schubert /* Set defaults for format and size if not specified. */ 2275796c8dcSSimon Schubert if (val.format == '?') 2285796c8dcSSimon Schubert { 2295796c8dcSSimon Schubert if (val.size == '?') 2305796c8dcSSimon Schubert { 2315796c8dcSSimon Schubert /* Neither has been specified. */ 2325796c8dcSSimon Schubert val.format = oformat; 2335796c8dcSSimon Schubert val.size = osize; 2345796c8dcSSimon Schubert } 2355796c8dcSSimon Schubert else 2365796c8dcSSimon Schubert /* If a size is specified, any format makes a reasonable 2375796c8dcSSimon Schubert default except 'i'. */ 2385796c8dcSSimon Schubert val.format = oformat == 'i' ? 'x' : oformat; 2395796c8dcSSimon Schubert } 2405796c8dcSSimon Schubert else if (val.size == '?') 2415796c8dcSSimon Schubert switch (val.format) 2425796c8dcSSimon Schubert { 2435796c8dcSSimon Schubert case 'a': 2445796c8dcSSimon Schubert /* Pick the appropriate size for an address. This is deferred 2455796c8dcSSimon Schubert until do_examine when we know the actual architecture to use. 2465796c8dcSSimon Schubert A special size value of 'a' is used to indicate this case. */ 2475796c8dcSSimon Schubert val.size = osize ? 'a' : osize; 2485796c8dcSSimon Schubert break; 2495796c8dcSSimon Schubert case 'f': 2505796c8dcSSimon Schubert /* Floating point has to be word or giantword. */ 2515796c8dcSSimon Schubert if (osize == 'w' || osize == 'g') 2525796c8dcSSimon Schubert val.size = osize; 2535796c8dcSSimon Schubert else 2545796c8dcSSimon Schubert /* Default it to giantword if the last used size is not 2555796c8dcSSimon Schubert appropriate. */ 2565796c8dcSSimon Schubert val.size = osize ? 'g' : osize; 2575796c8dcSSimon Schubert break; 2585796c8dcSSimon Schubert case 'c': 2595796c8dcSSimon Schubert /* Characters default to one byte. */ 2605796c8dcSSimon Schubert val.size = osize ? 'b' : osize; 2615796c8dcSSimon Schubert break; 262*cf7f2e2dSJohn Marino case 's': 263*cf7f2e2dSJohn Marino /* Display strings with byte size chars unless explicitly specified. */ 264*cf7f2e2dSJohn Marino val.size = '\0'; 265*cf7f2e2dSJohn Marino break; 266*cf7f2e2dSJohn Marino 2675796c8dcSSimon Schubert default: 2685796c8dcSSimon Schubert /* The default is the size most recently specified. */ 2695796c8dcSSimon Schubert val.size = osize; 2705796c8dcSSimon Schubert } 2715796c8dcSSimon Schubert 2725796c8dcSSimon Schubert return val; 2735796c8dcSSimon Schubert } 2745796c8dcSSimon Schubert 2755796c8dcSSimon Schubert /* Print value VAL on stream according to OPTIONS. 2765796c8dcSSimon Schubert Do not end with a newline. 2775796c8dcSSimon Schubert SIZE is the letter for the size of datum being printed. 2785796c8dcSSimon Schubert This is used to pad hex numbers so they line up. SIZE is 0 2795796c8dcSSimon Schubert for print / output and set for examine. */ 2805796c8dcSSimon Schubert 2815796c8dcSSimon Schubert static void 2825796c8dcSSimon Schubert print_formatted (struct value *val, int size, 2835796c8dcSSimon Schubert const struct value_print_options *options, 2845796c8dcSSimon Schubert struct ui_file *stream) 2855796c8dcSSimon Schubert { 2865796c8dcSSimon Schubert struct type *type = check_typedef (value_type (val)); 2875796c8dcSSimon Schubert int len = TYPE_LENGTH (type); 2885796c8dcSSimon Schubert 2895796c8dcSSimon Schubert if (VALUE_LVAL (val) == lval_memory) 2905796c8dcSSimon Schubert next_address = value_address (val) + len; 2915796c8dcSSimon Schubert 2925796c8dcSSimon Schubert if (size) 2935796c8dcSSimon Schubert { 2945796c8dcSSimon Schubert switch (options->format) 2955796c8dcSSimon Schubert { 2965796c8dcSSimon Schubert case 's': 2975796c8dcSSimon Schubert { 2985796c8dcSSimon Schubert struct type *elttype = value_type (val); 299*cf7f2e2dSJohn Marino 3005796c8dcSSimon Schubert next_address = (value_address (val) 3015796c8dcSSimon Schubert + val_print_string (elttype, 3025796c8dcSSimon Schubert value_address (val), -1, 303*cf7f2e2dSJohn Marino stream, options) * len); 3045796c8dcSSimon Schubert } 3055796c8dcSSimon Schubert return; 3065796c8dcSSimon Schubert 3075796c8dcSSimon Schubert case 'i': 3085796c8dcSSimon Schubert /* We often wrap here if there are long symbolic names. */ 3095796c8dcSSimon Schubert wrap_here (" "); 3105796c8dcSSimon Schubert next_address = (value_address (val) 3115796c8dcSSimon Schubert + gdb_print_insn (get_type_arch (type), 3125796c8dcSSimon Schubert value_address (val), stream, 3135796c8dcSSimon Schubert &branch_delay_insns)); 3145796c8dcSSimon Schubert return; 3155796c8dcSSimon Schubert } 3165796c8dcSSimon Schubert } 3175796c8dcSSimon Schubert 3185796c8dcSSimon Schubert if (options->format == 0 || options->format == 's' 3195796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_REF 3205796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_ARRAY 3215796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_STRING 3225796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_STRUCT 3235796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_UNION 3245796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_NAMESPACE) 3255796c8dcSSimon Schubert value_print (val, stream, options); 3265796c8dcSSimon Schubert else 3275796c8dcSSimon Schubert /* User specified format, so don't look to the the type to 3285796c8dcSSimon Schubert tell us what to do. */ 3295796c8dcSSimon Schubert print_scalar_formatted (value_contents (val), type, 3305796c8dcSSimon Schubert options, size, stream); 3315796c8dcSSimon Schubert } 3325796c8dcSSimon Schubert 3335796c8dcSSimon Schubert /* Return builtin floating point type of same length as TYPE. 3345796c8dcSSimon Schubert If no such type is found, return TYPE itself. */ 3355796c8dcSSimon Schubert static struct type * 3365796c8dcSSimon Schubert float_type_from_length (struct type *type) 3375796c8dcSSimon Schubert { 3385796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (type); 3395796c8dcSSimon Schubert const struct builtin_type *builtin = builtin_type (gdbarch); 3405796c8dcSSimon Schubert unsigned int len = TYPE_LENGTH (type); 3415796c8dcSSimon Schubert 3425796c8dcSSimon Schubert if (len == TYPE_LENGTH (builtin->builtin_float)) 3435796c8dcSSimon Schubert type = builtin->builtin_float; 3445796c8dcSSimon Schubert else if (len == TYPE_LENGTH (builtin->builtin_double)) 3455796c8dcSSimon Schubert type = builtin->builtin_double; 3465796c8dcSSimon Schubert else if (len == TYPE_LENGTH (builtin->builtin_long_double)) 3475796c8dcSSimon Schubert type = builtin->builtin_long_double; 3485796c8dcSSimon Schubert 3495796c8dcSSimon Schubert return type; 3505796c8dcSSimon Schubert } 3515796c8dcSSimon Schubert 3525796c8dcSSimon Schubert /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR, 3535796c8dcSSimon Schubert according to OPTIONS and SIZE on STREAM. 3545796c8dcSSimon Schubert Formats s and i are not supported at this level. 3555796c8dcSSimon Schubert 3565796c8dcSSimon Schubert This is how the elements of an array or structure are printed 3575796c8dcSSimon Schubert with a format. */ 3585796c8dcSSimon Schubert 3595796c8dcSSimon Schubert void 3605796c8dcSSimon Schubert print_scalar_formatted (const void *valaddr, struct type *type, 3615796c8dcSSimon Schubert const struct value_print_options *options, 3625796c8dcSSimon Schubert int size, struct ui_file *stream) 3635796c8dcSSimon Schubert { 3645796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (type); 3655796c8dcSSimon Schubert LONGEST val_long = 0; 3665796c8dcSSimon Schubert unsigned int len = TYPE_LENGTH (type); 3675796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 3685796c8dcSSimon Schubert 3695796c8dcSSimon Schubert /* If we get here with a string format, try again without it. Go 3705796c8dcSSimon Schubert all the way back to the language printers, which may call us 3715796c8dcSSimon Schubert again. */ 3725796c8dcSSimon Schubert if (options->format == 's') 3735796c8dcSSimon Schubert { 3745796c8dcSSimon Schubert struct value_print_options opts = *options; 3755796c8dcSSimon Schubert opts.format = 0; 3765796c8dcSSimon Schubert opts.deref_ref = 0; 377*cf7f2e2dSJohn Marino val_print (type, valaddr, 0, 0, stream, 0, NULL, &opts, 3785796c8dcSSimon Schubert current_language); 3795796c8dcSSimon Schubert return; 3805796c8dcSSimon Schubert } 3815796c8dcSSimon Schubert 3825796c8dcSSimon Schubert if (len > sizeof(LONGEST) && 3835796c8dcSSimon Schubert (TYPE_CODE (type) == TYPE_CODE_INT 3845796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_ENUM)) 3855796c8dcSSimon Schubert { 3865796c8dcSSimon Schubert switch (options->format) 3875796c8dcSSimon Schubert { 3885796c8dcSSimon Schubert case 'o': 3895796c8dcSSimon Schubert print_octal_chars (stream, valaddr, len, byte_order); 3905796c8dcSSimon Schubert return; 3915796c8dcSSimon Schubert case 'u': 3925796c8dcSSimon Schubert case 'd': 3935796c8dcSSimon Schubert print_decimal_chars (stream, valaddr, len, byte_order); 3945796c8dcSSimon Schubert return; 3955796c8dcSSimon Schubert case 't': 3965796c8dcSSimon Schubert print_binary_chars (stream, valaddr, len, byte_order); 3975796c8dcSSimon Schubert return; 3985796c8dcSSimon Schubert case 'x': 3995796c8dcSSimon Schubert print_hex_chars (stream, valaddr, len, byte_order); 4005796c8dcSSimon Schubert return; 4015796c8dcSSimon Schubert case 'c': 4025796c8dcSSimon Schubert print_char_chars (stream, type, valaddr, len, byte_order); 4035796c8dcSSimon Schubert return; 4045796c8dcSSimon Schubert default: 4055796c8dcSSimon Schubert break; 4065796c8dcSSimon Schubert }; 4075796c8dcSSimon Schubert } 4085796c8dcSSimon Schubert 4095796c8dcSSimon Schubert if (options->format != 'f') 4105796c8dcSSimon Schubert val_long = unpack_long (type, valaddr); 4115796c8dcSSimon Schubert 4125796c8dcSSimon Schubert /* If the value is a pointer, and pointers and addresses are not the 4135796c8dcSSimon Schubert same, then at this point, the value's length (in target bytes) is 4145796c8dcSSimon Schubert gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */ 4155796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_PTR) 4165796c8dcSSimon Schubert len = gdbarch_addr_bit (gdbarch) / TARGET_CHAR_BIT; 4175796c8dcSSimon Schubert 4185796c8dcSSimon Schubert /* If we are printing it as unsigned, truncate it in case it is actually 4195796c8dcSSimon Schubert a negative signed value (e.g. "print/u (short)-1" should print 65535 4205796c8dcSSimon Schubert (if shorts are 16 bits) instead of 4294967295). */ 4215796c8dcSSimon Schubert if (options->format != 'd' || TYPE_UNSIGNED (type)) 4225796c8dcSSimon Schubert { 4235796c8dcSSimon Schubert if (len < sizeof (LONGEST)) 4245796c8dcSSimon Schubert val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1; 4255796c8dcSSimon Schubert } 4265796c8dcSSimon Schubert 4275796c8dcSSimon Schubert switch (options->format) 4285796c8dcSSimon Schubert { 4295796c8dcSSimon Schubert case 'x': 4305796c8dcSSimon Schubert if (!size) 4315796c8dcSSimon Schubert { 4325796c8dcSSimon Schubert /* No size specified, like in print. Print varying # of digits. */ 4335796c8dcSSimon Schubert print_longest (stream, 'x', 1, val_long); 4345796c8dcSSimon Schubert } 4355796c8dcSSimon Schubert else 4365796c8dcSSimon Schubert switch (size) 4375796c8dcSSimon Schubert { 4385796c8dcSSimon Schubert case 'b': 4395796c8dcSSimon Schubert case 'h': 4405796c8dcSSimon Schubert case 'w': 4415796c8dcSSimon Schubert case 'g': 4425796c8dcSSimon Schubert print_longest (stream, size, 1, val_long); 4435796c8dcSSimon Schubert break; 4445796c8dcSSimon Schubert default: 4455796c8dcSSimon Schubert error (_("Undefined output size \"%c\"."), size); 4465796c8dcSSimon Schubert } 4475796c8dcSSimon Schubert break; 4485796c8dcSSimon Schubert 4495796c8dcSSimon Schubert case 'd': 4505796c8dcSSimon Schubert print_longest (stream, 'd', 1, val_long); 4515796c8dcSSimon Schubert break; 4525796c8dcSSimon Schubert 4535796c8dcSSimon Schubert case 'u': 4545796c8dcSSimon Schubert print_longest (stream, 'u', 0, val_long); 4555796c8dcSSimon Schubert break; 4565796c8dcSSimon Schubert 4575796c8dcSSimon Schubert case 'o': 4585796c8dcSSimon Schubert if (val_long) 4595796c8dcSSimon Schubert print_longest (stream, 'o', 1, val_long); 4605796c8dcSSimon Schubert else 4615796c8dcSSimon Schubert fprintf_filtered (stream, "0"); 4625796c8dcSSimon Schubert break; 4635796c8dcSSimon Schubert 4645796c8dcSSimon Schubert case 'a': 4655796c8dcSSimon Schubert { 4665796c8dcSSimon Schubert CORE_ADDR addr = unpack_pointer (type, valaddr); 467*cf7f2e2dSJohn Marino 4685796c8dcSSimon Schubert print_address (gdbarch, addr, stream); 4695796c8dcSSimon Schubert } 4705796c8dcSSimon Schubert break; 4715796c8dcSSimon Schubert 4725796c8dcSSimon Schubert case 'c': 4735796c8dcSSimon Schubert { 4745796c8dcSSimon Schubert struct value_print_options opts = *options; 4755796c8dcSSimon Schubert 476*cf7f2e2dSJohn Marino opts.format = 0; 4775796c8dcSSimon Schubert if (TYPE_UNSIGNED (type)) 4785796c8dcSSimon Schubert type = builtin_type (gdbarch)->builtin_true_unsigned_char; 4795796c8dcSSimon Schubert else 4805796c8dcSSimon Schubert type = builtin_type (gdbarch)->builtin_true_char; 4815796c8dcSSimon Schubert 4825796c8dcSSimon Schubert value_print (value_from_longest (type, val_long), stream, &opts); 4835796c8dcSSimon Schubert } 4845796c8dcSSimon Schubert break; 4855796c8dcSSimon Schubert 4865796c8dcSSimon Schubert case 'f': 4875796c8dcSSimon Schubert type = float_type_from_length (type); 4885796c8dcSSimon Schubert print_floating (valaddr, type, stream); 4895796c8dcSSimon Schubert break; 4905796c8dcSSimon Schubert 4915796c8dcSSimon Schubert case 0: 4925796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 4935796c8dcSSimon Schubert _("failed internal consistency check")); 4945796c8dcSSimon Schubert 4955796c8dcSSimon Schubert case 't': 4965796c8dcSSimon Schubert /* Binary; 't' stands for "two". */ 4975796c8dcSSimon Schubert { 4985796c8dcSSimon Schubert char bits[8 * (sizeof val_long) + 1]; 4995796c8dcSSimon Schubert char buf[8 * (sizeof val_long) + 32]; 5005796c8dcSSimon Schubert char *cp = bits; 5015796c8dcSSimon Schubert int width; 5025796c8dcSSimon Schubert 5035796c8dcSSimon Schubert if (!size) 5045796c8dcSSimon Schubert width = 8 * (sizeof val_long); 5055796c8dcSSimon Schubert else 5065796c8dcSSimon Schubert switch (size) 5075796c8dcSSimon Schubert { 5085796c8dcSSimon Schubert case 'b': 5095796c8dcSSimon Schubert width = 8; 5105796c8dcSSimon Schubert break; 5115796c8dcSSimon Schubert case 'h': 5125796c8dcSSimon Schubert width = 16; 5135796c8dcSSimon Schubert break; 5145796c8dcSSimon Schubert case 'w': 5155796c8dcSSimon Schubert width = 32; 5165796c8dcSSimon Schubert break; 5175796c8dcSSimon Schubert case 'g': 5185796c8dcSSimon Schubert width = 64; 5195796c8dcSSimon Schubert break; 5205796c8dcSSimon Schubert default: 5215796c8dcSSimon Schubert error (_("Undefined output size \"%c\"."), size); 5225796c8dcSSimon Schubert } 5235796c8dcSSimon Schubert 5245796c8dcSSimon Schubert bits[width] = '\0'; 5255796c8dcSSimon Schubert while (width-- > 0) 5265796c8dcSSimon Schubert { 5275796c8dcSSimon Schubert bits[width] = (val_long & 1) ? '1' : '0'; 5285796c8dcSSimon Schubert val_long >>= 1; 5295796c8dcSSimon Schubert } 5305796c8dcSSimon Schubert if (!size) 5315796c8dcSSimon Schubert { 5325796c8dcSSimon Schubert while (*cp && *cp == '0') 5335796c8dcSSimon Schubert cp++; 5345796c8dcSSimon Schubert if (*cp == '\0') 5355796c8dcSSimon Schubert cp--; 5365796c8dcSSimon Schubert } 5375796c8dcSSimon Schubert strcpy (buf, cp); 5385796c8dcSSimon Schubert fputs_filtered (buf, stream); 5395796c8dcSSimon Schubert } 5405796c8dcSSimon Schubert break; 5415796c8dcSSimon Schubert 5425796c8dcSSimon Schubert default: 5435796c8dcSSimon Schubert error (_("Undefined output format \"%c\"."), options->format); 5445796c8dcSSimon Schubert } 5455796c8dcSSimon Schubert } 5465796c8dcSSimon Schubert 5475796c8dcSSimon Schubert /* Specify default address for `x' command. 5485796c8dcSSimon Schubert The `info lines' command uses this. */ 5495796c8dcSSimon Schubert 5505796c8dcSSimon Schubert void 5515796c8dcSSimon Schubert set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr) 5525796c8dcSSimon Schubert { 5535796c8dcSSimon Schubert struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr; 5545796c8dcSSimon Schubert 5555796c8dcSSimon Schubert next_gdbarch = gdbarch; 5565796c8dcSSimon Schubert next_address = addr; 5575796c8dcSSimon Schubert 5585796c8dcSSimon Schubert /* Make address available to the user as $_. */ 5595796c8dcSSimon Schubert set_internalvar (lookup_internalvar ("_"), 5605796c8dcSSimon Schubert value_from_pointer (ptr_type, addr)); 5615796c8dcSSimon Schubert } 5625796c8dcSSimon Schubert 5635796c8dcSSimon Schubert /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM, 5645796c8dcSSimon Schubert after LEADIN. Print nothing if no symbolic name is found nearby. 5655796c8dcSSimon Schubert Optionally also print source file and line number, if available. 5665796c8dcSSimon Schubert DO_DEMANGLE controls whether to print a symbol in its native "raw" form, 5675796c8dcSSimon Schubert or to interpret it as a possible C++ name and convert it back to source 5685796c8dcSSimon Schubert form. However note that DO_DEMANGLE can be overridden by the specific 5695796c8dcSSimon Schubert settings of the demangle and asm_demangle variables. */ 5705796c8dcSSimon Schubert 5715796c8dcSSimon Schubert void 572*cf7f2e2dSJohn Marino print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr, 573*cf7f2e2dSJohn Marino struct ui_file *stream, 5745796c8dcSSimon Schubert int do_demangle, char *leadin) 5755796c8dcSSimon Schubert { 5765796c8dcSSimon Schubert char *name = NULL; 5775796c8dcSSimon Schubert char *filename = NULL; 5785796c8dcSSimon Schubert int unmapped = 0; 5795796c8dcSSimon Schubert int offset = 0; 5805796c8dcSSimon Schubert int line = 0; 5815796c8dcSSimon Schubert 5825796c8dcSSimon Schubert /* Throw away both name and filename. */ 5835796c8dcSSimon Schubert struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name); 5845796c8dcSSimon Schubert make_cleanup (free_current_contents, &filename); 5855796c8dcSSimon Schubert 586*cf7f2e2dSJohn Marino if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &offset, 5875796c8dcSSimon Schubert &filename, &line, &unmapped)) 5885796c8dcSSimon Schubert { 5895796c8dcSSimon Schubert do_cleanups (cleanup_chain); 5905796c8dcSSimon Schubert return; 5915796c8dcSSimon Schubert } 5925796c8dcSSimon Schubert 5935796c8dcSSimon Schubert fputs_filtered (leadin, stream); 5945796c8dcSSimon Schubert if (unmapped) 5955796c8dcSSimon Schubert fputs_filtered ("<*", stream); 5965796c8dcSSimon Schubert else 5975796c8dcSSimon Schubert fputs_filtered ("<", stream); 5985796c8dcSSimon Schubert fputs_filtered (name, stream); 5995796c8dcSSimon Schubert if (offset != 0) 6005796c8dcSSimon Schubert fprintf_filtered (stream, "+%u", (unsigned int) offset); 6015796c8dcSSimon Schubert 6025796c8dcSSimon Schubert /* Append source filename and line number if desired. Give specific 6035796c8dcSSimon Schubert line # of this addr, if we have it; else line # of the nearest symbol. */ 6045796c8dcSSimon Schubert if (print_symbol_filename && filename != NULL) 6055796c8dcSSimon Schubert { 6065796c8dcSSimon Schubert if (line != -1) 6075796c8dcSSimon Schubert fprintf_filtered (stream, " at %s:%d", filename, line); 6085796c8dcSSimon Schubert else 6095796c8dcSSimon Schubert fprintf_filtered (stream, " in %s", filename); 6105796c8dcSSimon Schubert } 6115796c8dcSSimon Schubert if (unmapped) 6125796c8dcSSimon Schubert fputs_filtered ("*>", stream); 6135796c8dcSSimon Schubert else 6145796c8dcSSimon Schubert fputs_filtered (">", stream); 6155796c8dcSSimon Schubert 6165796c8dcSSimon Schubert do_cleanups (cleanup_chain); 6175796c8dcSSimon Schubert } 6185796c8dcSSimon Schubert 6195796c8dcSSimon Schubert /* Given an address ADDR return all the elements needed to print the 6205796c8dcSSimon Schubert address in a symbolic form. NAME can be mangled or not depending 6215796c8dcSSimon Schubert on DO_DEMANGLE (and also on the asm_demangle global variable, 6225796c8dcSSimon Schubert manipulated via ''set print asm-demangle''). Return 0 in case of 6235796c8dcSSimon Schubert success, when all the info in the OUT paramters is valid. Return 1 6245796c8dcSSimon Schubert otherwise. */ 6255796c8dcSSimon Schubert int 626*cf7f2e2dSJohn Marino build_address_symbolic (struct gdbarch *gdbarch, 627*cf7f2e2dSJohn Marino CORE_ADDR addr, /* IN */ 6285796c8dcSSimon Schubert int do_demangle, /* IN */ 6295796c8dcSSimon Schubert char **name, /* OUT */ 6305796c8dcSSimon Schubert int *offset, /* OUT */ 6315796c8dcSSimon Schubert char **filename, /* OUT */ 6325796c8dcSSimon Schubert int *line, /* OUT */ 6335796c8dcSSimon Schubert int *unmapped) /* OUT */ 6345796c8dcSSimon Schubert { 6355796c8dcSSimon Schubert struct minimal_symbol *msymbol; 6365796c8dcSSimon Schubert struct symbol *symbol; 6375796c8dcSSimon Schubert CORE_ADDR name_location = 0; 6385796c8dcSSimon Schubert struct obj_section *section = NULL; 6395796c8dcSSimon Schubert char *name_temp = ""; 6405796c8dcSSimon Schubert 6415796c8dcSSimon Schubert /* Let's say it is mapped (not unmapped). */ 6425796c8dcSSimon Schubert *unmapped = 0; 6435796c8dcSSimon Schubert 6445796c8dcSSimon Schubert /* Determine if the address is in an overlay, and whether it is 6455796c8dcSSimon Schubert mapped. */ 6465796c8dcSSimon Schubert if (overlay_debugging) 6475796c8dcSSimon Schubert { 6485796c8dcSSimon Schubert section = find_pc_overlay (addr); 6495796c8dcSSimon Schubert if (pc_in_unmapped_range (addr, section)) 6505796c8dcSSimon Schubert { 6515796c8dcSSimon Schubert *unmapped = 1; 6525796c8dcSSimon Schubert addr = overlay_mapped_address (addr, section); 6535796c8dcSSimon Schubert } 6545796c8dcSSimon Schubert } 6555796c8dcSSimon Schubert 6565796c8dcSSimon Schubert /* First try to find the address in the symbol table, then 6575796c8dcSSimon Schubert in the minsyms. Take the closest one. */ 6585796c8dcSSimon Schubert 6595796c8dcSSimon Schubert /* This is defective in the sense that it only finds text symbols. So 6605796c8dcSSimon Schubert really this is kind of pointless--we should make sure that the 6615796c8dcSSimon Schubert minimal symbols have everything we need (by changing that we could 6625796c8dcSSimon Schubert save some memory, but for many debug format--ELF/DWARF or 6635796c8dcSSimon Schubert anything/stabs--it would be inconvenient to eliminate those minimal 6645796c8dcSSimon Schubert symbols anyway). */ 6655796c8dcSSimon Schubert msymbol = lookup_minimal_symbol_by_pc_section (addr, section); 6665796c8dcSSimon Schubert symbol = find_pc_sect_function (addr, section); 6675796c8dcSSimon Schubert 6685796c8dcSSimon Schubert if (symbol) 6695796c8dcSSimon Schubert { 670*cf7f2e2dSJohn Marino /* If this is a function (i.e. a code address), strip out any 671*cf7f2e2dSJohn Marino non-address bits. For instance, display a pointer to the 672*cf7f2e2dSJohn Marino first instruction of a Thumb function as <function>; the 673*cf7f2e2dSJohn Marino second instruction will be <function+2>, even though the 674*cf7f2e2dSJohn Marino pointer is <function+3>. This matches the ISA behavior. */ 675*cf7f2e2dSJohn Marino addr = gdbarch_addr_bits_remove (gdbarch, addr); 676*cf7f2e2dSJohn Marino 6775796c8dcSSimon Schubert name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)); 6785796c8dcSSimon Schubert if (do_demangle || asm_demangle) 6795796c8dcSSimon Schubert name_temp = SYMBOL_PRINT_NAME (symbol); 6805796c8dcSSimon Schubert else 6815796c8dcSSimon Schubert name_temp = SYMBOL_LINKAGE_NAME (symbol); 6825796c8dcSSimon Schubert } 6835796c8dcSSimon Schubert 6845796c8dcSSimon Schubert if (msymbol != NULL) 6855796c8dcSSimon Schubert { 6865796c8dcSSimon Schubert if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL) 6875796c8dcSSimon Schubert { 6885796c8dcSSimon Schubert /* The msymbol is closer to the address than the symbol; 6895796c8dcSSimon Schubert use the msymbol instead. */ 6905796c8dcSSimon Schubert symbol = 0; 6915796c8dcSSimon Schubert name_location = SYMBOL_VALUE_ADDRESS (msymbol); 6925796c8dcSSimon Schubert if (do_demangle || asm_demangle) 6935796c8dcSSimon Schubert name_temp = SYMBOL_PRINT_NAME (msymbol); 6945796c8dcSSimon Schubert else 6955796c8dcSSimon Schubert name_temp = SYMBOL_LINKAGE_NAME (msymbol); 6965796c8dcSSimon Schubert } 6975796c8dcSSimon Schubert } 6985796c8dcSSimon Schubert if (symbol == NULL && msymbol == NULL) 6995796c8dcSSimon Schubert return 1; 7005796c8dcSSimon Schubert 7015796c8dcSSimon Schubert /* If the nearest symbol is too far away, don't print anything symbolic. */ 7025796c8dcSSimon Schubert 7035796c8dcSSimon Schubert /* For when CORE_ADDR is larger than unsigned int, we do math in 7045796c8dcSSimon Schubert CORE_ADDR. But when we detect unsigned wraparound in the 7055796c8dcSSimon Schubert CORE_ADDR math, we ignore this test and print the offset, 7065796c8dcSSimon Schubert because addr+max_symbolic_offset has wrapped through the end 7075796c8dcSSimon Schubert of the address space back to the beginning, giving bogus comparison. */ 7085796c8dcSSimon Schubert if (addr > name_location + max_symbolic_offset 7095796c8dcSSimon Schubert && name_location + max_symbolic_offset > name_location) 7105796c8dcSSimon Schubert return 1; 7115796c8dcSSimon Schubert 7125796c8dcSSimon Schubert *offset = addr - name_location; 7135796c8dcSSimon Schubert 7145796c8dcSSimon Schubert *name = xstrdup (name_temp); 7155796c8dcSSimon Schubert 7165796c8dcSSimon Schubert if (print_symbol_filename) 7175796c8dcSSimon Schubert { 7185796c8dcSSimon Schubert struct symtab_and_line sal; 7195796c8dcSSimon Schubert 7205796c8dcSSimon Schubert sal = find_pc_sect_line (addr, section, 0); 7215796c8dcSSimon Schubert 7225796c8dcSSimon Schubert if (sal.symtab) 7235796c8dcSSimon Schubert { 7245796c8dcSSimon Schubert *filename = xstrdup (sal.symtab->filename); 7255796c8dcSSimon Schubert *line = sal.line; 7265796c8dcSSimon Schubert } 7275796c8dcSSimon Schubert } 7285796c8dcSSimon Schubert return 0; 7295796c8dcSSimon Schubert } 7305796c8dcSSimon Schubert 7315796c8dcSSimon Schubert 7325796c8dcSSimon Schubert /* Print address ADDR symbolically on STREAM. 7335796c8dcSSimon Schubert First print it as a number. Then perhaps print 7345796c8dcSSimon Schubert <SYMBOL + OFFSET> after the number. */ 7355796c8dcSSimon Schubert 7365796c8dcSSimon Schubert void 7375796c8dcSSimon Schubert print_address (struct gdbarch *gdbarch, 7385796c8dcSSimon Schubert CORE_ADDR addr, struct ui_file *stream) 7395796c8dcSSimon Schubert { 7405796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, addr), stream); 741*cf7f2e2dSJohn Marino print_address_symbolic (gdbarch, addr, stream, asm_demangle, " "); 742*cf7f2e2dSJohn Marino } 743*cf7f2e2dSJohn Marino 744*cf7f2e2dSJohn Marino /* Return a prefix for instruction address: 745*cf7f2e2dSJohn Marino "=> " for current instruction, else " ". */ 746*cf7f2e2dSJohn Marino 747*cf7f2e2dSJohn Marino const char * 748*cf7f2e2dSJohn Marino pc_prefix (CORE_ADDR addr) 749*cf7f2e2dSJohn Marino { 750*cf7f2e2dSJohn Marino if (has_stack_frames ()) 751*cf7f2e2dSJohn Marino { 752*cf7f2e2dSJohn Marino struct frame_info *frame; 753*cf7f2e2dSJohn Marino CORE_ADDR pc; 754*cf7f2e2dSJohn Marino 755*cf7f2e2dSJohn Marino frame = get_selected_frame (NULL); 756*cf7f2e2dSJohn Marino pc = get_frame_pc (frame); 757*cf7f2e2dSJohn Marino 758*cf7f2e2dSJohn Marino if (pc == addr) 759*cf7f2e2dSJohn Marino return "=> "; 760*cf7f2e2dSJohn Marino } 761*cf7f2e2dSJohn Marino return " "; 7625796c8dcSSimon Schubert } 7635796c8dcSSimon Schubert 7645796c8dcSSimon Schubert /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE 7655796c8dcSSimon Schubert controls whether to print the symbolic name "raw" or demangled. 7665796c8dcSSimon Schubert Global setting "addressprint" controls whether to print hex address 7675796c8dcSSimon Schubert or not. */ 7685796c8dcSSimon Schubert 7695796c8dcSSimon Schubert void 7705796c8dcSSimon Schubert print_address_demangle (struct gdbarch *gdbarch, CORE_ADDR addr, 7715796c8dcSSimon Schubert struct ui_file *stream, int do_demangle) 7725796c8dcSSimon Schubert { 7735796c8dcSSimon Schubert struct value_print_options opts; 774*cf7f2e2dSJohn Marino 7755796c8dcSSimon Schubert get_user_print_options (&opts); 7765796c8dcSSimon Schubert if (addr == 0) 7775796c8dcSSimon Schubert { 7785796c8dcSSimon Schubert fprintf_filtered (stream, "0"); 7795796c8dcSSimon Schubert } 7805796c8dcSSimon Schubert else if (opts.addressprint) 7815796c8dcSSimon Schubert { 7825796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, addr), stream); 783*cf7f2e2dSJohn Marino print_address_symbolic (gdbarch, addr, stream, do_demangle, " "); 7845796c8dcSSimon Schubert } 7855796c8dcSSimon Schubert else 7865796c8dcSSimon Schubert { 787*cf7f2e2dSJohn Marino print_address_symbolic (gdbarch, addr, stream, do_demangle, ""); 7885796c8dcSSimon Schubert } 7895796c8dcSSimon Schubert } 7905796c8dcSSimon Schubert 7915796c8dcSSimon Schubert 7925796c8dcSSimon Schubert /* Examine data at address ADDR in format FMT. 7935796c8dcSSimon Schubert Fetch it from memory and print on gdb_stdout. */ 7945796c8dcSSimon Schubert 7955796c8dcSSimon Schubert static void 7965796c8dcSSimon Schubert do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr) 7975796c8dcSSimon Schubert { 7985796c8dcSSimon Schubert char format = 0; 7995796c8dcSSimon Schubert char size; 8005796c8dcSSimon Schubert int count = 1; 8015796c8dcSSimon Schubert struct type *val_type = NULL; 8025796c8dcSSimon Schubert int i; 8035796c8dcSSimon Schubert int maxelts; 8045796c8dcSSimon Schubert struct value_print_options opts; 8055796c8dcSSimon Schubert 8065796c8dcSSimon Schubert format = fmt.format; 8075796c8dcSSimon Schubert size = fmt.size; 8085796c8dcSSimon Schubert count = fmt.count; 8095796c8dcSSimon Schubert next_gdbarch = gdbarch; 8105796c8dcSSimon Schubert next_address = addr; 8115796c8dcSSimon Schubert 812*cf7f2e2dSJohn Marino /* Instruction format implies fetch single bytes 813*cf7f2e2dSJohn Marino regardless of the specified size. 814*cf7f2e2dSJohn Marino The case of strings is handled in decode_format, only explicit 815*cf7f2e2dSJohn Marino size operator are not changed to 'b'. */ 816*cf7f2e2dSJohn Marino if (format == 'i') 8175796c8dcSSimon Schubert size = 'b'; 8185796c8dcSSimon Schubert 8195796c8dcSSimon Schubert if (size == 'a') 8205796c8dcSSimon Schubert { 8215796c8dcSSimon Schubert /* Pick the appropriate size for an address. */ 8225796c8dcSSimon Schubert if (gdbarch_ptr_bit (next_gdbarch) == 64) 8235796c8dcSSimon Schubert size = 'g'; 8245796c8dcSSimon Schubert else if (gdbarch_ptr_bit (next_gdbarch) == 32) 8255796c8dcSSimon Schubert size = 'w'; 8265796c8dcSSimon Schubert else if (gdbarch_ptr_bit (next_gdbarch) == 16) 8275796c8dcSSimon Schubert size = 'h'; 8285796c8dcSSimon Schubert else 8295796c8dcSSimon Schubert /* Bad value for gdbarch_ptr_bit. */ 8305796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 8315796c8dcSSimon Schubert _("failed internal consistency check")); 8325796c8dcSSimon Schubert } 8335796c8dcSSimon Schubert 8345796c8dcSSimon Schubert if (size == 'b') 8355796c8dcSSimon Schubert val_type = builtin_type (next_gdbarch)->builtin_int8; 8365796c8dcSSimon Schubert else if (size == 'h') 8375796c8dcSSimon Schubert val_type = builtin_type (next_gdbarch)->builtin_int16; 8385796c8dcSSimon Schubert else if (size == 'w') 8395796c8dcSSimon Schubert val_type = builtin_type (next_gdbarch)->builtin_int32; 8405796c8dcSSimon Schubert else if (size == 'g') 8415796c8dcSSimon Schubert val_type = builtin_type (next_gdbarch)->builtin_int64; 8425796c8dcSSimon Schubert 843*cf7f2e2dSJohn Marino if (format == 's') 844*cf7f2e2dSJohn Marino { 845*cf7f2e2dSJohn Marino struct type *char_type = NULL; 846*cf7f2e2dSJohn Marino 847*cf7f2e2dSJohn Marino /* Search for "char16_t" or "char32_t" types or fall back to 8-bit char 848*cf7f2e2dSJohn Marino if type is not found. */ 849*cf7f2e2dSJohn Marino if (size == 'h') 850*cf7f2e2dSJohn Marino char_type = builtin_type (next_gdbarch)->builtin_char16; 851*cf7f2e2dSJohn Marino else if (size == 'w') 852*cf7f2e2dSJohn Marino char_type = builtin_type (next_gdbarch)->builtin_char32; 853*cf7f2e2dSJohn Marino if (char_type) 854*cf7f2e2dSJohn Marino val_type = char_type; 855*cf7f2e2dSJohn Marino else 856*cf7f2e2dSJohn Marino { 857*cf7f2e2dSJohn Marino if (size != '\0' && size != 'b') 858*cf7f2e2dSJohn Marino warning (_("Unable to display strings with size '%c', using 'b' \ 859*cf7f2e2dSJohn Marino instead."), size); 860*cf7f2e2dSJohn Marino size = 'b'; 861*cf7f2e2dSJohn Marino val_type = builtin_type (next_gdbarch)->builtin_int8; 862*cf7f2e2dSJohn Marino } 863*cf7f2e2dSJohn Marino } 864*cf7f2e2dSJohn Marino 8655796c8dcSSimon Schubert maxelts = 8; 8665796c8dcSSimon Schubert if (size == 'w') 8675796c8dcSSimon Schubert maxelts = 4; 8685796c8dcSSimon Schubert if (size == 'g') 8695796c8dcSSimon Schubert maxelts = 2; 8705796c8dcSSimon Schubert if (format == 's' || format == 'i') 8715796c8dcSSimon Schubert maxelts = 1; 8725796c8dcSSimon Schubert 8735796c8dcSSimon Schubert get_formatted_print_options (&opts, format); 8745796c8dcSSimon Schubert 8755796c8dcSSimon Schubert /* Print as many objects as specified in COUNT, at most maxelts per line, 8765796c8dcSSimon Schubert with the address of the next one at the start of each line. */ 8775796c8dcSSimon Schubert 8785796c8dcSSimon Schubert while (count > 0) 8795796c8dcSSimon Schubert { 8805796c8dcSSimon Schubert QUIT; 881*cf7f2e2dSJohn Marino if (format == 'i') 882*cf7f2e2dSJohn Marino fputs_filtered (pc_prefix (next_address), gdb_stdout); 8835796c8dcSSimon Schubert print_address (next_gdbarch, next_address, gdb_stdout); 8845796c8dcSSimon Schubert printf_filtered (":"); 8855796c8dcSSimon Schubert for (i = maxelts; 8865796c8dcSSimon Schubert i > 0 && count > 0; 8875796c8dcSSimon Schubert i--, count--) 8885796c8dcSSimon Schubert { 8895796c8dcSSimon Schubert printf_filtered ("\t"); 8905796c8dcSSimon Schubert /* Note that print_formatted sets next_address for the next 8915796c8dcSSimon Schubert object. */ 8925796c8dcSSimon Schubert last_examine_address = next_address; 8935796c8dcSSimon Schubert 8945796c8dcSSimon Schubert if (last_examine_value) 8955796c8dcSSimon Schubert value_free (last_examine_value); 8965796c8dcSSimon Schubert 8975796c8dcSSimon Schubert /* The value to be displayed is not fetched greedily. 8985796c8dcSSimon Schubert Instead, to avoid the possibility of a fetched value not 8995796c8dcSSimon Schubert being used, its retrieval is delayed until the print code 9005796c8dcSSimon Schubert uses it. When examining an instruction stream, the 9015796c8dcSSimon Schubert disassembler will perform its own memory fetch using just 9025796c8dcSSimon Schubert the address stored in LAST_EXAMINE_VALUE. FIXME: Should 9035796c8dcSSimon Schubert the disassembler be modified so that LAST_EXAMINE_VALUE 9045796c8dcSSimon Schubert is left with the byte sequence from the last complete 9055796c8dcSSimon Schubert instruction fetched from memory? */ 9065796c8dcSSimon Schubert last_examine_value = value_at_lazy (val_type, next_address); 9075796c8dcSSimon Schubert 9085796c8dcSSimon Schubert if (last_examine_value) 9095796c8dcSSimon Schubert release_value (last_examine_value); 9105796c8dcSSimon Schubert 9115796c8dcSSimon Schubert print_formatted (last_examine_value, size, &opts, gdb_stdout); 9125796c8dcSSimon Schubert 9135796c8dcSSimon Schubert /* Display any branch delay slots following the final insn. */ 9145796c8dcSSimon Schubert if (format == 'i' && count == 1) 9155796c8dcSSimon Schubert count += branch_delay_insns; 9165796c8dcSSimon Schubert } 9175796c8dcSSimon Schubert printf_filtered ("\n"); 9185796c8dcSSimon Schubert gdb_flush (gdb_stdout); 9195796c8dcSSimon Schubert } 9205796c8dcSSimon Schubert } 9215796c8dcSSimon Schubert 9225796c8dcSSimon Schubert static void 9235796c8dcSSimon Schubert validate_format (struct format_data fmt, char *cmdname) 9245796c8dcSSimon Schubert { 9255796c8dcSSimon Schubert if (fmt.size != 0) 9265796c8dcSSimon Schubert error (_("Size letters are meaningless in \"%s\" command."), cmdname); 9275796c8dcSSimon Schubert if (fmt.count != 1) 9285796c8dcSSimon Schubert error (_("Item count other than 1 is meaningless in \"%s\" command."), 9295796c8dcSSimon Schubert cmdname); 9305796c8dcSSimon Schubert if (fmt.format == 'i') 9315796c8dcSSimon Schubert error (_("Format letter \"%c\" is meaningless in \"%s\" command."), 9325796c8dcSSimon Schubert fmt.format, cmdname); 9335796c8dcSSimon Schubert } 9345796c8dcSSimon Schubert 9355796c8dcSSimon Schubert /* Evaluate string EXP as an expression in the current language and 9365796c8dcSSimon Schubert print the resulting value. EXP may contain a format specifier as the 9375796c8dcSSimon Schubert first argument ("/x myvar" for example, to print myvar in hex). */ 9385796c8dcSSimon Schubert 9395796c8dcSSimon Schubert static void 9405796c8dcSSimon Schubert print_command_1 (char *exp, int inspect, int voidprint) 9415796c8dcSSimon Schubert { 9425796c8dcSSimon Schubert struct expression *expr; 9435796c8dcSSimon Schubert struct cleanup *old_chain = 0; 9445796c8dcSSimon Schubert char format = 0; 9455796c8dcSSimon Schubert struct value *val; 9465796c8dcSSimon Schubert struct format_data fmt; 9475796c8dcSSimon Schubert int cleanup = 0; 9485796c8dcSSimon Schubert 9495796c8dcSSimon Schubert if (exp && *exp == '/') 9505796c8dcSSimon Schubert { 9515796c8dcSSimon Schubert exp++; 9525796c8dcSSimon Schubert fmt = decode_format (&exp, last_format, 0); 9535796c8dcSSimon Schubert validate_format (fmt, "print"); 9545796c8dcSSimon Schubert last_format = format = fmt.format; 9555796c8dcSSimon Schubert } 9565796c8dcSSimon Schubert else 9575796c8dcSSimon Schubert { 9585796c8dcSSimon Schubert fmt.count = 1; 9595796c8dcSSimon Schubert fmt.format = 0; 9605796c8dcSSimon Schubert fmt.size = 0; 9615796c8dcSSimon Schubert fmt.raw = 0; 9625796c8dcSSimon Schubert } 9635796c8dcSSimon Schubert 9645796c8dcSSimon Schubert if (exp && *exp) 9655796c8dcSSimon Schubert { 9665796c8dcSSimon Schubert expr = parse_expression (exp); 9675796c8dcSSimon Schubert old_chain = make_cleanup (free_current_contents, &expr); 9685796c8dcSSimon Schubert cleanup = 1; 9695796c8dcSSimon Schubert val = evaluate_expression (expr); 9705796c8dcSSimon Schubert } 9715796c8dcSSimon Schubert else 9725796c8dcSSimon Schubert val = access_value_history (0); 9735796c8dcSSimon Schubert 9745796c8dcSSimon Schubert if (voidprint || (val && value_type (val) && 9755796c8dcSSimon Schubert TYPE_CODE (value_type (val)) != TYPE_CODE_VOID)) 9765796c8dcSSimon Schubert { 9775796c8dcSSimon Schubert struct value_print_options opts; 9785796c8dcSSimon Schubert int histindex = record_latest_value (val); 9795796c8dcSSimon Schubert 9805796c8dcSSimon Schubert if (histindex >= 0) 9815796c8dcSSimon Schubert annotate_value_history_begin (histindex, value_type (val)); 9825796c8dcSSimon Schubert else 9835796c8dcSSimon Schubert annotate_value_begin (value_type (val)); 9845796c8dcSSimon Schubert 9855796c8dcSSimon Schubert if (inspect) 9865796c8dcSSimon Schubert printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", 9875796c8dcSSimon Schubert exp, histindex); 9885796c8dcSSimon Schubert else if (histindex >= 0) 9895796c8dcSSimon Schubert printf_filtered ("$%d = ", histindex); 9905796c8dcSSimon Schubert 9915796c8dcSSimon Schubert if (histindex >= 0) 9925796c8dcSSimon Schubert annotate_value_history_value (); 9935796c8dcSSimon Schubert 9945796c8dcSSimon Schubert get_formatted_print_options (&opts, format); 9955796c8dcSSimon Schubert opts.inspect_it = inspect; 9965796c8dcSSimon Schubert opts.raw = fmt.raw; 9975796c8dcSSimon Schubert 9985796c8dcSSimon Schubert print_formatted (val, fmt.size, &opts, gdb_stdout); 9995796c8dcSSimon Schubert printf_filtered ("\n"); 10005796c8dcSSimon Schubert 10015796c8dcSSimon Schubert if (histindex >= 0) 10025796c8dcSSimon Schubert annotate_value_history_end (); 10035796c8dcSSimon Schubert else 10045796c8dcSSimon Schubert annotate_value_end (); 10055796c8dcSSimon Schubert 10065796c8dcSSimon Schubert if (inspect) 10075796c8dcSSimon Schubert printf_unfiltered ("\") )\030"); 10085796c8dcSSimon Schubert } 10095796c8dcSSimon Schubert 10105796c8dcSSimon Schubert if (cleanup) 10115796c8dcSSimon Schubert do_cleanups (old_chain); 10125796c8dcSSimon Schubert } 10135796c8dcSSimon Schubert 10145796c8dcSSimon Schubert static void 10155796c8dcSSimon Schubert print_command (char *exp, int from_tty) 10165796c8dcSSimon Schubert { 10175796c8dcSSimon Schubert print_command_1 (exp, 0, 1); 10185796c8dcSSimon Schubert } 10195796c8dcSSimon Schubert 10205796c8dcSSimon Schubert /* Same as print, except in epoch, it gets its own window. */ 10215796c8dcSSimon Schubert static void 10225796c8dcSSimon Schubert inspect_command (char *exp, int from_tty) 10235796c8dcSSimon Schubert { 10245796c8dcSSimon Schubert extern int epoch_interface; 10255796c8dcSSimon Schubert 10265796c8dcSSimon Schubert print_command_1 (exp, epoch_interface, 1); 10275796c8dcSSimon Schubert } 10285796c8dcSSimon Schubert 10295796c8dcSSimon Schubert /* Same as print, except it doesn't print void results. */ 10305796c8dcSSimon Schubert static void 10315796c8dcSSimon Schubert call_command (char *exp, int from_tty) 10325796c8dcSSimon Schubert { 10335796c8dcSSimon Schubert print_command_1 (exp, 0, 0); 10345796c8dcSSimon Schubert } 10355796c8dcSSimon Schubert 10365796c8dcSSimon Schubert void 10375796c8dcSSimon Schubert output_command (char *exp, int from_tty) 10385796c8dcSSimon Schubert { 10395796c8dcSSimon Schubert struct expression *expr; 10405796c8dcSSimon Schubert struct cleanup *old_chain; 10415796c8dcSSimon Schubert char format = 0; 10425796c8dcSSimon Schubert struct value *val; 10435796c8dcSSimon Schubert struct format_data fmt; 10445796c8dcSSimon Schubert struct value_print_options opts; 10455796c8dcSSimon Schubert 10465796c8dcSSimon Schubert fmt.size = 0; 10475796c8dcSSimon Schubert fmt.raw = 0; 10485796c8dcSSimon Schubert 10495796c8dcSSimon Schubert if (exp && *exp == '/') 10505796c8dcSSimon Schubert { 10515796c8dcSSimon Schubert exp++; 10525796c8dcSSimon Schubert fmt = decode_format (&exp, 0, 0); 10535796c8dcSSimon Schubert validate_format (fmt, "output"); 10545796c8dcSSimon Schubert format = fmt.format; 10555796c8dcSSimon Schubert } 10565796c8dcSSimon Schubert 10575796c8dcSSimon Schubert expr = parse_expression (exp); 10585796c8dcSSimon Schubert old_chain = make_cleanup (free_current_contents, &expr); 10595796c8dcSSimon Schubert 10605796c8dcSSimon Schubert val = evaluate_expression (expr); 10615796c8dcSSimon Schubert 10625796c8dcSSimon Schubert annotate_value_begin (value_type (val)); 10635796c8dcSSimon Schubert 10645796c8dcSSimon Schubert get_formatted_print_options (&opts, format); 10655796c8dcSSimon Schubert opts.raw = fmt.raw; 10665796c8dcSSimon Schubert print_formatted (val, fmt.size, &opts, gdb_stdout); 10675796c8dcSSimon Schubert 10685796c8dcSSimon Schubert annotate_value_end (); 10695796c8dcSSimon Schubert 10705796c8dcSSimon Schubert wrap_here (""); 10715796c8dcSSimon Schubert gdb_flush (gdb_stdout); 10725796c8dcSSimon Schubert 10735796c8dcSSimon Schubert do_cleanups (old_chain); 10745796c8dcSSimon Schubert } 10755796c8dcSSimon Schubert 10765796c8dcSSimon Schubert static void 10775796c8dcSSimon Schubert set_command (char *exp, int from_tty) 10785796c8dcSSimon Schubert { 10795796c8dcSSimon Schubert struct expression *expr = parse_expression (exp); 10805796c8dcSSimon Schubert struct cleanup *old_chain = 10815796c8dcSSimon Schubert make_cleanup (free_current_contents, &expr); 1082*cf7f2e2dSJohn Marino 10835796c8dcSSimon Schubert evaluate_expression (expr); 10845796c8dcSSimon Schubert do_cleanups (old_chain); 10855796c8dcSSimon Schubert } 10865796c8dcSSimon Schubert 10875796c8dcSSimon Schubert static void 10885796c8dcSSimon Schubert sym_info (char *arg, int from_tty) 10895796c8dcSSimon Schubert { 10905796c8dcSSimon Schubert struct minimal_symbol *msymbol; 10915796c8dcSSimon Schubert struct objfile *objfile; 10925796c8dcSSimon Schubert struct obj_section *osect; 10935796c8dcSSimon Schubert CORE_ADDR addr, sect_addr; 10945796c8dcSSimon Schubert int matches = 0; 10955796c8dcSSimon Schubert unsigned int offset; 10965796c8dcSSimon Schubert 10975796c8dcSSimon Schubert if (!arg) 10985796c8dcSSimon Schubert error_no_arg (_("address")); 10995796c8dcSSimon Schubert 11005796c8dcSSimon Schubert addr = parse_and_eval_address (arg); 11015796c8dcSSimon Schubert ALL_OBJSECTIONS (objfile, osect) 11025796c8dcSSimon Schubert { 11035796c8dcSSimon Schubert /* Only process each object file once, even if there's a separate 11045796c8dcSSimon Schubert debug file. */ 11055796c8dcSSimon Schubert if (objfile->separate_debug_objfile_backlink) 11065796c8dcSSimon Schubert continue; 11075796c8dcSSimon Schubert 11085796c8dcSSimon Schubert sect_addr = overlay_mapped_address (addr, osect); 11095796c8dcSSimon Schubert 11105796c8dcSSimon Schubert if (obj_section_addr (osect) <= sect_addr 11115796c8dcSSimon Schubert && sect_addr < obj_section_endaddr (osect) 11125796c8dcSSimon Schubert && (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, osect))) 11135796c8dcSSimon Schubert { 11145796c8dcSSimon Schubert const char *obj_name, *mapped, *sec_name, *msym_name; 11155796c8dcSSimon Schubert char *loc_string; 11165796c8dcSSimon Schubert struct cleanup *old_chain; 11175796c8dcSSimon Schubert 11185796c8dcSSimon Schubert matches = 1; 11195796c8dcSSimon Schubert offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol); 11205796c8dcSSimon Schubert mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped"); 11215796c8dcSSimon Schubert sec_name = osect->the_bfd_section->name; 11225796c8dcSSimon Schubert msym_name = SYMBOL_PRINT_NAME (msymbol); 11235796c8dcSSimon Schubert 11245796c8dcSSimon Schubert /* Don't print the offset if it is zero. 11255796c8dcSSimon Schubert We assume there's no need to handle i18n of "sym + offset". */ 11265796c8dcSSimon Schubert if (offset) 11275796c8dcSSimon Schubert loc_string = xstrprintf ("%s + %u", msym_name, offset); 11285796c8dcSSimon Schubert else 11295796c8dcSSimon Schubert loc_string = xstrprintf ("%s", msym_name); 11305796c8dcSSimon Schubert 11315796c8dcSSimon Schubert /* Use a cleanup to free loc_string in case the user quits 11325796c8dcSSimon Schubert a pagination request inside printf_filtered. */ 11335796c8dcSSimon Schubert old_chain = make_cleanup (xfree, loc_string); 11345796c8dcSSimon Schubert 11355796c8dcSSimon Schubert gdb_assert (osect->objfile && osect->objfile->name); 11365796c8dcSSimon Schubert obj_name = osect->objfile->name; 11375796c8dcSSimon Schubert 11385796c8dcSSimon Schubert if (MULTI_OBJFILE_P ()) 11395796c8dcSSimon Schubert if (pc_in_unmapped_range (addr, osect)) 11405796c8dcSSimon Schubert if (section_is_overlay (osect)) 11415796c8dcSSimon Schubert printf_filtered (_("%s in load address range of " 11425796c8dcSSimon Schubert "%s overlay section %s of %s\n"), 11435796c8dcSSimon Schubert loc_string, mapped, sec_name, obj_name); 11445796c8dcSSimon Schubert else 11455796c8dcSSimon Schubert printf_filtered (_("%s in load address range of " 11465796c8dcSSimon Schubert "section %s of %s\n"), 11475796c8dcSSimon Schubert loc_string, sec_name, obj_name); 11485796c8dcSSimon Schubert else 11495796c8dcSSimon Schubert if (section_is_overlay (osect)) 11505796c8dcSSimon Schubert printf_filtered (_("%s in %s overlay section %s of %s\n"), 11515796c8dcSSimon Schubert loc_string, mapped, sec_name, obj_name); 11525796c8dcSSimon Schubert else 11535796c8dcSSimon Schubert printf_filtered (_("%s in section %s of %s\n"), 11545796c8dcSSimon Schubert loc_string, sec_name, obj_name); 11555796c8dcSSimon Schubert else 11565796c8dcSSimon Schubert if (pc_in_unmapped_range (addr, osect)) 11575796c8dcSSimon Schubert if (section_is_overlay (osect)) 11585796c8dcSSimon Schubert printf_filtered (_("%s in load address range of %s overlay " 11595796c8dcSSimon Schubert "section %s\n"), 11605796c8dcSSimon Schubert loc_string, mapped, sec_name); 11615796c8dcSSimon Schubert else 11625796c8dcSSimon Schubert printf_filtered (_("%s in load address range of section %s\n"), 11635796c8dcSSimon Schubert loc_string, sec_name); 11645796c8dcSSimon Schubert else 11655796c8dcSSimon Schubert if (section_is_overlay (osect)) 11665796c8dcSSimon Schubert printf_filtered (_("%s in %s overlay section %s\n"), 11675796c8dcSSimon Schubert loc_string, mapped, sec_name); 11685796c8dcSSimon Schubert else 11695796c8dcSSimon Schubert printf_filtered (_("%s in section %s\n"), 11705796c8dcSSimon Schubert loc_string, sec_name); 11715796c8dcSSimon Schubert 11725796c8dcSSimon Schubert do_cleanups (old_chain); 11735796c8dcSSimon Schubert } 11745796c8dcSSimon Schubert } 11755796c8dcSSimon Schubert if (matches == 0) 11765796c8dcSSimon Schubert printf_filtered (_("No symbol matches %s.\n"), arg); 11775796c8dcSSimon Schubert } 11785796c8dcSSimon Schubert 11795796c8dcSSimon Schubert static void 11805796c8dcSSimon Schubert address_info (char *exp, int from_tty) 11815796c8dcSSimon Schubert { 11825796c8dcSSimon Schubert struct gdbarch *gdbarch; 11835796c8dcSSimon Schubert int regno; 11845796c8dcSSimon Schubert struct symbol *sym; 11855796c8dcSSimon Schubert struct minimal_symbol *msymbol; 11865796c8dcSSimon Schubert long val; 11875796c8dcSSimon Schubert struct obj_section *section; 1188*cf7f2e2dSJohn Marino CORE_ADDR load_addr, context_pc = 0; 11895796c8dcSSimon Schubert int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero 11905796c8dcSSimon Schubert if exp is a field of `this'. */ 11915796c8dcSSimon Schubert 11925796c8dcSSimon Schubert if (exp == 0) 11935796c8dcSSimon Schubert error (_("Argument required.")); 11945796c8dcSSimon Schubert 1195*cf7f2e2dSJohn Marino sym = lookup_symbol (exp, get_selected_block (&context_pc), VAR_DOMAIN, 11965796c8dcSSimon Schubert &is_a_field_of_this); 11975796c8dcSSimon Schubert if (sym == NULL) 11985796c8dcSSimon Schubert { 11995796c8dcSSimon Schubert if (is_a_field_of_this) 12005796c8dcSSimon Schubert { 12015796c8dcSSimon Schubert printf_filtered ("Symbol \""); 12025796c8dcSSimon Schubert fprintf_symbol_filtered (gdb_stdout, exp, 12035796c8dcSSimon Schubert current_language->la_language, DMGL_ANSI); 12045796c8dcSSimon Schubert printf_filtered ("\" is a field of the local class variable "); 12055796c8dcSSimon Schubert if (current_language->la_language == language_objc) 12065796c8dcSSimon Schubert printf_filtered ("`self'\n"); /* ObjC equivalent of "this" */ 12075796c8dcSSimon Schubert else 12085796c8dcSSimon Schubert printf_filtered ("`this'\n"); 12095796c8dcSSimon Schubert return; 12105796c8dcSSimon Schubert } 12115796c8dcSSimon Schubert 12125796c8dcSSimon Schubert msymbol = lookup_minimal_symbol (exp, NULL, NULL); 12135796c8dcSSimon Schubert 12145796c8dcSSimon Schubert if (msymbol != NULL) 12155796c8dcSSimon Schubert { 12165796c8dcSSimon Schubert gdbarch = get_objfile_arch (msymbol_objfile (msymbol)); 12175796c8dcSSimon Schubert load_addr = SYMBOL_VALUE_ADDRESS (msymbol); 12185796c8dcSSimon Schubert 12195796c8dcSSimon Schubert printf_filtered ("Symbol \""); 12205796c8dcSSimon Schubert fprintf_symbol_filtered (gdb_stdout, exp, 12215796c8dcSSimon Schubert current_language->la_language, DMGL_ANSI); 12225796c8dcSSimon Schubert printf_filtered ("\" is at "); 12235796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 12245796c8dcSSimon Schubert printf_filtered (" in a file compiled without debugging"); 12255796c8dcSSimon Schubert section = SYMBOL_OBJ_SECTION (msymbol); 12265796c8dcSSimon Schubert if (section_is_overlay (section)) 12275796c8dcSSimon Schubert { 12285796c8dcSSimon Schubert load_addr = overlay_unmapped_address (load_addr, section); 12295796c8dcSSimon Schubert printf_filtered (",\n -- loaded at "); 12305796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 12315796c8dcSSimon Schubert printf_filtered (" in overlay section %s", 12325796c8dcSSimon Schubert section->the_bfd_section->name); 12335796c8dcSSimon Schubert } 12345796c8dcSSimon Schubert printf_filtered (".\n"); 12355796c8dcSSimon Schubert } 12365796c8dcSSimon Schubert else 12375796c8dcSSimon Schubert error (_("No symbol \"%s\" in current context."), exp); 12385796c8dcSSimon Schubert return; 12395796c8dcSSimon Schubert } 12405796c8dcSSimon Schubert 12415796c8dcSSimon Schubert printf_filtered ("Symbol \""); 12425796c8dcSSimon Schubert fprintf_symbol_filtered (gdb_stdout, SYMBOL_PRINT_NAME (sym), 12435796c8dcSSimon Schubert current_language->la_language, DMGL_ANSI); 12445796c8dcSSimon Schubert printf_filtered ("\" is "); 12455796c8dcSSimon Schubert val = SYMBOL_VALUE (sym); 12465796c8dcSSimon Schubert section = SYMBOL_OBJ_SECTION (sym); 12475796c8dcSSimon Schubert gdbarch = get_objfile_arch (SYMBOL_SYMTAB (sym)->objfile); 12485796c8dcSSimon Schubert 12495796c8dcSSimon Schubert switch (SYMBOL_CLASS (sym)) 12505796c8dcSSimon Schubert { 12515796c8dcSSimon Schubert case LOC_CONST: 12525796c8dcSSimon Schubert case LOC_CONST_BYTES: 12535796c8dcSSimon Schubert printf_filtered ("constant"); 12545796c8dcSSimon Schubert break; 12555796c8dcSSimon Schubert 12565796c8dcSSimon Schubert case LOC_LABEL: 12575796c8dcSSimon Schubert printf_filtered ("a label at address "); 12585796c8dcSSimon Schubert load_addr = SYMBOL_VALUE_ADDRESS (sym); 12595796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 12605796c8dcSSimon Schubert if (section_is_overlay (section)) 12615796c8dcSSimon Schubert { 12625796c8dcSSimon Schubert load_addr = overlay_unmapped_address (load_addr, section); 12635796c8dcSSimon Schubert printf_filtered (",\n -- loaded at "); 12645796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 12655796c8dcSSimon Schubert printf_filtered (" in overlay section %s", 12665796c8dcSSimon Schubert section->the_bfd_section->name); 12675796c8dcSSimon Schubert } 12685796c8dcSSimon Schubert break; 12695796c8dcSSimon Schubert 12705796c8dcSSimon Schubert case LOC_COMPUTED: 12715796c8dcSSimon Schubert /* FIXME: cagney/2004-01-26: It should be possible to 12725796c8dcSSimon Schubert unconditionally call the SYMBOL_COMPUTED_OPS method when available. 12735796c8dcSSimon Schubert Unfortunately DWARF 2 stores the frame-base (instead of the 12745796c8dcSSimon Schubert function) location in a function's symbol. Oops! For the 12755796c8dcSSimon Schubert moment enable this when/where applicable. */ 1276*cf7f2e2dSJohn Marino SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, context_pc, gdb_stdout); 12775796c8dcSSimon Schubert break; 12785796c8dcSSimon Schubert 12795796c8dcSSimon Schubert case LOC_REGISTER: 12805796c8dcSSimon Schubert /* GDBARCH is the architecture associated with the objfile the symbol 12815796c8dcSSimon Schubert is defined in; the target architecture may be different, and may 12825796c8dcSSimon Schubert provide additional registers. However, we do not know the target 12835796c8dcSSimon Schubert architecture at this point. We assume the objfile architecture 12845796c8dcSSimon Schubert will contain all the standard registers that occur in debug info 12855796c8dcSSimon Schubert in that objfile. */ 12865796c8dcSSimon Schubert regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); 12875796c8dcSSimon Schubert 12885796c8dcSSimon Schubert if (SYMBOL_IS_ARGUMENT (sym)) 12895796c8dcSSimon Schubert printf_filtered (_("an argument in register %s"), 12905796c8dcSSimon Schubert gdbarch_register_name (gdbarch, regno)); 12915796c8dcSSimon Schubert else 12925796c8dcSSimon Schubert printf_filtered (_("a variable in register %s"), 12935796c8dcSSimon Schubert gdbarch_register_name (gdbarch, regno)); 12945796c8dcSSimon Schubert break; 12955796c8dcSSimon Schubert 12965796c8dcSSimon Schubert case LOC_STATIC: 12975796c8dcSSimon Schubert printf_filtered (_("static storage at address ")); 12985796c8dcSSimon Schubert load_addr = SYMBOL_VALUE_ADDRESS (sym); 12995796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 13005796c8dcSSimon Schubert if (section_is_overlay (section)) 13015796c8dcSSimon Schubert { 13025796c8dcSSimon Schubert load_addr = overlay_unmapped_address (load_addr, section); 13035796c8dcSSimon Schubert printf_filtered (_(",\n -- loaded at ")); 13045796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 13055796c8dcSSimon Schubert printf_filtered (_(" in overlay section %s"), 13065796c8dcSSimon Schubert section->the_bfd_section->name); 13075796c8dcSSimon Schubert } 13085796c8dcSSimon Schubert break; 13095796c8dcSSimon Schubert 13105796c8dcSSimon Schubert case LOC_REGPARM_ADDR: 13115796c8dcSSimon Schubert /* Note comment at LOC_REGISTER. */ 13125796c8dcSSimon Schubert regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); 13135796c8dcSSimon Schubert printf_filtered (_("address of an argument in register %s"), 13145796c8dcSSimon Schubert gdbarch_register_name (gdbarch, regno)); 13155796c8dcSSimon Schubert break; 13165796c8dcSSimon Schubert 13175796c8dcSSimon Schubert case LOC_ARG: 13185796c8dcSSimon Schubert printf_filtered (_("an argument at offset %ld"), val); 13195796c8dcSSimon Schubert break; 13205796c8dcSSimon Schubert 13215796c8dcSSimon Schubert case LOC_LOCAL: 13225796c8dcSSimon Schubert printf_filtered (_("a local variable at frame offset %ld"), val); 13235796c8dcSSimon Schubert break; 13245796c8dcSSimon Schubert 13255796c8dcSSimon Schubert case LOC_REF_ARG: 13265796c8dcSSimon Schubert printf_filtered (_("a reference argument at offset %ld"), val); 13275796c8dcSSimon Schubert break; 13285796c8dcSSimon Schubert 13295796c8dcSSimon Schubert case LOC_TYPEDEF: 13305796c8dcSSimon Schubert printf_filtered (_("a typedef")); 13315796c8dcSSimon Schubert break; 13325796c8dcSSimon Schubert 13335796c8dcSSimon Schubert case LOC_BLOCK: 13345796c8dcSSimon Schubert printf_filtered (_("a function at address ")); 13355796c8dcSSimon Schubert load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); 13365796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 13375796c8dcSSimon Schubert if (section_is_overlay (section)) 13385796c8dcSSimon Schubert { 13395796c8dcSSimon Schubert load_addr = overlay_unmapped_address (load_addr, section); 13405796c8dcSSimon Schubert printf_filtered (_(",\n -- loaded at ")); 13415796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 13425796c8dcSSimon Schubert printf_filtered (_(" in overlay section %s"), 13435796c8dcSSimon Schubert section->the_bfd_section->name); 13445796c8dcSSimon Schubert } 13455796c8dcSSimon Schubert break; 13465796c8dcSSimon Schubert 13475796c8dcSSimon Schubert case LOC_UNRESOLVED: 13485796c8dcSSimon Schubert { 13495796c8dcSSimon Schubert struct minimal_symbol *msym; 13505796c8dcSSimon Schubert 13515796c8dcSSimon Schubert msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), NULL, NULL); 13525796c8dcSSimon Schubert if (msym == NULL) 13535796c8dcSSimon Schubert printf_filtered ("unresolved"); 13545796c8dcSSimon Schubert else 13555796c8dcSSimon Schubert { 13565796c8dcSSimon Schubert section = SYMBOL_OBJ_SECTION (msym); 13575796c8dcSSimon Schubert load_addr = SYMBOL_VALUE_ADDRESS (msym); 13585796c8dcSSimon Schubert 13595796c8dcSSimon Schubert if (section 13605796c8dcSSimon Schubert && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0) 13615796c8dcSSimon Schubert printf_filtered (_("a thread-local variable at offset %s " 13625796c8dcSSimon Schubert "in the thread-local storage for `%s'"), 13635796c8dcSSimon Schubert paddress (gdbarch, load_addr), 13645796c8dcSSimon Schubert section->objfile->name); 13655796c8dcSSimon Schubert else 13665796c8dcSSimon Schubert { 13675796c8dcSSimon Schubert printf_filtered (_("static storage at address ")); 13685796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 13695796c8dcSSimon Schubert if (section_is_overlay (section)) 13705796c8dcSSimon Schubert { 13715796c8dcSSimon Schubert load_addr = overlay_unmapped_address (load_addr, section); 13725796c8dcSSimon Schubert printf_filtered (_(",\n -- loaded at ")); 13735796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout); 13745796c8dcSSimon Schubert printf_filtered (_(" in overlay section %s"), 13755796c8dcSSimon Schubert section->the_bfd_section->name); 13765796c8dcSSimon Schubert } 13775796c8dcSSimon Schubert } 13785796c8dcSSimon Schubert } 13795796c8dcSSimon Schubert } 13805796c8dcSSimon Schubert break; 13815796c8dcSSimon Schubert 13825796c8dcSSimon Schubert case LOC_OPTIMIZED_OUT: 13835796c8dcSSimon Schubert printf_filtered (_("optimized out")); 13845796c8dcSSimon Schubert break; 13855796c8dcSSimon Schubert 13865796c8dcSSimon Schubert default: 13875796c8dcSSimon Schubert printf_filtered (_("of unknown (botched) type")); 13885796c8dcSSimon Schubert break; 13895796c8dcSSimon Schubert } 13905796c8dcSSimon Schubert printf_filtered (".\n"); 13915796c8dcSSimon Schubert } 13925796c8dcSSimon Schubert 13935796c8dcSSimon Schubert 13945796c8dcSSimon Schubert static void 13955796c8dcSSimon Schubert x_command (char *exp, int from_tty) 13965796c8dcSSimon Schubert { 13975796c8dcSSimon Schubert struct expression *expr; 13985796c8dcSSimon Schubert struct format_data fmt; 13995796c8dcSSimon Schubert struct cleanup *old_chain; 14005796c8dcSSimon Schubert struct value *val; 14015796c8dcSSimon Schubert 14025796c8dcSSimon Schubert fmt.format = last_format ? last_format : 'x'; 14035796c8dcSSimon Schubert fmt.size = last_size; 14045796c8dcSSimon Schubert fmt.count = 1; 14055796c8dcSSimon Schubert fmt.raw = 0; 14065796c8dcSSimon Schubert 14075796c8dcSSimon Schubert if (exp && *exp == '/') 14085796c8dcSSimon Schubert { 14095796c8dcSSimon Schubert exp++; 14105796c8dcSSimon Schubert fmt = decode_format (&exp, last_format, last_size); 14115796c8dcSSimon Schubert } 14125796c8dcSSimon Schubert 14135796c8dcSSimon Schubert /* If we have an expression, evaluate it and use it as the address. */ 14145796c8dcSSimon Schubert 14155796c8dcSSimon Schubert if (exp != 0 && *exp != 0) 14165796c8dcSSimon Schubert { 14175796c8dcSSimon Schubert expr = parse_expression (exp); 14185796c8dcSSimon Schubert /* Cause expression not to be there any more if this command is 14195796c8dcSSimon Schubert repeated with Newline. But don't clobber a user-defined 14205796c8dcSSimon Schubert command's definition. */ 14215796c8dcSSimon Schubert if (from_tty) 14225796c8dcSSimon Schubert *exp = 0; 14235796c8dcSSimon Schubert old_chain = make_cleanup (free_current_contents, &expr); 14245796c8dcSSimon Schubert val = evaluate_expression (expr); 14255796c8dcSSimon Schubert if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF) 1426*cf7f2e2dSJohn Marino val = coerce_ref (val); 14275796c8dcSSimon Schubert /* In rvalue contexts, such as this, functions are coerced into 14285796c8dcSSimon Schubert pointers to functions. This makes "x/i main" work. */ 14295796c8dcSSimon Schubert if (/* last_format == 'i' && */ 14305796c8dcSSimon Schubert TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC 14315796c8dcSSimon Schubert && VALUE_LVAL (val) == lval_memory) 14325796c8dcSSimon Schubert next_address = value_address (val); 14335796c8dcSSimon Schubert else 14345796c8dcSSimon Schubert next_address = value_as_address (val); 14355796c8dcSSimon Schubert 14365796c8dcSSimon Schubert next_gdbarch = expr->gdbarch; 14375796c8dcSSimon Schubert do_cleanups (old_chain); 14385796c8dcSSimon Schubert } 14395796c8dcSSimon Schubert 14405796c8dcSSimon Schubert if (!next_gdbarch) 14415796c8dcSSimon Schubert error_no_arg (_("starting display address")); 14425796c8dcSSimon Schubert 14435796c8dcSSimon Schubert do_examine (fmt, next_gdbarch, next_address); 14445796c8dcSSimon Schubert 14455796c8dcSSimon Schubert /* If the examine succeeds, we remember its size and format for next 1446*cf7f2e2dSJohn Marino time. Set last_size to 'b' for strings. */ 1447*cf7f2e2dSJohn Marino if (fmt.format == 's') 1448*cf7f2e2dSJohn Marino last_size = 'b'; 1449*cf7f2e2dSJohn Marino else 14505796c8dcSSimon Schubert last_size = fmt.size; 14515796c8dcSSimon Schubert last_format = fmt.format; 14525796c8dcSSimon Schubert 14535796c8dcSSimon Schubert /* Set a couple of internal variables if appropriate. */ 14545796c8dcSSimon Schubert if (last_examine_value) 14555796c8dcSSimon Schubert { 14565796c8dcSSimon Schubert /* Make last address examined available to the user as $_. Use 14575796c8dcSSimon Schubert the correct pointer type. */ 14585796c8dcSSimon Schubert struct type *pointer_type 14595796c8dcSSimon Schubert = lookup_pointer_type (value_type (last_examine_value)); 14605796c8dcSSimon Schubert set_internalvar (lookup_internalvar ("_"), 14615796c8dcSSimon Schubert value_from_pointer (pointer_type, 14625796c8dcSSimon Schubert last_examine_address)); 14635796c8dcSSimon Schubert 14645796c8dcSSimon Schubert /* Make contents of last address examined available to the user 14655796c8dcSSimon Schubert as $__. If the last value has not been fetched from memory 14665796c8dcSSimon Schubert then don't fetch it now; instead mark it by voiding the $__ 14675796c8dcSSimon Schubert variable. */ 14685796c8dcSSimon Schubert if (value_lazy (last_examine_value)) 14695796c8dcSSimon Schubert clear_internalvar (lookup_internalvar ("__")); 14705796c8dcSSimon Schubert else 14715796c8dcSSimon Schubert set_internalvar (lookup_internalvar ("__"), last_examine_value); 14725796c8dcSSimon Schubert } 14735796c8dcSSimon Schubert } 14745796c8dcSSimon Schubert 14755796c8dcSSimon Schubert 14765796c8dcSSimon Schubert /* Add an expression to the auto-display chain. 14775796c8dcSSimon Schubert Specify the expression. */ 14785796c8dcSSimon Schubert 14795796c8dcSSimon Schubert static void 14805796c8dcSSimon Schubert display_command (char *exp, int from_tty) 14815796c8dcSSimon Schubert { 14825796c8dcSSimon Schubert struct format_data fmt; 14835796c8dcSSimon Schubert struct expression *expr; 14845796c8dcSSimon Schubert struct display *new; 14855796c8dcSSimon Schubert int display_it = 1; 14865796c8dcSSimon Schubert 14875796c8dcSSimon Schubert #if defined(TUI) 14885796c8dcSSimon Schubert /* NOTE: cagney/2003-02-13 The `tui_active' was previously 14895796c8dcSSimon Schubert `tui_version'. */ 14905796c8dcSSimon Schubert if (tui_active && exp != NULL && *exp == '$') 14915796c8dcSSimon Schubert display_it = (tui_set_layout_for_display_command (exp) == TUI_FAILURE); 14925796c8dcSSimon Schubert #endif 14935796c8dcSSimon Schubert 14945796c8dcSSimon Schubert if (display_it) 14955796c8dcSSimon Schubert { 14965796c8dcSSimon Schubert if (exp == 0) 14975796c8dcSSimon Schubert { 14985796c8dcSSimon Schubert do_displays (); 14995796c8dcSSimon Schubert return; 15005796c8dcSSimon Schubert } 15015796c8dcSSimon Schubert 15025796c8dcSSimon Schubert if (*exp == '/') 15035796c8dcSSimon Schubert { 15045796c8dcSSimon Schubert exp++; 15055796c8dcSSimon Schubert fmt = decode_format (&exp, 0, 0); 15065796c8dcSSimon Schubert if (fmt.size && fmt.format == 0) 15075796c8dcSSimon Schubert fmt.format = 'x'; 15085796c8dcSSimon Schubert if (fmt.format == 'i' || fmt.format == 's') 15095796c8dcSSimon Schubert fmt.size = 'b'; 15105796c8dcSSimon Schubert } 15115796c8dcSSimon Schubert else 15125796c8dcSSimon Schubert { 15135796c8dcSSimon Schubert fmt.format = 0; 15145796c8dcSSimon Schubert fmt.size = 0; 15155796c8dcSSimon Schubert fmt.count = 0; 15165796c8dcSSimon Schubert fmt.raw = 0; 15175796c8dcSSimon Schubert } 15185796c8dcSSimon Schubert 15195796c8dcSSimon Schubert innermost_block = NULL; 15205796c8dcSSimon Schubert expr = parse_expression (exp); 15215796c8dcSSimon Schubert 15225796c8dcSSimon Schubert new = (struct display *) xmalloc (sizeof (struct display)); 15235796c8dcSSimon Schubert 15245796c8dcSSimon Schubert new->exp_string = xstrdup (exp); 15255796c8dcSSimon Schubert new->exp = expr; 15265796c8dcSSimon Schubert new->block = innermost_block; 1527*cf7f2e2dSJohn Marino new->pspace = current_program_space; 15285796c8dcSSimon Schubert new->next = display_chain; 15295796c8dcSSimon Schubert new->number = ++display_number; 15305796c8dcSSimon Schubert new->format = fmt; 15315796c8dcSSimon Schubert new->enabled_p = 1; 15325796c8dcSSimon Schubert display_chain = new; 15335796c8dcSSimon Schubert 15345796c8dcSSimon Schubert if (from_tty && target_has_execution) 15355796c8dcSSimon Schubert do_one_display (new); 15365796c8dcSSimon Schubert 15375796c8dcSSimon Schubert dont_repeat (); 15385796c8dcSSimon Schubert } 15395796c8dcSSimon Schubert } 15405796c8dcSSimon Schubert 15415796c8dcSSimon Schubert static void 15425796c8dcSSimon Schubert free_display (struct display *d) 15435796c8dcSSimon Schubert { 15445796c8dcSSimon Schubert xfree (d->exp_string); 15455796c8dcSSimon Schubert xfree (d->exp); 15465796c8dcSSimon Schubert xfree (d); 15475796c8dcSSimon Schubert } 15485796c8dcSSimon Schubert 15495796c8dcSSimon Schubert /* Clear out the display_chain. Done when new symtabs are loaded, 15505796c8dcSSimon Schubert since this invalidates the types stored in many expressions. */ 15515796c8dcSSimon Schubert 15525796c8dcSSimon Schubert void 15535796c8dcSSimon Schubert clear_displays (void) 15545796c8dcSSimon Schubert { 15555796c8dcSSimon Schubert struct display *d; 15565796c8dcSSimon Schubert 15575796c8dcSSimon Schubert while ((d = display_chain) != NULL) 15585796c8dcSSimon Schubert { 15595796c8dcSSimon Schubert display_chain = d->next; 15605796c8dcSSimon Schubert free_display (d); 15615796c8dcSSimon Schubert } 15625796c8dcSSimon Schubert } 15635796c8dcSSimon Schubert 15645796c8dcSSimon Schubert /* Delete the auto-display number NUM. */ 15655796c8dcSSimon Schubert 15665796c8dcSSimon Schubert static void 15675796c8dcSSimon Schubert delete_display (int num) 15685796c8dcSSimon Schubert { 15695796c8dcSSimon Schubert struct display *d1, *d; 15705796c8dcSSimon Schubert 15715796c8dcSSimon Schubert if (!display_chain) 15725796c8dcSSimon Schubert error (_("No display number %d."), num); 15735796c8dcSSimon Schubert 15745796c8dcSSimon Schubert if (display_chain->number == num) 15755796c8dcSSimon Schubert { 15765796c8dcSSimon Schubert d1 = display_chain; 15775796c8dcSSimon Schubert display_chain = d1->next; 15785796c8dcSSimon Schubert free_display (d1); 15795796c8dcSSimon Schubert } 15805796c8dcSSimon Schubert else 15815796c8dcSSimon Schubert for (d = display_chain;; d = d->next) 15825796c8dcSSimon Schubert { 15835796c8dcSSimon Schubert if (d->next == 0) 15845796c8dcSSimon Schubert error (_("No display number %d."), num); 15855796c8dcSSimon Schubert if (d->next->number == num) 15865796c8dcSSimon Schubert { 15875796c8dcSSimon Schubert d1 = d->next; 15885796c8dcSSimon Schubert d->next = d1->next; 15895796c8dcSSimon Schubert free_display (d1); 15905796c8dcSSimon Schubert break; 15915796c8dcSSimon Schubert } 15925796c8dcSSimon Schubert } 15935796c8dcSSimon Schubert } 15945796c8dcSSimon Schubert 15955796c8dcSSimon Schubert /* Delete some values from the auto-display chain. 15965796c8dcSSimon Schubert Specify the element numbers. */ 15975796c8dcSSimon Schubert 15985796c8dcSSimon Schubert static void 15995796c8dcSSimon Schubert undisplay_command (char *args, int from_tty) 16005796c8dcSSimon Schubert { 16015796c8dcSSimon Schubert char *p = args; 16025796c8dcSSimon Schubert char *p1; 16035796c8dcSSimon Schubert int num; 16045796c8dcSSimon Schubert 16055796c8dcSSimon Schubert if (args == 0) 16065796c8dcSSimon Schubert { 16075796c8dcSSimon Schubert if (query (_("Delete all auto-display expressions? "))) 16085796c8dcSSimon Schubert clear_displays (); 16095796c8dcSSimon Schubert dont_repeat (); 16105796c8dcSSimon Schubert return; 16115796c8dcSSimon Schubert } 16125796c8dcSSimon Schubert 16135796c8dcSSimon Schubert while (*p) 16145796c8dcSSimon Schubert { 16155796c8dcSSimon Schubert p1 = p; 16165796c8dcSSimon Schubert while (*p1 >= '0' && *p1 <= '9') 16175796c8dcSSimon Schubert p1++; 16185796c8dcSSimon Schubert if (*p1 && *p1 != ' ' && *p1 != '\t') 16195796c8dcSSimon Schubert error (_("Arguments must be display numbers.")); 16205796c8dcSSimon Schubert 16215796c8dcSSimon Schubert num = atoi (p); 16225796c8dcSSimon Schubert 16235796c8dcSSimon Schubert delete_display (num); 16245796c8dcSSimon Schubert 16255796c8dcSSimon Schubert p = p1; 16265796c8dcSSimon Schubert while (*p == ' ' || *p == '\t') 16275796c8dcSSimon Schubert p++; 16285796c8dcSSimon Schubert } 16295796c8dcSSimon Schubert dont_repeat (); 16305796c8dcSSimon Schubert } 16315796c8dcSSimon Schubert 16325796c8dcSSimon Schubert /* Display a single auto-display. 16335796c8dcSSimon Schubert Do nothing if the display cannot be printed in the current context, 16345796c8dcSSimon Schubert or if the display is disabled. */ 16355796c8dcSSimon Schubert 16365796c8dcSSimon Schubert static void 16375796c8dcSSimon Schubert do_one_display (struct display *d) 16385796c8dcSSimon Schubert { 16395796c8dcSSimon Schubert int within_current_scope; 16405796c8dcSSimon Schubert 16415796c8dcSSimon Schubert if (d->enabled_p == 0) 16425796c8dcSSimon Schubert return; 16435796c8dcSSimon Schubert 1644*cf7f2e2dSJohn Marino /* The expression carries the architecture that was used at parse time. 1645*cf7f2e2dSJohn Marino This is a problem if the expression depends on architecture features 1646*cf7f2e2dSJohn Marino (e.g. register numbers), and the current architecture is now different. 1647*cf7f2e2dSJohn Marino For example, a display statement like "display/i $pc" is expected to 1648*cf7f2e2dSJohn Marino display the PC register of the current architecture, not the arch at 1649*cf7f2e2dSJohn Marino the time the display command was given. Therefore, we re-parse the 1650*cf7f2e2dSJohn Marino expression if the current architecture has changed. */ 1651*cf7f2e2dSJohn Marino if (d->exp != NULL && d->exp->gdbarch != get_current_arch ()) 1652*cf7f2e2dSJohn Marino { 1653*cf7f2e2dSJohn Marino xfree (d->exp); 1654*cf7f2e2dSJohn Marino d->exp = NULL; 1655*cf7f2e2dSJohn Marino d->block = NULL; 1656*cf7f2e2dSJohn Marino } 1657*cf7f2e2dSJohn Marino 16585796c8dcSSimon Schubert if (d->exp == NULL) 16595796c8dcSSimon Schubert { 16605796c8dcSSimon Schubert volatile struct gdb_exception ex; 1661*cf7f2e2dSJohn Marino 16625796c8dcSSimon Schubert TRY_CATCH (ex, RETURN_MASK_ALL) 16635796c8dcSSimon Schubert { 16645796c8dcSSimon Schubert innermost_block = NULL; 16655796c8dcSSimon Schubert d->exp = parse_expression (d->exp_string); 16665796c8dcSSimon Schubert d->block = innermost_block; 16675796c8dcSSimon Schubert } 16685796c8dcSSimon Schubert if (ex.reason < 0) 16695796c8dcSSimon Schubert { 16705796c8dcSSimon Schubert /* Can't re-parse the expression. Disable this display item. */ 16715796c8dcSSimon Schubert d->enabled_p = 0; 16725796c8dcSSimon Schubert warning (_("Unable to display \"%s\": %s"), 16735796c8dcSSimon Schubert d->exp_string, ex.message); 16745796c8dcSSimon Schubert return; 16755796c8dcSSimon Schubert } 16765796c8dcSSimon Schubert } 16775796c8dcSSimon Schubert 16785796c8dcSSimon Schubert if (d->block) 1679*cf7f2e2dSJohn Marino { 1680*cf7f2e2dSJohn Marino if (d->pspace == current_program_space) 16815796c8dcSSimon Schubert within_current_scope = contained_in (get_selected_block (0), d->block); 16825796c8dcSSimon Schubert else 1683*cf7f2e2dSJohn Marino within_current_scope = 0; 1684*cf7f2e2dSJohn Marino } 1685*cf7f2e2dSJohn Marino else 16865796c8dcSSimon Schubert within_current_scope = 1; 16875796c8dcSSimon Schubert if (!within_current_scope) 16885796c8dcSSimon Schubert return; 16895796c8dcSSimon Schubert 16905796c8dcSSimon Schubert current_display_number = d->number; 16915796c8dcSSimon Schubert 16925796c8dcSSimon Schubert annotate_display_begin (); 16935796c8dcSSimon Schubert printf_filtered ("%d", d->number); 16945796c8dcSSimon Schubert annotate_display_number_end (); 16955796c8dcSSimon Schubert printf_filtered (": "); 16965796c8dcSSimon Schubert if (d->format.size) 16975796c8dcSSimon Schubert { 16985796c8dcSSimon Schubert CORE_ADDR addr; 16995796c8dcSSimon Schubert struct value *val; 17005796c8dcSSimon Schubert 17015796c8dcSSimon Schubert annotate_display_format (); 17025796c8dcSSimon Schubert 17035796c8dcSSimon Schubert printf_filtered ("x/"); 17045796c8dcSSimon Schubert if (d->format.count != 1) 17055796c8dcSSimon Schubert printf_filtered ("%d", d->format.count); 17065796c8dcSSimon Schubert printf_filtered ("%c", d->format.format); 17075796c8dcSSimon Schubert if (d->format.format != 'i' && d->format.format != 's') 17085796c8dcSSimon Schubert printf_filtered ("%c", d->format.size); 17095796c8dcSSimon Schubert printf_filtered (" "); 17105796c8dcSSimon Schubert 17115796c8dcSSimon Schubert annotate_display_expression (); 17125796c8dcSSimon Schubert 17135796c8dcSSimon Schubert puts_filtered (d->exp_string); 17145796c8dcSSimon Schubert annotate_display_expression_end (); 17155796c8dcSSimon Schubert 17165796c8dcSSimon Schubert if (d->format.count != 1 || d->format.format == 'i') 17175796c8dcSSimon Schubert printf_filtered ("\n"); 17185796c8dcSSimon Schubert else 17195796c8dcSSimon Schubert printf_filtered (" "); 17205796c8dcSSimon Schubert 17215796c8dcSSimon Schubert val = evaluate_expression (d->exp); 17225796c8dcSSimon Schubert addr = value_as_address (val); 17235796c8dcSSimon Schubert if (d->format.format == 'i') 17245796c8dcSSimon Schubert addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr); 17255796c8dcSSimon Schubert 17265796c8dcSSimon Schubert annotate_display_value (); 17275796c8dcSSimon Schubert 17285796c8dcSSimon Schubert do_examine (d->format, d->exp->gdbarch, addr); 17295796c8dcSSimon Schubert } 17305796c8dcSSimon Schubert else 17315796c8dcSSimon Schubert { 17325796c8dcSSimon Schubert struct value_print_options opts; 17335796c8dcSSimon Schubert 17345796c8dcSSimon Schubert annotate_display_format (); 17355796c8dcSSimon Schubert 17365796c8dcSSimon Schubert if (d->format.format) 17375796c8dcSSimon Schubert printf_filtered ("/%c ", d->format.format); 17385796c8dcSSimon Schubert 17395796c8dcSSimon Schubert annotate_display_expression (); 17405796c8dcSSimon Schubert 17415796c8dcSSimon Schubert puts_filtered (d->exp_string); 17425796c8dcSSimon Schubert annotate_display_expression_end (); 17435796c8dcSSimon Schubert 17445796c8dcSSimon Schubert printf_filtered (" = "); 17455796c8dcSSimon Schubert 17465796c8dcSSimon Schubert annotate_display_expression (); 17475796c8dcSSimon Schubert 17485796c8dcSSimon Schubert get_formatted_print_options (&opts, d->format.format); 17495796c8dcSSimon Schubert opts.raw = d->format.raw; 17505796c8dcSSimon Schubert print_formatted (evaluate_expression (d->exp), 17515796c8dcSSimon Schubert d->format.size, &opts, gdb_stdout); 17525796c8dcSSimon Schubert printf_filtered ("\n"); 17535796c8dcSSimon Schubert } 17545796c8dcSSimon Schubert 17555796c8dcSSimon Schubert annotate_display_end (); 17565796c8dcSSimon Schubert 17575796c8dcSSimon Schubert gdb_flush (gdb_stdout); 17585796c8dcSSimon Schubert current_display_number = -1; 17595796c8dcSSimon Schubert } 17605796c8dcSSimon Schubert 17615796c8dcSSimon Schubert /* Display all of the values on the auto-display chain which can be 17625796c8dcSSimon Schubert evaluated in the current scope. */ 17635796c8dcSSimon Schubert 17645796c8dcSSimon Schubert void 17655796c8dcSSimon Schubert do_displays (void) 17665796c8dcSSimon Schubert { 17675796c8dcSSimon Schubert struct display *d; 17685796c8dcSSimon Schubert 17695796c8dcSSimon Schubert for (d = display_chain; d; d = d->next) 17705796c8dcSSimon Schubert do_one_display (d); 17715796c8dcSSimon Schubert } 17725796c8dcSSimon Schubert 17735796c8dcSSimon Schubert /* Delete the auto-display which we were in the process of displaying. 17745796c8dcSSimon Schubert This is done when there is an error or a signal. */ 17755796c8dcSSimon Schubert 17765796c8dcSSimon Schubert void 17775796c8dcSSimon Schubert disable_display (int num) 17785796c8dcSSimon Schubert { 17795796c8dcSSimon Schubert struct display *d; 17805796c8dcSSimon Schubert 17815796c8dcSSimon Schubert for (d = display_chain; d; d = d->next) 17825796c8dcSSimon Schubert if (d->number == num) 17835796c8dcSSimon Schubert { 17845796c8dcSSimon Schubert d->enabled_p = 0; 17855796c8dcSSimon Schubert return; 17865796c8dcSSimon Schubert } 17875796c8dcSSimon Schubert printf_unfiltered (_("No display number %d.\n"), num); 17885796c8dcSSimon Schubert } 17895796c8dcSSimon Schubert 17905796c8dcSSimon Schubert void 17915796c8dcSSimon Schubert disable_current_display (void) 17925796c8dcSSimon Schubert { 17935796c8dcSSimon Schubert if (current_display_number >= 0) 17945796c8dcSSimon Schubert { 17955796c8dcSSimon Schubert disable_display (current_display_number); 17965796c8dcSSimon Schubert fprintf_unfiltered (gdb_stderr, _("\ 17975796c8dcSSimon Schubert Disabling display %d to avoid infinite recursion.\n"), 17985796c8dcSSimon Schubert current_display_number); 17995796c8dcSSimon Schubert } 18005796c8dcSSimon Schubert current_display_number = -1; 18015796c8dcSSimon Schubert } 18025796c8dcSSimon Schubert 18035796c8dcSSimon Schubert static void 18045796c8dcSSimon Schubert display_info (char *ignore, int from_tty) 18055796c8dcSSimon Schubert { 18065796c8dcSSimon Schubert struct display *d; 18075796c8dcSSimon Schubert 18085796c8dcSSimon Schubert if (!display_chain) 18095796c8dcSSimon Schubert printf_unfiltered (_("There are no auto-display expressions now.\n")); 18105796c8dcSSimon Schubert else 18115796c8dcSSimon Schubert printf_filtered (_("Auto-display expressions now in effect:\n\ 18125796c8dcSSimon Schubert Num Enb Expression\n")); 18135796c8dcSSimon Schubert 18145796c8dcSSimon Schubert for (d = display_chain; d; d = d->next) 18155796c8dcSSimon Schubert { 18165796c8dcSSimon Schubert printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]); 18175796c8dcSSimon Schubert if (d->format.size) 18185796c8dcSSimon Schubert printf_filtered ("/%d%c%c ", d->format.count, d->format.size, 18195796c8dcSSimon Schubert d->format.format); 18205796c8dcSSimon Schubert else if (d->format.format) 18215796c8dcSSimon Schubert printf_filtered ("/%c ", d->format.format); 18225796c8dcSSimon Schubert puts_filtered (d->exp_string); 18235796c8dcSSimon Schubert if (d->block && !contained_in (get_selected_block (0), d->block)) 18245796c8dcSSimon Schubert printf_filtered (_(" (cannot be evaluated in the current context)")); 18255796c8dcSSimon Schubert printf_filtered ("\n"); 18265796c8dcSSimon Schubert gdb_flush (gdb_stdout); 18275796c8dcSSimon Schubert } 18285796c8dcSSimon Schubert } 18295796c8dcSSimon Schubert 18305796c8dcSSimon Schubert static void 18315796c8dcSSimon Schubert enable_display (char *args, int from_tty) 18325796c8dcSSimon Schubert { 18335796c8dcSSimon Schubert char *p = args; 18345796c8dcSSimon Schubert char *p1; 18355796c8dcSSimon Schubert int num; 18365796c8dcSSimon Schubert struct display *d; 18375796c8dcSSimon Schubert 18385796c8dcSSimon Schubert if (p == 0) 18395796c8dcSSimon Schubert { 18405796c8dcSSimon Schubert for (d = display_chain; d; d = d->next) 18415796c8dcSSimon Schubert d->enabled_p = 1; 18425796c8dcSSimon Schubert } 18435796c8dcSSimon Schubert else 18445796c8dcSSimon Schubert while (*p) 18455796c8dcSSimon Schubert { 18465796c8dcSSimon Schubert p1 = p; 18475796c8dcSSimon Schubert while (*p1 >= '0' && *p1 <= '9') 18485796c8dcSSimon Schubert p1++; 18495796c8dcSSimon Schubert if (*p1 && *p1 != ' ' && *p1 != '\t') 18505796c8dcSSimon Schubert error (_("Arguments must be display numbers.")); 18515796c8dcSSimon Schubert 18525796c8dcSSimon Schubert num = atoi (p); 18535796c8dcSSimon Schubert 18545796c8dcSSimon Schubert for (d = display_chain; d; d = d->next) 18555796c8dcSSimon Schubert if (d->number == num) 18565796c8dcSSimon Schubert { 18575796c8dcSSimon Schubert d->enabled_p = 1; 18585796c8dcSSimon Schubert goto win; 18595796c8dcSSimon Schubert } 18605796c8dcSSimon Schubert printf_unfiltered (_("No display number %d.\n"), num); 18615796c8dcSSimon Schubert win: 18625796c8dcSSimon Schubert p = p1; 18635796c8dcSSimon Schubert while (*p == ' ' || *p == '\t') 18645796c8dcSSimon Schubert p++; 18655796c8dcSSimon Schubert } 18665796c8dcSSimon Schubert } 18675796c8dcSSimon Schubert 18685796c8dcSSimon Schubert static void 18695796c8dcSSimon Schubert disable_display_command (char *args, int from_tty) 18705796c8dcSSimon Schubert { 18715796c8dcSSimon Schubert char *p = args; 18725796c8dcSSimon Schubert char *p1; 18735796c8dcSSimon Schubert struct display *d; 18745796c8dcSSimon Schubert 18755796c8dcSSimon Schubert if (p == 0) 18765796c8dcSSimon Schubert { 18775796c8dcSSimon Schubert for (d = display_chain; d; d = d->next) 18785796c8dcSSimon Schubert d->enabled_p = 0; 18795796c8dcSSimon Schubert } 18805796c8dcSSimon Schubert else 18815796c8dcSSimon Schubert while (*p) 18825796c8dcSSimon Schubert { 18835796c8dcSSimon Schubert p1 = p; 18845796c8dcSSimon Schubert while (*p1 >= '0' && *p1 <= '9') 18855796c8dcSSimon Schubert p1++; 18865796c8dcSSimon Schubert if (*p1 && *p1 != ' ' && *p1 != '\t') 18875796c8dcSSimon Schubert error (_("Arguments must be display numbers.")); 18885796c8dcSSimon Schubert 18895796c8dcSSimon Schubert disable_display (atoi (p)); 18905796c8dcSSimon Schubert 18915796c8dcSSimon Schubert p = p1; 18925796c8dcSSimon Schubert while (*p == ' ' || *p == '\t') 18935796c8dcSSimon Schubert p++; 18945796c8dcSSimon Schubert } 18955796c8dcSSimon Schubert } 18965796c8dcSSimon Schubert 18975796c8dcSSimon Schubert /* display_chain items point to blocks and expressions. Some expressions in 18985796c8dcSSimon Schubert turn may point to symbols. 18995796c8dcSSimon Schubert Both symbols and blocks are obstack_alloc'd on objfile_stack, and are 19005796c8dcSSimon Schubert obstack_free'd when a shared library is unloaded. 19015796c8dcSSimon Schubert Clear pointers that are about to become dangling. 19025796c8dcSSimon Schubert Both .exp and .block fields will be restored next time we need to display 19035796c8dcSSimon Schubert an item by re-parsing .exp_string field in the new execution context. */ 19045796c8dcSSimon Schubert 19055796c8dcSSimon Schubert static void 19065796c8dcSSimon Schubert clear_dangling_display_expressions (struct so_list *solib) 19075796c8dcSSimon Schubert { 1908*cf7f2e2dSJohn Marino struct objfile *objfile = solib->objfile; 19095796c8dcSSimon Schubert struct display *d; 19105796c8dcSSimon Schubert 1911*cf7f2e2dSJohn Marino /* With no symbol file we cannot have a block or expression from it. */ 1912*cf7f2e2dSJohn Marino if (objfile == NULL) 1913*cf7f2e2dSJohn Marino return; 1914*cf7f2e2dSJohn Marino if (objfile->separate_debug_objfile_backlink) 1915*cf7f2e2dSJohn Marino objfile = objfile->separate_debug_objfile_backlink; 1916*cf7f2e2dSJohn Marino gdb_assert (objfile->pspace == solib->pspace); 1917*cf7f2e2dSJohn Marino 1918*cf7f2e2dSJohn Marino for (d = display_chain; d != NULL; d = d->next) 19195796c8dcSSimon Schubert { 1920*cf7f2e2dSJohn Marino if (d->pspace != solib->pspace) 1921*cf7f2e2dSJohn Marino continue; 1922*cf7f2e2dSJohn Marino 1923*cf7f2e2dSJohn Marino if (lookup_objfile_from_block (d->block) == objfile 1924*cf7f2e2dSJohn Marino || (d->exp && exp_uses_objfile (d->exp, objfile))) 19255796c8dcSSimon Schubert { 19265796c8dcSSimon Schubert xfree (d->exp); 19275796c8dcSSimon Schubert d->exp = NULL; 19285796c8dcSSimon Schubert d->block = NULL; 19295796c8dcSSimon Schubert } 19305796c8dcSSimon Schubert } 19315796c8dcSSimon Schubert } 19325796c8dcSSimon Schubert 19335796c8dcSSimon Schubert 19345796c8dcSSimon Schubert /* Print the value in stack frame FRAME of a variable specified by a 19355796c8dcSSimon Schubert struct symbol. NAME is the name to print; if NULL then VAR's print 19365796c8dcSSimon Schubert name will be used. STREAM is the ui_file on which to print the 19375796c8dcSSimon Schubert value. INDENT specifies the number of indent levels to print 19385796c8dcSSimon Schubert before printing the variable name. */ 19395796c8dcSSimon Schubert 19405796c8dcSSimon Schubert void 19415796c8dcSSimon Schubert print_variable_and_value (const char *name, struct symbol *var, 19425796c8dcSSimon Schubert struct frame_info *frame, 19435796c8dcSSimon Schubert struct ui_file *stream, int indent) 19445796c8dcSSimon Schubert { 1945*cf7f2e2dSJohn Marino volatile struct gdb_exception except; 19465796c8dcSSimon Schubert 19475796c8dcSSimon Schubert if (!name) 19485796c8dcSSimon Schubert name = SYMBOL_PRINT_NAME (var); 19495796c8dcSSimon Schubert 19505796c8dcSSimon Schubert fprintf_filtered (stream, "%s%s = ", n_spaces (2 * indent), name); 1951*cf7f2e2dSJohn Marino TRY_CATCH (except, RETURN_MASK_ERROR) 1952*cf7f2e2dSJohn Marino { 1953*cf7f2e2dSJohn Marino struct value *val; 1954*cf7f2e2dSJohn Marino struct value_print_options opts; 19555796c8dcSSimon Schubert 19565796c8dcSSimon Schubert val = read_var_value (var, frame); 19575796c8dcSSimon Schubert get_user_print_options (&opts); 19585796c8dcSSimon Schubert common_val_print (val, stream, indent, &opts, current_language); 1959*cf7f2e2dSJohn Marino } 1960*cf7f2e2dSJohn Marino if (except.reason < 0) 1961*cf7f2e2dSJohn Marino fprintf_filtered(stream, "<error reading variable %s (%s)>", name, 1962*cf7f2e2dSJohn Marino except.message); 19635796c8dcSSimon Schubert fprintf_filtered (stream, "\n"); 19645796c8dcSSimon Schubert } 19655796c8dcSSimon Schubert 1966*cf7f2e2dSJohn Marino /* printf "printf format string" ARG to STREAM. */ 1967*cf7f2e2dSJohn Marino 19685796c8dcSSimon Schubert static void 1969*cf7f2e2dSJohn Marino ui_printf (char *arg, struct ui_file *stream) 19705796c8dcSSimon Schubert { 19715796c8dcSSimon Schubert char *f = NULL; 19725796c8dcSSimon Schubert char *s = arg; 19735796c8dcSSimon Schubert char *string = NULL; 19745796c8dcSSimon Schubert struct value **val_args; 19755796c8dcSSimon Schubert char *substrings; 19765796c8dcSSimon Schubert char *current_substring; 19775796c8dcSSimon Schubert int nargs = 0; 19785796c8dcSSimon Schubert int allocated_args = 20; 19795796c8dcSSimon Schubert struct cleanup *old_cleanups; 19805796c8dcSSimon Schubert 19815796c8dcSSimon Schubert val_args = xmalloc (allocated_args * sizeof (struct value *)); 19825796c8dcSSimon Schubert old_cleanups = make_cleanup (free_current_contents, &val_args); 19835796c8dcSSimon Schubert 19845796c8dcSSimon Schubert if (s == 0) 19855796c8dcSSimon Schubert error_no_arg (_("format-control string and values to print")); 19865796c8dcSSimon Schubert 19875796c8dcSSimon Schubert /* Skip white space before format string */ 19885796c8dcSSimon Schubert while (*s == ' ' || *s == '\t') 19895796c8dcSSimon Schubert s++; 19905796c8dcSSimon Schubert 19915796c8dcSSimon Schubert /* A format string should follow, enveloped in double quotes. */ 19925796c8dcSSimon Schubert if (*s++ != '"') 19935796c8dcSSimon Schubert error (_("Bad format string, missing '\"'.")); 19945796c8dcSSimon Schubert 19955796c8dcSSimon Schubert /* Parse the format-control string and copy it into the string STRING, 19965796c8dcSSimon Schubert processing some kinds of escape sequence. */ 19975796c8dcSSimon Schubert 19985796c8dcSSimon Schubert f = string = (char *) alloca (strlen (s) + 1); 19995796c8dcSSimon Schubert 20005796c8dcSSimon Schubert while (*s != '"') 20015796c8dcSSimon Schubert { 20025796c8dcSSimon Schubert int c = *s++; 20035796c8dcSSimon Schubert switch (c) 20045796c8dcSSimon Schubert { 20055796c8dcSSimon Schubert case '\0': 20065796c8dcSSimon Schubert error (_("Bad format string, non-terminated '\"'.")); 20075796c8dcSSimon Schubert 20085796c8dcSSimon Schubert case '\\': 20095796c8dcSSimon Schubert switch (c = *s++) 20105796c8dcSSimon Schubert { 20115796c8dcSSimon Schubert case '\\': 20125796c8dcSSimon Schubert *f++ = '\\'; 20135796c8dcSSimon Schubert break; 20145796c8dcSSimon Schubert case 'a': 20155796c8dcSSimon Schubert *f++ = '\a'; 20165796c8dcSSimon Schubert break; 20175796c8dcSSimon Schubert case 'b': 20185796c8dcSSimon Schubert *f++ = '\b'; 20195796c8dcSSimon Schubert break; 20205796c8dcSSimon Schubert case 'f': 20215796c8dcSSimon Schubert *f++ = '\f'; 20225796c8dcSSimon Schubert break; 20235796c8dcSSimon Schubert case 'n': 20245796c8dcSSimon Schubert *f++ = '\n'; 20255796c8dcSSimon Schubert break; 20265796c8dcSSimon Schubert case 'r': 20275796c8dcSSimon Schubert *f++ = '\r'; 20285796c8dcSSimon Schubert break; 20295796c8dcSSimon Schubert case 't': 20305796c8dcSSimon Schubert *f++ = '\t'; 20315796c8dcSSimon Schubert break; 20325796c8dcSSimon Schubert case 'v': 20335796c8dcSSimon Schubert *f++ = '\v'; 20345796c8dcSSimon Schubert break; 20355796c8dcSSimon Schubert case '"': 20365796c8dcSSimon Schubert *f++ = '"'; 20375796c8dcSSimon Schubert break; 20385796c8dcSSimon Schubert default: 20395796c8dcSSimon Schubert /* ??? TODO: handle other escape sequences */ 20405796c8dcSSimon Schubert error (_("Unrecognized escape character \\%c in format string."), 20415796c8dcSSimon Schubert c); 20425796c8dcSSimon Schubert } 20435796c8dcSSimon Schubert break; 20445796c8dcSSimon Schubert 20455796c8dcSSimon Schubert default: 20465796c8dcSSimon Schubert *f++ = c; 20475796c8dcSSimon Schubert } 20485796c8dcSSimon Schubert } 20495796c8dcSSimon Schubert 20505796c8dcSSimon Schubert /* Skip over " and following space and comma. */ 20515796c8dcSSimon Schubert s++; 20525796c8dcSSimon Schubert *f++ = '\0'; 20535796c8dcSSimon Schubert while (*s == ' ' || *s == '\t') 20545796c8dcSSimon Schubert s++; 20555796c8dcSSimon Schubert 20565796c8dcSSimon Schubert if (*s != ',' && *s != 0) 20575796c8dcSSimon Schubert error (_("Invalid argument syntax")); 20585796c8dcSSimon Schubert 20595796c8dcSSimon Schubert if (*s == ',') 20605796c8dcSSimon Schubert s++; 20615796c8dcSSimon Schubert while (*s == ' ' || *s == '\t') 20625796c8dcSSimon Schubert s++; 20635796c8dcSSimon Schubert 20645796c8dcSSimon Schubert /* Need extra space for the '\0's. Doubling the size is sufficient. */ 20655796c8dcSSimon Schubert substrings = alloca (strlen (string) * 2); 20665796c8dcSSimon Schubert current_substring = substrings; 20675796c8dcSSimon Schubert 20685796c8dcSSimon Schubert { 20695796c8dcSSimon Schubert /* Now scan the string for %-specs and see what kinds of args they want. 20705796c8dcSSimon Schubert argclass[I] classifies the %-specs so we can give printf_filtered 20715796c8dcSSimon Schubert something of the right size. */ 20725796c8dcSSimon Schubert 20735796c8dcSSimon Schubert enum argclass 20745796c8dcSSimon Schubert { 20755796c8dcSSimon Schubert int_arg, long_arg, long_long_arg, ptr_arg, 20765796c8dcSSimon Schubert string_arg, wide_string_arg, wide_char_arg, 20775796c8dcSSimon Schubert double_arg, long_double_arg, decfloat_arg 20785796c8dcSSimon Schubert }; 20795796c8dcSSimon Schubert enum argclass *argclass; 20805796c8dcSSimon Schubert enum argclass this_argclass; 20815796c8dcSSimon Schubert char *last_arg; 20825796c8dcSSimon Schubert int nargs_wanted; 20835796c8dcSSimon Schubert int i; 20845796c8dcSSimon Schubert 20855796c8dcSSimon Schubert argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass); 20865796c8dcSSimon Schubert nargs_wanted = 0; 20875796c8dcSSimon Schubert f = string; 20885796c8dcSSimon Schubert last_arg = string; 20895796c8dcSSimon Schubert while (*f) 20905796c8dcSSimon Schubert if (*f++ == '%') 20915796c8dcSSimon Schubert { 20925796c8dcSSimon Schubert int seen_hash = 0, seen_zero = 0, lcount = 0, seen_prec = 0; 20935796c8dcSSimon Schubert int seen_space = 0, seen_plus = 0; 20945796c8dcSSimon Schubert int seen_big_l = 0, seen_h = 0, seen_big_h = 0; 20955796c8dcSSimon Schubert int seen_big_d = 0, seen_double_big_d = 0; 20965796c8dcSSimon Schubert int bad = 0; 20975796c8dcSSimon Schubert 20985796c8dcSSimon Schubert /* Check the validity of the format specifier, and work 20995796c8dcSSimon Schubert out what argument it expects. We only accept C89 21005796c8dcSSimon Schubert format strings, with the exception of long long (which 21015796c8dcSSimon Schubert we autoconf for). */ 21025796c8dcSSimon Schubert 21035796c8dcSSimon Schubert /* Skip over "%%". */ 21045796c8dcSSimon Schubert if (*f == '%') 21055796c8dcSSimon Schubert { 21065796c8dcSSimon Schubert f++; 21075796c8dcSSimon Schubert continue; 21085796c8dcSSimon Schubert } 21095796c8dcSSimon Schubert 21105796c8dcSSimon Schubert /* The first part of a format specifier is a set of flag 21115796c8dcSSimon Schubert characters. */ 21125796c8dcSSimon Schubert while (strchr ("0-+ #", *f)) 21135796c8dcSSimon Schubert { 21145796c8dcSSimon Schubert if (*f == '#') 21155796c8dcSSimon Schubert seen_hash = 1; 21165796c8dcSSimon Schubert else if (*f == '0') 21175796c8dcSSimon Schubert seen_zero = 1; 21185796c8dcSSimon Schubert else if (*f == ' ') 21195796c8dcSSimon Schubert seen_space = 1; 21205796c8dcSSimon Schubert else if (*f == '+') 21215796c8dcSSimon Schubert seen_plus = 1; 21225796c8dcSSimon Schubert f++; 21235796c8dcSSimon Schubert } 21245796c8dcSSimon Schubert 21255796c8dcSSimon Schubert /* The next part of a format specifier is a width. */ 21265796c8dcSSimon Schubert while (strchr ("0123456789", *f)) 21275796c8dcSSimon Schubert f++; 21285796c8dcSSimon Schubert 21295796c8dcSSimon Schubert /* The next part of a format specifier is a precision. */ 21305796c8dcSSimon Schubert if (*f == '.') 21315796c8dcSSimon Schubert { 21325796c8dcSSimon Schubert seen_prec = 1; 21335796c8dcSSimon Schubert f++; 21345796c8dcSSimon Schubert while (strchr ("0123456789", *f)) 21355796c8dcSSimon Schubert f++; 21365796c8dcSSimon Schubert } 21375796c8dcSSimon Schubert 21385796c8dcSSimon Schubert /* The next part of a format specifier is a length modifier. */ 21395796c8dcSSimon Schubert if (*f == 'h') 21405796c8dcSSimon Schubert { 21415796c8dcSSimon Schubert seen_h = 1; 21425796c8dcSSimon Schubert f++; 21435796c8dcSSimon Schubert } 21445796c8dcSSimon Schubert else if (*f == 'l') 21455796c8dcSSimon Schubert { 21465796c8dcSSimon Schubert f++; 21475796c8dcSSimon Schubert lcount++; 21485796c8dcSSimon Schubert if (*f == 'l') 21495796c8dcSSimon Schubert { 21505796c8dcSSimon Schubert f++; 21515796c8dcSSimon Schubert lcount++; 21525796c8dcSSimon Schubert } 21535796c8dcSSimon Schubert } 21545796c8dcSSimon Schubert else if (*f == 'L') 21555796c8dcSSimon Schubert { 21565796c8dcSSimon Schubert seen_big_l = 1; 21575796c8dcSSimon Schubert f++; 21585796c8dcSSimon Schubert } 21595796c8dcSSimon Schubert /* Decimal32 modifier. */ 21605796c8dcSSimon Schubert else if (*f == 'H') 21615796c8dcSSimon Schubert { 21625796c8dcSSimon Schubert seen_big_h = 1; 21635796c8dcSSimon Schubert f++; 21645796c8dcSSimon Schubert } 21655796c8dcSSimon Schubert /* Decimal64 and Decimal128 modifiers. */ 21665796c8dcSSimon Schubert else if (*f == 'D') 21675796c8dcSSimon Schubert { 21685796c8dcSSimon Schubert f++; 21695796c8dcSSimon Schubert 21705796c8dcSSimon Schubert /* Check for a Decimal128. */ 21715796c8dcSSimon Schubert if (*f == 'D') 21725796c8dcSSimon Schubert { 21735796c8dcSSimon Schubert f++; 21745796c8dcSSimon Schubert seen_double_big_d = 1; 21755796c8dcSSimon Schubert } 21765796c8dcSSimon Schubert else 21775796c8dcSSimon Schubert seen_big_d = 1; 21785796c8dcSSimon Schubert } 21795796c8dcSSimon Schubert 21805796c8dcSSimon Schubert switch (*f) 21815796c8dcSSimon Schubert { 21825796c8dcSSimon Schubert case 'u': 21835796c8dcSSimon Schubert if (seen_hash) 21845796c8dcSSimon Schubert bad = 1; 21855796c8dcSSimon Schubert /* FALLTHROUGH */ 21865796c8dcSSimon Schubert 21875796c8dcSSimon Schubert case 'o': 21885796c8dcSSimon Schubert case 'x': 21895796c8dcSSimon Schubert case 'X': 21905796c8dcSSimon Schubert if (seen_space || seen_plus) 21915796c8dcSSimon Schubert bad = 1; 21925796c8dcSSimon Schubert /* FALLTHROUGH */ 21935796c8dcSSimon Schubert 21945796c8dcSSimon Schubert case 'd': 21955796c8dcSSimon Schubert case 'i': 21965796c8dcSSimon Schubert if (lcount == 0) 21975796c8dcSSimon Schubert this_argclass = int_arg; 21985796c8dcSSimon Schubert else if (lcount == 1) 21995796c8dcSSimon Schubert this_argclass = long_arg; 22005796c8dcSSimon Schubert else 22015796c8dcSSimon Schubert this_argclass = long_long_arg; 22025796c8dcSSimon Schubert 22035796c8dcSSimon Schubert if (seen_big_l) 22045796c8dcSSimon Schubert bad = 1; 22055796c8dcSSimon Schubert break; 22065796c8dcSSimon Schubert 22075796c8dcSSimon Schubert case 'c': 22085796c8dcSSimon Schubert this_argclass = lcount == 0 ? int_arg : wide_char_arg; 22095796c8dcSSimon Schubert if (lcount > 1 || seen_h || seen_big_l) 22105796c8dcSSimon Schubert bad = 1; 22115796c8dcSSimon Schubert if (seen_prec || seen_zero || seen_space || seen_plus) 22125796c8dcSSimon Schubert bad = 1; 22135796c8dcSSimon Schubert break; 22145796c8dcSSimon Schubert 22155796c8dcSSimon Schubert case 'p': 22165796c8dcSSimon Schubert this_argclass = ptr_arg; 22175796c8dcSSimon Schubert if (lcount || seen_h || seen_big_l) 22185796c8dcSSimon Schubert bad = 1; 22195796c8dcSSimon Schubert if (seen_prec || seen_zero || seen_space || seen_plus) 22205796c8dcSSimon Schubert bad = 1; 22215796c8dcSSimon Schubert break; 22225796c8dcSSimon Schubert 22235796c8dcSSimon Schubert case 's': 22245796c8dcSSimon Schubert this_argclass = lcount == 0 ? string_arg : wide_string_arg; 22255796c8dcSSimon Schubert if (lcount > 1 || seen_h || seen_big_l) 22265796c8dcSSimon Schubert bad = 1; 22275796c8dcSSimon Schubert if (seen_zero || seen_space || seen_plus) 22285796c8dcSSimon Schubert bad = 1; 22295796c8dcSSimon Schubert break; 22305796c8dcSSimon Schubert 22315796c8dcSSimon Schubert case 'e': 22325796c8dcSSimon Schubert case 'f': 22335796c8dcSSimon Schubert case 'g': 22345796c8dcSSimon Schubert case 'E': 22355796c8dcSSimon Schubert case 'G': 22365796c8dcSSimon Schubert if (seen_big_h || seen_big_d || seen_double_big_d) 22375796c8dcSSimon Schubert this_argclass = decfloat_arg; 22385796c8dcSSimon Schubert else if (seen_big_l) 22395796c8dcSSimon Schubert this_argclass = long_double_arg; 22405796c8dcSSimon Schubert else 22415796c8dcSSimon Schubert this_argclass = double_arg; 22425796c8dcSSimon Schubert 22435796c8dcSSimon Schubert if (lcount || seen_h) 22445796c8dcSSimon Schubert bad = 1; 22455796c8dcSSimon Schubert break; 22465796c8dcSSimon Schubert 22475796c8dcSSimon Schubert case '*': 22485796c8dcSSimon Schubert error (_("`*' not supported for precision or width in printf")); 22495796c8dcSSimon Schubert 22505796c8dcSSimon Schubert case 'n': 22515796c8dcSSimon Schubert error (_("Format specifier `n' not supported in printf")); 22525796c8dcSSimon Schubert 22535796c8dcSSimon Schubert case '\0': 22545796c8dcSSimon Schubert error (_("Incomplete format specifier at end of format string")); 22555796c8dcSSimon Schubert 22565796c8dcSSimon Schubert default: 22575796c8dcSSimon Schubert error (_("Unrecognized format specifier '%c' in printf"), *f); 22585796c8dcSSimon Schubert } 22595796c8dcSSimon Schubert 22605796c8dcSSimon Schubert if (bad) 22615796c8dcSSimon Schubert error (_("Inappropriate modifiers to format specifier '%c' in printf"), 22625796c8dcSSimon Schubert *f); 22635796c8dcSSimon Schubert 22645796c8dcSSimon Schubert f++; 22655796c8dcSSimon Schubert 22665796c8dcSSimon Schubert if (lcount > 1 && USE_PRINTF_I64) 22675796c8dcSSimon Schubert { 22685796c8dcSSimon Schubert /* Windows' printf does support long long, but not the usual way. 22695796c8dcSSimon Schubert Convert %lld to %I64d. */ 22705796c8dcSSimon Schubert int length_before_ll = f - last_arg - 1 - lcount; 2271*cf7f2e2dSJohn Marino 22725796c8dcSSimon Schubert strncpy (current_substring, last_arg, length_before_ll); 22735796c8dcSSimon Schubert strcpy (current_substring + length_before_ll, "I64"); 22745796c8dcSSimon Schubert current_substring[length_before_ll + 3] = 22755796c8dcSSimon Schubert last_arg[length_before_ll + lcount]; 22765796c8dcSSimon Schubert current_substring += length_before_ll + 4; 22775796c8dcSSimon Schubert } 22785796c8dcSSimon Schubert else if (this_argclass == wide_string_arg 22795796c8dcSSimon Schubert || this_argclass == wide_char_arg) 22805796c8dcSSimon Schubert { 22815796c8dcSSimon Schubert /* Convert %ls or %lc to %s. */ 22825796c8dcSSimon Schubert int length_before_ls = f - last_arg - 2; 2283*cf7f2e2dSJohn Marino 22845796c8dcSSimon Schubert strncpy (current_substring, last_arg, length_before_ls); 22855796c8dcSSimon Schubert strcpy (current_substring + length_before_ls, "s"); 22865796c8dcSSimon Schubert current_substring += length_before_ls + 2; 22875796c8dcSSimon Schubert } 22885796c8dcSSimon Schubert else 22895796c8dcSSimon Schubert { 22905796c8dcSSimon Schubert strncpy (current_substring, last_arg, f - last_arg); 22915796c8dcSSimon Schubert current_substring += f - last_arg; 22925796c8dcSSimon Schubert } 22935796c8dcSSimon Schubert *current_substring++ = '\0'; 22945796c8dcSSimon Schubert last_arg = f; 22955796c8dcSSimon Schubert argclass[nargs_wanted++] = this_argclass; 22965796c8dcSSimon Schubert } 22975796c8dcSSimon Schubert 22985796c8dcSSimon Schubert /* Now, parse all arguments and evaluate them. 22995796c8dcSSimon Schubert Store the VALUEs in VAL_ARGS. */ 23005796c8dcSSimon Schubert 23015796c8dcSSimon Schubert while (*s != '\0') 23025796c8dcSSimon Schubert { 23035796c8dcSSimon Schubert char *s1; 2304*cf7f2e2dSJohn Marino 23055796c8dcSSimon Schubert if (nargs == allocated_args) 23065796c8dcSSimon Schubert val_args = (struct value **) xrealloc ((char *) val_args, 23075796c8dcSSimon Schubert (allocated_args *= 2) 23085796c8dcSSimon Schubert * sizeof (struct value *)); 23095796c8dcSSimon Schubert s1 = s; 23105796c8dcSSimon Schubert val_args[nargs] = parse_to_comma_and_eval (&s1); 23115796c8dcSSimon Schubert 23125796c8dcSSimon Schubert nargs++; 23135796c8dcSSimon Schubert s = s1; 23145796c8dcSSimon Schubert if (*s == ',') 23155796c8dcSSimon Schubert s++; 23165796c8dcSSimon Schubert } 23175796c8dcSSimon Schubert 23185796c8dcSSimon Schubert if (nargs != nargs_wanted) 23195796c8dcSSimon Schubert error (_("Wrong number of arguments for specified format-string")); 23205796c8dcSSimon Schubert 23215796c8dcSSimon Schubert /* Now actually print them. */ 23225796c8dcSSimon Schubert current_substring = substrings; 23235796c8dcSSimon Schubert for (i = 0; i < nargs; i++) 23245796c8dcSSimon Schubert { 23255796c8dcSSimon Schubert switch (argclass[i]) 23265796c8dcSSimon Schubert { 23275796c8dcSSimon Schubert case string_arg: 23285796c8dcSSimon Schubert { 23295796c8dcSSimon Schubert gdb_byte *str; 23305796c8dcSSimon Schubert CORE_ADDR tem; 23315796c8dcSSimon Schubert int j; 2332*cf7f2e2dSJohn Marino 23335796c8dcSSimon Schubert tem = value_as_address (val_args[i]); 23345796c8dcSSimon Schubert 23355796c8dcSSimon Schubert /* This is a %s argument. Find the length of the string. */ 23365796c8dcSSimon Schubert for (j = 0;; j++) 23375796c8dcSSimon Schubert { 23385796c8dcSSimon Schubert gdb_byte c; 2339*cf7f2e2dSJohn Marino 23405796c8dcSSimon Schubert QUIT; 23415796c8dcSSimon Schubert read_memory (tem + j, &c, 1); 23425796c8dcSSimon Schubert if (c == 0) 23435796c8dcSSimon Schubert break; 23445796c8dcSSimon Schubert } 23455796c8dcSSimon Schubert 23465796c8dcSSimon Schubert /* Copy the string contents into a string inside GDB. */ 23475796c8dcSSimon Schubert str = (gdb_byte *) alloca (j + 1); 23485796c8dcSSimon Schubert if (j != 0) 23495796c8dcSSimon Schubert read_memory (tem, str, j); 23505796c8dcSSimon Schubert str[j] = 0; 23515796c8dcSSimon Schubert 2352*cf7f2e2dSJohn Marino fprintf_filtered (stream, current_substring, (char *) str); 23535796c8dcSSimon Schubert } 23545796c8dcSSimon Schubert break; 23555796c8dcSSimon Schubert case wide_string_arg: 23565796c8dcSSimon Schubert { 23575796c8dcSSimon Schubert gdb_byte *str; 23585796c8dcSSimon Schubert CORE_ADDR tem; 23595796c8dcSSimon Schubert int j; 23605796c8dcSSimon Schubert struct gdbarch *gdbarch 23615796c8dcSSimon Schubert = get_type_arch (value_type (val_args[i])); 23625796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 23635796c8dcSSimon Schubert struct type *wctype = lookup_typename (current_language, gdbarch, 23645796c8dcSSimon Schubert "wchar_t", NULL, 0); 23655796c8dcSSimon Schubert int wcwidth = TYPE_LENGTH (wctype); 23665796c8dcSSimon Schubert gdb_byte *buf = alloca (wcwidth); 23675796c8dcSSimon Schubert struct obstack output; 23685796c8dcSSimon Schubert struct cleanup *inner_cleanup; 23695796c8dcSSimon Schubert 23705796c8dcSSimon Schubert tem = value_as_address (val_args[i]); 23715796c8dcSSimon Schubert 23725796c8dcSSimon Schubert /* This is a %s argument. Find the length of the string. */ 23735796c8dcSSimon Schubert for (j = 0;; j += wcwidth) 23745796c8dcSSimon Schubert { 23755796c8dcSSimon Schubert QUIT; 23765796c8dcSSimon Schubert read_memory (tem + j, buf, wcwidth); 23775796c8dcSSimon Schubert if (extract_unsigned_integer (buf, wcwidth, byte_order) == 0) 23785796c8dcSSimon Schubert break; 23795796c8dcSSimon Schubert } 23805796c8dcSSimon Schubert 23815796c8dcSSimon Schubert /* Copy the string contents into a string inside GDB. */ 23825796c8dcSSimon Schubert str = (gdb_byte *) alloca (j + wcwidth); 23835796c8dcSSimon Schubert if (j != 0) 23845796c8dcSSimon Schubert read_memory (tem, str, j); 23855796c8dcSSimon Schubert memset (&str[j], 0, wcwidth); 23865796c8dcSSimon Schubert 23875796c8dcSSimon Schubert obstack_init (&output); 23885796c8dcSSimon Schubert inner_cleanup = make_cleanup_obstack_free (&output); 23895796c8dcSSimon Schubert 2390*cf7f2e2dSJohn Marino convert_between_encodings (target_wide_charset (gdbarch), 23915796c8dcSSimon Schubert host_charset (), 23925796c8dcSSimon Schubert str, j, wcwidth, 23935796c8dcSSimon Schubert &output, translit_char); 23945796c8dcSSimon Schubert obstack_grow_str0 (&output, ""); 23955796c8dcSSimon Schubert 2396*cf7f2e2dSJohn Marino fprintf_filtered (stream, current_substring, 2397*cf7f2e2dSJohn Marino obstack_base (&output)); 23985796c8dcSSimon Schubert do_cleanups (inner_cleanup); 23995796c8dcSSimon Schubert } 24005796c8dcSSimon Schubert break; 24015796c8dcSSimon Schubert case wide_char_arg: 24025796c8dcSSimon Schubert { 24035796c8dcSSimon Schubert struct gdbarch *gdbarch 24045796c8dcSSimon Schubert = get_type_arch (value_type (val_args[i])); 24055796c8dcSSimon Schubert struct type *wctype = lookup_typename (current_language, gdbarch, 24065796c8dcSSimon Schubert "wchar_t", NULL, 0); 24075796c8dcSSimon Schubert struct type *valtype; 24085796c8dcSSimon Schubert struct obstack output; 24095796c8dcSSimon Schubert struct cleanup *inner_cleanup; 24105796c8dcSSimon Schubert const gdb_byte *bytes; 24115796c8dcSSimon Schubert 24125796c8dcSSimon Schubert valtype = value_type (val_args[i]); 24135796c8dcSSimon Schubert if (TYPE_LENGTH (valtype) != TYPE_LENGTH (wctype) 24145796c8dcSSimon Schubert || TYPE_CODE (valtype) != TYPE_CODE_INT) 24155796c8dcSSimon Schubert error (_("expected wchar_t argument for %%lc")); 24165796c8dcSSimon Schubert 24175796c8dcSSimon Schubert bytes = value_contents (val_args[i]); 24185796c8dcSSimon Schubert 24195796c8dcSSimon Schubert obstack_init (&output); 24205796c8dcSSimon Schubert inner_cleanup = make_cleanup_obstack_free (&output); 24215796c8dcSSimon Schubert 2422*cf7f2e2dSJohn Marino convert_between_encodings (target_wide_charset (gdbarch), 24235796c8dcSSimon Schubert host_charset (), 24245796c8dcSSimon Schubert bytes, TYPE_LENGTH (valtype), 24255796c8dcSSimon Schubert TYPE_LENGTH (valtype), 24265796c8dcSSimon Schubert &output, translit_char); 24275796c8dcSSimon Schubert obstack_grow_str0 (&output, ""); 24285796c8dcSSimon Schubert 2429*cf7f2e2dSJohn Marino fprintf_filtered (stream, current_substring, 2430*cf7f2e2dSJohn Marino obstack_base (&output)); 24315796c8dcSSimon Schubert do_cleanups (inner_cleanup); 24325796c8dcSSimon Schubert } 24335796c8dcSSimon Schubert break; 24345796c8dcSSimon Schubert case double_arg: 24355796c8dcSSimon Schubert { 24365796c8dcSSimon Schubert struct type *type = value_type (val_args[i]); 24375796c8dcSSimon Schubert DOUBLEST val; 24385796c8dcSSimon Schubert int inv; 24395796c8dcSSimon Schubert 24405796c8dcSSimon Schubert /* If format string wants a float, unchecked-convert the value 24415796c8dcSSimon Schubert to floating point of the same size. */ 24425796c8dcSSimon Schubert type = float_type_from_length (type); 24435796c8dcSSimon Schubert val = unpack_double (type, value_contents (val_args[i]), &inv); 24445796c8dcSSimon Schubert if (inv) 24455796c8dcSSimon Schubert error (_("Invalid floating value found in program.")); 24465796c8dcSSimon Schubert 2447*cf7f2e2dSJohn Marino fprintf_filtered (stream, current_substring, (double) val); 24485796c8dcSSimon Schubert break; 24495796c8dcSSimon Schubert } 24505796c8dcSSimon Schubert case long_double_arg: 24515796c8dcSSimon Schubert #ifdef HAVE_LONG_DOUBLE 24525796c8dcSSimon Schubert { 24535796c8dcSSimon Schubert struct type *type = value_type (val_args[i]); 24545796c8dcSSimon Schubert DOUBLEST val; 24555796c8dcSSimon Schubert int inv; 24565796c8dcSSimon Schubert 24575796c8dcSSimon Schubert /* If format string wants a float, unchecked-convert the value 24585796c8dcSSimon Schubert to floating point of the same size. */ 24595796c8dcSSimon Schubert type = float_type_from_length (type); 24605796c8dcSSimon Schubert val = unpack_double (type, value_contents (val_args[i]), &inv); 24615796c8dcSSimon Schubert if (inv) 24625796c8dcSSimon Schubert error (_("Invalid floating value found in program.")); 24635796c8dcSSimon Schubert 2464*cf7f2e2dSJohn Marino fprintf_filtered (stream, current_substring, 2465*cf7f2e2dSJohn Marino (long double) val); 24665796c8dcSSimon Schubert break; 24675796c8dcSSimon Schubert } 24685796c8dcSSimon Schubert #else 24695796c8dcSSimon Schubert error (_("long double not supported in printf")); 24705796c8dcSSimon Schubert #endif 24715796c8dcSSimon Schubert case long_long_arg: 24725796c8dcSSimon Schubert #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG) 24735796c8dcSSimon Schubert { 24745796c8dcSSimon Schubert long long val = value_as_long (val_args[i]); 2475*cf7f2e2dSJohn Marino 2476*cf7f2e2dSJohn Marino fprintf_filtered (stream, current_substring, val); 24775796c8dcSSimon Schubert break; 24785796c8dcSSimon Schubert } 24795796c8dcSSimon Schubert #else 24805796c8dcSSimon Schubert error (_("long long not supported in printf")); 24815796c8dcSSimon Schubert #endif 24825796c8dcSSimon Schubert case int_arg: 24835796c8dcSSimon Schubert { 24845796c8dcSSimon Schubert int val = value_as_long (val_args[i]); 2485*cf7f2e2dSJohn Marino 2486*cf7f2e2dSJohn Marino fprintf_filtered (stream, current_substring, val); 24875796c8dcSSimon Schubert break; 24885796c8dcSSimon Schubert } 24895796c8dcSSimon Schubert case long_arg: 24905796c8dcSSimon Schubert { 24915796c8dcSSimon Schubert long val = value_as_long (val_args[i]); 2492*cf7f2e2dSJohn Marino 2493*cf7f2e2dSJohn Marino fprintf_filtered (stream, current_substring, val); 24945796c8dcSSimon Schubert break; 24955796c8dcSSimon Schubert } 24965796c8dcSSimon Schubert 24975796c8dcSSimon Schubert /* Handles decimal floating values. */ 24985796c8dcSSimon Schubert case decfloat_arg: 24995796c8dcSSimon Schubert { 25005796c8dcSSimon Schubert const gdb_byte *param_ptr = value_contents (val_args[i]); 2501*cf7f2e2dSJohn Marino 25025796c8dcSSimon Schubert #if defined (PRINTF_HAS_DECFLOAT) 25035796c8dcSSimon Schubert /* If we have native support for Decimal floating 25045796c8dcSSimon Schubert printing, handle it here. */ 2505*cf7f2e2dSJohn Marino fprintf_filtered (stream, current_substring, param_ptr); 25065796c8dcSSimon Schubert #else 25075796c8dcSSimon Schubert 25085796c8dcSSimon Schubert /* As a workaround until vasprintf has native support for DFP 25095796c8dcSSimon Schubert we convert the DFP values to string and print them using 25105796c8dcSSimon Schubert the %s format specifier. */ 25115796c8dcSSimon Schubert 25125796c8dcSSimon Schubert char *eos, *sos; 25135796c8dcSSimon Schubert int nnull_chars = 0; 25145796c8dcSSimon Schubert 25155796c8dcSSimon Schubert /* Parameter data. */ 25165796c8dcSSimon Schubert struct type *param_type = value_type (val_args[i]); 25175796c8dcSSimon Schubert unsigned int param_len = TYPE_LENGTH (param_type); 25185796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (param_type); 25195796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 25205796c8dcSSimon Schubert 25215796c8dcSSimon Schubert /* DFP output data. */ 25225796c8dcSSimon Schubert struct value *dfp_value = NULL; 25235796c8dcSSimon Schubert gdb_byte *dfp_ptr; 25245796c8dcSSimon Schubert int dfp_len = 16; 25255796c8dcSSimon Schubert gdb_byte dec[16]; 25265796c8dcSSimon Schubert struct type *dfp_type = NULL; 25275796c8dcSSimon Schubert char decstr[MAX_DECIMAL_STRING]; 25285796c8dcSSimon Schubert 25295796c8dcSSimon Schubert /* Points to the end of the string so that we can go back 25305796c8dcSSimon Schubert and check for DFP length modifiers. */ 25315796c8dcSSimon Schubert eos = current_substring + strlen (current_substring); 25325796c8dcSSimon Schubert 25335796c8dcSSimon Schubert /* Look for the float/double format specifier. */ 25345796c8dcSSimon Schubert while (*eos != 'f' && *eos != 'e' && *eos != 'E' 25355796c8dcSSimon Schubert && *eos != 'g' && *eos != 'G') 25365796c8dcSSimon Schubert eos--; 25375796c8dcSSimon Schubert 25385796c8dcSSimon Schubert sos = eos; 25395796c8dcSSimon Schubert 25405796c8dcSSimon Schubert /* Search for the '%' char and extract the size and type of 25415796c8dcSSimon Schubert the output decimal value based on its modifiers 25425796c8dcSSimon Schubert (%Hf, %Df, %DDf). */ 25435796c8dcSSimon Schubert while (*--sos != '%') 25445796c8dcSSimon Schubert { 25455796c8dcSSimon Schubert if (*sos == 'H') 25465796c8dcSSimon Schubert { 25475796c8dcSSimon Schubert dfp_len = 4; 25485796c8dcSSimon Schubert dfp_type = builtin_type (gdbarch)->builtin_decfloat; 25495796c8dcSSimon Schubert } 25505796c8dcSSimon Schubert else if (*sos == 'D' && *(sos - 1) == 'D') 25515796c8dcSSimon Schubert { 25525796c8dcSSimon Schubert dfp_len = 16; 25535796c8dcSSimon Schubert dfp_type = builtin_type (gdbarch)->builtin_declong; 25545796c8dcSSimon Schubert sos--; 25555796c8dcSSimon Schubert } 25565796c8dcSSimon Schubert else 25575796c8dcSSimon Schubert { 25585796c8dcSSimon Schubert dfp_len = 8; 25595796c8dcSSimon Schubert dfp_type = builtin_type (gdbarch)->builtin_decdouble; 25605796c8dcSSimon Schubert } 25615796c8dcSSimon Schubert } 25625796c8dcSSimon Schubert 25635796c8dcSSimon Schubert /* Replace %Hf, %Df and %DDf with %s's. */ 25645796c8dcSSimon Schubert *++sos = 's'; 25655796c8dcSSimon Schubert 25665796c8dcSSimon Schubert /* Go through the whole format string and pull the correct 25675796c8dcSSimon Schubert number of chars back to compensate for the change in the 25685796c8dcSSimon Schubert format specifier. */ 25695796c8dcSSimon Schubert while (nnull_chars < nargs - i) 25705796c8dcSSimon Schubert { 25715796c8dcSSimon Schubert if (*eos == '\0') 25725796c8dcSSimon Schubert nnull_chars++; 25735796c8dcSSimon Schubert 25745796c8dcSSimon Schubert *++sos = *++eos; 25755796c8dcSSimon Schubert } 25765796c8dcSSimon Schubert 25775796c8dcSSimon Schubert /* Conversion between different DFP types. */ 25785796c8dcSSimon Schubert if (TYPE_CODE (param_type) == TYPE_CODE_DECFLOAT) 25795796c8dcSSimon Schubert decimal_convert (param_ptr, param_len, byte_order, 25805796c8dcSSimon Schubert dec, dfp_len, byte_order); 25815796c8dcSSimon Schubert else 25825796c8dcSSimon Schubert /* If this is a non-trivial conversion, just output 0. 25835796c8dcSSimon Schubert A correct converted value can be displayed by explicitly 25845796c8dcSSimon Schubert casting to a DFP type. */ 25855796c8dcSSimon Schubert decimal_from_string (dec, dfp_len, byte_order, "0"); 25865796c8dcSSimon Schubert 25875796c8dcSSimon Schubert dfp_value = value_from_decfloat (dfp_type, dec); 25885796c8dcSSimon Schubert 25895796c8dcSSimon Schubert dfp_ptr = (gdb_byte *) value_contents (dfp_value); 25905796c8dcSSimon Schubert 25915796c8dcSSimon Schubert decimal_to_string (dfp_ptr, dfp_len, byte_order, decstr); 25925796c8dcSSimon Schubert 25935796c8dcSSimon Schubert /* Print the DFP value. */ 2594*cf7f2e2dSJohn Marino fprintf_filtered (stream, current_substring, decstr); 25955796c8dcSSimon Schubert 25965796c8dcSSimon Schubert break; 25975796c8dcSSimon Schubert #endif 25985796c8dcSSimon Schubert } 25995796c8dcSSimon Schubert 26005796c8dcSSimon Schubert case ptr_arg: 26015796c8dcSSimon Schubert { 26025796c8dcSSimon Schubert /* We avoid the host's %p because pointers are too 26035796c8dcSSimon Schubert likely to be the wrong size. The only interesting 26045796c8dcSSimon Schubert modifier for %p is a width; extract that, and then 26055796c8dcSSimon Schubert handle %p as glibc would: %#x or a literal "(nil)". */ 26065796c8dcSSimon Schubert 26075796c8dcSSimon Schubert char *p, *fmt, *fmt_p; 26085796c8dcSSimon Schubert #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG) 26095796c8dcSSimon Schubert long long val = value_as_long (val_args[i]); 26105796c8dcSSimon Schubert #else 26115796c8dcSSimon Schubert long val = value_as_long (val_args[i]); 26125796c8dcSSimon Schubert #endif 26135796c8dcSSimon Schubert 26145796c8dcSSimon Schubert fmt = alloca (strlen (current_substring) + 5); 26155796c8dcSSimon Schubert 26165796c8dcSSimon Schubert /* Copy up to the leading %. */ 26175796c8dcSSimon Schubert p = current_substring; 26185796c8dcSSimon Schubert fmt_p = fmt; 26195796c8dcSSimon Schubert while (*p) 26205796c8dcSSimon Schubert { 26215796c8dcSSimon Schubert int is_percent = (*p == '%'); 2622*cf7f2e2dSJohn Marino 26235796c8dcSSimon Schubert *fmt_p++ = *p++; 26245796c8dcSSimon Schubert if (is_percent) 26255796c8dcSSimon Schubert { 26265796c8dcSSimon Schubert if (*p == '%') 26275796c8dcSSimon Schubert *fmt_p++ = *p++; 26285796c8dcSSimon Schubert else 26295796c8dcSSimon Schubert break; 26305796c8dcSSimon Schubert } 26315796c8dcSSimon Schubert } 26325796c8dcSSimon Schubert 26335796c8dcSSimon Schubert if (val != 0) 26345796c8dcSSimon Schubert *fmt_p++ = '#'; 26355796c8dcSSimon Schubert 26365796c8dcSSimon Schubert /* Copy any width. */ 26375796c8dcSSimon Schubert while (*p >= '0' && *p < '9') 26385796c8dcSSimon Schubert *fmt_p++ = *p++; 26395796c8dcSSimon Schubert 26405796c8dcSSimon Schubert gdb_assert (*p == 'p' && *(p + 1) == '\0'); 26415796c8dcSSimon Schubert if (val != 0) 26425796c8dcSSimon Schubert { 26435796c8dcSSimon Schubert #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG) 26445796c8dcSSimon Schubert *fmt_p++ = 'l'; 26455796c8dcSSimon Schubert #endif 26465796c8dcSSimon Schubert *fmt_p++ = 'l'; 26475796c8dcSSimon Schubert *fmt_p++ = 'x'; 26485796c8dcSSimon Schubert *fmt_p++ = '\0'; 2649*cf7f2e2dSJohn Marino fprintf_filtered (stream, fmt, val); 26505796c8dcSSimon Schubert } 26515796c8dcSSimon Schubert else 26525796c8dcSSimon Schubert { 26535796c8dcSSimon Schubert *fmt_p++ = 's'; 26545796c8dcSSimon Schubert *fmt_p++ = '\0'; 2655*cf7f2e2dSJohn Marino fprintf_filtered (stream, fmt, "(nil)"); 26565796c8dcSSimon Schubert } 26575796c8dcSSimon Schubert 26585796c8dcSSimon Schubert break; 26595796c8dcSSimon Schubert } 26605796c8dcSSimon Schubert default: 26615796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 26625796c8dcSSimon Schubert _("failed internal consistency check")); 26635796c8dcSSimon Schubert } 26645796c8dcSSimon Schubert /* Skip to the next substring. */ 26655796c8dcSSimon Schubert current_substring += strlen (current_substring) + 1; 26665796c8dcSSimon Schubert } 2667*cf7f2e2dSJohn Marino /* Print the portion of the format string after the last argument. 2668*cf7f2e2dSJohn Marino Note that this will not include any ordinary %-specs, but it 2669*cf7f2e2dSJohn Marino might include "%%". That is why we use printf_filtered and not 2670*cf7f2e2dSJohn Marino puts_filtered here. Also, we pass a dummy argument because 2671*cf7f2e2dSJohn Marino some platforms have modified GCC to include -Wformat-security 2672*cf7f2e2dSJohn Marino by default, which will warn here if there is no argument. */ 2673*cf7f2e2dSJohn Marino fprintf_filtered (stream, last_arg, 0); 26745796c8dcSSimon Schubert } 26755796c8dcSSimon Schubert do_cleanups (old_cleanups); 26765796c8dcSSimon Schubert } 26775796c8dcSSimon Schubert 2678*cf7f2e2dSJohn Marino /* Implement the "printf" command. */ 2679*cf7f2e2dSJohn Marino 2680*cf7f2e2dSJohn Marino static void 2681*cf7f2e2dSJohn Marino printf_command (char *arg, int from_tty) 2682*cf7f2e2dSJohn Marino { 2683*cf7f2e2dSJohn Marino ui_printf (arg, gdb_stdout); 2684*cf7f2e2dSJohn Marino } 2685*cf7f2e2dSJohn Marino 2686*cf7f2e2dSJohn Marino /* Implement the "eval" command. */ 2687*cf7f2e2dSJohn Marino 2688*cf7f2e2dSJohn Marino static void 2689*cf7f2e2dSJohn Marino eval_command (char *arg, int from_tty) 2690*cf7f2e2dSJohn Marino { 2691*cf7f2e2dSJohn Marino struct ui_file *ui_out = mem_fileopen (); 2692*cf7f2e2dSJohn Marino struct cleanup *cleanups = make_cleanup_ui_file_delete (ui_out); 2693*cf7f2e2dSJohn Marino char *expanded; 2694*cf7f2e2dSJohn Marino 2695*cf7f2e2dSJohn Marino ui_printf (arg, ui_out); 2696*cf7f2e2dSJohn Marino 2697*cf7f2e2dSJohn Marino expanded = ui_file_xstrdup (ui_out, NULL); 2698*cf7f2e2dSJohn Marino make_cleanup (xfree, expanded); 2699*cf7f2e2dSJohn Marino 2700*cf7f2e2dSJohn Marino execute_command (expanded, from_tty); 2701*cf7f2e2dSJohn Marino 2702*cf7f2e2dSJohn Marino do_cleanups (cleanups); 2703*cf7f2e2dSJohn Marino } 2704*cf7f2e2dSJohn Marino 27055796c8dcSSimon Schubert void 27065796c8dcSSimon Schubert _initialize_printcmd (void) 27075796c8dcSSimon Schubert { 27085796c8dcSSimon Schubert struct cmd_list_element *c; 27095796c8dcSSimon Schubert 27105796c8dcSSimon Schubert current_display_number = -1; 27115796c8dcSSimon Schubert 27125796c8dcSSimon Schubert observer_attach_solib_unloaded (clear_dangling_display_expressions); 27135796c8dcSSimon Schubert 27145796c8dcSSimon Schubert add_info ("address", address_info, 27155796c8dcSSimon Schubert _("Describe where symbol SYM is stored.")); 27165796c8dcSSimon Schubert 27175796c8dcSSimon Schubert add_info ("symbol", sym_info, _("\ 27185796c8dcSSimon Schubert Describe what symbol is at location ADDR.\n\ 27195796c8dcSSimon Schubert Only for symbols with fixed locations (global or static scope).")); 27205796c8dcSSimon Schubert 27215796c8dcSSimon Schubert add_com ("x", class_vars, x_command, _("\ 27225796c8dcSSimon Schubert Examine memory: x/FMT ADDRESS.\n\ 27235796c8dcSSimon Schubert ADDRESS is an expression for the memory address to examine.\n\ 27245796c8dcSSimon Schubert FMT is a repeat count followed by a format letter and a size letter.\n\ 27255796c8dcSSimon Schubert Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\ 27265796c8dcSSimon Schubert t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\ 27275796c8dcSSimon Schubert Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\ 27285796c8dcSSimon Schubert The specified number of objects of the specified size are printed\n\ 27295796c8dcSSimon Schubert according to the format.\n\n\ 27305796c8dcSSimon Schubert Defaults for format and size letters are those previously used.\n\ 27315796c8dcSSimon Schubert Default count is 1. Default address is following last thing printed\n\ 27325796c8dcSSimon Schubert with this command or \"print\".")); 27335796c8dcSSimon Schubert 27345796c8dcSSimon Schubert #if 0 27355796c8dcSSimon Schubert add_com ("whereis", class_vars, whereis_command, 27365796c8dcSSimon Schubert _("Print line number and file of definition of variable.")); 27375796c8dcSSimon Schubert #endif 27385796c8dcSSimon Schubert 27395796c8dcSSimon Schubert add_info ("display", display_info, _("\ 27405796c8dcSSimon Schubert Expressions to display when program stops, with code numbers.")); 27415796c8dcSSimon Schubert 27425796c8dcSSimon Schubert add_cmd ("undisplay", class_vars, undisplay_command, _("\ 27435796c8dcSSimon Schubert Cancel some expressions to be displayed when program stops.\n\ 27445796c8dcSSimon Schubert Arguments are the code numbers of the expressions to stop displaying.\n\ 27455796c8dcSSimon Schubert No argument means cancel all automatic-display expressions.\n\ 27465796c8dcSSimon Schubert \"delete display\" has the same effect as this command.\n\ 27475796c8dcSSimon Schubert Do \"info display\" to see current list of code numbers."), 27485796c8dcSSimon Schubert &cmdlist); 27495796c8dcSSimon Schubert 27505796c8dcSSimon Schubert add_com ("display", class_vars, display_command, _("\ 27515796c8dcSSimon Schubert Print value of expression EXP each time the program stops.\n\ 27525796c8dcSSimon Schubert /FMT may be used before EXP as in the \"print\" command.\n\ 27535796c8dcSSimon Schubert /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\ 27545796c8dcSSimon Schubert as in the \"x\" command, and then EXP is used to get the address to examine\n\ 27555796c8dcSSimon Schubert and examining is done as in the \"x\" command.\n\n\ 27565796c8dcSSimon Schubert With no argument, display all currently requested auto-display expressions.\n\ 27575796c8dcSSimon Schubert Use \"undisplay\" to cancel display requests previously made.")); 27585796c8dcSSimon Schubert 27595796c8dcSSimon Schubert add_cmd ("display", class_vars, enable_display, _("\ 27605796c8dcSSimon Schubert Enable some expressions to be displayed when program stops.\n\ 27615796c8dcSSimon Schubert Arguments are the code numbers of the expressions to resume displaying.\n\ 27625796c8dcSSimon Schubert No argument means enable all automatic-display expressions.\n\ 27635796c8dcSSimon Schubert Do \"info display\" to see current list of code numbers."), &enablelist); 27645796c8dcSSimon Schubert 27655796c8dcSSimon Schubert add_cmd ("display", class_vars, disable_display_command, _("\ 27665796c8dcSSimon Schubert Disable some expressions to be displayed when program stops.\n\ 27675796c8dcSSimon Schubert Arguments are the code numbers of the expressions to stop displaying.\n\ 27685796c8dcSSimon Schubert No argument means disable all automatic-display expressions.\n\ 27695796c8dcSSimon Schubert Do \"info display\" to see current list of code numbers."), &disablelist); 27705796c8dcSSimon Schubert 27715796c8dcSSimon Schubert add_cmd ("display", class_vars, undisplay_command, _("\ 27725796c8dcSSimon Schubert Cancel some expressions to be displayed when program stops.\n\ 27735796c8dcSSimon Schubert Arguments are the code numbers of the expressions to stop displaying.\n\ 27745796c8dcSSimon Schubert No argument means cancel all automatic-display expressions.\n\ 27755796c8dcSSimon Schubert Do \"info display\" to see current list of code numbers."), &deletelist); 27765796c8dcSSimon Schubert 27775796c8dcSSimon Schubert add_com ("printf", class_vars, printf_command, _("\ 27785796c8dcSSimon Schubert printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ 27795796c8dcSSimon Schubert This is useful for formatted output in user-defined commands.")); 27805796c8dcSSimon Schubert 27815796c8dcSSimon Schubert add_com ("output", class_vars, output_command, _("\ 27825796c8dcSSimon Schubert Like \"print\" but don't put in value history and don't print newline.\n\ 27835796c8dcSSimon Schubert This is useful in user-defined commands.")); 27845796c8dcSSimon Schubert 27855796c8dcSSimon Schubert add_prefix_cmd ("set", class_vars, set_command, _("\ 27865796c8dcSSimon Schubert Evaluate expression EXP and assign result to variable VAR, using assignment\n\ 27875796c8dcSSimon Schubert syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ 27885796c8dcSSimon Schubert example). VAR may be a debugger \"convenience\" variable (names starting\n\ 27895796c8dcSSimon Schubert with $), a register (a few standard names starting with $), or an actual\n\ 27905796c8dcSSimon Schubert variable in the program being debugged. EXP is any valid expression.\n\ 27915796c8dcSSimon Schubert Use \"set variable\" for variables with names identical to set subcommands.\n\ 27925796c8dcSSimon Schubert \n\ 27935796c8dcSSimon Schubert With a subcommand, this command modifies parts of the gdb environment.\n\ 27945796c8dcSSimon Schubert You can see these environment settings with the \"show\" command."), 27955796c8dcSSimon Schubert &setlist, "set ", 1, &cmdlist); 27965796c8dcSSimon Schubert if (dbx_commands) 27975796c8dcSSimon Schubert add_com ("assign", class_vars, set_command, _("\ 27985796c8dcSSimon Schubert Evaluate expression EXP and assign result to variable VAR, using assignment\n\ 27995796c8dcSSimon Schubert syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ 28005796c8dcSSimon Schubert example). VAR may be a debugger \"convenience\" variable (names starting\n\ 28015796c8dcSSimon Schubert with $), a register (a few standard names starting with $), or an actual\n\ 28025796c8dcSSimon Schubert variable in the program being debugged. EXP is any valid expression.\n\ 28035796c8dcSSimon Schubert Use \"set variable\" for variables with names identical to set subcommands.\n\ 28045796c8dcSSimon Schubert \nWith a subcommand, this command modifies parts of the gdb environment.\n\ 28055796c8dcSSimon Schubert You can see these environment settings with the \"show\" command.")); 28065796c8dcSSimon Schubert 28075796c8dcSSimon Schubert /* "call" is the same as "set", but handy for dbx users to call fns. */ 28085796c8dcSSimon Schubert c = add_com ("call", class_vars, call_command, _("\ 28095796c8dcSSimon Schubert Call a function in the program.\n\ 28105796c8dcSSimon Schubert The argument is the function name and arguments, in the notation of the\n\ 28115796c8dcSSimon Schubert current working language. The result is printed and saved in the value\n\ 28125796c8dcSSimon Schubert history, if it is not void.")); 28135796c8dcSSimon Schubert set_cmd_completer (c, expression_completer); 28145796c8dcSSimon Schubert 28155796c8dcSSimon Schubert add_cmd ("variable", class_vars, set_command, _("\ 28165796c8dcSSimon Schubert Evaluate expression EXP and assign result to variable VAR, using assignment\n\ 28175796c8dcSSimon Schubert syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ 28185796c8dcSSimon Schubert example). VAR may be a debugger \"convenience\" variable (names starting\n\ 28195796c8dcSSimon Schubert with $), a register (a few standard names starting with $), or an actual\n\ 28205796c8dcSSimon Schubert variable in the program being debugged. EXP is any valid expression.\n\ 28215796c8dcSSimon Schubert This may usually be abbreviated to simply \"set\"."), 28225796c8dcSSimon Schubert &setlist); 28235796c8dcSSimon Schubert 28245796c8dcSSimon Schubert c = add_com ("print", class_vars, print_command, _("\ 28255796c8dcSSimon Schubert Print value of expression EXP.\n\ 28265796c8dcSSimon Schubert Variables accessible are those of the lexical environment of the selected\n\ 28275796c8dcSSimon Schubert stack frame, plus all those whose scope is global or an entire file.\n\ 28285796c8dcSSimon Schubert \n\ 28295796c8dcSSimon Schubert $NUM gets previous value number NUM. $ and $$ are the last two values.\n\ 28305796c8dcSSimon Schubert $$NUM refers to NUM'th value back from the last one.\n\ 28315796c8dcSSimon Schubert Names starting with $ refer to registers (with the values they would have\n\ 28325796c8dcSSimon Schubert if the program were to return to the stack frame now selected, restoring\n\ 28335796c8dcSSimon Schubert all registers saved by frames farther in) or else to debugger\n\ 28345796c8dcSSimon Schubert \"convenience\" variables (any such name not a known register).\n\ 28355796c8dcSSimon Schubert Use assignment expressions to give values to convenience variables.\n\ 28365796c8dcSSimon Schubert \n\ 28375796c8dcSSimon Schubert {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\ 28385796c8dcSSimon Schubert @ is a binary operator for treating consecutive data objects\n\ 28395796c8dcSSimon Schubert anywhere in memory as an array. FOO@NUM gives an array whose first\n\ 28405796c8dcSSimon Schubert element is FOO, whose second element is stored in the space following\n\ 28415796c8dcSSimon Schubert where FOO is stored, etc. FOO must be an expression whose value\n\ 28425796c8dcSSimon Schubert resides in memory.\n\ 28435796c8dcSSimon Schubert \n\ 28445796c8dcSSimon Schubert EXP may be preceded with /FMT, where FMT is a format letter\n\ 28455796c8dcSSimon Schubert but no count or size letter (see \"x\" command).")); 28465796c8dcSSimon Schubert set_cmd_completer (c, expression_completer); 28475796c8dcSSimon Schubert add_com_alias ("p", "print", class_vars, 1); 28485796c8dcSSimon Schubert 28495796c8dcSSimon Schubert c = add_com ("inspect", class_vars, inspect_command, _("\ 28505796c8dcSSimon Schubert Same as \"print\" command, except that if you are running in the epoch\n\ 28515796c8dcSSimon Schubert environment, the value is printed in its own window.")); 28525796c8dcSSimon Schubert set_cmd_completer (c, expression_completer); 28535796c8dcSSimon Schubert 28545796c8dcSSimon Schubert add_setshow_uinteger_cmd ("max-symbolic-offset", no_class, 28555796c8dcSSimon Schubert &max_symbolic_offset, _("\ 28565796c8dcSSimon Schubert Set the largest offset that will be printed in <symbol+1234> form."), _("\ 28575796c8dcSSimon Schubert Show the largest offset that will be printed in <symbol+1234> form."), NULL, 28585796c8dcSSimon Schubert NULL, 28595796c8dcSSimon Schubert show_max_symbolic_offset, 28605796c8dcSSimon Schubert &setprintlist, &showprintlist); 28615796c8dcSSimon Schubert add_setshow_boolean_cmd ("symbol-filename", no_class, 28625796c8dcSSimon Schubert &print_symbol_filename, _("\ 28635796c8dcSSimon Schubert Set printing of source filename and line number with <symbol>."), _("\ 28645796c8dcSSimon Schubert Show printing of source filename and line number with <symbol>."), NULL, 28655796c8dcSSimon Schubert NULL, 28665796c8dcSSimon Schubert show_print_symbol_filename, 28675796c8dcSSimon Schubert &setprintlist, &showprintlist); 2868*cf7f2e2dSJohn Marino 2869*cf7f2e2dSJohn Marino add_com ("eval", no_class, eval_command, _("\ 2870*cf7f2e2dSJohn Marino Convert \"printf format string\", arg1, arg2, arg3, ..., argn to\n\ 2871*cf7f2e2dSJohn Marino a command line, and call it.")); 28725796c8dcSSimon Schubert } 2873