LLDB  mainline
NativeProcessFreeBSD.h
Go to the documentation of this file.
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 
14 
16 #include "lldb/Utility/ArchSpec.h"
17 #include "lldb/Utility/FileSpec.h"
18 
19 #include "NativeThreadFreeBSD.h"
20 
21 namespace lldb_private {
22 namespace process_freebsd {
23 /// \class NativeProcessFreeBSD
24 /// Manages communication with the inferior (debugee) process.
25 ///
26 /// Upon construction, this class prepares and launches an inferior process
27 /// for debugging.
28 ///
29 /// Changes in the inferior process state are broadcasted.
32 public:
34  public:
35  llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
36  Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
37  MainLoop &mainloop) const override;
38 
39  llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
40  Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
41  MainLoop &mainloop) const override;
42 
43  Extension GetSupportedExtensions() const override;
44  };
45 
46  // NativeProcessProtocol Interface
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 Interrupt() override;
56 
57  Status Kill() override;
58 
60  MemoryRegionInfo &range_info) override;
61 
62  Status ReadMemory(lldb::addr_t addr, void *buf, size_t size,
63  size_t &bytes_read) override;
64 
65  Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
66  size_t &bytes_written) override;
67 
68  size_t UpdateThreads() override;
69 
70  const ArchSpec &GetArchitecture() const override { return m_arch; }
71 
73  bool hardware) override;
74 
75  // The two following methods are probably not necessary and probably
76  // will never be called. Nevertheless, we implement them right now
77  // to reduce the differences between different platforms and reduce
78  // the risk of the lack of implementation actually breaking something,
79  // at least for the time being.
80  Status GetLoadedModuleFileSpec(const char *module_path,
81  FileSpec &file_spec) override;
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  // Interface used by NativeRegisterContext-derived classes.
89  static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
90  int data = 0, int *result = nullptr);
91 
92  bool SupportHardwareSingleStepping() const;
93 
94  llvm::Expected<std::string> SaveCore(llvm::StringRef path_hint) override;
95 
96 protected:
97  llvm::Expected<llvm::ArrayRef<uint8_t>>
98  GetSoftwareBreakpointTrapOpcode(size_t size_hint) override;
99 
100 private:
105  std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
106 
107  // Private Instance Methods
108  NativeProcessFreeBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
109  const ArchSpec &arch, MainLoop &mainloop);
110 
111  bool HasThreadNoLock(lldb::tid_t thread_id);
112 
114  void RemoveThread(lldb::tid_t thread_id);
115 
116  void MonitorCallback(lldb::pid_t pid, int signal);
117  void MonitorExited(lldb::pid_t pid, WaitStatus status);
118  void MonitorSIGSTOP(lldb::pid_t pid);
119  void MonitorSIGTRAP(lldb::pid_t pid);
120  void MonitorSignal(lldb::pid_t pid, int signal);
121  void MonitorClone(::pid_t child_pid, bool is_vfork,
122  NativeThreadFreeBSD &parent_thread);
123 
125  void SigchldHandler();
126 
127  Status Attach();
128  Status SetupTrace();
130 };
131 
132 } // namespace process_freebsd
133 } // namespace lldb_private
134 
135 #endif // #ifndef liblldb_NativeProcessFreeBSD_H_
lldb_private::process_freebsd::NativeProcessFreeBSD::Detach
Status Detach() override
Definition: NativeProcessFreeBSD.cpp:499
lldb_private::NativeProcessProtocol::NativeDelegate
Definition: NativeProcessProtocol.h:221
lldb_private::ArchSpec
Definition: ArchSpec.h:33
NativeThreadFreeBSD.h
lldb_private::process_freebsd::NativeProcessFreeBSD::Resume
Status Resume(const ResumeActionList &resume_actions) override
Definition: NativeProcessFreeBSD.cpp:426
lldb_private::process_freebsd::NativeProcessFreeBSD::Signal
Status Signal(int signo) override
Sends a process a UNIX signal signal.
Definition: NativeProcessFreeBSD.cpp:512
lldb_private::process_freebsd::NativeProcessFreeBSD::SetBreakpoint
Status SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override
Definition: NativeProcessFreeBSD.cpp:692
lldb_private::process_freebsd::NativeProcessFreeBSD
Definition: NativeProcessFreeBSD.h:30
lldb_private::process_freebsd::NativeProcessFreeBSD::m_supports_mem_region
LazyBool m_supports_mem_region
Definition: NativeProcessFreeBSD.h:104
lldb_private::process_freebsd::NativeProcessFreeBSD::Halt
Status Halt() override
Definition: NativeProcessFreeBSD.cpp:491
lldb_private::process_freebsd::NativeProcessFreeBSD::SaveCore
llvm::Expected< std::string > SaveCore(llvm::StringRef path_hint) override
Write a core dump (without crashing the program).
Definition: NativeProcessFreeBSD.cpp:1018
lldb_private::MemoryRegionInfo
Definition: MemoryRegionInfo.h:21
lldb_private::process_freebsd::NativeProcessFreeBSD::PopulateMemoryRegionCache
Status PopulateMemoryRegionCache()
Definition: NativeProcessFreeBSD.cpp:610
lldb_private::process_freebsd::NativeProcessFreeBSD::NativeProcessFreeBSD
NativeProcessFreeBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate, const ArchSpec &arch, MainLoop &mainloop)
Definition: NativeProcessFreeBSD.cpp:143
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::LazyBool
LazyBool
Definition: lldb-private-enumerations.h:115
lldb_private::process_freebsd::NativeThreadFreeBSD
Definition: NativeThreadFreeBSD.h:25
lldb_private::process_freebsd::NativeProcessFreeBSD::MonitorClone
void MonitorClone(::pid_t child_pid, bool is_vfork, NativeThreadFreeBSD &parent_thread)
Definition: NativeProcessFreeBSD.cpp:954
lldb_private::process_freebsd::NativeProcessFreeBSD::ReinitializeThreads
Status ReinitializeThreads()
Definition: NativeProcessFreeBSD.cpp:927
lldb_private::process_freebsd::NativeProcessFreeBSD::RemoveThread
void RemoveThread(lldb::tid_t thread_id)
Definition: NativeProcessFreeBSD.cpp:798
lldb_private::process_freebsd::NativeProcessFreeBSD::m_sigchld_handle
MainLoop::SignalHandleUP m_sigchld_handle
Definition: NativeProcessFreeBSD.h:101
lldb_private::WaitStatus
Definition: Host.h:34
lldb_private::process_freebsd::NativeProcessFreeBSD::MonitorSignal
void MonitorSignal(lldb::pid_t pid, int signal)
Definition: NativeProcessFreeBSD.cpp:354
lldb_private::process_freebsd::NativeProcessFreeBSD::Factory::Attach
llvm::Expected< std::unique_ptr< NativeProcessProtocol > > Attach(lldb::pid_t pid, NativeDelegate &native_delegate, MainLoop &mainloop) const override
Attach to an existing process.
Definition: NativeProcessFreeBSD.cpp:108
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::process_freebsd::NativeProcessFreeBSD::Factory::Launch
llvm::Expected< std::unique_ptr< NativeProcessProtocol > > Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate, MainLoop &mainloop) const override
Launch a process for debugging.
Definition: NativeProcessFreeBSD.cpp:54
lldb_private::process_freebsd::NativeProcessFreeBSD::GetLoadedModuleFileSpec
Status GetLoadedModuleFileSpec(const char *module_path, FileSpec &file_spec) override
Definition: NativeProcessFreeBSD.cpp:699
lldb_private::NativeProcessSoftwareSingleStep
Definition: NativeProcessSoftwareSingleStep.h:19
lldb_private::process_freebsd::NativeProcessFreeBSD::PtraceWrapper
static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr=nullptr, int data=0, int *result=nullptr)
Definition: NativeProcessFreeBSD.cpp:381
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
MemoryRegionInfo.h
lldb_private::process_freebsd::NativeProcessFreeBSD::MonitorSIGSTOP
void MonitorSIGSTOP(lldb::pid_t pid)
Definition: NativeProcessFreeBSD.cpp:186
lldb_private::process_freebsd::NativeProcessFreeBSD::WriteMemory
Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override
Definition: NativeProcessFreeBSD.cpp:870
lldb_private::process_freebsd::NativeProcessFreeBSD::Factory::GetSupportedExtensions
Extension GetSupportedExtensions() const override
Get the bitmask of extensions supported by this process plugin.
Definition: NativeProcessFreeBSD.cpp:132
NativeProcessELF.h
lldb_private::process_freebsd::NativeProcessFreeBSD::ReadMemory
Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override
Definition: NativeProcessFreeBSD.cpp:843
lldb_private::process_freebsd::NativeProcessFreeBSD::MonitorCallback
void MonitorCallback(lldb::pid_t pid, int signal)
Definition: NativeProcessFreeBSD.cpp:161
lldb_private::process_freebsd::NativeProcessFreeBSD::Attach
Status Attach()
Definition: NativeProcessFreeBSD.cpp:814
lldb_private::process_freebsd::NativeProcessFreeBSD::m_main_loop
MainLoop & m_main_loop
Definition: NativeProcessFreeBSD.h:103
lldb_private::NativeProcessProtocol::Extension
Extension
Extension flag constants, returned by Factory::GetSupportedExtensions() and passed to SetEnabledExten...
Definition: NativeProcessProtocol.h:245
lldb_private::process_freebsd::NativeProcessFreeBSD::GetArchitecture
const ArchSpec & GetArchitecture() const override
Definition: NativeProcessFreeBSD.h:70
lldb_private::Status
Definition: Status.h:44
uint32_t
lldb_private::MainLoop
Definition: MainLoop.h:38
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb_private::MainLoop::SignalHandleUP
std::unique_ptr< SignalHandle > SignalHandleUP
Definition: MainLoop.h:40
lldb_private::process_freebsd::NativeProcessFreeBSD::GetFileLoadAddress
Status GetFileLoadAddress(const llvm::StringRef &file_name, lldb::addr_t &load_addr) override
Definition: NativeProcessFreeBSD.cpp:720
ArchSpec.h
lldb_private::process_freebsd::NativeProcessFreeBSD::GetMemoryRegionInfo
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info) override
Definition: NativeProcessFreeBSD.cpp:554
lldb_private::process_freebsd::NativeProcessFreeBSD::Kill
Status Kill() override
Definition: NativeProcessFreeBSD.cpp:523
lldb_private::process_freebsd::NativeProcessFreeBSD::GetAuxvData
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > GetAuxvData() const override
Definition: NativeProcessFreeBSD.cpp:900
lldb_private::process_freebsd::NativeProcessFreeBSD::MonitorSIGTRAP
void MonitorSIGTRAP(lldb::pid_t pid)
Definition: NativeProcessFreeBSD.cpp:195
lldb_private::process_freebsd::NativeProcessFreeBSD::Interrupt
Status Interrupt() override
Tells a process to interrupt all operations as if by a Ctrl-C.
Definition: NativeProcessFreeBSD.cpp:521
lldb_private::ResumeActionList
Definition: Debug.h:33
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::NativeProcessELF
Definition: NativeProcessELF.h:21
lldb_private::process_freebsd::NativeProcessFreeBSD::AddThread
NativeThreadFreeBSD & AddThread(lldb::tid_t thread_id)
Definition: NativeProcessFreeBSD.cpp:782
lldb_private::eLazyBoolCalculate
@ eLazyBoolCalculate
Definition: lldb-private-enumerations.h:115
lldb_private::process_freebsd::NativeProcessFreeBSD::SetupTrace
Status SetupTrace()
Definition: NativeProcessFreeBSD.cpp:912
FileSpec.h
lldb_private::process_freebsd::NativeProcessFreeBSD::UpdateThreads
size_t UpdateThreads() override
Definition: NativeProcessFreeBSD.cpp:690
lldb_private::process_freebsd::NativeProcessFreeBSD::SupportHardwareSingleStepping
bool SupportHardwareSingleStepping() const
Definition: NativeProcessFreeBSD.cpp:950
lldb_private::process_freebsd::NativeProcessFreeBSD::MonitorExited
void MonitorExited(lldb::pid_t pid, WaitStatus status)
Definition: NativeProcessFreeBSD.cpp:172
lldb_private::process_freebsd::NativeProcessFreeBSD::Factory
Definition: NativeProcessFreeBSD.h:33
lldb_private::process_freebsd::NativeProcessFreeBSD::m_mem_region_cache
std::vector< std::pair< MemoryRegionInfo, FileSpec > > m_mem_region_cache
Definition: NativeProcessFreeBSD.h:105
lldb_private::process_freebsd::NativeProcessFreeBSD::SigchldHandler
void SigchldHandler()
Definition: NativeProcessFreeBSD.cpp:737
NativeProcessSoftwareSingleStep.h
lldb_private::NativeProcessProtocol::Factory
Definition: NativeProcessProtocol.h:258
lldb_private::process_freebsd::NativeProcessFreeBSD::m_arch
ArchSpec m_arch
Definition: NativeProcessFreeBSD.h:102
lldb_private::process_freebsd::NativeProcessFreeBSD::GetSoftwareBreakpointTrapOpcode
llvm::Expected< llvm::ArrayRef< uint8_t > > GetSoftwareBreakpointTrapOpcode(size_t size_hint) override
Definition: NativeProcessFreeBSD.cpp:406
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
lldb_private::process_freebsd::NativeProcessFreeBSD::HasThreadNoLock
bool HasThreadNoLock(lldb::tid_t thread_id)
Definition: NativeProcessFreeBSD.cpp:769