This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
gdb 5.0: solib.c (LM_ADDR) should be signed, not unsigned (fwd)
- To: gdb-patches at sourceware dot cygnus dot com
- Subject: gdb 5.0: solib.c (LM_ADDR) should be signed, not unsigned (fwd)
- From: "Maciej W. Rozycki" <macro at ds2 dot pg dot gda dot pl>
- Date: Wed, 21 Jun 2000 16:14:38 +0200 (MET DST)
- Organization: Technical University of Gdansk
---------- Forwarded message ----------
Message-ID: <Pine.GSO.3.96.1000619191851.10348S-100000@delta.ds2.pg.gda.pl>
Date: Mon, 19 Jun 2000 19:29:18 +0200 (MET DST)
From: "Maciej W. Rozycki" <macro@ds2.pg.gda.pl>
To: bug-gdb@gnu.org
Subject: gdb 5.0: solib.c (LM_ADDR) should be signed, not unsigned
Hi,
The SVR4 ABI specifies the base address to be a difference between the
load address and the link-time address. Currently it is treated as an
unsigned value. This causes problems on 32-bit platforms, where 64-bit
BFD is available. I've been able to observe it for elf32-littlemips.
Given a link-time address of about 0x5000000 and a load address of about
0x20000000, LM_ADDR is about -0x30000000 or 0xc0000000. Due to an
unsigned promotion of LM_ADDR gdb calculates section addresses incorrectly
to be about 0x120000000 (obviously incorrect for a 32-bit target).
The following patch fixes this problem for me.
Maciej
--
+ Maciej W. Rozycki, Technical University of Gdansk, Poland +
+--------------------------------------------------------------+
+ e-mail: macro@ds2.pg.gda.pl, PGP key available +
diff -u --recursive --new-file gdb-5.0.macro/gdb/defs.h gdb-5.0/gdb/defs.h
--- gdb-5.0.macro/gdb/defs.h Mon May 1 05:45:32 2000
+++ gdb-5.0/gdb/defs.h Sat Jun 17 12:27:17 2000
@@ -1067,6 +1067,8 @@
extern CORE_ADDR extract_address (void *, int);
+extern CORE_ADDR extract_address_diff (void *, int);
+
extern void store_signed_integer (void *, int, LONGEST);
extern void store_unsigned_integer (void *, int, ULONGEST);
diff -u --recursive --new-file gdb-5.0.macro/gdb/findvar.c gdb-5.0/gdb/findvar.c
--- gdb-5.0.macro/gdb/findvar.c Fri Mar 31 22:04:50 2000
+++ gdb-5.0/gdb/findvar.c Sat Jun 17 12:26:31 2000
@@ -177,6 +177,14 @@
return (CORE_ADDR) extract_unsigned_integer (addr, len);
}
+CORE_ADDR
+extract_address_diff (void *addr, int len)
+{
+ /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
+ whether we want this to be true eventually. */
+ return (CORE_ADDR) extract_signed_integer (addr, len);
+}
+
void
store_signed_integer (void *addr, int len, LONGEST val)
{
diff -u --recursive --new-file gdb-5.0.macro/gdb/solib.c gdb-5.0/gdb/solib.c
--- gdb-5.0.macro/gdb/solib.c Wed Apr 5 20:40:22 2000
+++ gdb-5.0/gdb/solib.c Sat Jun 17 13:10:40 2000
@@ -117,10 +117,12 @@
#define SOLIB_EXTRACT_ADDRESS(member) \
extract_address (&member, sizeof (member))
+#define SOLIB_EXTRACT_ADDRESS_DIFF(member) \
+ extract_address_diff (&member, sizeof (member))
#ifndef SVR4_SHARED_LIBS
-#define LM_ADDR(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.lm_addr))
+#define LM_ADDR(so) (SOLIB_EXTRACT_ADDRESS_DIFF ((so) -> lm.lm_addr))
#define LM_NEXT(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.lm_next))
#define LM_NAME(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.lm_name))
/* Test for first link map entry; first entry is a shared library. */
@@ -133,7 +135,7 @@
#else /* SVR4_SHARED_LIBS */
-#define LM_ADDR(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.l_addr))
+#define LM_ADDR(so) (SOLIB_EXTRACT_ADDRESS_DIFF ((so) -> lm.l_addr))
#define LM_NEXT(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.l_next))
#define LM_NAME(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.l_name))
/* Test for first link map entry; first entry is the exec-file. */