From a6795414d123170f287b2351d93e56ad3b528871 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sun, 16 Apr 2000 19:46:35 +0000 Subject: [PATCH] Implemented 'walk process' and 'walk threads' commands using toolhelp snapshots. --- debugger/dbg.y | 3 ++- debugger/debug.l | 1 + debugger/debugger.h | 1 + debugger/info.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/debugger/dbg.y b/debugger/dbg.y index 913e1d4f797..fea90c095a8 100644 --- a/debugger/dbg.y +++ b/debugger/dbg.y @@ -45,7 +45,7 @@ int yyerror(char *); %token tCONT tPASS tSTEP tLIST tNEXT tQUIT tHELP tBACKTRACE tINFO tWALK tUP tDOWN %token tENABLE tDISABLE tBREAK tWATCH tDELETE tSET tMODE tPRINT tEXAM tABORT %token tCLASS tMAPS tMODULE tSTACK tSEGMENTS tREGS tWND tQUEUE tLOCAL -%token tPROCESS tMODREF +%token tPROCESS tTHREAD tMODREF %token tEOL tSTRING tDEBUGSTR %token tFRAME tSHARE tCOND tDISPLAY tUNDISPLAY tDISASSEMBLE %token tSTEPI tNEXTI tFINISH tSHOW tDIR tWHATIS @@ -282,6 +282,7 @@ walk_command: | tWALK tWND tEOL { DEBUG_WalkWindows( 0, 0 ); } | tWALK tWND tNUM tEOL { DEBUG_WalkWindows( $3, 0 ); } | tWALK tPROCESS tEOL { DEBUG_WalkProcess(); } + | tWALK tTHREAD tEOL { DEBUG_WalkThreads(); } | tWALK tMODREF expr_value tEOL { DEBUG_WalkModref( $3 ); } diff --git a/debugger/debug.l b/debugger/debug.l index 2884216b31e..75f165d0484 100644 --- a/debugger/debug.l +++ b/debugger/debug.l @@ -159,6 +159,7 @@ $gs { yylval.reg = REG_GS; return tREG; } module|modul|modu|mod { return tMODULE; } queue|queu|que { return tQUEUE; } process|proces|proce|proc { return tPROCESS; } +threads|thread|threa|thre|thr|th { return tTHREAD; } modref|modre|modr { return tMODREF; } registers|regs|reg|re { return tREGS; } segments|segment|segm|seg|se { return tSEGMENTS; } diff --git a/debugger/debugger.h b/debugger/debugger.h index 2ff273cc0fe..24d3bb4bbec 100644 --- a/debugger/debugger.h +++ b/debugger/debugger.h @@ -320,6 +320,7 @@ extern void DEBUG_WalkModref(DWORD p); extern void DEBUG_DumpModule(DWORD mod); extern void DEBUG_WalkModules(void); extern void DEBUG_WalkProcess(void); +extern void DEBUG_WalkThreads(void); extern void DEBUG_DumpQueue(DWORD q); extern void DEBUG_WalkQueues(void); extern void DEBUG_InfoSegments(DWORD s, int v); diff --git a/debugger/info.c b/debugger/info.c index 606e50c2ad3..bd6abee062a 100644 --- a/debugger/info.c +++ b/debugger/info.c @@ -13,6 +13,7 @@ #include "wingdi.h" #include "winuser.h" #include "toolhelp.h" +#include "tlhelp32.h" #include "debugger.h" #include "expr.h" @@ -440,7 +441,49 @@ void DEBUG_WalkWindows(HWND hWnd, int indent) void DEBUG_WalkProcess(void) { - DEBUG_Printf(DBG_CHN_MESG, "No longer walking processes list\n"); + HANDLE snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); + if (snap != INVALID_HANDLE_VALUE) + { + PROCESSENTRY32 entry; + DWORD current = DEBUG_CurrProcess ? DEBUG_CurrProcess->pid : 0; + BOOL ok = Process32First( snap, &entry ); + + DEBUG_Printf(DBG_CHN_MESG, "%-8.8s %-8.8s %-8.8s %s\n", + "pid", "threads", "parent", "exe" ); + while (ok) + { + if (entry.th32ProcessID != GetCurrentProcessId()) + DEBUG_Printf(DBG_CHN_MESG, "%08lx %8d %08lx '%s'%s\n", + entry.th32ProcessID, entry.cntThreads, + entry.th32ParentProcessID, entry.szExeFile, + (entry.th32ProcessID == current) ? " <==" : "" ); + ok = Process32Next( snap, &entry ); + } + CloseHandle( snap ); + } +} + +void DEBUG_WalkThreads(void) +{ + HANDLE snap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 ); + if (snap != INVALID_HANDLE_VALUE) + { + THREADENTRY32 entry; + DWORD current = DEBUG_CurrThread ? DEBUG_CurrThread->tid : 0; + BOOL ok = Thread32First( snap, &entry ); + + DEBUG_Printf(DBG_CHN_MESG, "%-8.8s %-8.8s %s\n", + "tid", "process", "prio" ); + while (ok) + { + if (entry.th32OwnerProcessID != GetCurrentProcessId()) + DEBUG_Printf(DBG_CHN_MESG, "%08lx %08lx %4ld%s\n", + entry.th32ThreadID, entry.th32OwnerProcessID, + entry.tbBasePri, (entry.th32ThreadID == current) ? " <==" : "" ); + ok = Thread32Next( snap, &entry ); + } + CloseHandle( snap ); + } } void DEBUG_WalkModref(DWORD p) -- 2.11.4.GIT