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]

[patch] Move dll related code out of inferiors.c


Hi,
When modifying gdbserver/inferiors.c, I find dll-related code is put
in it, but dll stuff is not related to inferior.  In fact, dll
related code is using `struct inferior_list' as a linked list.  This
patch is to move dll stuff out of inferiors.c to a new file dll.c,
but still using `struct inferior_list' as a linked list data
structure.

Tested on x86_64-linux/native-gdbserver, and cross compiled gdbserver
for i586-mingw32 (because dll.c is used by win32-low.c).  OK to
apply?

Note that it is not perfect to leave dll.c using `struct
inferior_list'.  The follow-up patch can add a general `struct list'
and both dll.c and inferiors.c can use it.  What do you think?

-- 
Yao (éå)
	* inferiors.c: Move code to ...
	* dll.c: .... here.  New.
	* server.h: Declare clear_dlls.
	* Makefile.in (SFILES): Add dll.c.
	(OBS): Add dll.o
---
 gdb/gdbserver/Makefile.in |    3 +-
 gdb/gdbserver/dll.c       |  110 +++++++++++++++++++++++++++++++++++++++++++++
 gdb/gdbserver/inferiors.c |   88 +-----------------------------------
 gdb/gdbserver/server.h    |    1 +
 4 files changed, 115 insertions(+), 87 deletions(-)
 create mode 100644 gdb/gdbserver/dll.c

diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 624e9af..87aface 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -106,7 +106,7 @@ INTERNAL_LDFLAGS = $(LDFLAGS) @RDYNAMIC@
 
 # All source files that go into linking GDB remote server.
 
