[Go to site: main page, start]

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 /// Returns the exception the debug loop is currently reporting, or null if
40 /// there is none. Safe to call from any thread.
42
43 Status StopDebugging(bool terminate);
44
46
47 /// Release a HandleLoadDllEvent / HandleUnloadDllEvent that is parked on
48 /// m_dll_event_pred. The delegate's Resume() path calls this to let the
49 /// debug loop issue ContinueDebugEvent. Mirrors ContinueAsyncException.
51
52private:
53 void FreeProcessHandles();
54 void DebugLoop();
55 ExceptionResult HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info,
56 DWORD thread_id, bool shutting_down);
57 DWORD HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info,
58 DWORD thread_id);
59 DWORD HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info,
60 DWORD thread_id);
61 DWORD HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info,
62 DWORD thread_id);
63 DWORD HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info,
64 DWORD thread_id);
65 DWORD HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info, DWORD thread_id);
66 DWORD HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info,
67 DWORD thread_id);
68 DWORD HandleODSEvent(const OUTPUT_DEBUG_STRING_INFO &info, DWORD thread_id);
69 DWORD HandleRipEvent(const RIP_INFO &info, DWORD thread_id);
70
72
73 HostProcess m_process; // The process being debugged.
74 HostThread m_main_thread; // The main thread of the inferior.
75
76 // The image file of the process being debugged.
78
79 // The current exception waiting to be handled.
82
83 // A predicate which gets signalled when an exception is finished processing
84 // and the debug loop can be continued.
86
87 // Predicate gated by HandleLoadDllEvent / HandleUnloadDllEvent when the
88 // delegate asks them to park.
90
91 // An event which gets signalled by the debugger thread when it exits the
92 // debugger loop and is detached from the inferior.
94
95 // Signals the loop to detach from the process (specified by pid).
96 std::atomic<DWORD> m_pid_to_detach;
97
98 // Signals the debug loop to stop processing certain types of events that
99 // block shutdown.
100 std::atomic<bool> m_is_shutting_down;
101
102 // Indicates we've detached from the inferior process and the debug loop can
103 // exit.
104 bool m_detached = false;
105
110 const ProcessAttachInfo &launch_info);
111};
112} // namespace lldb_private
113#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)
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