1 //===-- NativeProcessOpenBSD.h --------------------------------- -*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_NativeProcessOpenBSD_H_ 11 #define liblldb_NativeProcessOpenBSD_H_ 12 13 #include "lldb/Target/MemoryRegionInfo.h" 14 #include "lldb/Utility/ArchSpec.h" 15 #include "lldb/Utility/FileSpec.h" 16 17 #include "NativeThreadOpenBSD.h" 18 #include "lldb/Host/common/NativeProcessProtocol.h" 19 20 namespace lldb_private { 21 namespace process_openbsd { 22 /// @class NativeProcessOpenBSD 23 /// Manages communication with the inferior (debugee) process. 24 /// 25 /// Upon construction, this class prepares and launches an inferior process 26 /// for debugging. 27 /// 28 /// Changes in the inferior process state are broadcasted. 29 class NativeProcessOpenBSD : public NativeProcessProtocol { 30 public: 31 class Factory : public NativeProcessProtocol::Factory { 32 public: 33 llvm::Expected<std::unique_ptr<NativeProcessProtocol>> 34 Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate, 35 MainLoop &mainloop) const override; 36 37 llvm::Expected<std::unique_ptr<NativeProcessProtocol>> 38 Attach(lldb::pid_t pid, NativeDelegate &native_delegate, 39 MainLoop &mainloop) const override; 40 41 Extension GetSupportedExtensions() const override; 42 }; 43 44 // --------------------------------------------------------------------- 45 // NativeProcessProtocol Interface 46 // --------------------------------------------------------------------- 47 Status Resume(const ResumeActionList &resume_actions) override; 48 49 Status Halt() override; 50 51 Status Detach() override; 52 53 Status Signal(int signo) override; 54 55 Status Kill() override; 56 57 Status GetMemoryRegionInfo(lldb::addr_t load_addr, 58 MemoryRegionInfo &range_info) override; 59 60 Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, 61 size_t &bytes_read) override; 62 63 Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, 64 size_t &bytes_written) override; 65 66 llvm::Expected<lldb::addr_t> AllocateMemory(size_t size, uint32_t permissions) override; 67 68 llvm::Error DeallocateMemory(lldb::addr_t addr) override; 69 70 lldb::addr_t GetSharedLibraryInfoAddress() override; 71 72 size_t UpdateThreads() override; 73 GetArchitecture()74 const ArchSpec &GetArchitecture() const override { return m_arch; } 75 76 Status SetBreakpoint(lldb::addr_t addr, uint32_t size, 77 bool hardware) override; 78 79 Status GetLoadedModuleFileSpec(const char *module_path, 80 FileSpec &file_spec) override; 81 82 Status GetFileLoadAddress(const llvm::StringRef &file_name, 83 lldb::addr_t &load_addr) override; 84 85 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> 86 GetAuxvData() const override; 87 88 // --------------------------------------------------------------------- 89 // Interface used by NativeRegisterContext-derived classes. 90 // --------------------------------------------------------------------- 91 static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr, 92 int data = 0, int *result = nullptr); 93 94 private: 95 MainLoop::SignalHandleUP m_sigchld_handle; 96 ArchSpec m_arch; 97 std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache; 98 99 // --------------------------------------------------------------------- 100 // Private Instance Methods 101 // --------------------------------------------------------------------- 102 NativeProcessOpenBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate, 103 const ArchSpec &arch, MainLoop &mainloop); 104 105 bool HasThreadNoLock(lldb::tid_t thread_id); 106 107 NativeThreadOpenBSD &AddThread(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 MonitorSIGTRAP(lldb::pid_t pid); 112 void MonitorSignal(lldb::pid_t pid, int signal); 113 114 Status PopulateMemoryRegionCache(); 115 void SigchldHandler(); 116 117 Status Attach(); 118 Status ReinitializeThreads(); 119 }; 120 121 } // namespace process_openbsd 122 } // namespace lldb_private 123 124 #endif // #ifndef liblldb_NativeProcessOpenBSD_H_ 125