* sol-thread.c (_initialize_sol_thread): Add FIXME regarding
[deliverable/binutils-gdb.git] / gdb / f-valprint.c
index 69e7da02e98b1f7bc970c490a3d5375b95e4e2dd..26aa83b31bad7b470814d81a6d3b7a713ae0d316 100644 (file)
@@ -1,7 +1,7 @@
 /* Support for printing Fortran values for GDB, the GNU debugger.
 
-   Copyright 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2003, 2005 Free
-   Software Foundation, Inc.
+   Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2003, 2005, 2006,
+   2007, 2008 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.
@@ -10,7 +10,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -19,9 +19,7 @@
    GNU General Public License for more details.
 
    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.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
 #include "gdb_string.h"
@@ -65,13 +63,15 @@ int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
 int
 f77_get_dynamic_lowerbound (struct type *type, int *lower_bound)
 {
+  struct frame_info *frame;
   CORE_ADDR current_frame_addr;
   CORE_ADDR ptr_to_lower_bound;
 
   switch (TYPE_ARRAY_LOWER_BOUND_TYPE (type))
     {
     case BOUND_BY_VALUE_ON_STACK:
-      current_frame_addr = get_frame_base (deprecated_selected_frame);
+      frame = deprecated_safe_get_selected_frame ();
+      current_frame_addr = get_frame_base (frame);
       if (current_frame_addr > 0)
        {
          *lower_bound =
@@ -95,13 +95,15 @@ f77_get_dynamic_lowerbound (struct type *type, int *lower_bound)
       break;
 
     case BOUND_BY_REF_ON_STACK:
-      current_frame_addr = get_frame_base (deprecated_selected_frame);
+      frame = deprecated_safe_get_selected_frame ();
+      current_frame_addr = get_frame_base (frame);
       if (current_frame_addr > 0)
        {
+         struct gdbarch *arch = get_frame_arch (frame);
          ptr_to_lower_bound =
            read_memory_typed_address (current_frame_addr +
                                       TYPE_ARRAY_LOWER_BOUND_VALUE (type),
-                                      builtin_type_void_data_ptr);
+                                      builtin_type (arch)->builtin_data_ptr);
          *lower_bound = read_memory_integer (ptr_to_lower_bound, 4);
        }
       else
@@ -123,13 +125,15 @@ f77_get_dynamic_lowerbound (struct type *type, int *lower_bound)
 int
 f77_get_dynamic_upperbound (struct type *type, int *upper_bound)
 {
+  struct frame_info *frame;
   CORE_ADDR current_frame_addr = 0;
   CORE_ADDR ptr_to_upper_bound;
 
   switch (TYPE_ARRAY_UPPER_BOUND_TYPE (type))
     {
     case BOUND_BY_VALUE_ON_STACK:
-      current_frame_addr = get_frame_base (deprecated_selected_frame);
+      frame = deprecated_safe_get_selected_frame ();
+      current_frame_addr = get_frame_base (frame);
       if (current_frame_addr > 0)
        {
          *upper_bound =
@@ -158,13 +162,15 @@ f77_get_dynamic_upperbound (struct type *type, int *upper_bound)
       break;
 
     case BOUND_BY_REF_ON_STACK:
-      current_frame_addr = get_frame_base (deprecated_selected_frame);
+      frame = deprecated_safe_get_selected_frame ();
+      current_frame_addr = get_frame_base (frame);
       if (current_frame_addr > 0)
        {
+         struct gdbarch *arch = get_frame_arch (frame);
          ptr_to_upper_bound =
            read_memory_typed_address (current_frame_addr +
                                       TYPE_ARRAY_UPPER_BOUND_VALUE (type),
-                                      builtin_type_void_data_ptr);
+                                      builtin_type (arch)->builtin_data_ptr);
          *upper_bound = read_memory_integer (ptr_to_upper_bound, 4);
        }
       else
@@ -274,7 +280,7 @@ f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
 
 static void
 f77_print_array_1 (int nss, int ndimensions, struct type *type,
-                  const bfd_byte *valaddr, CORE_ADDR address,
+                  const gdb_byte *valaddr, CORE_ADDR address,
                   struct ui_file *stream, int format,
                   int deref_ref, int recurse, enum val_prettyprint pretty,
                   int *elts)
@@ -304,7 +310,8 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
                     valaddr + i * F77_DIM_OFFSET (ndimensions),
                     0,
                     address + i * F77_DIM_OFFSET (ndimensions),
-                    stream, format, deref_ref, recurse, pretty);
+                    stream, format, deref_ref, recurse, pretty,
+                    current_language);
 
          if (i != (F77_DIM_SIZE (nss) - 1))
            fprintf_filtered (stream, ", ");
@@ -319,7 +326,7 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
    stuff and then immediately call f77_print_array_1() */
 
 static void
