ReactOS 0.4.16-dev-334-g4d9f67c
drwtsn32.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: Dr. Watson crash reporter
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Debug loop
5 * COPYRIGHT: Copyright 2017 Mark Jansen <mark.jansen@reactos.org>
6 */
7
8#include "precomp.h"
9#include <psapi.h>
10
11#define MS_VC_EXCEPTION_THREAD_NAME 0x406d1388
12
14{
16 Size = 0;
17 Unloaded = false;
18}
19
21{
22 MODULEINFO mi = {0};
24 assert(BaseAddress == mi.lpBaseOfDll);
25 Size = mi.SizeOfImage;
26
27 ModuleName.resize(MAX_PATH);
29 ModuleName.resize(dwLen);
30}
31
32
34 : Handle(handle)
35{
36 memset(&Context, 0, sizeof(Context));
37}
38
40{
43}
44
46 :ProcessID(0)
47 ,ThreadID(0)
49 ,Event(NULL)
50 ,FirstBPHit(false)
51{
53}
54
55
57{
58 switch(evt.dwDebugEventCode)
59 {
61 {
62 data.ProcessPath.resize(MAX_PATH*2);
63 DWORD len = GetModuleFileNameExW(evt.u.CreateProcessInfo.hProcess, NULL, &data.ProcessPath[0], data.ProcessPath.size());
64 if (len)
65 {
66 data.ProcessPath.resize(len);
67 std::string::size_type pos = data.ProcessPath.find_last_of(L"\\/");
68 if (pos != std::string::npos)
69 data.ProcessName = data.ProcessPath.substr(pos+1);
70 }
71 else
72 {
73 data.ProcessPath = L"??";
74 }
75 if (data.ProcessName.empty())
76 data.ProcessName = data.ProcessPath;
77
79 data.ProcessID = evt.dwProcessId;
80 data.ProcessHandle = evt.u.CreateProcessInfo.hProcess;
82 }
83 break;
85 data.Threads[evt.dwThreadId] = ThreadData(evt.u.CreateThread.hThread);
86 break;
88 {
89 ThreadMap::iterator it = data.Threads.find(evt.dwThreadId);
90 if (it != data.Threads.end())
91 {
92 data.Threads.erase(it);
93 }
94 }
95 break;
98 for (size_t n = 0; n < data.Modules.size(); ++n)
99 {
100 if (data.Modules[n].BaseAddress == evt.u.LoadDll.lpBaseOfDll)
101 {
102 data.Modules[n].Unloaded = false;
103 return true;
104 }
105 }
106 data.Modules.push_back(ModuleData(evt.u.LoadDll.lpBaseOfDll));
107 break;
109 for (size_t n = 0; n < data.Modules.size(); ++n)
110 {
111 if (data.Modules[n].BaseAddress == evt.u.UnloadDll.lpBaseOfDll)
112 data.Modules[n].Unloaded = true;
113 }
114 break;
115 case OUTPUT_DEBUG_STRING_EVENT: // ignore
116 break;
118 if (evt.u.Exception.dwFirstChance)
119 {
121 {
123 if (!data.FirstBPHit)
124 {
125 data.FirstBPHit = true;
126
127 if (data.Event)
128 {
129 SetEvent(data.Event);
130 CloseHandle(data.Event);
131 data.Event = NULL;
132 }
133 return true;
134 }
135 break;
137 /* Thread name */
138 return true;
139 case DBG_CONTROL_C:
141 return true;
142 }
143 }
144 data.ExceptionInfo = evt.u.Exception;
145 data.ThreadID = evt.dwThreadId;
146 return false;
148 //assert(FALSE);
149 return false;
150 case RIP_EVENT:
151 //assert(FALSE);
152 return false;
153 default:
154 assert(false);
155 }
156 return true;
157}
158
EXCEPTION_DEBUG_INFO ExceptionInfo
Definition: drwtsn32.h:46
DumpData()
Definition: drwtsn32.cpp:45
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define GetModuleFileNameExW(w, x, y, z)
Definition: compat.h:922
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI GetThreadContext(IN HANDLE hThread, OUT LPCONTEXT lpContext)
Definition: thread.c:501
DWORD WINAPI GetModuleFileNameExA(HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, DWORD nSize)
Definition: psapi.c:972
BOOL WINAPI GetModuleInformation(HANDLE hProcess, HMODULE hModule, LPMODULEINFO lpmodinfo, DWORD cb)
Definition: psapi.c:1064
#define assert(x)
Definition: debug.h:53
#define MS_VC_EXCEPTION_THREAD_NAME
Definition: drwtsn32.cpp:11
bool UpdateFromEvent(DEBUG_EVENT &evt, DumpData &data)
Definition: drwtsn32.cpp:56
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG Handle
Definition: gdb_input.c:15
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble n
Definition: glext.h:7729
GLenum const GLvoid * addr
Definition: glext.h:9621
GLenum GLsizei len
Definition: glext.h:6722
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
#define CONTEXT_DEBUG_REGISTERS
Definition: nt_native.h:1373
#define CONTEXT_CONTROL
Definition: nt_native.h:1369
#define CONTEXT_INTEGER
Definition: nt_native.h:1370
#define DBG_CONTROL_BREAK
Definition: ntstatus.h:55
#define DBG_CONTROL_C
Definition: ntstatus.h:52
#define L(x)
Definition: ntvdm.h:50
#define memset(x, y, z)
Definition: compat.h:39
#define false
Definition: stdbool.h:37
void Update(HANDLE hProcess)
Definition: drwtsn32.cpp:20
bool Unloaded
Definition: drwtsn32.h:16
std::string ModuleName
Definition: drwtsn32.h:13
void * BaseAddress
Definition: drwtsn32.h:14
ModuleData(void *addr)
Definition: drwtsn32.cpp:13
ThreadData(HANDLE handle=NULL)
Definition: drwtsn32.cpp:33
HANDLE Handle
Definition: drwtsn32.h:25
void Update()
Definition: drwtsn32.cpp:39
UNLOAD_DLL_DEBUG_INFO UnloadDll
Definition: winbase.h:823
union _DEBUG_EVENT::@3274 u
DWORD dwDebugEventCode
Definition: winbase.h:813
DWORD dwThreadId
Definition: winbase.h:815
DWORD dwProcessId
Definition: winbase.h:814
LOAD_DLL_DEBUG_INFO LoadDll
Definition: winbase.h:822
EXCEPTION_DEBUG_INFO Exception
Definition: winbase.h:817
CREATE_PROCESS_DEBUG_INFO CreateProcessInfo
Definition: winbase.h:819
CREATE_THREAD_DEBUG_INFO CreateThread
Definition: winbase.h:818
EXCEPTION_RECORD ExceptionRecord
Definition: winbase.h:776
DWORD ExceptionCode
Definition: compat.h:208
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
static MONITORINFO mi
Definition: win.c:7338
#define RIP_EVENT
Definition: winbase.h:111
#define CREATE_PROCESS_DEBUG_EVENT
Definition: winbase.h:105
#define LOAD_DLL_DEBUG_EVENT
Definition: winbase.h:108
#define EXIT_PROCESS_DEBUG_EVENT
Definition: winbase.h:107
#define OUTPUT_DEBUG_STRING_EVENT
Definition: winbase.h:110
#define EXCEPTION_DEBUG_EVENT
Definition: winbase.h:103
#define CREATE_THREAD_DEBUG_EVENT
Definition: winbase.h:104
#define UNLOAD_DLL_DEBUG_EVENT
Definition: winbase.h:109
#define EXCEPTION_BREAKPOINT
Definition: winbase.h:339
#define EXIT_THREAD_DEBUG_EVENT
Definition: winbase.h:106