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
47
50 LLDB_INSTRUMENT_VA(this, rhs);
51
53 return *this;
54}
55
57
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 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
91 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
104 std::lock_guard<TargetAPIMutex> guard(api_lock);
105 llvm::consumeError(loc_sp->SetEnabled(enabled));
106 }
107}
108
110 LLDB_INSTRUMENT_VA(this);
111
112 BreakpointLocationSP loc_sp = GetSP();
113 if (loc_sp) {
114 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
115 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
127 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
139 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
151 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
162 std::lock_guard<TargetAPIMutex> guard(api_lock);
163 // Treat a nullptr as clearing the condition
164 if (!condition)
165 loc_sp->SetCondition(StopCondition());
166 else
167 loc_sp->SetCondition(StopCondition(condition));
168 }
169}
170
172 LLDB_INSTRUMENT_VA(this);
173
174 BreakpointLocationSP loc_sp = GetSP();
175 if (!loc_sp)
176 return nullptr;
177
178 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
179 std::lock_guard<TargetAPIMutex> guard(api_lock);
180 StopCondition cond = loc_sp->GetCondition();
181 if (!cond)
182 return nullptr;
183 return ConstString(cond.GetText()).GetCString();
184}
185
187 LLDB_INSTRUMENT_VA(this, auto_continue);
188
189 BreakpointLocationSP loc_sp = GetSP();
190 if (loc_sp) {
191 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
192 std::lock_guard<TargetAPIMutex> guard(api_lock);
193 loc_sp->SetAutoContinue(auto_continue);
194 }
195}
196
198 LLDB_INSTRUMENT_VA(this);
199
200 BreakpointLocationSP loc_sp = GetSP();
201 if (loc_sp) {
202 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
203 std::lock_guard<TargetAPIMutex> guard(api_lock);
204 return loc_sp->IsAutoContinue();
205 }
206 return false;
207}
208
210 void *baton) {
211 LLDB_INSTRUMENT_VA(this, callback, baton);
212
213 BreakpointLocationSP loc_sp = GetSP();
214
215 if (loc_sp) {
216 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
217 std::lock_guard<TargetAPIMutex> guard(api_lock);
218 BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
220 baton_sp, false);
221 }
222}
223
225 const char *callback_function_name) {
226 LLDB_INSTRUMENT_VA(this, callback_function_name);
227}
228
230 const char *callback_function_name,
231 SBStructuredData &extra_args) {
232 LLDB_INSTRUMENT_VA(this, callback_function_name, extra_args);
233 SBError sb_error;
234 BreakpointLocationSP loc_sp = GetSP();
235
236 if (loc_sp) {
237 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
238 std::lock_guard<TargetAPIMutex> guard(api_lock);
239 BreakpointOptions &bp_options = loc_sp->GetLocationOptions();
240 llvm::Error error = loc_sp->GetBreakpoint()
241 .GetTarget()
242 .GetDebugger()
243 .GetScriptInterpreter()
244 ->SetBreakpointCommandCallbackFunction(
245 bp_options, callback_function_name,
246 extra_args.m_impl_up->GetObjectSP());
247 sb_error.SetError(Status::FromError(std::move(error)));
248 } else
249 sb_error = Status::FromErrorString("invalid breakpoint");
250
251 return sb_error;
252}
253
255SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
256 LLDB_INSTRUMENT_VA(this, callback_body_text);
257
258 BreakpointLocationSP loc_sp = GetSP();
259
260 SBError sb_error;
261 if (loc_sp) {
262 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
263 std::lock_guard<TargetAPIMutex> guard(api_lock);
264 BreakpointOptions &bp_options = loc_sp->GetLocationOptions();
265 llvm::Error error =
266 loc_sp->GetBreakpoint()
267 .GetTarget()
268 .GetDebugger()
269 .GetScriptInterpreter()
270 ->SetBreakpointCommandCallback(bp_options, callback_body_text,
271 /*is_callback=*/false);
272 sb_error.SetError(Status::FromError(std::move(error)));
273 } else
274 sb_error = Status::FromErrorString("invalid breakpoint");
275
276 return sb_error;
277}
278
280 LLDB_INSTRUMENT_VA(this, commands);
281
282 BreakpointLocationSP loc_sp = GetSP();
283 if (!loc_sp)
284 return;
285 if (commands.GetSize() == 0)
286 return;
287
288 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
289 std::lock_guard<TargetAPIMutex> guard(api_lock);
290 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
292
293 loc_sp->GetLocationOptions().SetCommandDataCallback(cmd_data_up);
294}
295
297 LLDB_INSTRUMENT_VA(this, commands);
298
299 BreakpointLocationSP loc_sp = GetSP();
300 if (!loc_sp)
301 return false;
302 StringList command_list;
303 bool has_commands =
304 loc_sp->GetLocationOptions().GetCommandLineCallbacks(command_list);
305 if (has_commands)
306 commands.AppendList(command_list);
307 return has_commands;
308}
309
311 LLDB_INSTRUMENT_VA(this, thread_id);
312
313 BreakpointLocationSP loc_sp = GetSP();
314 if (loc_sp) {
315 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
316 std::lock_guard<TargetAPIMutex> guard(api_lock);
317 loc_sp->SetThreadID(thread_id);
318 }
319}
320
322 LLDB_INSTRUMENT_VA(this);
323
325 BreakpointLocationSP loc_sp = GetSP();
326 if (loc_sp) {
327 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
328 std::lock_guard<TargetAPIMutex> guard(api_lock);
329 return loc_sp->GetThreadID();
330 }
331 return tid;
332}
333
335 LLDB_INSTRUMENT_VA(this, index);
336
337 BreakpointLocationSP loc_sp = GetSP();
338 if (loc_sp) {
339 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
340 std::lock_guard<TargetAPIMutex> guard(api_lock);
341 loc_sp->SetThreadIndex(index);
342 }
343}
344
346 LLDB_INSTRUMENT_VA(this);
347
348 uint32_t thread_idx = UINT32_MAX;
349 BreakpointLocationSP loc_sp = GetSP();
350 if (loc_sp) {
351 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
352 std::lock_guard<TargetAPIMutex> guard(api_lock);
353 return loc_sp->GetThreadIndex();
354 }
355 return thread_idx;
356}
357
358void SBBreakpointLocation::SetThreadName(const char *thread_name) {
359 LLDB_INSTRUMENT_VA(this, thread_name);
360
361 BreakpointLocationSP loc_sp = GetSP();
362 if (loc_sp) {
363 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
364 std::lock_guard<TargetAPIMutex> guard(api_lock);
365 loc_sp->SetThreadName(thread_name);
366 }
367}
368
370 LLDB_INSTRUMENT_VA(this);
371
372 BreakpointLocationSP loc_sp = GetSP();
373 if (!loc_sp)
374 return nullptr;
375
376 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
377 std::lock_guard<TargetAPIMutex> guard(api_lock);
378 return ConstString(loc_sp->GetThreadName()).GetCString();
379}
380
381void SBBreakpointLocation::SetQueueName(const char *queue_name) {
382 LLDB_INSTRUMENT_VA(this, queue_name);
383
384 BreakpointLocationSP loc_sp = GetSP();
385 if (loc_sp) {
386 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
387 std::lock_guard<TargetAPIMutex> guard(api_lock);
388 loc_sp->SetQueueName(queue_name);
389 }
390}
391
393 LLDB_INSTRUMENT_VA(this);
394
395 BreakpointLocationSP loc_sp = GetSP();
396 if (!loc_sp)
397 return nullptr;
398
399 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
400 std::lock_guard<TargetAPIMutex> guard(api_lock);
401 return ConstString(loc_sp->GetQueueName()).GetCString();
402}
403
405 LLDB_INSTRUMENT_VA(this);
406
407 BreakpointLocationSP loc_sp = GetSP();
408 if (loc_sp) {
409 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
410 std::lock_guard<TargetAPIMutex> guard(api_lock);
411 return loc_sp->IsResolved();
412 }
413 return false;
414}
415
417 const lldb::BreakpointLocationSP &break_loc_sp) {
418 // Uninstall the callbacks?
419 m_opaque_wp = break_loc_sp;
420}
421
423 DescriptionLevel level) {
424 LLDB_INSTRUMENT_VA(this, description, level);
425
426 Stream &strm = description.ref();
427 BreakpointLocationSP loc_sp = GetSP();
428
429 if (loc_sp) {
430 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
431 std::lock_guard<TargetAPIMutex> guard(api_lock);
432 loc_sp->GetDescription(&strm, level);
433 strm.EOL();
434 } else
435 strm.PutCString("No value");
436
437 return true;
438}
439
441 LLDB_INSTRUMENT_VA(this);
442
443 BreakpointLocationSP loc_sp = GetSP();
444 if (loc_sp) {
445 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
446 std::lock_guard<TargetAPIMutex> guard(api_lock);
447 return loc_sp->GetID();
448 } else
450}
451
453 LLDB_INSTRUMENT_VA(this);
454
455 BreakpointLocationSP loc_sp = GetSP();
456
457 SBBreakpoint sb_bp;
458 if (loc_sp) {
459 TargetAPIMutex api_lock = loc_sp->GetTarget().GetAPIMutex();
460 std::lock_guard<TargetAPIMutex> guard(api_lock);
461 sb_bp = loc_sp->GetBreakpoint().shared_from_this();
462 }
463
464 return sb_bp;
465}
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...
A uniqued constant string class.
Definition ConstString.h:40
const char * GetCString() const
Get the string value as a C string.
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
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.
@ 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:144
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