brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · c29cac5 Raw
86 lines · cpp
1//===-- TestBreakpointSetCallback.cpp2//--------------------------------------------===//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-exception7//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 27using namespace lldb_private;28using namespace lldb;29 30static constexpr lldb::user_id_t expected_breakpoint_id = 1;31static constexpr lldb::user_id_t expected_breakpoint_location_id = 0;32 33int baton_value;34 35class BreakpointSetCallbackTest : public ::testing::Test {36public:37  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,38                                lldb::user_id_t break_id,39                                lldb::user_id_t break_loc_id,40                                TargetSP expected_target_sp) {41    EXPECT_EQ(context->exe_ctx_ref.GetTargetSP(), expected_target_sp);42    EXPECT_EQ(baton, &baton_value);43    EXPECT_EQ(break_id, expected_breakpoint_id);44    EXPECT_EQ(break_loc_id, expected_breakpoint_location_id);45  }46 47protected: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> subsystems;56};57 58TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) {59  // Set up the debugger, make sure that was done properly.60  TargetSP target_sp;61  ArchSpec arch("x86_64-apple-macosx-");62  Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));63 64  m_debugger_sp = Debugger::CreateInstance();65 66  // Create target67  m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch,68                                              lldb_private::eLoadDependentsNo,69                                              m_platform_sp, target_sp);70 71  // Create breakpoint72  BreakpointSP breakpoint_sp =73      target_sp->CreateBreakpoint(0xDEADBEEF, false, false);74 75  breakpoint_sp->SetCallback(76      [target_sp](void *baton, StoppointCallbackContext *context,77                  lldb::user_id_t break_id, lldb::user_id_t break_loc_id) {78        CheckCallbackArgs(baton, context, break_id, break_loc_id, target_sp);79        return true;80      },81      (void *)&baton_value, true);82  ExecutionContext exe_ctx(target_sp, false);83  StoppointCallbackContext context(nullptr, exe_ctx, true);84  breakpoint_sp->InvokeCallback(&context, 0);85}86