LLDB mainline
ProcessDebugger.h
Go to the documentation of this file.
1//===-- ProcessDebugger.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_ProcessDebugger_h_
10#define liblldb_ProcessDebugger_h_
11
13
14#include "lldb/Utility/Status.h"
15#include "lldb/lldb-forward.h"
16#include "lldb/lldb-types.h"
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/Error.h"
20#include "llvm/Support/ErrorExtras.h"
21#include "llvm/Support/Mutex.h"
22
23#include "ForwardDecl.h"
24#include <map>
25#include <set>
26
27namespace lldb_private {
28
29class HostProcess;
30class HostThread;
33
35public:
36 ProcessWindowsData(bool stop_at_entry) : m_stop_at_entry(stop_at_entry) {
37 m_initial_stop_event = ::CreateEvent(nullptr, TRUE, FALSE, nullptr);
38 }
39
41
44 // StopInfoSP m_pending_stop_info;
48 std::map<lldb::tid_t, lldb::ThreadSP> m_new_threads;
49 std::set<lldb::tid_t> m_exited_threads;
50};
51
53
54public:
56
57 virtual void OnExitProcess(uint32_t exit_code);
58 virtual void OnDebuggerConnected(lldb::addr_t image_base);
59 virtual ExceptionResult OnDebugException(bool first_chance,
60 const ExceptionRecord &record);
61 virtual void OnCreateThread(const HostThread &thread);
62 virtual void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code);
63 virtual DllEventAction OnLoadDll(const ModuleSpec &module_spec,
64 lldb::addr_t module_addr,
65 lldb::tid_t thread_id);
66 virtual DllEventAction OnUnloadDll(lldb::addr_t module_addr,
67 lldb::tid_t thread_id);
68 virtual void OnDebugString(lldb::addr_t debug_string_addr, bool is_unicode,
69 uint16_t length_lower_word);
70 virtual void OnDebuggerError(const Status &error, uint32_t type);
71
72 static bool IsSystemDLL(llvm::StringRef path);
73
75
76protected:
78
80 DebugDelegateSP delegate);
81
82 Status AttachProcess(lldb::pid_t pid, const ProcessAttachInfo &attach_info,
83 DebugDelegateSP delegate);
84
86
87 Status HaltProcess(bool &caused_stop);
88
90 MemoryRegionInfo &range_info);
91
92 Status ReadMemory(lldb::addr_t addr, void *buf, size_t size,
93 size_t &bytes_read);
94
95 /// Read an OUTPUT_DEBUG_STRING_INFO payload from the inferior.
96 /// `length_lower_word` is the OS-supplied low 16 bits of the string length;
97 /// the helper walks 64 KiB chunks (up to 1 MiB) until it finds the NUL
98 /// terminator, then strips it. Shared between ProcessWindows (in-process)
99 /// and NativeProcessWindows (lldb-server).
100 llvm::Error ReadDebugString(lldb::addr_t debug_string_addr, bool is_unicode,
101 uint16_t length_lower_word,
103
104 Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
105 size_t &bytes_written);
106
107 Status AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr);
108
110
112
114 HostProcess &process);
115
116protected:
117 llvm::sys::Mutex m_mutex;
118 std::unique_ptr<ProcessWindowsData> m_session_data;
119};
120
121} // namespace lldb_private
122
123#endif // #ifndef liblldb_ProcessDebugger_h_
static llvm::raw_ostream & error(Stream &strm)
ExceptionResult
Definition ForwardDecl.h:16
DllEventAction
Definition ForwardDecl.h:29
void * HANDLE
Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written)
Status DestroyProcess(lldb::StateType process_state)
Status LaunchProcess(ProcessLaunchInfo &launch_info, DebugDelegateSP delegate)
Status WaitForDebuggerConnection(DebuggerThreadSP debugger, HostProcess &process)
virtual DllEventAction OnLoadDll(const ModuleSpec &module_spec, lldb::addr_t module_addr, lldb::tid_t thread_id)
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info)
virtual void OnCreateThread(const HostThread &thread)
virtual void OnDebuggerError(const Status &error, uint32_t type)
virtual void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code)
virtual void OnDebuggerConnected(lldb::addr_t image_base)
std::unique_ptr< ProcessWindowsData > m_session_data
Status AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr)
virtual ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record)
Status AttachProcess(lldb::pid_t pid, const ProcessAttachInfo &attach_info, DebugDelegateSP delegate)
lldb::pid_t GetDebuggedProcessId() const
virtual void OnDebugString(lldb::addr_t debug_string_addr, bool is_unicode, uint16_t length_lower_word)
Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read)
bool IsSystemModuleAddress(lldb::addr_t addr)
virtual void OnExitProcess(uint32_t exit_code)
virtual DllEventAction OnUnloadDll(lldb::addr_t module_addr, lldb::tid_t thread_id)
static bool IsSystemDLL(llvm::StringRef path)
llvm::Error ReadDebugString(lldb::addr_t debug_string_addr, bool is_unicode, uint16_t length_lower_word, llvm::SmallVectorImpl< char > &output)
Read an OUTPUT_DEBUG_STRING_INFO payload from the inferior.
Status HaltProcess(bool &caused_stop)
Status DeallocateMemory(lldb::addr_t addr)
ProcessWindowsData(bool stop_at_entry)
std::map< lldb::tid_t, lldb::ThreadSP > m_new_threads
std::set< lldb::tid_t > m_exited_threads
An error handling class.
Definition Status.h:118
A class that represents a running process on the host machine.
std::shared_ptr< DebuggerThread > DebuggerThreadSP
Definition ForwardDecl.h:46
std::shared_ptr< IDebugDelegate > DebugDelegateSP
Definition ForwardDecl.h:45
StateType
Process and Thread States.
uint64_t pid_t
Definition lldb-types.h:83
uint64_t addr_t
Definition lldb-types.h:80
uint64_t tid_t
Definition lldb-types.h:84