aboutsummaryrefslogtreecommitdiff
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
parent1053c6389a699550f2c7c1f118ce4d2c1889a73a (diff)
downloadfsf-binutils-gdb-9e439f0098d1dd21d79dff3f030ddcd0b1cb244b.zip
fsf-binutils-gdb-9e439f0098d1dd21d79dff3f030ddcd0b1cb244b.tar.gz
fsf-binutils-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.
-rw-r--r--gdb/ChangeLog36
-rw-r--r--gdb/nat/windows-nat.c142
-rw-r--r--gdb/nat/windows-nat.h90
-rw-r--r--gdb/windows-nat.c212
4 files changed, 279 insertions, 201 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 673fa3e..621a5db 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,41 @@
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.
+
+2021-04-30 Tom Tromey <tromey@adacore.com>
+
* windows-nat.c (bad_GetModuleFileNameEx): Remove define.
(bad_DebugActiveProcessStop, bad_DebugBreakProcess)
(bad_DebugSetProcessKillOnExit, bad_EnumProcessModules)
diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c
index 794e2df..fa1ae95 100644
--- a/gdb/nat/windows-nat.c
+++ b/gdb/nat/windows-nat.c
@@ -45,6 +45,29 @@ bool wow64_process = false;
bool ignore_first_breakpoint = false;
#endif
+AdjustTokenPrivileges_ftype *AdjustTokenPrivileges;
+DebugActiveProcessStop_ftype *DebugActiveProcessStop;
+DebugBreakProcess_ftype *DebugBreakProcess;
+DebugSetProcessKillOnExit_ftype *DebugSetProcessKillOnExit;
+EnumProcessModules_ftype *EnumProcessModules;
+#ifdef __x86_64__
+EnumProcessModulesEx_ftype *EnumProcessModulesEx;
+#endif
+GetModuleInformation_ftype *GetModuleInformation;
+GetModuleFileNameExA_ftype *GetModuleFileNameExA;
+GetModuleFileNameExW_ftype *GetModuleFileNameExW;
+LookupPrivilegeValueA_ftype *LookupPrivilegeValueA;
+OpenProcessToken_ftype *OpenProcessToken;
+GetCurrentConsoleFont_ftype *GetCurrentConsoleFont;
+GetConsoleFontSize_ftype *GetConsoleFontSize;
+#ifdef __x86_64__
+Wow64SuspendThread_ftype *Wow64SuspendThread;
+Wow64GetThreadContext_ftype *Wow64GetThreadContext;
+Wow64SetThreadContext_ftype *Wow64SetThreadContext;
+Wow64GetThreadSelectorEntry_ftype *Wow64GetThreadSelectorEntry;
+#endif
+
+
/* Note that 'debug_events' must be locally defined in the relevant
functions. */
#define DEBUG_EVENTS(fmt, ...) \
@@ -388,4 +411,123 @@ wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout)
return result;
}
+/* 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;
+}
+
+/* See windows-nat.h. */
+
+bool
+initialize_loadable ()
+{
+ bool result = true;
+ HMODULE hm = NULL;
+
+#define GPA(m, func) \
+ func = (func ## _ftype *) GetProcAddress (m, #func)
+
+ hm = LoadLibrary (TEXT ("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 (TEXT ("psapi.dll"));
+ if (hm)
+ {
+ GPA (hm, EnumProcessModules);
+#ifdef __x86_64__
+ GPA (hm, EnumProcessModulesEx);
+#endif
+ GPA (hm, GetModuleInformation);
+ GPA (hm, GetModuleFileNameExA);
+ GPA (hm, GetModuleFileNameExW);
+ }
+
+ if (!EnumProcessModules || !GetModuleInformation
+ || !GetModuleFileNameExA || !GetModuleFileNameExW)
+ {
+ /* Set variables to dummy versions of these processes if the function
+ wasn't found in psapi.dll. */
+ EnumProcessModules = bad;
+ GetModuleInformation = bad;
+ GetModuleFileNameExA = bad;
+ GetModuleFileNameExW = bad;
+
+ result = false;
+ }
+
+ hm = LoadLibrary (TEXT ("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
+
+ return result;
+}
+
}
diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h
index d8aeaa4..fafa65d 100644
--- a/gdb/nat/windows-nat.h
+++ b/gdb/nat/windows-nat.h
@@ -20,6 +20,7 @@
#define NAT_WINDOWS_NAT_H
#include <windows.h>
+#include <psapi.h>
#include <vector>
#include "gdbsupport/gdb_optional.h"
@@ -257,6 +258,95 @@ extern BOOL continue_last_debug_event (DWORD continue_status,
extern BOOL wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout);
+#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 GetModuleFileNameExA dyn_GetModuleFileNameExA
+#define GetModuleFileNameExW dyn_GetModuleFileNameExW
+#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);
+extern AdjustTokenPrivileges_ftype *AdjustTokenPrivileges;
+
+typedef BOOL WINAPI (DebugActiveProcessStop_ftype) (DWORD);
+extern DebugActiveProcessStop_ftype *DebugActiveProcessStop;
+
+typedef BOOL WINAPI (DebugBreakProcess_ftype) (HANDLE);
+extern DebugBreakProcess_ftype *DebugBreakProcess;
+
+typedef BOOL WINAPI (DebugSetProcessKillOnExit_ftype) (BOOL);
+extern DebugSetProcessKillOnExit_ftype *DebugSetProcessKillOnExit;
+
+typedef BOOL WINAPI (EnumProcessModules_ftype) (HANDLE, HMODULE *, DWORD,
+ LPDWORD);
+extern EnumProcessModules_ftype *EnumProcessModules;
+
+#ifdef __x86_64__
+typedef BOOL WINAPI (EnumProcessModulesEx_ftype) (HANDLE, HMODULE *, DWORD,
+ LPDWORD, DWORD);
+extern EnumProcessModulesEx_ftype *EnumProcessModulesEx;
+#endif
+
+typedef BOOL WINAPI (GetModuleInformation_ftype) (HANDLE, HMODULE,
+ LPMODULEINFO, DWORD);
+extern GetModuleInformation_ftype *GetModuleInformation;
+
+typedef DWORD WINAPI (GetModuleFileNameExA_ftype) (HANDLE, HMODULE, LPSTR,
+ DWORD);
+extern GetModuleFileNameExA_ftype *GetModuleFileNameExA;
+
+typedef DWORD WINAPI (GetModuleFileNameExW_ftype) (HANDLE, HMODULE,
+ LPWSTR, DWORD);
+extern GetModuleFileNameExW_ftype *GetModuleFileNameExW;
+
+typedef BOOL WINAPI (LookupPrivilegeValueA_ftype) (LPCSTR, LPCSTR, PLUID);
+extern LookupPrivilegeValueA_ftype *LookupPrivilegeValueA;
+
+typedef BOOL WINAPI (OpenProcessToken_ftype) (HANDLE, DWORD, PHANDLE);
+extern OpenProcessToken_ftype *OpenProcessToken;
+
+typedef BOOL WINAPI (GetCurrentConsoleFont_ftype) (HANDLE, BOOL,
+ CONSOLE_FONT_INFO *);
+extern GetCurrentConsoleFont_ftype *GetCurrentConsoleFont;
+
+typedef COORD WINAPI (GetConsoleFontSize_ftype) (HANDLE, DWORD);
+extern GetConsoleFontSize_ftype *GetConsoleFontSize;
+
+#ifdef __x86_64__
+typedef DWORD WINAPI (Wow64SuspendThread_ftype) (HANDLE);
+extern Wow64SuspendThread_ftype *Wow64SuspendThread;
+
+typedef BOOL WINAPI (Wow64GetThreadContext_ftype) (HANDLE, PWOW64_CONTEXT);
+extern Wow64GetThreadContext_ftype *Wow64GetThreadContext;
+
+typedef BOOL WINAPI (Wow64SetThreadContext_ftype) (HANDLE,
+ const WOW64_CONTEXT *);
+extern Wow64SetThreadContext_ftype *Wow64SetThreadContext;
+
+typedef BOOL WINAPI (Wow64GetThreadSelectorEntry_ftype) (HANDLE, DWORD,
+ PLDT_ENTRY);
+extern Wow64GetThreadSelectorEntry_ftype *Wow64GetThreadSelectorEntry;
+#endif
+
+/* Load any functions which may not be available in ancient versions
+ of Windows. */
+
+extern bool initialize_loadable ();
+
}
#endif
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
-}