|
| 1 | +//===----------------------------------------------------------------------===// |
| 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 | +// Use the umbrella header for -Wdocumentation. |
| 9 | +#include "lldb/API/LLDB.h" |
| 10 | + |
| 11 | +#include "TestingSupport/SubsystemRAII.h" |
| 12 | +#include "lldb/API/SBBreakpoint.h" |
| 13 | +#include "lldb/API/SBBreakpointLocation.h" |
| 14 | +#include "lldb/API/SBDebugger.h" |
| 15 | +#include "lldb/API/SBTarget.h" |
| 16 | +#include "gtest/gtest.h" |
| 17 | +#include <memory> |
| 18 | +#include <mutex> |
| 19 | + |
| 20 | +using namespace lldb_private; |
| 21 | +using namespace lldb; |
| 22 | + |
| 23 | +class BreakpointClearConditionTest : public ::testing::Test { |
| 24 | +public: |
| 25 | + void SetUp() override { |
| 26 | + m_sb_debugger = SBDebugger::Create(/*source_init_files=*/false); |
| 27 | + }; |
| 28 | + |
| 29 | + void TearDown() override { SBDebugger::Destroy(m_sb_debugger); } |
| 30 | + SBDebugger m_sb_debugger; |
| 31 | + SubsystemRAII<lldb::SBDebugger> subsystems; |
| 32 | +}; |
| 33 | + |
| 34 | +template <typename T> void test_condition(T sb_object) { |
| 35 | + const char *in_cond_str = "Here is a condition"; |
| 36 | + sb_object.SetCondition(in_cond_str); |
| 37 | + // Make sure we set the condition correctly: |
| 38 | + const char *out_cond_str = sb_object.GetCondition(); |
| 39 | + EXPECT_STREQ(in_cond_str, out_cond_str); |
| 40 | + // Now unset it by passing in nullptr and make sure that works: |
| 41 | + const char *empty_tokens[2] = {nullptr, ""}; |
| 42 | + for (auto token : empty_tokens) { |
| 43 | + sb_object.SetCondition(token); |
| 44 | + out_cond_str = sb_object.GetCondition(); |
| 45 | + // And make sure an unset condition returns nullptr: |
| 46 | + EXPECT_EQ(nullptr, out_cond_str); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +TEST_F(BreakpointClearConditionTest, BreakpointClearConditionTest) { |
| 51 | + // Create target |
| 52 | + SBTarget sb_target; |
| 53 | + SBError error; |
| 54 | + sb_target = |
| 55 | + m_sb_debugger.CreateTarget("", "x86_64-apple-macosx-", "remote-macosx", |
| 56 | + /*add_dependent=*/false, error); |
| 57 | + |
| 58 | + EXPECT_EQ(sb_target.IsValid(), true); |
| 59 | + |
| 60 | + // Create breakpoint |
| 61 | + SBBreakpoint sb_breakpoint = sb_target.BreakpointCreateByAddress(0xDEADBEEF); |
| 62 | + test_condition(sb_breakpoint); |
| 63 | + |
| 64 | + // Address breakpoints always have one location, so we can also use this |
| 65 | + // to test the location: |
| 66 | + SBBreakpointLocation sb_loc = sb_breakpoint.GetLocationAtIndex(0); |
| 67 | + EXPECT_EQ(sb_loc.IsValid(), true); |
| 68 | + test_condition(sb_loc); |
| 69 | +} |
0 commit comments