[PATCH 1/9] dbghelp/tests: Added dedicated structure to control the debuggee

Eric Pouech eric.pouech at gmail.com
Mon Jul 12 07:20:08 CDT 2021


- for now, it's purely inside the tests/dbghelp.c
- the goal is to also allow an external process

Signed-off-by: Eric Pouech <eric.pouech at gmail.com>

---
 dlls/dbghelp/tests/dbghelp.c |   57 +++++++++++++++++++++++++-----------------
 1 file changed, 34 insertions(+), 23 deletions(-)

diff --git a/dlls/dbghelp/tests/dbghelp.c b/dlls/dbghelp/tests/dbghelp.c
index a243d047d18..c9bbd90deb4 100644
--- a/dlls/dbghelp/tests/dbghelp.c
+++ b/dlls/dbghelp/tests/dbghelp.c
@@ -21,6 +21,13 @@
 #include "dbghelp.h"
 #include "wine/test.h"
 
+struct debuggee
+{
+    const char* name; /* name of main module */
+    HANDLE hProcess;
+    HANDLE hThread; /* either new thread calling stack_walk_thread, or main thread */
+};
+
 #if defined(__i386__) || defined(__x86_64__)
 
 static DWORD CALLBACK stack_walk_thread(void *arg)
@@ -30,32 +37,19 @@ static DWORD CALLBACK stack_walk_thread(void *arg)
     return 0;
 }
 
-static void test_stack_walk(void)
+static void test_stack_walk(const struct debuggee* dbg)
 {
     char si_buf[sizeof(SYMBOL_INFO) + 200];
     SYMBOL_INFO *si = (SYMBOL_INFO *)si_buf;
     STACKFRAME64 frame = {{0}}, frame0;
     BOOL found_our_frame = FALSE;
     DWORD machine;
-    HANDLE thread;
     DWORD64 disp;
     CONTEXT ctx;
-    DWORD count;
     BOOL ret;
 
-    thread = CreateThread(NULL, 0, stack_walk_thread, NULL, 0, NULL);
-
-    /* wait for the thread to suspend itself */
-    do
-    {
-        Sleep(50);
-        count = SuspendThread(thread);
-        ResumeThread(thread);
-    }
-    while (!count);
-
     ctx.ContextFlags = CONTEXT_CONTROL;
-    ret = GetThreadContext(thread, &ctx);
+    ret = GetThreadContext(dbg->hThread, &ctx);
     ok(ret, "got error %u\n", ret);
 
     frame.AddrPC.Mode    = AddrModeFlat;
@@ -84,7 +78,7 @@ static void test_stack_walk(void)
     frame0 = frame;
 
     /* first invocation just calculates the return address */
-    ret = StackWalk64(machine, GetCurrentProcess(), thread, &frame, &ctx, NULL,
+    ret = StackWalk64(machine, dbg->hProcess, dbg->hThread, &frame, &ctx, NULL,
         SymFunctionTableAccess64, SymGetModuleBase64, NULL);
     ok(ret, "StackWalk64() failed: %u\n", GetLastError());
     ok(frame.AddrPC.Offset == frame0.AddrPC.Offset, "expected %s, got %s\n",
@@ -100,7 +94,7 @@ static void test_stack_walk(void)
     {
         char *addr;
 
-        ret = StackWalk64(machine, GetCurrentProcess(), thread, &frame, &ctx, NULL,
+        ret = StackWalk64(machine, dbg->hProcess, dbg->hThread, &frame, &ctx, NULL,
             SymFunctionTableAccess64, SymGetModuleBase64, NULL);
         ok(ret, "StackWalk64() failed: %u\n", GetLastError());
 
@@ -112,12 +106,12 @@ static void test_stack_walk(void)
 
             si->SizeOfStruct = sizeof(SYMBOL_INFO);
             si->MaxNameLen = 200;
-            if (SymFromAddr(GetCurrentProcess(), frame.AddrPC.Offset, &disp, si))
+            if (SymFromAddr(dbg->hProcess, frame.AddrPC.Offset, &disp, si))
                 ok(!strcmp(si->Name, "stack_walk_thread"), "got wrong name %s\n", si->Name);
         }
     }
 
-    ret = StackWalk64(machine, GetCurrentProcess(), thread, &frame, &ctx, NULL,
+    ret = StackWalk64(machine, dbg->hProcess, dbg->hThread, &frame, &ctx, NULL,
         SymFunctionTableAccess64, SymGetModuleBase64, NULL);
     ok(!ret, "StackWalk64() should have failed\n");
 
@@ -126,7 +120,7 @@ static void test_stack_walk(void)
 
 #else /* __i386__ || __x86_64__ */
 
-static void test_stack_walk(void)
+static void test_stack_walk(const struct debuggee* dbg)
 {
 }
 
@@ -134,11 +128,28 @@ static void test_stack_walk(void)
 
 START_TEST(dbghelp)
 {
-    BOOL ret = SymInitialize(GetCurrentProcess(), NULL, TRUE);
+    struct debuggee dbg;
+    DWORD count;
+    BOOL ret;
+
+    dbg.name = "self";
+    dbg.hProcess = GetCurrentProcess();
+    dbg.hThread = CreateThread(NULL, 0, stack_walk_thread, NULL, 0, NULL);
+
+    /* wait for the thread to suspend itself */
+    do
+    {
+        Sleep(50);
+        count = SuspendThread(dbg.hThread);
+        ResumeThread(dbg.hThread);
+    }
+    while (!count);
+
+    ret = SymInitialize(dbg.hProcess, NULL, TRUE);
     ok(ret, "got error %u\n", GetLastError());
 
-    test_stack_walk();
+    test_stack_walk(&dbg);
 
-    ret = SymCleanup(GetCurrentProcess());
+    ret = SymCleanup(dbg.hProcess);
     ok(ret, "got error %u\n", GetLastError());
 }




More information about the wine-devel mailing list