blob: 0bfb6486208cffb0f9424ab0e3dd80128b011f0e [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);
Zachary Turnerc62733b2015-05-20 18:31:17 +000037 Error DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info);
Zachary Turner3985f892014-11-10 22:32:18 +000038
39 HostProcess
40 GetProcess() const
41 {
42 return m_process;
43 }
44 HostThread
45 GetMainThread() const
46 {
47 return m_main_thread;
48 }
Zachary Turnerfb6c34942014-12-10 23:25:10 +000049 std::weak_ptr<ExceptionRecord>
Zachary Turnerc6a66532014-12-03 22:04:18 +000050 GetActiveException()
51 {
Zachary Turnerfb6c34942014-12-10 23:25:10 +000052 return m_active_exception;
Zachary Turnerc6a66532014-12-03 22:04:18 +000053 }
54
55 Error StopDebugging(bool terminate);
Zachary Turner02862bc2014-11-07 23:44:13 +000056
Zachary Turnerdcd80372014-11-11 00:00:14 +000057 void ContinueAsyncException(ExceptionResult result);
58
Zachary Turner02862bc2014-11-07 23:44:13 +000059 private:
Zachary Turnerc6a66532014-12-03 22:04:18 +000060 void FreeProcessHandles();
Zachary Turner02862bc2014-11-07 23:44:13 +000061 void DebugLoop();
Zachary Turnerdcd80372014-11-11 00:00:14 +000062 ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info, DWORD thread_id);
Zachary Turner02862bc2014-11-07 23:44:13 +000063 DWORD HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info, DWORD thread_id);
64 DWORD HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info, DWORD thread_id);
65 DWORD HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info, DWORD thread_id);
66 DWORD HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info, DWORD thread_id);
67 DWORD HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread_id);
68 DWORD HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info, DWORD thread_id);
69 DWORD HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, DWORD thread_id);
70 DWORD HandleRipEvent(const RIP_INFO &info, DWORD thread_id);
71
72 DebugDelegateSP m_debug_delegate;
73
Zachary Turner02862bc2014-11-07 23:44:13 +000074 HostProcess m_process; // The process being debugged.
75 HostThread m_main_thread; // The main thread of the inferior.
76 HANDLE m_image_file; // The image file of the process being debugged.
77
Zachary Turnerfb6c34942014-12-10 23:25:10 +000078 ExceptionRecordSP m_active_exception; // The current exception waiting to be handled
Zachary Turnerc6a66532014-12-03 22:04:18 +000079
80 Predicate<ExceptionResult> m_exception_pred; // A predicate which gets signalled when an exception
81 // is finished processing and the debug loop can be
82 // continued.
Zachary Turnerdcd80372014-11-11 00:00:14 +000083
Zachary Turnerc62733b2015-05-20 18:31:17 +000084 static lldb::thread_result_t DebuggerThreadLaunchRoutine(void *data);
85 lldb::thread_result_t DebuggerThreadLaunchRoutine(const ProcessLaunchInfo &launch_info);
86 static lldb::thread_result_t DebuggerThreadAttachRoutine(void *data);
87 lldb::thread_result_t DebuggerThreadAttachRoutine(lldb::pid_t pid, const ProcessAttachInfo &launch_info);
Zachary Turner02862bc2014-11-07 23:44:13 +000088};
89}
90
91#endif