aboutsummaryrefslogtreecommitdiff
path: root/gdb/windows-nat.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2021-04-30 10:22:23 -0600
committerTom Tromey <tromey@adacore.com>2021-04-30 10:22:24 -0600
commit9e439f0098d1dd21d79dff3f030ddcd0b1cb244b (patch)
tree1b9c55df7a9a563014b832c88512445ed70c070f /gdb/windows-nat.c
parent1053c6389a699550f2c7c1f118ce4d2c1889a73a (diff)
downloadgdb-9e439f0098d1dd21d79dff3f030ddcd0b1cb244b.zip
gdb-9e439f0098d1dd21d79dff3f030ddcd0b1cb244b.tar.gz
gdb-9e439f0098d1dd21d79dff3f030ddcd0b1cb244b.tar.bz2
Move function indirection code to nat/windows-nat
gdb and gdbserver both look for functions in some Windows DLLs at runtime. This patch moves this code out of gdb and into nat/windows-nat, so it can be shared by both programs. gdb/ChangeLog 2021-04-30 Tom Tromey <tromey@adacore.com> * windows-nat.c: Move code to nat/windows-nat.[ch]. (_initialize_windows_nat): Call initialize_loadable. * nat/windows-nat.h (AdjustTokenPrivileges) (DebugActiveProcessStop, DebugBreakProcess) (DebugSetProcessKillOnExit, EnumProcessModules) (EnumProcessModulesEx, GetModuleInformation) (GetModuleFileNameExA, GetModuleFileNameExW) (LookupPrivilegeValueA, OpenProcessToken, GetConsoleFontSize) (GetCurrentConsoleFont, Wow64SuspendThread) (Wow64GetThreadContext, Wow64SetThreadContext) (Wow64GetThreadSelectorEntry): Move from windows-nat.c. (AdjustTokenPrivileges_ftype) (DebugActiveProcessStop_ftype, DebugBreakProcess_ftype) (DebugSetProcessKillOnExit_ftype, EnumProcessModules_ftype) (EnumProcessModulesEx_ftype, GetModuleInformation_ftype) (GetModuleFileNameExA_ftype, GetModuleFileNameExW_ftype) (LookupPrivilegeValueA_ftype, OpenProcessToken_ftype) (GetConsoleFontSize_ftype) (GetCurrentConsoleFont_ftype, Wow64SuspendThread_ftype) (Wow64GetThreadContext_ftype, Wow64SetThreadContext_ftype) (Wow64GetThreadSelectorEntry_ftype): Likewise. (initialize_loadable): Declare. * nat/windows-nat.c (AdjustTokenPrivileges) (DebugActiveProcessStop, DebugBreakProcess) (DebugSetProcessKillOnExit, EnumProcessModules) (EnumProcessModulesEx, GetModuleInformation, GetModuleFileNameExA) (GetModuleFileNameExW, LookupPrivilegeValueA, OpenProcessToken) (GetCurrentConsoleFont, GetConsoleFontSize, Wow64SuspendThread) (Wow64GetThreadContext, Wow64SetThreadContext) (Wow64GetThreadSelectorEntry): Define. (bad, bad_GetCurrentConsoleFont, bad_GetConsoleFontSize): Move from windows-nat.c. (initialize_loadable): Likewise, and rename.
Diffstat (limited to 'gdb/windows-nat.c')
-rw-r--r--gdb/windows-nat.c212
1 files changed, 11 insertions, 201 deletions
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 3723891..471d8fc 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -36,7 +36,6 @@
#include <fcntl.h>
#include <windows.h>
#include <imagehlp.h>
-#include <psapi.h>
#ifdef __CYGWIN__
#include <wchar.h>
#include <sys/cygwin.h>
@@ -75,91 +74,15 @@
using namespace windows_nat;
-#define AdjustTokenPrivileges dyn_AdjustTokenPrivileges
-#define DebugActiveProcessStop dyn_DebugActiveProcessStop
-#define DebugBreakProcess dyn_DebugBreakProcess
-#define DebugSetProcessKillOnExit dyn_DebugSetProcessKillOnExit
-#define EnumProcessModules dyn_EnumProcessModules
-#define EnumProcessModulesEx dyn_EnumProcessModulesEx
-#define GetModuleInformation dyn_GetModuleInformation
-#define LookupPrivilegeValueA dyn_LookupPrivilegeValueA
-#define OpenProcessToken dyn_OpenProcessToken
-#define GetConsoleFontSize dyn_GetConsoleFontSize
-#define GetCurrentConsoleFont dyn_GetCurrentConsoleFont
-#define Wow64SuspendThread dyn_Wow64SuspendThread
-#define Wow64GetThreadContext dyn_Wow64GetThreadContext
-#define Wow64SetThreadContext dyn_Wow64SetThreadContext
-#define Wow64GetThreadSelectorEntry dyn_Wow64GetThreadSelectorEntry
-
-typedef BOOL WINAPI (AdjustTokenPrivileges_ftype) (HANDLE, BOOL,
- PTOKEN_PRIVILEGES,
- DWORD, PTOKEN_PRIVILEGES,
- PDWORD);
-static AdjustTokenPrivileges_ftype *AdjustTokenPrivileges;
-
-typedef BOOL WINAPI (DebugActiveProcessStop_ftype) (DWORD);
-static DebugActiveProcessStop_ftype *DebugActiveProcessStop;
-
-typedef BOOL WINAPI (DebugBreakProcess_ftype) (HANDLE);
-static DebugBreakProcess_ftype *DebugBreakProcess;
-
-typedef BOOL WINAPI (DebugSetProcessKillOnExit_ftype) (BOOL);
-static DebugSetProcessKillOnExit_ftype *DebugSetProcessKillOnExit;
-
-typedef BOOL WINAPI (EnumProcessModules_ftype) (HANDLE, HMODULE *, DWORD,
- LPDWORD);
-static EnumProcessModules_ftype *EnumProcessModules;
-
-#ifdef __x86_64__
-typedef BOOL WINAPI (EnumProcessModulesEx_ftype) (HANDLE, HMODULE *, DWORD,
- LPDWORD, DWORD);
-static EnumProcessModulesEx_ftype *EnumProcessModulesEx;
-#endif
-
-typedef BOOL WINAPI (GetModuleInformation_ftype) (HANDLE, HMODULE,
- LPMODULEINFO, DWORD);
-static GetModuleInformation_ftype *GetModuleInformation;
-
-typedef BOOL WINAPI (LookupPrivilegeValueA_ftype) (LPCSTR, LPCSTR, PLUID);
-static LookupPrivilegeValueA_ftype *LookupPrivilegeValueA;
-
-typedef BOOL WINAPI (OpenProcessToken_ftype) (HANDLE, DWORD, PHANDLE);
-static OpenProcessToken_ftype *OpenProcessToken;
-
-typedef BOOL WINAPI (GetCurrentConsoleFont_ftype) (HANDLE, BOOL,
- CONSOLE_FONT_INFO *);
-static GetCurrentConsoleFont_ftype *GetCurrentConsoleFont;
-
-typedef COORD WINAPI (GetConsoleFontSize_ftype) (HANDLE, DWORD);
-static GetConsoleFontSize_ftype *GetConsoleFontSize;
-
-#ifdef __x86_64__
-typedef DWORD WINAPI (Wow64SuspendThread_ftype) (HANDLE);
-static Wow64SuspendThread_ftype *Wow64SuspendThread;
-
-typedef BOOL WINAPI (Wow64GetThreadContext_ftype) (HANDLE, PWOW64_CONTEXT);
-static Wow64GetThreadContext_ftype *Wow64GetThreadContext;
-
-typedef BOOL WINAPI (Wow64SetThreadContext_ftype) (HANDLE,
- const WOW64_CONTEXT *);
-static Wow64SetThreadContext_ftype *Wow64SetThreadContext;
-
-typedef BOOL WINAPI (Wow64GetThreadSelectorEntry_ftype) (HANDLE, DWORD,
- PLDT_ENTRY);
-static Wow64GetThreadSelectorEntry_ftype *Wow64GetThreadSelectorEntry;
-#endif
-
#undef STARTUPINFO
#undef CreateProcess
#undef GetModuleFileNameEx
#ifndef __CYGWIN__
# define __PMAX (MAX_PATH + 1)
- typedef DWORD WINAPI (GetModuleFileNameEx_ftype) (HANDLE, HMODULE, LPSTR, DWORD);
- static GetModuleFileNameEx_ftype *GetModuleFileNameEx;
+# define GetModuleFileNameEx GetModuleFileNameExA
# define STARTUPINFO STARTUPINFOA
# define CreateProcess CreateProcessA
-# define GetModuleFileNameEx_name "GetModuleFileNameExA"
#else
# define __PMAX PATH_MAX
/* The starting and ending address of the cygwin1.dll text segment. */
@@ -167,12 +90,9 @@ static Wow64GetThreadSelectorEntry_ftype *Wow64GetThreadSelectorEntry;
static CORE_ADDR cygwin_load_end;
# define __USEWIDE
typedef wchar_t cygwin_buf_t;
- typedef DWORD WINAPI (GetModuleFileNameEx_ftype) (HANDLE, HMODULE,
- LPWSTR, DWORD);
- static GetModuleFileNameEx_ftype *GetModuleFileNameEx;
+# define GetModuleFileNameEx GetModuleFileNameExW
# define STARTUPINFO STARTUPINFOW
# define CreateProcess CreateProcessW
-# define GetModuleFileNameEx_name "GetModuleFileNameExW"
#endif
static int have_saved_context; /* True if we've saved context from a
@@ -3430,6 +3350,15 @@ Show whether to display kernel exceptions in child process."), NULL,
add_cmd ("selector", class_info, display_selectors,
_("Display selectors infos."),
&info_w32_cmdlist);
+
+ if (!initialize_loadable ())
+ {
+ /* This will probably fail on Windows 9x/Me. Let the user know
+ that we're missing some functionality. */
+ warning(_("\
+cannot automatically find executable file or library to read symbols.\n\
+Use \"file\" or \"dll\" command to load executable/libraries directly."));
+ }
}
/* Hardware watchpoint support, adapted from go32-nat.c code. */
@@ -3529,122 +3458,3 @@ _initialize_check_for_gdb_ini ()
}
}
}
-
-/* Define dummy functions which always return error for the rare cases where
- these functions could not be found. */
-template<typename... T>
-BOOL WINAPI
-bad (T... args)
-{
- return FALSE;
-}
-
-template<typename... T>
-DWORD WINAPI
-bad (T... args)
-{
- return 0;
-}
-
-static BOOL WINAPI
-bad_GetCurrentConsoleFont (HANDLE w, BOOL bMaxWindow, CONSOLE_FONT_INFO *f)
-{
- f->nFont = 0;
- return 1;
-}
-
-static COORD WINAPI
-bad_GetConsoleFontSize (HANDLE w, DWORD nFont)
-{
- COORD size;
- size.X = 8;
- size.Y = 12;
- return size;
-}
-
-/* Load any functions which may not be available in ancient versions
- of Windows. */
-
-void _initialize_loadable ();
-void
-_initialize_loadable ()
-{
- HMODULE hm = NULL;
-
-#define GPA(m, func) \
- func = (func ## _ftype *) GetProcAddress (m, #func)
-
- hm = LoadLibrary ("kernel32.dll");
- if (hm)
- {
- GPA (hm, DebugActiveProcessStop);
- GPA (hm, DebugBreakProcess);
- GPA (hm, DebugSetProcessKillOnExit);
- GPA (hm, GetConsoleFontSize);
- GPA (hm, DebugActiveProcessStop);
- GPA (hm, GetCurrentConsoleFont);
-#ifdef __x86_64__
- GPA (hm, Wow64SuspendThread);
- GPA (hm, Wow64GetThreadContext);
- GPA (hm, Wow64SetThreadContext);
- GPA (hm, Wow64GetThreadSelectorEntry);
-#endif
- }
-
- /* Set variables to dummy versions of these processes if the function
- wasn't found in kernel32.dll. */
- if (!DebugBreakProcess)
- DebugBreakProcess = bad;
- if (!DebugActiveProcessStop || !DebugSetProcessKillOnExit)
- {
- DebugActiveProcessStop = bad;
- DebugSetProcessKillOnExit = bad;
- }
- if (!GetConsoleFontSize)
- GetConsoleFontSize = bad_GetConsoleFontSize;
- if (!GetCurrentConsoleFont)
- GetCurrentConsoleFont = bad_GetCurrentConsoleFont;
-
- /* Load optional functions used for retrieving filename information
- associated with the currently debugged process or its dlls. */
- hm = LoadLibrary ("psapi.dll");
- if (hm)
- {
- GPA (hm, EnumProcessModules);
-#ifdef __x86_64__
- GPA (hm, EnumProcessModulesEx);
-#endif
- GPA (hm, GetModuleInformation);
- GetModuleFileNameEx = (GetModuleFileNameEx_ftype *)
- GetProcAddress (hm, GetModuleFileNameEx_name);
- }
-
- if (!EnumProcessModules || !GetModuleInformation || !GetModuleFileNameEx)
- {
- /* Set variables to dummy versions of these processes if the function
- wasn't found in psapi.dll. */
- EnumProcessModules = bad;
- GetModuleInformation = bad;
- GetModuleFileNameEx = bad;
- /* This will probably fail on Windows 9x/Me. Let the user know
- that we're missing some functionality. */
- warning(_("\
-cannot automatically find executable file or library to read symbols.\n\
-Use \"file\" or \"dll\" command to load executable/libraries directly."));
- }
-
- hm = LoadLibrary ("advapi32.dll");
- if (hm)
- {
- GPA (hm, OpenProcessToken);
- GPA (hm, LookupPrivilegeValueA);
- GPA (hm, AdjustTokenPrivileges);
- /* Only need to set one of these since if OpenProcessToken fails nothing
- else is needed. */
- if (!OpenProcessToken || !LookupPrivilegeValueA
- || !AdjustTokenPrivileges)
- OpenProcessToken = bad;
- }
-
-#undef GPA
-}