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#include <mutex>
15
16#include "ForwardDecl.h"
20#include "lldb/Utility/Locked.h"
22
23namespace lldb_private {
24
25// DebuggerThread
26//
27// Debugs a single process, notifying listeners as appropriate when interesting
28// things occur.
29class DebuggerThread : public std::enable_shared_from_this<DebuggerThread> {
30public:
31 DebuggerThread(DebugDelegateSP debug_delegate);
32 virtual ~DebuggerThread();
33
34 Status DebugLaunch(const ProcessLaunchInfo &launch_info);
35 Status DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info);
36
37 HostProcess GetProcess() const { return *m_process.LockShared(); }
39
40 /// The path the process was created with, as recorded in its process
41 /// parameters, or an empty string if it could not be read. Set by the
42 /// create-process event.
43 const std::string &GetImagePath() const { return m_image_path; }
44
45 /// Returns the exception the debug loop is currently reporting, or null if
46 /// there is none. Safe to call from any thread.
48
49 Status StopDebugging(bool terminate);
50
52
53 /// Release a HandleLoadDllEvent / HandleUnloadDllEvent that is parked on
54 /// m_dll_event_pred. The delegate's Resume() path calls this to let the
55 /// debug loop issue ContinueDebugEvent. Mirrors ContinueAsyncException.
57
58private:
59 /// Have the delegate report the stop it collected, then wait until the
60 /// client resumes before taking the next debug event.
62
63 void FreeProcessHandles();
64 void DebugLoop();
65 ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info,
66 DWORD thread_id, bool shutting_down);
67 DWORD HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info,
68 DWORD thread_id);
69 DWORD HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info,
70 DWORD thread_id);
71 DWORD HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info,
72 DWORD thread_id);
73 DWORD HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info,
74 DWORD thread_id);
75 DWORD HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread_id);
76 DWORD HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info,
77 DWORD thread_id);
78 DWORD HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, DWORD thread_id);
79 DWORD HandleRipEvent(const RIP_INFO &info, DWORD thread_id);
80
82
83 Guarded<HostProcess> m_process; // The process being debugged.
84 HostThread m_main_thread; // The main thread of the inferior.
85
86 // The image file of the process being debugged.
88 std::string m_image_path;
89
90 // The current exception waiting to be handled.
93
94 // A predicate which gets signalled when an exception is finished processing
95 // and the debug loop can be continued.
97
98 // Predicate gated by HandleLoadDllEvent / HandleUnloadDllEvent when the
99 // delegate asks them to park.
101
102 // An event which gets signalled by the debugger thread when it exits the
103 // debugger loop and is detached from the inferior.
105
106 // Signals the loop to detach from the process (specified by pid).
107 std::atomic<DWORD> m_pid_to_detach;
108
109 // Signals the debug loop to stop processing certain types of events that
110 // block shutdown.
111 std::atomic<bool> m_is_shutting_down;
112
113 // Indicates we've detached from the inferior process and the debug loop can
114 // exit.
115 bool m_detached = false;
116
121 const ProcessAttachInfo &launch_info);
122};
123} // namespace lldb_private
124#endif
ExceptionResult
Definition ForwardDecl.h:16
void * HANDLE
std::atomic< bool > m_is_shutting_down
std::atomic< DWORD > m_pid_to_detach
void ContinueAsyncDllEvent()
Release a HandleLoadDllEvent / HandleUnloadDllEvent that is parked on m_dll_event_pred.
Predicate< bool > m_dll_event_pred
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)
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)
DebuggerThread(DebugDelegateSP debug_delegate)
ExceptionRecordSP GetActiveException()
Returns the exception the debug loop is currently reporting, or null if there is none.
void ReportDeferredStopAndWaitForResume()
Have the delegate report the stop it collected, then wait until the client resumes before taking the ...
DWORD HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info, DWORD thread_id)
ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info, DWORD thread_id, bool shutting_down)
Status DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info)
Guarded< HostProcess > m_process
const std::string & GetImagePath() const
The path the process was created with, as recorded in its process parameters, or an empty string if i...
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)
DWORD HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info, DWORD thread_id)
Bundles a value of type T with the Mutex that guards it.
Definition Locked.h:178
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:118
A class that represents a running process on the host machine.
std::shared_ptr< IDebugDelegate > DebugDelegateSP
Definition ForwardDecl.h:45
std::shared_ptr< ExceptionRecord > ExceptionRecordSP
Definition ForwardDecl.h:47
void * thread_result_t
Definition lldb-types.h:62
uint64_t pid_t
Definition lldb-types.h:84