|
| 1 | +//===-- TestBreakpointSetCallback.cpp |
| 2 | +//--------------------------------------------===// |
| 3 | +// |
| 4 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | +// See https://llvm.org/LICENSE.txt for license information. |
| 6 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +#include "Plugins/Platform/MacOSX/PlatformMacOSX.h" |
| 11 | +#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h" |
| 12 | +#include "TestingSupport/SubsystemRAII.h" |
| 13 | +#include "TestingSupport/TestUtilities.h" |
| 14 | +#include "lldb/Breakpoint/StoppointCallbackContext.h" |
| 15 | +#include "lldb/Core/Debugger.h" |
| 16 | +#include "lldb/Core/Progress.h" |
| 17 | +#include "lldb/Host/FileSystem.h" |
| 18 | +#include "lldb/Host/HostInfo.h" |
| 19 | +#include "lldb/Target/ExecutionContext.h" |
| 20 | +#include "lldb/lldb-private-enumerations.h" |
| 21 | +#include "lldb/lldb-types.h" |
| 22 | +#include "gtest/gtest.h" |
| 23 | +#include <iostream> |
| 24 | +#include <memory> |
| 25 | +#include <mutex> |
| 26 | + |
| 27 | +using namespace lldb_private; |
| 28 | +using namespace lldb; |
| 29 | + |
| 30 | +static constexpr lldb::user_id_t expected_breakpoint_id = 1; |
| 31 | +static constexpr lldb::user_id_t expected_breakpoint_location_id = 0; |
| 32 | + |
| 33 | +class BreakpointSetCallbackTest : public ::testing::Test { |
| 34 | +public: |
| 35 | + static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context, |
| 36 | + lldb::user_id_t break_id, |
| 37 | + lldb::user_id_t break_loc_id, |
| 38 | + lldb::user_id_t expected_breakpoint_id, |
| 39 | + lldb::user_id_t expected_breakpoint_loc_id, |
| 40 | + TargetSP expected_target_sp) { |
| 41 | + EXPECT_EQ(context->exe_ctx_ref.GetTargetSP(), expected_target_sp); |
| 42 | + EXPECT_EQ(baton, "hello"); |
| 43 | + EXPECT_EQ(break_id, expected_breakpoint_id); |
| 44 | + EXPECT_EQ(break_loc_id, expected_breakpoint_loc_id); |
| 45 | + } |
| 46 | + |
| 47 | +protected: |
| 48 | + void SetUp() override { |
| 49 | + std::call_once(TestUtilities::g_debugger_initialize_flag, |
| 50 | + []() { Debugger::Initialize(nullptr); }); |
| 51 | + }; |
| 52 | + |
| 53 | + DebuggerSP m_debugger_sp; |
| 54 | + PlatformSP m_platform_sp; |
| 55 | + SubsystemRAII<FileSystem, HostInfo, PlatformMacOSX, ProgressManager> |
| 56 | + subsystems; |
| 57 | +}; |
| 58 | + |
| 59 | +TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) { |
| 60 | + void *baton = (void *)"hello"; |
| 61 | + // Set up the debugger, make sure that was done properly. |
| 62 | + TargetSP target_sp; |
| 63 | + ArchSpec arch("x86_64-apple-macosx-"); |
| 64 | + Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch)); |
| 65 | + |
| 66 | + m_debugger_sp = Debugger::CreateInstance(); |
| 67 | + |
| 68 | + // Create target |
| 69 | + m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch, |
| 70 | + lldb_private::eLoadDependentsNo, |
| 71 | + m_platform_sp, target_sp); |
| 72 | + |
| 73 | + // Create breakpoint |
| 74 | + BreakpointSP breakpoint_sp = |
| 75 | + target_sp->CreateBreakpoint(0xDEADBEEF, false, false); |
| 76 | + |
| 77 | + breakpoint_sp->SetCallback( |
| 78 | + [target_sp](void *baton, StoppointCallbackContext *context, |
| 79 | + lldb::user_id_t break_id, lldb::user_id_t break_loc_id) { |
| 80 | + CheckCallbackArgs(baton, context, break_id, break_loc_id, |
| 81 | + expected_breakpoint_id, |
| 82 | + expected_breakpoint_location_id, target_sp); |
| 83 | + return true; |
| 84 | + }, |
| 85 | + baton, true); |
| 86 | + ExecutionContext exe_ctx(target_sp, false); |
| 87 | + StoppointCallbackContext context(nullptr, exe_ctx, true); |
| 88 | + breakpoint_sp->InvokeCallback(&context, 0); |
| 89 | +} |
0 commit comments