180814287SRaphael Isemann //===-- SBBreakpointOptionCommon.cpp --------------------------------------===//
2b842f2ecSJim Ingham //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6b842f2ecSJim Ingham //
7b842f2ecSJim Ingham //===----------------------------------------------------------------------===//
8b842f2ecSJim Ingham
9b842f2ecSJim Ingham #include "lldb/API/SBBreakpointName.h"
10b842f2ecSJim Ingham #include "lldb/API/SBBreakpointLocation.h"
11b842f2ecSJim Ingham #include "lldb/API/SBDebugger.h"
12b842f2ecSJim Ingham #include "lldb/API/SBEvent.h"
13b842f2ecSJim Ingham #include "lldb/API/SBProcess.h"
14b842f2ecSJim Ingham #include "lldb/API/SBStream.h"
15b842f2ecSJim Ingham #include "lldb/API/SBStringList.h"
16b842f2ecSJim Ingham #include "lldb/API/SBThread.h"
17b842f2ecSJim Ingham
18b842f2ecSJim Ingham #include "lldb/Breakpoint/BreakpointName.h"
19b842f2ecSJim Ingham #include "lldb/Breakpoint/StoppointCallbackContext.h"
20b842f2ecSJim Ingham #include "lldb/Core/Address.h"
21b842f2ecSJim Ingham #include "lldb/Core/Debugger.h"
22b842f2ecSJim Ingham #include "lldb/Interpreter/CommandInterpreter.h"
23b842f2ecSJim Ingham #include "lldb/Interpreter/ScriptInterpreter.h"
24b842f2ecSJim Ingham #include "lldb/Target/Process.h"
25b842f2ecSJim Ingham #include "lldb/Target/Target.h"
26b842f2ecSJim Ingham #include "lldb/Target/Thread.h"
27b842f2ecSJim Ingham #include "lldb/Target/ThreadSpec.h"
28*1755f5b1SJonas Devlieghere #include "lldb/Utility/Instrumentation.h"
29b842f2ecSJim Ingham #include "lldb/Utility/Log.h"
30b842f2ecSJim Ingham #include "lldb/Utility/Stream.h"
31b842f2ecSJim Ingham
32b842f2ecSJim Ingham #include "lldb/lldb-enumerations.h"
33b842f2ecSJim Ingham
34b842f2ecSJim Ingham #include "SBBreakpointOptionCommon.h"
35b842f2ecSJim Ingham
36b842f2ecSJim Ingham #include "llvm/ADT/STLExtras.h"
37b842f2ecSJim Ingham
38b842f2ecSJim Ingham using namespace lldb;
39b842f2ecSJim Ingham using namespace lldb_private;
40b842f2ecSJim Ingham
SBBreakpointCallbackBaton(SBBreakpointHitCallback callback,void * baton)41*1755f5b1SJonas Devlieghere SBBreakpointCallbackBaton::SBBreakpointCallbackBaton(
42*1755f5b1SJonas Devlieghere SBBreakpointHitCallback callback, void *baton)
43a8f3ae7cSJonas Devlieghere : TypedBaton(std::make_unique<CallbackData>()) {
44*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, callback, baton);
45b842f2ecSJim Ingham getItem()->callback = callback;
46b842f2ecSJim Ingham getItem()->callback_baton = baton;
47b842f2ecSJim Ingham }
48b842f2ecSJim Ingham
PrivateBreakpointHitCallback(void * baton,StoppointCallbackContext * ctx,lldb::user_id_t break_id,lldb::user_id_t break_loc_id)49*1755f5b1SJonas Devlieghere bool SBBreakpointCallbackBaton::PrivateBreakpointHitCallback(
50*1755f5b1SJonas Devlieghere void *baton, StoppointCallbackContext *ctx, lldb::user_id_t break_id,
51*1755f5b1SJonas Devlieghere lldb::user_id_t break_loc_id) {
52*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(baton, ctx, break_id, break_loc_id);
53b842f2ecSJim Ingham ExecutionContext exe_ctx(ctx->exe_ctx_ref);
54b842f2ecSJim Ingham BreakpointSP bp_sp(
55b842f2ecSJim Ingham exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id));
56b842f2ecSJim Ingham if (baton && bp_sp) {
57b842f2ecSJim Ingham CallbackData *data = (CallbackData *)baton;
58b842f2ecSJim Ingham lldb_private::Breakpoint *bp = bp_sp.get();
59b842f2ecSJim Ingham if (bp && data->callback) {
60b842f2ecSJim Ingham Process *process = exe_ctx.GetProcessPtr();
61b842f2ecSJim Ingham if (process) {
62b842f2ecSJim Ingham SBProcess sb_process(process->shared_from_this());
63b842f2ecSJim Ingham SBThread sb_thread;
64b842f2ecSJim Ingham SBBreakpointLocation sb_location;
65b842f2ecSJim Ingham assert(bp_sp);
66b842f2ecSJim Ingham sb_location.SetLocation(bp_sp->FindLocationByID(break_loc_id));
67b842f2ecSJim Ingham Thread *thread = exe_ctx.GetThreadPtr();
68b842f2ecSJim Ingham if (thread)
69b842f2ecSJim Ingham sb_thread.SetThread(thread->shared_from_this());
70b842f2ecSJim Ingham
71b842f2ecSJim Ingham return data->callback(data->callback_baton, sb_process, sb_thread,
72b842f2ecSJim Ingham sb_location);
73b842f2ecSJim Ingham }
74b842f2ecSJim Ingham }
75b842f2ecSJim Ingham }
76b842f2ecSJim Ingham return true; // Return true if we should stop at this breakpoint
77b842f2ecSJim Ingham }
78b842f2ecSJim Ingham
79e2564051SDavide Italiano SBBreakpointCallbackBaton::~SBBreakpointCallbackBaton() = default;
80