Commit 7f10145a authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

dbghelp: Simplify thread info generation in minidump.

parent f799bf02
...@@ -119,7 +119,6 @@ static void fetch_thread_stack(struct dump_context* dc, const void* teb_addr, ...@@ -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' * fetches some information about thread of id 'tid'
*/ */
static BOOL fetch_thread_info(struct dump_context* dc, int thd_idx, static BOOL fetch_thread_info(struct dump_context* dc, int thd_idx,
const MINIDUMP_EXCEPTION_INFORMATION* except,
MINIDUMP_THREAD* mdThd, CONTEXT* ctx) MINIDUMP_THREAD* mdThd, CONTEXT* ctx)
{ {
DWORD tid = dc->threads[thd_idx].tid; DWORD tid = dc->threads[thd_idx].tid;
...@@ -144,44 +143,22 @@ static BOOL fetch_thread_info(struct dump_context* dc, int thd_idx, ...@@ -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()); FIXME("Couldn't open thread %lu (%lu)\n", tid, GetLastError());
return FALSE; return FALSE;
} }
if (NtQueryInformationThread(hThread, ThreadBasicInformation, if (NtQueryInformationThread(hThread, ThreadBasicInformation,
&tbi, sizeof(tbi), NULL) == STATUS_SUCCESS) &tbi, sizeof(tbi), NULL) == STATUS_SUCCESS)
{ {
mdThd->Teb = (ULONG_PTR)tbi.TebBaseAddress; mdThd->Teb = (ULONG_PTR)tbi.TebBaseAddress;
if (tbi.ExitStatus == STILL_ACTIVE) if (tbi.ExitStatus == STILL_ACTIVE)
{ {
if (tid != GetCurrentThreadId() && mdThd->SuspendCount = SuspendThread(hThread);
(mdThd->SuspendCount = SuspendThread(hThread)) != (DWORD)-1) ctx->ContextFlags = CONTEXT_ALL;
{ if (!GetThreadContext(hThread, ctx))
ctx->ContextFlags = CONTEXT_FULL; memset(ctx, 0, sizeof(*ctx));
if (!GetThreadContext(hThread, ctx)) fetch_thread_stack(dc, tbi.TebBaseAddress, ctx, &mdThd->Stack);
memset(ctx, 0, sizeof(*ctx)); ResumeThread(hThread);
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;
} }
else
mdThd->SuspendCount = (DWORD)-1;
} }
CloseHandle(hThread); CloseHandle(hThread);
return TRUE; return TRUE;
...@@ -733,7 +710,7 @@ static unsigned dump_threads(struct dump_context* dc) ...@@ -733,7 +710,7 @@ static unsigned dump_threads(struct dump_context* dc)
for (i = 0; i < dc->num_threads; i++) 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 | flags_out = ThreadWriteThread | ThreadWriteStack | ThreadWriteContext |
ThreadWriteInstructionWindow; ThreadWriteInstructionWindow;
......
...@@ -192,7 +192,7 @@ static unsigned minidump_get_number_of_threads(void *data) ...@@ -192,7 +192,7 @@ static unsigned minidump_get_number_of_threads(void *data)
return thread_list->NumberOfThreads; 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; MINIDUMP_THREAD_LIST *thread_list;
ULONG stream_size; ULONG stream_size;
...@@ -208,17 +208,12 @@ static void minidump_check_threads(void *data, unsigned todo_flags) ...@@ -208,17 +208,12 @@ static void minidump_check_threads(void *data, unsigned todo_flags)
const MINIDUMP_THREAD *thread = &thread_list->Threads[i]; const MINIDUMP_THREAD *thread = &thread_list->Threads[i];
const CONTEXT *ctx; const CONTEXT *ctx;
todo_wine_if(todo_flags & 4)
ok(thread->SuspendCount == 0, "Unexpected value\n"); ok(thread->SuspendCount == 0, "Unexpected value\n");
todo_wine_if(todo_flags & 1)
ok(thread->Stack.StartOfMemoryRange, "Unexpected value %I64x\n", thread->Stack.StartOfMemoryRange); 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->Stack.Memory.DataSize, "Unexpected value %x\n", thread->Stack.Memory.DataSize);
ok(thread->Teb, "Unexpected value\n"); ok(thread->Teb, "Unexpected value\n");
todo_wine_if(todo_flags & 8)
ok(thread->ThreadContext.DataSize >= sizeof(CONTEXT), "Unexpected value\n"); ok(thread->ThreadContext.DataSize >= sizeof(CONTEXT), "Unexpected value\n");
ctx = RVA_TO_ADDR(data, thread->ThreadContext.Rva); ctx = RVA_TO_ADDR(data, thread->ThreadContext.Rva);
todo_wine_if(todo_flags & 2)
ok((ctx->ContextFlags & CONTEXT_ALL) == CONTEXT_ALL, "Unexpected value\n"); ok((ctx->ContextFlags & CONTEXT_ALL) == CONTEXT_ALL, "Unexpected value\n");
} }
} }
...@@ -463,7 +458,7 @@ static void test_current_process(void) ...@@ -463,7 +458,7 @@ static void test_current_process(void)
num_threads = minidump_get_number_of_threads(data); num_threads = minidump_get_number_of_threads(data);
ok(num_threads > 0, "Unexpected number of threads\n"); 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); md = minidump_get_memory_description(data, (DWORD_PTR)&i);
ok(md.kind == MD_STACK, "Couldn't find automatic variable\n"); ok(md.kind == MD_STACK, "Couldn't find automatic variable\n");
...@@ -807,7 +802,7 @@ static void test_exception(void) ...@@ -807,7 +802,7 @@ static void test_exception(void)
ok(except_info->ThreadContext.Rva, "Unexpected value\n"); ok(except_info->ThreadContext.Rva, "Unexpected value\n");
mctx = RVA_TO_ADDR(data, except_info->ThreadContext.Rva); mctx = RVA_TO_ADDR(data, except_info->ThreadContext.Rva);
ok(!memcmp(mctx, &ctx, sizeof(ctx)), "Unexpected value\n"); ok(!memcmp(mctx, &ctx, sizeof(ctx)), "Unexpected value\n");
minidump_check_threads(data, 2); minidump_check_threads(data);
minidump_close_for_read(data); minidump_close_for_read(data);
DeleteFileA("foo.mdmp"); DeleteFileA("foo.mdmp");
winetest_pop_context(); winetest_pop_context();
......
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