1//===-- StackFrameRecognizerTest.cpp --------------------------------------===//
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
9#include "lldb/Target/StackFrameRecognizer.h"
10#include "Plugins/Platform/Linux/PlatformLinux.h"
11#include "lldb/Core/Debugger.h"
12#include "lldb/Host/FileSystem.h"
13#include "lldb/Host/HostInfo.h"
14#include "lldb/lldb-enumerations.h"
15#include "lldb/lldb-forward.h"
16#include "lldb/lldb-private-enumerations.h"
17#include "lldb/lldb-private.h"
18#include "llvm/Support/FormatVariadic.h"
19#include "gtest/gtest.h"
20
21using namespace lldb_private;
22using namespace lldb;
23
24namespace {
25class StackFrameRecognizerTest : public ::testing::Test {
26public:
27 void SetUp() override {
28 FileSystem::Initialize();
29 HostInfo::Initialize();
30
31 // Pretend Linux is the host platform.
32 platform_linux::PlatformLinux::Initialize();
33 ArchSpec arch("powerpc64-pc-linux");
34 Platform::SetHostPlatform(
35 platform_linux::PlatformLinux::CreateInstance(force: true, arch: &arch));
36 }
37
38 void TearDown() override {
39 platform_linux::PlatformLinux::Terminate();
40 HostInfo::Terminate();
41 FileSystem::Terminate();
42 }
43};
44
45class DummyStackFrameRecognizer : public StackFrameRecognizer {
46public:
47 std::string GetName() override { return "Dummy StackFrame Recognizer"; }
48};
49
50void RegisterDummyStackFrameRecognizer(StackFrameRecognizerManager &manager) {
51 RegularExpressionSP module_regex_sp = nullptr;
52 RegularExpressionSP symbol_regex_sp(new RegularExpression("boom"));
53
54 StackFrameRecognizerSP dummy_recognizer_sp(new DummyStackFrameRecognizer());
55
56 manager.AddRecognizer(recognizer: dummy_recognizer_sp, module: module_regex_sp, symbol: symbol_regex_sp,
57 symbol_mangling: Mangled::NamePreference::ePreferDemangled, first_instruction_only: false);
58}
59
60} // namespace
61
62TEST_F(StackFrameRecognizerTest, NullModuleRegex) {
63 DebuggerSP debugger_sp = Debugger::CreateInstance();
64 ASSERT_TRUE(debugger_sp);
65
66 StackFrameRecognizerManager manager;
67
68 RegisterDummyStackFrameRecognizer(manager);
69
70 bool any_printed = false;
71 manager.ForEach(callback: [&any_printed](uint32_t recognizer_id, bool enabled,
72 std::string name, std::string function,
73 llvm::ArrayRef<ConstString> symbols,
74 Mangled::NamePreference symbol_mangling,
75 bool regexp) { any_printed = true; });
76
77 EXPECT_TRUE(any_printed);
78}
79

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of lldb/unittests/Target/StackFrameRecognizerTest.cpp