-f77_print_array (struct type *type, const bfd_byte *valaddr,
+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)
@@ -358,7 +365,7 @@ f77_print_array (struct type *type, const bfd_byte *valaddr,
    The PRETTY parameter controls prettyprinting.  */
 
 int
-f_val_print (struct type *type, const bfd_byte *valaddr, int embedded_offset,
+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)
 {
@@ -366,6 +373,7 @@ f_val_print (struct type *type, const bfd_byte *valaddr, int embedded_offset,
   struct type *elttype;
   LONGEST val;
   CORE_ADDR addr;
+  int index;
 
   CHECK_TYPEDEF (type);
   switch (TYPE_CODE (type))
@@ -402,7 +410,7 @@ f_val_print (struct type *type, const bfd_byte *valaddr, int embedded_offset,
            }
 
          if (addressprint && format != 's')
-           print_address_numeric (addr, 1, stream);
+           fputs_filtered (paddress (addr), stream);
 
          /* For a pointer to char or unsigned char, also print the string
             pointed to, unless pointer is null.  */
@@ -426,7 +434,7 @@ f_val_print (struct type *type, const bfd_byte *valaddr, int embedded_offset,
          CORE_ADDR addr
            = extract_typed_address (valaddr + embedded_offset, type);
          fprintf_filtered (stream, "@");
-         print_address_numeric (addr, 1, stream);
+         fputs_filtered (paddress (addr), stream);
          if (deref_ref)
            fputs_filtered (": ", stream);
        }
@@ -438,17 +446,9 @@ f_val_print (struct type *type, const bfd_byte *valaddr, int embedded_offset,
              struct value *deref_val =
              value_at
              (TYPE_TARGET_TYPE (type),
-              unpack_pointer (lookup_pointer_type (builtin_type_void),
-                              valaddr + embedded_offset));
-             val_print (value_type (deref_val),
-                        value_contents (deref_val),
-                        0,
-                        VALUE_ADDRESS (deref_val),
-                        stream,
-                        format,
-                        deref_ref,
-                        recurse,
-                        pretty);
+              unpack_pointer (type, valaddr + embedded_offset));
+             common_val_print (deref_val, stream, format, deref_ref, recurse,
+                               pretty, current_language);
            }
          else
            fputs_filtered ("???", stream);
@@ -490,6 +490,13 @@ f_val_print (struct type *type, const bfd_byte *valaddr, int embedded_offset,
        }
       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);
@@ -516,26 +523,7 @@ f_val_print (struct type *type, const bfd_byte *valaddr, int embedded_offset,
        print_scalar_formatted (valaddr, type, format, 0, stream);
       else
        {
-         val = 0;
-         switch (TYPE_LENGTH (type))
-           {
-           case 1:
-             val = unpack_long (builtin_type_f_logical_s1, valaddr);
-             break;
-
-           case 2:
-             val = unpack_long (builtin_type_f_logical_s2, valaddr);
-             break;
-
-           case 4:
-             val = unpack_long (builtin_type_f_logical, valaddr);
-             break;
-
-           default:
-             error (_("Logicals of length %d bytes not supported"),
-                    TYPE_LENGTH (type));
-
-           }
+         val = extract_unsigned_integer (valaddr, TYPE_LENGTH (type));
 
          if (val == 0)
            fprintf_filtered (stream, ".FALSE.");
@@ -555,20 +543,7 @@ f_val_print (struct type *type, const bfd_byte *valaddr, int embedded_offset,
       break;
 
     case TYPE_CODE_COMPLEX:
-      switch (TYPE_LENGTH (type))
-       {
-       case 8:
-         type = builtin_type_f_real;
-         break;
-       case 16:
-         type = builtin_type_f_real_s8;
-         break;
-       case 32:
-         type = builtin_type_f_real_s16;
-         break;
-       default:
-         error (_("Cannot print out complex*%d variables"), TYPE_LENGTH (type));
-       }
+      type = TYPE_TARGET_TYPE (type);
       fputs_filtered ("(", stream);
       print_floating (valaddr, type, stream);
       fputs_filtered (",", stream);
@@ -583,6 +558,23 @@ f_val_print (struct type *type, const bfd_byte *valaddr, int embedded_offset,
       fprintf_filtered (stream, "<incomplete type>");
       break;
 
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+      /* 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));
     }
@@ -597,7 +589,7 @@ list_all_visible_commons (char *funname)
 
   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)
     {
@@ -626,10 +618,7 @@ info_common_command (char *comname, int from_tty)
      first make sure that it is visible and if so, let 
      us display its contents */
 
-  fi = deprecated_selected_frame;
-
-  if (fi == NULL)
-    error (_("No frame selected"));
+  fi = get_selected_frame (_("No frame selected"));
 
   /* The following is generally ripped off from stack.c's routine 
      print_frame_info() */
@@ -651,14 +640,15 @@ info_common_command (char *comname, int 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 (get_frame_pc (fi));
+      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 = DEPRECATED_SYMBOL_NAME (msymbol);
+       funname = SYMBOL_LINKAGE_NAME (msymbol);
       else
-       funname = DEPRECATED_SYMBOL_NAME (func);
+       funname = SYMBOL_LINKAGE_NAME (func);
     }
   else
     {
@@ -666,7 +656,9 @@ info_common_command (char *comname, int from_tty)
       lookup_minimal_symbol_by_pc (get_frame_pc (fi));
 
       if (msymbol != NULL)
-       funname = DEPRECATED_SYMBOL_NAME (msymbol);
+       funname = SYMBOL_LINKAGE_NAME (msymbol);
+      else /* Got no 'funname', code below will fail.  */
+       error (_("No function found for frame."));
     }
 
   /* If comname is NULL, we assume the user wishes to see the 
@@ -683,23 +675,23 @@ info_common_command (char *comname, int from_tty)
   if (the_common)
     {
       if (strcmp (comname, BLANK_COMMON_NAME_LOCAL) == 0)
-       printf_filtered ("Contents of blank COMMON block:\n");
+       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 = ", DEPRECATED_SYMBOL_NAME (entry->symbol));
+         printf_filtered ("%s = ", SYMBOL_PRINT_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);
 }
 
@@ -718,10 +710,7 @@ there_is_a_visible_common_named (char *comname)
   if (comname == NULL)
     error (_("Cannot deal with NULL common name!"));
 
-  fi = deprecated_selected_frame;
-
-  if (fi == NULL)
-    error (_("No frame selected"));
+  fi = get_selected_frame (_("No frame selected"));
 
   /* The following is generally ripped off from stack.c's routine 
      print_frame_info() */
@@ -748,9 +737,9 @@ there_is_a_visible_common_named (char *comname)
       if (msymbol != NULL
          && (SYMBOL_VALUE_ADDRESS (msymbol)
              > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
-       funname = DEPRECATED_SYMBOL_NAME (msymbol);
+       funname = SYMBOL_LINKAGE_NAME (msymbol);
       else
-       funname = DEPRECATED_SYMBOL_NAME (func);
+       funname = SYMBOL_LINKAGE_NAME (func);
     }
   else
     {
@@ -758,7 +747,7 @@ there_is_a_visible_common_named (char *comname)
       lookup_minimal_symbol_by_pc (fi->pc);
 
       if (msymbol != NULL)
-       funname = DEPRECATED_SYMBOL_NAME (msymbol);
+       funname = SYMBOL_LINKAGE_NAME (msymbol);
     }
 
   the_common = find_common_for_function (comname, funname);
@@ -771,8 +760,8 @@ void
 _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."));
 }
This page took 0.028403 seconds and 4 git commands to generate.