1 //===-- NativeProcessNetBSD.h --------------------------------- -*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_NativeProcessNetBSD_H_
10 #define liblldb_NativeProcessNetBSD_H_
12 #include "lldb/Target/MemoryRegionInfo.h"
13 #include "lldb/Utility/ArchSpec.h"
14 #include "lldb/Utility/FileSpec.h"
16 #include "NativeThreadNetBSD.h"
17 #include "lldb/Host/common/NativeProcessProtocol.h"
19 namespace lldb_private {
20 namespace process_netbsd {
21 /// \class NativeProcessNetBSD
22 /// Manages communication with the inferior (debugee) process.
24 /// Upon construction, this class prepares and launches an inferior process
27 /// Changes in the inferior process state are broadcasted.
28 class NativeProcessNetBSD : public NativeProcessProtocol {
30 class Factory : public NativeProcessProtocol::Factory {
32 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
33 Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
34 MainLoop &mainloop) const override;
36 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
37 Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
38 MainLoop &mainloop) const override;
41 // NativeProcessProtocol Interface
42 Status Resume(const ResumeActionList &resume_actions) override;
44 Status Halt() override;
46 Status Detach() override;
48 Status Signal(int signo) override;
50 Status Kill() override;
52 Status GetMemoryRegionInfo(lldb::addr_t load_addr,
53 MemoryRegionInfo &range_info) override;
55 Status ReadMemory(lldb::addr_t addr, void *buf, size_t size,
56 size_t &bytes_read) override;
58 Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
59 size_t &bytes_written) override;
61 Status AllocateMemory(size_t size, uint32_t permissions,
62 lldb::addr_t &addr) override;
64 Status DeallocateMemory(lldb::addr_t addr) override;
66 lldb::addr_t GetSharedLibraryInfoAddress() override;
68 size_t UpdateThreads() override;
70 const ArchSpec &GetArchitecture() const override { return m_arch; }
72 Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
73 bool hardware) override;
75 Status GetLoadedModuleFileSpec(const char *module_path,
76 FileSpec &file_spec) override;
78 Status GetFileLoadAddress(const llvm::StringRef &file_name,
79 lldb::addr_t &load_addr) override;
81 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
82 GetAuxvData() const override;
84 // Interface used by NativeRegisterContext-derived classes.
85 static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
86 int data = 0, int *result = nullptr);
89 MainLoop::SignalHandleUP m_sigchld_handle;
91 LazyBool m_supports_mem_region = eLazyBoolCalculate;
92 std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
94 // Private Instance Methods
95 NativeProcessNetBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
96 const ArchSpec &arch, MainLoop &mainloop);
98 bool HasThreadNoLock(lldb::tid_t thread_id);
100 NativeThreadNetBSD &AddThread(lldb::tid_t thread_id);
102 void MonitorCallback(lldb::pid_t pid, int signal);
103 void MonitorExited(lldb::pid_t pid, WaitStatus status);
104 void MonitorSIGSTOP(lldb::pid_t pid);
105 void MonitorSIGTRAP(lldb::pid_t pid);
106 void MonitorSignal(lldb::pid_t pid, int signal);
108 Status PopulateMemoryRegionCache();
109 void SigchldHandler();
112 Status ReinitializeThreads();
115 } // namespace process_netbsd
116 } // namespace lldb_private
118 #endif // #ifndef liblldb_NativeProcessNetBSD_H_