Skip to content

Commit

Permalink
Grab the actual exception by kicking the event,
Browse files Browse the repository at this point in the history
Fix output of version,
fix infinite loops in the stackwalk
  • Loading branch information
learn-more committed Dec 16, 2017
1 parent 1a9c060 commit 1b27cfb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 25 deletions.
40 changes: 30 additions & 10 deletions base/applications/drwtsn32/drwtsn32.cpp
Expand Up @@ -42,12 +42,14 @@ void ThreadData::Update()

DumpData::DumpData()
:ProcessID(0)
,ThreadID(0)
,ProcessHandle(NULL)
,Event(NULL)
,FirstBPHit(false)
{
memset(&ExceptionInfo, 0, sizeof(ExceptionInfo));
}

//static bool g_bIgnoreOnce = true;

bool UpdateFromEvent(DEBUG_EVENT& evt, DumpData& data)
{
Expand Down Expand Up @@ -111,16 +113,34 @@ bool UpdateFromEvent(DEBUG_EVENT& evt, DumpData& data)
case OUTPUT_DEBUG_STRING_EVENT: // ignore
break;
case EXCEPTION_DEBUG_EVENT:
//if (g_bIgnoreOnce)
//{
// g_bIgnoreOnce = false;
// if (evt.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT)
// {
// xfprintf(stdout, "Ignoring initial breakpoint\n");
// return true;
// }
//}
if (evt.u.Exception.dwFirstChance)
{
switch(evt.u.Exception.ExceptionRecord.ExceptionCode)
{
case EXCEPTION_BREAKPOINT:
if (!data.FirstBPHit)
{
data.FirstBPHit = true;

if (data.Event)
{
SetEvent(data.Event);
CloseHandle(data.Event);
data.Event = NULL;
}
return true;
}
break;
case 0x406d1388:
/* Thread name */
return true;
case DBG_CONTROL_C:
case DBG_CONTROL_BREAK:
return true;
}
}
data.ExceptionInfo = evt.u.Exception;
data.ThreadID = evt.dwThreadId;
return false;
case EXIT_PROCESS_DEBUG_EVENT:
//assert(FALSE);
Expand Down
3 changes: 3 additions & 0 deletions base/applications/drwtsn32/drwtsn32.h
Expand Up @@ -39,10 +39,13 @@ class DumpData
std::string ProcessPath;
std::string ProcessName;
DWORD ProcessID;
DWORD ThreadID;
HANDLE ProcessHandle;
ModuleList Modules;
ThreadMap Threads;
EXCEPTION_DEBUG_INFO ExceptionInfo;
HANDLE Event;
bool FirstBPHit;

DumpData();
};
Expand Down
10 changes: 4 additions & 6 deletions base/applications/drwtsn32/main.cpp
Expand Up @@ -120,11 +120,11 @@ int abort(FILE* output, int err)
int main(int argc, char* argv[])
{
DWORD pid = 0;
HANDLE hEvent = 0;
char Buffer[MAX_PATH+55];
char Filename[50];
FILE* output = NULL;
SYSTEMTIME st;
DumpData data;


for (int n = 0; n < argc; ++n)
Expand All @@ -150,7 +150,7 @@ int main(int argc, char* argv[])
{
if (n + 1 < argc)
{
hEvent = (HANDLE)strtoul(argv[n+1], NULL, 10);
data.Event = (HANDLE)strtoul(argv[n+1], NULL, 10);
n++;
}
}
Expand Down Expand Up @@ -209,19 +209,17 @@ int main(int argc, char* argv[])

assert(evt.dwDebugEventCode == CREATE_PROCESS_DEBUG_EVENT);

DumpData data;
while (UpdateFromEvent(evt, data))
{
ContinueDebugEvent(evt.dwProcessId, evt.dwThreadId, DBG_EXCEPTION_HANDLED);
ContinueDebugEvent(evt.dwProcessId, evt.dwThreadId, DBG_CONTINUE);

if (!WaitForDebugEvent(&evt, 30000))
return abort(output, -4);
}

PrintBugreport(output, data);

if (hEvent)
SetEvent(hEvent);
TerminateProcess(data.ProcessHandle, data.ExceptionInfo.ExceptionRecord.ExceptionCode);

return abort(output, 0);
}
12 changes: 6 additions & 6 deletions base/applications/drwtsn32/stacktrace.cpp
Expand Up @@ -65,17 +65,17 @@ void PrintStackBacktrace(FILE* output, DumpData& data, ThreadData& thread)

