LLDB  mainline
SBBreakpointLocation.cpp
Go to the documentation of this file.
1 //===-- SBBreakpointLocation.cpp ------------------------------------------===//
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 
10 #include "lldb/API/SBAddress.h"
11 #include "lldb/API/SBDebugger.h"
12 #include "lldb/API/SBDefines.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/API/SBStringList.h"
17 
20 #include "lldb/Core/Debugger.h"
21 #include "lldb/Core/StreamFile.h"
25 #include "lldb/Target/Target.h"
26 #include "lldb/Target/ThreadSpec.h"
27 #include "lldb/Utility/Stream.h"
28 #include "lldb/lldb-defines.h"
29 #include "lldb/lldb-types.h"
30 
31 using namespace lldb;
32 using namespace lldb_private;
33 
35 
37  const lldb::BreakpointLocationSP &break_loc_sp)
38  : m_opaque_wp(break_loc_sp) {
39  LLDB_INSTRUMENT_VA(this, break_loc_sp);
40 }
41 
43  : m_opaque_wp(rhs.m_opaque_wp) {
44  LLDB_INSTRUMENT_VA(this, rhs);
45 }
46 
49  LLDB_INSTRUMENT_VA(this, rhs);
50 
52  return *this;
53 }
54 
56 
57 BreakpointLocationSP SBBreakpointLocation::GetSP() const {
58  return m_opaque_wp.lock();
59 }
60 
62  LLDB_INSTRUMENT_VA(this);
63  return this->operator bool();
64 }
65 SBBreakpointLocation::operator bool() const {
66  LLDB_INSTRUMENT_VA(this);
67 
68  return bool(GetSP());
69 }
70 
72  LLDB_INSTRUMENT_VA(this);
73 
74  BreakpointLocationSP loc_sp = GetSP();
75  if (loc_sp) {
76  return SBAddress(loc_sp->GetAddress());
77  }
78 
79  return SBAddress();
80 }
81 
83  LLDB_INSTRUMENT_VA(this);
84 
85  addr_t ret_addr = LLDB_INVALID_ADDRESS;
86  BreakpointLocationSP loc_sp = GetSP();
87 
88  if (loc_sp) {
89  std::lock_guard<std::recursive_mutex> guard(
90  loc_sp->GetTarget().GetAPIMutex());
91  ret_addr = loc_sp->GetLoadAddress();
92  }
93 
94  return ret_addr;
95 }
96 
98  LLDB_INSTRUMENT_VA(this, enabled);
99 
100  BreakpointLocationSP loc_sp = GetSP();
101  if (loc_sp) {
102  std::lock_guard<std::recursive_mutex> guard(
103  loc_sp->GetTarget().GetAPIMutex());
104  loc_sp->SetEnabled(enabled);
105  }
106 }
107 
109  LLDB_INSTRUMENT_VA(this);
110 
111  BreakpointLocationSP loc_sp = GetSP();
112  if (loc_sp) {
113  std::lock_guard<std::recursive_mutex> guard(
114  loc_sp->GetTarget().GetAPIMutex());
115  return loc_sp->IsEnabled();
116  } else
117  return false;
118 }
119 
121  LLDB_INSTRUMENT_VA(this);
122 
123  BreakpointLocationSP loc_sp = GetSP();
124  if (loc_sp) {
125  std::lock_guard<std::recursive_mutex> guard(
126  loc_sp->GetTarget().GetAPIMutex());
127  return loc_sp->GetHitCount();
128  } else
129  return 0;
130 }
131 
133  LLDB_INSTRUMENT_VA(this);
134 
135  BreakpointLocationSP loc_sp = GetSP();
136  if (loc_sp) {
137  std::lock_guard<std::recursive_mutex> guard(
138  loc_sp->GetTarget().GetAPIMutex());
139  return loc_sp->GetIgnoreCount();
140  } else
141  return 0;
142 }
143 
145  LLDB_INSTRUMENT_VA(this, n);
146 
147  BreakpointLocationSP loc_sp = GetSP();
148  if (loc_sp) {
149  std::lock_guard<std::recursive_mutex> guard(
150  loc_sp->GetTarget().GetAPIMutex());
151  loc_sp->SetIgnoreCount(n);
152  }
153 }
154 
155 void SBBreakpointLocation::SetCondition(const char *condition) {
156  LLDB_INSTRUMENT_VA(this, condition);
157 
158  BreakpointLocationSP loc_sp = GetSP();
159  if (loc_sp) {
160  std::lock_guard<std::recursive_mutex> guard(
161  loc_sp->GetTarget().GetAPIMutex());
162  loc_sp->SetCondition(condition);
163  }
164 }
165 
167  LLDB_INSTRUMENT_VA(this);
168 
169  BreakpointLocationSP loc_sp = GetSP();
170  if (loc_sp) {
171  std::lock_guard<std::recursive_mutex> guard(
172  loc_sp->GetTarget().GetAPIMutex());
173  return loc_sp->GetConditionText();
174  }
175  return nullptr;
176 }
177 
178 void SBBreakpointLocation::SetAutoContinue(bool auto_continue) {
179  LLDB_INSTRUMENT_VA(this, auto_continue);
180 
181  BreakpointLocationSP loc_sp = GetSP();
182  if (loc_sp) {
183  std::lock_guard<std::recursive_mutex> guard(
184  loc_sp->GetTarget().GetAPIMutex());
185  loc_sp->SetAutoContinue(auto_continue);
186  }
187 }
188 
190  LLDB_INSTRUMENT_VA(this);
191 
192  BreakpointLocationSP loc_sp = GetSP();
193  if (loc_sp) {
194  std::lock_guard<std::recursive_mutex> guard(
195  loc_sp->GetTarget().GetAPIMutex());
196  return loc_sp->IsAutoContinue();
197  }
198  return false;
199 }
200 
202  const char *callback_function_name) {
203  LLDB_INSTRUMENT_VA(this, callback_function_name);
204 }
205 
207  const char *callback_function_name,
208  SBStructuredData &extra_args) {
209  LLDB_INSTRUMENT_VA(this, callback_function_name, extra_args);
210  SBError sb_error;
211  BreakpointLocationSP loc_sp = GetSP();
212 
213  if (loc_sp) {
214  Status error;
215  std::lock_guard<std::recursive_mutex> guard(
216  loc_sp->GetTarget().GetAPIMutex());
217  BreakpointOptions &bp_options = loc_sp->GetLocationOptions();
218  error = loc_sp->GetBreakpoint()
219  .GetTarget()
220  .GetDebugger()
221  .GetScriptInterpreter()
222  ->SetBreakpointCommandCallbackFunction(bp_options,
223  callback_function_name,
224  extra_args.m_impl_up
225  ->GetObjectSP());
226  sb_error.SetError(error);
227  } else
228  sb_error.SetErrorString("invalid breakpoint");
229 
230  return sb_error;
231 }
232 
233 SBError
234 SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
235  LLDB_INSTRUMENT_VA(this, callback_body_text);
236 
237  BreakpointLocationSP loc_sp = GetSP();
238 
239  SBError sb_error;
240  if (loc_sp) {
241  std::lock_guard<std::recursive_mutex> guard(
242  loc_sp->GetTarget().GetAPIMutex());
243  BreakpointOptions &bp_options = loc_sp->GetLocationOptions();
244  Status error =
245  loc_sp->GetBreakpoint()
246  .GetTarget()
247  .GetDebugger()
248  .GetScriptInterpreter()
249  ->SetBreakpointCommandCallback(bp_options, callback_body_text);
250  sb_error.SetError(error);
251  } else
252  sb_error.SetErrorString("invalid breakpoint");
253 
254  return sb_error;
255 }
256 
258  LLDB_INSTRUMENT_VA(this, commands);
259 
260  BreakpointLocationSP loc_sp = GetSP();
261  if (!loc_sp)
262  return;
263  if (commands.GetSize() == 0)
264  return;
265 
266  std::lock_guard<std::recursive_mutex> guard(
267  loc_sp->GetTarget().GetAPIMutex());
268  std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
270 
271  loc_sp->GetLocationOptions().SetCommandDataCallback(cmd_data_up);
272 }
273 
275  LLDB_INSTRUMENT_VA(this, commands);
276 
277  BreakpointLocationSP loc_sp = GetSP();
278  if (!loc_sp)
279  return false;
280  StringList command_list;
281  bool has_commands =
282  loc_sp->GetLocationOptions().GetCommandLineCallbacks(command_list);
283  if (has_commands)
284  commands.AppendList(command_list);
285  return has_commands;
286 }
287 
289  LLDB_INSTRUMENT_VA(this, thread_id);
290 
291  BreakpointLocationSP loc_sp = GetSP();
292  if (loc_sp) {
293  std::lock_guard<std::recursive_mutex> guard(
294  loc_sp->GetTarget().GetAPIMutex());
295  loc_sp->SetThreadID(thread_id);
296  }
297 }
298 
300  LLDB_INSTRUMENT_VA(this);
301 
303  BreakpointLocationSP loc_sp = GetSP();
304  if (loc_sp) {
305  std::lock_guard<std::recursive_mutex> guard(
306  loc_sp->GetTarget().GetAPIMutex());
307  return loc_sp->GetThreadID();
308  }
309  return tid;
310 }
311 
313  LLDB_INSTRUMENT_VA(this, index);
314 
315  BreakpointLocationSP loc_sp = GetSP();
316  if (loc_sp) {
317  std::lock_guard<std::recursive_mutex> guard(
318  loc_sp->GetTarget().GetAPIMutex());
319  loc_sp->SetThreadIndex(index);
320  }
321 }
322 
324  LLDB_INSTRUMENT_VA(this);
325 
326  uint32_t thread_idx = UINT32_MAX;
327  BreakpointLocationSP loc_sp = GetSP();
328  if (loc_sp) {
329  std::lock_guard<std::recursive_mutex> guard(
330  loc_sp->GetTarget().GetAPIMutex());
331  return loc_sp->GetThreadIndex();
332  }
333  return thread_idx;
334 }
335 
336 void SBBreakpointLocation::SetThreadName(const char *thread_name) {
337  LLDB_INSTRUMENT_VA(this, thread_name);
338 
339  BreakpointLocationSP loc_sp = GetSP();
340  if (loc_sp) {
341  std::lock_guard<std::recursive_mutex> guard(
342  loc_sp->GetTarget().GetAPIMutex());
343  loc_sp->SetThreadName(thread_name);
344  }
345 }
346 
348  LLDB_INSTRUMENT_VA(this);
349 
350  BreakpointLocationSP loc_sp = GetSP();
351  if (loc_sp) {
352  std::lock_guard<std::recursive_mutex> guard(
353  loc_sp->GetTarget().GetAPIMutex());
354  return loc_sp->GetThreadName();
355  }
356  return nullptr;
357 }
358 
359 void SBBreakpointLocation::SetQueueName(const char *queue_name) {
360  LLDB_INSTRUMENT_VA(this, queue_name);
361 
362  BreakpointLocationSP loc_sp = GetSP();
363  if (loc_sp) {
364  std::lock_guard<std::recursive_mutex> guard(
365  loc_sp->GetTarget().GetAPIMutex());
366  loc_sp->SetQueueName(queue_name);
367  }
368 }
369 
371  LLDB_INSTRUMENT_VA(this);
372 
373  BreakpointLocationSP loc_sp = GetSP();
374  if (loc_sp) {
375  std::lock_guard<std::recursive_mutex> guard(
376  loc_sp->GetTarget().GetAPIMutex());
377  loc_sp->GetQueueName();
378  }
379  return nullptr;
380 }
381 
383  LLDB_INSTRUMENT_VA(this);
384 
385  BreakpointLocationSP loc_sp = GetSP();
386  if (loc_sp) {
387  std::lock_guard<std::recursive_mutex> guard(
388  loc_sp->GetTarget().GetAPIMutex());
389  return loc_sp->IsResolved();
390  }
391  return false;
392 }
393 
395  const lldb::BreakpointLocationSP &break_loc_sp) {
396  // Uninstall the callbacks?
397  m_opaque_wp = break_loc_sp;
398 }
399 
401  DescriptionLevel level) {
402  LLDB_INSTRUMENT_VA(this, description, level);
403 
404  Stream &strm = description.ref();
405  BreakpointLocationSP loc_sp = GetSP();
406 
407  if (loc_sp) {
408  std::lock_guard<std::recursive_mutex> guard(
409  loc_sp->GetTarget().GetAPIMutex());
410  loc_sp->GetDescription(&strm, level);
411  strm.EOL();
412  } else
413  strm.PutCString("No value");
414 
415  return true;
416 }
417 
419  LLDB_INSTRUMENT_VA(this);
420 
421  BreakpointLocationSP loc_sp = GetSP();
422  if (loc_sp) {
423  std::lock_guard<std::recursive_mutex> guard(
424  loc_sp->GetTarget().GetAPIMutex());
425  return loc_sp->GetID();
426  } else
427  return LLDB_INVALID_BREAK_ID;
428 }
429 
431  LLDB_INSTRUMENT_VA(this);
432 
433  BreakpointLocationSP loc_sp = GetSP();
434 
435  SBBreakpoint sb_bp;
436  if (loc_sp) {
437  std::lock_guard<std::recursive_mutex> guard(
438  loc_sp->GetTarget().GetAPIMutex());
439  sb_bp = loc_sp->GetBreakpoint().shared_from_this();
440  }
441 
442  return sb_bp;
443 }
lldb::SBBreakpointLocation
Definition: SBBreakpointLocation.h:17
lldb::SBStringList
Definition: SBStringList.h:16
Instrumentation.h
lldb::SBBreakpointLocation::GetThreadName
const char * GetThreadName() const
Definition: SBBreakpointLocation.cpp:347
lldb::SBBreakpointLocation::GetID
break_id_t GetID()
Definition: SBBreakpointLocation.cpp:418
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:176
lldb::SBStringList::GetSize
uint32_t GetSize() const
Definition: SBStringList.cpp:96
lldb::SBBreakpointLocation::SetQueueName
void SetQueueName(const char *queue_name)
Definition: SBBreakpointLocation.cpp:359
lldb::SBBreakpointLocation::~SBBreakpointLocation
~SBBreakpointLocation()
lldb_private::BreakpointOptions::CommandData
Definition: BreakpointOptions.h:45
SBDefines.h
lldb::SBBreakpointLocation::GetThreadIndex
uint32_t GetThreadIndex() const
Definition: SBBreakpointLocation.cpp:323
lldb::SBBreakpointLocation::IsEnabled
bool IsEnabled()
Definition: SBBreakpointLocation.cpp:108
lldb::SBBreakpointLocation::GetDescription
bool GetDescription(lldb::SBStream &description, DescriptionLevel level)
Definition: SBBreakpointLocation.cpp:400
lldb::SBError
Definition: SBError.h:20
lldb-defines.h
lldb::SBBreakpointLocation::IsResolved
bool IsResolved()
Definition: SBBreakpointLocation.cpp:382
SBStringList.h
BreakpointLocation.h
lldb::SBBreakpointLocation::SetThreadName
void SetThreadName(const char *thread_name)
Definition: SBBreakpointLocation.cpp:336
lldb::SBBreakpointLocation::SetThreadIndex
void SetThreadIndex(uint32_t index)
Definition: SBBreakpointLocation.cpp:312
lldb::SBBreakpointLocation::SetScriptCallbackBody
SBError SetScriptCallbackBody(const char *script_body_text)
Definition: SBBreakpointLocation.cpp:234
lldb::SBBreakpointLocation::GetThreadID
lldb::tid_t GetThreadID()
Definition: SBBreakpointLocation.cpp:299
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb::SBBreakpointLocation::operator=
const lldb::SBBreakpointLocation & operator=(const lldb::SBBreakpointLocation &rhs)
Definition: SBBreakpointLocation.cpp:48
Debugger.h
lldb::SBBreakpointLocation::SetScriptCallbackFunction
void SetScriptCallbackFunction(const char *callback_function_name)
Definition: SBBreakpointLocation.cpp:201
lldb::SBBreakpointLocation::GetBreakpoint
SBBreakpoint GetBreakpoint()
Definition: SBBreakpointLocation.cpp:430
lldb::SBStructuredData::m_impl_up
StructuredDataImplUP m_impl_up
Definition: SBStructuredData.h:104
lldb::eScriptLanguageNone
@ eScriptLanguageNone
Definition: lldb-enumerations.h:217
Target.h
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb::SBBreakpointLocation::GetHitCount
uint32_t GetHitCount()
Definition: SBBreakpointLocation.cpp:120
SBStream.h
lldb::SBBreakpointLocation::GetLoadAddress
lldb::addr_t GetLoadAddress()
Definition: SBBreakpointLocation.cpp:82
ThreadSpec.h
lldb::SBBreakpointLocation::GetSP
BreakpointLocationSP GetSP() const
Definition: SBBreakpointLocation.cpp:57
lldb::SBBreakpointLocation::GetAddress
lldb::SBAddress GetAddress()
Definition: SBBreakpointLocation.cpp:71
lldb::SBBreakpointLocation::SetIgnoreCount
void SetIgnoreCount(uint32_t n)
Definition: SBBreakpointLocation.cpp:144
lldb::break_id_t
int32_t break_id_t
Definition: lldb-types.h:88
lldb::SBBreakpointLocation::SetCondition
void SetCondition(const char *condition)
Definition: SBBreakpointLocation.cpp:155
lldb_private::StringList
Definition: StringList.h:26
lldb::SBBreakpointLocation::GetCommandLineCommands
bool GetCommandLineCommands(lldb::SBStringList &commands)
Definition: SBBreakpointLocation.cpp:274
lldb::SBError::SetErrorString
void SetErrorString(const char *err_str)
Definition: SBError.cpp:121
lldb_private::BreakpointOptions
Definition: BreakpointOptions.h:27
lldb::SBBreakpointLocation::m_opaque_wp
lldb::BreakpointLocationWP m_opaque_wp
Definition: SBBreakpointLocation.h:98
SBDebugger.h
lldb::SBBreakpointLocation::GetIgnoreCount
uint32_t GetIgnoreCount()
Definition: SBBreakpointLocation.cpp:132
lldb::SBError::SetError
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:95
lldb::SBBreakpointLocation::GetAutoContinue
bool GetAutoContinue()
Definition: SBBreakpointLocation.cpp:189
SBAddress.h
lldb::SBBreakpointLocation::GetCondition
const char * GetCondition()
Definition: SBBreakpointLocation.cpp:166
LLDB_INVALID_BREAK_ID
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:37
lldb-types.h
StreamFile.h
lldb_private::Status
Definition: Status.h:44
uint32_t
lldb::SBStructuredData
Definition: SBStructuredData.h:17
lldb::SBBreakpoint
Definition: SBBreakpoint.h:18
lldb_private::Stream::EOL
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:128
SBBreakpointLocation.h
lldb::SBBreakpointLocation::GetQueueName
const char * GetQueueName() const
Definition: SBBreakpointLocation.cpp:370
lldb::SBBreakpointLocation::IsValid
bool IsValid() const
Definition: SBBreakpointLocation.cpp:61
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:19
lldb::SBBreakpointLocation::SetThreadID
void SetThreadID(lldb::tid_t sb_thread_id)
Definition: SBBreakpointLocation.cpp:288
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
SBStructuredData.h
StructuredDataImpl.h
lldb::SBAddress
Definition: SBAddress.h:17
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBBreakpointLocation::SetAutoContinue
void SetAutoContinue(bool auto_continue)
Definition: SBBreakpointLocation.cpp:178
Breakpoint.h
lldb::SBBreakpointLocation::SetEnabled
void SetEnabled(bool enabled)
Definition: SBBreakpointLocation.cpp:97
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
CommandInterpreter.h
lldb::SBBreakpointLocation::SetLocation
void SetLocation(const lldb::BreakpointLocationSP &break_loc_sp)
Definition: SBBreakpointLocation.cpp:394
LLDB_INVALID_THREAD_ID
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:82
Stream.h
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb::SBStream
Definition: SBStream.h:18
lldb::SBAddress
class LLDB_API SBAddress
Definition: SBDefines.h:33
lldb::SBBreakpointLocation::SBBreakpointLocation
SBBreakpointLocation()
Definition: SBBreakpointLocation.cpp:34
ScriptInterpreter.h
lldb
Definition: SBAddress.h:15
lldb::SBBreakpointLocation::SetCommandLineCommands
void SetCommandLineCommands(lldb::SBStringList &commands)
Definition: SBBreakpointLocation.cpp:257
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:207
lldb::SBStringList::AppendList
void AppendList(const char **strv, int strc)
Definition: SBStringList.cpp:69
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86