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 "Utils.h"
11#include "lldb/API/SBAddress.h"
12#include "lldb/API/SBDebugger.h"
13#include "lldb/API/SBDefines.h"
14#include "lldb/API/SBStream.h"
18
21#include "lldb/Core/Debugger.h"
25#include "lldb/Target/Target.h"
27#include "lldb/Utility/Stream.h"
28#include "lldb/lldb-defines.h"
29#include "lldb/lldb-types.h"
30
32
33using namespace lldb;
34using 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
48
51 LLDB_INSTRUMENT_VA(this, rhs);
52
54 return *this;
55}
56
58
62
65 return this->operator bool();
66}
67SBBreakpointLocation::operator bool() const {
69
70 return bool(GetSP());
71}
72
75
76 BreakpointLocationSP loc_sp = GetSP();
77 if (loc_sp) {
78 return SBAddress(loc_sp->GetAddress());
79 }
80
81 return SBAddress();
82}
83
86
88 BreakpointLocationSP loc_sp = GetSP();
89
90 if (loc_sp) {
91 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
92 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
105 std::lock_guard<TargetAPIMutex> guard(api_lock);
106 llvm::consumeError(loc_sp->SetEnabled(enabled));
107 }
108}
109
111 LLDB_INSTRUMENT_VA(this);
112
113 BreakpointLocationSP loc_sp = GetSP();
114 if (loc_sp) {
115 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
116 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
128 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
140 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
152 std::lock_guard<TargetAPIMutex> guard(api_lock);
153 loc_sp->SetIgnoreCount(n);
154 }
155}
156
157void SBBreakpointLocation::SetCondition(const char *condition) {
158 LLDB_INSTRUMENT_VA(this, condition);
159
160 BreakpointLocationSP loc_sp = GetSP();
161 if (loc_sp) {
162 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
163 std::lock_guard<TargetAPIMutex> guard(api_lock);
164 // Treat a nullptr as clearing the condition
165 if (!condition)
166 loc_sp->SetCondition(StopCondition());
167 else
168 loc_sp->SetCondition(StopCondition(condition));
169 }
170}
171
173 LLDB_INSTRUMENT_VA(this);
174
175 BreakpointLocationSP loc_sp = GetSP();
176 if (!loc_sp)
177 return nullptr;
178
179 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
180 std::lock_guard<TargetAPIMutex> guard(api_lock);
181 StopCondition cond = loc_sp->GetCondition();
182 if (!cond)
183 return nullptr;
184 return GetDebuggerStringPool(loc_sp->GetTarget()).Intern(cond.GetText());
185}
186
188 LLDB_INSTRUMENT_VA(this, auto_continue);
189
190 BreakpointLocationSP loc_sp = GetSP();
191 if (loc_sp) {
192 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
193 std::lock_guard<TargetAPIMutex> guard(api_lock);
194 loc_sp->SetAutoContinue(auto_continue);
195 }
196}
197
199 LLDB_INSTRUMENT_VA(this);
200
201 BreakpointLocationSP loc_sp = GetSP();
202 if (loc_sp) {
203 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
204 std::lock_guard<TargetAPIMutex> guard(api_lock);
205 return loc_sp->IsAutoContinue();
206 }
207 return false;
208}
209
211 void *baton) {
212 LLDB_INSTRUMENT_VA(this, callback, baton);
213
214 BreakpointLocationSP loc_sp = GetSP();
215
216 if (loc_sp) {
217 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
218 std::lock_guard<TargetAPIMutex> guard(api_lock);
219 BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
221 baton_sp, false);
222 }
223}
224
226 const char *callback_function_name) {
227 LLDB_INSTRUMENT_VA(this, callback_function_name);
228}
229
231 const char *callback_function_name,
232 SBStructuredData &extra_args) {
233 LLDB_INSTRUMENT_VA(this, callback_function_name, extra_args);
234 SBError sb_error;
235 BreakpointLocationSP loc_sp = GetSP();
236
237 if (loc_sp) {
238 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
239 std::lock_guard<TargetAPIMutex> guard(api_lock);
240 BreakpointOptions &bp_options = loc_sp->GetLocationOptions();
241 llvm::Error error = loc_sp->GetBreakpoint()
242 .GetTarget()
243 .GetDebugger()
244 .GetScriptInterpreter()
245 ->SetBreakpointCommandCallbackFunction(
246 bp_options, callback_function_name,
247 extra_args.m_impl_up->GetObjectSP());
248 sb_error.SetError(Status::FromError(std::move(error)));
249 } else
250 sb_error = Status::FromErrorString("invalid breakpoint");
251
252 return sb_error;
253}
254
256SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
257 LLDB_INSTRUMENT_VA(this, callback_body_text);
258
259 BreakpointLocationSP loc_sp = GetSP();
260
261 SBError sb_error;
262 if (loc_sp) {
263 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
264 std::lock_guard<TargetAPIMutex> guard(api_lock);
265 BreakpointOptions &bp_options = loc_sp->GetLocationOptions();
266 llvm::Error error =
267 loc_sp->GetBreakpoint()
268 .GetTarget()
269 .GetDebugger()
270 .GetScriptInterpreter()
271 ->SetBreakpointCommandCallback(bp_options, callback_body_text,
272 /*is_callback=*/false);
273 sb_error.SetError(Status::FromError(std::move(error)));
274 } else
275 sb_error = Status::FromErrorString("invalid breakpoint");
276
277 return sb_error;
278}
279
281 LLDB_INSTRUMENT_VA(this, commands);
282
283 BreakpointLocationSP loc_sp = GetSP();
284 if (!loc_sp)
285 return;
286 if (commands.GetSize() == 0)
287 return;
288
289 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
290 std::lock_guard<TargetAPIMutex> guard(api_lock);
291 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
293
294 loc_sp->GetLocationOptions().SetCommandDataCallback(cmd_data_up);
295}
296
298 LLDB_INSTRUMENT_VA(this, commands);
299
300 BreakpointLocationSP loc_sp = GetSP();
301 if (!loc_sp)
302 return false;
303 StringList command_list;
304 bool has_commands =
305 loc_sp->GetLocationOptions().GetCommandLineCallbacks(command_list);
306 if (has_commands)
307 commands.AppendList(command_list);
308 return has_commands;
309}
310
312 LLDB_INSTRUMENT_VA(this, thread_id);
313
314 BreakpointLocationSP loc_sp = GetSP();
315 if (loc_sp) {
316 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
317 std::lock_guard<TargetAPIMutex> guard(api_lock);
318 loc_sp->SetThreadID(thread_id);
319 }
320}
321
323 LLDB_INSTRUMENT_VA(this);
324
326 BreakpointLocationSP loc_sp = GetSP();
327 if (loc_sp) {
328 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
329 std::lock_guard<TargetAPIMutex> guard(api_lock);
330 return loc_sp->GetThreadID();
331 }
332 return tid;
333}
334
336 LLDB_INSTRUMENT_VA(this, index);
337
338 BreakpointLocationSP loc_sp = GetSP();
339 if (loc_sp) {
340 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
341 std::lock_guard<TargetAPIMutex> guard(api_lock);
342 loc_sp->SetThreadIndex(index);
343 }
344}
345
347 LLDB_INSTRUMENT_VA(this);
348
349 uint32_t thread_idx = UINT32_MAX;
350 BreakpointLocationSP loc_sp = GetSP();
351 if (loc_sp) {
352 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
353 std::lock_guard<TargetAPIMutex> guard(api_lock);
354 return loc_sp->GetThreadIndex();
355 }
356 return thread_idx;
357}
358
359void SBBreakpointLocation::SetThreadName(const char *thread_name) {
360 LLDB_INSTRUMENT_VA(this, thread_name);
361
362 BreakpointLocationSP loc_sp = GetSP();
363 if (loc_sp) {
364 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
365 std::lock_guard<TargetAPIMutex> guard(api_lock);
366 loc_sp->SetThreadName(thread_name);
367 }
368}
369
371 LLDB_INSTRUMENT_VA(this);
372
373 BreakpointLocationSP loc_sp = GetSP();
374 if (!loc_sp)
375 return nullptr;
376
377 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
378 std::lock_guard<TargetAPIMutex> guard(api_lock);
379 return GetDebuggerStringPool(loc_sp->GetTarget())
380 .Intern(loc_sp->GetThreadName());
381}
382
383void SBBreakpointLocation::SetQueueName(const char *queue_name) {
384 LLDB_INSTRUMENT_VA(this, queue_name);
385
386 BreakpointLocationSP loc_sp = GetSP();
387 if (loc_sp) {
388 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
389 std::lock_guard<TargetAPIMutex> guard(api_lock);
390 loc_sp->SetQueueName(queue_name);
391 }
392}
393
395 LLDB_INSTRUMENT_VA(this);
396
397 BreakpointLocationSP loc_sp = GetSP();
398 if (!loc_sp)
399 return nullptr;
400
401 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
402 std::lock_guard<TargetAPIMutex> guard(api_lock);
403 return GetDebuggerStringPool(loc_sp->GetTarget())
404 .Intern(loc_sp->GetQueueName());
405}
406
408 LLDB_INSTRUMENT_VA(this);
409
410 BreakpointLocationSP loc_sp = GetSP();
411 if (loc_sp) {
412 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
413 std::lock_guard<TargetAPIMutex> guard(api_lock);
414 return loc_sp->IsResolved();
415 }
416 return false;
417}
418
420 const lldb::BreakpointLocationSP &break_loc_sp) {
421 // Uninstall the callbacks?
422 m_opaque_wp = break_loc_sp;
423}
424
426 DescriptionLevel level) {
427 LLDB_INSTRUMENT_VA(this, description, level);
428
429 Stream &strm = description.ref();
430 BreakpointLocationSP loc_sp = GetSP();
431
432 if (loc_sp) {
433 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
434 std::lock_guard<TargetAPIMutex> guard(api_lock);
435 loc_sp->GetDescription(&strm, level);
436 strm.EOL();
437 } else
438 strm.PutCString("No value");
439
440 return true;
441}
442
444 LLDB_INSTRUMENT_VA(this);
445
446 BreakpointLocationSP loc_sp = GetSP();
447 if (loc_sp) {
448 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
449 std::lock_guard<TargetAPIMutex> guard(api_lock);
450 return loc_sp->GetID();
451 } else
453}
454
456 LLDB_INSTRUMENT_VA(this);
457
458 BreakpointLocationSP loc_sp = GetSP();
459
460 SBBreakpoint sb_bp;
461 if (loc_sp) {
462 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
463 std::lock_guard<TargetAPIMutex> guard(api_lock);
464 sb_bp = loc_sp->GetBreakpoint().shared_from_this();
465 }
466
467 return sb_bp;
468}
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)
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)
BreakpointLocationSP GetSP() const
void SetThreadName(const char *thread_name)
void SetError(uint32_t err, lldb::ErrorType type)
Definition SBError.cpp:124
lldb_private::Stream & ref()
Definition SBStream.cpp:179
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...
static Status FromErrorString(const char *str)
Definition Status.h:141
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:136
llvm::StringRef GetText() const
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:63
size_t EOL()
Output and End of Line character to the stream.
Definition Stream.cpp:155
const char * Intern(llvm::StringRef str) const
Definition StringPool.h:78
A Lockable handle over a Target's API mutex, returned by Target::GetAPIMutex() and backing the public...
#define LLDB_INVALID_BREAK_ID
#define LLDB_INVALID_THREAD_ID
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
A class that represents a running process on the host machine.
StringPoolRef GetDebuggerStringPool(const Target &target)
Strings interned here live as long as target's debugger.
Definition Utils.h:21
@ eScriptLanguageNone
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
int32_t break_id_t
Definition lldb-types.h:88
std::shared_ptr< lldb_private::Baton > BatonSP
bool(* SBBreakpointHitCallback)(void *baton, lldb::SBProcess &process, lldb::SBThread &thread, lldb::SBBreakpointLocation &location)
Definition SBDefines.h:145
class LLDB_API SBAddress
Definition SBDefines.h:45
uint64_t addr_t
Definition lldb-types.h:80
uint64_t tid_t
Definition lldb-types.h:85