Med Ismail Bennani | 047c4b0 | 2020-02-07 16:33:33 +0100 | [diff] [blame] | 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/Utility/Reproducer.h" |
| 15 | #include "lldb/lldb-enumerations.h" |
| 16 | #include "lldb/lldb-forward.h" |
| 17 | #include "lldb/lldb-private-enumerations.h" |
| 18 | #include "lldb/lldb-private.h" |
| 19 | #include "llvm/Support/FormatVariadic.h" |
| 20 | #include "gtest/gtest.h" |
| 21 | |
| 22 | using namespace lldb_private; |
| 23 | using namespace lldb_private::repro; |
| 24 | using namespace lldb; |
| 25 | |
| 26 | namespace { |
| 27 | class StackFrameRecognizerTest : public ::testing::Test { |
| 28 | public: |
| 29 | void SetUp() override { |
| 30 | llvm::cantFail(Reproducer::Initialize(ReproducerMode::Off, llvm::None)); |
| 31 | FileSystem::Initialize(); |
| 32 | HostInfo::Initialize(); |
| 33 | |
| 34 | // Pretend Linux is the host platform. |
| 35 | platform_linux::PlatformLinux::Initialize(); |
| 36 | ArchSpec arch("powerpc64-pc-linux"); |
| 37 | Platform::SetHostPlatform( |
| 38 | platform_linux::PlatformLinux::CreateInstance(true, &arch)); |
| 39 | } |
| 40 | |
| 41 | void TearDown() override { |
| 42 | platform_linux::PlatformLinux::Terminate(); |
| 43 | HostInfo::Terminate(); |
| 44 | FileSystem::Terminate(); |
| 45 | Reproducer::Terminate(); |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | class DummyStackFrameRecognizer : public StackFrameRecognizer { |
| 50 | public: |
| 51 | std::string GetName() override { return "Dummy StackFrame Recognizer"; } |
| 52 | }; |
| 53 | |
Raphael Isemann | 1b7c9ea | 2020-07-17 08:36:38 +0200 | [diff] [blame] | 54 | void RegisterDummyStackFrameRecognizer(StackFrameRecognizerManager &manager) { |
| 55 | RegularExpressionSP module_regex_sp = nullptr; |
| 56 | RegularExpressionSP symbol_regex_sp(new RegularExpression("boom")); |
Med Ismail Bennani | 047c4b0 | 2020-02-07 16:33:33 +0100 | [diff] [blame] | 57 | |
Raphael Isemann | 1b7c9ea | 2020-07-17 08:36:38 +0200 | [diff] [blame] | 58 | StackFrameRecognizerSP dummy_recognizer_sp(new DummyStackFrameRecognizer()); |
Med Ismail Bennani | 047c4b0 | 2020-02-07 16:33:33 +0100 | [diff] [blame] | 59 | |
Raphael Isemann | 1b7c9ea | 2020-07-17 08:36:38 +0200 | [diff] [blame] | 60 | manager.AddRecognizer(dummy_recognizer_sp, module_regex_sp, symbol_regex_sp, |
| 61 | false); |
Med Ismail Bennani | 047c4b0 | 2020-02-07 16:33:33 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | } // namespace |
| 65 | |
| 66 | TEST_F(StackFrameRecognizerTest, NullModuleRegex) { |
| 67 | DebuggerSP debugger_sp = Debugger::CreateInstance(); |
| 68 | ASSERT_TRUE(debugger_sp); |
| 69 | |
Raphael Isemann | 1b7c9ea | 2020-07-17 08:36:38 +0200 | [diff] [blame] | 70 | StackFrameRecognizerManager manager; |
| 71 | |
| 72 | RegisterDummyStackFrameRecognizer(manager); |
Med Ismail Bennani | 047c4b0 | 2020-02-07 16:33:33 +0100 | [diff] [blame] | 73 | |
| 74 | bool any_printed = false; |
Raphael Isemann | 1b7c9ea | 2020-07-17 08:36:38 +0200 | [diff] [blame] | 75 | manager.ForEach([&any_printed](uint32_t recognizer_id, std::string name, |
| 76 | std::string function, |
| 77 | llvm::ArrayRef<ConstString> symbols, |
| 78 | bool regexp) { any_printed = true; }); |
Med Ismail Bennani | 047c4b0 | 2020-02-07 16:33:33 +0100 | [diff] [blame] | 79 | |
| 80 | EXPECT_TRUE(any_printed); |
| 81 | } |