This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb/users/hjl/linux/master] always read synthetic pointers as signed integers


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b597c318b86b5ad2bca1f72ee8c0fbe33cbb7dad

commit b597c318b86b5ad2bca1f72ee8c0fbe33cbb7dad
Author: Yao Qi <yao@codesourcery.com>
Date:   Sun Dec 28 16:12:53 2014 +0800

    always read synthetic pointers as signed integers
    
    I see the error message "access outside bounds of object referenced
    via synthetic pointer" in the two fails below of mips gdb testing
    
    print d[-2]^M
    access outside bounds of object referenced via synthetic pointer^M
    (gdb) FAIL: gdb.dwarf2/implptrconst.exp: print d[-2]
    (gdb) print/d p[-1]^M
    access outside bounds of object referenced via synthetic pointer^M
    (gdb) FAIL: gdb.dwarf2/implptrpiece.exp: print/d p[-1]
    
    in the first test, 'd[-2]' is processed by GDB as '* (&d[-2])'.  'd'
    is a synthetic pointer, so its value is zero, the address of 'd[-2]'
    is -2.  In dwarf2loc.c:indirect_pieced_value,
    
      /* This is an offset requested by GDB, such as value subscripts.
         However, due to how synthetic pointers are implemented, this is
         always presented to us as a pointer type.  This means we have to
         sign-extend it manually as appropriate.  */
      byte_offset = value_as_address (value);
      if (TYPE_LENGTH (value_type (value)) < sizeof (LONGEST))
        byte_offset = gdb_sign_extend (byte_offset,
    				   8 * TYPE_LENGTH (value_type (value)));
      byte_offset += piece->v.ptr.offset;
    
    We know that the value is really an offset instead of address, so the
    fix is to extract the value as an (signed) offset.
    
    gdb:
    
    2015-01-08  Pedro Alves  <palves@redhat.com>
    	    Yao Qi  <yao@codesourcery.com>
    
    	* dwarf2loc.c (indirect_pieced_value): Don't call
    	gdb_sign_extend.  Call extract_signed_integer instead.
    	* utils.c (gdb_sign_extend): Remove.
    	* utils.h (gdb_sign_extend): Remove declaration.

Diff:
---
 gdb/ChangeLog   |  8 ++++++++
 gdb/dwarf2loc.c | 16 +++++++++++-----
 gdb/utils.c     | 17 -----------------
 gdb/utils.h     |  5 -----
 4 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2fa7422..fea9207 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2015-01-08  Pedro Alves  <palves@redhat.com>
+	    Yao Qi  <yao@codesourcery.com>
+
+	* dwarf2loc.c (indirect_pieced_value): Don't call
+	gdb_sign_extend.  Call extract_signed_integer instead.
+	* utils.c (gdb_sign_extend): Remove.
+	* utils.h (gdb_sign_extend): Remove declaration.
+
 2015-01-07  Pierre Muller  <muller@sourceware.org>
 
 	PR symtab/17811
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 2bd12d6..bdb2160 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -2012,6 +2012,7 @@ indirect_pieced_value (struct value *value)
   int i, bit_offset, bit_length;
   struct dwarf_expr_piece *piece = NULL;
   LONGEST byte_offset;
+  enum bfd_endian byte_order;
 
   type = check_typedef (value_type (value));
   if (TYPE_CODE (type) != TYPE_CODE_PTR)
@@ -2056,11 +2057,16 @@ indirect_pieced_value (struct value *value)
   /* This is an offset requested by GDB, such as value subscripts.
      However, due to how synthetic pointers are implemented, this is
      always presented to us as a pointer type.  This means we have to
-     sign-extend it manually as appropriate.  */
-  byte_offset = value_as_address (value);
-  if (TYPE_LENGTH (value_type (value)) < sizeof (LONGEST))
-    byte_offset = gdb_sign_extend (byte_offset,
-				   8 * TYPE_LENGTH (value_type (value)));
+     sign-extend it manually as appropriate.  Use raw
+     extract_signed_integer directly rather than value_as_address and
+     sign extend afterwards on architectures that would need it
+     (mostly everywhere except MIPS, which has signed addresses) as
+     the later would go through gdbarch_pointer_to_address and thus
+     return a CORE_ADDR with high bits set on architectures that
+     encode address spaces and other things in CORE_ADDR.  */
+  byte_order = gdbarch_byte_order (get_frame_arch (frame));
+  byte_offset = extract_signed_integer (value_contents (value),
+					TYPE_LENGTH (type), byte_order);
   byte_offset += piece->v.ptr.offset;
 
   gdb_assert (piece);
diff --git a/gdb/utils.c b/gdb/utils.c
index 084db87..72b1e2a 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3021,23 +3021,6 @@ align_down (ULONGEST v, int n)
   return (v & -n);
 }
 
-/* See utils.h.  */
-
-LONGEST
-gdb_sign_extend (LONGEST value, int bit)
-{
-  gdb_assert (bit >= 1 && bit <= 8 * sizeof (LONGEST));
-
-  if (((value >> (bit - 1)) & 1) != 0)
-    {
-      LONGEST signbit = ((LONGEST) 1) << (bit - 1);
-
-      value = (value ^ signbit) - signbit;
-    }
-
-  return value;
-}
-
 /* Allocation function for the libiberty hash table which uses an
    obstack.  The obstack is passed as DATA.  */
 
diff --git a/gdb/utils.h b/gdb/utils.h
index 0a73864..3debde7 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -340,11 +340,6 @@ extern int myread (int, char *, int);
 extern ULONGEST align_up (ULONGEST v, int n);
 extern ULONGEST align_down (ULONGEST v, int n);
 
-/* Sign extend VALUE.  BIT is the (1-based) index of the bit in VALUE
-   to sign-extend.  */
-
-extern LONGEST gdb_sign_extend (LONGEST value, int bit);
-
 /* Resource limits used by getrlimit and setrlimit.  */
 
 enum resource_limit_kind


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]