This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: [Proposal] GDB honouring RPATH in binaries.
Okay, there's a patch down below. The nice thing is it lets me create the
following function and then assign it to TARGET_SO_FIND_AND_OPEN_SOLIB in my
initialization code. I've tested it and it removes my requirements to
monkey with solib-search-path.
cheers,
Kris
/* example of finding our solibs */
int
nto_find_and_open_solib (char *solib, unsigned o_flag, char **temp_pathname)
{
char *buf, arch_path[PATH_MAX], *nto_root, *endian;
const char *arch;
char *path_fmt = "%s/lib:%s/usr/lib:%s/usr/photon/lib\
:%s/usr/photon/dll:%s/lib/dll";
nto_root = nto_target ();
if (strcmp (TARGET_ARCHITECTURE->arch_name, "i386") == 0)
{
arch = "x86";
endian = "";
}
else if (strcmp (TARGET_ARCHITECTURE->arch_name, "rs6000") == 0)
{
arch = "ppc";
endian = "be";
}
else
{
arch = TARGET_ARCHITECTURE->arch_name;
endian = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? "be" : "le";
}
sprintf (arch_path, "%s/%s%s", nto_root, arch, endian);
buf = alloca (strlen(path_fmt) + arch_path * 5 + 1);
sprintf (buf, path_fmt, arch_path, arch_path, arch_path, arch_path,
arch_path);
return openp(buf, 1, solib, o_flags, 0, temp_pathname);
}
Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.53
diff -c -r1.53 solib.c
*** solib.c 18 Jan 2003 15:55:52 -0000 1.53
--- solib.c 21 Feb 2003 20:23:43 -0000
***************
*** 160,165 ****
--- 160,169 ----
1, lbasename (in_pathname), O_RDONLY, 0,
&temp_pathname);
+ /* If not found, next use target supplied solib search method (if
existing) */
+ if (found_file < 0 && TARGET_SO_FIND_AND_OPEN_SOLIB)
+ found_file = TARGET_SO_FIND_AND_OPEN_SOLIB (in_pathname, O_RDONLY,
&temp_pathname);
+
/* If not found, next search the inferior's $PATH environment variable.
*/
if (found_file < 0 && solib_search_path != NULL)
found_file = openp (get_in_environ (inferior_environ, "PATH"),
***************
*** 844,849 ****
--- 848,860 ----
do_clear_solib (NULL);
}
+ static void
+ reload_shared_libraries (char *ignored, int from_tty)
+ {
+ no_shared_libraries (NULL, from_tty);
+ solib_add (NULL, from_tty, NULL, auto_solib_add);
+ }
+
void
_initialize_solib (void)
{
***************
*** 873,878 ****
--- 884,890 ----
For other (relative) files, you can add values using `set
solib-search-path'.",
&setlist);
add_show_from_set (c, &showlist);
+ set_cmd_cfunc (c, reload_shared_libraries);
set_cmd_completer (c, filename_completer);
/* Set the default value of "solib-absolute-prefix" from the sysroot, if
***************
*** 885,889 ****
--- 897,902 ----
This takes precedence over the environment variables PATH and
LD_LIBRARY_PATH.",
&setlist);
add_show_from_set (c, &showlist);
+ set_cmd_cfunc (c, reload_shared_libraries);
set_cmd_completer (c, filename_completer);
}
Index: solist.h
===================================================================
RCS file: /cvs/src/src/gdb/solist.h,v
retrieving revision 1.7
diff -c -r1.7 solist.h
*** solist.h 21 Oct 2001 19:20:30 -0000 1.7
--- solist.h 21 Feb 2003 20:23:44 -0000
***************
*** 99,104 ****
--- 99,109 ----
/* Determine if PC lies in the dynamic symbol resolution code of
the run time loader */
int (*in_dynsym_resolve_code) (CORE_ADDR pc);
+
+ /* Extra hook for finding and opening a solib. Convenience function
+ for remote debuggers finding host libs */
+ int (*find_and_open_solib) (char *soname, unsigned o_flags, char
**temp_pathname);
+
};
void free_so (struct so_list *so);
***************
*** 122,126 ****
--- 127,133 ----
(current_target_so_ops->open_symbol_file_object)
#define TARGET_SO_IN_DYNSYM_RESOLVE_CODE \
(current_target_so_ops->in_dynsym_resolve_code)
+ #define TARGET_SO_FIND_AND_OPEN_SOLIB \
+ (current_target_so_ops->find_and_open_solib)
#endif