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_private::repro; 23 using namespace lldb; 24 25 namespace { 26 class StackFrameRecognizerTest : public ::testing::Test { 27 public: 28 void SetUp() override { 29 FileSystem::Initialize(); 30 HostInfo::Initialize(); 31 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)); 37 } 38 39 void TearDown() override { 40 platform_linux::PlatformLinux::Terminate(); 41 HostInfo::Terminate(); 42 FileSystem::Terminate(); 43 } 44 }; 45 46 class DummyStackFrameRecognizer : public StackFrameRecognizer { 47 public: 48 std::string GetName() override { return "Dummy StackFrame Recognizer"; } 49 }; 50 51 void RegisterDummyStackFrameRecognizer(StackFrameRecognizerManager &manager) { 52 RegularExpressionSP module_regex_sp = nullptr; 53 RegularExpressionSP symbol_regex_sp(new RegularExpression("boom")); 54 55 StackFrameRecognizerSP dummy_recognizer_sp(new DummyStackFrameRecognizer()); 56 57 manager.AddRecognizer(dummy_recognizer_sp, module_regex_sp, symbol_regex_sp, 58 Mangled::NamePreference::ePreferDemangled, false); 59 } 60 61 } // namespace 62 63 TEST_F(StackFrameRecognizerTest, NullModuleRegex) { 64 DebuggerSP debugger_sp = Debugger::CreateInstance(); 65 ASSERT_TRUE(debugger_sp); 66 67 StackFrameRecognizerManager manager; 68 69 RegisterDummyStackFrameRecognizer(manager); 70 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; }); 77 78 EXPECT_TRUE(any_printed); 79 } 80