* i386-xdep.c, symm-xdep.c: Remove most 387 support.
[deliverable/binutils-gdb.git] / gdb / findvar.c
index c674a548961a40838166f2344478553bb660a722..58da6b6a3fbdcb366908e6289108a2f8032bada6 100644 (file)
@@ -3,19 +3,19 @@
 
 This file is part of GDB.
 
-GDB is free software; you can redistribute it and/or modify
+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 1, or (at your option)
-any later version.
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
 
-GDB is distributed in the hope that it will be useful,
+This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GDB; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include <stdio.h>
 #include "defs.h"
@@ -177,7 +177,7 @@ read_relative_register_raw_bytes (regnum, myaddr)
       return 0;
     }
 
-  get_saved_register (myaddr, &optim, (CORE_ADDR) NULL, selected_frame,
+  get_saved_register (myaddr, &optim, (CORE_ADDR *) NULL, selected_frame,
                       regnum, (enum lval_type *)NULL);
   return optim;
 }
@@ -267,8 +267,9 @@ read_register_bytes (regbyte, myaddr, len)
 }
 
 /* Read register REGNO into memory at MYADDR, which must be large enough
-   for REGISTER_RAW_BYTES (REGNO).  If the register is known to be the
-   size of a CORE_ADDR or smaller, read_register can be used instead.  */
+   for REGISTER_RAW_BYTES (REGNO).  Target byte-order.
+   If the register is known to be the size of a CORE_ADDR or smaller,
+   read_register can be used instead.  */
 void
 read_register_gen (regno, myaddr)
      int regno;
@@ -353,7 +354,8 @@ supply_register (regno, val)
 /* Given a struct symbol for a variable,
    and a stack frame id, read the value of the variable
    and return a (pointer to a) struct value containing the value. 
-   If the variable cannot be found, return a zero pointer.  */
+   If the variable cannot be found, return a zero pointer.
+   If FRAME is NULL, use the selected_frame.  */
 
 value
 read_var_value (var, frame)
@@ -364,7 +366,6 @@ read_var_value (var, frame)
   struct frame_info *fi;
   struct type *type = SYMBOL_TYPE (var);
   CORE_ADDR addr;
-  int val;
   register int len;
 
   v = allocate_value (type);
@@ -376,8 +377,7 @@ read_var_value (var, frame)
   switch (SYMBOL_CLASS (var))
     {
     case LOC_CONST:
-      val = SYMBOL_VALUE (var);
-      bcopy (&val, VALUE_CONTENTS_RAW (v), len);
+      bcopy (&SYMBOL_VALUE (var), VALUE_CONTENTS_RAW (v), len);
       SWAP_TARGET_AND_HOST (VALUE_CONTENTS_RAW (v), len);
       VALUE_LVAL (v) = not_lval;
       return v;
@@ -390,10 +390,13 @@ read_var_value (var, frame)
       return v;
 
     case LOC_CONST_BYTES:
-      addr = SYMBOL_VALUE_ADDRESS (var);
-      bcopy (addr, VALUE_CONTENTS_RAW (v), len);
-      VALUE_LVAL (v) = not_lval;
-      return v;
+      {
+       char *bytes_addr;
+       bytes_addr = SYMBOL_VALUE_BYTES (var);
+       bcopy (bytes_addr, VALUE_CONTENTS_RAW (v), len);
+       VALUE_LVAL (v) = not_lval;
+       return v;
+      }
 
     case LOC_STATIC:
     case LOC_EXTERNAL:
@@ -410,6 +413,8 @@ read_var_value (var, frame)
 
     case LOC_ARG:
       fi = get_frame_info (frame);
+      if (fi == NULL)
+       return 0;
       addr = FRAME_ARGS_ADDRESS (fi);
       if (!addr) {
        return 0;
@@ -419,17 +424,21 @@ read_var_value (var, frame)
       
     case LOC_REF_ARG:
       fi = get_frame_info (frame);
+      if (fi == NULL)
+       return 0;
       addr = FRAME_ARGS_ADDRESS (fi);
       if (!addr) {
        return 0;
       }
       addr += SYMBOL_VALUE (var);
-      addr = read_memory_integer (addr, sizeof (CORE_ADDR));
+      read_memory (addr, &addr, sizeof (CORE_ADDR));
       break;
       
     case LOC_LOCAL:
     case LOC_LOCAL_ARG:
       fi = get_frame_info (frame);
+      if (fi == NULL)
+       return 0;
       addr = SYMBOL_VALUE (var) + FRAME_LOCALS_ADDRESS (fi);
       break;
 
@@ -444,11 +453,15 @@ read_var_value (var, frame)
     case LOC_REGISTER:
     case LOC_REGPARM:
       {
-       struct block *b = get_frame_block (frame);
+       struct block *b;
 
+       if (frame == NULL)
+         return 0;
+       b = get_frame_block (frame);
+       
        v = value_from_register (type, SYMBOL_VALUE (var), frame);
 
-       if (REG_STRUCT_HAS_ADDR(b->gcc_compile_flag)
+       if (REG_STRUCT_HAS_ADDR (BLOCK_GCC_COMPILED (b))
            && TYPE_CODE (type) == TYPE_CODE_STRUCT)
          addr = *(CORE_ADDR *)VALUE_CONTENTS (v);
        else
@@ -621,9 +634,10 @@ value_from_register (type, regnum, frame)
   return v;
 }
 \f
-/* Given a struct symbol for a variable,
+/* Given a struct symbol for a variable or function,
    and a stack frame id, 
-   return a (pointer to a) struct value containing the variable's address.  */
+   return a (pointer to a) struct value containing the properly typed
+   address.  */
 
 value
 locate_var_value (var, frame)
@@ -642,7 +656,8 @@ locate_var_value (var, frame)
   if (lazy_value == 0)
     error ("Address of \"%s\" is unknown.", SYMBOL_NAME (var));
 
-  if (VALUE_LAZY (lazy_value))
+  if (VALUE_LAZY (lazy_value)
+      || TYPE_CODE (type) == TYPE_CODE_FUNC)
     {
       addr = VALUE_ADDRESS (lazy_value);
 
@@ -653,11 +668,12 @@ locate_var_value (var, frame)
        {
          char *buf = alloca (TYPE_LENGTH (type));
          read_memory (addr, buf, TYPE_LENGTH (type));
-         addr = unpack_long (type, buf);
+         addr = unpack_pointer (type, buf);
          type = TYPE_TARGET_TYPE (type);
        }
 
       /* Address of an array is of the type of address of it's elements.  */
+       /* FIXME, this is probably wrong now for ANSI C. */
       result_type =
        lookup_pointer_type (TYPE_CODE (type) == TYPE_CODE_ARRAY ?
                             TYPE_TARGET_TYPE (type) : type);
This page took 0.026343 seconds and 4 git commands to generate.