blob: fb536b4cc11ed408a21d265268104bba3ff28cc1 [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
Kate Stoneb9c1b512016-09-06 20:57:50 +000022namespace lldb_private {
Zachary Turner02862bc2014-11-07 23:44:13 +000023
24//----------------------------------------------------------------------
25// DebuggerThread
26//
27// Debugs a single process, notifying listeners as appropriate when interesting
28// things occur.
29//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000030class DebuggerThread : public std::enable_shared_from_this<DebuggerThread> {
31public:
32 DebuggerThread(DebugDelegateSP debug_delegate);
33 virtual ~DebuggerThread();
Zachary Turner02862bc2014-11-07 23:44:13 +000034
Kate Stoneb9c1b512016-09-06 20:57:50 +000035 Error DebugLaunch(const ProcessLaunchInfo &launch_info);
36 Error DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info);
Zachary Turner3985f892014-11-10 22:32:18 +000037
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 HostProcess GetProcess() const { return m_process; }
39 HostThread GetMainThread() const { return m_main_thread; }
40 std::weak_ptr<ExceptionRecord> GetActiveException() {
41 return m_active_exception;
42 }
Zachary Turnerc6a66532014-12-03 22:04:18 +000043
Kate Stoneb9c1b512016-09-06 20:57:50 +000044 Error StopDebugging(bool terminate);
Zachary Turner02862bc2014-11-07 23:44:13 +000045
Kate Stoneb9c1b512016-09-06 20:57:50 +000046 void ContinueAsyncException(ExceptionResult result);
Zachary Turnerdcd80372014-11-11 00:00:14 +000047
Kate Stoneb9c1b512016-09-06 20:57:50 +000048private:
49 void FreeProcessHandles();
50 void DebugLoop();
51 ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info,
52 DWORD thread_id);
53 DWORD HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info,
54 DWORD thread_id);
55 DWORD HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info,
56 DWORD thread_id);
57 DWORD HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info,
58 DWORD thread_id);
59 DWORD HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info,
60 DWORD thread_id);
61 DWORD HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread_id);
62 DWORD HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info,
63 DWORD thread_id);
64 DWORD HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, DWORD thread_id);
65 DWORD HandleRipEvent(const RIP_INFO &info, DWORD thread_id);
Zachary Turner02862bc2014-11-07 23:44:13 +000066
Kate Stoneb9c1b512016-09-06 20:57:50 +000067 DebugDelegateSP m_debug_delegate;
Zachary Turner02862bc2014-11-07 23:44:13 +000068
Kate Stoneb9c1b512016-09-06 20:57:50 +000069 HostProcess m_process; // The process being debugged.
70 HostThread m_main_thread; // The main thread of the inferior.
71 HANDLE m_image_file; // The image file of the process being debugged.
Zachary Turner02862bc2014-11-07 23:44:13 +000072
Kate Stoneb9c1b512016-09-06 20:57:50 +000073 ExceptionRecordSP
74 m_active_exception; // The current exception waiting to be handled
Zachary Turnerc6a66532014-12-03 22:04:18 +000075
Kate Stoneb9c1b512016-09-06 20:57:50 +000076 Predicate<ExceptionResult>
77 m_exception_pred; // A predicate which gets signalled when an exception
78 // is finished processing and the debug loop can be
79 // continued.
Zachary Turnerdcd80372014-11-11 00:00:14 +000080
Kate Stoneb9c1b512016-09-06 20:57:50 +000081 HANDLE m_debugging_ended_event; // An event which gets signalled by the
82 // debugger thread when it
83 // exits the debugger loop and is detached from the inferior.
Zachary Turner3c1c5b92015-05-21 19:56:26 +000084
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 std::atomic<DWORD> m_pid_to_detach; // Signals the loop to detach from the
86 // process (specified by pid).
87 std::atomic<bool> m_is_shutting_down; // Signals the debug loop to stop
88 // processing certain types of
89 // events that block shutdown.
90 bool m_detached; // Indicates we've detached from the inferior process and the
91 // debug loop can exit.
Adrian McCarthya59a7212015-06-19 18:26:53 +000092
Kate Stoneb9c1b512016-09-06 20:57:50 +000093 static lldb::thread_result_t DebuggerThreadLaunchRoutine(void *data);
94 lldb::thread_result_t
95 DebuggerThreadLaunchRoutine(const ProcessLaunchInfo &launch_info);
96 static lldb::thread_result_t DebuggerThreadAttachRoutine(void *data);
97 lldb::thread_result_t
98 DebuggerThreadAttachRoutine(lldb::pid_t pid,
99 const ProcessAttachInfo &launch_info);
Zachary Turner02862bc2014-11-07 23:44:13 +0000100};
101}
102
103#endif