blob: 3646d86e5afef21c654cd23c1c485892b079a879 [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
Adrian McCarthya59a7212015-06-19 18:26:53 +000013#include <atomic>
Zachary Turnerfb6c34942014-12-10 23:25:10 +000014#include <memory>
15
Zachary Turner02862bc2014-11-07 23:44:13 +000016#include "ForwardDecl.h"
17#include "lldb/Host/HostProcess.h"
18#include "lldb/Host/HostThread.h"
Zachary Turnerdcd80372014-11-11 00:00:14 +000019#include "lldb/Host/Predicate.h"
Zachary Turner02862bc2014-11-07 23:44:13 +000020#include "lldb/Host/windows/windows.h"
21
Zachary Turner02862bc2014-11-07 23:44:13 +000022namespace lldb_private
23{
24
25//----------------------------------------------------------------------
26// DebuggerThread
27//
28// Debugs a single process, notifying listeners as appropriate when interesting
29// things occur.
30//----------------------------------------------------------------------
31class DebuggerThread : public std::enable_shared_from_this<DebuggerThread>
32{
33 public:
34 DebuggerThread(DebugDelegateSP debug_delegate);
35 virtual ~DebuggerThread();
36
Zachary Turner3985f892014-11-10 22:32:18 +000037 Error DebugLaunch(const ProcessLaunchInfo &launch_info);
Zachary Turnerc62733b2015-05-20 18:31:17 +000038 Error DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info);
Zachary Turner3985f892014-11-10 22:32:18 +000039
40 HostProcess
41 GetProcess() const
42 {
43 return m_process;
44 }
45 HostThread
46 GetMainThread() const
47 {
48 return m_main_thread;
49 }
Zachary Turnerfb6c34942014-12-10 23:25:10 +000050 std::weak_ptr<ExceptionRecord>
Zachary Turnerc6a66532014-12-03 22:04:18 +000051 GetActiveException()
52 {
Zachary Turnerfb6c34942014-12-10 23:25:10 +000053 return m_active_exception;
Zachary Turnerc6a66532014-12-03 22:04:18 +000054 }
55
56 Error StopDebugging(bool terminate);
Zachary Turner02862bc2014-11-07 23:44:13 +000057
Zachary Turnerdcd80372014-11-11 00:00:14 +000058 void ContinueAsyncException(ExceptionResult result);
59
Zachary Turner02862bc2014-11-07 23:44:13 +000060 private:
Zachary Turnerc6a66532014-12-03 22:04:18 +000061 void FreeProcessHandles();
Zachary Turner02862bc2014-11-07 23:44:13 +000062 void DebugLoop();
Zachary Turnerdcd80372014-11-11 00:00:14 +000063 ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info, DWORD thread_id);
Zachary Turner02862bc2014-11-07 23:44:13 +000064 DWORD HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info, DWORD thread_id);
65 DWORD HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info, DWORD thread_id);
66 DWORD HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info, DWORD thread_id);
67 DWORD HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info, DWORD thread_id);
68 DWORD HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread_id);
69 DWORD HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info, DWORD thread_id);
70 DWORD HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, DWORD thread_id);
71 DWORD HandleRipEvent(const RIP_INFO &info, DWORD thread_id);
72
73 DebugDelegateSP m_debug_delegate;
74
Zachary Turner02862bc2014-11-07 23:44:13 +000075 HostProcess m_process; // The process being debugged.
76 HostThread m_main_thread; // The main thread of the inferior.
77 HANDLE m_image_file; // The image file of the process being debugged.
78
Zachary Turnerfb6c34942014-12-10 23:25:10 +000079 ExceptionRecordSP m_active_exception; // The current exception waiting to be handled
Zachary Turnerc6a66532014-12-03 22:04:18 +000080
81 Predicate<ExceptionResult> m_exception_pred; // A predicate which gets signalled when an exception
82 // is finished processing and the debug loop can be
83 // continued.
Zachary Turnerdcd80372014-11-11 00:00:14 +000084
Zachary Turner3c1c5b92015-05-21 19:56:26 +000085 HANDLE m_debugging_ended_event; // An event which gets signalled by the debugger thread when it
86 // exits the debugger loop and is detached from the inferior.
87
Adrian McCarthya59a7212015-06-19 18:26:53 +000088 std::atomic<DWORD> m_pid_to_detach; // Signals the loop to detach from the process (specified by pid).
89 bool m_detached; // Indicates we've detached from the inferior process and the debug loop can exit.
90
Zachary Turnerc62733b2015-05-20 18:31:17 +000091 static lldb::thread_result_t DebuggerThreadLaunchRoutine(void *data);
92 lldb::thread_result_t DebuggerThreadLaunchRoutine(const ProcessLaunchInfo &launch_info);
93 static lldb::thread_result_t DebuggerThreadAttachRoutine(void *data);
94 lldb::thread_result_t DebuggerThreadAttachRoutine(lldb::pid_t pid, const ProcessAttachInfo &launch_info);
Zachary Turner02862bc2014-11-07 23:44:13 +000095};
96}
97
98#endif