Signed vs. unsigned adresses in solib-svr4

Andreas Schwab schwab@suse.de
Thu Mar 29 11:38:00 GMT 2007


Daniel Jacobowitz <drow@false.org> writes:

> On Tue, Mar 27, 2007 at 10:20:23PM +0200, Andreas Schwab wrote:
>> > - since I know that the assumption is wrong for MIPS.  Isn't there an
>> > extract_address or something like that which would be suitable?
>> 
>> There is extract_typed_address, but I don't know how to construct the
>> struct type that it needs.
>
> Probably builtin_type_void_data_ptr is all you need.

How about this then?  Regtestest on
{i386,ia64,ppc,ppc64,s390,s390x,x86_64}-linux.

Andreas.

2007-03-29  Andreas Schwab  <schwab@suse.de>

	* solib-svr4.h (struct link_map_offsets): Remove l_addr_size,
	l_ld_size, l_next_size, l_prev_size, l_name_size.

	* solib-svr4.c (LM_ADDR_FROM_LINK_MAP): Use extract_typed_address
	to extract addresses from link map.
	(LM_DYNAMIC_FROM_LINK_MAP): Likewise.
	(LM_NEXT): Likewise.
	(LM_NAME): Likewise.
	(IGNORE_FIRST_LINK_MAP_ENTRY): Likewise.
	(elf_locate_base): Likewise.
	(open_symbol_file_object): Likewise.
	(svr4_fetch_objfile_link_map): Likewise.
	(SOLIB_EXTRACT_ADDRESS): Remove unused macro.
	(HAS_LM_DYNAMIC_FROM_LINK_MAP): Test l_ld_offset instead of
	l_ld_size.
        (svr4_ilp32_fetch_link_map_offsets): Don't set removed members.
	(svr4_lp64_fetch_link_map_offsets): Likewise.

	* solib-legacy.c (legacy_svr4_fetch_link_map_offsets): Don't set
	removed members.  Set l_ld_offset to -1 if not present.

--- gdb/solib-legacy.c.~1.11.~	2007-01-10 11:18:50.000000000 +0100
+++ gdb/solib-legacy.c	2007-03-29 12:56:05.000000000 +0200
@@ -63,51 +63,28 @@ legacy_svr4_fetch_link_map_offsets (void
       lmo.link_map_size = sizeof (struct link_map);
 
       lmo.l_addr_offset = offsetof (struct link_map, l_addr);
-      lmo.l_addr_size = fieldsize (struct link_map, l_addr);
-
       lmo.l_next_offset = offsetof (struct link_map, l_next);
-      lmo.l_next_size = fieldsize (struct link_map, l_next);
-
       lmo.l_ld_offset = offsetof (struct link_map, l_ld);
-      lmo.l_ld_size = fieldsize (struct link_map, l_ld);
-
       lmo.l_prev_offset = offsetof (struct link_map, l_prev);
-      lmo.l_prev_size = fieldsize (struct link_map, l_prev);
-
       lmo.l_name_offset = offsetof (struct link_map, l_name);
-      lmo.l_name_size = fieldsize (struct link_map, l_name);
 #else /* !defined(HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS) */
 #ifdef HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS
       lmo.link_map_size = sizeof (struct link_map);
 
       lmo.l_addr_offset = offsetof (struct link_map, lm_addr);
-      lmo.l_addr_size = fieldsize (struct link_map, lm_addr);
-
       lmo.l_next_offset = offsetof (struct link_map, lm_next);
-      lmo.l_next_size = fieldsize (struct link_map, lm_next);
-
       /* FIXME: Is this the right field name, or is it available at all?  */
       lmo.l_ld_offset = offsetof (struct link_map, lm_ld);
-      lmo.l_ld_size = fieldsize (struct link_map, lm_ld);
-
       lmo.l_name_offset = offsetof (struct link_map, lm_name);
-      lmo.l_name_size = fieldsize (struct link_map, lm_name);
 #else /* !defined(HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS) */
 #if HAVE_STRUCT_SO_MAP_WITH_SOM_MEMBERS
       lmo.link_map_size = sizeof (struct so_map);
 
       lmo.l_addr_offset = offsetof (struct so_map, som_addr);
-      lmo.l_addr_size = fieldsize (struct so_map, som_addr);
-
       lmo.l_next_offset = offsetof (struct so_map, som_next);
-      lmo.l_next_size = fieldsize (struct so_map, som_next);
-
       lmo.l_name_offset = offsetof (struct so_map, som_path);
-      lmo.l_name_size = fieldsize (struct so_map, som_path);
-
       /* FIXME: Is the address of the dynamic table available?  */
-      lmo.l_ld_offset = 0;
-      lmo.l_ld_size = 0;
+      lmo.l_ld_offset = -1;
 #endif /* HAVE_STRUCT_SO_MAP_WITH_SOM_MEMBERS */
 #endif /* HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS */
 #endif /* HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS */
@@ -126,16 +103,9 @@ legacy_svr4_fetch_link_map_offsets (void
       lmo32.link_map_size = sizeof (struct link_map32);
 
       lmo32.l_addr_offset = offsetof (struct link_map32, l_addr);
-      lmo32.l_addr_size = fieldsize (struct link_map32, l_addr);
-
       lmo32.l_next_offset = offsetof (struct link_map32, l_next);
-      lmo32.l_next_size = fieldsize (struct link_map32, l_next);
-
       lmo32.l_prev_offset = offsetof (struct link_map32, l_prev);
-      lmo32.l_prev_size = fieldsize (struct link_map32, l_prev);
-
       lmo32.l_name_offset = offsetof (struct link_map32, l_name);
-      lmo32.l_name_size = fieldsize (struct link_map32, l_name);
     }
 #endif /* defined (HAVE_STRUCT_LINK_MAP32) */
 
--- gdb/solib-svr4.c.~1.61.~	2007-03-27 21:15:04.000000000 +0200
+++ gdb/solib-svr4.c	2007-03-29 12:56:47.000000000 +0200
@@ -118,19 +118,6 @@ static char *main_name_list[] =
   NULL
 };
 
