xref: /freebsd/contrib/llvm-project/lldb/source/API/SBBreakpointOptionCommon.cpp (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1 //===-- SBBreakpointOptionCommon.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 
9 #include "lldb/API/SBBreakpointName.h"
10 #include "lldb/API/SBBreakpointLocation.h"
11 #include "lldb/API/SBDebugger.h"
12 #include "lldb/API/SBEvent.h"
13 #include "lldb/API/SBProcess.h"
14 #include "lldb/API/SBStream.h"
15 #include "lldb/API/SBStringList.h"
16 #include "lldb/API/SBThread.h"
17 
18 #include "lldb/Breakpoint/BreakpointName.h"
19 #include "lldb/Breakpoint/StoppointCallbackContext.h"
20 #include "lldb/Core/Address.h"
21 #include "lldb/Core/Debugger.h"
22 #include "lldb/Core/StreamFile.h"
23 #include "lldb/Interpreter/CommandInterpreter.h"
24 #include "lldb/Interpreter/ScriptInterpreter.h"
25 #include "lldb/Target/Process.h"
26 #include "lldb/Target/Target.h"
27 #include "lldb/Target/Thread.h"
28 #include "lldb/Target/ThreadSpec.h"
29 #include "lldb/Utility/Instrumentation.h"
30 #include "lldb/Utility/Log.h"
31 #include "lldb/Utility/Stream.h"
32 
33 #include "lldb/lldb-enumerations.h"
34 
35 #include "SBBreakpointOptionCommon.h"
36 
37 #include "llvm/ADT/STLExtras.h"
38 
39 using namespace lldb;
40 using namespace lldb_private;
41 
42 SBBreakpointCallbackBaton::SBBreakpointCallbackBaton(
43     SBBreakpointHitCallback callback, void *baton)
44     : TypedBaton(std::make_unique<CallbackData>()) {
45   LLDB_INSTRUMENT_VA(this, callback, baton);
46   getItem()->callback = callback;
47   getItem()->callback_baton = baton;
48 }
49 
50 bool SBBreakpointCallbackBaton::PrivateBreakpointHitCallback(
51     void *baton, StoppointCallbackContext *ctx, lldb::user_id_t break_id,
52     lldb::user_id_t break_loc_id) {
53   LLDB_INSTRUMENT_VA(baton, ctx, break_id, break_loc_id);
54   ExecutionContext exe_ctx(ctx->exe_ctx_ref);
55   BreakpointSP bp_sp(
56       exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id));
57   if (baton && bp_sp) {
58     CallbackData *data = (CallbackData *)baton;
59     lldb_private::Breakpoint *bp = bp_sp.get();
60     if (bp && data->callback) {
61       Process *process = exe_ctx.GetProcessPtr();
62       if (process) {
63         SBProcess sb_process(process->shared_from_this());
64         SBThread sb_thread;
65         SBBreakpointLocation sb_location;
66         assert(bp_sp);
67         sb_location.SetLocation(bp_sp->FindLocationByID(break_loc_id));
68         Thread *thread = exe_ctx.GetThreadPtr();
69         if (thread)
70           sb_thread.SetThread(thread->shared_from_this());
71 
72         return data->callback(data->callback_baton, sb_process, sb_thread,
73                               sb_location);
74       }
75     }
76   }
77   return true; // Return true if we should stop at this breakpoint
78 }
79 
80 SBBreakpointCallbackBaton::~SBBreakpointCallbackBaton() = default;
81