* os9kread.c (os9k_process_one_symbol): Note nonportable
authorFred Fish <fnf@specifix.com>
Sun, 24 Mar 1996 00:22:50 +0000 (00:22 +0000)
committerFred Fish <fnf@specifix.com>
Sun, 24 Mar 1996 00:22:50 +0000 (00:22 +0000)
assumption that an int can hold a char *.

* bcache.h (struct hashlink): Wrap data[] inside union with
double to force longest alignment.
(BCACHE_DATA): New macro to access data[].
(BCACHE_ALIGNMENT): New macro to get offset to data[].
* bcache.c (lookup_cache, bcache): Use BCACHE_DATA to get
  address of cached data.  Use BCACHE_ALIGNMENT to compute
amount of space to allocate for each hashlink struct.

gdb/ChangeLog
gdb/bcache.c
gdb/bcache.h
gdb/os9kread.c

index b156178981632fdcbc2cab9d0a860ee1933f2b38..f8c73d43afb88e5d50e6fd3e39083a54b5523840 100644 (file)
@@ -1,3 +1,16 @@
+Sat Mar 23 17:24:28 1996  Fred Fish  <fnf@cygnus.com>
+
+       * os9kread.c (os9k_process_one_symbol): Note nonportable
+       assumption that an int can hold a char *.
+
+       * bcache.h (struct hashlink): Wrap data[] inside union with
+       double to force longest alignment.
+       (BCACHE_DATA): New macro to access data[].
+       (BCACHE_ALIGNMENT): New macro to get offset to data[].
+       * bcache.c (lookup_cache, bcache): Use BCACHE_DATA to get
+       address of cached data.  Use BCACHE_ALIGNMENT to compute
+       amount of space to allocate for each hashlink struct.
+
 Sat Mar 23 17:10:56 1996  Fred Fish  <fnf@cygnus.com>
 
        * configure, testsuite/configure, testsuite/gdb.base/configure,
index af80afbbdd8a14c0f4840866a70f8d67e710fc6f..c47893b2edff7c1c22e55c8f1d11a4a91efd1585 100644 (file)
@@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "defs.h"
 #include "obstack.h"
 #include "bcache.h"
+#include "gdb_string.h"                /* For memcpy declaration */
 
 /* FIXME:  Incredibly simplistic hash generator.  Probably way too expensive
  (consider long strings) and unlikely to have good distribution across hash
@@ -67,9 +68,9 @@ lookup_cache (bytes, count, hashval, bcachep)
       linkp = hashtablep[hashval];
       while (linkp != NULL)
        {
-         if (memcmp (linkp -> data, bytes, count) == 0)
+         if (memcmp (BCACHE_DATA (linkp), bytes, count) == 0)
            {
-             location = linkp -> data;
+             location = BCACHE_DATA (linkp);
              break;
            }
          linkp = linkp -> next;
@@ -115,17 +116,17 @@ bcache (bytes, count, bcachep)
            {
              *hashtablepp = (struct hashlink **)
                obstack_alloc (&bcachep->cache, BCACHE_HASHSIZE * sizeof (struct hashlink *));
-             bcachep -> cache_bytes += sizeof (struct hashlink *);
+             bcachep -> cache_bytes += BCACHE_HASHSIZE * sizeof (struct hashlink *);
              memset (*hashtablepp, 0, BCACHE_HASHSIZE * sizeof (struct hashlink *));
            }
          linkpp = &(*hashtablepp)[hashval];
          newlink = (struct hashlink *)
-           obstack_alloc (&bcachep->cache, sizeof (struct hashlink *) + count);
-         bcachep -> cache_bytes += sizeof (struct hashlink *) + count;
-         memcpy (newlink -> data, bytes, count);
+           obstack_alloc (&bcachep->cache, BCACHE_DATA_ALIGNMENT + count);
+         bcachep -> cache_bytes += BCACHE_DATA_ALIGNMENT + count;
+         memcpy (BCACHE_DATA (newlink), bytes, count);
          newlink -> next = *linkpp;
          *linkpp = newlink;
-         location = newlink -> data;
+         location = BCACHE_DATA (newlink);
        }
     }
   return (location);
index e389c8eb16bf408780b1f5aedebc460a00bee1d7..1e6d25a547a32de86a738efce3b16d55d6f9d911 100644 (file)
@@ -25,11 +25,30 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #define BCACHE_HASHSIZE        (1 << BCACHE_HASHLENGTH)
 #define BCACHE_MAXLENGTH       128
 
+/* Note that the user data is stored in data[].  Since it can be any type,
+   it needs to have the same alignment  as the most strict alignment of 
+   any type on the host machine.  So do it the same way obstack does. */
+
 struct hashlink {
   struct hashlink *next;
-  char data[1];
+  union {
+    char data[1];
+    double dummy;
+  } d;
 };
 
+/* BCACHE_DATA is used to get the address of the cached data. */
+
+#define BCACHE_DATA(p) ((p)->d.data)
+
+/* BCACHE_DATA_ALIGNMENT is used to get the offset of the start of
+   cached data within the hashlink struct.  This value, plus the
+   size of the cached data, is the amount of space to allocate for
+   a hashlink struct to hold the next pointer and the data. */
+
+#define BCACHE_DATA_ALIGNMENT \
+       (((char *) &BCACHE_DATA((struct hashlink*) 0) - (char *) 0))
+
 struct bcache {
   struct obstack cache;
   struct hashlink **indextable[BCACHE_MAXLENGTH];
index 2de292219b4773198c21b44448d2aa85ed0e4162..edef8bc4674b261bf555087eb0b3d1660ca9ddc0 100644 (file)
@@ -1528,9 +1528,10 @@ os9k_process_one_symbol (type, desc, valu, name, section_offsets, objfile)
     case N_SYM_SLINE:
       /* This type of "symbol" really just records
         one line-number -- core-address correspondence.
-        Enter it in the line list for this symbol table.  */
+        Enter it in the line list for this symbol table. */
       /* Relocate for dynamic loading and for ELF acc fn-relative syms.  */
       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT); 
+      /* FIXME: loses if sizeof (char *) > sizeof (int) */
       record_line (current_subfile, (int)name, valu);
       break;
 
This page took 0.031186 seconds and 4 git commands to generate.