1 //===-- NativeProcessFreeBSD.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_NativeProcessFreeBSD_H_ 10 #define liblldb_NativeProcessFreeBSD_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 "NativeThreadFreeBSD.h" 18 19 namespace lldb_private { 20 namespace process_freebsd { 21 /// \class NativeProcessFreeBSD 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 NativeProcessFreeBSD : 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 41 // NativeProcessProtocol Interface 42 Status Resume(const ResumeActionList &resume_actions) override; 43 44 Status Halt() override; 45 46 Status Detach() override; 47 48 Status Signal(int signo) override; 49 50 Status Interrupt() override; 51 52 Status Kill() override; 53 54 Status GetMemoryRegionInfo(lldb::addr_t load_addr, 55 MemoryRegionInfo &range_info) override; 56 57 Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, 58 size_t &bytes_read) override; 59 60 Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, 61 size_t &bytes_written) override; 62 63 size_t UpdateThreads() override; 64 GetArchitecture()65 const ArchSpec &GetArchitecture() const override { return m_arch; } 66 67 Status SetBreakpoint(lldb::addr_t addr, uint32_t size, 68 bool hardware) override; 69 70 // The two following methods are probably not necessary and probably 71 // will never be called. Nevertheless, we implement them right now 72 // to reduce the differences between different platforms and reduce 73 // the risk of the lack of implementation actually breaking something, 74 // at least for the time being. 75 Status GetLoadedModuleFileSpec(const char *module_path, 76 FileSpec &file_spec) override; 77 Status GetFileLoadAddress(const llvm::StringRef &file_name, 78 lldb::addr_t &load_addr) override; 79 80 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> 81 GetAuxvData() const override; 82 83 // Interface used by NativeRegisterContext-derived classes. 84 static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr, 85 int data = 0, int *result = nullptr); 86 87 private: 88 MainLoop::SignalHandleUP m_sigchld_handle; 89 ArchSpec m_arch; 90 LazyBool m_supports_mem_region = eLazyBoolCalculate; 91 std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache; 92 93 // Private Instance Methods 94 NativeProcessFreeBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate, 95 const ArchSpec &arch, MainLoop &mainloop); 96 97 bool HasThreadNoLock(lldb::tid_t thread_id); 98 99 NativeThreadFreeBSD &AddThread(lldb::tid_t thread_id); 100 void RemoveThread(lldb::tid_t thread_id); 101 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); 107 108 Status PopulateMemoryRegionCache(); 109 void SigchldHandler(); 110 111 Status Attach(); 112 Status SetupTrace(); 113 Status ReinitializeThreads(); 114 }; 115 116 } // namespace process_freebsd 117 } // namespace lldb_private 118 119 #endif // #ifndef liblldb_NativeProcessFreeBSD_H_ 120