X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Ff-valprint.c;h=b83597cf3b0a8645ab9baedf396db64328fe9e2f;hb=366da635ba4e3110b6fb0a7cd06ff67291f03c71;hp=a007c871c1eae641064de22b003815902b661d4c;hpb=abd8680d6efd97e7ba848a6392ee3ad72be18cd0;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c index a007c871c1..b83597cf3b 100644 --- a/gdb/f-valprint.c +++ b/gdb/f-valprint.c @@ -1,5 +1,8 @@ /* Support for printing Fortran values for GDB, the GNU debugger. - Copyright 1993-1995, 2000 Free Software Foundation, Inc. + + Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2003, 2005, 2006 + Free Software Foundation, Inc. + Contributed by Motorola. Adapted from the C definitions by Farooq Butt (fmbutt@engage.sps.mot.com), additionally worked over by Stan Shebs. @@ -17,8 +20,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ #include "defs.h" #include "gdb_string.h" @@ -26,30 +29,24 @@ #include "gdbtypes.h" #include "expression.h" #include "value.h" -#include "demangle.h" #include "valprint.h" #include "language.h" #include "f-lang.h" #include "frame.h" #include "gdbcore.h" #include "command.h" +#include "block.h" #if 0 -static int there_is_a_visible_common_named PARAMS ((char *)); +static int there_is_a_visible_common_named (char *); #endif -extern void _initialize_f_valprint PARAMS ((void)); -static void info_common_command PARAMS ((char *, int)); -static void list_all_visible_commons PARAMS ((char *)); -static void f77_print_array (struct type *, char *, CORE_ADDR, - struct ui_file *, int, int, int, - enum val_prettyprint); -static void f77_print_array_1 (int, int, struct type *, char *, - CORE_ADDR, struct ui_file *, int, int, int, - enum val_prettyprint); +extern void _initialize_f_valprint (void); +static void info_common_command (char *, int); +static void list_all_visible_commons (char *); static void f77_create_arrayprint_offset_tbl (struct type *, struct ui_file *); -static void f77_get_dynamic_length_of_aggregate PARAMS ((struct type *)); +static void f77_get_dynamic_length_of_aggregate (struct type *); int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2]; @@ -66,9 +63,7 @@ int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2]; #define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0]) int -f77_get_dynamic_lowerbound (type, lower_bound) - struct type *type; - int *lower_bound; +f77_get_dynamic_lowerbound (struct type *type, int *lower_bound) { CORE_ADDR current_frame_addr; CORE_ADDR ptr_to_lower_bound; @@ -76,7 +71,7 @@ f77_get_dynamic_lowerbound (type, lower_bound) switch (TYPE_ARRAY_LOWER_BOUND_TYPE (type)) { case BOUND_BY_VALUE_ON_STACK: - current_frame_addr = selected_frame->frame; + current_frame_addr = get_frame_base (deprecated_selected_frame); if (current_frame_addr > 0) { *lower_bound = @@ -96,17 +91,17 @@ f77_get_dynamic_lowerbound (type, lower_bound) break; case BOUND_CANNOT_BE_DETERMINED: - error ("Lower bound may not be '*' in F77"); + error (_("Lower bound may not be '*' in F77")); break; case BOUND_BY_REF_ON_STACK: - current_frame_addr = selected_frame->frame; + current_frame_addr = get_frame_base (deprecated_selected_frame); if (current_frame_addr > 0) { ptr_to_lower_bound = - read_memory_integer (current_frame_addr + - TYPE_ARRAY_LOWER_BOUND_VALUE (type), - 4); + read_memory_typed_address (current_frame_addr + + TYPE_ARRAY_LOWER_BOUND_VALUE (type), + builtin_type_void_data_ptr); *lower_bound = read_memory_integer (ptr_to_lower_bound, 4); } else @@ -119,16 +114,14 @@ f77_get_dynamic_lowerbound (type, lower_bound) case BOUND_BY_REF_IN_REG: case BOUND_BY_VALUE_IN_REG: default: - error ("??? unhandled dynamic array bound type ???"); + error (_("??? unhandled dynamic array bound type ???")); break; } return BOUND_FETCH_OK; } int -f77_get_dynamic_upperbound (type, upper_bound) - struct type *type; - int *upper_bound; +f77_get_dynamic_upperbound (struct type *type, int *upper_bound) { CORE_ADDR current_frame_addr = 0; CORE_ADDR ptr_to_upper_bound; @@ -136,7 +129,7 @@ f77_get_dynamic_upperbound (type, upper_bound) switch (TYPE_ARRAY_UPPER_BOUND_TYPE (type)) { case BOUND_BY_VALUE_ON_STACK: - current_frame_addr = selected_frame->frame; + current_frame_addr = get_frame_base (deprecated_selected_frame); if (current_frame_addr > 0) { *upper_bound = @@ -165,13 +158,13 @@ f77_get_dynamic_upperbound (type, upper_bound) break; case BOUND_BY_REF_ON_STACK: - current_frame_addr = selected_frame->frame; + current_frame_addr = get_frame_base (deprecated_selected_frame); if (current_frame_addr > 0) { ptr_to_upper_bound = - read_memory_integer (current_frame_addr + - TYPE_ARRAY_UPPER_BOUND_VALUE (type), - 4); + read_memory_typed_address (current_frame_addr + + TYPE_ARRAY_UPPER_BOUND_VALUE (type), + builtin_type_void_data_ptr); *upper_bound = read_memory_integer (ptr_to_upper_bound, 4); } else @@ -184,7 +177,7 @@ f77_get_dynamic_upperbound (type, upper_bound) case BOUND_BY_REF_IN_REG: case BOUND_BY_VALUE_IN_REG: default: - error ("??? unhandled dynamic array bound type ???"); + error (_("??? unhandled dynamic array bound type ???")); break; } return BOUND_FETCH_OK; @@ -193,8 +186,7 @@ f77_get_dynamic_upperbound (type, upper_bound) /* Obtain F77 adjustable array dimensions */ static void -f77_get_dynamic_length_of_aggregate (type) - struct type *type; +f77_get_dynamic_length_of_aggregate (struct type *type) { int upper_bound = -1; int lower_bound = 1; @@ -216,11 +208,11 @@ f77_get_dynamic_length_of_aggregate (type) /* Recursion ends here, start setting up lengths. */ retcode = f77_get_dynamic_lowerbound (type, &lower_bound); if (retcode == BOUND_FETCH_ERROR) - error ("Cannot obtain valid array lower bound"); + error (_("Cannot obtain valid array lower bound")); retcode = f77_get_dynamic_upperbound (type, &upper_bound); if (retcode == BOUND_FETCH_ERROR) - error ("Cannot obtain valid array upper bound"); + error (_("Cannot obtain valid array upper bound")); /* Patch in a valid length value. */ @@ -232,9 +224,7 @@ f77_get_dynamic_length_of_aggregate (type) type "type". */ static void -f77_create_arrayprint_offset_tbl (type, stream) - struct type *type; - struct ui_file *stream; +f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream) { struct type *tmp_type; int eltlen; @@ -250,11 +240,11 @@ f77_create_arrayprint_offset_tbl (type, stream) retcode = f77_get_dynamic_upperbound (tmp_type, &upper); if (retcode == BOUND_FETCH_ERROR) - error ("Cannot obtain dynamic upper bound"); + error (_("Cannot obtain dynamic upper bound")); retcode = f77_get_dynamic_lowerbound (tmp_type, &lower); if (retcode == BOUND_FETCH_ERROR) - error ("Cannot obtain dynamic lower bound"); + error (_("Cannot obtain dynamic lower bound")); F77_DIM_SIZE (ndimen) = upper - lower + 1; @@ -277,40 +267,38 @@ f77_create_arrayprint_offset_tbl (type, stream) } } + + /* Actual function which prints out F77 arrays, Valaddr == address in the superior. Address == the address in the inferior. */ static void -f77_print_array_1 (nss, ndimensions, type, valaddr, address, - stream, format, deref_ref, recurse, pretty) - int nss; - int ndimensions; - struct type *type; - char *valaddr; - CORE_ADDR address; - struct ui_file *stream; - int format; - int deref_ref; - int recurse; - enum val_prettyprint pretty; +f77_print_array_1 (int nss, int ndimensions, struct type *type, + const gdb_byte *valaddr, CORE_ADDR address, + struct ui_file *stream, int format, + int deref_ref, int recurse, enum val_prettyprint pretty, + int *elts) { int i; if (nss != ndimensions) { - for (i = 0; i < F77_DIM_SIZE (nss); i++) + for (i = 0; (i < F77_DIM_SIZE (nss) && (*elts) < print_max); i++) { fprintf_filtered (stream, "( "); f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type), valaddr + i * F77_DIM_OFFSET (nss), address + i * F77_DIM_OFFSET (nss), - stream, format, deref_ref, recurse, pretty); + stream, format, deref_ref, recurse, pretty, elts); fprintf_filtered (stream, ") "); } + if (*elts >= print_max && i < F77_DIM_SIZE (nss)) + fprintf_filtered (stream, "..."); } else { - for (i = 0; (i < F77_DIM_SIZE (nss) && i < print_max); i++) + for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < print_max; + i++, (*elts)++) { val_print (TYPE_TARGET_TYPE (type), valaddr + i * F77_DIM_OFFSET (ndimensions), @@ -321,7 +309,7 @@ f77_print_array_1 (nss, ndimensions, type, valaddr, address, if (i != (F77_DIM_SIZE (nss) - 1)) fprintf_filtered (stream, ", "); - if (i == print_max - 1) + if ((*elts == print_max - 1) && (i != (F77_DIM_SIZE (nss) - 1))) fprintf_filtered (stream, "..."); } } @@ -331,23 +319,18 @@ f77_print_array_1 (nss, ndimensions, type, valaddr, address, stuff and then immediately call f77_print_array_1() */ static void -f77_print_array (type, valaddr, address, stream, format, deref_ref, recurse, - pretty) - struct type *type; - char *valaddr; - CORE_ADDR address; - struct ui_file *stream; - int format; - int deref_ref; - int recurse; - enum val_prettyprint pretty; +f77_print_array (struct type *type, const gdb_byte *valaddr, + CORE_ADDR address, struct ui_file *stream, + int format, int deref_ref, int recurse, + enum val_prettyprint pretty) { int ndimensions; + int elts = 0; ndimensions = calc_f77_array_dims (type); if (ndimensions > MAX_FORTRAN_DIMS || ndimensions < 0) - error ("Type node corrupt! F77 arrays cannot have %d subscripts (%d Max)", + error (_("Type node corrupt! F77 arrays cannot have %d subscripts (%d Max)"), ndimensions, MAX_FORTRAN_DIMS); /* Since F77 arrays are stored column-major, we set up an @@ -357,7 +340,7 @@ f77_print_array (type, valaddr, address, stream, format, deref_ref, recurse, f77_create_arrayprint_offset_tbl (type, stream); f77_print_array_1 (1, ndimensions, type, valaddr, address, stream, format, - deref_ref, recurse, pretty); + deref_ref, recurse, pretty, &elts); } @@ -375,22 +358,15 @@ f77_print_array (type, valaddr, address, stream, format, deref_ref, recurse, The PRETTY parameter controls prettyprinting. */ int -f_val_print (type, valaddr, embedded_offset, address, stream, format, deref_ref, recurse, - pretty) - struct type *type; - char *valaddr; - int embedded_offset; - CORE_ADDR address; - struct ui_file *stream; - int format; - int deref_ref; - int recurse; - enum val_prettyprint pretty; +f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, + CORE_ADDR address, struct ui_file *stream, int format, + int deref_ref, int recurse, enum val_prettyprint pretty) { - register unsigned int i = 0; /* Number of characters printed */ + unsigned int i = 0; /* Number of characters printed */ struct type *elttype; LONGEST val; CORE_ADDR addr; + int index; CHECK_TYPEDEF (type); switch (TYPE_CODE (type)) @@ -406,11 +382,7 @@ f_val_print (type, valaddr, embedded_offset, address, stream, format, deref_ref, deref_ref, recurse, pretty); fprintf_filtered (stream, ")"); break; -#if 0 - /* Array of unspecified length: treat like pointer to first elt. */ - valaddr = (char *) &address; - /* FALL THROUGH */ -#endif + case TYPE_CODE_PTR: if (format && format != 's') { @@ -431,7 +403,7 @@ f_val_print (type, valaddr, embedded_offset, address, stream, format, deref_ref, } if (addressprint && format != 's') - fprintf_filtered (stream, "0x%s", paddr_nz (addr)); + deprecated_print_address_numeric (addr, 1, stream); /* For a pointer to char or unsigned char, also print the string pointed to, unless pointer is null. */ @@ -441,9 +413,39 @@ f_val_print (type, valaddr, embedded_offset, address, stream, format, deref_ref, && addr != 0) i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream); - /* Return number of characters printed, plus one for the - terminating null if we have "reached the end". */ - return (i + (print_max && i != print_max)); + /* Return number of characters printed, including the terminating + '\0' if we reached the end. val_print_string takes care including + the terminating '\0' if necessary. */ + return i; + } + break; + + case TYPE_CODE_REF: + elttype = check_typedef (TYPE_TARGET_TYPE (type)); + if (addressprint) + { + CORE_ADDR addr + = extract_typed_address (valaddr + embedded_offset, type); + fprintf_filtered (stream, "@"); + deprecated_print_address_numeric (addr, 1, stream); + if (deref_ref) + fputs_filtered (": ", stream); + } + /* De-reference the reference. */ + if (deref_ref) + { + if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) + { + struct value *deref_val = + value_at + (TYPE_TARGET_TYPE (type), + unpack_pointer (lookup_pointer_type (builtin_type_void), + valaddr + embedded_offset)); + common_val_print (deref_val, stream, format, deref_ref, recurse, + pretty); + } + else + fputs_filtered ("???", stream); } break; @@ -482,6 +484,13 @@ f_val_print (type, valaddr, embedded_offset, address, stream, format, deref_ref, } break; + case TYPE_CODE_FLAGS: + if (format) + print_scalar_formatted (valaddr, type, format, 0, stream); + else + val_print_type_code_flags (type, valaddr, stream); + break; + case TYPE_CODE_FLT: if (format) print_scalar_formatted (valaddr, type, format, 0, stream); @@ -524,7 +533,7 @@ f_val_print (type, valaddr, embedded_offset, address, stream, format, deref_ref, break; default: - error ("Logicals of length %d bytes not supported", + error (_("Logicals of length %d bytes not supported"), TYPE_LENGTH (type)); } @@ -559,12 +568,12 @@ f_val_print (type, valaddr, embedded_offset, address, stream, format, deref_ref, type = builtin_type_f_real_s16; break; default: - error ("Cannot print out complex*%d variables", TYPE_LENGTH (type)); + error (_("Cannot print out complex*%d variables"), TYPE_LENGTH (type)); } fputs_filtered ("(", stream); print_floating (valaddr, type, stream); fputs_filtered (",", stream); - print_floating (valaddr, type, stream); + print_floating (valaddr + TYPE_LENGTH (type), type, stream); fputs_filtered (")", stream); break; @@ -575,26 +584,41 @@ f_val_print (type, valaddr, embedded_offset, address, stream, format, deref_ref, fprintf_filtered (stream, ""); break; + case TYPE_CODE_STRUCT: + /* Starting from the Fortran 90 standard, Fortran supports derived + types. */ + fprintf_filtered (stream, "{ "); + for (index = 0; index < TYPE_NFIELDS (type); index++) + { + int offset = TYPE_FIELD_BITPOS (type, index) / 8; + f_val_print (TYPE_FIELD_TYPE (type, index), valaddr + offset, + embedded_offset, address, stream, + format, deref_ref, recurse, pretty); + if (index != TYPE_NFIELDS (type) - 1) + fputs_filtered (", ", stream); + } + fprintf_filtered (stream, "}"); + break; + default: - error ("Invalid F77 type code %d in symbol table.", TYPE_CODE (type)); + error (_("Invalid F77 type code %d in symbol table."), TYPE_CODE (type)); } gdb_flush (stream); return 0; } static void -list_all_visible_commons (funname) - char *funname; +list_all_visible_commons (char *funname) { SAVED_F77_COMMON_PTR tmp; tmp = head_common_list; - printf_filtered ("All COMMON blocks visible at this level:\n\n"); + printf_filtered (_("All COMMON blocks visible at this level:\n\n")); while (tmp != NULL) { - if (STREQ (tmp->owning_function, funname)) + if (strcmp (tmp->owning_function, funname) == 0) printf_filtered ("%s\n", tmp->name); tmp = tmp->next; @@ -606,14 +630,12 @@ list_all_visible_commons (funname) given name */ static void -info_common_command (comname, from_tty) - char *comname; - int from_tty; +info_common_command (char *comname, int from_tty) { SAVED_F77_COMMON_PTR the_common; COMMON_ENTRY_PTR entry; struct frame_info *fi; - register char *funname = 0; + char *funname = 0; struct symbol *func; /* We have been told to display the contents of F77 COMMON @@ -621,15 +643,15 @@ info_common_command (comname, from_tty) first make sure that it is visible and if so, let us display its contents */ - fi = selected_frame; + fi = deprecated_selected_frame; if (fi == NULL) - error ("No frame selected"); + error (_("No frame selected")); /* The following is generally ripped off from stack.c's routine print_frame_info() */ - func = find_pc_function (fi->pc); + func = find_pc_function (get_frame_pc (fi)); if (func) { /* In certain pathological cases, the symtabs give the wrong @@ -646,22 +668,22 @@ info_common_command (comname, from_tty) be any minimal symbols in the middle of a function. FIXME: (Not necessarily true. What about text labels) */ - struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc); + struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (get_frame_pc (fi)); if (msymbol != NULL && (SYMBOL_VALUE_ADDRESS (msymbol) > BLOCK_START (SYMBOL_BLOCK_VALUE (func)))) - funname = SYMBOL_NAME (msymbol); + funname = DEPRECATED_SYMBOL_NAME (msymbol); else - funname = SYMBOL_NAME (func); + funname = DEPRECATED_SYMBOL_NAME (func); } else { - register struct minimal_symbol *msymbol = - lookup_minimal_symbol_by_pc (fi->pc); + struct minimal_symbol *msymbol = + lookup_minimal_symbol_by_pc (get_frame_pc (fi)); if (msymbol != NULL) - funname = SYMBOL_NAME (msymbol); + funname = DEPRECATED_SYMBOL_NAME (msymbol); } /* If comname is NULL, we assume the user wishes to see the @@ -677,24 +699,24 @@ info_common_command (comname, from_tty) if (the_common) { - if (STREQ (comname, BLANK_COMMON_NAME_LOCAL)) - printf_filtered ("Contents of blank COMMON block:\n"); + if (strcmp (comname, BLANK_COMMON_NAME_LOCAL) == 0) + printf_filtered (_("Contents of blank COMMON block:\n")); else - printf_filtered ("Contents of F77 COMMON block '%s':\n", comname); + printf_filtered (_("Contents of F77 COMMON block '%s':\n"), comname); printf_filtered ("\n"); entry = the_common->entries; while (entry != NULL) { - printf_filtered ("%s = ", SYMBOL_NAME (entry->symbol)); + printf_filtered ("%s = ", DEPRECATED_SYMBOL_NAME (entry->symbol)); print_variable_value (entry->symbol, fi, gdb_stdout); printf_filtered ("\n"); entry = entry->next; } } else - printf_filtered ("Cannot locate the common block %s in function '%s'\n", + printf_filtered (_("Cannot locate the common block %s in function '%s'\n"), comname, funname); } @@ -703,21 +725,20 @@ info_common_command (comname, from_tty) #if 0 static int -there_is_a_visible_common_named (comname) - char *comname; +there_is_a_visible_common_named (char *comname) { SAVED_F77_COMMON_PTR the_common; struct frame_info *fi; - register char *funname = 0; + char *funname = 0; struct symbol *func; if (comname == NULL) - error ("Cannot deal with NULL common name!"); + error (_("Cannot deal with NULL common name!")); - fi = selected_frame; + fi = deprecated_selected_frame; if (fi == NULL) - error ("No frame selected"); + error (_("No frame selected")); /* The following is generally ripped off from stack.c's routine print_frame_info() */ @@ -744,17 +765,17 @@ there_is_a_visible_common_named (comname) if (msymbol != NULL && (SYMBOL_VALUE_ADDRESS (msymbol) > BLOCK_START (SYMBOL_BLOCK_VALUE (func)))) - funname = SYMBOL_NAME (msymbol); + funname = DEPRECATED_SYMBOL_NAME (msymbol); else - funname = SYMBOL_NAME (func); + funname = DEPRECATED_SYMBOL_NAME (func); } else { - register struct minimal_symbol *msymbol = + struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc); if (msymbol != NULL) - funname = SYMBOL_NAME (msymbol); + funname = DEPRECATED_SYMBOL_NAME (msymbol); } the_common = find_common_for_function (comname, funname); @@ -764,11 +785,11 @@ there_is_a_visible_common_named (comname) #endif void -_initialize_f_valprint () +_initialize_f_valprint (void) { add_info ("common", info_common_command, - "Print out the values contained in a Fortran COMMON block."); + _("Print out the values contained in a Fortran COMMON block.")); if (xdb_commands) add_com ("lc", class_info, info_common_command, - "Print out the values contained in a Fortran COMMON block."); + _("Print out the values contained in a Fortran COMMON block.")); }