printcmd.c revision 98944
119370Spst/* Print values for GNU debugger GDB. 219370Spst 398944Sobrien Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 498944Sobrien 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software 598944Sobrien Foundation, Inc. 619370Spst 798944Sobrien This file is part of GDB. 819370Spst 998944Sobrien This program is free software; you can redistribute it and/or modify 1098944Sobrien it under the terms of the GNU General Public License as published by 1198944Sobrien the Free Software Foundation; either version 2 of the License, or 1298944Sobrien (at your option) any later version. 1319370Spst 1498944Sobrien This program is distributed in the hope that it will be useful, 1598944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1698944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1798944Sobrien GNU General Public License for more details. 1819370Spst 1998944Sobrien You should have received a copy of the GNU General Public License 2098944Sobrien along with this program; if not, write to the Free Software 2198944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2298944Sobrien Boston, MA 02111-1307, USA. */ 2398944Sobrien 2419370Spst#include "defs.h" 2519370Spst#include "gdb_string.h" 2619370Spst#include "frame.h" 2719370Spst#include "symtab.h" 2819370Spst#include "gdbtypes.h" 2919370Spst#include "value.h" 3019370Spst#include "language.h" 3119370Spst#include "expression.h" 3219370Spst#include "gdbcore.h" 3319370Spst#include "gdbcmd.h" 3419370Spst#include "target.h" 3519370Spst#include "breakpoint.h" 3619370Spst#include "demangle.h" 3719370Spst#include "valprint.h" 3819370Spst#include "annotate.h" 3998944Sobrien#include "symfile.h" /* for overlay functions */ 4098944Sobrien#include "objfiles.h" /* ditto */ 4198944Sobrien#include "completer.h" /* for completion functions */ 4298944Sobrien#include "ui-out.h" 4319370Spst 4419370Spstextern int asm_demangle; /* Whether to demangle syms in asm printouts */ 4519370Spstextern int addressprint; /* Whether to print hex addresses in HLL " */ 4619370Spst 4719370Spststruct format_data 4898944Sobrien { 4998944Sobrien int count; 5098944Sobrien char format; 5198944Sobrien char size; 5298944Sobrien }; 5319370Spst 5419370Spst/* Last specified output format. */ 5519370Spst 5619370Spststatic char last_format = 'x'; 5719370Spst 5819370Spst/* Last specified examination size. 'b', 'h', 'w' or `q'. */ 5919370Spst 6019370Spststatic char last_size = 'w'; 6119370Spst 6219370Spst/* Default address to examine next. */ 6319370Spst 6419370Spststatic CORE_ADDR next_address; 6519370Spst 6646283Sdfr/* Default section to examine next. */ 6746283Sdfr 6846283Sdfrstatic asection *next_section; 6946283Sdfr 7019370Spst/* Last address examined. */ 7119370Spst 7219370Spststatic CORE_ADDR last_examine_address; 7319370Spst 7419370Spst/* Contents of last address examined. 7519370Spst This is not valid past the end of the `x' command! */ 7619370Spst 7798944Sobrienstatic struct value *last_examine_value; 7819370Spst 7919370Spst/* Largest offset between a symbolic value and an address, that will be 8019370Spst printed as `0x1234 <symbol+offset>'. */ 8119370Spst 8219370Spststatic unsigned int max_symbolic_offset = UINT_MAX; 8319370Spst 8419370Spst/* Append the source filename and linenumber of the symbol when 8519370Spst printing a symbolic value as `<symbol at filename:linenum>' if set. */ 8619370Spststatic int print_symbol_filename = 0; 8719370Spst 8819370Spst/* Number of auto-display expression currently being displayed. 8919370Spst So that we can disable it if we get an error or a signal within it. 9019370Spst -1 when not doing one. */ 9119370Spst 9219370Spstint current_display_number; 9319370Spst 9419370Spst/* Flag to low-level print routines that this value is being printed 9519370Spst in an epoch window. We'd like to pass this as a parameter, but 9619370Spst every routine would need to take it. Perhaps we can encapsulate 9719370Spst this in the I/O stream once we have GNU stdio. */ 9819370Spst 9919370Spstint inspect_it = 0; 10019370Spst 10119370Spststruct display 10298944Sobrien { 10398944Sobrien /* Chain link to next auto-display item. */ 10498944Sobrien struct display *next; 10598944Sobrien /* Expression to be evaluated and displayed. */ 10698944Sobrien struct expression *exp; 10798944Sobrien /* Item number of this auto-display item. */ 10898944Sobrien int number; 10998944Sobrien /* Display format specified. */ 11098944Sobrien struct format_data format; 11198944Sobrien /* Innermost block required by this expression when evaluated */ 11298944Sobrien struct block *block; 11398944Sobrien /* Status of this display (enabled or disabled) */ 11498944Sobrien int enabled_p; 11598944Sobrien }; 11619370Spst 11719370Spst/* Chain of expressions whose values should be displayed 11819370Spst automatically each time the program stops. */ 11919370Spst 12019370Spststatic struct display *display_chain; 12119370Spst 12219370Spststatic int display_number; 12319370Spst 12446283Sdfr/* Prototypes for exported functions. */ 12519370Spst 12698944Sobrienvoid output_command (char *, int); 12719370Spst 12898944Sobrienvoid _initialize_printcmd (void); 12919370Spst 13046283Sdfr/* Prototypes for local functions. */ 13146283Sdfr 13298944Sobrienstatic void delete_display (int); 13319370Spst 13498944Sobrienstatic void enable_display (char *, int); 13519370Spst 13698944Sobrienstatic void disable_display_command (char *, int); 13719370Spst 13898944Sobrienstatic void disassemble_command (char *, int); 13919370Spst 14098944Sobrienstatic void printf_command (char *, int); 14119370Spst 14298944Sobrienstatic void print_frame_nameless_args (struct frame_info *, long, 14398944Sobrien int, int, struct ui_file *); 14419370Spst 14598944Sobrienstatic void display_info (char *, int); 14619370Spst 14798944Sobrienstatic void do_one_display (struct display *); 14819370Spst 14998944Sobrienstatic void undisplay_command (char *, int); 15019370Spst 15198944Sobrienstatic void free_display (struct display *); 15219370Spst 15398944Sobrienstatic void display_command (char *, int); 15419370Spst 15598944Sobrienvoid x_command (char *, int); 15619370Spst 15798944Sobrienstatic void address_info (char *, int); 15819370Spst 15998944Sobrienstatic void set_command (char *, int); 16019370Spst 16198944Sobrienstatic void call_command (char *, int); 16219370Spst 16398944Sobrienstatic void inspect_command (char *, int); 16419370Spst 16598944Sobrienstatic void print_command (char *, int); 16619370Spst 16798944Sobrienstatic void print_command_1 (char *, int, int); 16819370Spst 16998944Sobrienstatic void validate_format (struct format_data, char *); 17019370Spst 17198944Sobrienstatic void do_examine (struct format_data, CORE_ADDR addr, 17298944Sobrien asection * section); 17319370Spst 17498944Sobrienstatic void print_formatted (struct value *, int, int, struct ui_file *); 17519370Spst 17698944Sobrienstatic struct format_data decode_format (char **, int, int); 17719370Spst 17898944Sobrienstatic int print_insn (CORE_ADDR, struct ui_file *); 17919370Spst 18098944Sobrienstatic void sym_info (char *, int); 18198944Sobrien 18246283Sdfr 18319370Spst/* Decode a format specification. *STRING_PTR should point to it. 18419370Spst OFORMAT and OSIZE are used as defaults for the format and size 18519370Spst if none are given in the format specification. 18619370Spst If OSIZE is zero, then the size field of the returned value 18719370Spst should be set only if a size is explicitly specified by the 18819370Spst user. 18919370Spst The structure returned describes all the data 19019370Spst found in the specification. In addition, *STRING_PTR is advanced 19119370Spst past the specification and past all whitespace following it. */ 19219370Spst 19319370Spststatic struct format_data 19498944Sobriendecode_format (char **string_ptr, int oformat, int osize) 19519370Spst{ 19619370Spst struct format_data val; 19719370Spst register char *p = *string_ptr; 19819370Spst 19919370Spst val.format = '?'; 20019370Spst val.size = '?'; 20119370Spst val.count = 1; 20219370Spst 20319370Spst if (*p >= '0' && *p <= '9') 20419370Spst val.count = atoi (p); 20598944Sobrien while (*p >= '0' && *p <= '9') 20698944Sobrien p++; 20719370Spst 20819370Spst /* Now process size or format letters that follow. */ 20919370Spst 21019370Spst while (1) 21119370Spst { 21219370Spst if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g') 21319370Spst val.size = *p++; 21419370Spst else if (*p >= 'a' && *p <= 'z') 21519370Spst val.format = *p++; 21619370Spst else 21719370Spst break; 21819370Spst } 21919370Spst 22098944Sobrien while (*p == ' ' || *p == '\t') 22198944Sobrien p++; 22219370Spst *string_ptr = p; 22319370Spst 22419370Spst /* Set defaults for format and size if not specified. */ 22519370Spst if (val.format == '?') 22619370Spst { 22719370Spst if (val.size == '?') 22819370Spst { 22919370Spst /* Neither has been specified. */ 23019370Spst val.format = oformat; 23119370Spst val.size = osize; 23219370Spst } 23319370Spst else 23419370Spst /* If a size is specified, any format makes a reasonable 23519370Spst default except 'i'. */ 23619370Spst val.format = oformat == 'i' ? 'x' : oformat; 23719370Spst } 23819370Spst else if (val.size == '?') 23919370Spst switch (val.format) 24019370Spst { 24119370Spst case 'a': 24219370Spst case 's': 24319370Spst /* Pick the appropriate size for an address. */ 24419370Spst if (TARGET_PTR_BIT == 64) 24519370Spst val.size = osize ? 'g' : osize; 24619370Spst else if (TARGET_PTR_BIT == 32) 24719370Spst val.size = osize ? 'w' : osize; 24819370Spst else if (TARGET_PTR_BIT == 16) 24919370Spst val.size = osize ? 'h' : osize; 25019370Spst else 25119370Spst /* Bad value for TARGET_PTR_BIT */ 25298944Sobrien internal_error (__FILE__, __LINE__, "failed internal consistency check"); 25319370Spst break; 25419370Spst case 'f': 25519370Spst /* Floating point has to be word or giantword. */ 25619370Spst if (osize == 'w' || osize == 'g') 25719370Spst val.size = osize; 25819370Spst else 25919370Spst /* Default it to giantword if the last used size is not 26019370Spst appropriate. */ 26119370Spst val.size = osize ? 'g' : osize; 26219370Spst break; 26319370Spst case 'c': 26419370Spst /* Characters default to one byte. */ 26519370Spst val.size = osize ? 'b' : osize; 26619370Spst break; 26719370Spst default: 26819370Spst /* The default is the size most recently specified. */ 26919370Spst val.size = osize; 27019370Spst } 27119370Spst 27219370Spst return val; 27319370Spst} 27419370Spst 27598944Sobrien/* Print value VAL on stream according to FORMAT, a letter or 0. 27619370Spst Do not end with a newline. 27719370Spst 0 means print VAL according to its own type. 27819370Spst SIZE is the letter for the size of datum being printed. 27919370Spst This is used to pad hex numbers so they line up. */ 28019370Spst 28119370Spststatic void 28298944Sobrienprint_formatted (struct value *val, register int format, int size, 28398944Sobrien struct ui_file *stream) 28419370Spst{ 28519370Spst struct type *type = check_typedef (VALUE_TYPE (val)); 28619370Spst int len = TYPE_LENGTH (type); 28719370Spst 28819370Spst if (VALUE_LVAL (val) == lval_memory) 28946283Sdfr { 29046283Sdfr next_address = VALUE_ADDRESS (val) + len; 29146283Sdfr next_section = VALUE_BFD_SECTION (val); 29246283Sdfr } 29319370Spst 29419370Spst switch (format) 29519370Spst { 29619370Spst case 's': 29746283Sdfr /* FIXME: Need to handle wchar_t's here... */ 29819370Spst next_address = VALUE_ADDRESS (val) 29998944Sobrien + val_print_string (VALUE_ADDRESS (val), -1, 1, stream); 30046283Sdfr next_section = VALUE_BFD_SECTION (val); 30119370Spst break; 30219370Spst 30319370Spst case 'i': 30419370Spst /* The old comment says 30598944Sobrien "Force output out, print_insn not using _filtered". 30698944Sobrien I'm not completely sure what that means, I suspect most print_insn 30798944Sobrien now do use _filtered, so I guess it's obsolete. 30898944Sobrien --Yes, it does filter now, and so this is obsolete. -JB */ 30946283Sdfr 31019370Spst /* We often wrap here if there are long symbolic names. */ 31119370Spst wrap_here (" "); 31219370Spst next_address = VALUE_ADDRESS (val) 31398944Sobrien + print_insn (VALUE_ADDRESS (val), stream); 31446283Sdfr next_section = VALUE_BFD_SECTION (val); 31519370Spst break; 31619370Spst 31719370Spst default: 31819370Spst if (format == 0 31919370Spst || TYPE_CODE (type) == TYPE_CODE_ARRAY 32019370Spst || TYPE_CODE (type) == TYPE_CODE_STRING 32119370Spst || TYPE_CODE (type) == TYPE_CODE_STRUCT 32219370Spst || TYPE_CODE (type) == TYPE_CODE_UNION) 32398944Sobrien /* If format is 0, use the 'natural' format for 32498944Sobrien * that type of value. If the type is non-scalar, 32598944Sobrien * we have to use language rules to print it as 32698944Sobrien * a series of scalars. 32798944Sobrien */ 32898944Sobrien value_print (val, stream, format, Val_pretty_default); 32919370Spst else 33098944Sobrien /* User specified format, so don't look to the 33198944Sobrien * the type to tell us what to do. 33298944Sobrien */ 33319370Spst print_scalar_formatted (VALUE_CONTENTS (val), type, 33498944Sobrien format, size, stream); 33519370Spst } 33619370Spst} 33719370Spst 33819370Spst/* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR, 33919370Spst according to letters FORMAT and SIZE on STREAM. 34019370Spst FORMAT may not be zero. Formats s and i are not supported at this level. 34119370Spst 34219370Spst This is how the elements of an array or structure are printed 34319370Spst with a format. */ 34419370Spst 34519370Spstvoid 34698944Sobrienprint_scalar_formatted (char *valaddr, struct type *type, int format, int size, 34798944Sobrien struct ui_file *stream) 34819370Spst{ 34919370Spst LONGEST val_long; 35019370Spst unsigned int len = TYPE_LENGTH (type); 35119370Spst 35219370Spst if (len > sizeof (LONGEST) 35319370Spst && (format == 't' 35419370Spst || format == 'c' 35519370Spst || format == 'o' 35619370Spst || format == 'u' 35719370Spst || format == 'd' 35819370Spst || format == 'x')) 35919370Spst { 36098944Sobrien if (!TYPE_UNSIGNED (type) 36198944Sobrien || !extract_long_unsigned_integer (valaddr, len, &val_long)) 36219370Spst { 36319370Spst /* We can't print it normally, but we can print it in hex. 36419370Spst Printing it in the wrong radix is more useful than saying 36519370Spst "use /x, you dummy". */ 36619370Spst /* FIXME: we could also do octal or binary if that was the 36719370Spst desired format. */ 36819370Spst /* FIXME: we should be using the size field to give us a 36919370Spst minimum field width to print. */ 37046283Sdfr 37198944Sobrien if (format == 'o') 37298944Sobrien print_octal_chars (stream, valaddr, len); 37398944Sobrien else if (format == 'd') 37498944Sobrien print_decimal_chars (stream, valaddr, len); 37598944Sobrien else if (format == 't') 37698944Sobrien print_binary_chars (stream, valaddr, len); 37798944Sobrien else 37898944Sobrien /* replace with call to print_hex_chars? Looks 37998944Sobrien like val_print_type_code_int is redoing 38098944Sobrien work. - edie */ 38146283Sdfr 38298944Sobrien val_print_type_code_int (type, valaddr, stream); 38346283Sdfr 38419370Spst return; 38519370Spst } 38619370Spst 38719370Spst /* If we get here, extract_long_unsigned_integer set val_long. */ 38819370Spst } 38919370Spst else if (format != 'f') 39019370Spst val_long = unpack_long (type, valaddr); 39119370Spst 39298944Sobrien /* If the value is a pointer, and pointers and addresses are not the 39398944Sobrien same, then at this point, the value's length is TARGET_ADDR_BIT, not 39498944Sobrien TYPE_LENGTH (type). */ 39598944Sobrien if (TYPE_CODE (type) == TYPE_CODE_PTR) 39698944Sobrien len = TARGET_ADDR_BIT; 39798944Sobrien 39819370Spst /* If we are printing it as unsigned, truncate it in case it is actually 39919370Spst a negative signed value (e.g. "print/u (short)-1" should print 65535 40019370Spst (if shorts are 16 bits) instead of 4294967295). */ 40119370Spst if (format != 'd') 40219370Spst { 40319370Spst if (len < sizeof (LONGEST)) 40419370Spst val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1; 40519370Spst } 40619370Spst 40719370Spst switch (format) 40819370Spst { 40919370Spst case 'x': 41019370Spst if (!size) 41119370Spst { 41219370Spst /* no size specified, like in print. Print varying # of digits. */ 41319370Spst print_longest (stream, 'x', 1, val_long); 41419370Spst } 41519370Spst else 41619370Spst switch (size) 41719370Spst { 41819370Spst case 'b': 41919370Spst case 'h': 42019370Spst case 'w': 42119370Spst case 'g': 42219370Spst print_longest (stream, size, 1, val_long); 42319370Spst break; 42419370Spst default: 42519370Spst error ("Undefined output size \"%c\".", size); 42619370Spst } 42719370Spst break; 42819370Spst 42919370Spst case 'd': 43019370Spst print_longest (stream, 'd', 1, val_long); 43119370Spst break; 43219370Spst 43319370Spst case 'u': 43419370Spst print_longest (stream, 'u', 0, val_long); 43519370Spst break; 43619370Spst 43719370Spst case 'o': 43819370Spst if (val_long) 43919370Spst print_longest (stream, 'o', 1, val_long); 44019370Spst else 44119370Spst fprintf_filtered (stream, "0"); 44219370Spst break; 44319370Spst 44419370Spst case 'a': 44598944Sobrien { 44698944Sobrien CORE_ADDR addr = unpack_pointer (type, valaddr); 44798944Sobrien print_address (addr, stream); 44898944Sobrien } 44919370Spst break; 45019370Spst 45119370Spst case 'c': 45298944Sobrien value_print (value_from_longest (builtin_type_true_char, val_long), 45398944Sobrien stream, 0, Val_pretty_default); 45419370Spst break; 45519370Spst 45619370Spst case 'f': 45798944Sobrien if (len == TYPE_LENGTH (builtin_type_float)) 45898944Sobrien type = builtin_type_float; 45998944Sobrien else if (len == TYPE_LENGTH (builtin_type_double)) 46098944Sobrien type = builtin_type_double; 46198944Sobrien else if (len == TYPE_LENGTH (builtin_type_long_double)) 46298944Sobrien type = builtin_type_long_double; 46319370Spst print_floating (valaddr, type, stream); 46419370Spst break; 46519370Spst 46619370Spst case 0: 46798944Sobrien internal_error (__FILE__, __LINE__, "failed internal consistency check"); 46819370Spst 46919370Spst case 't': 47019370Spst /* Binary; 't' stands for "two". */ 47119370Spst { 47298944Sobrien char bits[8 * (sizeof val_long) + 1]; 47398944Sobrien char buf[8 * (sizeof val_long) + 32]; 47419370Spst char *cp = bits; 47519370Spst int width; 47619370Spst 47798944Sobrien if (!size) 47898944Sobrien width = 8 * (sizeof val_long); 47998944Sobrien else 48098944Sobrien switch (size) 48119370Spst { 48219370Spst case 'b': 48319370Spst width = 8; 48419370Spst break; 48519370Spst case 'h': 48619370Spst width = 16; 48719370Spst break; 48819370Spst case 'w': 48919370Spst width = 32; 49019370Spst break; 49119370Spst case 'g': 49219370Spst width = 64; 49319370Spst break; 49419370Spst default: 49519370Spst error ("Undefined output size \"%c\".", size); 49619370Spst } 49719370Spst 49898944Sobrien bits[width] = '\0'; 49998944Sobrien while (width-- > 0) 50098944Sobrien { 50198944Sobrien bits[width] = (val_long & 1) ? '1' : '0'; 50298944Sobrien val_long >>= 1; 50398944Sobrien } 50419370Spst if (!size) 50519370Spst { 50619370Spst while (*cp && *cp == '0') 50719370Spst cp++; 50819370Spst if (*cp == '\0') 50919370Spst cp--; 51019370Spst } 51198944Sobrien strcpy (buf, local_binary_format_prefix ()); 51246283Sdfr strcat (buf, cp); 51398944Sobrien strcat (buf, local_binary_format_suffix ()); 51498944Sobrien fprintf_filtered (stream, buf); 51519370Spst } 51619370Spst break; 51719370Spst 51819370Spst default: 51919370Spst error ("Undefined output format \"%c\".", format); 52019370Spst } 52119370Spst} 52219370Spst 52319370Spst/* Specify default address for `x' command. 52419370Spst `info lines' uses this. */ 52519370Spst 52619370Spstvoid 52798944Sobrienset_next_address (CORE_ADDR addr) 52819370Spst{ 52919370Spst next_address = addr; 53019370Spst 53119370Spst /* Make address available to the user as $_. */ 53219370Spst set_internalvar (lookup_internalvar ("_"), 53398944Sobrien value_from_pointer (lookup_pointer_type (builtin_type_void), 53498944Sobrien addr)); 53519370Spst} 53619370Spst 53719370Spst/* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM, 53819370Spst after LEADIN. Print nothing if no symbolic name is found nearby. 53919370Spst Optionally also print source file and line number, if available. 54019370Spst DO_DEMANGLE controls whether to print a symbol in its native "raw" form, 54119370Spst or to interpret it as a possible C++ name and convert it back to source 54219370Spst form. However note that DO_DEMANGLE can be overridden by the specific 54319370Spst settings of the demangle and asm_demangle variables. */ 54419370Spst 54519370Spstvoid 54698944Sobrienprint_address_symbolic (CORE_ADDR addr, struct ui_file *stream, int do_demangle, 54798944Sobrien char *leadin) 54819370Spst{ 54998944Sobrien char *name = NULL; 55098944Sobrien char *filename = NULL; 55198944Sobrien int unmapped = 0; 55298944Sobrien int offset = 0; 55398944Sobrien int line = 0; 55498944Sobrien 55598944Sobrien /* throw away both name and filename */ 55698944Sobrien struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name); 55798944Sobrien make_cleanup (free_current_contents, &filename); 55898944Sobrien 55998944Sobrien if (build_address_symbolic (addr, do_demangle, &name, &offset, &filename, &line, &unmapped)) 56098944Sobrien { 56198944Sobrien do_cleanups (cleanup_chain); 56298944Sobrien return; 56398944Sobrien } 56498944Sobrien 56598944Sobrien fputs_filtered (leadin, stream); 56698944Sobrien if (unmapped) 56798944Sobrien fputs_filtered ("<*", stream); 56898944Sobrien else 56998944Sobrien fputs_filtered ("<", stream); 57098944Sobrien fputs_filtered (name, stream); 57198944Sobrien if (offset != 0) 57298944Sobrien fprintf_filtered (stream, "+%u", (unsigned int) offset); 57398944Sobrien 57498944Sobrien /* Append source filename and line number if desired. Give specific 57598944Sobrien line # of this addr, if we have it; else line # of the nearest symbol. */ 57698944Sobrien if (print_symbol_filename && filename != NULL) 57798944Sobrien { 57898944Sobrien if (line != -1) 57998944Sobrien fprintf_filtered (stream, " at %s:%d", filename, line); 58098944Sobrien else 58198944Sobrien fprintf_filtered (stream, " in %s", filename); 58298944Sobrien } 58398944Sobrien if (unmapped) 58498944Sobrien fputs_filtered ("*>", stream); 58598944Sobrien else 58698944Sobrien fputs_filtered (">", stream); 58798944Sobrien 58898944Sobrien do_cleanups (cleanup_chain); 58998944Sobrien} 59098944Sobrien 59198944Sobrien/* Given an address ADDR return all the elements needed to print the 59298944Sobrien address in a symbolic form. NAME can be mangled or not depending 59398944Sobrien on DO_DEMANGLE (and also on the asm_demangle global variable, 59498944Sobrien manipulated via ''set print asm-demangle''). Return 0 in case of 59598944Sobrien success, when all the info in the OUT paramters is valid. Return 1 59698944Sobrien otherwise. */ 59798944Sobrienint 59898944Sobrienbuild_address_symbolic (CORE_ADDR addr, /* IN */ 59998944Sobrien int do_demangle, /* IN */ 60098944Sobrien char **name, /* OUT */ 60198944Sobrien int *offset, /* OUT */ 60298944Sobrien char **filename, /* OUT */ 60398944Sobrien int *line, /* OUT */ 60498944Sobrien int *unmapped) /* OUT */ 60598944Sobrien{ 60619370Spst struct minimal_symbol *msymbol; 60719370Spst struct symbol *symbol; 60819370Spst struct symtab *symtab = 0; 60919370Spst CORE_ADDR name_location = 0; 61046283Sdfr asection *section = 0; 61198944Sobrien char *name_temp = ""; 61298944Sobrien 61398944Sobrien /* Let's say it is unmapped. */ 61498944Sobrien *unmapped = 0; 61519370Spst 61698944Sobrien /* Determine if the address is in an overlay, and whether it is 61798944Sobrien mapped. */ 61846283Sdfr if (overlay_debugging) 61946283Sdfr { 62046283Sdfr section = find_pc_overlay (addr); 62146283Sdfr if (pc_in_unmapped_range (addr, section)) 62246283Sdfr { 62398944Sobrien *unmapped = 1; 62446283Sdfr addr = overlay_mapped_address (addr, section); 62546283Sdfr } 62646283Sdfr } 62746283Sdfr 62846283Sdfr /* On some targets, add in extra "flag" bits to PC for 62946283Sdfr disassembly. This should ensure that "rounding errors" in 63046283Sdfr symbol addresses that are masked for disassembly favour the 63146283Sdfr the correct symbol. */ 63246283Sdfr 63346283Sdfr#ifdef GDB_TARGET_UNMASK_DISAS_PC 63446283Sdfr addr = GDB_TARGET_UNMASK_DISAS_PC (addr); 63546283Sdfr#endif 63646283Sdfr 63719370Spst /* First try to find the address in the symbol table, then 63819370Spst in the minsyms. Take the closest one. */ 63919370Spst 64019370Spst /* This is defective in the sense that it only finds text symbols. So 64119370Spst really this is kind of pointless--we should make sure that the 64219370Spst minimal symbols have everything we need (by changing that we could 64319370Spst save some memory, but for many debug format--ELF/DWARF or 64419370Spst anything/stabs--it would be inconvenient to eliminate those minimal 64519370Spst symbols anyway). */ 64646283Sdfr msymbol = lookup_minimal_symbol_by_pc_section (addr, section); 64746283Sdfr symbol = find_pc_sect_function (addr, section); 64819370Spst 64919370Spst if (symbol) 65019370Spst { 65146283Sdfr name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)); 65219370Spst if (do_demangle) 65398944Sobrien name_temp = SYMBOL_SOURCE_NAME (symbol); 65419370Spst else 65598944Sobrien name_temp = SYMBOL_LINKAGE_NAME (symbol); 65619370Spst } 65719370Spst 65819370Spst if (msymbol != NULL) 65919370Spst { 66019370Spst if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL) 66119370Spst { 66219370Spst /* The msymbol is closer to the address than the symbol; 66319370Spst use the msymbol instead. */ 66419370Spst symbol = 0; 66519370Spst symtab = 0; 66619370Spst name_location = SYMBOL_VALUE_ADDRESS (msymbol); 66719370Spst if (do_demangle) 66898944Sobrien name_temp = SYMBOL_SOURCE_NAME (msymbol); 66919370Spst else 67098944Sobrien name_temp = SYMBOL_LINKAGE_NAME (msymbol); 67119370Spst } 67219370Spst } 67319370Spst if (symbol == NULL && msymbol == NULL) 67498944Sobrien return 1; 67519370Spst 67646283Sdfr /* On some targets, mask out extra "flag" bits from PC for handsome 67746283Sdfr disassembly. */ 67846283Sdfr 67946283Sdfr#ifdef GDB_TARGET_MASK_DISAS_PC 68046283Sdfr name_location = GDB_TARGET_MASK_DISAS_PC (name_location); 68146283Sdfr addr = GDB_TARGET_MASK_DISAS_PC (addr); 68246283Sdfr#endif 68346283Sdfr 68419370Spst /* If the nearest symbol is too far away, don't print anything symbolic. */ 68519370Spst 68619370Spst /* For when CORE_ADDR is larger than unsigned int, we do math in 68719370Spst CORE_ADDR. But when we detect unsigned wraparound in the 68819370Spst CORE_ADDR math, we ignore this test and print the offset, 68919370Spst because addr+max_symbolic_offset has wrapped through the end 69019370Spst of the address space back to the beginning, giving bogus comparison. */ 69119370Spst if (addr > name_location + max_symbolic_offset 69219370Spst && name_location + max_symbolic_offset > name_location) 69398944Sobrien return 1; 69419370Spst 69598944Sobrien *offset = addr - name_location; 69619370Spst 69798944Sobrien *name = xstrdup (name_temp); 69898944Sobrien 69919370Spst if (print_symbol_filename) 70019370Spst { 70119370Spst struct symtab_and_line sal; 70219370Spst 70346283Sdfr sal = find_pc_sect_line (addr, section, 0); 70446283Sdfr 70519370Spst if (sal.symtab) 70698944Sobrien { 70798944Sobrien *filename = xstrdup (sal.symtab->filename); 70898944Sobrien *line = sal.line; 70998944Sobrien } 71019370Spst else if (symtab && symbol && symbol->line) 71198944Sobrien { 71298944Sobrien *filename = xstrdup (symtab->filename); 71398944Sobrien *line = symbol->line; 71498944Sobrien } 71519370Spst else if (symtab) 71698944Sobrien { 71798944Sobrien *filename = xstrdup (symtab->filename); 71898944Sobrien *line = -1; 71998944Sobrien } 72019370Spst } 72198944Sobrien return 0; 72219370Spst} 72319370Spst 72419370Spst/* Print address ADDR on STREAM. USE_LOCAL means the same thing as for 72519370Spst print_longest. */ 72619370Spstvoid 72798944Sobrienprint_address_numeric (CORE_ADDR addr, int use_local, struct ui_file *stream) 72819370Spst{ 72998944Sobrien /* Truncate address to the size of a target address, avoiding shifts 73098944Sobrien larger or equal than the width of a CORE_ADDR. The local 73198944Sobrien variable ADDR_BIT stops the compiler reporting a shift overflow 73298944Sobrien when it won't occur. */ 73398944Sobrien /* NOTE: This assumes that the significant address information is 73498944Sobrien kept in the least significant bits of ADDR - the upper bits were 73598944Sobrien either zero or sign extended. Should ADDRESS_TO_POINTER() or 73698944Sobrien some ADDRESS_TO_PRINTABLE() be used to do the conversion? */ 73798944Sobrien 73898944Sobrien int addr_bit = TARGET_ADDR_BIT; 73998944Sobrien 74098944Sobrien if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT)) 74198944Sobrien addr &= ((CORE_ADDR) 1 << addr_bit) - 1; 74246283Sdfr print_longest (stream, 'x', use_local, (ULONGEST) addr); 74319370Spst} 74419370Spst 74519370Spst/* Print address ADDR symbolically on STREAM. 74619370Spst First print it as a number. Then perhaps print 74719370Spst <SYMBOL + OFFSET> after the number. */ 74819370Spst 74919370Spstvoid 75098944Sobrienprint_address (CORE_ADDR addr, struct ui_file *stream) 75119370Spst{ 75219370Spst print_address_numeric (addr, 1, stream); 75319370Spst print_address_symbolic (addr, stream, asm_demangle, " "); 75419370Spst} 75519370Spst 75619370Spst/* Print address ADDR symbolically on STREAM. Parameter DEMANGLE 75719370Spst controls whether to print the symbolic name "raw" or demangled. 75819370Spst Global setting "addressprint" controls whether to print hex address 75919370Spst or not. */ 76019370Spst 76119370Spstvoid 76298944Sobrienprint_address_demangle (CORE_ADDR addr, struct ui_file *stream, int do_demangle) 76319370Spst{ 76419370Spst if (addr == 0) 76519370Spst { 76619370Spst fprintf_filtered (stream, "0"); 76719370Spst } 76819370Spst else if (addressprint) 76919370Spst { 77019370Spst print_address_numeric (addr, 1, stream); 77119370Spst print_address_symbolic (addr, stream, do_demangle, " "); 77219370Spst } 77319370Spst else 77419370Spst { 77519370Spst print_address_symbolic (addr, stream, do_demangle, ""); 77619370Spst } 77719370Spst} 77819370Spst 77919370Spst 78019370Spst/* These are the types that $__ will get after an examine command of one 78119370Spst of these sizes. */ 78219370Spst 78346283Sdfrstatic struct type *examine_i_type; 78446283Sdfr 78519370Spststatic struct type *examine_b_type; 78619370Spststatic struct type *examine_h_type; 78719370Spststatic struct type *examine_w_type; 78819370Spststatic struct type *examine_g_type; 78919370Spst 79019370Spst/* Examine data at address ADDR in format FMT. 79119370Spst Fetch it from memory and print on gdb_stdout. */ 79219370Spst 79319370Spststatic void 79498944Sobriendo_examine (struct format_data fmt, CORE_ADDR addr, asection *sect) 79519370Spst{ 79619370Spst register char format = 0; 79719370Spst register char size; 79819370Spst register int count = 1; 79919370Spst struct type *val_type = NULL; 80019370Spst register int i; 80119370Spst register int maxelts; 80219370Spst 80319370Spst format = fmt.format; 80419370Spst size = fmt.size; 80519370Spst count = fmt.count; 80619370Spst next_address = addr; 80746283Sdfr next_section = sect; 80819370Spst 80919370Spst /* String or instruction format implies fetch single bytes 81019370Spst regardless of the specified size. */ 81119370Spst if (format == 's' || format == 'i') 81219370Spst size = 'b'; 81319370Spst 81446283Sdfr if (format == 'i') 81546283Sdfr val_type = examine_i_type; 81646283Sdfr else if (size == 'b') 81719370Spst val_type = examine_b_type; 81819370Spst else if (size == 'h') 81919370Spst val_type = examine_h_type; 82019370Spst else if (size == 'w') 82119370Spst val_type = examine_w_type; 82219370Spst else if (size == 'g') 82319370Spst val_type = examine_g_type; 82419370Spst 82519370Spst maxelts = 8; 82619370Spst if (size == 'w') 82719370Spst maxelts = 4; 82819370Spst if (size == 'g') 82919370Spst maxelts = 2; 83019370Spst if (format == 's' || format == 'i') 83119370Spst maxelts = 1; 83219370Spst 83319370Spst /* Print as many objects as specified in COUNT, at most maxelts per line, 83419370Spst with the address of the next one at the start of each line. */ 83519370Spst 83619370Spst while (count > 0) 83719370Spst { 83819370Spst QUIT; 83919370Spst print_address (next_address, gdb_stdout); 84019370Spst printf_filtered (":"); 84119370Spst for (i = maxelts; 84219370Spst i > 0 && count > 0; 84319370Spst i--, count--) 84419370Spst { 84519370Spst printf_filtered ("\t"); 84619370Spst /* Note that print_formatted sets next_address for the next 84719370Spst object. */ 84819370Spst last_examine_address = next_address; 84946283Sdfr 85046283Sdfr if (last_examine_value) 85146283Sdfr value_free (last_examine_value); 85246283Sdfr 85346283Sdfr /* The value to be displayed is not fetched greedily. 85498944Sobrien Instead, to avoid the posibility of a fetched value not 85598944Sobrien being used, its retreval is delayed until the print code 85698944Sobrien uses it. When examining an instruction stream, the 85798944Sobrien disassembler will perform its own memory fetch using just 85898944Sobrien the address stored in LAST_EXAMINE_VALUE. FIXME: Should 85998944Sobrien the disassembler be modified so that LAST_EXAMINE_VALUE 86098944Sobrien is left with the byte sequence from the last complete 86198944Sobrien instruction fetched from memory? */ 86246283Sdfr last_examine_value = value_at_lazy (val_type, next_address, sect); 86346283Sdfr 86446283Sdfr if (last_examine_value) 86546283Sdfr release_value (last_examine_value); 86646283Sdfr 86798944Sobrien print_formatted (last_examine_value, format, size, gdb_stdout); 86819370Spst } 86919370Spst printf_filtered ("\n"); 87019370Spst gdb_flush (gdb_stdout); 87119370Spst } 87219370Spst} 87319370Spst 87419370Spststatic void 87598944Sobrienvalidate_format (struct format_data fmt, char *cmdname) 87619370Spst{ 87719370Spst if (fmt.size != 0) 87819370Spst error ("Size letters are meaningless in \"%s\" command.", cmdname); 87919370Spst if (fmt.count != 1) 88019370Spst error ("Item count other than 1 is meaningless in \"%s\" command.", 88119370Spst cmdname); 88219370Spst if (fmt.format == 'i' || fmt.format == 's') 88319370Spst error ("Format letter \"%c\" is meaningless in \"%s\" command.", 88419370Spst fmt.format, cmdname); 88519370Spst} 88619370Spst 88719370Spst/* Evaluate string EXP as an expression in the current language and 88898944Sobrien print the resulting value. EXP may contain a format specifier as the 88998944Sobrien first argument ("/x myvar" for example, to print myvar in hex). 89098944Sobrien */ 89119370Spst 89219370Spststatic void 89398944Sobrienprint_command_1 (char *exp, int inspect, int voidprint) 89419370Spst{ 89519370Spst struct expression *expr; 89619370Spst register struct cleanup *old_chain = 0; 89719370Spst register char format = 0; 89898944Sobrien struct value *val; 89919370Spst struct format_data fmt; 90019370Spst int cleanup = 0; 90119370Spst 90219370Spst /* Pass inspect flag to the rest of the print routines in a global (sigh). */ 90319370Spst inspect_it = inspect; 90419370Spst 90519370Spst if (exp && *exp == '/') 90619370Spst { 90719370Spst exp++; 90819370Spst fmt = decode_format (&exp, last_format, 0); 90919370Spst validate_format (fmt, "print"); 91019370Spst last_format = format = fmt.format; 91119370Spst } 91219370Spst else 91319370Spst { 91419370Spst fmt.count = 1; 91519370Spst fmt.format = 0; 91619370Spst fmt.size = 0; 91719370Spst } 91819370Spst 91919370Spst if (exp && *exp) 92019370Spst { 92119370Spst struct type *type; 92219370Spst expr = parse_expression (exp); 92398944Sobrien old_chain = make_cleanup (free_current_contents, &expr); 92419370Spst cleanup = 1; 92519370Spst val = evaluate_expression (expr); 92619370Spst 92719370Spst /* C++: figure out what type we actually want to print it as. */ 92819370Spst type = VALUE_TYPE (val); 92919370Spst 93019370Spst if (objectprint 93198944Sobrien && (TYPE_CODE (type) == TYPE_CODE_PTR 93219370Spst || TYPE_CODE (type) == TYPE_CODE_REF) 93398944Sobrien && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT 93419370Spst || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION)) 93519370Spst { 93698944Sobrien struct value *v; 93719370Spst 93819370Spst v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type)); 93919370Spst if (v != 0) 94019370Spst { 94119370Spst val = v; 94219370Spst type = VALUE_TYPE (val); 94319370Spst } 94419370Spst } 94519370Spst } 94619370Spst else 94719370Spst val = access_value_history (0); 94819370Spst 94919370Spst if (voidprint || (val && VALUE_TYPE (val) && 95098944Sobrien TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID)) 95119370Spst { 95219370Spst int histindex = record_latest_value (val); 95319370Spst 95419370Spst if (histindex >= 0) 95519370Spst annotate_value_history_begin (histindex, VALUE_TYPE (val)); 95619370Spst else 95719370Spst annotate_value_begin (VALUE_TYPE (val)); 95819370Spst 95919370Spst if (inspect) 96019370Spst printf_unfiltered ("\031(gdb-makebuffer \"%s\" %d '(\"", exp, histindex); 96198944Sobrien else if (histindex >= 0) 96298944Sobrien printf_filtered ("$%d = ", histindex); 96319370Spst 96419370Spst if (histindex >= 0) 96519370Spst annotate_value_history_value (); 96619370Spst 96798944Sobrien print_formatted (val, format, fmt.size, gdb_stdout); 96819370Spst printf_filtered ("\n"); 96919370Spst 97019370Spst if (histindex >= 0) 97119370Spst annotate_value_history_end (); 97219370Spst else 97319370Spst annotate_value_end (); 97419370Spst 97519370Spst if (inspect) 97698944Sobrien printf_unfiltered ("\") )\030"); 97719370Spst } 97819370Spst 97919370Spst if (cleanup) 98019370Spst do_cleanups (old_chain); 98198944Sobrien inspect_it = 0; /* Reset print routines to normal */ 98219370Spst} 98319370Spst 98419370Spst/* ARGSUSED */ 98519370Spststatic void 98698944Sobrienprint_command (char *exp, int from_tty) 98719370Spst{ 98819370Spst print_command_1 (exp, 0, 1); 98919370Spst} 99019370Spst 99119370Spst/* Same as print, except in epoch, it gets its own window */ 99219370Spst/* ARGSUSED */ 99319370Spststatic void 99498944Sobrieninspect_command (char *exp, int from_tty) 99519370Spst{ 99619370Spst extern int epoch_interface; 99719370Spst 99819370Spst print_command_1 (exp, epoch_interface, 1); 99919370Spst} 100019370Spst 100119370Spst/* Same as print, except it doesn't print void results. */ 100219370Spst/* ARGSUSED */ 100319370Spststatic void 100498944Sobriencall_command (char *exp, int from_tty) 100519370Spst{ 100619370Spst print_command_1 (exp, 0, 0); 100719370Spst} 100819370Spst 100919370Spst/* ARGSUSED */ 101046283Sdfrvoid 101198944Sobrienoutput_command (char *exp, int from_tty) 101219370Spst{ 101319370Spst struct expression *expr; 101419370Spst register struct cleanup *old_chain; 101519370Spst register char format = 0; 101698944Sobrien struct value *val; 101719370Spst struct format_data fmt; 101819370Spst 101919370Spst if (exp && *exp == '/') 102019370Spst { 102119370Spst exp++; 102219370Spst fmt = decode_format (&exp, 0, 0); 102319370Spst validate_format (fmt, "output"); 102419370Spst format = fmt.format; 102519370Spst } 102619370Spst 102719370Spst expr = parse_expression (exp); 102898944Sobrien old_chain = make_cleanup (free_current_contents, &expr); 102919370Spst 103019370Spst val = evaluate_expression (expr); 103119370Spst 103219370Spst annotate_value_begin (VALUE_TYPE (val)); 103319370Spst 103498944Sobrien print_formatted (val, format, fmt.size, gdb_stdout); 103519370Spst 103619370Spst annotate_value_end (); 103719370Spst 103898944Sobrien wrap_here (""); 103998944Sobrien gdb_flush (gdb_stdout); 104098944Sobrien 104119370Spst do_cleanups (old_chain); 104219370Spst} 104319370Spst 104419370Spst/* ARGSUSED */ 104519370Spststatic void 104698944Sobrienset_command (char *exp, int from_tty) 104719370Spst{ 104819370Spst struct expression *expr = parse_expression (exp); 104998944Sobrien register struct cleanup *old_chain = 105098944Sobrien make_cleanup (free_current_contents, &expr); 105119370Spst evaluate_expression (expr); 105219370Spst do_cleanups (old_chain); 105319370Spst} 105419370Spst 105519370Spst/* ARGSUSED */ 105619370Spststatic void 105798944Sobriensym_info (char *arg, int from_tty) 105846283Sdfr{ 105946283Sdfr struct minimal_symbol *msymbol; 106098944Sobrien struct objfile *objfile; 106198944Sobrien struct obj_section *osect; 106298944Sobrien asection *sect; 106398944Sobrien CORE_ADDR addr, sect_addr; 106498944Sobrien int matches = 0; 106598944Sobrien unsigned int offset; 106646283Sdfr 106746283Sdfr if (!arg) 106846283Sdfr error_no_arg ("address"); 106946283Sdfr 107046283Sdfr addr = parse_and_eval_address (arg); 107146283Sdfr ALL_OBJSECTIONS (objfile, osect) 107298944Sobrien { 107398944Sobrien sect = osect->the_bfd_section; 107498944Sobrien sect_addr = overlay_mapped_address (addr, sect); 107546283Sdfr 107698944Sobrien if (osect->addr <= sect_addr && sect_addr < osect->endaddr && 107798944Sobrien (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect))) 107898944Sobrien { 107998944Sobrien matches = 1; 108098944Sobrien offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol); 108198944Sobrien if (offset) 108298944Sobrien printf_filtered ("%s + %u in ", 108398944Sobrien SYMBOL_SOURCE_NAME (msymbol), offset); 108498944Sobrien else 108598944Sobrien printf_filtered ("%s in ", 108698944Sobrien SYMBOL_SOURCE_NAME (msymbol)); 108798944Sobrien if (pc_in_unmapped_range (addr, sect)) 108898944Sobrien printf_filtered ("load address range of "); 108998944Sobrien if (section_is_overlay (sect)) 109098944Sobrien printf_filtered ("%s overlay ", 109198944Sobrien section_is_mapped (sect) ? "mapped" : "unmapped"); 109298944Sobrien printf_filtered ("section %s", sect->name); 109398944Sobrien printf_filtered ("\n"); 109498944Sobrien } 109598944Sobrien } 109646283Sdfr if (matches == 0) 109746283Sdfr printf_filtered ("No symbol matches %s.\n", arg); 109846283Sdfr} 109946283Sdfr 110046283Sdfr/* ARGSUSED */ 110146283Sdfrstatic void 110298944Sobrienaddress_info (char *exp, int from_tty) 110319370Spst{ 110419370Spst register struct symbol *sym; 110519370Spst register struct minimal_symbol *msymbol; 110619370Spst register long val; 110719370Spst register long basereg; 110846283Sdfr asection *section; 110946283Sdfr CORE_ADDR load_addr; 111019370Spst int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero 111119370Spst if exp is a field of `this'. */ 111219370Spst 111319370Spst if (exp == 0) 111419370Spst error ("Argument required."); 111519370Spst 111698944Sobrien sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE, 111798944Sobrien &is_a_field_of_this, (struct symtab **) NULL); 111819370Spst if (sym == NULL) 111919370Spst { 112019370Spst if (is_a_field_of_this) 112119370Spst { 112219370Spst printf_filtered ("Symbol \""); 112319370Spst fprintf_symbol_filtered (gdb_stdout, exp, 112419370Spst current_language->la_language, DMGL_ANSI); 112519370Spst printf_filtered ("\" is a field of the local class variable `this'\n"); 112619370Spst return; 112719370Spst } 112819370Spst 112919370Spst msymbol = lookup_minimal_symbol (exp, NULL, NULL); 113019370Spst 113119370Spst if (msymbol != NULL) 113219370Spst { 113346283Sdfr load_addr = SYMBOL_VALUE_ADDRESS (msymbol); 113446283Sdfr 113519370Spst printf_filtered ("Symbol \""); 113619370Spst fprintf_symbol_filtered (gdb_stdout, exp, 113719370Spst current_language->la_language, DMGL_ANSI); 113819370Spst printf_filtered ("\" is at "); 113946283Sdfr print_address_numeric (load_addr, 1, gdb_stdout); 114046283Sdfr printf_filtered (" in a file compiled without debugging"); 114146283Sdfr section = SYMBOL_BFD_SECTION (msymbol); 114246283Sdfr if (section_is_overlay (section)) 114346283Sdfr { 114446283Sdfr load_addr = overlay_unmapped_address (load_addr, section); 114546283Sdfr printf_filtered (",\n -- loaded at "); 114646283Sdfr print_address_numeric (load_addr, 1, gdb_stdout); 114746283Sdfr printf_filtered (" in overlay section %s", section->name); 114846283Sdfr } 114946283Sdfr printf_filtered (".\n"); 115019370Spst } 115119370Spst else 115219370Spst error ("No symbol \"%s\" in current context.", exp); 115319370Spst return; 115419370Spst } 115519370Spst 115619370Spst printf_filtered ("Symbol \""); 115719370Spst fprintf_symbol_filtered (gdb_stdout, SYMBOL_NAME (sym), 115819370Spst current_language->la_language, DMGL_ANSI); 115919370Spst printf_filtered ("\" is "); 116098944Sobrien val = SYMBOL_VALUE (sym); 116119370Spst basereg = SYMBOL_BASEREG (sym); 116246283Sdfr section = SYMBOL_BFD_SECTION (sym); 116319370Spst 116419370Spst switch (SYMBOL_CLASS (sym)) 116519370Spst { 116619370Spst case LOC_CONST: 116719370Spst case LOC_CONST_BYTES: 116819370Spst printf_filtered ("constant"); 116919370Spst break; 117019370Spst 117119370Spst case LOC_LABEL: 117219370Spst printf_filtered ("a label at address "); 117398944Sobrien print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym), 117446283Sdfr 1, gdb_stdout); 117546283Sdfr if (section_is_overlay (section)) 117646283Sdfr { 117746283Sdfr load_addr = overlay_unmapped_address (load_addr, section); 117846283Sdfr printf_filtered (",\n -- loaded at "); 117946283Sdfr print_address_numeric (load_addr, 1, gdb_stdout); 118046283Sdfr printf_filtered (" in overlay section %s", section->name); 118146283Sdfr } 118219370Spst break; 118319370Spst 118419370Spst case LOC_REGISTER: 118546283Sdfr printf_filtered ("a variable in register %s", REGISTER_NAME (val)); 118619370Spst break; 118719370Spst 118819370Spst case LOC_STATIC: 118919370Spst printf_filtered ("static storage at address "); 119098944Sobrien print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym), 119146283Sdfr 1, gdb_stdout); 119246283Sdfr if (section_is_overlay (section)) 119346283Sdfr { 119446283Sdfr load_addr = overlay_unmapped_address (load_addr, section); 119546283Sdfr printf_filtered (",\n -- loaded at "); 119646283Sdfr print_address_numeric (load_addr, 1, gdb_stdout); 119746283Sdfr printf_filtered (" in overlay section %s", section->name); 119846283Sdfr } 119919370Spst break; 120019370Spst 120146283Sdfr case LOC_INDIRECT: 120246283Sdfr printf_filtered ("external global (indirect addressing), at address *("); 120346283Sdfr print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (sym), 120446283Sdfr 1, gdb_stdout); 120546283Sdfr printf_filtered (")"); 120646283Sdfr if (section_is_overlay (section)) 120746283Sdfr { 120846283Sdfr load_addr = overlay_unmapped_address (load_addr, section); 120946283Sdfr printf_filtered (",\n -- loaded at "); 121046283Sdfr print_address_numeric (load_addr, 1, gdb_stdout); 121146283Sdfr printf_filtered (" in overlay section %s", section->name); 121246283Sdfr } 121346283Sdfr break; 121446283Sdfr 121519370Spst case LOC_REGPARM: 121646283Sdfr printf_filtered ("an argument in register %s", REGISTER_NAME (val)); 121719370Spst break; 121819370Spst 121919370Spst case LOC_REGPARM_ADDR: 122046283Sdfr printf_filtered ("address of an argument in register %s", REGISTER_NAME (val)); 122119370Spst break; 122219370Spst 122319370Spst case LOC_ARG: 122419370Spst printf_filtered ("an argument at offset %ld", val); 122519370Spst break; 122619370Spst 122719370Spst case LOC_LOCAL_ARG: 122819370Spst printf_filtered ("an argument at frame offset %ld", val); 122919370Spst break; 123019370Spst 123119370Spst case LOC_LOCAL: 123219370Spst printf_filtered ("a local variable at frame offset %ld", val); 123319370Spst break; 123419370Spst 123519370Spst case LOC_REF_ARG: 123619370Spst printf_filtered ("a reference argument at offset %ld", val); 123719370Spst break; 123819370Spst 123919370Spst case LOC_BASEREG: 124019370Spst printf_filtered ("a variable at offset %ld from register %s", 124198944Sobrien val, REGISTER_NAME (basereg)); 124219370Spst break; 124319370Spst 124419370Spst case LOC_BASEREG_ARG: 124519370Spst printf_filtered ("an argument at offset %ld from register %s", 124698944Sobrien val, REGISTER_NAME (basereg)); 124719370Spst break; 124819370Spst 124919370Spst case LOC_TYPEDEF: 125019370Spst printf_filtered ("a typedef"); 125119370Spst break; 125219370Spst 125319370Spst case LOC_BLOCK: 125419370Spst printf_filtered ("a function at address "); 125546283Sdfr#ifdef GDB_TARGET_MASK_DISAS_PC 125646283Sdfr print_address_numeric 125798944Sobrien (load_addr = GDB_TARGET_MASK_DISAS_PC (BLOCK_START (SYMBOL_BLOCK_VALUE (sym))), 125846283Sdfr 1, gdb_stdout); 125946283Sdfr#else 126098944Sobrien print_address_numeric (load_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)), 126146283Sdfr 1, gdb_stdout); 126246283Sdfr#endif 126346283Sdfr if (section_is_overlay (section)) 126446283Sdfr { 126546283Sdfr load_addr = overlay_unmapped_address (load_addr, section); 126646283Sdfr printf_filtered (",\n -- loaded at "); 126746283Sdfr print_address_numeric (load_addr, 1, gdb_stdout); 126846283Sdfr printf_filtered (" in overlay section %s", section->name); 126946283Sdfr } 127019370Spst break; 127119370Spst 127219370Spst case LOC_UNRESOLVED: 127319370Spst { 127419370Spst struct minimal_symbol *msym; 127519370Spst 127619370Spst msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, NULL); 127719370Spst if (msym == NULL) 127819370Spst printf_filtered ("unresolved"); 127919370Spst else 128019370Spst { 128146283Sdfr section = SYMBOL_BFD_SECTION (msym); 128219370Spst printf_filtered ("static storage at address "); 128398944Sobrien print_address_numeric (load_addr = SYMBOL_VALUE_ADDRESS (msym), 128446283Sdfr 1, gdb_stdout); 128546283Sdfr if (section_is_overlay (section)) 128646283Sdfr { 128746283Sdfr load_addr = overlay_unmapped_address (load_addr, section); 128846283Sdfr printf_filtered (",\n -- loaded at "); 128946283Sdfr print_address_numeric (load_addr, 1, gdb_stdout); 129046283Sdfr printf_filtered (" in overlay section %s", section->name); 129146283Sdfr } 129219370Spst } 129319370Spst } 129419370Spst break; 129519370Spst 129646283Sdfr case LOC_THREAD_LOCAL_STATIC: 129746283Sdfr printf_filtered ( 129898944Sobrien "a thread-local variable at offset %ld from the thread base register %s", 129998944Sobrien val, REGISTER_NAME (basereg)); 130046283Sdfr break; 130146283Sdfr 130219370Spst case LOC_OPTIMIZED_OUT: 130319370Spst printf_filtered ("optimized out"); 130419370Spst break; 130598944Sobrien 130619370Spst default: 130719370Spst printf_filtered ("of unknown (botched) type"); 130819370Spst break; 130919370Spst } 131019370Spst printf_filtered (".\n"); 131119370Spst} 131219370Spst 131346283Sdfrvoid 131498944Sobrienx_command (char *exp, int from_tty) 131519370Spst{ 131619370Spst struct expression *expr; 131719370Spst struct format_data fmt; 131819370Spst struct cleanup *old_chain; 131919370Spst struct value *val; 132019370Spst 132119370Spst fmt.format = last_format; 132219370Spst fmt.size = last_size; 132319370Spst fmt.count = 1; 132419370Spst 132519370Spst if (exp && *exp == '/') 132619370Spst { 132719370Spst exp++; 132819370Spst fmt = decode_format (&exp, last_format, last_size); 132919370Spst } 133019370Spst 133119370Spst /* If we have an expression, evaluate it and use it as the address. */ 133219370Spst 133319370Spst if (exp != 0 && *exp != 0) 133419370Spst { 133519370Spst expr = parse_expression (exp); 133619370Spst /* Cause expression not to be there any more 133798944Sobrien if this command is repeated with Newline. 133898944Sobrien But don't clobber a user-defined command's definition. */ 133919370Spst if (from_tty) 134019370Spst *exp = 0; 134198944Sobrien old_chain = make_cleanup (free_current_contents, &expr); 134219370Spst val = evaluate_expression (expr); 134319370Spst if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF) 134419370Spst val = value_ind (val); 134519370Spst /* In rvalue contexts, such as this, functions are coerced into 134698944Sobrien pointers to functions. This makes "x/i main" work. */ 134798944Sobrien if (/* last_format == 'i' && */ 134898944Sobrien TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC 134998944Sobrien && VALUE_LVAL (val) == lval_memory) 135019370Spst next_address = VALUE_ADDRESS (val); 135119370Spst else 135298944Sobrien next_address = value_as_address (val); 135346283Sdfr if (VALUE_BFD_SECTION (val)) 135446283Sdfr next_section = VALUE_BFD_SECTION (val); 135519370Spst do_cleanups (old_chain); 135619370Spst } 135719370Spst 135846283Sdfr do_examine (fmt, next_address, next_section); 135919370Spst 136019370Spst /* If the examine succeeds, we remember its size and format for next time. */ 136119370Spst last_size = fmt.size; 136219370Spst last_format = fmt.format; 136319370Spst 136419370Spst /* Set a couple of internal variables if appropriate. */ 136519370Spst if (last_examine_value) 136619370Spst { 136719370Spst /* Make last address examined available to the user as $_. Use 136898944Sobrien the correct pointer type. */ 136998944Sobrien struct type *pointer_type 137098944Sobrien = lookup_pointer_type (VALUE_TYPE (last_examine_value)); 137119370Spst set_internalvar (lookup_internalvar ("_"), 137298944Sobrien value_from_pointer (pointer_type, 137398944Sobrien last_examine_address)); 137498944Sobrien 137598944Sobrien /* Make contents of last address examined available to the user as $__. */ 137646283Sdfr /* If the last value has not been fetched from memory then don't 137746283Sdfr fetch it now - instead mark it by voiding the $__ variable. */ 137846283Sdfr if (VALUE_LAZY (last_examine_value)) 137946283Sdfr set_internalvar (lookup_internalvar ("__"), 138046283Sdfr allocate_value (builtin_type_void)); 138146283Sdfr else 138246283Sdfr set_internalvar (lookup_internalvar ("__"), last_examine_value); 138319370Spst } 138419370Spst} 138598944Sobrien 138619370Spst 138719370Spst/* Add an expression to the auto-display chain. 138819370Spst Specify the expression. */ 138919370Spst 139019370Spststatic void 139198944Sobriendisplay_command (char *exp, int from_tty) 139219370Spst{ 139319370Spst struct format_data fmt; 139419370Spst register struct expression *expr; 139519370Spst register struct display *new; 139646283Sdfr int display_it = 1; 139719370Spst 139846283Sdfr#if defined(TUI) 139946283Sdfr if (tui_version && *exp == '$') 140098944Sobrien display_it = (tui_set_layout (exp) == TUI_FAILURE); 140146283Sdfr#endif 140219370Spst 140346283Sdfr if (display_it) 140419370Spst { 140546283Sdfr if (exp == 0) 140646283Sdfr { 140746283Sdfr do_displays (); 140846283Sdfr return; 140946283Sdfr } 141019370Spst 141146283Sdfr if (*exp == '/') 141246283Sdfr { 141346283Sdfr exp++; 141446283Sdfr fmt = decode_format (&exp, 0, 0); 141546283Sdfr if (fmt.size && fmt.format == 0) 141646283Sdfr fmt.format = 'x'; 141746283Sdfr if (fmt.format == 'i' || fmt.format == 's') 141846283Sdfr fmt.size = 'b'; 141946283Sdfr } 142046283Sdfr else 142146283Sdfr { 142246283Sdfr fmt.format = 0; 142346283Sdfr fmt.size = 0; 142446283Sdfr fmt.count = 0; 142546283Sdfr } 142619370Spst 142746283Sdfr innermost_block = 0; 142846283Sdfr expr = parse_expression (exp); 142919370Spst 143046283Sdfr new = (struct display *) xmalloc (sizeof (struct display)); 143119370Spst 143246283Sdfr new->exp = expr; 143346283Sdfr new->block = innermost_block; 143446283Sdfr new->next = display_chain; 143546283Sdfr new->number = ++display_number; 143646283Sdfr new->format = fmt; 143798944Sobrien new->enabled_p = 1; 143846283Sdfr display_chain = new; 143919370Spst 144046283Sdfr if (from_tty && target_has_execution) 144146283Sdfr do_one_display (new); 144246283Sdfr 144346283Sdfr dont_repeat (); 144446283Sdfr } 144519370Spst} 144619370Spst 144719370Spststatic void 144898944Sobrienfree_display (struct display *d) 144919370Spst{ 145098944Sobrien xfree (d->exp); 145198944Sobrien xfree (d); 145219370Spst} 145319370Spst 145419370Spst/* Clear out the display_chain. 145519370Spst Done when new symtabs are loaded, since this invalidates 145619370Spst the types stored in many expressions. */ 145719370Spst 145819370Spstvoid 145998944Sobrienclear_displays (void) 146019370Spst{ 146119370Spst register struct display *d; 146219370Spst 146319370Spst while ((d = display_chain) != NULL) 146419370Spst { 146598944Sobrien xfree (d->exp); 146619370Spst display_chain = d->next; 146798944Sobrien xfree (d); 146819370Spst } 146919370Spst} 147019370Spst 147119370Spst/* Delete the auto-display number NUM. */ 147219370Spst 147319370Spststatic void 147498944Sobriendelete_display (int num) 147519370Spst{ 147619370Spst register struct display *d1, *d; 147719370Spst 147819370Spst if (!display_chain) 147919370Spst error ("No display number %d.", num); 148019370Spst 148119370Spst if (display_chain->number == num) 148219370Spst { 148319370Spst d1 = display_chain; 148419370Spst display_chain = d1->next; 148519370Spst free_display (d1); 148619370Spst } 148719370Spst else 148898944Sobrien for (d = display_chain;; d = d->next) 148919370Spst { 149019370Spst if (d->next == 0) 149119370Spst error ("No display number %d.", num); 149219370Spst if (d->next->number == num) 149319370Spst { 149419370Spst d1 = d->next; 149519370Spst d->next = d1->next; 149619370Spst free_display (d1); 149719370Spst break; 149819370Spst } 149919370Spst } 150019370Spst} 150119370Spst 150219370Spst/* Delete some values from the auto-display chain. 150319370Spst Specify the element numbers. */ 150419370Spst 150519370Spststatic void 150698944Sobrienundisplay_command (char *args, int from_tty) 150719370Spst{ 150819370Spst register char *p = args; 150919370Spst register char *p1; 151019370Spst register int num; 151119370Spst 151219370Spst if (args == 0) 151319370Spst { 151419370Spst if (query ("Delete all auto-display expressions? ")) 151519370Spst clear_displays (); 151619370Spst dont_repeat (); 151719370Spst return; 151819370Spst } 151919370Spst 152019370Spst while (*p) 152119370Spst { 152219370Spst p1 = p; 152398944Sobrien while (*p1 >= '0' && *p1 <= '9') 152498944Sobrien p1++; 152519370Spst if (*p1 && *p1 != ' ' && *p1 != '\t') 152619370Spst error ("Arguments must be display numbers."); 152719370Spst 152819370Spst num = atoi (p); 152919370Spst 153019370Spst delete_display (num); 153119370Spst 153219370Spst p = p1; 153398944Sobrien while (*p == ' ' || *p == '\t') 153498944Sobrien p++; 153519370Spst } 153619370Spst dont_repeat (); 153719370Spst} 153819370Spst 153919370Spst/* Display a single auto-display. 154019370Spst Do nothing if the display cannot be printed in the current context, 154119370Spst or if the display is disabled. */ 154219370Spst 154319370Spststatic void 154498944Sobriendo_one_display (struct display *d) 154519370Spst{ 154619370Spst int within_current_scope; 154719370Spst 154898944Sobrien if (d->enabled_p == 0) 154919370Spst return; 155019370Spst 155119370Spst if (d->block) 155219370Spst within_current_scope = contained_in (get_selected_block (), d->block); 155319370Spst else 155419370Spst within_current_scope = 1; 155519370Spst if (!within_current_scope) 155619370Spst return; 155719370Spst 155819370Spst current_display_number = d->number; 155919370Spst 156019370Spst annotate_display_begin (); 156119370Spst printf_filtered ("%d", d->number); 156219370Spst annotate_display_number_end (); 156319370Spst printf_filtered (": "); 156419370Spst if (d->format.size) 156519370Spst { 156619370Spst CORE_ADDR addr; 156798944Sobrien struct value *val; 156819370Spst 156919370Spst annotate_display_format (); 157019370Spst 157119370Spst printf_filtered ("x/"); 157219370Spst if (d->format.count != 1) 157319370Spst printf_filtered ("%d", d->format.count); 157419370Spst printf_filtered ("%c", d->format.format); 157519370Spst if (d->format.format != 'i' && d->format.format != 's') 157619370Spst printf_filtered ("%c", d->format.size); 157719370Spst printf_filtered (" "); 157819370Spst 157919370Spst annotate_display_expression (); 158019370Spst 158119370Spst print_expression (d->exp, gdb_stdout); 158219370Spst annotate_display_expression_end (); 158319370Spst 158419370Spst if (d->format.count != 1) 158519370Spst printf_filtered ("\n"); 158619370Spst else 158719370Spst printf_filtered (" "); 158898944Sobrien 158946283Sdfr val = evaluate_expression (d->exp); 159098944Sobrien addr = value_as_address (val); 159119370Spst if (d->format.format == 'i') 159219370Spst addr = ADDR_BITS_REMOVE (addr); 159319370Spst 159419370Spst annotate_display_value (); 159519370Spst 159646283Sdfr do_examine (d->format, addr, VALUE_BFD_SECTION (val)); 159719370Spst } 159819370Spst else 159919370Spst { 160019370Spst annotate_display_format (); 160119370Spst 160219370Spst if (d->format.format) 160319370Spst printf_filtered ("/%c ", d->format.format); 160419370Spst 160519370Spst annotate_display_expression (); 160619370Spst 160719370Spst print_expression (d->exp, gdb_stdout); 160819370Spst annotate_display_expression_end (); 160919370Spst 161019370Spst printf_filtered (" = "); 161119370Spst 161219370Spst annotate_display_expression (); 161319370Spst 161419370Spst print_formatted (evaluate_expression (d->exp), 161598944Sobrien d->format.format, d->format.size, gdb_stdout); 161619370Spst printf_filtered ("\n"); 161719370Spst } 161819370Spst 161919370Spst annotate_display_end (); 162019370Spst 162119370Spst gdb_flush (gdb_stdout); 162219370Spst current_display_number = -1; 162319370Spst} 162419370Spst 162519370Spst/* Display all of the values on the auto-display chain which can be 162619370Spst evaluated in the current scope. */ 162719370Spst 162819370Spstvoid 162998944Sobriendo_displays (void) 163019370Spst{ 163119370Spst register struct display *d; 163219370Spst 163319370Spst for (d = display_chain; d; d = d->next) 163419370Spst do_one_display (d); 163519370Spst} 163619370Spst 163719370Spst/* Delete the auto-display which we were in the process of displaying. 163819370Spst This is done when there is an error or a signal. */ 163919370Spst 164019370Spstvoid 164198944Sobriendisable_display (int num) 164219370Spst{ 164319370Spst register struct display *d; 164419370Spst 164519370Spst for (d = display_chain; d; d = d->next) 164619370Spst if (d->number == num) 164719370Spst { 164898944Sobrien d->enabled_p = 0; 164919370Spst return; 165019370Spst } 165119370Spst printf_unfiltered ("No display number %d.\n", num); 165219370Spst} 165398944Sobrien 165419370Spstvoid 165598944Sobriendisable_current_display (void) 165619370Spst{ 165719370Spst if (current_display_number >= 0) 165819370Spst { 165919370Spst disable_display (current_display_number); 166019370Spst fprintf_unfiltered (gdb_stderr, "Disabling display %d to avoid infinite recursion.\n", 166198944Sobrien current_display_number); 166219370Spst } 166319370Spst current_display_number = -1; 166419370Spst} 166519370Spst 166619370Spststatic void 166798944Sobriendisplay_info (char *ignore, int from_tty) 166819370Spst{ 166919370Spst register struct display *d; 167019370Spst 167119370Spst if (!display_chain) 167219370Spst printf_unfiltered ("There are no auto-display expressions now.\n"); 167319370Spst else 167498944Sobrien printf_filtered ("Auto-display expressions now in effect:\n\ 167519370SpstNum Enb Expression\n"); 167619370Spst 167719370Spst for (d = display_chain; d; d = d->next) 167819370Spst { 167998944Sobrien printf_filtered ("%d: %c ", d->number, "ny"[(int) d->enabled_p]); 168019370Spst if (d->format.size) 168119370Spst printf_filtered ("/%d%c%c ", d->format.count, d->format.size, 168298944Sobrien d->format.format); 168319370Spst else if (d->format.format) 168419370Spst printf_filtered ("/%c ", d->format.format); 168519370Spst print_expression (d->exp, gdb_stdout); 168619370Spst if (d->block && !contained_in (get_selected_block (), d->block)) 168719370Spst printf_filtered (" (cannot be evaluated in the current context)"); 168819370Spst printf_filtered ("\n"); 168919370Spst gdb_flush (gdb_stdout); 169019370Spst } 169119370Spst} 169219370Spst 169319370Spststatic void 169498944Sobrienenable_display (char *args, int from_tty) 169519370Spst{ 169619370Spst register char *p = args; 169719370Spst register char *p1; 169819370Spst register int num; 169919370Spst register struct display *d; 170019370Spst 170119370Spst if (p == 0) 170219370Spst { 170319370Spst for (d = display_chain; d; d = d->next) 170498944Sobrien d->enabled_p = 1; 170519370Spst } 170619370Spst else 170719370Spst while (*p) 170819370Spst { 170919370Spst p1 = p; 171019370Spst while (*p1 >= '0' && *p1 <= '9') 171119370Spst p1++; 171219370Spst if (*p1 && *p1 != ' ' && *p1 != '\t') 171319370Spst error ("Arguments must be display numbers."); 171498944Sobrien 171519370Spst num = atoi (p); 171698944Sobrien 171719370Spst for (d = display_chain; d; d = d->next) 171819370Spst if (d->number == num) 171919370Spst { 172098944Sobrien d->enabled_p = 1; 172119370Spst goto win; 172219370Spst } 172319370Spst printf_unfiltered ("No display number %d.\n", num); 172419370Spst win: 172519370Spst p = p1; 172619370Spst while (*p == ' ' || *p == '\t') 172719370Spst p++; 172819370Spst } 172919370Spst} 173019370Spst 173119370Spst/* ARGSUSED */ 173219370Spststatic void 173398944Sobriendisable_display_command (char *args, int from_tty) 173419370Spst{ 173519370Spst register char *p = args; 173619370Spst register char *p1; 173719370Spst register struct display *d; 173819370Spst 173919370Spst if (p == 0) 174019370Spst { 174119370Spst for (d = display_chain; d; d = d->next) 174298944Sobrien d->enabled_p = 0; 174319370Spst } 174419370Spst else 174519370Spst while (*p) 174619370Spst { 174719370Spst p1 = p; 174819370Spst while (*p1 >= '0' && *p1 <= '9') 174919370Spst p1++; 175019370Spst if (*p1 && *p1 != ' ' && *p1 != '\t') 175119370Spst error ("Arguments must be display numbers."); 175298944Sobrien 175319370Spst disable_display (atoi (p)); 175419370Spst 175519370Spst p = p1; 175619370Spst while (*p == ' ' || *p == '\t') 175719370Spst p++; 175819370Spst } 175919370Spst} 176098944Sobrien 176119370Spst 176219370Spst/* Print the value in stack frame FRAME of a variable 176319370Spst specified by a struct symbol. */ 176419370Spst 176519370Spstvoid 176698944Sobrienprint_variable_value (struct symbol *var, struct frame_info *frame, 176798944Sobrien struct ui_file *stream) 176819370Spst{ 176998944Sobrien struct value *val = read_var_value (var, frame); 177019370Spst 177119370Spst value_print (val, stream, 0, Val_pretty_default); 177219370Spst} 177319370Spst 177419370Spst/* Print the arguments of a stack frame, given the function FUNC 177519370Spst running in that frame (as a symbol), the info on the frame, 177619370Spst and the number of args according to the stack frame (or -1 if unknown). */ 177719370Spst 177819370Spst/* References here and elsewhere to "number of args according to the 177919370Spst stack frame" appear in all cases to refer to "number of ints of args 178019370Spst according to the stack frame". At least for VAX, i386, isi. */ 178119370Spst 178219370Spstvoid 178398944Sobrienprint_frame_args (struct symbol *func, struct frame_info *fi, int num, 178498944Sobrien struct ui_file *stream) 178519370Spst{ 178619370Spst struct block *b = NULL; 178719370Spst int first = 1; 178819370Spst register int i; 178919370Spst register struct symbol *sym; 179098944Sobrien struct value *val; 179119370Spst /* Offset of next stack argument beyond the one we have seen that is 179219370Spst at the highest offset. 179319370Spst -1 if we haven't come to a stack argument yet. */ 179419370Spst long highest_offset = -1; 179519370Spst int arg_size; 179619370Spst /* Number of ints of arguments that we have printed so far. */ 179719370Spst int args_printed = 0; 179898944Sobrien struct cleanup *old_chain, *list_chain; 179998944Sobrien struct ui_stream *stb; 180019370Spst 180198944Sobrien stb = ui_out_stream_new (uiout); 180298944Sobrien old_chain = make_cleanup_ui_out_stream_delete (stb); 180398944Sobrien 180419370Spst if (func) 180519370Spst { 180619370Spst b = SYMBOL_BLOCK_VALUE (func); 180798944Sobrien ALL_BLOCK_SYMBOLS (b, i, sym) 180898944Sobrien { 180998944Sobrien QUIT; 181019370Spst 181198944Sobrien /* Keep track of the highest stack argument offset seen, and 181298944Sobrien skip over any kinds of symbols we don't care about. */ 181319370Spst 181498944Sobrien switch (SYMBOL_CLASS (sym)) 181598944Sobrien { 181698944Sobrien case LOC_ARG: 181798944Sobrien case LOC_REF_ARG: 181898944Sobrien { 181998944Sobrien long current_offset = SYMBOL_VALUE (sym); 182098944Sobrien arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym)); 182119370Spst 182298944Sobrien /* Compute address of next argument by adding the size of 182398944Sobrien this argument and rounding to an int boundary. */ 182498944Sobrien current_offset = 182598944Sobrien ((current_offset + arg_size + sizeof (int) - 1) 182698944Sobrien & ~(sizeof (int) - 1)); 182719370Spst 182898944Sobrien /* If this is the highest offset seen yet, set highest_offset. */ 182998944Sobrien if (highest_offset == -1 183098944Sobrien || (current_offset > highest_offset)) 183198944Sobrien highest_offset = current_offset; 183219370Spst 183398944Sobrien /* Add the number of ints we're about to print to args_printed. */ 183498944Sobrien args_printed += (arg_size + sizeof (int) - 1) / sizeof (int); 183598944Sobrien } 183619370Spst 183798944Sobrien /* We care about types of symbols, but don't need to keep track of 183898944Sobrien stack offsets in them. */ 183998944Sobrien case LOC_REGPARM: 184098944Sobrien case LOC_REGPARM_ADDR: 184198944Sobrien case LOC_LOCAL_ARG: 184298944Sobrien case LOC_BASEREG_ARG: 184398944Sobrien break; 184419370Spst 184598944Sobrien /* Other types of symbols we just skip over. */ 184698944Sobrien default: 184798944Sobrien continue; 184898944Sobrien } 184919370Spst 185098944Sobrien /* We have to look up the symbol because arguments can have 185198944Sobrien two entries (one a parameter, one a local) and the one we 185298944Sobrien want is the local, which lookup_symbol will find for us. 185398944Sobrien This includes gcc1 (not gcc2) on the sparc when passing a 185498944Sobrien small structure and gcc2 when the argument type is float 185598944Sobrien and it is passed as a double and converted to float by 185698944Sobrien the prologue (in the latter case the type of the LOC_ARG 185798944Sobrien symbol is double and the type of the LOC_LOCAL symbol is 185898944Sobrien float). */ 185998944Sobrien /* But if the parameter name is null, don't try it. 186098944Sobrien Null parameter names occur on the RS/6000, for traceback tables. 186198944Sobrien FIXME, should we even print them? */ 186219370Spst 186398944Sobrien if (*SYMBOL_NAME (sym)) 186419370Spst { 186598944Sobrien struct symbol *nsym; 186698944Sobrien nsym = lookup_symbol 186798944Sobrien (SYMBOL_NAME (sym), 186898944Sobrien b, VAR_NAMESPACE, (int *) NULL, (struct symtab **) NULL); 186998944Sobrien if (SYMBOL_CLASS (nsym) == LOC_REGISTER) 187098944Sobrien { 187198944Sobrien /* There is a LOC_ARG/LOC_REGISTER pair. This means that 187298944Sobrien it was passed on the stack and loaded into a register, 187398944Sobrien or passed in a register and stored in a stack slot. 187498944Sobrien GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER. 187519370Spst 187698944Sobrien Reasons for using the LOC_ARG: 187798944Sobrien (1) because find_saved_registers may be slow for remote 187898944Sobrien debugging, 187998944Sobrien (2) because registers are often re-used and stack slots 188098944Sobrien rarely (never?) are. Therefore using the stack slot is 188198944Sobrien much less likely to print garbage. 188219370Spst 188398944Sobrien Reasons why we might want to use the LOC_REGISTER: 188498944Sobrien (1) So that the backtrace prints the same value as 188598944Sobrien "print foo". I see no compelling reason why this needs 188698944Sobrien to be the case; having the backtrace print the value which 188798944Sobrien was passed in, and "print foo" print the value as modified 188898944Sobrien within the called function, makes perfect sense to me. 188919370Spst 189098944Sobrien Additional note: It might be nice if "info args" displayed 189198944Sobrien both values. 189298944Sobrien One more note: There is a case with sparc structure passing 189398944Sobrien where we need to use the LOC_REGISTER, but this is dealt with 189498944Sobrien by creating a single LOC_REGPARM in symbol reading. */ 189519370Spst 189698944Sobrien /* Leave sym (the LOC_ARG) alone. */ 189798944Sobrien ; 189898944Sobrien } 189998944Sobrien else 190098944Sobrien sym = nsym; 190119370Spst } 190219370Spst 190398944Sobrien /* Print the current arg. */ 190498944Sobrien if (!first) 190598944Sobrien ui_out_text (uiout, ", "); 190698944Sobrien ui_out_wrap_hint (uiout, " "); 190719370Spst 190898944Sobrien annotate_arg_begin (); 190919370Spst 191098944Sobrien list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); 191198944Sobrien fprintf_symbol_filtered (stb->stream, SYMBOL_SOURCE_NAME (sym), 191298944Sobrien SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI); 191398944Sobrien ui_out_field_stream (uiout, "name", stb); 191498944Sobrien annotate_arg_name_end (); 191598944Sobrien ui_out_text (uiout, "="); 191619370Spst 191798944Sobrien /* Avoid value_print because it will deref ref parameters. We just 191898944Sobrien want to print their addresses. Print ??? for args whose address 191998944Sobrien we do not know. We pass 2 as "recurse" to val_print because our 192098944Sobrien standard indentation here is 4 spaces, and val_print indents 192198944Sobrien 2 for each recurse. */ 192298944Sobrien val = read_var_value (sym, fi); 192319370Spst 192498944Sobrien annotate_arg_value (val == NULL ? NULL : VALUE_TYPE (val)); 192519370Spst 192698944Sobrien if (val) 192798944Sobrien { 192898944Sobrien val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), 0, 192998944Sobrien VALUE_ADDRESS (val), 193098944Sobrien stb->stream, 0, 0, 2, Val_no_prettyprint); 193198944Sobrien ui_out_field_stream (uiout, "value", stb); 193298944Sobrien } 193398944Sobrien else 193498944Sobrien ui_out_text (uiout, "???"); 193519370Spst 193698944Sobrien /* Invoke ui_out_tuple_end. */ 193798944Sobrien do_cleanups (list_chain); 193819370Spst 193998944Sobrien annotate_arg_end (); 194098944Sobrien 194198944Sobrien first = 0; 194298944Sobrien } 194319370Spst } 194419370Spst 194519370Spst /* Don't print nameless args in situations where we don't know 194619370Spst enough about the stack to find them. */ 194719370Spst if (num != -1) 194819370Spst { 194919370Spst long start; 195019370Spst 195119370Spst if (highest_offset == -1) 195219370Spst start = FRAME_ARGS_SKIP; 195319370Spst else 195419370Spst start = highest_offset; 195519370Spst 195619370Spst print_frame_nameless_args (fi, start, num - args_printed, 195719370Spst first, stream); 195819370Spst } 195998944Sobrien do_cleanups (old_chain); 196019370Spst} 196119370Spst 196219370Spst/* Print nameless args on STREAM. 196319370Spst FI is the frameinfo for this frame, START is the offset 196419370Spst of the first nameless arg, and NUM is the number of nameless args to 196519370Spst print. FIRST is nonzero if this is the first argument (not just 196619370Spst the first nameless arg). */ 196719370Spst 196819370Spststatic void 196998944Sobrienprint_frame_nameless_args (struct frame_info *fi, long start, int num, 197098944Sobrien int first, struct ui_file *stream) 197119370Spst{ 197219370Spst int i; 197319370Spst CORE_ADDR argsaddr; 197419370Spst long arg_value; 197519370Spst 197619370Spst for (i = 0; i < num; i++) 197719370Spst { 197819370Spst QUIT; 197919370Spst#ifdef NAMELESS_ARG_VALUE 198019370Spst NAMELESS_ARG_VALUE (fi, start, &arg_value); 198119370Spst#else 198219370Spst argsaddr = FRAME_ARGS_ADDRESS (fi); 198319370Spst if (!argsaddr) 198419370Spst return; 198519370Spst 198619370Spst arg_value = read_memory_integer (argsaddr + start, sizeof (int)); 198719370Spst#endif 198819370Spst 198919370Spst if (!first) 199019370Spst fprintf_filtered (stream, ", "); 199119370Spst 199219370Spst#ifdef PRINT_NAMELESS_INTEGER 199319370Spst PRINT_NAMELESS_INTEGER (stream, arg_value); 199419370Spst#else 199519370Spst#ifdef PRINT_TYPELESS_INTEGER 199619370Spst PRINT_TYPELESS_INTEGER (stream, builtin_type_int, (LONGEST) arg_value); 199719370Spst#else 199819370Spst fprintf_filtered (stream, "%ld", arg_value); 199919370Spst#endif /* PRINT_TYPELESS_INTEGER */ 200019370Spst#endif /* PRINT_NAMELESS_INTEGER */ 200119370Spst first = 0; 200219370Spst start += sizeof (int); 200319370Spst } 200419370Spst} 200519370Spst 200619370Spst/* ARGSUSED */ 200719370Spststatic void 200898944Sobrienprintf_command (char *arg, int from_tty) 200919370Spst{ 201046283Sdfr register char *f = NULL; 201119370Spst register char *s = arg; 201246283Sdfr char *string = NULL; 201398944Sobrien struct value **val_args; 201419370Spst char *substrings; 201519370Spst char *current_substring; 201619370Spst int nargs = 0; 201719370Spst int allocated_args = 20; 201819370Spst struct cleanup *old_cleanups; 201919370Spst 202098944Sobrien val_args = (struct value **) xmalloc (allocated_args 202198944Sobrien * sizeof (struct value *)); 202298944Sobrien old_cleanups = make_cleanup (free_current_contents, &val_args); 202319370Spst 202419370Spst if (s == 0) 202519370Spst error_no_arg ("format-control string and values to print"); 202619370Spst 202719370Spst /* Skip white space before format string */ 202898944Sobrien while (*s == ' ' || *s == '\t') 202998944Sobrien s++; 203019370Spst 203119370Spst /* A format string should follow, enveloped in double quotes */ 203219370Spst if (*s++ != '"') 203319370Spst error ("Bad format string, missing '\"'."); 203419370Spst 203519370Spst /* Parse the format-control string and copy it into the string STRING, 203619370Spst processing some kinds of escape sequence. */ 203719370Spst 203819370Spst f = string = (char *) alloca (strlen (s) + 1); 203919370Spst 204019370Spst while (*s != '"') 204119370Spst { 204219370Spst int c = *s++; 204319370Spst switch (c) 204419370Spst { 204519370Spst case '\0': 204619370Spst error ("Bad format string, non-terminated '\"'."); 204719370Spst 204819370Spst case '\\': 204919370Spst switch (c = *s++) 205019370Spst { 205119370Spst case '\\': 205219370Spst *f++ = '\\'; 205319370Spst break; 205419370Spst case 'a': 205519370Spst *f++ = '\a'; 205619370Spst break; 205719370Spst case 'b': 205819370Spst *f++ = '\b'; 205919370Spst break; 206019370Spst case 'f': 206119370Spst *f++ = '\f'; 206219370Spst break; 206319370Spst case 'n': 206419370Spst *f++ = '\n'; 206519370Spst break; 206619370Spst case 'r': 206719370Spst *f++ = '\r'; 206819370Spst break; 206919370Spst case 't': 207019370Spst *f++ = '\t'; 207119370Spst break; 207219370Spst case 'v': 207319370Spst *f++ = '\v'; 207419370Spst break; 207519370Spst case '"': 207619370Spst *f++ = '"'; 207719370Spst break; 207819370Spst default: 207919370Spst /* ??? TODO: handle other escape sequences */ 208019370Spst error ("Unrecognized escape character \\%c in format string.", 208119370Spst c); 208219370Spst } 208319370Spst break; 208419370Spst 208519370Spst default: 208619370Spst *f++ = c; 208719370Spst } 208819370Spst } 208919370Spst 209019370Spst /* Skip over " and following space and comma. */ 209119370Spst s++; 209219370Spst *f++ = '\0'; 209398944Sobrien while (*s == ' ' || *s == '\t') 209498944Sobrien s++; 209519370Spst 209619370Spst if (*s != ',' && *s != 0) 209719370Spst error ("Invalid argument syntax"); 209819370Spst 209998944Sobrien if (*s == ',') 210098944Sobrien s++; 210198944Sobrien while (*s == ' ' || *s == '\t') 210298944Sobrien s++; 210319370Spst 210419370Spst /* Need extra space for the '\0's. Doubling the size is sufficient. */ 210519370Spst substrings = alloca (strlen (string) * 2); 210619370Spst current_substring = substrings; 210719370Spst 210819370Spst { 210919370Spst /* Now scan the string for %-specs and see what kinds of args they want. 211019370Spst argclass[I] classifies the %-specs so we can give printf_filtered 211119370Spst something of the right size. */ 211219370Spst 211398944Sobrien enum argclass 211498944Sobrien { 211598944Sobrien no_arg, int_arg, string_arg, double_arg, long_long_arg 211698944Sobrien }; 211719370Spst enum argclass *argclass; 211819370Spst enum argclass this_argclass; 211919370Spst char *last_arg; 212019370Spst int nargs_wanted; 212119370Spst int lcount; 212219370Spst int i; 212319370Spst 212419370Spst argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass); 212519370Spst nargs_wanted = 0; 212619370Spst f = string; 212719370Spst last_arg = string; 212819370Spst while (*f) 212919370Spst if (*f++ == '%') 213019370Spst { 213119370Spst lcount = 0; 213298944Sobrien while (strchr ("0123456789.hlL-+ #", *f)) 213319370Spst { 213419370Spst if (*f == 'l' || *f == 'L') 213519370Spst lcount++; 213619370Spst f++; 213719370Spst } 213819370Spst switch (*f) 213919370Spst { 214019370Spst case 's': 214119370Spst this_argclass = string_arg; 214219370Spst break; 214319370Spst 214419370Spst case 'e': 214519370Spst case 'f': 214619370Spst case 'g': 214719370Spst this_argclass = double_arg; 214819370Spst break; 214919370Spst 215019370Spst case '*': 215119370Spst error ("`*' not supported for precision or width in printf"); 215219370Spst 215319370Spst case 'n': 215419370Spst error ("Format specifier `n' not supported in printf"); 215519370Spst 215619370Spst case '%': 215719370Spst this_argclass = no_arg; 215819370Spst break; 215919370Spst 216019370Spst default: 216119370Spst if (lcount > 1) 216219370Spst this_argclass = long_long_arg; 216319370Spst else 216419370Spst this_argclass = int_arg; 216519370Spst break; 216619370Spst } 216719370Spst f++; 216819370Spst if (this_argclass != no_arg) 216919370Spst { 217019370Spst strncpy (current_substring, last_arg, f - last_arg); 217119370Spst current_substring += f - last_arg; 217219370Spst *current_substring++ = '\0'; 217319370Spst last_arg = f; 217419370Spst argclass[nargs_wanted++] = this_argclass; 217519370Spst } 217619370Spst } 217719370Spst 217819370Spst /* Now, parse all arguments and evaluate them. 217919370Spst Store the VALUEs in VAL_ARGS. */ 218019370Spst 218119370Spst while (*s != '\0') 218219370Spst { 218319370Spst char *s1; 218419370Spst if (nargs == allocated_args) 218598944Sobrien val_args = (struct value **) xrealloc ((char *) val_args, 218698944Sobrien (allocated_args *= 2) 218798944Sobrien * sizeof (struct value *)); 218819370Spst s1 = s; 218919370Spst val_args[nargs] = parse_to_comma_and_eval (&s1); 219098944Sobrien 219119370Spst /* If format string wants a float, unchecked-convert the value to 219219370Spst floating point of the same size */ 219398944Sobrien 219419370Spst if (argclass[nargs] == double_arg) 219519370Spst { 219619370Spst struct type *type = VALUE_TYPE (val_args[nargs]); 219719370Spst if (TYPE_LENGTH (type) == sizeof (float)) 219898944Sobrien VALUE_TYPE (val_args[nargs]) = builtin_type_float; 219919370Spst if (TYPE_LENGTH (type) == sizeof (double)) 220098944Sobrien VALUE_TYPE (val_args[nargs]) = builtin_type_double; 220119370Spst } 220219370Spst nargs++; 220319370Spst s = s1; 220419370Spst if (*s == ',') 220519370Spst s++; 220619370Spst } 220798944Sobrien 220819370Spst if (nargs != nargs_wanted) 220919370Spst error ("Wrong number of arguments for specified format-string"); 221019370Spst 221119370Spst /* Now actually print them. */ 221219370Spst current_substring = substrings; 221319370Spst for (i = 0; i < nargs; i++) 221419370Spst { 221519370Spst switch (argclass[i]) 221619370Spst { 221719370Spst case string_arg: 221819370Spst { 221919370Spst char *str; 222019370Spst CORE_ADDR tem; 222119370Spst int j; 222298944Sobrien tem = value_as_address (val_args[i]); 222319370Spst 222419370Spst /* This is a %s argument. Find the length of the string. */ 222598944Sobrien for (j = 0;; j++) 222619370Spst { 222719370Spst char c; 222819370Spst QUIT; 222998944Sobrien read_memory (tem + j, &c, 1); 223019370Spst if (c == 0) 223119370Spst break; 223219370Spst } 223319370Spst 223419370Spst /* Copy the string contents into a string inside GDB. */ 223519370Spst str = (char *) alloca (j + 1); 223698944Sobrien if (j != 0) 223798944Sobrien read_memory (tem, str, j); 223819370Spst str[j] = 0; 223919370Spst 224019370Spst printf_filtered (current_substring, str); 224119370Spst } 224219370Spst break; 224319370Spst case double_arg: 224419370Spst { 224519370Spst double val = value_as_double (val_args[i]); 224619370Spst printf_filtered (current_substring, val); 224719370Spst break; 224819370Spst } 224919370Spst case long_long_arg: 225019370Spst#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG) 225119370Spst { 225219370Spst long long val = value_as_long (val_args[i]); 225319370Spst printf_filtered (current_substring, val); 225419370Spst break; 225519370Spst } 225619370Spst#else 225719370Spst error ("long long not supported in printf"); 225819370Spst#endif 225919370Spst case int_arg: 226019370Spst { 226119370Spst /* FIXME: there should be separate int_arg and long_arg. */ 226219370Spst long val = value_as_long (val_args[i]); 226319370Spst printf_filtered (current_substring, val); 226419370Spst break; 226519370Spst } 226698944Sobrien default: /* purecov: deadcode */ 226798944Sobrien error ("internal error in printf_command"); /* purecov: deadcode */ 226819370Spst } 226919370Spst /* Skip to the next substring. */ 227019370Spst current_substring += strlen (current_substring) + 1; 227119370Spst } 227219370Spst /* Print the portion of the format string after the last argument. */ 227319370Spst printf_filtered (last_arg); 227419370Spst } 227519370Spst do_cleanups (old_cleanups); 227619370Spst} 227719370Spst 227819370Spst/* Dump a specified section of assembly code. With no command line 227919370Spst arguments, this command will dump the assembly code for the 228019370Spst function surrounding the pc value in the selected frame. With one 228119370Spst argument, it will dump the assembly code surrounding that pc value. 228219370Spst Two arguments are interpeted as bounds within which to dump 228319370Spst assembly. */ 228419370Spst 228519370Spst/* ARGSUSED */ 228619370Spststatic void 228798944Sobriendisassemble_command (char *arg, int from_tty) 228819370Spst{ 228919370Spst CORE_ADDR low, high; 229019370Spst char *name; 229146283Sdfr CORE_ADDR pc, pc_masked; 229219370Spst char *space_index; 229346283Sdfr#if 0 229446283Sdfr asection *section; 229546283Sdfr#endif 229619370Spst 229719370Spst name = NULL; 229819370Spst if (!arg) 229919370Spst { 230019370Spst if (!selected_frame) 230119370Spst error ("No frame selected.\n"); 230219370Spst 230319370Spst pc = get_frame_pc (selected_frame); 230419370Spst if (find_pc_partial_function (pc, &name, &low, &high) == 0) 230519370Spst error ("No function contains program counter for selected frame.\n"); 230646283Sdfr#if defined(TUI) 230746283Sdfr else if (tui_version) 230898944Sobrien low = tuiGetLowDisassemblyAddress (low, pc); 230946283Sdfr#endif 231046283Sdfr low += FUNCTION_START_OFFSET; 231119370Spst } 231219370Spst else if (!(space_index = (char *) strchr (arg, ' '))) 231319370Spst { 231419370Spst /* One argument. */ 231519370Spst pc = parse_and_eval_address (arg); 231619370Spst if (find_pc_partial_function (pc, &name, &low, &high) == 0) 231719370Spst error ("No function contains specified address.\n"); 231846283Sdfr#if defined(TUI) 231946283Sdfr else if (tui_version) 232098944Sobrien low = tuiGetLowDisassemblyAddress (low, pc); 232146283Sdfr#endif 232246283Sdfr low += FUNCTION_START_OFFSET; 232319370Spst } 232419370Spst else 232519370Spst { 232619370Spst /* Two arguments. */ 232719370Spst *space_index = '\0'; 232819370Spst low = parse_and_eval_address (arg); 232919370Spst high = parse_and_eval_address (space_index + 1); 233019370Spst } 233119370Spst 233246283Sdfr#if defined(TUI) 233398944Sobrien if (!tui_is_window_visible (DISASSEM_WIN)) 233446283Sdfr#endif 233519370Spst { 233646283Sdfr printf_filtered ("Dump of assembler code "); 233746283Sdfr if (name != NULL) 233846283Sdfr { 233946283Sdfr printf_filtered ("for function %s:\n", name); 234046283Sdfr } 234146283Sdfr else 234246283Sdfr { 234346283Sdfr printf_filtered ("from "); 234446283Sdfr print_address_numeric (low, 1, gdb_stdout); 234546283Sdfr printf_filtered (" to "); 234646283Sdfr print_address_numeric (high, 1, gdb_stdout); 234746283Sdfr printf_filtered (":\n"); 234846283Sdfr } 234946283Sdfr 235046283Sdfr /* Dump the specified range. */ 235146283Sdfr pc = low; 235246283Sdfr 235346283Sdfr#ifdef GDB_TARGET_MASK_DISAS_PC 235446283Sdfr pc_masked = GDB_TARGET_MASK_DISAS_PC (pc); 235546283Sdfr#else 235646283Sdfr pc_masked = pc; 235746283Sdfr#endif 235846283Sdfr 235946283Sdfr while (pc_masked < high) 236046283Sdfr { 236146283Sdfr QUIT; 236246283Sdfr print_address (pc_masked, gdb_stdout); 236346283Sdfr printf_filtered (":\t"); 236446283Sdfr /* We often wrap here if there are long symbolic names. */ 236546283Sdfr wrap_here (" "); 236646283Sdfr pc += print_insn (pc, gdb_stdout); 236746283Sdfr printf_filtered ("\n"); 236846283Sdfr 236946283Sdfr#ifdef GDB_TARGET_MASK_DISAS_PC 237046283Sdfr pc_masked = GDB_TARGET_MASK_DISAS_PC (pc); 237146283Sdfr#else 237246283Sdfr pc_masked = pc; 237346283Sdfr#endif 237446283Sdfr } 237546283Sdfr printf_filtered ("End of assembler dump.\n"); 237646283Sdfr gdb_flush (gdb_stdout); 237719370Spst } 237846283Sdfr#if defined(TUI) 237919370Spst else 238019370Spst { 238198944Sobrien tui_show_assembly (low); 238219370Spst } 238346283Sdfr#endif 238419370Spst} 238519370Spst 238619370Spst/* Print the instruction at address MEMADDR in debugged memory, 238719370Spst on STREAM. Returns length of the instruction, in bytes. */ 238819370Spst 238919370Spststatic int 239098944Sobrienprint_insn (CORE_ADDR memaddr, struct ui_file *stream) 239119370Spst{ 239298944Sobrien if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) 239346283Sdfr TARGET_PRINT_INSN_INFO->endian = BFD_ENDIAN_BIG; 239446283Sdfr else 239546283Sdfr TARGET_PRINT_INSN_INFO->endian = BFD_ENDIAN_LITTLE; 239619370Spst 239746283Sdfr if (TARGET_ARCHITECTURE != NULL) 239846283Sdfr TARGET_PRINT_INSN_INFO->mach = TARGET_ARCHITECTURE->mach; 239946283Sdfr /* else: should set .mach=0 but some disassemblers don't grok this */ 240019370Spst 240198944Sobrien TARGET_PRINT_INSN_INFO->stream = stream; 240298944Sobrien 240346283Sdfr return TARGET_PRINT_INSN (memaddr, TARGET_PRINT_INSN_INFO); 240419370Spst} 240598944Sobrien 240619370Spst 240719370Spstvoid 240898944Sobrien_initialize_printcmd (void) 240919370Spst{ 241098944Sobrien struct cmd_list_element *c; 241198944Sobrien 241219370Spst current_display_number = -1; 241319370Spst 241419370Spst add_info ("address", address_info, 241598944Sobrien "Describe where symbol SYM is stored."); 241619370Spst 241798944Sobrien add_info ("symbol", sym_info, 241846283Sdfr "Describe what symbol is at location ADDR.\n\ 241946283SdfrOnly for symbols with fixed locations (global or static scope)."); 242046283Sdfr 242119370Spst add_com ("x", class_vars, x_command, 242219370Spst concat ("Examine memory: x/FMT ADDRESS.\n\ 242319370SpstADDRESS is an expression for the memory address to examine.\n\ 242419370SpstFMT is a repeat count followed by a format letter and a size letter.\n\ 242519370SpstFormat letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\ 242619370Spst t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n", 242798944Sobrien "Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\ 242819370SpstThe specified number of objects of the specified size are printed\n\ 242919370Spstaccording to the format.\n\n\ 243019370SpstDefaults for format and size letters are those previously used.\n\ 243119370SpstDefault count is 1. Default address is following last thing printed\n\ 243219370Spstwith this command or \"print\".", NULL)); 243319370Spst 243498944Sobrien c = add_com ("disassemble", class_vars, disassemble_command, 243598944Sobrien "Disassemble a specified section of memory.\n\ 243619370SpstDefault is the function surrounding the pc of the selected frame.\n\ 243719370SpstWith a single argument, the function surrounding that address is dumped.\n\ 243819370SpstTwo arguments are taken as a range of memory to dump."); 243998944Sobrien c->completer = location_completer; 244046283Sdfr if (xdb_commands) 244198944Sobrien add_com_alias ("va", "disassemble", class_xdb, 0); 244219370Spst 244319370Spst#if 0 244419370Spst add_com ("whereis", class_vars, whereis_command, 244519370Spst "Print line number and file of definition of variable."); 244619370Spst#endif 244798944Sobrien 244819370Spst add_info ("display", display_info, 244919370Spst "Expressions to display when program stops, with code numbers."); 245019370Spst 245119370Spst add_cmd ("undisplay", class_vars, undisplay_command, 245219370Spst "Cancel some expressions to be displayed when program stops.\n\ 245319370SpstArguments are the code numbers of the expressions to stop displaying.\n\ 245419370SpstNo argument means cancel all automatic-display expressions.\n\ 245519370Spst\"delete display\" has the same effect as this command.\n\ 245619370SpstDo \"info display\" to see current list of code numbers.", 245798944Sobrien &cmdlist); 245819370Spst 245919370Spst add_com ("display", class_vars, display_command, 246019370Spst "Print value of expression EXP each time the program stops.\n\ 246119370Spst/FMT may be used before EXP as in the \"print\" command.\n\ 246219370Spst/FMT \"i\" or \"s\" or including a size-letter is allowed,\n\ 246319370Spstas in the \"x\" command, and then EXP is used to get the address to examine\n\ 246419370Spstand examining is done as in the \"x\" command.\n\n\ 246519370SpstWith no argument, display all currently requested auto-display expressions.\n\ 246619370SpstUse \"undisplay\" to cancel display requests previously made." 246798944Sobrien ); 246819370Spst 246998944Sobrien add_cmd ("display", class_vars, enable_display, 247019370Spst "Enable some expressions to be displayed when program stops.\n\ 247119370SpstArguments are the code numbers of the expressions to resume displaying.\n\ 247219370SpstNo argument means enable all automatic-display expressions.\n\ 247319370SpstDo \"info display\" to see current list of code numbers.", &enablelist); 247419370Spst 247598944Sobrien add_cmd ("display", class_vars, disable_display_command, 247619370Spst "Disable some expressions to be displayed when program stops.\n\ 247719370SpstArguments are the code numbers of the expressions to stop displaying.\n\ 247819370SpstNo argument means disable all automatic-display expressions.\n\ 247919370SpstDo \"info display\" to see current list of code numbers.", &disablelist); 248019370Spst 248198944Sobrien add_cmd ("display", class_vars, undisplay_command, 248219370Spst "Cancel some expressions to be displayed when program stops.\n\ 248319370SpstArguments are the code numbers of the expressions to stop displaying.\n\ 248419370SpstNo argument means cancel all automatic-display expressions.\n\ 248519370SpstDo \"info display\" to see current list of code numbers.", &deletelist); 248619370Spst 248719370Spst add_com ("printf", class_vars, printf_command, 248898944Sobrien "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ 248919370SpstThis is useful for formatted output in user-defined commands."); 249019370Spst 249119370Spst add_com ("output", class_vars, output_command, 249219370Spst "Like \"print\" but don't put in value history and don't print newline.\n\ 249319370SpstThis is useful in user-defined commands."); 249419370Spst 249519370Spst add_prefix_cmd ("set", class_vars, set_command, 249698944Sobrien concat ("Evaluate expression EXP and assign result to variable VAR, using assignment\n\ 249719370Spstsyntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ 249819370Spstexample). VAR may be a debugger \"convenience\" variable (names starting\n\ 249919370Spstwith $), a register (a few standard names starting with $), or an actual\n\ 250019370Spstvariable in the program being debugged. EXP is any valid expression.\n", 250198944Sobrien "Use \"set variable\" for variables with names identical to set subcommands.\n\ 250219370Spst\nWith a subcommand, this command modifies parts of the gdb environment.\n\ 250319370SpstYou can see these environment settings with the \"show\" command.", NULL), 250498944Sobrien &setlist, "set ", 1, &cmdlist); 250546283Sdfr if (dbx_commands) 250698944Sobrien add_com ("assign", class_vars, set_command, concat ("Evaluate expression \ 250746283SdfrEXP and assign result to variable VAR, using assignment\n\ 250846283Sdfrsyntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ 250946283Sdfrexample). VAR may be a debugger \"convenience\" variable (names starting\n\ 251046283Sdfrwith $), a register (a few standard names starting with $), or an actual\n\ 251146283Sdfrvariable in the program being debugged. EXP is any valid expression.\n", 251298944Sobrien "Use \"set variable\" for variables with names identical to set subcommands.\n\ 251346283Sdfr\nWith a subcommand, this command modifies parts of the gdb environment.\n\ 251446283SdfrYou can see these environment settings with the \"show\" command.", NULL)); 251519370Spst 251619370Spst /* "call" is the same as "set", but handy for dbx users to call fns. */ 251798944Sobrien c = add_com ("call", class_vars, call_command, 251898944Sobrien "Call a function in the program.\n\ 251919370SpstThe argument is the function name and arguments, in the notation of the\n\ 252019370Spstcurrent working language. The result is printed and saved in the value\n\ 252119370Spsthistory, if it is not void."); 252298944Sobrien c->completer = location_completer; 252319370Spst 252419370Spst add_cmd ("variable", class_vars, set_command, 252598944Sobrien "Evaluate expression EXP and assign result to variable VAR, using assignment\n\ 252619370Spstsyntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\ 252719370Spstexample). VAR may be a debugger \"convenience\" variable (names starting\n\ 252819370Spstwith $), a register (a few standard names starting with $), or an actual\n\ 252919370Spstvariable in the program being debugged. EXP is any valid expression.\n\ 253019370SpstThis may usually be abbreviated to simply \"set\".", 253198944Sobrien &setlist); 253219370Spst 253398944Sobrien c = add_com ("print", class_vars, print_command, 253419370Spst concat ("Print value of expression EXP.\n\ 253519370SpstVariables accessible are those of the lexical environment of the selected\n\ 253619370Spststack frame, plus all those whose scope is global or an entire file.\n\ 253719370Spst\n\ 253819370Spst$NUM gets previous value number NUM. $ and $$ are the last two values.\n\ 253919370Spst$$NUM refers to NUM'th value back from the last one.\n\ 254019370SpstNames starting with $ refer to registers (with the values they would have\n", 254198944Sobrien "if the program were to return to the stack frame now selected, restoring\n\ 254219370Spstall registers saved by frames farther in) or else to debugger\n\ 254319370Spst\"convenience\" variables (any such name not a known register).\n\ 254419370SpstUse assignment expressions to give values to convenience variables.\n", 254519370Spst "\n\ 254619370Spst{TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\ 254719370Spst@ is a binary operator for treating consecutive data objects\n\ 254819370Spstanywhere in memory as an array. FOO@NUM gives an array whose first\n\ 254919370Spstelement is FOO, whose second element is stored in the space following\n\ 255019370Spstwhere FOO is stored, etc. FOO must be an expression whose value\n\ 255119370Spstresides in memory.\n", 255219370Spst "\n\ 255319370SpstEXP may be preceded with /FMT, where FMT is a format letter\n\ 255419370Spstbut no count or size letter (see \"x\" command).", NULL)); 255598944Sobrien c->completer = location_completer; 255619370Spst add_com_alias ("p", "print", class_vars, 1); 255719370Spst 255898944Sobrien c = add_com ("inspect", class_vars, inspect_command, 255998944Sobrien "Same as \"print\" command, except that if you are running in the epoch\n\ 256019370Spstenvironment, the value is printed in its own window."); 256198944Sobrien c->completer = location_completer; 256219370Spst 256319370Spst add_show_from_set ( 256498944Sobrien add_set_cmd ("max-symbolic-offset", no_class, var_uinteger, 256598944Sobrien (char *) &max_symbolic_offset, 256698944Sobrien "Set the largest offset that will be printed in <symbol+1234> form.", 256798944Sobrien &setprintlist), 256898944Sobrien &showprintlist); 256919370Spst add_show_from_set ( 257098944Sobrien add_set_cmd ("symbol-filename", no_class, var_boolean, 257198944Sobrien (char *) &print_symbol_filename, 257298944Sobrien "Set printing of source filename and line number with <symbol>.", 257398944Sobrien &setprintlist), 257498944Sobrien &showprintlist); 257519370Spst 257646283Sdfr /* For examine/instruction a single byte quantity is specified as 257746283Sdfr the data. This avoids problems with value_at_lazy() requiring a 257846283Sdfr valid data type (and rejecting VOID). */ 257946283Sdfr examine_i_type = init_type (TYPE_CODE_INT, 1, 0, "examine_i_type", NULL); 258046283Sdfr 258119370Spst examine_b_type = init_type (TYPE_CODE_INT, 1, 0, "examine_b_type", NULL); 258219370Spst examine_h_type = init_type (TYPE_CODE_INT, 2, 0, "examine_h_type", NULL); 258319370Spst examine_w_type = init_type (TYPE_CODE_INT, 4, 0, "examine_w_type", NULL); 258419370Spst examine_g_type = init_type (TYPE_CODE_INT, 8, 0, "examine_g_type", NULL); 258546283Sdfr 258619370Spst} 2587