Fix BZ15121 -- x/a broken for addresses in shared libraries (try #2)
Paul Pluzhnikov
ppluzhnikov@google.com
Mon Oct 10 16:25:00 GMT 2016
Greetings,
Attached is my second attempt to fix BZ15121. Tested on Linux/x86_64;
no new failures.
Previous attempt:
https://sourceware.org/ml/gdb-patches/2015-09/msg00074.html
The change to long_long.exp needs to be made conditional (i.e. use old
pattern on MIPS and SH; new pattern everywhere else). I am not sure how
to achieve that. Should I make it conditional on 'istarget "mips*"' or ... ?
Thanks,
2016-10-10 Paul Pluzhnikov <ppluzhnikov@google.com>
[BZ #15121]
* gdb/gdbarch.h (gdbarch_sign_extend_vma): New.
(set_gdbarch_sign_extend_vma): New.
* gdb/gdbarch.c (struct gdbarch): Add sign_extend_vma.
(gdbarch_sign_extend_vma, set_gdbarch_sign_extend_vma): New.
(gdbarch_find_by_info): Set sign_extend_vma from BFD.
* gdb/value.c (unpack_pointer): Don't sign-extend when necessary.
testsuite/ChangeLog:
2016-10-10 Paul Pluzhnikov <ppluzhnikov@google.com>
[BZ #15121]
* gdb.base/long_long.exp: Adjust.
--
Paul Pluzhnikov
-------------- next part --------------
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 4d8ef18..fd46892 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -130,6 +130,7 @@ struct gdbarch
enum bfd_endian byte_order_for_code;
enum gdb_osabi osabi;
const struct target_desc * target_desc;
+ int sign_extend_vma;
/* target specific vector. */
struct gdbarch_tdep *tdep;
@@ -4918,6 +4919,17 @@ set_gdbarch_addressable_memory_unit_size (struct gdbarch *gdbarch,
gdbarch->addressable_memory_unit_size = addressable_memory_unit_size;
}
+int
+gdbarch_sign_extend_vma (struct gdbarch *gdbarch)
+{
+ return gdbarch->sign_extend_vma;
+}
+
+void
+set_gdbarch_sign_extend_vma (struct gdbarch *gdbarch, int value)
+{
+ gdbarch->sign_extend_vma = value;
+}
/* Keep a registry of per-architecture data-pointers required by GDB
modules. */
@@ -5234,6 +5246,11 @@ gdbarch_find_by_info (struct gdbarch_info info)
return NULL;
}
+ /* We do this every time because on the first call we may not yet have
+ abfd available. */
+ new_gdbarch->sign_extend_vma = info.abfd == NULL ?
+ 0 : bfd_get_sign_extend_vma (info.abfd);
+
/* Is this a pre-existing architecture (as determined by already
being initialized)? Move it to the front of the architecture
list (keeping the list sorted Most Recently Used). */
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index cd01718..26dbf03 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -1530,6 +1530,9 @@ typedef int (gdbarch_addressable_memory_unit_size_ftype) (struct gdbarch *gdbarc
extern int gdbarch_addressable_memory_unit_size (struct gdbarch *gdbarch);
extern void set_gdbarch_addressable_memory_unit_size (struct gdbarch *gdbarch, gdbarch_addressable_memory_unit_size_ftype *addressable_memory_unit_size);
+extern int gdbarch_sign_extend_vma (struct gdbarch *gdbarch);
+extern void set_gdbarch_sign_extend_vma (struct gdbarch *gdbarch, int sign_extend_vma);
+
/* Definition for an unknown syscall, used basically in error-cases. */
#define UNKNOWN_SYSCALL (-1)
diff --git a/gdb/testsuite/gdb.base/long_long.exp b/gdb/testsuite/gdb.base/long_long.exp
index ab47374..8f48266 100644
--- a/gdb/testsuite/gdb.base/long_long.exp
+++ b/gdb/testsuite/gdb.base/long_long.exp
@@ -249,7 +249,7 @@ gdb_test "x/2bd b" "1.*-89"
gdb_test "x/2bu b" "1.*167"
gdb_test "x/2bo b" "01.*0247"
gdb_test "x/2bt b" "00000001.*10100111"
-gdb_test_ptr "x/2ba b" "" "" "0x1.*0xffffffa7" "0x1.*0xffffffffffffffa7"
+gdb_test_ptr "x/2ba b" "" "" "0x1.*0xa7" "0x1.*0xa7"
gdb_test "x/2bc b" "1 '.001'.*-89 '.\[0-9\]*'"
gdb_test "x/2bf b" "1.*-89"
@@ -258,7 +258,7 @@ gdb_test "x/2hd h" "291.*-22738"
gdb_test "x/2hu h" "291.*42798"
gdb_test "x/2ho h" "0443.*0123456"
gdb_test "x/2ht h" "0000000100100011.*1010011100101110"
-gdb_test_ptr "x/2ha h" "" "" "0x123.*0xffffa72e" "0x123.*0xffffffffffffa72e"
+gdb_test_ptr "x/2ha h" "" "" "0x123.*0xa72e" "0x123.*0xa72e"
gdb_test "x/2hc h" "35 '.'.*46 '.'"
gdb_test "x/2hf h" "291.*-22738"
@@ -267,7 +267,7 @@ gdb_test "x/2wd w" "19088743.*-1490098887"
gdb_test "x/2wu w" "19088743.*2804868409"
gdb_test "x/2wo w" "0110642547.*024713562471"
gdb_test "x/2wt w" "00000001001000110100010101100111.*10100111001011101110010100111001"
-gdb_test_ptr "x/2wa w" "" "" "0x1234567.*0xa72ee539" "0x1234567.*0xffffffffa72ee539"
+gdb_test_ptr "x/2wa w" "" "" "0x1234567.*0xa72ee539" "0x1234567.*0xa72ee539"
gdb_test "x/2wc w" "103 'g'.*57 '9'"
gdb_test "x/2wf w" "2.99881655e-0?38.*-2.42716126e-0?15"
diff --git a/gdb/value.c b/gdb/value.c
index b825aec..9c38cfe 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -3040,7 +3040,17 @@ unpack_pointer (struct type *type, const gdb_byte *valaddr)
{
/* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
whether we want this to be true eventually. */
- return unpack_long (type, valaddr);
+ const LONGEST ret = unpack_long (type, valaddr);
+ const int len = TYPE_LENGTH (type);
+
+ if (sizeof (CORE_ADDR) > len && ret < 0) {
+ struct gdbarch *arch = get_type_arch (type);
+
+ if (!gdbarch_sign_extend_vma (arch))
+ /* Don't sign-extend 32-bit pointer. BZ 15121. */
+ return ret & ((1UL << (8 * len)) - 1);
+ }
+ return ret;
}
More information about the Gdb-patches
mailing list