2004-08-12 22:22:59 +02:00
|
|
|
/* This testcase is part of GDB, the GNU debugger.
|
|
|
|
|
2012-01-04 09:17:56 +01:00
|
|
|
Copyright 2004, 2007-2012 Free Software Foundation, Inc.
|
2004-08-12 22:22:59 +02:00
|
|
|
|
|
|
|
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
|
2007-08-23 20:08:50 +02:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
2004-08-12 22:22:59 +02:00
|
|
|
(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.
|
2007-08-23 20:08:50 +02:00
|
|
|
|
2004-08-12 22:22:59 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
2007-08-23 20:08:50 +02:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2004-08-12 22:22:59 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2004-08-26 21:26:11 +02:00
|
|
|
#include <stdlib.h>
|
2007-07-17 Pedro Alves <pedro_alves@portugalmail.pt>
Daniel Jacobowitz <dan@codesourcery.com>
* config/i386/cygwin.mt (TDEPFILES): Add solib-target.o.
* coff-pe-read.c (read_pe_exported_syms): Delete verbose
printf.
* NEWS: Mention gdbserver DLL support.
* gdb.base/unload.c (dlopen, dlsym, dlclose, dlerror): Define
for __WIN32__.
(SHLIB_NAME): Delete definition. Always pass dlerror to fprintf.
* gdb.base/unload.exp: Use shared library test routines.
* inferiors.c (all_dlls, dlls_changed, get_dll): New.
(add_thread): Minor cleanups.
(clear_inferiors): Move lower in the file. Clear the DLL
list.
(free_one_dll, match_dll, loaded_dll, unloaded_dll, clear_list): New.
* remote-utils.c (prepare_resume_reply): Check dlls_changed.
(xml_escape_text): New.
* server.c (handle_query): Handle qXfer:libraries:read. Report it
for qSupported.
(handle_v_cont): Report errors.
(gdbserver_version): Update.
(main): Correct size of own_buf. Do not report initial DLL events.
* server.h (struct dll_info, all_dlls, dlls_changed, loaded_dll)
(unloaded_dll, xml_escape_text): New.
* win32-low.c (enum target_waitkind): Update comments.
(win32_add_one_solib, get_image_name, winapi_EnumProcessModules)
(winapi_GetModuleInformation, winapi_GetModuleFileNameExA)
(win32_EnumProcessModules, win32_GetModuleInformation)
(win32_GetModuleFileNameExA, load_psapi, psapi_get_dll_name)
(winapi_CreateToolhelp32Snapshot, winapi_Module32First)
(winapi_Module32Next, win32_CreateToolhelp32Snapshot)
(win32_Module32First, win32_Module32Next, load_toolhelp)
(toolhelp_get_dll_name, handle_load_dll, handle_unload_dll): New.
(get_child_debug_event): Handle DLL events.
(win32_wait): Likewise.
2007-07-17 14:51:41 +02:00
|
|
|
|
|
|
|
#ifdef __WIN32__
|
|
|
|
#include <windows.h>
|
2007-09-04 00:12:13 +02:00
|
|
|
#define dlopen(name, mode) LoadLibrary (TEXT (name))
|
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
# define dlsym(handle, func) GetProcAddress (handle, TEXT (func))
|
|
|
|
#else
|
|
|
|
# define dlsym(handle, func) GetProcAddress (handle, func)
|
|
|
|
#endif
|
2007-07-17 Pedro Alves <pedro_alves@portugalmail.pt>
Daniel Jacobowitz <dan@codesourcery.com>
* config/i386/cygwin.mt (TDEPFILES): Add solib-target.o.
* coff-pe-read.c (read_pe_exported_syms): Delete verbose
printf.
* NEWS: Mention gdbserver DLL support.
* gdb.base/unload.c (dlopen, dlsym, dlclose, dlerror): Define
for __WIN32__.
(SHLIB_NAME): Delete definition. Always pass dlerror to fprintf.
* gdb.base/unload.exp: Use shared library test routines.
* inferiors.c (all_dlls, dlls_changed, get_dll): New.
(add_thread): Minor cleanups.
(clear_inferiors): Move lower in the file. Clear the DLL
list.
(free_one_dll, match_dll, loaded_dll, unloaded_dll, clear_list): New.
* remote-utils.c (prepare_resume_reply): Check dlls_changed.
(xml_escape_text): New.
* server.c (handle_query): Handle qXfer:libraries:read. Report it
for qSupported.
(handle_v_cont): Report errors.
(gdbserver_version): Update.
(main): Correct size of own_buf. Do not report initial DLL events.
* server.h (struct dll_info, all_dlls, dlls_changed, loaded_dll)
(unloaded_dll, xml_escape_text): New.
* win32-low.c (enum target_waitkind): Update comments.
(win32_add_one_solib, get_image_name, winapi_EnumProcessModules)
(winapi_GetModuleInformation, winapi_GetModuleFileNameExA)
(win32_EnumProcessModules, win32_GetModuleInformation)
(win32_GetModuleFileNameExA, load_psapi, psapi_get_dll_name)
(winapi_CreateToolhelp32Snapshot, winapi_Module32First)
(winapi_Module32Next, win32_CreateToolhelp32Snapshot)
(win32_Module32First, win32_Module32Next, load_toolhelp)
(toolhelp_get_dll_name, handle_load_dll, handle_unload_dll): New.
(get_child_debug_event): Handle DLL events.
(win32_wait): Likewise.
2007-07-17 14:51:41 +02:00
|
|
|
#define dlclose(handle) FreeLibrary (handle)
|
|
|
|
#else
|
2004-08-12 22:22:59 +02:00
|
|
|
#include <dlfcn.h>
|
2007-07-17 Pedro Alves <pedro_alves@portugalmail.pt>
Daniel Jacobowitz <dan@codesourcery.com>
* config/i386/cygwin.mt (TDEPFILES): Add solib-target.o.
* coff-pe-read.c (read_pe_exported_syms): Delete verbose
printf.
* NEWS: Mention gdbserver DLL support.
* gdb.base/unload.c (dlopen, dlsym, dlclose, dlerror): Define
for __WIN32__.
(SHLIB_NAME): Delete definition. Always pass dlerror to fprintf.
* gdb.base/unload.exp: Use shared library test routines.
* inferiors.c (all_dlls, dlls_changed, get_dll): New.
(add_thread): Minor cleanups.
(clear_inferiors): Move lower in the file. Clear the DLL
list.
(free_one_dll, match_dll, loaded_dll, unloaded_dll, clear_list): New.
* remote-utils.c (prepare_resume_reply): Check dlls_changed.
(xml_escape_text): New.
* server.c (handle_query): Handle qXfer:libraries:read. Report it
for qSupported.
(handle_v_cont): Report errors.
(gdbserver_version): Update.
(main): Correct size of own_buf. Do not report initial DLL events.
* server.h (struct dll_info, all_dlls, dlls_changed, loaded_dll)
(unloaded_dll, xml_escape_text): New.
* win32-low.c (enum target_waitkind): Update comments.
(win32_add_one_solib, get_image_name, winapi_EnumProcessModules)
(winapi_GetModuleInformation, winapi_GetModuleFileNameExA)
(win32_EnumProcessModules, win32_GetModuleInformation)
(win32_GetModuleFileNameExA, load_psapi, psapi_get_dll_name)
(winapi_CreateToolhelp32Snapshot, winapi_Module32First)
(winapi_Module32Next, win32_CreateToolhelp32Snapshot)
(win32_Module32First, win32_Module32Next, load_toolhelp)
(toolhelp_get_dll_name, handle_load_dll, handle_unload_dll): New.
(get_child_debug_event): Handle DLL events.
(win32_wait): Likewise.
2007-07-17 14:51:41 +02:00
|
|
|
#endif
|
2004-08-12 22:22:59 +02:00
|
|
|
|
|
|
|
int k = 0;
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
void *handle;
|
|
|
|
int (*unloadshr) (int);
|
|
|
|
int y;
|
2004-08-15 12:24:08 +02:00
|
|
|
const char *msg;
|
2004-08-12 22:22:59 +02:00
|
|
|
|
|
|
|
handle = dlopen (SHLIB_NAME, RTLD_LAZY);
|
|
|
|
|
|
|
|
if (!handle)
|
|
|
|
{
|
2010-02-17 23:55:40 +01:00
|
|
|
fprintf (stderr, "%s\n", dlerror ());
|
2004-08-12 22:22:59 +02:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2009-12-23 23:24:51 +01:00
|
|
|
unloadshr = (int (*) (int)) dlsym (handle, "shrfunc1");
|
2004-08-12 22:22:59 +02:00
|
|
|
|
|
|
|
if (!unloadshr)
|
|
|
|
{
|
2009-10-01 23:33:24 +02:00
|
|
|
#ifdef __WIN32__
|
2010-02-17 23:55:40 +01:00
|
|
|
fprintf (stderr, "error %d occurred\n", GetLastError ());
|
2009-10-01 23:33:24 +02:00
|
|
|
#else
|
2010-02-17 23:55:40 +01:00
|
|
|
fprintf (stderr, "%s\n", dlerror ());
|
2009-10-01 23:33:24 +02:00
|
|
|
#endif
|
2004-08-12 22:22:59 +02:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2009-12-23 23:24:51 +01:00
|
|
|
y = (*unloadshr) (1);
|
2004-08-12 22:22:59 +02:00
|
|
|
|
2009-12-23 23:24:51 +01:00
|
|
|
dlclose (handle);
|
|
|
|
handle = NULL; /* y-set-1 */
|
|
|
|
|
|
|
|
/* The second library should share the same memory address. */
|
|
|
|
|
|
|
|
handle = dlopen (SHLIB_NAME2, RTLD_LAZY);
|
|
|
|
|
|
|
|
if (!handle)
|
|
|
|
{
|
2010-02-17 23:55:40 +01:00
|
|
|
fprintf (stderr, "%s\n", dlerror ());
|
2009-12-23 23:24:51 +01:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
unloadshr = (int (*)(int)) dlsym (handle, "shrfunc2");
|
|
|
|
|
|
|
|
if (!unloadshr)
|
|
|
|
{
|
|
|
|
#ifdef __WIN32__
|
2010-02-17 23:55:40 +01:00
|
|
|
fprintf (stderr, "error %d occurred\n", GetLastError ());
|
2009-12-23 23:24:51 +01:00
|
|
|
#else
|
2010-02-17 23:55:40 +01:00
|
|
|
fprintf (stderr, "%s\n", dlerror ());
|
2009-12-23 23:24:51 +01:00
|
|
|
#endif
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
y = (*unloadshr) (2);
|
2004-08-12 22:22:59 +02:00
|
|
|
|
|
|
|
dlclose (handle);
|
2009-12-23 23:24:51 +01:00
|
|
|
handle = NULL; /* y-set-2 */
|
2004-08-12 22:22:59 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|