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"
21
22namespace lldb_private {
23
24// DebuggerThread
25//
26// Debugs a single process, notifying listeners as appropriate when interesting
27// things occur.
28class DebuggerThread : public std::enable_shared_from_this<DebuggerThread> {
29public:
30 DebuggerThread(DebugDelegateSP debug_delegate);
31 virtual ~DebuggerThread();
32
33 Status DebugLaunch(const ProcessLaunchInfo &launch_info);
34 Status DebugAttach(lldb::pid_t pid, const ProcessAttachInfo &attach_info);
35
36 HostProcess GetProcess() const { return m_process; }
38
39 /// The path the process was created with, as recorded in its process
40 /// parameters, or an empty string if it could not be read. Set by the
41 /// create-process event.
42 const std::string &GetImagePath() const { return m_image_path; }
43
44 /// Returns the exception the debug loop is currently reporting, or null if
45 /// there is none. Safe to call from any thread.
47
48 Status StopDebugging(bool terminate);
49
51
52 /// Release a HandleLoadDllEvent / HandleUnloadDllEvent that is parked on
53 /// m_dll_event_pred. The delegate's Resume() path calls this to let the
54 /// debug loop issue ContinueDebugEvent. Mirrors ContinueAsyncException.
56
57private:
58 void FreeProcessHandles();
59 void DebugLoop();
60 ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info,
61 DWORD thread_id, bool shutting_down);
62 DWORD HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info,
63 DWORD thread_id);
64 DWORD HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info,
65 DWORD thread_id);
66 DWORD HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info,
67 DWORD thread_id);
68 DWORD HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info,
69 DWORD thread_id);
70 DWORD HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread_id);
71 DWORD HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info,
72 DWORD thread_id);
73 DWORD HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, DWORD thread_id);
74 DWORD HandleRipEvent(const RIP_INFO &info, DWORD thread_id);
75
77
78 HostProcess m_process; // The process being debugged.
79 HostThread m_main_thread; // The main thread of the inferior.
80
81 // The image file of the process being debugged.
83 std::string m_image_path;
84
85 // The current exception waiting to be handled.
88
89 // A predicate which gets signalled when an exception is finished processing
90 // and the debug loop can be continued.
92
93 // Predicate gated by HandleLoadDllEvent / HandleUnloadDllEvent when the
94 // delegate asks them to park.
96
97 // An event which gets signalled by the debugger thread when it exits the
98 // debugger loop and is detached from the inferior.
100
101 // Signals the loop to detach from the process (specified by pid).
102 std::atomic<DWORD> m_pid_to_detach;
103
104 // Signals the debug loop to stop processing certain types of events that
105 // block shutdown.
106 std::atomic<bool> m_is_shutting_down;
107
108 // Indicates we've detached from the inferior process and the debug loop can
109 // exit.
110 bool m_detached = false;
111
116 const ProcessAttachInfo &launch_info);
117};
118} // namespace lldb_private
119#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.
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)
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)
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