Debian Codegraph @

lldb/unittests/Target/StackFrameRecognizerTest.cpp

raw
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
21 using namespace lldb_private;
22 using namespace lldb;
23
24 namespace {
25 class StackFrameRecognizerTest : public ::testing::Test {
26 public:
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(true, &arch));
36 }
37
38 void TearDown() override {
39 platform_linux::PlatformLinux::Terminate();
40 HostInfo::Terminate();
41 FileSystem::Terminate();
42 }
43 };
44
45 class DummyStackFrameRecognizer : public StackFrameRecognizer {
46 public:
47 std::string GetName() override { return "Dummy StackFrame Recognizer"; }
48 };
49
50 void 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(dummy_recognizer_sp, module_regex_sp, symbol_regex_sp,
57 Mangled::NamePreference::ePreferDemangled, false);
58 }
59
60 } // namespace
61
62 TEST_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([&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 }