-SFILES=	$(srcdir)/gdbreplay.c $(srcdir)/inferiors.c \
+SFILES=	$(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
 	$(srcdir)/mem-break.c $(srcdir)/proc-service.c \
 	$(srcdir)/proc-service.list $(srcdir)/regcache.c \
 	$(srcdir)/remote-utils.c $(srcdir)/server.c $(srcdir)/target.c \
@@ -141,6 +141,7 @@ OBS = inferiors.o regcache.o remote-utils.o server.o signals.o target.o \
 	utils.o version.o vec.o \
 	mem-break.o hostio.o event-loop.o tracepoint.o \
 	xml-utils.o common-utils.o ptid.o buffer.o \
+	dll.o \
 	$(XML_BUILTIN) \
 	$(DEPFILES) $(LIBOBJS)
 GDBREPLAY_OBS = gdbreplay.o version.o
diff --git a/gdb/gdbserver/dll.c b/gdb/gdbserver/dll.c
new file mode 100644
index 0000000..aac8970
--- /dev/null
+++ b/gdb/gdbserver/dll.c
@@ -0,0 +1,110 @@
+/* Copyright (C) 2012 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "server.h"
+
+#define get_dll(inf) ((struct dll_info *)(inf))
+
+struct inferior_list all_dlls;
+int dlls_changed;
+
+static void
+free_one_dll (struct inferior_list_entry *inf)
+{
+  struct dll_info *dll = get_dll (inf);
+  if (dll->name != NULL)
+    free (dll->name);
+  free (dll);
+}
+
+/* Find a DLL with the same name and/or base address.  A NULL name in
+   the key is ignored; so is an all-ones base address.  */
+
+static int
+match_dll (struct inferior_list_entry *inf, void *arg)
+{
+  struct dll_info *iter = (void *) inf;
+  struct dll_info *key = arg;
+
+  if (key->base_addr != ~(CORE_ADDR) 0
+      && iter->base_addr == key->base_addr)
+    return 1;
+  else if (key->name != NULL
+	   && iter->name != NULL
+	   && strcmp (key->name, iter->name) == 0)
+    return 1;
+
+  return 0;
+}
+
+/* Record a newly loaded DLL at BASE_ADDR.  */
+
+void
+loaded_dll (const char *name, CORE_ADDR base_addr)
+{
+  struct dll_info *new_dll = xmalloc (sizeof (*new_dll));
+  memset (new_dll, 0, sizeof (*new_dll));
+
+  new_dll->entry.id = minus_one_ptid;
+
+  new_dll->name = xstrdup (name);
+  new_dll->base_addr = base_addr;
+
+  add_inferior_to_list (&all_dlls, &new_dll->entry);
+  dlls_changed = 1;
+}
+
+/* Record that the DLL with NAME and BASE_ADDR has been unloaded.  */
+
+void
+unloaded_dll (const char *name, CORE_ADDR base_addr)
+{
+  struct dll_info *dll;
+  struct dll_info key_dll;
+
+  /* Be careful not to put the key DLL in any list.  */
+  key_dll.name = (char *) name;
+  key_dll.base_addr = base_addr;
+
+  dll = (void *) find_inferior (&all_dlls, match_dll, &key_dll);
+
+  if (dll == NULL)
+    /* For some inferiors we might get unloaded_dll events without having
+       a corresponding loaded_dll.  In that case, the dll cannot be found
+       in ALL_DLL, and there is nothing further for us to do.
+
+       This has been observed when running 32bit executables on Windows64
+       (i.e. through WOW64, the interface between the 32bits and 64bits
+       worlds).  In that case, the inferior always does some strange
+       unloading of unnamed dll.  */
+    return;
+  else
+    {
+      /* DLL has been found so remove the entry and free associated
+         resources.  */
+      remove_inferior (&all_dlls, &dll->entry);
+      free_one_dll (&dll->entry);
+      dlls_changed = 1;
+    }
+}
+
+void
+clear_dlls (void)
+{
+  for_each_inferior (&all_dlls, free_one_dll);
+  all_dlls.head = all_dlls.tail = NULL;
+}
diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c
index a7e1a83..8d5ada0 100644
--- a/gdb/gdbserver/inferiors.c
+++ b/gdb/gdbserver/inferiors.c
@@ -25,13 +25,10 @@
 
 struct inferior_list all_processes;
 struct inferior_list all_threads;
-struct inferior_list all_dlls;
-int dlls_changed;
 
 struct thread_info *current_inferior;
 
 #define get_thread(inf) ((struct thread_info *)(inf))
-#define get_dll(inf) ((struct dll_info *)(inf))
 
 void
 add_inferior_to_list (struct inferior_list *list,
@@ -229,86 +226,6 @@ set_inferior_regcache_data (struct thread_info *inferior, void *data)
   inferior->regcache_data = data;
 }
 
-static void
-free_one_dll (struct inferior_list_entry *inf)
-{
-  struct dll_info *dll = get_dll (inf);
-  if (dll->name != NULL)
-    free (dll->name);
-  free (dll);
-}
-
-/* Find a DLL with the same name and/or base address.  A NULL name in
-   the key is ignored; so is an all-ones base address.  */
-
-static int
-match_dll (struct inferior_list_entry *inf, void *arg)
-{
-  struct dll_info *iter = (void *) inf;
-  struct dll_info *key = arg;
-
-  if (key->base_addr != ~(CORE_ADDR) 0
-      && iter->base_addr == key->base_addr)
-    return 1;
-  else if (key->name != NULL
-	   && iter->name != NULL
-	   && strcmp (key->name, iter->name) == 0)
-    return 1;
-
-  return 0;
-}
-
-/* Record a newly loaded DLL at BASE_ADDR.  */
-
-void
-loaded_dll (const char *name, CORE_ADDR base_addr)
-{
-  struct dll_info *new_dll = xmalloc (sizeof (*new_dll));
-  memset (new_dll, 0, sizeof (*new_dll));
-
-  new_dll->entry.id = minus_one_ptid;
-
-  new_dll->name = xstrdup (name);
-  new_dll->base_addr = base_addr;
-
-  add_inferior_to_list (&all_dlls, &new_dll->entry);
-  dlls_changed = 1;
-}
-
-/* Record that the DLL with NAME and BASE_ADDR has been unloaded.  */
-
-void
-unloaded_dll (const char *name, CORE_ADDR base_addr)
-{
-  struct dll_info *dll;
-  struct dll_info key_dll;
-
-  /* Be careful not to put the key DLL in any list.  */
-  key_dll.name = (char *) name;
-  key_dll.base_addr = base_addr;
-
-  dll = (void *) find_inferior (&all_dlls, match_dll, &key_dll);
-
-  if (dll == NULL)
-    /* For some inferiors we might get unloaded_dll events without having
-       a corresponding loaded_dll.  In that case, the dll cannot be found
-       in ALL_DLL, and there is nothing further for us to do.
-
-       This has been observed when running 32bit executables on Windows64
-       (i.e. through WOW64, the interface between the 32bits and 64bits
-       worlds).  In that case, the inferior always does some strange
-       unloading of unnamed dll.  */
-    return;
-  else
-    {
-      /* DLL has been found so remove the entry and free associated
-         resources.  */
-      remove_inferior (&all_dlls, &dll->entry);
-      free_one_dll (&dll->entry);
-      dlls_changed = 1;
-    }
-}
-
 #define clear_list(LIST) \
   do { (LIST)->head = (LIST)->tail = NULL; } while (0)
 
@@ -316,10 +233,9 @@ void
 clear_inferiors (void)
 {
   for_each_inferior (&all_threads, free_one_thread);
-  for_each_inferior (&all_dlls, free_one_dll);
-
   clear_list (&all_threads);
-  clear_list (&all_dlls);
+
+  clear_dlls ();
 
   current_inferior = NULL;
 }
diff --git a/gdb/gdbserver/server.h b/gdb/gdbserver/server.h
index 62bee56..918052d 100644
--- a/gdb/gdbserver/server.h
+++ b/gdb/gdbserver/server.h
@@ -236,6 +236,7 @@ extern struct inferior_list all_processes;
 extern struct inferior_list all_threads;
 extern struct inferior_list all_dlls;
 extern int dlls_changed;
+extern void clear_dlls (void);
 
 void add_inferior_to_list (struct inferior_list *list,
 			   struct inferior_list_entry *new_inferior);
-- 
1.7.0.4


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