From 1053c6389a699550f2c7c1f118ce4d2c1889a73a Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 30 Apr 2021 10:22:23 -0600 Subject: [PATCH] Use template functions in windows-nat.c windows-nat.c defines a number of replacement functions that simply return zero. This patch removes these in favor of a couple of template functions. gdb/ChangeLog 2021-04-30 Tom Tromey * windows-nat.c (bad_GetModuleFileNameEx): Remove define. (bad_DebugActiveProcessStop, bad_DebugBreakProcess) (bad_DebugSetProcessKillOnExit, bad_EnumProcessModules) (bad_GetModuleFileNameExW, bad_GetModuleFileNameExA) (bad_GetModuleInformation, bad_OpenProcessToken): Remove. (bad): New template functions. (_initialize_loadable): Update. --- gdb/ChangeLog | 10 ++++++++ gdb/windows-nat.c | 62 +++++++++++------------------------------------ 2 files changed, 24 insertions(+), 48 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f89346dfb26..673fa3e692d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2021-04-30 Tom Tromey + + * windows-nat.c (bad_GetModuleFileNameEx): Remove define. + (bad_DebugActiveProcessStop, bad_DebugBreakProcess) + (bad_DebugSetProcessKillOnExit, bad_EnumProcessModules) + (bad_GetModuleFileNameExW, bad_GetModuleFileNameExA) + (bad_GetModuleInformation, bad_OpenProcessToken): Remove. + (bad): New template functions. + (_initialize_loadable): Update. + 2021-04-30 Tom Tromey * ada-lang.c (ada_index_type): Use ada_check_typedef. diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index c0f64f87910..37238913a0f 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -160,7 +160,6 @@ static Wow64GetThreadSelectorEntry_ftype *Wow64GetThreadSelectorEntry; # define STARTUPINFO STARTUPINFOA # define CreateProcess CreateProcessA # define GetModuleFileNameEx_name "GetModuleFileNameExA" -# define bad_GetModuleFileNameEx bad_GetModuleFileNameExA #else # define __PMAX PATH_MAX /* The starting and ending address of the cygwin1.dll text segment. */ @@ -174,7 +173,6 @@ static Wow64GetThreadSelectorEntry_ftype *Wow64GetThreadSelectorEntry; # define STARTUPINFO STARTUPINFOW # define CreateProcess CreateProcessW # define GetModuleFileNameEx_name "GetModuleFileNameExW" -# define bad_GetModuleFileNameEx bad_GetModuleFileNameExW #endif static int have_saved_context; /* True if we've saved context from a @@ -3534,52 +3532,19 @@ _initialize_check_for_gdb_ini () /* Define dummy functions which always return error for the rare cases where these functions could not be found. */ -static BOOL WINAPI -bad_DebugActiveProcessStop (DWORD w) -{ - return FALSE; -} -static BOOL WINAPI -bad_DebugBreakProcess (HANDLE w) -{ - return FALSE; -} -static BOOL WINAPI -bad_DebugSetProcessKillOnExit (BOOL w) -{ - return FALSE; -} -static BOOL WINAPI -bad_EnumProcessModules (HANDLE w, HMODULE *x, DWORD y, LPDWORD z) +template +BOOL WINAPI +bad (T... args) { return FALSE; } -#ifdef __USEWIDE -static DWORD WINAPI -bad_GetModuleFileNameExW (HANDLE w, HMODULE x, LPWSTR y, DWORD z) -{ - return 0; -} -#else -static DWORD WINAPI -bad_GetModuleFileNameExA (HANDLE w, HMODULE x, LPSTR y, DWORD z) +template +DWORD WINAPI +bad (T... args) { return 0; } -#endif - -static BOOL WINAPI -bad_GetModuleInformation (HANDLE w, HMODULE x, LPMODULEINFO y, DWORD z) -{ - return FALSE; -} - -static BOOL WINAPI -bad_OpenProcessToken (HANDLE w, DWORD x, PHANDLE y) -{ - return FALSE; -} static BOOL WINAPI bad_GetCurrentConsoleFont (HANDLE w, BOOL bMaxWindow, CONSOLE_FONT_INFO *f) @@ -3587,6 +3552,7 @@ bad_GetCurrentConsoleFont (HANDLE w, BOOL bMaxWindow, CONSOLE_FONT_INFO *f) f->nFont = 0; return 1; } + static COORD WINAPI bad_GetConsoleFontSize (HANDLE w, DWORD nFont) { @@ -3628,11 +3594,11 @@ _initialize_loadable () /* Set variables to dummy versions of these processes if the function wasn't found in kernel32.dll. */ if (!DebugBreakProcess) - DebugBreakProcess = bad_DebugBreakProcess; + DebugBreakProcess = bad; if (!DebugActiveProcessStop || !DebugSetProcessKillOnExit) { - DebugActiveProcessStop = bad_DebugActiveProcessStop; - DebugSetProcessKillOnExit = bad_DebugSetProcessKillOnExit; + DebugActiveProcessStop = bad; + DebugSetProcessKillOnExit = bad; } if (!GetConsoleFontSize) GetConsoleFontSize = bad_GetConsoleFontSize; @@ -3657,9 +3623,9 @@ _initialize_loadable () { /* Set variables to dummy versions of these processes if the function wasn't found in psapi.dll. */ - EnumProcessModules = bad_EnumProcessModules; - GetModuleInformation = bad_GetModuleInformation; - GetModuleFileNameEx = bad_GetModuleFileNameEx; + 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(_("\ @@ -3677,7 +3643,7 @@ Use \"file\" or \"dll\" command to load executable/libraries directly.")); else is needed. */ if (!OpenProcessToken || !LookupPrivilegeValueA || !AdjustTokenPrivileges) - OpenProcessToken = bad_OpenProcessToken; + OpenProcessToken = bad; } #undef GPA -- 2.30.2