This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFC] Prevent GDB from loading native libraries when debugging a cross-target corefile
- From: Edjunior Barbosa Machado <emachado at linux dot vnet dot ibm dot com>
- To: gdb-patches at sourceware dot org
- Cc: Nathan Miller <nathanm2 at us dot ibm dot com>, Jon Tollefson <tollefso at us dot ibm dot com>
- Date: Fri, 28 Sep 2012 03:31:44 -0300
- Subject: [RFC] Prevent GDB from loading native libraries when debugging a cross-target corefile
Hi,
The GDB documentation recommends the following in the 'set solib-search-path'
description:
"If you want to use `solib-search-path' instead of `sysroot', be sure to set
`sysroot' to a nonexistent directory to prevent gdb from finding your host's
libraries." (http://sourceware.org/gdb/onlinedocs/gdb/Files.html)
However, when trying to debug cross-target corefiles using recent versions of
gdb, we noticed it's trying to load host libraries instead of libraries from a
cross-architecture jail (pointed by solib-search-path). Here's the example
showing the problem:
Using a faulty application foo that uses a shared library libfoo.so, generate a
corefile in the target system (a powerpc machine in my example here):
$ ls /usr/local/lib/libfoo.so
/usr/local/lib/libfoo.so
$ ./foo
Segmentation fault (core dumped)
Then copy the binary and the corefile for a cross-target debugging in the host
(an x86 machine here) that has his own libfoo.so at the same /usr/local/lib
and a cross environment at /opt/at6.0/ppc. Note that 'info sharedlibrary'
shows that GDB was trying to load the native library libfoo.so:
$ powerpc64-linux-gdb ./foo -q
Reading symbols from /home/emachado/bugs/ppc32-bin/foo...done.
(gdb) set sysroot /dev/null
(gdb) set solib-search-path /opt/at6.0/ppc/lib:/opt/at6.0/ppc/usr/lib
(gdb) core core.19304
[New LWP 19304]
warning: `/usr/local/lib/libfoo.so': Shared library architecture unknown is not compatible with target architecture powerpc:common.
warning: .dynamic section for "/opt/at6.0/ppc/lib/libc.so.6" is not at the expected address (wrong library or version mismatch?)
warning: .dynamic section for "/opt/at6.0/ppc/lib/ld.so.1" is not at the expected address (wrong library or version mismatch?)
warning: Could not load shared library symbols for linux-vdso32.so.1.
Do you need "set solib-search-path" or "set sysroot"?
Core was generated by `./foo'.
Program terminated with signal 11, Segmentation fault.
#0 0x10000704 in main () at foo.c:7
7 printf("null dereference: %c\n", *p);
(gdb) info sharedlibrary
>From To Syms Read Shared Object Library
No linux-vdso32.so.1
0x0ffdec50 0x0ffded58 Yes (*) /usr/local/lib/libfoo.so
0x0fe49a5c 0x0ff6aacc Yes /opt/at6.0/ppc/lib/libc.so.6
0xf7eb2fb0 0xf7ece9d0 Yes /opt/at6.0/ppc/lib/ld.so.1
(*): Shared library is missing debugging information.
It might be worth mentioning that this behavior was modified by this patch from
April 2010:
http://sourceware.org/ml/gdb-patches/2010-04/msg00758.html
Please consider the following patch as a fix for this issue.
Thanks,
--
Edjunior
gdb/
2012-09-28 Nathan Miller <nathanm2@us.ibm.com>
Edjunior Machado <emachado@linux.vnet.ibm.com>
* solib.c (solib_find): Prevent GDB from loading native libraries when
debugging a cross-target corefile.
---
gdb/solib.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/gdb/solib.c b/gdb/solib.c
index 01573f8..d795678 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -300,11 +300,6 @@ solib_find (char *in_pathname, int *fd)
if (found_file < 0)
temp_pathname = NULL;
- /* If not found, search the solib_search_path (if any). */
- if (found_file < 0 && solib_search_path != NULL)
- found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
- in_pathname, O_RDONLY | O_BINARY, &temp_pathname);
-
/* If the search in gdb_sysroot failed, and the path name is
absolute at this point, make it relative. (openp will try and open the
file according to its absolute path otherwise, which is not what we want.)
--
1.7.9.5