[MLIR][NVVM] Add Op for TMA Store with reduction (#118853)
[llvm-project.git] / lldb / source / API / SBBreakpointLocation.cpp
blobb2d1da3927c6ea00fa6ba39e997533198f91eb50
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 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBBreakpointLocation.h"
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"
15 #include "lldb/API/SBStructuredData.h"
16 #include "lldb/Utility/Instrumentation.h"
18 #include "lldb/Breakpoint/Breakpoint.h"
19 #include "lldb/Breakpoint/BreakpointLocation.h"
20 #include "lldb/Core/Debugger.h"
21 #include "lldb/Core/StructuredDataImpl.h"
22 #include "lldb/Interpreter/CommandInterpreter.h"
23 #include "lldb/Interpreter/ScriptInterpreter.h"
24 #include "lldb/Target/Target.h"
25 #include "lldb/Target/ThreadSpec.h"
26 #include "lldb/Utility/Stream.h"
27 #include "lldb/lldb-defines.h"
28 #include "lldb/lldb-types.h"
30 #include "SBBreakpointOptionCommon.h"
32 using namespace lldb;
33 using namespace lldb_private;
35 SBBreakpointLocation::SBBreakpointLocation() { LLDB_INSTRUMENT_VA(this); }
37 SBBreakpointLocation::SBBreakpointLocation(
38 const lldb::BreakpointLocationSP &break_loc_sp)
39 : m_opaque_wp(break_loc_sp) {
40 LLDB_INSTRUMENT_VA(this, break_loc_sp);
43 SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs)
44 : m_opaque_wp(rhs.m_opaque_wp) {
45 LLDB_INSTRUMENT_VA(this, rhs);
48 const SBBreakpointLocation &SBBreakpointLocation::
49 operator=(const SBBreakpointLocation &rhs) {
50 LLDB_INSTRUMENT_VA(this, rhs);
52 m_opaque_wp = rhs.m_opaque_wp;
53 return *this;
56 SBBreakpointLocation::~SBBreakpointLocation() = default;
58 BreakpointLocationSP SBBreakpointLocation::GetSP() const {
59 return m_opaque_wp.lock();
62 bool SBBreakpointLocation::IsValid() const {
63 LLDB_INSTRUMENT_VA(this);
64 return this->operator bool();
66 SBBreakpointLocation::operator bool() const {
67 LLDB_INSTRUMENT_VA(this);
69 return bool(GetSP());
72 SBAddress SBBreakpointLocation::GetAddress() {
73 LLDB_INSTRUMENT_VA(this);
75 BreakpointLocationSP loc_sp = GetSP();
76 if (loc_sp) {
77 return SBAddress(loc_sp->GetAddress());
80 return SBAddress();
83 addr_t SBBreakpointLocation::GetLoadAddress() {
84 LLDB_INSTRUMENT_VA(this);
86 addr_t ret_addr = LLDB_INVALID_ADDRESS;
87 BreakpointLocationSP loc_sp = GetSP();
89 if (loc_sp) {
90 std::lock_guard<std::recursive_mutex> guard(
91 loc_sp->GetTarget().GetAPIMutex());
92 ret_addr = loc_sp->GetLoadAddress();
95 return ret_addr;
98 void SBBreakpointLocation::SetEnabled(bool enabled) {
99 LLDB_INSTRUMENT_VA(this, enabled);
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);
109 bool SBBreakpointLocation::IsEnabled() {
110 LLDB_INSTRUMENT_VA(this);
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;
121 uint32_t SBBreakpointLocation::GetHitCount() {
122 LLDB_INSTRUMENT_VA(this);
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;
133 uint32_t SBBreakpointLocation::GetIgnoreCount() {
134 LLDB_INSTRUMENT_VA(this);
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;
145 void SBBreakpointLocation::SetIgnoreCount(uint32_t n) {
146 LLDB_INSTRUMENT_VA(this, n);
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);
156 void SBBreakpointLocation::SetCondition(const char *condition) {
157 LLDB_INSTRUMENT_VA(this, condition);
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);
167 const char *SBBreakpointLocation::GetCondition() {
168 LLDB_INSTRUMENT_VA(this);
170 BreakpointLocationSP loc_sp = GetSP();
171 if (!loc_sp)
172 return nullptr;
174 std::lock_guard<std::recursive_mutex> guard(
175 loc_sp->GetTarget().GetAPIMutex());
176 return ConstString(loc_sp->GetConditionText()).GetCString();
179 void SBBreakpointLocation::SetAutoContinue(bool auto_continue) {
180 LLDB_INSTRUMENT_VA(this, auto_continue);
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);
190 bool SBBreakpointLocation::GetAutoContinue() {
191 LLDB_INSTRUMENT_VA(this);
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();
199 return false;
202 void SBBreakpointLocation::SetCallback(SBBreakpointHitCallback callback,
203 void *baton) {
204 LLDB_INSTRUMENT_VA(this, callback, baton);
206 BreakpointLocationSP loc_sp = GetSP();
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));
212 loc_sp->SetCallback(SBBreakpointCallbackBaton::PrivateBreakpointHitCallback,
213 baton_sp, false);
217 void SBBreakpointLocation::SetScriptCallbackFunction(
218 const char *callback_function_name) {
219 LLDB_INSTRUMENT_VA(this, callback_function_name);
222 SBError SBBreakpointLocation::SetScriptCallbackFunction(
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();
229 if (loc_sp) {
230 Status error;
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");
246 return sb_error;
249 SBError
250 SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
251 LLDB_INSTRUMENT_VA(this, callback_body_text);
253 BreakpointLocationSP loc_sp = GetSP();
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");
271 return sb_error;
274 void SBBreakpointLocation::SetCommandLineCommands(SBStringList &commands) {
275 LLDB_INSTRUMENT_VA(this, commands);
277 BreakpointLocationSP loc_sp = GetSP();
278 if (!loc_sp)
279 return;
280 if (commands.GetSize() == 0)
281 return;
283 std::lock_guard<std::recursive_mutex> guard(
284 loc_sp->GetTarget().GetAPIMutex());
285 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
286 new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
288 loc_sp->GetLocationOptions().SetCommandDataCallback(cmd_data_up);
291 bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) {
292 LLDB_INSTRUMENT_VA(this, commands);
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;
305 void SBBreakpointLocation::SetThreadID(lldb::tid_t thread_id) {
306 LLDB_INSTRUMENT_VA(this, thread_id);
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);
316 lldb::tid_t SBBreakpointLocation::GetThreadID() {
317 LLDB_INSTRUMENT_VA(this);
319 lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
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();
326 return tid;
329 void SBBreakpointLocation::SetThreadIndex(uint32_t index) {
330 LLDB_INSTRUMENT_VA(this, index);
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);
340 uint32_t SBBreakpointLocation::GetThreadIndex() const {
341 LLDB_INSTRUMENT_VA(this);
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();
350 return thread_idx;
353 void SBBreakpointLocation::SetThreadName(const char *thread_name) {
354 LLDB_INSTRUMENT_VA(this, thread_name);
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);
364 const char *SBBreakpointLocation::GetThreadName() const {
365 LLDB_INSTRUMENT_VA(this);
367 BreakpointLocationSP loc_sp = GetSP();
368 if (!loc_sp)
369 return nullptr;
371 std::lock_guard<std::recursive_mutex> guard(
372 loc_sp->GetTarget().GetAPIMutex());
373 return ConstString(loc_sp->GetThreadName()).GetCString();
376 void SBBreakpointLocation::SetQueueName(const char *queue_name) {
377 LLDB_INSTRUMENT_VA(this, queue_name);
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);
387 const char *SBBreakpointLocation::GetQueueName() const {
388 LLDB_INSTRUMENT_VA(this);
390 BreakpointLocationSP loc_sp = GetSP();
391 if (!loc_sp)
392 return nullptr;
394 std::lock_guard<std::recursive_mutex> guard(
395 loc_sp->GetTarget().GetAPIMutex());
396 return ConstString(loc_sp->GetQueueName()).GetCString();
399 bool SBBreakpointLocation::IsResolved() {
400 LLDB_INSTRUMENT_VA(this);
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();
408 return false;
411 void SBBreakpointLocation::SetLocation(
412 const lldb::BreakpointLocationSP &break_loc_sp) {
413 // Uninstall the callbacks?
414 m_opaque_wp = break_loc_sp;
417 bool SBBreakpointLocation::GetDescription(SBStream &description,
418 DescriptionLevel level) {
419 LLDB_INSTRUMENT_VA(this, description, level);
421 Stream &strm = description.ref();
422 BreakpointLocationSP loc_sp = GetSP();
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");
432 return true;
435 break_id_t SBBreakpointLocation::GetID() {
436 LLDB_INSTRUMENT_VA(this);
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;
447 SBBreakpoint SBBreakpointLocation::GetBreakpoint() {
448 LLDB_INSTRUMENT_VA(this);
450 BreakpointLocationSP loc_sp = GetSP();
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();
459 return sb_bp;