This is the mail archive of the gdb-patches@sources.redhat.com 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]

[PATCH] solib-svr4.c: Fix set_solib_svr4_fetch_link_map_offsets


I've just committed the patch below.  It makes
set_solib_svr4_fetch_link_map_offsets() work as intended...

Part of my revamp of solib-svr4.c was to introduce struct
link_map_offsets which contains the offsets (and sizes) of various
members the struct r_debug and struct link_map.  This was done to
eliminate reliance on various header files (notably link.h) which
may not exist when building a cross debugger.  Also, it should be
noted that even if this header file exists, it is likely that
the structs defined for the host system will not match those needed
by the target.

At the present time, none of the multiarched targets make use of the
function set_solib_svr4_fetch_link_map_offsets() that I provided for
establishing a target's link map fetching function.  Instead, the
two targets which do define a link map offsets fetcher define the macro
SVR4_FETCH_LINK_MAP_OFFSETS in their tm-*.h files.  Of these targets,
x86 has a good excuse since it is not multiarched yet.  The sh target
is multiarched and therefore shouldn't have a good excuse.  BUT...

I recently attempted to use set_solib_svr4_fetch_link_map_offsets() to
establish a Linux/PPC specific link map fetcher, but discovered a
number of problems.  One of them is as follows...  I attempted to call
set_solib_svr4_fetch_link_map_offsets() from rs6000_gdbarch_init().
The <arch>_gdbarch_init() functions (as they are commonly named) are
used to allocate and initialize a gdbarch struct which is then installed
to define a new "architecture" after this function returns.

Prior to the patch below, set_solib_svr4_fetch_link_map_offsets()
(henceforth abbreviated sssflmo()) would just set the static global
default_svr4_fetch_link_map_offsets to the value passed to sssflmo().
The problem with this is that init_fetch_link_map_offsets() would
be called when the new architecture was installed and the old
(i.e, pre-patch) definition of this function would wipe out the value
that sssflmo() had previously set.

My solution to this problem was to introduce a static global to hold
the value which fetch_link_map_offsets should be initialized to. 
sssflmo() merely sets this static global to the argument passed to it. 
init_fetch_link_map_offsets() is responsible for actually setting
fetch_link_map_offsets using the static global.

I mentioned above that I had run into a number of problems while
creating a Linux/PPC specific link map offset fetcher.  Fixes for the
other problems I encountered will be addressed in other patches. 
As a heads up though, one of the problems is that solib-svr4.c
actually contains (ifdef'd) shared library support for both SVR4 and
SunOS.  I will be disentangling these mechanisms and will place SunOS
shared library support in its own file.  That way we'll be able to do
away with the SVR4_SHARED_LIBS macro and we won't accidentally attempt
to ever include <link.h> from solib-svr4.c any longer.

	* solib-svr4.c (fetch_link_map_offsets): Add comment.
	(fetch_link_map_offsets_init): New static global.
	(set_solib_svr4_fetch_link_map_offsets, init_fetch_link_map_offsets):
	Revise implementation to use ``fetch_link_map_offsets_init''
	instead of ``fetch_link_map_offsets''.

Index: solib-svr4.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-svr4.c,v
retrieving revision 1.17
diff -u -p -r1.17 solib-svr4.c
--- solib-svr4.c	2001/08/29 19:34:08	1.17
+++ solib-svr4.c	2001/09/20 19:52:35
@@ -62,9 +62,21 @@
 #endif
 
 static struct link_map_offsets *default_svr4_fetch_link_map_offsets (void);
+
+/* fetch_link_map_offsets is the pointer to the architecture specific
+   link map offsets fetching function.  It uses the gdbarch_swap
+   mechanism to change its value when the architecture changes.  */
 static struct link_map_offsets *(*fetch_link_map_offsets)(void) = 
   default_svr4_fetch_link_map_offsets;
 
+/* fetch_link_map_offsets_init is like the above, but obtains its
+   value from a call to set_solib_svr4_fetch_link_map_offsets().
+   This latter function is intended to be called from a *_gdbarch_init()
+   function.  The value of ``fetch_link_map_offsets_init'' is used
+   to actually set ``fetch_link_map_offsets'' when the architecture
+   is installed.  */
+static struct link_map_offsets *(*fetch_link_map_offsets_init)(void) = 0;
+
 /* legacy_svr4_fetch_link_map_offsets_hook is a pointer to a function
    which is used to fetch link map offsets.  It will only be set
    by solib-legacy.c, if at all. */
@@ -1642,16 +1654,35 @@ svr4_relocate_section_addresses (struct 
   sec->endaddr += LM_ADDR (so);
 }
 
+/* set_solib_svr4_fetch_link_map_offsets() is intended to be called by
+   a <arch>_gdbarch_init() function.  It uses ``fetch_link_map_offsets_init''
+   to temporarily hold a pointer to the link map offsets fetcher for
+   a particular architecture.  Once the architecture is actually installed,
+   init_fetch_link_map_offsets(), below, will be called to install this
+   value in ``fetch_link_map_offsets''.  After that, the gdbarch_swap
+   machinery will manage the contents of this variable whenever the
+   architecture changes.  */
+
 void
 set_solib_svr4_fetch_link_map_offsets (struct link_map_offsets *(*flmo) (void))
 {
-  fetch_link_map_offsets = flmo;
+  fetch_link_map_offsets_init = flmo;
 }
 
+/* Initialize the value of ``fetch_link_map_offsets'' when a new
+   architecture is created.  set_solib_svr4_fetch_link_map_offsets()
+   is used to set the value that ``fetch_link_map_offsets'' should
+   be initialized to.  */
+
 static void
 init_fetch_link_map_offsets (void)
 {
-  set_solib_svr4_fetch_link_map_offsets (default_svr4_fetch_link_map_offsets);
+  if (fetch_link_map_offsets_init != NULL)
+    fetch_link_map_offsets = fetch_link_map_offsets_init;
+  else
+    fetch_link_map_offsets = default_svr4_fetch_link_map_offsets;
+
+  fetch_link_map_offsets_init = NULL;
 }
 
 static struct target_so_ops svr4_so_ops;


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