Skip to content

Commit 0dc8040

Browse files
committed
add unit test for breakpoint::setcallback
1 parent 2c6f486 commit 0dc8040

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed

lldb/unittests/Breakpoint/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ add_lldb_unittest(LLDBBreakpointTests
55
LINK_LIBS
66
lldbBreakpoint
77
lldbCore
8+
LLVMTestingSupport
9+
lldbUtilityHelpers
10+
lldbPluginPlatformMacOSX
811
LINK_COMPONENTS
912
Support
1013
)

lldb/unittests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
5252
add_subdirectory(API)
5353
endif()
5454
add_subdirectory(Breakpoint)
55+
add_subdirectory(Callback)
5556
add_subdirectory(Core)
5657
add_subdirectory(DataFormatter)
5758
add_subdirectory(Disassembler)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
add_lldb_unittest(LLDBCallbackTests
2+
TestBreakpointSetCallback.cpp
3+
4+
LINK_LIBS
5+
lldbBreakpoint
6+
lldbCore
7+
LLVMTestingSupport
8+
lldbUtilityHelpers
9+
lldbPluginPlatformMacOSX
10+
LINK_COMPONENTS
11+
Support
12+
)
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
class BreakpointSetCallbackTest : public ::testing::Test {
31+
public:
32+
static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
33+
lldb::user_id_t break_id,
34+
lldb::user_id_t break_loc_id,
35+
lldb::user_id_t expected_breakpoint_id,
36+
lldb::user_id_t expected_breakpoint_loc_id) {
37+
EXPECT_TRUE(baton);
38+
EXPECT_TRUE(context);
39+
EXPECT_EQ(break_id, expected_breakpoint_id);
40+
EXPECT_EQ(break_loc_id, expected_breakpoint_loc_id);
41+
}
42+
43+
protected:
44+
// The debugger's initialization function can't be called with no arguments
45+
// so calling it using SubsystemRAII will cause the test build to fail as
46+
// SubsystemRAII will call Initialize with no arguments. As such we set it up
47+
// here the usual way.
48+
void SetUp() override {
49+
std::call_once(TestUtilities::g_debugger_initialize_flag,
50+
[]() { Debugger::Initialize(nullptr); });
51+
52+
// Set up the debugger, make sure that was done properly.
53+
ArchSpec arch("x86_64-apple-macosx-");
54+
Platform::SetHostPlatform(
55+
PlatformRemoteMacOSX::CreateInstance(true, &arch));
56+
57+
m_debugger_sp = Debugger::CreateInstance();
58+
m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch,
59+
lldb_private::eLoadDependentsNo,
60+
m_platform_sp, m_target_sp);
61+
m_breakpoint_sp = m_target_sp->CreateBreakpoint(0xDEADBEEF, false, false);
62+
};
63+
64+
static bool callback(void *baton, StoppointCallbackContext *context,
65+
lldb::user_id_t break_id, lldb::user_id_t break_loc_id) {
66+
BreakpointSetCallbackTest::CheckCallbackArgs(baton, context, break_id,
67+
break_loc_id, 0, 0);
68+
return true;
69+
}
70+
71+
DebuggerSP m_debugger_sp;
72+
PlatformSP m_platform_sp;
73+
TargetSP m_target_sp;
74+
BreakpointSP m_breakpoint_sp;
75+
Event *m_event;
76+
const ExecutionContext m_exe_ctx;
77+
lldb::user_id_t expected_breakpoint_id;
78+
lldb::user_id_t expected_breakpoint_loc_id;
79+
SubsystemRAII<FileSystem, HostInfo, PlatformMacOSX, ProgressManager>
80+
subsystems;
81+
};
82+
83+
TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) {
84+
void *baton = (void *)"hello";
85+
StoppointCallbackContext context(m_event, m_exe_ctx, true);
86+
m_breakpoint_sp->SetCallback(BreakpointSetCallbackTest::callback, baton,
87+
false);
88+
m_breakpoint_sp->InvokeCallback(&context, 0);
89+
}

0 commit comments

Comments
 (0)