GDBserver
|
00001 /* Copyright (C) 2002-2013 Free Software Foundation, Inc. 00002 00003 This file is part of GDB. 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00017 00018 #include "server.h" 00019 #include "dll.h" 00020 00021 #define get_dll(inf) ((struct dll_info *)(inf)) 00022 00023 struct inferior_list all_dlls; 00024 int dlls_changed; 00025 00026 static void 00027 free_one_dll (struct inferior_list_entry *inf) 00028 { 00029 struct dll_info *dll = get_dll (inf); 00030 if (dll->name != NULL) 00031 free (dll->name); 00032 free (dll); 00033 } 00034 00035 /* Find a DLL with the same name and/or base address. A NULL name in 00036 the key is ignored; so is an all-ones base address. */ 00037 00038 static int 00039 match_dll (struct inferior_list_entry *inf, void *arg) 00040 { 00041 struct dll_info *iter = (void *) inf; 00042 struct dll_info *key = arg; 00043 00044 if (key->base_addr != ~(CORE_ADDR) 0 00045 && iter->base_addr == key->base_addr) 00046 return 1; 00047 else if (key->name != NULL 00048 && iter->name != NULL 00049 && strcmp (key->name, iter->name) == 0) 00050 return 1; 00051 00052 return 0; 00053 } 00054 00055 /* Record a newly loaded DLL at BASE_ADDR. */ 00056 00057 void 00058 loaded_dll (const char *name, CORE_ADDR base_addr) 00059 { 00060 struct dll_info *new_dll = xmalloc (sizeof (*new_dll)); 00061 memset (new_dll, 0, sizeof (*new_dll)); 00062 00063 new_dll->entry.id = minus_one_ptid; 00064 00065 new_dll->name = xstrdup (name); 00066 new_dll->base_addr = base_addr; 00067 00068 add_inferior_to_list (&all_dlls, &new_dll->entry); 00069 dlls_changed = 1; 00070 } 00071 00072 /* Record that the DLL with NAME and BASE_ADDR has been unloaded. */ 00073 00074 void 00075 unloaded_dll (const char *name, CORE_ADDR base_addr) 00076 { 00077 struct dll_info *dll; 00078 struct dll_info key_dll; 00079 00080 /* Be careful not to put the key DLL in any list. */ 00081 key_dll.name = (char *) name; 00082 key_dll.base_addr = base_addr; 00083 00084 dll = (void *) find_inferior (&all_dlls, match_dll, &key_dll); 00085 00086 if (dll == NULL) 00087 /* For some inferiors we might get unloaded_dll events without having 00088 a corresponding loaded_dll. In that case, the dll cannot be found 00089 in ALL_DLL, and there is nothing further for us to do. 00090 00091 This has been observed when running 32bit executables on Windows64 00092 (i.e. through WOW64, the interface between the 32bits and 64bits 00093 worlds). In that case, the inferior always does some strange 00094 unloading of unnamed dll. */ 00095 return; 00096 else 00097 { 00098 /* DLL has been found so remove the entry and free associated 00099 resources. */ 00100 remove_inferior (&all_dlls, &dll->entry); 00101 free_one_dll (&dll->entry); 00102 dlls_changed = 1; 00103 } 00104 } 00105 00106 void 00107 clear_dlls (void) 00108 { 00109 for_each_inferior (&all_dlls, free_one_dll); 00110 all_dlls.head = all_dlls.tail = NULL; 00111 }