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 12 #include "Plugins/Process/POSIX/NativeProcessELF.h" 13 #include "lldb/Target/MemoryRegionInfo.h" 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. 28 class NativeProcessNetBSD : public NativeProcessELF { 29 public: 30 class Factory : public NativeProcessProtocol::Factory { 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 56 Status GetMemoryRegionInfo(lldb::addr_t load_addr, 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 65 lldb::addr_t GetSharedLibraryInfoAddress() override; 66 67 size_t UpdateThreads() override; 68 69 const ArchSpec &GetArchitecture() const override { return m_arch; } 70 71 Status SetBreakpoint(lldb::addr_t addr, uint32_t size, 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 private: 92 MainLoop::SignalHandleUP m_sigchld_handle; 93 ArchSpec m_arch; 94 MainLoop& m_main_loop; 95 LazyBool m_supports_mem_region = eLazyBoolCalculate; 96 std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache; 97 98 // Private Instance Methods 99 NativeProcessNetBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate, 100 const ArchSpec &arch, MainLoop &mainloop); 101 102 bool HasThreadNoLock(lldb::tid_t thread_id); 103 104 NativeThreadNetBSD &AddThread(lldb::tid_t thread_id); 105 void RemoveThread(lldb::tid_t thread_id); 106 107 void MonitorCallback(lldb::pid_t pid, int signal); 108 void MonitorExited(lldb::pid_t pid, WaitStatus status); 109 void MonitorSIGSTOP(lldb::pid_t pid); 110 void MonitorSIGTRAP(lldb::pid_t pid); 111 void MonitorSignal(lldb::pid_t pid, int signal); 112 void MonitorClone(::pid_t child_pid, bool is_vfork, 113 NativeThreadNetBSD &parent_thread); 114 115 Status PopulateMemoryRegionCache(); 116 void SigchldHandler(); 117 118 Status Attach(); 119 Status SetupTrace(); 120 Status ReinitializeThreads(); 121 }; 122 123 } // namespace process_netbsd 124 } // namespace lldb_private 125 126 #endif // #ifndef liblldb_NativeProcessNetBSD_H_ 127