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