This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[PATCH RFC] handle unload dll in win32-nat.c
- From: Pierre Muller <muller at cerbere dot u-strasbg dot fr>
- To: gdb-patches at sources dot redhat dot com
- Date: Thu, 15 Nov 2001 11:38:42 +0100
- Subject: [PATCH RFC] handle unload dll in win32-nat.c
I wanted to add unloading of DLLs in windows.
Note that I removed some related changes manually from the
diffs file, so it will probably only apply with some fuzz.
2001-11-15 Pierre Muller <muller@ics.u-strasbg.fr>
* win32-nat.c (struct so_stuff): Add objfile *objfile field needed to be
able to remove
the DLL when unloaded. Remove unused last field.
(handle_unload_dll): New function to handle unloading of DLL.
(solib_symbols_add): Change return type to struct objfile *.
(get_child_debug_event): call handle_unload_dll function.
Index: win32-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/win32-nat.c,v
retrieving revision 1.36
diff -u -r1.36 win32-nat.c
--- win32-nat.c 2001/11/01 16:17:08 1.36
+++ win32-nat.c 2001/11/15 10:34:53
@@ -438,9 +438,10 @@
/* Maintain a linked list of "so" information. */
struct so_stuff
{
- struct so_stuff *next, **last;
+ struct so_stuff *next;
DWORD load_addr;
int loaded;
+ struct objfile *objfile;
char name[1];
} solib_start, *solib_end;
@@ -533,11 +534,12 @@
so = (struct so_stuff *) xmalloc (sizeof (struct so_stuff) + strlen
(ppath) + 8 + 1);
so->loaded = 0;
so->load_addr = load_addr;
+ so->next = NULL;
+ so->objfile = NULL;
strcpy (so->name, ppath);
solib_end->next = so;
solib_end = so;
- so->next = NULL;
len = strlen (ppath);
if (len > max_dll_name_len)
max_dll_name_len = len;
@@ -626,6 +628,33 @@
return 1;
}
+static int
+handle_unload_dll (void *dummy ATTRIBUTE_UNUSED)
+{
+ DWORD lpBaseOfDll = (DWORD) current_event.u.UnloadDll.lpBaseOfDll;
+ struct so_stuff *so = &solib_start, *so1 = solib_start.next;
+
+ while (so1 != NULL)
+ {
+ if (so1->load_addr == lpBaseOfDll + 0x1000)
+ {
+ so->next = so1->next;
+ if (!so->next)
+ solib_end = so;
+ if (so1->objfile)
+ free_objfile (so1->objfile);
+ xfree(so1);
+ return 1;
+ }
+ so = so1;
+ so1 = so->next;
+ }
+ error ("Error: dll starting at 0x%lx not found.\n", (DWORD) lpBaseOfDll);
+
+ return 0;
+}
+
+
/* Return name of last loaded DLL. */
char *
child_solib_loaded_library_pathname (int pid ATTRIBUTE_UNUSED)
@@ -646,12 +675,13 @@
}
solib_start.next = NULL;
+ solib_start.objfile = NULL;
solib_end = &solib_start;
max_dll_name_len = sizeof ("DLL Name") - 1;
}
/* Add DLL symbol information. */
-static void
+static struct objfile *
solib_symbols_add (char *name, int from_tty, CORE_ADDR load_addr)
{
struct section_addr_info section_addrs;
@@ -661,14 +691,12 @@
of the file header and the section alignment. */
if (!name || !name[0])
- return;
+ return NULL;
memset (§ion_addrs, 0, sizeof (section_addrs));
section_addrs.other[0].name = ".text";
section_addrs.other[0].addr = load_addr;
- safe_symbol_file_add (name, from_tty, NULL, 0, OBJF_SHARED);
-
- return;
+ return safe_symbol_file_add (name, from_tty, NULL, 0, OBJF_SHARED);
}
/* Load DLL symbol info. */
@@ -934,7 +968,11 @@
(unsigned) current_event.dwProcessId,
(unsigned) current_event.dwThreadId,
"UNLOAD_DLL_DEBUG_EVENT"));
- break; /* FIXME: don't know what to do here */
+ catch_errors (handle_unload_dll, NULL, (char *) "", RETURN_MASK_ALL);
+ registers_changed (); /* mark all regs invalid */
+ /* ourstatus->kind = TARGET_WAITKIND_UNLOADED;
+ does not exist yet. */
+ break;
case EXCEPTION_DEBUG_EVENT:
DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
@@ -1719,7 +1762,8 @@
else
{
if (solib_end && solib_end->name)
- solib_symbols_add (solib_end->name, from_tty, solib_end->load_addr);
+ solib_end->objfile = solib_symbols_add (solib_end->name, from_tty,
+ solib_end->load_addr);
}
}
Pierre Muller
Institut Charles Sadron
6,rue Boussingault
F 67083 STRASBOURG CEDEX (France)
mailto:muller@ics.u-strasbg.fr
Phone : (33)-3-88-41-40-07 Fax : (33)-3-88-41-40-99