blob: a11aede202073cac7a6fb5c49262be0dc74a3d36 [file] [log] [blame]
Zachary Turner02862bc2014-11-07 23:44:13 +00001//===-- DebuggerThread.h ----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_Plugins_Process_Windows_DebuggerThread_H_
11#define liblldb_Plugins_Process_Windows_DebuggerThread_H_
12
Zachary Turnerfb6c34942014-12-10 23:25:10 +000013#include <memory>
14
Zachary Turner02862bc2014-11-07 23:44:13 +000015#include "ForwardDecl.h"
16#include "lldb/Host/HostProcess.h"
17#include "lldb/Host/HostThread.h"
Zachary Turnerdcd80372014-11-11 00:00:14 +000018#include "lldb/Host/Predicate.h"
Zachary Turner02862bc2014-11-07 23:44:13 +000019#include "lldb/Host/windows/windows.h"
20
Zachary Turner02862bc2014-11-07 23:44:13 +000021namespace lldb_private
22{
23
24//----------------------------------------------------------------------
25// DebuggerThread
26//
27// Debugs a single process, notifying listeners as appropriate when interesting
28// things occur.
29//----------------------------------------------------------------------
30class DebuggerThread : public std::enable_shared_from_this<DebuggerThread>
31{
32 public:
33 DebuggerThread(DebugDelegateSP debug_delegate);
34 virtual ~DebuggerThread();
35
Zachary Turner3985f892014-11-10 22:32:18 +000036 Error DebugLaunch(const ProcessLaunchInfo &launch_info);
37
38 HostProcess
39 GetProcess() const
40 {
41 return m_process;
42 }
43 HostThread
44 GetMainThread() const
45 {
46 return m_main_thread;
47 }
Zachary Turnerfb6c34942014-12-10 23:25:10 +000048 std::weak_ptr<ExceptionRecord>
Zachary Turnerc6a66532014-12-03 22:04:18 +000049 GetActiveException()
50 {
Zachary Turnerfb6c34942014-12-10 23:25:10 +000051 return m_active_exception;
Zachary Turnerc6a66532014-12-03 22:04:18 +000052 }
53
54 Error StopDebugging(bool terminate);
Zachary Turner02862bc2014-11-07 23:44:13 +000055
Zachary Turnerdcd80372014-11-11 00:00:14 +000056 void ContinueAsyncException(ExceptionResult result);
57
Zachary Turner02862bc2014-11-07 23:44:13 +000058 private:
Zachary Turnerc6a66532014-12-03 22:04:18 +000059 void FreeProcessHandles();
Zachary Turner02862bc2014-11-07 23:44:13 +000060 void DebugLoop();
Zachary Turnerdcd80372014-11-11 00:00:14 +000061 ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info, DWORD thread_id);
Zachary Turner02862bc2014-11-07 23:44:13 +000062 DWORD HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info, DWORD thread_id);
63 DWORD HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info, DWORD thread_id);
64 DWORD HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info, DWORD thread_id);
65 DWORD HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info, DWORD thread_id);
66 DWORD HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread_id);
67 DWORD HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info, DWORD thread_id);
68 DWORD HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, DWORD thread_id);
69 DWORD HandleRipEvent(const RIP_INFO &info, DWORD thread_id);
70
71 DebugDelegateSP m_debug_delegate;
72
Zachary Turner02862bc2014-11-07 23:44:13 +000073 HostProcess m_process; // The process being debugged.
74 HostThread m_main_thread; // The main thread of the inferior.
75 HANDLE m_image_file; // The image file of the process being debugged.
76
Zachary Turnerfb6c34942014-12-10 23:25:10 +000077 ExceptionRecordSP m_active_exception; // The current exception waiting to be handled
Zachary Turnerc6a66532014-12-03 22:04:18 +000078
79 Predicate<ExceptionResult> m_exception_pred; // A predicate which gets signalled when an exception
80 // is finished processing and the debug loop can be
81 // continued.
Zachary Turnerdcd80372014-11-11 00:00:14 +000082
Zachary Turner02862bc2014-11-07 23:44:13 +000083 static lldb::thread_result_t DebuggerThreadRoutine(void *data);
84 lldb::thread_result_t DebuggerThreadRoutine(const ProcessLaunchInfo &launch_info);
85};
86}
87
88#endif