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