Fixed %p in printf (now using wsprintf which doesn't support it).
Added ThreadId and ProcessId internal vars. Allow at startup to pick up a process to debug.
This commit is contained in:
parent
3de3cad9ce
commit
f1822356b5
|
@ -451,7 +451,7 @@ BOOL DEBUG_Main( BOOL is_debug, BOOL force, DWORD code )
|
|||
DEBUG_Printf( DBG_CHN_MESG, " in 16-bit code (%04x:%04lx).\n",
|
||||
(WORD)DEBUG_context.SegCs, DEBUG_context.Eip );
|
||||
#else
|
||||
DEBUG_Printf( DBG_CHN_MESG, " (%p).\n", GET_IP(&DEBUG_context) );
|
||||
DEBUG_Printf( DBG_CHN_MESG, " (0x%08lx).\n", GET_IP(&DEBUG_context) );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -177,6 +177,8 @@ typedef struct tagDBG_PROCESS {
|
|||
|
||||
extern DBG_PROCESS* DEBUG_CurrProcess;
|
||||
extern DBG_THREAD* DEBUG_CurrThread;
|
||||
extern DWORD DEBUG_CurrTid;
|
||||
extern DWORD DEBUG_CurrPid;
|
||||
extern CONTEXT DEBUG_context;
|
||||
|
||||
#define DEBUG_READ_MEM(addr, buf, len) \
|
||||
|
@ -434,7 +436,11 @@ extern void DEBUG_Disassemble( const DBG_VALUE *, const DBG_VALUE*, int offset )
|
|||
#define DBG_CHN_FIXME 8
|
||||
#define DBG_CHN_TRACE 16
|
||||
extern void DEBUG_Output(int chn, const char* buffer, int len);
|
||||
#ifdef __GNUC__
|
||||
extern int DEBUG_Printf(int chn, const char* format, ...) __attribute__((format (printf,2,3)));
|
||||
#else
|
||||
extern int DEBUG_Printf(int chn, const char* format, ...);
|
||||
#endif
|
||||
extern DBG_INTVAR* DEBUG_GetIntVar(const char*);
|
||||
|
||||
/* Choose your allocator! */
|
||||
|
|
|
@ -444,14 +444,17 @@ void DEBUG_WalkProcess(void)
|
|||
{
|
||||
PROCESSENTRY32 entry;
|
||||
DWORD current = DEBUG_CurrProcess ? DEBUG_CurrProcess->pid : 0;
|
||||
BOOL ok = Process32First( snap, &entry );
|
||||
BOOL ok;
|
||||
|
||||
entry.dwSize = sizeof(entry);
|
||||
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",
|
||||
DEBUG_Printf(DBG_CHN_MESG, "%08lx %8ld %08lx '%s'%s\n",
|
||||
entry.th32ProcessID, entry.cntThreads,
|
||||
entry.th32ParentProcessID, entry.szExeFile,
|
||||
(entry.th32ProcessID == current) ? " <==" : "" );
|
||||
|
@ -468,7 +471,10 @@ void DEBUG_WalkThreads(void)
|
|||
{
|
||||
THREADENTRY32 entry;
|
||||
DWORD current = DEBUG_CurrThread ? DEBUG_CurrThread->tid : 0;
|
||||
BOOL ok = Thread32First( snap, &entry );
|
||||
BOOL ok;
|
||||
|
||||
entry.dwSize = sizeof(entry);
|
||||
ok = Thread32First( snap, &entry );
|
||||
|
||||
DEBUG_Printf(DBG_CHN_MESG, "%-8.8s %-8.8s %s\n",
|
||||
"tid", "process", "prio" );
|
||||
|
|
|
@ -18,6 +18,10 @@ INTERNAL_VAR(UseXTerm, TRUE, NULL, DEBUG_TypeIntConst)
|
|||
/* debugging debugger */
|
||||
INTERNAL_VAR(ExtDbgOnInvalidAddress, FALSE, NULL, DEBUG_TypeIntConst)
|
||||
|
||||
/* current process/thread */
|
||||
INTERNAL_VAR(ThreadId, FALSE, &DEBUG_CurrTid, DEBUG_TypeIntConst)
|
||||
INTERNAL_VAR(ProcessId, FALSE, &DEBUG_CurrPid, DEBUG_TypeIntConst)
|
||||
|
||||
/* context manipulation */
|
||||
#ifdef __i386__
|
||||
/* FIXME: 16 bit registers use imply that CPU is little endian, which is
|
||||
|
|
|
@ -599,7 +599,8 @@ DEBUG_ParseTypedefStab(char * ptr, const char * typename)
|
|||
}
|
||||
else
|
||||
{
|
||||
DEBUG_Printf(DBG_CHN_MESG, "Unknown condition %p %p (%s)\n", *dt, *dt2, ptr);
|
||||
DEBUG_Printf(DBG_CHN_MESG, "Unknown condition %08lx %08lx (%s)\n",
|
||||
(unsigned long)*dt, (unsigned long)*dt2, ptr);
|
||||
}
|
||||
if( *tc == '\0' )
|
||||
*c = '\0';
|
||||
|
@ -1229,7 +1230,7 @@ DEBUG_ProcessElfObject(const char * filename, unsigned int load_offset)
|
|||
if (DEBUG_FindModuleByName(filename, DM_TYPE_ELF))
|
||||
goto leave;
|
||||
|
||||
DEBUG_Printf(DBG_CHN_MESG, "Loading stabs debug symbols from %s (0x%08lx)\n",
|
||||
DEBUG_Printf(DBG_CHN_MESG, "Loading stabs debug symbols from %s (0x%08x)\n",
|
||||
filename, load_offset);
|
||||
|
||||
/*
|
||||
|
@ -1404,7 +1405,7 @@ DEBUG_ReadExecutableDbgInfo(const char* exe_name)
|
|||
DBG_VALUE value;
|
||||
|
||||
DEBUG_Printf(DBG_CHN_TRACE, "Setting up a breakpoint on r_brk(%lx)\n",
|
||||
dbg_hdr.r_brk);
|
||||
(unsigned long)dbg_hdr.r_brk);
|
||||
|
||||
DEBUG_SetBreakpoints(FALSE);
|
||||
value.type = NULL;
|
||||
|
|
|
@ -273,8 +273,8 @@ void DEBUG_BackTrace(BOOL noisy)
|
|||
|
||||
if (is16) {
|
||||
if (!DEBUG_READ_MEM((void*)next_switch, &frame32, sizeof(STACK32FRAME))) {
|
||||
if (noisy) DEBUG_Printf( DBG_CHN_MESG, "Bad stack frame %p\n",
|
||||
(STACK32FRAME*)next_switch );
|
||||
if (noisy) DEBUG_Printf( DBG_CHN_MESG, "Bad stack frame 0x%08lx\n",
|
||||
(unsigned long)(STACK32FRAME*)next_switch );
|
||||
return;
|
||||
}
|
||||
cur_switch = (DWORD)frame32.frame16;
|
||||
|
@ -286,7 +286,8 @@ void DEBUG_BackTrace(BOOL noisy)
|
|||
p = DEBUG_ToLinear(&tmp);
|
||||
|
||||
if (!DEBUG_READ_MEM((void*)p, &frame16, sizeof(STACK16FRAME))) {
|
||||
if (noisy) DEBUG_Printf( DBG_CHN_MESG, "Bad stack frame %p\n", (STACK16FRAME*)p );
|
||||
if (noisy) DEBUG_Printf( DBG_CHN_MESG, "Bad stack frame 0x%08lx\n",
|
||||
(unsigned long)(STACK16FRAME*)p );
|
||||
return;
|
||||
}
|
||||
cur_switch = (DWORD)frame16.frame32;
|
||||
|
@ -306,7 +307,8 @@ void DEBUG_BackTrace(BOOL noisy)
|
|||
if (is16) {
|
||||
|
||||
if (!DEBUG_READ_MEM((void*)next_switch, &frame32, sizeof(STACK32FRAME))) {
|
||||
if (noisy) DEBUG_Printf( DBG_CHN_MESG, "Bad stack frame %p\n", (STACK32FRAME*)next_switch );
|
||||
if (noisy) DEBUG_Printf( DBG_CHN_MESG, "Bad stack frame 0x%08lx\n",
|
||||
(unsigned long)(STACK32FRAME*)next_switch );
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -324,8 +326,8 @@ void DEBUG_BackTrace(BOOL noisy)
|
|||
p = DEBUG_ToLinear(&tmp);
|
||||
|
||||
if (!DEBUG_READ_MEM((void*)p, &frame16, sizeof(STACK16FRAME))) {
|
||||
if (noisy) DEBUG_Printf( DBG_CHN_MESG, "Bad stack frame %p\n",
|
||||
(STACK16FRAME*)p );
|
||||
if (noisy) DEBUG_Printf( DBG_CHN_MESG, "Bad stack frame 0x%08lx\n",
|
||||
(unsigned long)(STACK16FRAME*)p );
|
||||
return;
|
||||
}
|
||||
cur_switch = (DWORD)frame16.frame32;
|
||||
|
@ -339,8 +341,8 @@ void DEBUG_BackTrace(BOOL noisy)
|
|||
p = DEBUG_ToLinear(&tmp);
|
||||
|
||||
if (!DEBUG_READ_MEM((void*)p, &frame16, sizeof(STACK16FRAME))) {
|
||||
if (noisy) DEBUG_Printf( DBG_CHN_MESG, "Bad stack frame %p\n",
|
||||
(STACK16FRAME*)p );
|
||||
if (noisy) DEBUG_Printf( DBG_CHN_MESG, "Bad stack frame 0x%08lx\n",
|
||||
(unsigned long)(STACK16FRAME*)p );
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -354,8 +356,8 @@ void DEBUG_BackTrace(BOOL noisy)
|
|||
|
||||
next_switch = cur_switch;
|
||||
if (!DEBUG_READ_MEM((void*)next_switch, &frame32, sizeof(STACK32FRAME))) {
|
||||
if (noisy) DEBUG_Printf( DBG_CHN_MESG, "Bad stack frame %p\n",
|
||||
(STACK32FRAME*)next_switch );
|
||||
if (noisy) DEBUG_Printf( DBG_CHN_MESG, "Bad stack frame 0x%08lx\n",
|
||||
(unsigned long)(STACK32FRAME*)next_switch );
|
||||
return;
|
||||
}
|
||||
cur_switch = (DWORD)frame32.frame16;
|
||||
|
|
|
@ -933,12 +933,12 @@ DEBUG_DumpTypes(void)
|
|||
switch(dt->type)
|
||||
{
|
||||
case DT_BASIC:
|
||||
DEBUG_Printf(DBG_CHN_MESG, "0x%p - BASIC(%s)\n",
|
||||
dt, name);
|
||||
DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - BASIC(%s)\n",
|
||||
(unsigned long)dt, name);
|
||||
break;
|
||||
case DT_POINTER:
|
||||
DEBUG_Printf(DBG_CHN_MESG, "0x%p - POINTER(%s)(%p)\n",
|
||||
dt, name, dt->un.pointer.pointsto);
|
||||
DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - POINTER(%s)(%08lx)\n",
|
||||
(unsigned long)dt, name, (unsigned long)dt->un.pointer.pointsto);
|
||||
break;
|
||||
case DT_STRUCT:
|
||||
member_name = "none";
|
||||
|
@ -952,22 +952,24 @@ DEBUG_DumpTypes(void)
|
|||
nm++;
|
||||
}
|
||||
}
|
||||
DEBUG_Printf(DBG_CHN_MESG, "0x%p - STRUCT(%s) %d %d %s\n", dt, name,
|
||||
dt->un.structure.size, nm, member_name);
|
||||
DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - STRUCT(%s) %d %d %s\n",
|
||||
(unsigned long)dt, name, dt->un.structure.size, nm, member_name);
|
||||
break;
|
||||
case DT_ARRAY:
|
||||
DEBUG_Printf(DBG_CHN_MESG, "0x%p - ARRAY(%s)(%p)\n",
|
||||
dt, name, dt->un.array.basictype);
|
||||
DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - ARRAY(%s)(%08lx)\n",
|
||||
(unsigned long)dt, name, (unsigned long)dt->un.array.basictype);
|
||||
break;
|
||||
case DT_ENUM:
|
||||
DEBUG_Printf(DBG_CHN_MESG, "0x%p - ENUM(%s)\n", dt, name);
|
||||
DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - ENUM(%s)\n",
|
||||
(unsigned long)dt, name);
|
||||
break;
|
||||
case DT_BITFIELD:
|
||||
DEBUG_Printf(DBG_CHN_MESG, "0x%p - BITFIELD(%s)\n", dt, name);
|
||||
DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - BITFIELD(%s)\n",
|
||||
(unsigned long)dt, name);
|
||||
break;
|
||||
case DT_FUNC:
|
||||
DEBUG_Printf(DBG_CHN_MESG, "0x%p - FUNC(%s)(%p)\n",
|
||||
dt, name, dt->un.funct.rettype);
|
||||
DEBUG_Printf(DBG_CHN_MESG, "0x%08lx - FUNC(%s)(%08lx)\n",
|
||||
(unsigned long)dt, name, (unsigned long)dt->un.funct.rettype);
|
||||
break;
|
||||
case DT_CONST:
|
||||
case DT_TYPEDEF:
|
||||
|
|
|
@ -24,6 +24,8 @@ HANDLE dbg_heap = 0;
|
|||
|
||||
DBG_PROCESS* DEBUG_CurrProcess = NULL;
|
||||
DBG_THREAD* DEBUG_CurrThread = NULL;
|
||||
DWORD DEBUG_CurrTid;
|
||||
DWORD DEBUG_CurrPid;
|
||||
CONTEXT DEBUG_context;
|
||||
|
||||
static DBG_PROCESS* proc = NULL;
|
||||
|
@ -74,8 +76,7 @@ static BOOL DEBUG_IntVarsRW(int read)
|
|||
#undef INTERNAL_VAR
|
||||
}
|
||||
|
||||
if (RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\WineDbg", &hkey) &&
|
||||
RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\WineDbg", &hkey)) {
|
||||
if (RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\WineDbg", &hkey)) {
|
||||
/* since the IVars are not yet setup, DEBUG_Printf doesn't work,
|
||||
* so don't use it */
|
||||
fprintf(stderr, "Cannot create WineDbg key in registry\n");
|
||||
|
@ -343,6 +344,9 @@ static BOOL DEBUG_HandleDebugEvent(DEBUG_EVENT* de, LPDWORD cont)
|
|||
char buffer[256];
|
||||
BOOL ret;
|
||||
|
||||
DEBUG_CurrPid = de->dwProcessId;
|
||||
DEBUG_CurrTid = de->dwThreadId;
|
||||
|
||||
__TRY {
|
||||
ret = TRUE;
|
||||
*cont = 0L;
|
||||
|
@ -390,8 +394,8 @@ static BOOL DEBUG_HandleDebugEvent(DEBUG_EVENT* de, LPDWORD cont)
|
|||
break;
|
||||
|
||||
case CREATE_THREAD_DEBUG_EVENT:
|
||||
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: create thread D @%p\n", de->dwProcessId, de->dwThreadId,
|
||||
de->u.CreateThread.lpStartAddress);
|
||||
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: create thread D @%08lx\n", de->dwProcessId, de->dwThreadId,
|
||||
(unsigned long)(LPVOID)de->u.CreateThread.lpStartAddress);
|
||||
|
||||
if (DEBUG_CurrProcess == NULL) {
|
||||
DEBUG_Printf(DBG_CHN_ERR, "Unknown process\n");
|
||||
|
@ -420,10 +424,10 @@ static BOOL DEBUG_HandleDebugEvent(DEBUG_EVENT* de, LPDWORD cont)
|
|||
de->u.CreateProcessInfo.lpImageName);
|
||||
|
||||
/* FIXME unicode ? de->u.CreateProcessInfo.fUnicode */
|
||||
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: create process %s @%p (%ld<%ld>)\n",
|
||||
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: create process %s @%08lx (%ld<%ld>)\n",
|
||||
de->dwProcessId, de->dwThreadId,
|
||||
buffer,
|
||||
de->u.CreateProcessInfo.lpStartAddress,
|
||||
(unsigned long)(LPVOID)de->u.CreateProcessInfo.lpStartAddress,
|
||||
de->u.CreateProcessInfo.dwDebugInfoFileOffset,
|
||||
de->u.CreateProcessInfo.nDebugInfoSize);
|
||||
|
||||
|
@ -442,9 +446,9 @@ static BOOL DEBUG_HandleDebugEvent(DEBUG_EVENT* de, LPDWORD cont)
|
|||
}
|
||||
}
|
||||
|
||||
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: create thread I @%p\n",
|
||||
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: create thread I @%08lx\n",
|
||||
de->dwProcessId, de->dwThreadId,
|
||||
de->u.CreateProcessInfo.lpStartAddress);
|
||||
(unsigned long)(LPVOID)de->u.CreateProcessInfo.lpStartAddress);
|
||||
|
||||
DEBUG_CurrThread = DEBUG_AddThread(DEBUG_CurrProcess,
|
||||
de->dwThreadId,
|
||||
|
@ -501,9 +505,9 @@ static BOOL DEBUG_HandleDebugEvent(DEBUG_EVENT* de, LPDWORD cont)
|
|||
de->u.LoadDll.lpImageName);
|
||||
|
||||
/* FIXME unicode: de->u.LoadDll.fUnicode */
|
||||
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: loads DLL %s @%p (%ld<%ld>)\n",
|
||||
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: loads DLL %s @%08lx (%ld<%ld>)\n",
|
||||
de->dwProcessId, de->dwThreadId,
|
||||
buffer, de->u.LoadDll.lpBaseOfDll,
|
||||
buffer, (unsigned long)de->u.LoadDll.lpBaseOfDll,
|
||||
de->u.LoadDll.dwDebugInfoFileOffset,
|
||||
de->u.LoadDll.nDebugInfoSize);
|
||||
CharUpper(buffer);
|
||||
|
@ -511,8 +515,8 @@ static BOOL DEBUG_HandleDebugEvent(DEBUG_EVENT* de, LPDWORD cont)
|
|||
break;
|
||||
|
||||
case UNLOAD_DLL_DEBUG_EVENT:
|
||||
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: unload DLL @%p\n", de->dwProcessId, de->dwThreadId,
|
||||
de->u.UnloadDll.lpBaseOfDll);
|
||||
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: unload DLL @%08lx\n", de->dwProcessId, de->dwThreadId,
|
||||
(unsigned long)de->u.UnloadDll.lpBaseOfDll);
|
||||
break;
|
||||
|
||||
case OUTPUT_DEBUG_STRING_EVENT:
|
||||
|
@ -614,6 +618,24 @@ int DEBUG_main(int argc, char** argv)
|
|||
pid = 0;
|
||||
}
|
||||
}
|
||||
if (argc == 1) {
|
||||
LPSTR org, ptr;
|
||||
|
||||
DEBUG_Printf(DBG_CHN_MESG, "\n");
|
||||
DEBUG_WalkProcess();
|
||||
pid = strtol(org = readline("Enter pid to debug: "), &ptr, 0);
|
||||
if (pid && ptr && ptr != org && *ptr == '\0') {
|
||||
if (!(DEBUG_CurrProcess = DEBUG_AddProcess(pid, 0))) goto leave;
|
||||
|
||||
if (!DebugActiveProcess(pid)) {
|
||||
DEBUG_Printf(DBG_CHN_ERR, "Can't attach process %ld: %ld\n",
|
||||
pid, GetLastError());
|
||||
goto leave;
|
||||
}
|
||||
} else {
|
||||
pid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
PROCESS_INFORMATION info;
|
||||
|
|
Loading…
Reference in New Issue