keiths / rpms / gdb

Forked from rpms/gdb 5 months ago
Clone
7b8bd72
http://sourceware.org/ml/gdb-patches/2010-03/msg01000.html
7b8bd72
Subject: [patch 2/6] PIE: Attach binary even after ld.so re-prelinked  underneath
7b8bd72
7b8bd72
Hi,
7b8bd72
7b8bd72
when I have seen the PIE-binary-changed-sice-start tested also
7b8bd72
ld.so-changed-since-start and it did not work.
7b8bd72
7b8bd72
There is questionable when to print and when to not to print non-fatal memory
7b8bd72
read errors.  Similar change I requested in
7b8bd72
	Re: [RFC/ia64] memory error when reading wrong core file
7b8bd72
	http://sourceware.org/ml/gdb-patches/2010-02/msg00001.html
7b8bd72
so that GDB prints at least as a warning
7b8bd72
	Cannot access memory at address ...
7b8bd72
when some unexpected error happens.
7b8bd72
7b8bd72
Contrary to it there is not such warning present in the code below as in the
7b8bd72
case of non-valgrind PIE with re-prelinked ld.so the memory read error happens
7b8bd72
there.  Some GDB code rework could probably avoid it.
7b8bd72
7b8bd72
Just for example all the memory read errors in read_program_header or even
7b8bd72
- primarily - scan_dyntag are currently IMO-incorrectly silent and others.
7b8bd72
Therefore posted the patch this way, making all these warnings printed and
7b8bd72
possibly fixing code attempting incorrect reads along the way could be done by
7b8bd72
a different patch.
7b8bd72
7b8bd72
No regressions on {x86_64,x86_64-m32,i686}-fedora12-linux-gnu for the whole
7b8bd72
patch series together.
7b8bd72
7b8bd72
7b8bd72
Thanks,
7b8bd72
Jan
7b8bd72
7b8bd72
7b8bd72
gdb/
7b8bd72
2010-03-29  Jan Kratochvil  <jan.kratochvil@redhat.com>
7b8bd72
7b8bd72
	* auxv.c (ld_so_xfer_auxv): Do not error on failed read of data_address.
7b8bd72
7b8bd72
gdb/testsuite/
7b8bd72
2010-03-29  Jan Kratochvil  <jan.kratochvil@redhat.com>
7b8bd72
7b8bd72
	* gdb.base/break-interp.exp (test_attach): Keep $interp changed.  Move
7b8bd72
	its restore after the <$relink_args != ""> loop.  new comment.
7b8bd72
7b8bd72
--- a/gdb/auxv.c
7b8bd72
+++ b/gdb/auxv.c
7b8bd72
@@ -96,7 +96,16 @@ ld_so_xfer_auxv (gdb_byte *readbuf,
7b8bd72
 
7b8bd72
   pointer_address = SYMBOL_VALUE_ADDRESS (msym);
7b8bd72
 
7b8bd72
-  data_address = read_memory_typed_address (pointer_address, ptr_type);
7b8bd72
+  /* While it is an error I am not aware how to solve attaching to PIE under
7b8bd72
+     valgrind --db-attach=yes different way when ld.so on-disk file has prelink
7b8bd72
+     change in the meantime.  Currently GDB will drop back to procfs_xfer_auxv
7b8bd72
+     (so that at least non-valgrind PIE attachments with prelink change of
7b8bd72
+     ld.so work).  To make it working even with valgrind is PR 11440 requiring
7b8bd72
+     a valgrind extension.  */
7b8bd72
+  if (target_read_memory (pointer_address, ptr_buf, ptr_size) != 0)
7b8bd72
+    return -1;
7b8bd72
+
7b8bd72
+  data_address = extract_typed_address (ptr_buf, ptr_type);
7b8bd72
 
7b8bd72
   /* Possibly still not initialized such as during an inferior startup.  */
7b8bd72
   if (data_address == 0)
7b8bd72
--- a/gdb/testsuite/gdb.base/break-interp.exp
7b8bd72
+++ b/gdb/testsuite/gdb.base/break-interp.exp
7b8bd72
@@ -419,12 +419,16 @@ proc test_attach {file displacement {relink_args ""}} {
7b8bd72
 	global exec interp_saved interp
7b8bd72
 
7b8bd72
 	foreach relink {YES NO} {
7b8bd72
-	    if {[prelink$relink $relink_args [file tail $exec]]
7b8bd72
-	        && [copy $interp_saved $interp]} {
7b8bd72
+	    # It would be more correct to also [copy $interp_saved $interp]
7b8bd72
+	    # here to really test just different prelink of $exec.
7b8bd72
+	    # But we would need a separate test for different prelink of ld.so
7b8bd72
+	    # where a bug occured.  It is now all merged into this single test.
7b8bd72
+	    if [prelink$relink $relink_args [file tail $exec]] {
7b8bd72
 		# /proc/PID/exe cannot be loaded as it is "EXECNAME (deleted)".
7b8bd72
 		test_attach_gdb $exec $pid $displacement "attach-relink$relink"
7b8bd72
 	    }
7b8bd72
 	}
7b8bd72
+	copy $interp_saved $interp
7b8bd72
     }
7b8bd72
 
7b8bd72
     remote_exec host "kill -9 $pid"
7b8bd72