dbghelp: Simplify thread info generation in minidump.

Signed-off-by: Eric Pouech <epouech@codeweavers.com>
This commit is contained in:
Eric Pouech 2024-03-11 10:53:48 +01:00 committed by Alexandre Julliard
parent f799bf025b
commit 7f10145a91
2 changed files with 13 additions and 41 deletions

View file

@ -119,7 +119,6 @@ static void fetch_thread_stack(struct dump_context* dc, const void* teb_addr,
* fetches some information about thread of id 'tid'
*/
static BOOL fetch_thread_info(struct dump_context* dc, int thd_idx,
const MINIDUMP_EXCEPTION_INFORMATION* except,
MINIDUMP_THREAD* mdThd, CONTEXT* ctx)
{
DWORD tid = dc->threads[thd_idx].tid;
@ -144,44 +143,22 @@ static BOOL fetch_thread_info(struct dump_context* dc, int thd_idx,
FIXME("Couldn't open thread %lu (%lu)\n", tid, GetLastError());
return FALSE;
}
if (NtQueryInformationThread(hThread, ThreadBasicInformation,
&tbi, sizeof(tbi), NULL) == STATUS_SUCCESS)
{
mdThd->Teb = (ULONG_PTR)tbi.TebBaseAddress;
if (tbi.ExitStatus == STILL_ACTIVE)
{
if (tid != GetCurrentThreadId() &&
(mdThd->SuspendCount = SuspendThread(hThread)) != (DWORD)-1)
{
ctx->ContextFlags = CONTEXT_FULL;
if (!GetThreadContext(hThread, ctx))
memset(ctx, 0, sizeof(*ctx));
fetch_thread_stack(dc, tbi.TebBaseAddress, ctx, &mdThd->Stack);
ResumeThread(hThread);
}
else if (tid == GetCurrentThreadId() && except)
{
CONTEXT lctx, *pctx;
mdThd->SuspendCount = 1;
if (except->ClientPointers)
{
EXCEPTION_POINTERS ep;
ReadProcessMemory(dc->process->handle, except->ExceptionPointers,
&ep, sizeof(ep), NULL);
ReadProcessMemory(dc->process->handle, ep.ContextRecord,
&lctx, sizeof(lctx), NULL);
pctx = &lctx;
}
else pctx = except->ExceptionPointers->ContextRecord;
*ctx = *pctx;
fetch_thread_stack(dc, tbi.TebBaseAddress, pctx, &mdThd->Stack);
}
else mdThd->SuspendCount = 0;
mdThd->SuspendCount = SuspendThread(hThread);
ctx->ContextFlags = CONTEXT_ALL;
if (!GetThreadContext(hThread, ctx))
memset(ctx, 0, sizeof(*ctx));
fetch_thread_stack(dc, tbi.TebBaseAddress, ctx, &mdThd->Stack);
ResumeThread(hThread);
}
else
mdThd->SuspendCount = (DWORD)-1;
}
CloseHandle(hThread);
return TRUE;
@ -733,7 +710,7 @@ static unsigned dump_threads(struct dump_context* dc)
for (i = 0; i < dc->num_threads; i++)
{
fetch_thread_info(dc, i, dc->except_param, &mdThd, &ctx);
fetch_thread_info(dc, i, &mdThd, &ctx);
flags_out = ThreadWriteThread | ThreadWriteStack | ThreadWriteContext |
ThreadWriteInstructionWindow;

View file

@ -192,7 +192,7 @@ static unsigned minidump_get_number_of_threads(void *data)
return thread_list->NumberOfThreads;
}
static void minidump_check_threads(void *data, unsigned todo_flags)
static void minidump_check_threads(void *data)
{
MINIDUMP_THREAD_LIST *thread_list;
ULONG stream_size;
@ -208,17 +208,12 @@ static void minidump_check_threads(void *data, unsigned todo_flags)
const MINIDUMP_THREAD *thread = &thread_list->Threads[i];
const CONTEXT *ctx;
todo_wine_if(todo_flags & 4)
ok(thread->SuspendCount == 0, "Unexpected value\n");
todo_wine_if(todo_flags & 1)
ok(thread->Stack.StartOfMemoryRange, "Unexpected value %I64x\n", thread->Stack.StartOfMemoryRange);
todo_wine_if(todo_flags & 1)
ok(thread->Stack.Memory.DataSize, "Unexpected value %x\n", thread->Stack.Memory.DataSize);
ok(thread->Teb, "Unexpected value\n");
todo_wine_if(todo_flags & 8)
ok(thread->ThreadContext.DataSize >= sizeof(CONTEXT), "Unexpected value\n");
ctx = RVA_TO_ADDR(data, thread->ThreadContext.Rva);
todo_wine_if(todo_flags & 2)
ok((ctx->ContextFlags & CONTEXT_ALL) == CONTEXT_ALL, "Unexpected value\n");
}
}
@ -463,7 +458,7 @@ static void test_current_process(void)
num_threads = minidump_get_number_of_threads(data);
ok(num_threads > 0, "Unexpected number of threads\n");
minidump_check_threads(data, 2);
minidump_check_threads(data);
md = minidump_get_memory_description(data, (DWORD_PTR)&i);
ok(md.kind == MD_STACK, "Couldn't find automatic variable\n");
@ -807,7 +802,7 @@ static void test_exception(void)
ok(except_info->ThreadContext.Rva, "Unexpected value\n");
mctx = RVA_TO_ADDR(data, except_info->ThreadContext.Rva);
ok(!memcmp(mctx, &ctx, sizeof(ctx)), "Unexpected value\n");
minidump_check_threads(data, 2);
minidump_check_threads(data);
minidump_close_for_read(data);
DeleteFileA("foo.mdmp");
winetest_pop_context();