xfprintf(output, NEWLINE "*----> Stack Back Trace <----*" NEWLINE NEWLINE);
bool first = true;
int max = 200;
ULONG_PTR LastFrame = StackFrame.AddrFrame.Offset - 8;
while(StackWalk64(MachineType, data.ProcessHandle, thread.Handle, &StackFrame, &thread.Context,
NULL, SymFunctionTableAccess64, SymGetModuleBase64, NULL))
{
if (!StackFrame.AddrPC.Offset)
break;

if (max-- < 0)
{
xfprintf(output, "Error, infinite loop, aborting!\n");
}
if (LastFrame >= StackFrame.AddrFrame.Offset)
break;

LastFrame = StackFrame.AddrFrame.Offset;

if (first)
{
Expand All @@ -97,7 +97,7 @@ void PrintStackBacktrace(FILE* output, DumpData& data, ThreadData& thread)
strcpy(sym->Name, "<nosymbols>");

xfprintf(output, "%p %p %p %p %p %p %s!%s" NEWLINE,
(ULONG_PTR)StackFrame.AddrFrame.Offset, (ULONG_PTR)StackFrame.AddrReturn.Offset,
(ULONG_PTR)StackFrame.AddrFrame.Offset, (ULONG_PTR)StackFrame.AddrPC.Offset,
(ULONG_PTR)StackFrame.Params[0], (ULONG_PTR)StackFrame.Params[1],
(ULONG_PTR)StackFrame.Params[2], (ULONG_PTR)StackFrame.Params[3],
Module.ModuleName, sym->Name);
Expand Down
6 changes: 3 additions & 3 deletions base/applications/drwtsn32/sysinfo.cpp
Expand Up @@ -54,7 +54,7 @@ void PrintSystemInfo(FILE* output, DumpData& data)
GetLocalTime(&LocalTime);
xfprintf(output, NEWLINE "ReactOS " KERNEL_VERSION_STR " DrWtsn32" NEWLINE NEWLINE);
xfprintf(output, "Application exception occurred:" NEWLINE);
xfprintf(output, " App: %s (pid=%d)" NEWLINE, data.ProcessName.c_str(), data.ProcessID);
xfprintf(output, " App: %s (pid=%d, tid=0x%x)" NEWLINE, data.ProcessName.c_str(), data.ProcessID, data.ThreadID);
xfprintf(output, " When: %d/%d/%d @ %02d:%02d:%02d.%d" NEWLINE,
LocalTime.wDay, LocalTime.wMonth, LocalTime.wYear,
LocalTime.wHour, LocalTime.wMinute, LocalTime.wSecond, LocalTime.wMilliseconds);
Expand Down Expand Up @@ -98,8 +98,8 @@ void PrintSystemInfo(FILE* output, DumpData& data)
ReadKey(hKey, "ProductName", Buffer, sizeof(Buffer));
ReadKey(hKey, "CurrentVersion", Version, sizeof(Version));
xfprintf(output, " %s Version: %s" NEWLINE, Buffer, Version);
ReadKey(hKey, "CurrentBuild", Buffer, sizeof(Buffer));
xfprintf(output, " Current Build: %s" NEWLINE, Buffer);
ReadKey(hKey, "BuildLab", Buffer, sizeof(Buffer));
xfprintf(output, " BuildLab: %s" NEWLINE, Buffer);
ReadKey(hKey, "CSDVersion", Buffer, sizeof(Buffer));
if (Buffer[0])
xfprintf(output, " Service Pack: %s" NEWLINE, Buffer);
Expand Down

0 comments on commit 1b27cfb

Please sign in to comment.