Commit 3b8805fc authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

Fixed regression on 'bt <tid>' command.

parent c9eb05e5
...@@ -100,7 +100,7 @@ int stack_get_frame(SYMBOL_INFO* symbol, IMAGEHLP_STACK_FRAME* ihsf) ...@@ -100,7 +100,7 @@ int stack_get_frame(SYMBOL_INFO* symbol, IMAGEHLP_STACK_FRAME* ihsf)
void stack_backtrace(DWORD tid, BOOL noisy) void stack_backtrace(DWORD tid, BOOL noisy)
{ {
STACKFRAME sf; STACKFRAME sf;
CONTEXT ctx; CONTEXT saved_dbg_context;
struct dbg_thread* thread; struct dbg_thread* thread;
unsigned nf; unsigned nf;
...@@ -109,24 +109,28 @@ void stack_backtrace(DWORD tid, BOOL noisy) ...@@ -109,24 +109,28 @@ void stack_backtrace(DWORD tid, BOOL noisy)
THREADENTRY32 entry; THREADENTRY32 entry;
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (snapshot == INVALID_HANDLE_VALUE) { if (snapshot == INVALID_HANDLE_VALUE)
{
dbg_printf("unable to create toolhelp snapshot\n"); dbg_printf("unable to create toolhelp snapshot\n");
return; return;
} }
entry.dwSize = sizeof(entry); entry.dwSize = sizeof(entry);
if (!Thread32First(snapshot, &entry)) { if (!Thread32First(snapshot, &entry))
{
CloseHandle(snapshot); CloseHandle(snapshot);
return; return;
} }
do { do
{
if (entry.th32OwnerProcessID == GetCurrentProcessId()) continue; if (entry.th32OwnerProcessID == GetCurrentProcessId()) continue;
if (dbg_curr_process) dbg_detach_debuggee(); if (dbg_curr_process) dbg_detach_debuggee();
dbg_printf("\n"); dbg_printf("\n");
if (!dbg_attach_debuggee(entry.th32OwnerProcessID, FALSE, TRUE)) { if (!dbg_attach_debuggee(entry.th32OwnerProcessID, FALSE, TRUE))
{
dbg_printf("\nwarning: could not attach to 0x%lx\n", entry.th32OwnerProcessID); dbg_printf("\nwarning: could not attach to 0x%lx\n", entry.th32OwnerProcessID);
continue; continue;
} }
...@@ -134,21 +138,23 @@ void stack_backtrace(DWORD tid, BOOL noisy) ...@@ -134,21 +138,23 @@ void stack_backtrace(DWORD tid, BOOL noisy)
dbg_printf("Backtracing for thread 0x%lx in process 0x%lx (%s):\n", entry.th32ThreadID, dbg_curr_pid, dbg_curr_process->imageName); dbg_printf("Backtracing for thread 0x%lx in process 0x%lx (%s):\n", entry.th32ThreadID, dbg_curr_pid, dbg_curr_process->imageName);
stack_backtrace(entry.th32ThreadID, TRUE); stack_backtrace(entry.th32ThreadID, TRUE);
} while (Thread32Next(snapshot, &entry)); }
while (Thread32Next(snapshot, &entry));
if (dbg_curr_process) dbg_detach_debuggee(); if (dbg_curr_process) dbg_detach_debuggee();
CloseHandle(snapshot); CloseHandle(snapshot);
return; return;
} }
if (!dbg_curr_process) { if (!dbg_curr_process)
{
dbg_printf("You must be attached to a process to run this command.\n"); dbg_printf("You must be attached to a process to run this command.\n");
return; return;
} }
saved_dbg_context = dbg_context; /* as we may modify dbg_context... */
if (tid == dbg_curr_tid) if (tid == dbg_curr_tid)
{ {
ctx = dbg_context; /* as StackWalk may modify it... */
thread = dbg_curr_thread; thread = dbg_curr_thread;
if (frames) HeapFree(GetProcessHeap(), 0, frames); if (frames) HeapFree(GetProcessHeap(), 0, frames);
frames = NULL; frames = NULL;
...@@ -161,16 +167,21 @@ void stack_backtrace(DWORD tid, BOOL noisy) ...@@ -161,16 +167,21 @@ void stack_backtrace(DWORD tid, BOOL noisy)
dbg_printf("Unknown thread id (0x%08lx) in current process\n", tid); dbg_printf("Unknown thread id (0x%08lx) in current process\n", tid);
return; return;
} }
memset(&ctx, 0, sizeof(ctx)); memset(&dbg_context, 0, sizeof(dbg_context));
ctx.ContextFlags = CONTEXT_CONTROL; dbg_context.ContextFlags = CONTEXT_FULL;
#ifdef CONTEXT_SEGMENTS if (SuspendThread(thread->handle) != -1)
ctx.ContextFlags |= CONTEXT_SEGMENTS; {
#endif if (!GetThreadContext(thread->handle, &dbg_context))
if (SuspendThread(thread->handle) == -1 || {
!GetThreadContext(thread->handle, &ctx)) dbg_printf("Can't get context for thread 0x%lx in current process\n",
tid);
ResumeThread(thread->handle);
return;
}
}
else
{ {
dbg_printf("Can't get context for thread 0x%lx in current process\n", dbg_printf("Can't suspend thread 0x%lx in current process\n", tid);
tid);
return; return;
} }
} }
...@@ -182,7 +193,7 @@ void stack_backtrace(DWORD tid, BOOL noisy) ...@@ -182,7 +193,7 @@ void stack_backtrace(DWORD tid, BOOL noisy)
if (noisy) dbg_printf("Backtrace:\n"); if (noisy) dbg_printf("Backtrace:\n");
while (StackWalk(IMAGE_FILE_MACHINE_I386, dbg_curr_process->handle, while (StackWalk(IMAGE_FILE_MACHINE_I386, dbg_curr_process->handle,
thread->handle, &sf, &ctx, NULL, SymFunctionTableAccess, thread->handle, &sf, &dbg_context, NULL, SymFunctionTableAccess,
SymGetModuleBase, NULL)) SymGetModuleBase, NULL))
{ {
if (tid == dbg_curr_tid) if (tid == dbg_curr_tid)
...@@ -206,6 +217,7 @@ void stack_backtrace(DWORD tid, BOOL noisy) ...@@ -206,6 +217,7 @@ void stack_backtrace(DWORD tid, BOOL noisy)
nf++; nf++;
} }
dbg_context = saved_dbg_context;
if (tid == dbg_curr_tid) if (tid == dbg_curr_tid)
{ {
nframe = nf; nframe = nf;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment