1 //===-- ProcessFreeBSD.h ------------------------------------------*- C++
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ProcessFreeBSD_H_
11 #define liblldb_ProcessFreeBSD_H_
13 #include "Plugins/Process/POSIX/ProcessMessage.h"
14 #include "lldb/Target/Process.h"
15 #include "lldb/Target/ThreadList.h"
23 class ProcessFreeBSD : public lldb_private::Process {
27 static lldb::ProcessSP
28 CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
29 const lldb_private::FileSpec *crash_file_path);
31 static void Initialize();
33 static void Terminate();
35 static lldb_private::ConstString GetPluginNameStatic();
37 static const char *GetPluginDescriptionStatic();
39 // Constructors and destructors
40 ProcessFreeBSD(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
41 lldb::UnixSignalsSP &unix_signals_sp);
45 virtual lldb_private::Status WillResume() override;
47 // PluginInterface protocol
48 virtual lldb_private::ConstString GetPluginName() override;
50 virtual uint32_t GetPluginVersion() override;
54 void Finalize() override;
56 bool CanDebug(lldb::TargetSP target_sp,
57 bool plugin_specified_by_name) override;
59 lldb_private::Status WillLaunch(lldb_private::Module *module) override;
61 lldb_private::Status DoAttachToProcessWithID(
63 const lldb_private::ProcessAttachInfo &attach_info) override;
66 DoLaunch(lldb_private::Module *exe_module,
67 lldb_private::ProcessLaunchInfo &launch_info) override;
69 void DidLaunch() override;
71 lldb_private::Status DoResume() override;
73 lldb_private::Status DoHalt(bool &caused_stop) override;
75 lldb_private::Status DoDetach(bool keep_stopped) override;
77 lldb_private::Status DoSignal(int signal) override;
79 lldb_private::Status DoDestroy() override;
81 void DoDidExec() override;
83 void RefreshStateAfterStop() override;
85 bool IsAlive() override;
87 size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
88 lldb_private::Status &error) override;
90 size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
91 lldb_private::Status &error) override;
93 lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
94 lldb_private::Status &error) override;
96 lldb_private::Status DoDeallocateMemory(lldb::addr_t ptr) override;
99 GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite *bp_site);
102 EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
105 DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
107 lldb_private::Status EnableWatchpoint(lldb_private::Watchpoint *wp,
108 bool notify = true) override;
110 lldb_private::Status DisableWatchpoint(lldb_private::Watchpoint *wp,
111 bool notify = true) override;
113 lldb_private::Status GetWatchpointSupportInfo(uint32_t &num) override;
115 lldb_private::Status GetWatchpointSupportInfo(uint32_t &num,
116 bool &after) override;
118 virtual uint32_t UpdateThreadListIfNeeded();
120 bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
121 lldb_private::ThreadList &new_thread_list) override;
123 virtual lldb::ByteOrder GetByteOrder() const;
125 lldb::addr_t GetImageInfoAddress() override;
127 size_t PutSTDIN(const char *buf, size_t len,
128 lldb_private::Status &error) override;
130 lldb_private::DataExtractor GetAuxvData() override;
132 // ProcessFreeBSD internal API.
134 /// Registers the given message with this process.
135 virtual void SendMessage(const ProcessMessage &message);
137 ProcessMonitor &GetMonitor() {
142 lldb_private::FileSpec
143 GetFileSpec(const lldb_private::FileAction *file_action,
144 const lldb_private::FileSpec &default_file_spec,
145 const lldb_private::FileSpec &dbg_pts_file_spec);
147 /// Adds the thread to the list of threads for which we have received the
148 /// initial stopping signal.
149 /// The \p stop_tid parameter indicates the thread which the stop happened
151 bool AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid);
153 bool WaitingForInitialStop(lldb::tid_t stop_tid);
155 virtual FreeBSDThread *CreateNewFreeBSDThread(lldb_private::Process &process,
158 static bool SingleStepBreakpointHit(
159 void *baton, lldb_private::StoppointCallbackContext *context,
160 lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
162 lldb_private::Status SetupSoftwareSingleStepping(lldb::tid_t tid);
164 lldb_private::Status SetSoftwareSingleStepBreakpoint(lldb::tid_t tid,
167 bool IsSoftwareStepBreakpoint(lldb::tid_t tid);
169 bool SupportHardwareSingleStepping() const;
171 typedef std::vector<lldb::tid_t> tid_collection;
172 tid_collection &GetStepTids() { return m_step_tids; }
175 static const size_t MAX_TRAP_OPCODE_SIZE = 8;
177 /// Target byte order.
178 lldb::ByteOrder m_byte_order;
181 ProcessMonitor *m_monitor;
183 /// The module we are executing.
184 lldb_private::Module *m_module;
186 /// Message queue notifying this instance of inferior process state changes.
187 std::recursive_mutex m_message_mutex;
188 std::queue<ProcessMessage> m_message_queue;
190 /// Drive any exit events to completion.
193 /// Returns true if the process has exited.
196 /// Returns true if the process is stopped.
199 /// Returns true if at least one running is currently running
200 bool IsAThreadRunning();
202 typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
203 MMapMap m_addr_to_mmap_size;
205 typedef std::set<lldb::tid_t> ThreadStopSet;
206 /// Every thread begins with a stop signal. This keeps track
207 /// of the threads for which we have received the stop signal.
208 ThreadStopSet m_seen_initial_stop;
210 friend class FreeBSDThread;
212 tid_collection m_suspend_tids;
213 tid_collection m_run_tids;
214 tid_collection m_step_tids;
215 std::map<lldb::tid_t, lldb::break_id_t> m_threads_stepping_with_breakpoint;
220 #endif // liblldb_ProcessFreeBSD_H_