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"
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
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
59BreakpointLocationSP SBBreakpointLocation::GetSP() const {
60 return m_opaque_wp.lock();
61}
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 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
157void 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 return nullptr;
174
175 std::lock_guard<std::recursive_mutex> guard(
176 loc_sp->GetTarget().GetAPIMutex());
177 return ConstString(loc_sp->GetConditionText()).GetCString();
178}
179
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) {
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
251SBBreakpointLocation::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 /*is_callback=*/false);
268 sb_error.SetError(error);
269 } else
270 sb_error.SetErrorString("invalid breakpoint");
271
272 return sb_error;
273}
274
276 LLDB_INSTRUMENT_VA(this, commands);
277
278 BreakpointLocationSP loc_sp = GetSP();
279 if (!loc_sp)
280 return;
281 if (commands.GetSize() == 0)
282 return;
283
284 std::lock_guard<std::recursive_mutex> guard(
285 loc_sp->GetTarget().GetAPIMutex());
286 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
288
289 loc_sp->GetLocationOptions().SetCommandDataCallback(cmd_data_up);
290}
291
293 LLDB_INSTRUMENT_VA(this, commands);
294
295 BreakpointLocationSP loc_sp = GetSP();
296 if (!loc_sp)
297 return false;
298 StringList command_list;
299 bool has_commands =
300 loc_sp->GetLocationOptions().GetCommandLineCallbacks(command_list);
301 if (has_commands)
302 commands.AppendList(command_list);
303 return has_commands;
304}
305
307 LLDB_INSTRUMENT_VA(this, thread_id);
308
309 BreakpointLocationSP loc_sp = GetSP();
310 if (loc_sp) {
311 std::lock_guard<std::recursive_mutex> guard(
312 loc_sp->GetTarget().GetAPIMutex());
313 loc_sp->SetThreadID(thread_id);
314 }
315}
316
318 LLDB_INSTRUMENT_VA(this);
319
321 BreakpointLocationSP loc_sp = GetSP();
322 if (loc_sp) {
323 std::lock_guard<std::recursive_mutex> guard(
324 loc_sp->GetTarget().GetAPIMutex());
325 return loc_sp->GetThreadID();
326 }
327 return tid;
328}
329
331 LLDB_INSTRUMENT_VA(this, index);
332
333 BreakpointLocationSP loc_sp = GetSP();
334 if (loc_sp) {
335 std::lock_guard<std::recursive_mutex> guard(
336 loc_sp->GetTarget().GetAPIMutex());
337 loc_sp->SetThreadIndex(index);
338 }
339}
340
342 LLDB_INSTRUMENT_VA(this);
343
344 uint32_t thread_idx = UINT32_MAX;
345 BreakpointLocationSP loc_sp = GetSP();
346 if (loc_sp) {
347 std::lock_guard<std::recursive_mutex> guard(
348 loc_sp->GetTarget().GetAPIMutex());
349 return loc_sp->GetThreadIndex();
350 }
351 return thread_idx;
352}
353
354void SBBreakpointLocation::SetThreadName(const char *thread_name) {
355 LLDB_INSTRUMENT_VA(this, thread_name);
356
357 BreakpointLocationSP loc_sp = GetSP();
358 if (loc_sp) {
359 std::lock_guard<std::recursive_mutex> guard(
360 loc_sp->GetTarget().GetAPIMutex());
361 loc_sp->SetThreadName(thread_name);
362 }
363}
364
366 LLDB_INSTRUMENT_VA(this);
367
368 BreakpointLocationSP loc_sp = GetSP();
369 if (!loc_sp)
370 return nullptr;
371
372 std::lock_guard<std::recursive_mutex> guard(
373 loc_sp->GetTarget().GetAPIMutex());
374 return ConstString(loc_sp->GetThreadName()).GetCString();
375}
376
377void SBBreakpointLocation::SetQueueName(const char *queue_name) {
378 LLDB_INSTRUMENT_VA(this, queue_name);
379
380 BreakpointLocationSP loc_sp = GetSP();
381 if (loc_sp) {
382 std::lock_guard<std::recursive_mutex> guard(
383 loc_sp->GetTarget().GetAPIMutex());
384 loc_sp->SetQueueName(queue_name);
385 }
386}
387
389 LLDB_INSTRUMENT_VA(this);
390
391 BreakpointLocationSP loc_sp = GetSP();
392 if (!loc_sp)
393 return nullptr;
394
395 std::lock_guard<std::recursive_mutex> guard(
396 loc_sp->GetTarget().GetAPIMutex());
397 return ConstString(loc_sp->GetQueueName()).GetCString();
398}
399
401 LLDB_INSTRUMENT_VA(this);
402
403 BreakpointLocationSP loc_sp = GetSP();
404 if (loc_sp) {
405 std::lock_guard<std::recursive_mutex> guard(
406 loc_sp->GetTarget().GetAPIMutex());
407 return loc_sp->IsResolved();
408 }
409 return false;
410}
411
413 const lldb::BreakpointLocationSP &break_loc_sp) {
414 // Uninstall the callbacks?
415 m_opaque_wp = break_loc_sp;
416}
417
419 DescriptionLevel level) {
420 LLDB_INSTRUMENT_VA(this, description, level);
421
422 Stream &strm = description.ref();
423 BreakpointLocationSP loc_sp = GetSP();
424
425 if (loc_sp) {
426 std::lock_guard<std::recursive_mutex> guard(
427 loc_sp->GetTarget().GetAPIMutex());
428 loc_sp->GetDescription(&strm, level);
429 strm.EOL();
430 } else
431 strm.PutCString("No value");
432
433 return true;
434}
435
437 LLDB_INSTRUMENT_VA(this);
438
439 BreakpointLocationSP loc_sp = GetSP();
440 if (loc_sp) {
441 std::lock_guard<std::recursive_mutex> guard(
442 loc_sp->GetTarget().GetAPIMutex());
443 return loc_sp->GetID();
444 } else
446}
447
449 LLDB_INSTRUMENT_VA(this);
450
451 BreakpointLocationSP loc_sp = GetSP();
452
453 SBBreakpoint sb_bp;
454 if (loc_sp) {
455 std::lock_guard<std::recursive_mutex> guard(
456 loc_sp->GetTarget().GetAPIMutex());
457 sb_bp = loc_sp->GetBreakpoint().shared_from_this();
458 }
459
460 return sb_bp;
461}
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 SetErrorString(const char *err_str)
Definition: SBError.cpp:132
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:106
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:221
An error handling class.
Definition: Status.h:44
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:128
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:37
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:82
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
#define UINT32_MAX
Definition: lldb-defines.h:19
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
@ eScriptLanguageNone
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
int32_t break_id_t
Definition: lldb-types.h:84
bool(* SBBreakpointHitCallback)(void *baton, SBProcess &process, SBThread &thread, lldb::SBBreakpointLocation &location)
Definition: SBDefines.h:120
uint64_t addr_t
Definition: lldb-types.h:79
uint64_t tid_t
Definition: lldb-types.h:82