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"
17
20#include "lldb/Core/Debugger.h"
24#include "lldb/Target/Target.h"
26#include "lldb/Utility/Stream.h"
27#include "lldb/lldb-defines.h"
28#include "lldb/lldb-types.h"
29
31
32using namespace lldb;
33using namespace lldb_private;
34
36
38 const lldb::BreakpointLocationSP &break_loc_sp)
39 : m_opaque_wp(break_loc_sp) {
40 LLDB_INSTRUMENT_VA(this, break_loc_sp);
41}
42
44 : m_opaque_wp(rhs.m_opaque_wp) {
45 LLDB_INSTRUMENT_VA(this, rhs);
46}
47
50 LLDB_INSTRUMENT_VA(this, rhs);
51
53 return *this;
54}
55
57
59 return m_opaque_wp.lock();
60}
61
64 return this->operator bool();
65}
66SBBreakpointLocation::operator bool() const {
68
69 return bool(GetSP());
70}
71
74
75 BreakpointLocationSP loc_sp = GetSP();
76 if (loc_sp) {
77 return SBAddress(loc_sp->GetAddress());
78 }
79
80 return SBAddress();
81}
82
85
87 BreakpointLocationSP loc_sp = GetSP();
88
89 if (loc_sp) {
90 std::lock_guard<std::recursive_mutex> guard(
91 loc_sp->GetTarget().GetAPIMutex());
92 ret_addr = loc_sp->GetLoadAddress();
93 }
94
95 return ret_addr;
96}
97
99 LLDB_INSTRUMENT_VA(this, enabled);
100
101 BreakpointLocationSP loc_sp = GetSP();
102 if (loc_sp) {
103 std::lock_guard<std::recursive_mutex> guard(
104 loc_sp->GetTarget().GetAPIMutex());
105 loc_sp->SetEnabled(enabled);
106 }
107}
108
110 LLDB_INSTRUMENT_VA(this);
111
112 BreakpointLocationSP loc_sp = GetSP();
113 if (loc_sp) {
114 std::lock_guard<std::recursive_mutex> guard(
115 loc_sp->GetTarget().GetAPIMutex());
116 return loc_sp->IsEnabled();
117 } else
118 return false;
119}
120
122 LLDB_INSTRUMENT_VA(this);
123
124 BreakpointLocationSP loc_sp = GetSP();
125 if (loc_sp) {
126 std::lock_guard<std::recursive_mutex> guard(
127 loc_sp->GetTarget().GetAPIMutex());
128 return loc_sp->GetHitCount();
129 } else
130 return 0;
131}
132
134 LLDB_INSTRUMENT_VA(this);
135
136 BreakpointLocationSP loc_sp = GetSP();
137 if (loc_sp) {
138 std::lock_guard<std::recursive_mutex> guard(
139 loc_sp->GetTarget().GetAPIMutex());
140 return loc_sp->GetIgnoreCount();
141 } else
142 return 0;
143}
144
146 LLDB_INSTRUMENT_VA(this, n);
147
148 BreakpointLocationSP loc_sp = GetSP();
149 if (loc_sp) {
150 std::lock_guard<std::recursive_mutex> guard(
151 loc_sp->GetTarget().GetAPIMutex());
152 loc_sp->SetIgnoreCount(n);
153 }
154}
155
156void SBBreakpointLocation::SetCondition(const char *condition) {
157 LLDB_INSTRUMENT_VA(this, condition);
158
159 BreakpointLocationSP loc_sp = GetSP();
160 if (loc_sp) {
161 std::lock_guard<std::recursive_mutex> guard(
162 loc_sp->GetTarget().GetAPIMutex());
163 loc_sp->SetCondition(condition);
164 }
165}
166
168 LLDB_INSTRUMENT_VA(this);
169
170 BreakpointLocationSP loc_sp = GetSP();
171 if (!loc_sp)
172 return nullptr;
173
174 std::lock_guard<std::recursive_mutex> guard(
175 loc_sp->GetTarget().GetAPIMutex());
176 return ConstString(loc_sp->GetConditionText()).GetCString();
177}
178
180 LLDB_INSTRUMENT_VA(this, auto_continue);
181
182 BreakpointLocationSP loc_sp = GetSP();
183 if (loc_sp) {
184 std::lock_guard<std::recursive_mutex> guard(
185 loc_sp->GetTarget().GetAPIMutex());
186 loc_sp->SetAutoContinue(auto_continue);
187 }
188}
189
191 LLDB_INSTRUMENT_VA(this);
192
193 BreakpointLocationSP loc_sp = GetSP();
194 if (loc_sp) {
195 std::lock_guard<std::recursive_mutex> guard(
196 loc_sp->GetTarget().GetAPIMutex());
197 return loc_sp->IsAutoContinue();
198 }
199 return false;
200}
201
203 void *baton) {
204 LLDB_INSTRUMENT_VA(this, callback, baton);
205
206 BreakpointLocationSP loc_sp = GetSP();
207
208 if (loc_sp) {
209 std::lock_guard<std::recursive_mutex> guard(
210 loc_sp->GetTarget().GetAPIMutex());
211 BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
213 baton_sp, false);
214 }
215}
216
218 const char *callback_function_name) {
219 LLDB_INSTRUMENT_VA(this, callback_function_name);
220}
221
223 const char *callback_function_name,
224 SBStructuredData &extra_args) {
225 LLDB_INSTRUMENT_VA(this, callback_function_name, extra_args);
226 SBError sb_error;
227 BreakpointLocationSP loc_sp = GetSP();
228
229 if (loc_sp) {
231 std::lock_guard<std::recursive_mutex> guard(
232 loc_sp->GetTarget().GetAPIMutex());
233 BreakpointOptions &bp_options = loc_sp->GetLocationOptions();
234 error = loc_sp->GetBreakpoint()
235 .GetTarget()
236 .GetDebugger()
237 .GetScriptInterpreter()
238 ->SetBreakpointCommandCallbackFunction(bp_options,
239 callback_function_name,
240 extra_args.m_impl_up
241 ->GetObjectSP());
242 sb_error.SetError(std::move(error));
243 } else
244 sb_error = Status::FromErrorString("invalid breakpoint");
245
246 return sb_error;
247}
248
250SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
251 LLDB_INSTRUMENT_VA(this, callback_body_text);
252
253 BreakpointLocationSP loc_sp = GetSP();
254
255 SBError sb_error;
256 if (loc_sp) {
257 std::lock_guard<std::recursive_mutex> guard(
258 loc_sp->GetTarget().GetAPIMutex());
259 BreakpointOptions &bp_options = loc_sp->GetLocationOptions();
260 Status error =
261 loc_sp->GetBreakpoint()
262 .GetTarget()
263 .GetDebugger()
264 .GetScriptInterpreter()
265 ->SetBreakpointCommandCallback(bp_options, callback_body_text,
266 /*is_callback=*/false);
267 sb_error.SetError(std::move(error));
268 } else
269 sb_error = Status::FromErrorString("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
353void 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 return nullptr;
370
371 std::lock_guard<std::recursive_mutex> guard(
372 loc_sp->GetTarget().GetAPIMutex());
373 return ConstString(loc_sp->GetThreadName()).GetCString();
374}
375
376void 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 return nullptr;
393
394 std::lock_guard<std::recursive_mutex> guard(
395 loc_sp->GetTarget().GetAPIMutex());
396 return ConstString(loc_sp->GetQueueName()).GetCString();
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
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}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT_VA(...)
static bool PrivateBreakpointHitCallback(void *baton, lldb_private::StoppointCallbackContext *ctx, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
void SetCondition(const char *condition)
void SetCallback(SBBreakpointHitCallback callback, void *baton)
void SetQueueName(const char *queue_name)
const char * GetThreadName() const
bool GetCommandLineCommands(lldb::SBStringList &commands)
void SetLocation(const lldb::BreakpointLocationSP &break_loc_sp)
void SetScriptCallbackFunction(const char *callback_function_name)
lldb::BreakpointLocationWP m_opaque_wp
void SetCommandLineCommands(lldb::SBStringList &commands)
SBError SetScriptCallbackBody(const char *script_body_text)
bool GetDescription(lldb::SBStream &description, DescriptionLevel level)
const lldb::SBBreakpointLocation & operator=(const lldb::SBBreakpointLocation &rhs)
void SetThreadID(lldb::tid_t sb_thread_id)
void SetAutoContinue(bool auto_continue)
void SetThreadIndex(uint32_t index)
BreakpointLocationSP GetSP() const
void SetThreadName(const char *thread_name)
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:110
lldb_private::Stream & ref()
Definition: SBStream.cpp:177
uint32_t GetSize() const
void AppendList(const char **strv, int strc)
StructuredDataImplUP m_impl_up
"lldb/Breakpoint/BreakpointOptions.h" Class that manages the options on a breakpoint or breakpoint lo...
A uniqued constant string class.
Definition: ConstString.h:40
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
An error handling class.
Definition: Status.h:115
static Status FromErrorString(const char *str)
Definition: Status.h:138
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:155
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:37
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:90
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
#define UINT32_MAX
Definition: lldb-defines.h:19
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
@ eScriptLanguageNone
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
Definition: lldb-forward.h:324
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
int32_t break_id_t
Definition: lldb-types.h:86
std::shared_ptr< lldb_private::Baton > BatonSP
Definition: lldb-forward.h:319
bool(* SBBreakpointHitCallback)(void *baton, lldb::SBProcess &process, lldb::SBThread &thread, lldb::SBBreakpointLocation &location)
Definition: SBDefines.h:139
uint64_t addr_t
Definition: lldb-types.h:80
uint64_t tid_t
Definition: lldb-types.h:84