1 //===-- NativeProcessNetBSD.h --------------------------------- -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_NativeProcessNetBSD_H_
11 #define liblldb_NativeProcessNetBSD_H_
13 #include "lldb/Target/MemoryRegionInfo.h"
14 #include "lldb/Utility/ArchSpec.h"
15 #include "lldb/Utility/FileSpec.h"
17 #include "NativeThreadNetBSD.h"
18 #include "lldb/Host/common/NativeProcessProtocol.h"
20 namespace lldb_private {
21 namespace process_netbsd {
22 /// @class NativeProcessNetBSD
23 /// Manages communication with the inferior (debugee) process.
25 /// Upon construction, this class prepares and launches an inferior process
28 /// Changes in the inferior process state are broadcasted.
29 class NativeProcessNetBSD : public NativeProcessProtocol {
31 class Factory : public NativeProcessProtocol::Factory {
33 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
34 Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
35 MainLoop &mainloop) const override;
37 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
38 Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
39 MainLoop &mainloop) const override;
42 // ---------------------------------------------------------------------
43 // NativeProcessProtocol Interface
44 // ---------------------------------------------------------------------
45 Status Resume(const ResumeActionList &resume_actions) override;
47 Status Halt() override;
49 Status Detach() override;
51 Status Signal(int signo) override;
53 Status Kill() override;
55 Status GetMemoryRegionInfo(lldb::addr_t load_addr,
56 MemoryRegionInfo &range_info) override;
58 Status ReadMemory(lldb::addr_t addr, void *buf, size_t size,
59 size_t &bytes_read) override;
61 Status ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size,
62 size_t &bytes_read) override;
64 Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
65 size_t &bytes_written) override;
67 Status AllocateMemory(size_t size, uint32_t permissions,
68 lldb::addr_t &addr) override;
70 Status DeallocateMemory(lldb::addr_t addr) override;
72 lldb::addr_t GetSharedLibraryInfoAddress() override;
74 size_t UpdateThreads() override;
76 const ArchSpec &GetArchitecture() const override { return m_arch; }
78 Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
79 bool hardware) override;
81 Status GetLoadedModuleFileSpec(const char *module_path,
82 FileSpec &file_spec) override;
84 Status GetFileLoadAddress(const llvm::StringRef &file_name,
85 lldb::addr_t &load_addr) override;
87 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
88 GetAuxvData() const override;
90 // ---------------------------------------------------------------------
91 // Interface used by NativeRegisterContext-derived classes.
92 // ---------------------------------------------------------------------
93 static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
94 int data = 0, int *result = nullptr);
97 // ---------------------------------------------------------------------
98 // NativeProcessProtocol protected interface
99 // ---------------------------------------------------------------------
102 GetSoftwareBreakpointTrapOpcode(size_t trap_opcode_size_hint,
103 size_t &actual_opcode_size,
104 const uint8_t *&trap_opcode_bytes) override;
107 MainLoop::SignalHandleUP m_sigchld_handle;
109 LazyBool m_supports_mem_region = eLazyBoolCalculate;
110 std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
112 // ---------------------------------------------------------------------
113 // Private Instance Methods
114 // ---------------------------------------------------------------------
115 NativeProcessNetBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
116 const ArchSpec &arch, MainLoop &mainloop);
118 bool HasThreadNoLock(lldb::tid_t thread_id);
120 NativeThreadNetBSD &AddThread(lldb::tid_t thread_id);
122 void MonitorCallback(lldb::pid_t pid, int signal);
123 void MonitorExited(lldb::pid_t pid, WaitStatus status);
124 void MonitorSIGSTOP(lldb::pid_t pid);
125 void MonitorSIGTRAP(lldb::pid_t pid);
126 void MonitorSignal(lldb::pid_t pid, int signal);
128 Status GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size);
129 Status FixupBreakpointPCAsNeeded(NativeThreadNetBSD &thread);
130 Status PopulateMemoryRegionCache();
131 void SigchldHandler();
134 Status ReinitializeThreads();
137 } // namespace process_netbsd
138 } // namespace lldb_private
140 #endif // #ifndef liblldb_NativeProcessNetBSD_H_