LLDB  mainline
NativeProcessNetBSD.h
Go to the documentation of this file.
1 //===-- NativeProcessNetBSD.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_NativeProcessNetBSD_H_
10 #define liblldb_NativeProcessNetBSD_H_
11 
14 #include "lldb/Utility/ArchSpec.h"
15 #include "lldb/Utility/FileSpec.h"
16 
17 #include "NativeThreadNetBSD.h"
18 
19 namespace lldb_private {
20 namespace process_netbsd {
21 /// \class NativeProcessNetBSD
22 /// Manages communication with the inferior (debugee) process.
23 ///
24 /// Upon construction, this class prepares and launches an inferior process
25 /// for debugging.
26 ///
27 /// Changes in the inferior process state are broadcasted.
29 public:
31  public:
32  llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
33  Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
34  MainLoop &mainloop) const override;
35 
36  llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
37  Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
38  MainLoop &mainloop) const override;
39 
40  Extension GetSupportedExtensions() const override;
41  };
42 
43  // NativeProcessProtocol Interface
44  Status Resume(const ResumeActionList &resume_actions) override;
45 
46  Status Halt() override;
47 
48  Status Detach() override;
49 
50  Status Signal(int signo) override;
51 
52  Status Interrupt() override;
53 
54  Status Kill() override;
55 
57  MemoryRegionInfo &range_info) override;
58 
59  Status ReadMemory(lldb::addr_t addr, void *buf, size_t size,
60  size_t &bytes_read) override;
61 
62  Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
63  size_t &bytes_written) override;
64 
66 
67  size_t UpdateThreads() override;
68 
69  const ArchSpec &GetArchitecture() const override { return m_arch; }
70 
72  bool hardware) override;
73 
74  // The two following methods are probably not necessary and probably
75  // will never be called. Nevertheless, we implement them right now
76  // to reduce the differences between different platforms and reduce
77  // the risk of the lack of implementation actually breaking something,
78  // at least for the time being.
79  Status GetLoadedModuleFileSpec(const char *module_path,
80  FileSpec &file_spec) override;
81  Status GetFileLoadAddress(const llvm::StringRef &file_name,
82  lldb::addr_t &load_addr) override;
83 
84  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
85  GetAuxvData() const override;
86 
87  // Interface used by NativeRegisterContext-derived classes.
88  static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
89  int data = 0, int *result = nullptr);
90 
91  llvm::Expected<std::string> SaveCore(llvm::StringRef path_hint) override;
92 
93 private:
98  std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
99 
100  // Private Instance Methods
101  NativeProcessNetBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
102  const ArchSpec &arch, MainLoop &mainloop);
103 
104  bool HasThreadNoLock(lldb::tid_t thread_id);
105 
107  void RemoveThread(lldb::tid_t thread_id);
108 
109  void MonitorCallback(lldb::pid_t pid, int signal);
110  void MonitorExited(lldb::pid_t pid, WaitStatus status);
111  void MonitorSIGSTOP(lldb::pid_t pid);
112  void MonitorSIGTRAP(lldb::pid_t pid);
113  void MonitorSignal(lldb::pid_t pid, int signal);
114  void MonitorClone(::pid_t child_pid, bool is_vfork,
115  NativeThreadNetBSD &parent_thread);
116 
118  void SigchldHandler();
119 
120  Status Attach();
121  Status SetupTrace();
123 };
124 
125 } // namespace process_netbsd
126 } // namespace lldb_private
127 
128 #endif // #ifndef liblldb_NativeProcessNetBSD_H_
lldb_private::NativeProcessProtocol::NativeDelegate
Definition: NativeProcessProtocol.h:221
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::process_netbsd::NativeProcessNetBSD::GetAuxvData
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > GetAuxvData() const override
Definition: NativeProcessNetBSD.cpp:937
lldb_private::process_netbsd::NativeProcessNetBSD::MonitorExited
void MonitorExited(lldb::pid_t pid, WaitStatus status)
Definition: NativeProcessNetBSD.cpp:174
lldb_private::process_netbsd::NativeProcessNetBSD::GetSharedLibraryInfoAddress
lldb::addr_t GetSharedLibraryInfoAddress() override
Definition: NativeProcessNetBSD.cpp:722
lldb_private::process_netbsd::NativeProcessNetBSD::GetLoadedModuleFileSpec
Status GetLoadedModuleFileSpec(const char *module_path, FileSpec &file_spec) override
Definition: NativeProcessNetBSD.cpp:737
lldb_private::process_netbsd::NativeProcessNetBSD::SetupTrace
Status SetupTrace()
Definition: NativeProcessNetBSD.cpp:967
lldb_private::MemoryRegionInfo
Definition: MemoryRegionInfo.h:21
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::LazyBool
LazyBool
Definition: lldb-private-enumerations.h:115
lldb_private::process_netbsd::NativeProcessNetBSD
Definition: NativeProcessNetBSD.h:28
lldb_private::process_netbsd::NativeProcessNetBSD::SaveCore
llvm::Expected< std::string > SaveCore(llvm::StringRef path_hint) override
Write a core dump (without crashing the program).
Definition: NativeProcessNetBSD.cpp:1079
lldb_private::WaitStatus
Definition: Host.h:34
lldb_private::process_netbsd::NativeProcessNetBSD::Kill
Status Kill() override
Definition: NativeProcessNetBSD.cpp:564
lldb_private::process_netbsd::NativeProcessNetBSD::m_supports_mem_region
LazyBool m_supports_mem_region
Definition: NativeProcessNetBSD.h:97
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::process_netbsd::NativeProcessNetBSD::AddThread
NativeThreadNetBSD & AddThread(lldb::tid_t thread_id)
Definition: NativeProcessNetBSD.cpp:819
lldb_private::process_netbsd::NativeProcessNetBSD::m_main_loop
MainLoop & m_main_loop
Definition: NativeProcessNetBSD.h:96
lldb_private::process_netbsd::NativeProcessNetBSD::NativeProcessNetBSD
NativeProcessNetBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate, const ArchSpec &arch, MainLoop &mainloop)
Definition: NativeProcessNetBSD.cpp:145
lldb_private::process_netbsd::NativeProcessNetBSD::Resume
Status Resume(const ResumeActionList &resume_actions) override
Definition: NativeProcessNetBSD.cpp:461
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
MemoryRegionInfo.h
lldb_private::process_netbsd::NativeProcessNetBSD::RemoveThread
void RemoveThread(lldb::tid_t thread_id)
Definition: NativeProcessNetBSD.cpp:835
NativeThreadNetBSD.h
lldb_private::process_netbsd::NativeProcessNetBSD::Attach
Status Attach()
Definition: NativeProcessNetBSD.cpp:851
lldb_private::process_netbsd::NativeProcessNetBSD::m_arch
ArchSpec m_arch
Definition: NativeProcessNetBSD.h:95
NativeProcessELF.h
lldb_private::process_netbsd::NativeProcessNetBSD::MonitorSignal
void MonitorSignal(lldb::pid_t pid, int signal)
Definition: NativeProcessNetBSD.cpp:361
lldb_private::process_netbsd::NativeProcessNetBSD::PopulateMemoryRegionCache
Status PopulateMemoryRegionCache()
Definition: NativeProcessNetBSD.cpp:656
lldb_private::process_netbsd::NativeProcessNetBSD::GetMemoryRegionInfo
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info) override
Definition: NativeProcessNetBSD.cpp:600
lldb_private::process_netbsd::NativeProcessNetBSD::Factory
Definition: NativeProcessNetBSD.h:30
lldb_private::process_netbsd::NativeProcessNetBSD::SigchldHandler
void SigchldHandler()
Definition: NativeProcessNetBSD.cpp:774
lldb_private::process_netbsd::NativeProcessNetBSD::Detach
Status Detach() override
Definition: NativeProcessNetBSD.cpp:538
lldb_private::process_netbsd::NativeProcessNetBSD::GetArchitecture
const ArchSpec & GetArchitecture() const override
Definition: NativeProcessNetBSD.h:69
lldb_private::process_netbsd::NativeThreadNetBSD
Definition: NativeThreadNetBSD.h:25
lldb_private::NativeProcessProtocol::Extension
Extension
Extension flag constants, returned by Factory::GetSupportedExtensions() and passed to SetEnabledExten...
Definition: NativeProcessProtocol.h:245
lldb_private::process_netbsd::NativeProcessNetBSD::m_sigchld_handle
MainLoop::SignalHandleUP m_sigchld_handle
Definition: NativeProcessNetBSD.h:94
lldb_private::Status
Definition: Status.h:44
lldb_private::process_netbsd::NativeProcessNetBSD::SetBreakpoint
Status SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override
Definition: NativeProcessNetBSD.cpp:729
lldb_private::process_netbsd::NativeProcessNetBSD::HasThreadNoLock
bool HasThreadNoLock(lldb::tid_t thread_id)
Definition: NativeProcessNetBSD.cpp:806
uint32_t
lldb_private::MainLoop
Definition: MainLoop.h:38
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb_private::MainLoop::SignalHandleUP
std::unique_ptr< SignalHandle > SignalHandleUP
Definition: MainLoop.h:40
ArchSpec.h
lldb_private::process_netbsd::NativeProcessNetBSD::UpdateThreads
size_t UpdateThreads() override
Definition: NativeProcessNetBSD.cpp:727
lldb_private::process_netbsd::NativeProcessNetBSD::Interrupt
Status Interrupt() override
Tells a process to interrupt all operations as if by a Ctrl-C.
Definition: NativeProcessNetBSD.cpp:560
lldb_private::process_netbsd::NativeProcessNetBSD::Factory::Attach
llvm::Expected< std::unique_ptr< NativeProcessProtocol > > Attach(lldb::pid_t pid, NativeDelegate &native_delegate, MainLoop &mainloop) const override
Attach to an existing process.
Definition: NativeProcessNetBSD.cpp:113
lldb_private::process_netbsd::NativeProcessNetBSD::MonitorSIGTRAP
void MonitorSIGTRAP(lldb::pid_t pid)
Definition: NativeProcessNetBSD.cpp:209
lldb_private::process_netbsd::NativeProcessNetBSD::ReadMemory
Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override
Definition: NativeProcessNetBSD.cpp:880
lldb_private::process_netbsd::NativeProcessNetBSD::ReinitializeThreads
Status ReinitializeThreads()
Definition: NativeProcessNetBSD.cpp:984
lldb_private::process_netbsd::NativeProcessNetBSD::PtraceWrapper
static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr=nullptr, int data=0, int *result=nullptr)
Definition: NativeProcessNetBSD.cpp:384
lldb_private::process_netbsd::NativeProcessNetBSD::GetFileLoadAddress
Status GetFileLoadAddress(const llvm::StringRef &file_name, lldb::addr_t &load_addr) override
Definition: NativeProcessNetBSD.cpp:757
lldb_private::ResumeActionList
Definition: Debug.h:33
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::NativeProcessELF
Definition: NativeProcessELF.h:21
lldb_private::eLazyBoolCalculate
@ eLazyBoolCalculate
Definition: lldb-private-enumerations.h:115
lldb_private::process_netbsd::NativeProcessNetBSD::MonitorCallback
void MonitorCallback(lldb::pid_t pid, int signal)
Definition: NativeProcessNetBSD.cpp:163
FileSpec.h
lldb_private::process_netbsd::NativeProcessNetBSD::MonitorSIGSTOP
void MonitorSIGSTOP(lldb::pid_t pid)
Definition: NativeProcessNetBSD.cpp:188
lldb_private::process_netbsd::NativeProcessNetBSD::MonitorClone
void MonitorClone(::pid_t child_pid, bool is_vfork, NativeThreadNetBSD &parent_thread)
Definition: NativeProcessNetBSD.cpp:1014
lldb_private::process_netbsd::NativeProcessNetBSD::Signal
Status Signal(int signo) override
Sends a process a UNIX signal signal.
Definition: NativeProcessNetBSD.cpp:551
lldb_private::process_netbsd::NativeProcessNetBSD::Factory::Launch
llvm::Expected< std::unique_ptr< NativeProcessProtocol > > Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate, MainLoop &mainloop) const override
Launch a process for debugging.
Definition: NativeProcessNetBSD.cpp:59
lldb_private::process_netbsd::NativeProcessNetBSD::WriteMemory
Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override
Definition: NativeProcessNetBSD.cpp:907
lldb_private::NativeProcessProtocol::Factory
Definition: NativeProcessProtocol.h:258
lldb_private::process_netbsd::NativeProcessNetBSD::Factory::GetSupportedExtensions
Extension GetSupportedExtensions() const override
Get the bitmask of extensions supported by this process plugin.
Definition: NativeProcessNetBSD.cpp:137
lldb_private::process_netbsd::NativeProcessNetBSD::m_mem_region_cache
std::vector< std::pair< MemoryRegionInfo, FileSpec > > m_mem_region_cache
Definition: NativeProcessNetBSD.h:98
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
lldb_private::process_netbsd::NativeProcessNetBSD::Halt
Status Halt() override
Definition: NativeProcessNetBSD.cpp:536