LLDB mainline
DebuggerThread.h
Go to the documentation of this file.
1//===-- DebuggerThread.h ----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef liblldb_Plugins_Process_Windows_DebuggerThread_H_
10#define liblldb_Plugins_Process_Windows_DebuggerThread_H_
11
12#include <atomic>
13#include <memory>
14
15#include "ForwardDecl.h"
20
21namespace lldb_private {
22
23// DebuggerThread
24//
25// Debugs a single process, notifying listeners as appropriate when interesting
26// things occur.
27class DebuggerThread : public std::enable_shared_from_this<DebuggerThread> {
28public:
29 DebuggerThread(DebugDelegateSP debug_delegate);
30 virtual ~DebuggerThread();
31
32 Status DebugLaunch(const ProcessLaunchInfo &launch_info);
33 Status DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info);
34
35 HostProcess GetProcess() const { return m_process; }
37 std::weak_ptr<ExceptionRecord> GetActiveException() {
38 return m_active_exception;
39 }
40
41 Status StopDebugging(bool terminate);
42
44
45private:
46 void FreeProcessHandles();
47 void DebugLoop();
48 ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info,
49 DWORD thread_id);
50 DWORD HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info,
51 DWORD thread_id);
52 DWORD HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info,
53 DWORD thread_id);
54 DWORD HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info,
55 DWORD thread_id);
56 DWORD HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info,
57 DWORD thread_id);
58 DWORD HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread_id);
59 DWORD HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info,
60 DWORD thread_id);
61 DWORD HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, DWORD thread_id);
62 DWORD HandleRipEvent(const RIP_INFO &info, DWORD thread_id);
63
65
66 HostProcess m_process; // The process being debugged.
67 HostThread m_main_thread; // The main thread of the inferior.
68
69 // The image file of the process being debugged.
70 HANDLE m_image_file = nullptr;
71
72 // The current exception waiting to be handled
74
75 // A predicate which gets signalled when an exception is finished processing
76 // and the debug loop can be continued.
78
79 // An event which gets signalled by the debugger thread when it exits the
80 // debugger loop and is detached from the inferior.
81 HANDLE m_debugging_ended_event = nullptr;
82
83 // Signals the loop to detach from the process (specified by pid).
84 std::atomic<DWORD> m_pid_to_detach;
85
86 // Signals the debug loop to stop processing certain types of events that
87 // block shutdown.
88 std::atomic<bool> m_is_shutting_down;
89
90 // Indicates we've detached from the inferior process and the debug loop can
91 // exit.
92 bool m_detached = false;
93
98 const ProcessAttachInfo &launch_info);
99};
100}
101#endif
ExceptionResult
Definition: ForwardDecl.h:16
std::atomic< bool > m_is_shutting_down
std::atomic< DWORD > m_pid_to_detach
DWORD HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info, DWORD thread_id)
DWORD HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, DWORD thread_id)
DWORD HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread_id)
ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info, DWORD thread_id)
DWORD HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info, DWORD thread_id)
Status StopDebugging(bool terminate)
DWORD HandleRipEvent(const RIP_INFO &info, DWORD thread_id)
void ContinueAsyncException(ExceptionResult result)
HostProcess GetProcess() const
lldb::thread_result_t DebuggerThreadAttachRoutine(lldb::pid_t pid, const ProcessAttachInfo &launch_info)
DWORD HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info, DWORD thread_id)
std::weak_ptr< ExceptionRecord > GetActiveException()
Status DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info)
lldb::thread_result_t DebuggerThreadLaunchRoutine(const ProcessLaunchInfo &launch_info)
ExceptionRecordSP m_active_exception
Predicate< ExceptionResult > m_exception_pred
Status DebugLaunch(const ProcessLaunchInfo &launch_info)
HostThread GetMainThread() const
DWORD HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info, DWORD thread_id)
DebugDelegateSP m_debug_delegate
DWORD HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info, DWORD thread_id)
A C++ wrapper class for providing threaded access to a value of type T.
Definition: Predicate.h:42
An error handling class.
Definition: Status.h:44
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
std::shared_ptr< ExceptionRecord > ExceptionRecordSP
Definition: ForwardDecl.h:37
std::shared_ptr< IDebugDelegate > DebugDelegateSP
Definition: ForwardDecl.h:35
void * thread_result_t
Definition: lldb-types.h:62
uint64_t pid_t
Definition: lldb-types.h:81