-/* Macro to extract an address from a solib structure.  When GDB is
-   configured for some 32-bit targets (e.g. Solaris 2.7 sparc), BFD is
-   configured to handle 64-bit targets, so CORE_ADDR is 64 bits.  We
-   have to extract only the significant bits of addresses to get the
-   right address when accessing the core file BFD.
-
-   Assume that the address is unsigned.  */
-
-#define SOLIB_EXTRACT_ADDRESS(MEMBER) \
-	extract_unsigned_integer (&(MEMBER), sizeof (MEMBER))
-
-/* local data declarations */
-
 /* link map access functions */
 
 static CORE_ADDR
@@ -138,9 +125,8 @@ LM_ADDR_FROM_LINK_MAP (struct so_list *s
 {
   struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
 
-  return (CORE_ADDR) extract_signed_integer (so->lm_info->lm
-					     + lmo->l_addr_offset,
-					     lmo->l_addr_size);
+  return extract_typed_address (so->lm_info->lm + lmo->l_addr_offset,
+				builtin_type_void_data_ptr);
 }
 
 static int
@@ -148,7 +134,7 @@ HAS_LM_DYNAMIC_FROM_LINK_MAP ()
 {
   struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
 
-  return (lmo->l_ld_size != 0);
+  return lmo->l_ld_offset >= 0;
 }
 
 static CORE_ADDR
@@ -156,11 +142,8 @@ LM_DYNAMIC_FROM_LINK_MAP (struct so_list
 {
   struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
 
-  gdb_assert (lmo->l_ld_size != 0);
-
-  return (CORE_ADDR) extract_signed_integer (so->lm_info->lm
-					     + lmo->l_ld_offset,
-					     lmo->l_ld_size);
+  return extract_typed_address (so->lm_info->lm + lmo->l_ld_offset,
+				builtin_type_void_data_ptr);
 }
 
 static CORE_ADDR
@@ -238,9 +221,8 @@ LM_NEXT (struct so_list *so)
 {
   struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
 
-  /* Assume that the address is unsigned.  */
-  return extract_unsigned_integer (so->lm_info->lm + lmo->l_next_offset,
-				   lmo->l_next_size);
+  return extract_typed_address (so->lm_info->lm + lmo->l_next_offset,
+				builtin_type_void_data_ptr);
 }
 
 static CORE_ADDR
@@ -248,9 +230,8 @@ LM_NAME (struct so_list *so)
 {
   struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
 
-  /* Assume that the address is unsigned.  */
-  return extract_unsigned_integer (so->lm_info->lm + lmo->l_name_offset,
-				   lmo->l_name_size);
+  return extract_typed_address (so->lm_info->lm + lmo->l_name_offset,
+				builtin_type_void_data_ptr);
 }
 
 static int
@@ -258,9 +239,8 @@ IGNORE_FIRST_LINK_MAP_ENTRY (struct so_l
 {
   struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
 
-  /* Assume that the address is unsigned.  */
-  return extract_unsigned_integer (so->lm_info->lm + lmo->l_prev_offset,
-				   lmo->l_prev_size) == 0;
+  return extract_typed_address (so->lm_info->lm + lmo->l_prev_offset,
+				builtin_type_void_data_ptr) == 0;
 }
 
 static CORE_ADDR debug_base;	/* Base of dynamic linker structures */
@@ -446,7 +426,7 @@ elf_locate_base (void)
 	  else if (dyn_tag == DT_MIPS_RLD_MAP)
 	    {
 	      gdb_byte *pbuf;
-	      int pbuf_size = TARGET_PTR_BIT / HOST_CHAR_BIT;
+	      int pbuf_size = TYPE_LENGTH (builtin_type_void_data_ptr);
 
 	      pbuf = alloca (pbuf_size);
 	      /* DT_MIPS_RLD_MAP contains a pointer to the address
@@ -455,7 +435,7 @@ elf_locate_base (void)
 				      (bfd_byte *) x_dynp->d_un.d_ptr);
 	      if (target_read_memory (dyn_ptr, pbuf, pbuf_size))
 		return 0;
-	      return extract_unsigned_integer (pbuf, pbuf_size);
+	      return extract_typed_address (pbuf, builtin_type_void_data_ptr);
 	    }
 	}
     }
@@ -481,7 +461,7 @@ elf_locate_base (void)
 	  else if (dyn_tag == DT_MIPS_RLD_MAP)
 	    {
 	      gdb_byte *pbuf;
-	      int pbuf_size = TARGET_PTR_BIT / HOST_CHAR_BIT;
+	      int pbuf_size = TYPE_LENGTH (builtin_type_void_data_ptr);
 
 	      pbuf = alloca (pbuf_size);
 	      /* DT_MIPS_RLD_MAP contains a pointer to the address
@@ -490,7 +470,7 @@ elf_locate_base (void)
 				      (bfd_byte *) x_dynp->d_un.d_ptr);
 	      if (target_read_memory (dyn_ptr, pbuf, pbuf_size))
 		return 0;
-	      return extract_unsigned_integer (pbuf, pbuf_size);
+	      return extract_typed_address (pbuf, builtin_type_void_data_ptr);
 	    }
 	}
     }
@@ -620,7 +600,8 @@ open_symbol_file_object (void *from_ttyp
   int errcode;
   int from_tty = *(int *)from_ttyp;
   struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
-  gdb_byte *l_name_buf = xmalloc (lmo->l_name_size);
+  int l_name_size = TYPE_LENGTH (builtin_type_void_data_ptr);
+  gdb_byte *l_name_buf = xmalloc (l_name_size);
   struct cleanup *cleanups = make_cleanup (xfree, l_name_buf);
 
   if (symfile_objfile)
@@ -636,11 +617,10 @@ open_symbol_file_object (void *from_ttyp
     return 0;	/* failed somehow... */
 
   /* Read address of name from target memory to GDB.  */
-  read_memory (lm + lmo->l_name_offset, l_name_buf, lmo->l_name_size);
+  read_memory (lm + lmo->l_name_offset, l_name_buf, l_name_size);
 
-  /* Convert the address to host format.  Assume that the address is
-     unsigned.  */
-  l_name = extract_unsigned_integer (l_name_buf, lmo->l_name_size);
+  /* Convert the address to host format.  */
+  l_name = extract_typed_address (l_name_buf, builtin_type_void_data_ptr);
 
   /* Free l_name_buf.  */
   do_cleanups (cleanups);
@@ -836,7 +816,8 @@ svr4_fetch_objfile_link_map (struct objf
       struct lm_info objfile_lm_info;
       struct cleanup *old_chain;
       CORE_ADDR name_address;
-      gdb_byte *l_name_buf = xmalloc (lmo->l_name_size);
+      int l_name_size = TYPE_LENGTH (builtin_type_void_data_ptr);
+      gdb_byte *l_name_buf = xmalloc (l_name_size);
       old_chain = make_cleanup (xfree, l_name_buf);
 
       /* Set up the buffer to contain the portion of the link_map
@@ -849,11 +830,11 @@ svr4_fetch_objfile_link_map (struct objf
       read_memory (lm, objfile_lm_info.lm, lmo->link_map_size);
 
       /* Read address of name from target memory to GDB.  */
-      read_memory (lm + lmo->l_name_offset, l_name_buf, lmo->l_name_size);
+      read_memory (lm + lmo->l_name_offset, l_name_buf, l_name_size);
 
-      /* Extract this object's name.  Assume that the address is
-         unsigned.  */
-      name_address = extract_unsigned_integer (l_name_buf, lmo->l_name_size);
+      /* Extract this object's name.  */
+      name_address = extract_typed_address (l_name_buf,
+					    builtin_type_void_data_ptr);
       target_read_string (name_address, &buffer,
       			  SO_NAME_MAX_PATH_SIZE - 1, &errcode);
       make_cleanup (xfree, buffer);
@@ -872,10 +853,9 @@ svr4_fetch_objfile_link_map (struct objf
     	      return lm;
       	    }
   	}
-      /* Not the file we wanted, continue checking.  Assume that the
-         address is unsigned.  */
-      lm = extract_unsigned_integer (objfile_lm_info.lm + lmo->l_next_offset,
-				     lmo->l_next_size);
+      /* Not the file we wanted, continue checking.  */
+      lm = extract_typed_address (objfile_lm_info.lm + lmo->l_next_offset,
+				  builtin_type_void_data_ptr);
       do_cleanups (old_chain);
     }
   return 0;
@@ -1521,15 +1501,10 @@ svr4_ilp32_fetch_link_map_offsets (void)
       /* Everything we need is in the first 20 bytes.  */
       lmo.link_map_size = 20;
       lmo.l_addr_offset = 0;
-      lmo.l_addr_size = 4;
       lmo.l_name_offset = 4;
-      lmo.l_name_size = 4;
       lmo.l_ld_offset = 8;
-      lmo.l_ld_size = 4;
       lmo.l_next_offset = 12;
-      lmo.l_next_size = 4;
       lmo.l_prev_offset = 16;
-      lmo.l_prev_size = 4;
     }
 
   return lmp;
@@ -1556,15 +1531,10 @@ svr4_lp64_fetch_link_map_offsets (void)
       /* Everything we need is in the first 40 bytes.  */
       lmo.link_map_size = 40;
       lmo.l_addr_offset = 0;
-      lmo.l_addr_size = 8;
       lmo.l_name_offset = 8;
-      lmo.l_name_size = 8;
       lmo.l_ld_offset = 16;
-      lmo.l_ld_size = 8;
       lmo.l_next_offset = 24;
-      lmo.l_next_size = 8;
       lmo.l_prev_offset = 32;
-      lmo.l_prev_size = 8;
     }
 
   return lmp;
--- gdb/solib-svr4.h.~1.13.~	2007-01-10 11:18:50.000000000 +0100
+++ gdb/solib-svr4.h	2007-03-29 13:37:05.000000000 +0200
@@ -46,32 +46,17 @@ struct link_map_offsets
     /* Offset to l_addr field in struct link_map.  */
     int l_addr_offset;
 
-    /* Size of l_addr field in struct link_map.  */
-    int l_addr_size;
-
     /* Offset to l_ld field in struct link_map.  */
     int l_ld_offset;
 
-    /* Size of l_ld field in struct link_map.  */
-    int l_ld_size;
-
     /* Offset to l_next field in struct link_map.  */
     int l_next_offset;
 
-    /* Size of l_next field in struct link_map.  */
-    int l_next_size;
-
     /* Offset to l_prev field in struct link_map.  */
     int l_prev_offset;
 
-    /* Size of l_prev field in struct link_map.  */
-    int l_prev_size;
-
     /* Offset to l_name field in struct link_map.  */
     int l_name_offset;
-
-    /* Size of l_name field in struct link_map.  */
-    int l_name_size;
   };
 
 /* set_solib_svr4_fetch_link_map_offsets() is intended to be called by

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



More information about the Gdb-patches mailing list