1 //===-- StackFrameRecognizerTest.cpp --------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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"
21 using namespace lldb_private
;
22 using namespace lldb_private::repro
;
26 class StackFrameRecognizerTest
: public ::testing::Test
{
28 void SetUp() override
{
29 FileSystem::Initialize();
30 HostInfo::Initialize();
32 // Pretend Linux is the host platform.
33 platform_linux::PlatformLinux::Initialize();
34 ArchSpec
arch("powerpc64-pc-linux");
35 Platform::SetHostPlatform(
36 platform_linux::PlatformLinux::CreateInstance(true, &arch
));
39 void TearDown() override
{
40 platform_linux::PlatformLinux::Terminate();
41 HostInfo::Terminate();
42 FileSystem::Terminate();
46 class DummyStackFrameRecognizer
: public StackFrameRecognizer
{
48 std::string
GetName() override
{ return "Dummy StackFrame Recognizer"; }
51 void RegisterDummyStackFrameRecognizer(StackFrameRecognizerManager
&manager
) {
52 RegularExpressionSP module_regex_sp
= nullptr;
53 RegularExpressionSP
symbol_regex_sp(new RegularExpression("boom"));
55 StackFrameRecognizerSP
dummy_recognizer_sp(new DummyStackFrameRecognizer());
57 manager
.AddRecognizer(dummy_recognizer_sp
, module_regex_sp
, symbol_regex_sp
,
58 Mangled::NamePreference::ePreferDemangled
, false);
63 TEST_F(StackFrameRecognizerTest
, NullModuleRegex
) {
64 DebuggerSP debugger_sp
= Debugger::CreateInstance();
65 ASSERT_TRUE(debugger_sp
);
67 StackFrameRecognizerManager manager
;
69 RegisterDummyStackFrameRecognizer(manager
);
71 bool any_printed
= false;
72 manager
.ForEach([&any_printed
](uint32_t recognizer_id
, bool enabled
,
73 std::string name
, std::string function
,
74 llvm::ArrayRef
<ConstString
> symbols
,
75 Mangled::NamePreference symbol_mangling
,
76 bool regexp
) { any_printed
= true; });
78 EXPECT_TRUE(any_printed
);