LLDB  mainline
ProcessFreeBSD.h
Go to the documentation of this file.
1 //===-- ProcessFreeBSD.h ------------------------------------------*- C++
2 //-*-===//
3 //
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
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_ProcessFreeBSD_H_
11 #define liblldb_ProcessFreeBSD_H_
12 
14 #include "lldb/Target/Process.h"
15 #include "lldb/Target/ThreadList.h"
16 #include <mutex>
17 #include <queue>
18 #include <set>
19 
20 class ProcessMonitor;
21 class FreeBSDThread;
22 
24 
25 public:
26  // Static functions.
27  static lldb::ProcessSP
28  CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
29  const lldb_private::FileSpec *crash_file_path);
30 
31  static void Initialize();
32 
33  static void Terminate();
34 
36 
37  static const char *GetPluginDescriptionStatic();
38 
39  // Constructors and destructors
40  ProcessFreeBSD(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
41  lldb::UnixSignalsSP &unix_signals_sp);
42 
44 
45  virtual lldb_private::Status WillResume() override;
46 
47  // PluginInterface protocol
48  virtual lldb_private::ConstString GetPluginName() override;
49 
50  virtual uint32_t GetPluginVersion() override;
51 
52 public:
53  // Process protocol.
54  void Finalize() override;
55 
56  bool CanDebug(lldb::TargetSP target_sp,
57  bool plugin_specified_by_name) override;
58 
60 
62  lldb::pid_t pid,
63  const lldb_private::ProcessAttachInfo &attach_info) override;
64 
66  DoLaunch(lldb_private::Module *exe_module,
67  lldb_private::ProcessLaunchInfo &launch_info) override;
68 
69  void DidLaunch() override;
70 
71  lldb_private::Status DoResume() override;
72 
73  lldb_private::Status DoHalt(bool &caused_stop) override;
74 
75  lldb_private::Status DoDetach(bool keep_stopped) override;
76 
77  lldb_private::Status DoSignal(int signal) override;
78 
80 
81  void DoDidExec() override;
82 
83  void RefreshStateAfterStop() override;
84 
85  bool IsAlive() override;
86 
87  size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
88  lldb_private::Status &error) override;
89 
90  size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
91  lldb_private::Status &error) override;
92 
93  lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
94  lldb_private::Status &error) override;
95 
97 
98  virtual size_t
100 
103 
106 
108  bool notify = true) override;
109 
111  bool notify = true) override;
112 
114 
116  bool &after) override;
117 
119 
120  bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
121  lldb_private::ThreadList &new_thread_list) override;
122 
123  virtual lldb::ByteOrder GetByteOrder() const;
124 
126 
127  size_t PutSTDIN(const char *buf, size_t len,
128  lldb_private::Status &error) override;
129 
131 
132  // ProcessFreeBSD internal API.
133 
134  /// Registers the given message with this process.
135  virtual void SendMessage(const ProcessMessage &message);
136 
138  assert(m_monitor);
139  return *m_monitor;
140  }
141 
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);
146 
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
150  /// for.
152 
153  bool WaitingForInitialStop(lldb::tid_t stop_tid);
154 
156  lldb::tid_t tid);
157 
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);
161 
163 
165  lldb::addr_t addr);
166 
168 
169  bool SupportHardwareSingleStepping() const;
170 
171  typedef std::vector<lldb::tid_t> tid_collection;
172  tid_collection &GetStepTids() { return m_step_tids; }
173 
174 protected:
175  static const size_t MAX_TRAP_OPCODE_SIZE = 8;
176 
177  /// Target byte order.
179 
180  /// Process monitor;
182 
183  /// The module we are executing.
185 
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;
189 
190  /// Drive any exit events to completion.
192 
193  /// Returns true if the process has exited.
194  bool HasExited();
195 
196  /// Returns true if the process is stopped.
197  bool IsStopped();
198 
199  /// Returns true if at least one running is currently running
200  bool IsAThreadRunning();
201 
202  typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
204 
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;
209 
210  friend class FreeBSDThread;
211 
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;
216 
218 };
219 
220 #endif // liblldb_ProcessFreeBSD_H_
Class that manages the actual breakpoint that will be inserted into the running program.
static lldb_private::ConstString GetPluginNameStatic()
An data extractor class.
Definition: DataExtractor.h:48
bool IsSoftwareStepBreakpoint(lldb::tid_t tid)
std::queue< ProcessMessage > m_message_queue
lldb_private::Status DoResume() override
Resumes all of a process&#39;s threads as configured using the Thread run control functions.
bool IsAlive() override
Check if a process is still alive.
virtual uint32_t UpdateThreadListIfNeeded()
virtual size_t GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite *bp_site)
void DidLaunch() override
Called after launching a process.
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const lldb_private::FileSpec *crash_file_path)
virtual uint32_t GetPluginVersion() override
lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions, lldb_private::Status &error) override
Actually allocate memory in the process.
lldb_private::Status DoLaunch(lldb_private::Module *exe_module, lldb_private::ProcessLaunchInfo &launch_info) override
Launch a new process.
virtual lldb_private::ConstString GetPluginName() override
lldb_private::FileSpec GetFileSpec(const lldb_private::FileAction *file_action, const lldb_private::FileSpec &default_file_spec, const lldb_private::FileSpec &dbg_pts_file_spec)
tid_collection m_step_tids
A file utility class.
Definition: FileSpec.h:56
bool AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid)
Adds the thread to the list of threads for which we have received the initial stopping signal...
bool IsAThreadRunning()
Returns true if at least one running is currently running.
tid_collection & GetStepTids()
std::set< lldb::tid_t > ThreadStopSet
bool SupportHardwareSingleStepping() const
ProcessMonitor * m_monitor
Process monitor;.
lldb_private::Status DoDetach(bool keep_stopped) override
Detaches from a running or stopped process.
static const char * GetPluginDescriptionStatic()
bool m_exit_now
Drive any exit events to completion.
Manages communication with the inferior (debugee) process.
lldb_private::Status EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override
uint64_t user_id_t
Definition: lldb-types.h:84
virtual FreeBSDThread * CreateNewFreeBSDThread(lldb_private::Process &process, lldb::tid_t tid)
static llvm::raw_ostream & error(Stream &strm)
ThreadStopSet m_seen_initial_stop
Every thread begins with a stop signal.
MMapMap m_addr_to_mmap_size
lldb_private::Status WillLaunch(lldb_private::Module *module) override
Called before launching to a process.
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:75
ProcessMonitor & GetMonitor()
lldb_private::Status SetSoftwareSingleStepBreakpoint(lldb::tid_t tid, lldb::addr_t addr)
uint64_t tid_t
Definition: lldb-types.h:86
ByteOrder
Byte ordering definitions.
size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, lldb_private::Status &error) override
Actually do the writing of memory to a process.
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
A plug-in interface definition class for debugging a process.
Definition: Process.h:365
static void Terminate()
virtual void SendMessage(const ProcessMessage &message)
Registers the given message with this process.
lldb_private::DataExtractor GetAuxvData() override
static void Initialize()
bool HasExited()
Returns true if the process has exited.
tid_collection m_suspend_tids
std::map< lldb::tid_t, lldb::break_id_t > m_threads_stepping_with_breakpoint
lldb_private::Status DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override
lldb_private::Status DoDestroy() override
static const size_t MAX_TRAP_OPCODE_SIZE
void DoDidExec() override
Subclasses of Process should implement this function if they need to do anything after a process exec...
lldb_private::Status SetupSoftwareSingleStepping(lldb::tid_t tid)
ProcessFreeBSD(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, lldb::UnixSignalsSP &unix_signals_sp)
uint64_t addr_t
Definition: lldb-types.h:83
size_t PutSTDIN(const char *buf, size_t len, lldb_private::Status &error) override
Puts data into this process&#39;s STDIN.
A uniqued constant string class.
Definition: ConstString.h:40
static bool SingleStepBreakpointHit(void *baton, lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
lldb_private::Status DoDeallocateMemory(lldb::addr_t ptr) override
Actually deallocate memory in the process.
lldb_private::Status DoSignal(int signal) override
Sends a process a UNIX signal signal.
lldb_private::Status DoHalt(bool &caused_stop) override
Halts a running process.
uint64_t pid_t
Definition: lldb-types.h:85
lldb::addr_t GetImageInfoAddress() override
Get the image information address for the current process.
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
lldb_private::Status EnableWatchpoint(lldb_private::Watchpoint *wp, bool notify=true) override
lldb_private::Module * m_module
The module we are executing.
lldb_private::Status DoAttachToProcessWithID(lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info) override
Attach to an existing process using a process ID.
lldb::ByteOrder m_byte_order
Target byte order.
virtual lldb_private::Status WillResume() override
Called before resuming to a process.
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
virtual lldb::ByteOrder GetByteOrder() const
std::map< lldb::addr_t, lldb::addr_t > MMapMap
bool IsStopped()
Returns true if the process is stopped.
void Finalize() override
This object is about to be destroyed, do any necessary cleanup.
size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, lldb_private::Status &error) override
Actually do the reading of memory from a process.
lldb_private::Status GetWatchpointSupportInfo(uint32_t &num) override
std::vector< lldb::tid_t > tid_collection
tid_collection m_run_tids
lldb_private::Status DisableWatchpoint(lldb_private::Watchpoint *wp, bool notify=true) override
std::recursive_mutex m_message_mutex
Message queue notifying this instance of inferior process state changes.
bool UpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list) override
An error handling class.
Definition: Status.h:44
bool WaitingForInitialStop(lldb::tid_t stop_tid)