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

bsd-uthread, properly clean up after ourselves


Hi, 

I've noticed a couple of issues with the bsd-thread target regarding
tear down, while working on making the core target always register
at least the main thread.

First, there's a typo here:

void
bsd_uthread_solib_loaded (struct so_list *so)
{
  const char **names = bsd_uthread_solib_names;

  for (names = bsd_uthread_solib_names; *names; names++)
    {
      if (strncmp (so->so_original_name, *names, strlen (*names)) == 0)
	{
	  solib_read_symbols (so, so->from_tty);

	  if (bsd_uthread_activate (so->objfile))
	    {
	      bsd_uthread_solib_name == so->so_original_name;

                                     ^^
	      return;
	    }
	}
    }
}

Which makes this, a nop:

void
bsd_uthread_solib_unloaded (struct so_list *so)
{
  if (!bsd_uthread_solib_name)
    return;

  if (strcmp (so->so_original_name, bsd_uthread_solib_name) == 0)
    bsd_uthread_deactivate ();
}

Second, if popping this target, and we haven't cleaned up the
shared library list yet, we'd leave bsd_uthread_active still set.
That doesn't look conceptually right to me.

The attached patch addresses both issues, but fixing the typo,
and by moving the globals cleanup to target_close.  unpush_target
ends up calling bsd_uthread_close, so unloading -lc_r or -lpthread
will still work (or ratter, will start working, due to the typo
being fixed).

OK?

-- 
Pedro Alves
2008-08-11  Pedro Alves  <pedro@codesourcery.com>

	* bsd-uthread.c (bsd_uthread_close): New.
	(bsd_uthread_deactivate): Don't cleanup here, just unpush the target.
	(bsd_uthread_solib_loaded): Fix typo.
	(bsd_uthread_target): Register bsd_uthread_close.

---
 gdb/bsd-uthread.c |   25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

Index: src/gdb/bsd-uthread.c
===================================================================
--- src.orig/gdb/bsd-uthread.c	2008-08-11 13:23:16.000000000 +0100
+++ src/gdb/bsd-uthread.c	2008-08-11 13:23:53.000000000 +0100
@@ -192,18 +192,12 @@ bsd_uthread_activate (struct objfile *ob
   return 1;
 }
 
-/* Deactivate the thread stratum implemented by this module.  */
+/* Cleanup due to deactivation.  */
 
 static void
-bsd_uthread_deactivate (void)
+bsd_uthread_close (int quitting)
 {
-  /* Skip if the thread stratum has already been deactivated.  */
-  if (!bsd_uthread_active)
-    return;
-
   bsd_uthread_active = 0;
-  unpush_target (bsd_uthread_ops_hack);
-
   bsd_uthread_thread_run_addr = 0;
   bsd_uthread_thread_list_addr = 0;
   bsd_uthread_thread_state_offset = 0;
@@ -212,6 +206,18 @@ bsd_uthread_deactivate (void)
   bsd_uthread_solib_name = NULL;
 }
 
+/* Deactivate the thread stratum implemented by this module.  */
+
+static void
+bsd_uthread_deactivate (void)
+{
+  /* Skip if the thread stratum has already been deactivated.  */
+  if (!bsd_uthread_active)
+    return;
+
+  unpush_target (bsd_uthread_ops_hack);
+}
+
 void
 bsd_uthread_inferior_created (struct target_ops *ops, int from_tty)
 {
@@ -239,7 +245,7 @@ bsd_uthread_solib_loaded (struct so_list
 
 	  if (bsd_uthread_activate (so->objfile))
 	    {
-	      bsd_uthread_solib_name == so->so_original_name;
+	      bsd_uthread_solib_name = so->so_original_name;
 	      return;
 	    }
 	}
@@ -492,6 +498,7 @@ bsd_uthread_target (void)
   t->to_shortname = "bsd-uthreads";
   t->to_longname = "BSD user-level threads";
   t->to_doc = "BSD user-level threads";
+  t->to_close = bsd_uthread_close;
   t->to_mourn_inferior = bsd_uthread_mourn_inferior;
   t->to_fetch_registers = bsd_uthread_fetch_registers;
   t->to_store_registers = bsd_uthread_store_registers;

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