From eca3715f88b4ffd33b4384c3ba41c74d2f861b35 Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Mon, 23 Jan 2006 16:30:03 +0100 Subject: [PATCH] dbghelp: Live targets. In SymInitialize, now trying to check if the hProcess is a real live target or not. If we think it is, try to grasp ELF information from it. --- dlls/dbghelp/dbghelp.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/dlls/dbghelp/dbghelp.c b/dlls/dbghelp/dbghelp.c index e0b90489454..66d687d5e05 100644 --- a/dlls/dbghelp/dbghelp.c +++ b/dlls/dbghelp/dbghelp.c @@ -163,6 +163,17 @@ static BOOL WINAPI process_invade_cb(char* name, DWORD base, DWORD size, void* u return TRUE; } +/****************************************************************** + * check_live_target + * + */ +static BOOL check_live_target(struct process* pcs) +{ + if (!GetProcessId(pcs->handle)) return FALSE; + if (!elf_read_wine_loader_dbg_info(pcs)) return FALSE; + return getenv("DBGHELP_NOLIVE") == NULL; +} + /****************************************************************** * SymInitialize (DBGHELP.@) * @@ -178,11 +189,14 @@ static BOOL WINAPI process_invade_cb(char* name, DWORD base, DWORD size, void* u * our internal ELF modules representation (loading / unloading). This way, * we'll pair every loaded builtin PE module with its ELF counterpart (and * access its debug information). - * - if fInvadeProcess (in SymInitialize) is FALSE, we won't be able to - * make the peering between a builtin PE module and its ELF counterpart, hence - * we won't be able to provide the requested debug information. We'll - * however be able to load native PE modules (and their debug information) - * without any trouble. + * - if fInvadeProcess (in SymInitialize) is FALSE, we check anyway if the + * hProcess refers to a running process. We use some heuristics here, so YMMV. + * If we detect a live target, then we get the same handling as if + * fInvadeProcess is TRUE (except that the modules are not loaded). Otherwise, + * we won't be able to make the peering between a builtin PE module and its ELF + * counterpart. Hence we won't be able to provide the requested debug + * information. We'll however be able to load native PE modules (and their + * debug information) without any trouble. * Note also that this scheme can be intertwined with the deferred loading * mechanism (ie only load the debug information when we actually need it). */ @@ -237,17 +251,19 @@ BOOL WINAPI SymInitialize(HANDLE hProcess, PSTR UserSearchPath, BOOL fInvadeProc pcs->dbg_hdr_addr = 0; pcs->next = process_first; process_first = pcs; - - if (fInvadeProcess) + + if (check_live_target(pcs)) { - if (!elf_read_wine_loader_dbg_info(pcs)) - { - SymCleanup(hProcess); - return FALSE; - } - EnumerateLoadedModules(hProcess, process_invade_cb, (void*)hProcess); + if (fInvadeProcess) + EnumerateLoadedModules(hProcess, process_invade_cb, (void*)hProcess); elf_synchronize_module_list(pcs); } + else if (fInvadeProcess) + { + SymCleanup(hProcess); + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } return TRUE; }