brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · dfaea7e Raw
120 lines · cpp
1//===-- RichManglingContextTest.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-exception6//7//===----------------------------------------------------------------------===//8 9#include "lldb/Core/RichManglingContext.h"10 11#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"12#include "TestingSupport/SubsystemRAII.h"13#include "lldb/Utility/ConstString.h"14 15#include "gtest/gtest.h"16 17using namespace lldb;18using namespace lldb_private;19 20TEST(RichManglingContextTest, Basic) {21  RichManglingContext RMC;22  ConstString mangled("_ZN3foo3barEv");23 24  EXPECT_TRUE(RMC.FromItaniumName(mangled));25  EXPECT_FALSE(RMC.IsCtorOrDtor());26  EXPECT_EQ("foo", RMC.ParseFunctionDeclContextName());27  EXPECT_EQ("bar", RMC.ParseFunctionBaseName());28  EXPECT_EQ("foo::bar()", RMC.ParseFullName());29}30 31TEST(RichManglingContextTest, FromCxxMethodName) {32 33  SubsystemRAII<CPlusPlusLanguage> lang;34 35  RichManglingContext ItaniumRMC;36  ConstString mangled("_ZN3foo3barEv");37  EXPECT_TRUE(ItaniumRMC.FromItaniumName(mangled));38 39  RichManglingContext CxxMethodRMC;40  ConstString demangled("foo::bar()");41  EXPECT_TRUE(CxxMethodRMC.FromCxxMethodName(demangled));42 43  EXPECT_EQ(ItaniumRMC.IsCtorOrDtor(), CxxMethodRMC.IsCtorOrDtor());44  EXPECT_EQ(ItaniumRMC.ParseFunctionDeclContextName(),45            CxxMethodRMC.ParseFunctionDeclContextName());46  EXPECT_EQ(ItaniumRMC.ParseFunctionBaseName(),47            CxxMethodRMC.ParseFunctionBaseName());48  EXPECT_EQ(ItaniumRMC.ParseFullName(), CxxMethodRMC.ParseFullName());49 50  // Construct with a random name.51  {52    RichManglingContext CxxMethodRMC;53    EXPECT_TRUE(CxxMethodRMC.FromCxxMethodName(ConstString("X")));54  }55 56  // Construct with a function without a context.57  {58    RichManglingContext CxxMethodRMC;59    EXPECT_TRUE(CxxMethodRMC.FromCxxMethodName(60        ConstString("void * operator new(unsigned __int64)")));61 62    // We expect its context is empty.63    EXPECT_TRUE(CxxMethodRMC.ParseFunctionDeclContextName().empty());64  }65}66 67TEST(RichManglingContextTest, SwitchProvider) {68  RichManglingContext RMC;69  llvm::StringRef mangled = "_ZN3foo3barEv";70  llvm::StringRef demangled = "foo::bar()";71 72  EXPECT_TRUE(RMC.FromItaniumName(ConstString(mangled)));73  EXPECT_EQ("foo::bar()", RMC.ParseFullName());74 75  SubsystemRAII<CPlusPlusLanguage> lang;76 77  EXPECT_TRUE(RMC.FromCxxMethodName(ConstString(demangled)));78  EXPECT_EQ("foo::bar()", RMC.ParseFullName());79 80  EXPECT_TRUE(RMC.FromItaniumName(ConstString(mangled)));81  EXPECT_EQ("foo::bar()", RMC.ParseFullName());82}83 84TEST(RichManglingContextTest, IPDRealloc) {85  // The demangled name should fit into the Itanium default buffer.86  const char *ShortMangled = "_ZN3foo3barEv";87 88  // The demangled name for this will certainly not fit into the default buffer.89  const char *LongMangled =90      "_ZNK3shk6detail17CallbackPublisherIZNS_5ThrowERKNSt15__exception_"91      "ptr13exception_ptrEEUlOT_E_E9SubscribeINS0_9ConcatMapINS0_"92      "18CallbackSubscriberIZNS_6GetAllIiNS1_IZZNS_9ConcatMapIZNS_6ConcatIJNS1_"93      "IZZNS_3MapIZZNS_7IfEmptyIS9_EEDaS7_ENKUlS6_E_clINS1_IZZNS_4TakeIiEESI_"94      "S7_ENKUlS6_E_clINS1_IZZNS_6FilterIZNS_9ElementAtEmEUlS7_E_EESI_S7_"95      "ENKUlS6_E_clINS1_IZZNSL_ImEESI_S7_ENKUlS6_E_clINS1_IZNS_4FromINS0_"96      "22InfiniteRangeContainerIiEEEESI_S7_EUlS7_E_EEEESI_S6_EUlS7_E_EEEESI_S6_"97      "EUlS7_E_EEEESI_S6_EUlS7_E_EEEESI_S6_EUlS7_E_EESI_S7_ENKUlS6_E_clIS14_"98      "EESI_S6_EUlS7_E_EERNS1_IZZNSH_IS9_EESI_S7_ENKSK_IS14_EESI_S6_EUlS7_E0_"99      "EEEEESI_DpOT_EUlS7_E_EESI_S7_ENKUlS6_E_clINS1_IZNS_5StartIJZNS_"100      "4JustIJS19_S1C_EEESI_S1F_EUlvE_ZNS1K_IJS19_S1C_EEESI_S1F_EUlvE0_EEESI_"101      "S1F_EUlS7_E_EEEESI_S6_EUlS7_E_EEEESt6vectorIS6_SaIS6_EERKT0_NS_"102      "12ElementCountEbEUlS7_E_ZNSD_IiS1Q_EES1T_S1W_S1X_bEUlOS3_E_ZNSD_IiS1Q_"103      "EES1T_S1W_S1X_bEUlvE_EES1G_S1O_E25ConcatMapValuesSubscriberEEEDaS7_";104 105  RichManglingContext RMC;106 107  // Demangle the short one.108  EXPECT_TRUE(RMC.FromItaniumName(ConstString(ShortMangled)));109  const char *ShortDemangled = RMC.ParseFullName().data();110 111  // Demangle the long one.112  EXPECT_TRUE(RMC.FromItaniumName(ConstString(LongMangled)));113  const char *LongDemangled = RMC.ParseFullName().data();114 115  // Make sure a new buffer was allocated or the default buffer was extended.116  bool AllocatedNewBuffer = (ShortDemangled != LongDemangled);117  bool ExtendedExistingBuffer = (strlen(LongDemangled) > 2048);118  EXPECT_TRUE(AllocatedNewBuffer || ExtendedExistingBuffer);119}120