Christopher Ferris | 9323b72 | 2017-03-03 17:43:14 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <stdlib.h> |
| 18 | |
| 19 | #include <gtest/gtest.h> |
| 20 | |
| 21 | #include <demangle.h> |
| 22 | |
| 23 | #include "Demangler.h" |
| 24 | |
Christopher Ferris | 15d2e42 | 2017-05-31 14:40:15 -0700 | [diff] [blame] | 25 | TEST(DemangleTest, IllegalArgumentModifiers) { |
| 26 | Demangler demangler; |
| 27 | |
| 28 | ASSERT_EQ("_Zpp4FUNKK", demangler.Parse("_Zpp4FUNKK")); |
| 29 | ASSERT_EQ("_Zpp4FUNVV", demangler.Parse("_Zpp4FUNVV")); |
| 30 | } |
| 31 | |
| 32 | TEST(DemangleTest, VoidArgument) { |
Christopher Ferris | 9323b72 | 2017-03-03 17:43:14 -0800 | [diff] [blame] | 33 | Demangler demangler; |
| 34 | |
| 35 | ASSERT_EQ("func()", demangler.Parse("_ZN4funcEv")); |
| 36 | ASSERT_EQ("func(void&)", demangler.Parse("_ZN4funcERv")); |
| 37 | ASSERT_EQ("func(void, void)", demangler.Parse("_ZN4funcEvv")); |
| 38 | ASSERT_EQ("func(void*)", demangler.Parse("_ZN4funcEPv")); |
| 39 | ASSERT_EQ("func(void const)", demangler.Parse("_ZN4funcEKv")); |
| 40 | ASSERT_EQ("func(void volatile)", demangler.Parse("_ZN4funcEVv")); |
| 41 | } |
| 42 | |
| 43 | TEST(DemangleTest, ArgumentModifiers) { |
| 44 | Demangler demangler; |
| 45 | |
| 46 | ASSERT_EQ("func(char)", demangler.Parse("_ZN4funcEc")); |
| 47 | ASSERT_EQ("func(char*)", demangler.Parse("_ZN4funcEPc")); |
| 48 | ASSERT_EQ("func(char**)", demangler.Parse("_ZN4funcEPPc")); |
| 49 | ASSERT_EQ("func(char***)", demangler.Parse("_ZN4funcEPPPc")); |
| 50 | ASSERT_EQ("func(char&)", demangler.Parse("_ZN4funcERc")); |
| 51 | ASSERT_EQ("func(char*&)", demangler.Parse("_ZN4funcERPc")); |
| 52 | ASSERT_EQ("func(char&)", demangler.Parse("_ZN4funcERRc")); |
| 53 | ASSERT_EQ("func(char*&*)", demangler.Parse("_ZN4funcEPRPc")); |
| 54 | ASSERT_EQ("func(char**&)", demangler.Parse("_ZN4funcERRPPc")); |
| 55 | ASSERT_EQ("func(char const)", demangler.Parse("_ZN4funcEKc")); |
| 56 | ASSERT_EQ("func(char volatile)", demangler.Parse("_ZN4funcEVc")); |
| 57 | ASSERT_EQ("func(char volatile const)", demangler.Parse("_ZN4funcEKVc")); |
| 58 | ASSERT_EQ("func(char const volatile)", demangler.Parse("_ZN4funcEVKc")); |
| 59 | ASSERT_EQ("func(char const* volatile&)", demangler.Parse("_ZN4funcERVPKc")); |
| 60 | ASSERT_EQ("func(void, char, short)", demangler.Parse("_ZN4funcEvcs")); |
| 61 | ASSERT_EQ("func(void*, char&, short&*)", demangler.Parse("_ZN4funcEPvRcPRs")); |
| 62 | } |
| 63 | |
| 64 | TEST(DemangleTest, FunctionModifiers) { |
| 65 | Demangler demangler; |
| 66 | |
| 67 | ASSERT_EQ("func() const", demangler.Parse("_ZNK4funcEv")); |
| 68 | ASSERT_EQ("func() volatile", demangler.Parse("_ZNV4funcEv")); |
| 69 | ASSERT_EQ("func() volatile const", demangler.Parse("_ZNKV4funcEv")); |
| 70 | ASSERT_EQ("func() const volatile", demangler.Parse("_ZNVK4funcEv")); |
| 71 | } |
| 72 | |
| 73 | TEST(DemangleTest, MultiplePartsInName) { |
| 74 | Demangler demangler; |
| 75 | |
| 76 | ASSERT_EQ("one::two()", demangler.Parse("_ZN3one3twoEv")); |
| 77 | ASSERT_EQ("one::two::three()", demangler.Parse("_ZN3one3two5threeEv")); |
| 78 | ASSERT_EQ("one::two::three::four()", demangler.Parse("_ZN3one3two5three4fourEv")); |
| 79 | ASSERT_EQ("one::two::three::four::five()", demangler.Parse("_ZN3one3two5three4four4fiveEv")); |
| 80 | ASSERT_EQ("one(two::three::four::five)", demangler.Parse("_ZN3oneEN3two5three4four4fiveE")); |
| 81 | } |
| 82 | |
| 83 | TEST(DemangleTest, AnonymousNamespace) { |
| 84 | Demangler demangler; |
| 85 | |
| 86 | ASSERT_EQ("(anonymous namespace)::two()", demangler.Parse("_ZN12_GLOBAL__N_13twoEv")); |
| 87 | ASSERT_EQ("one::two((anonymous namespace))", demangler.Parse("_ZN3one3twoE12_GLOBAL__N_1")); |
| 88 | } |
| 89 | |
| 90 | TEST(DemangleTest, DestructorValues) { |
| 91 | Demangler demangler; |
| 92 | |
| 93 | ASSERT_EQ("one::two::~two()", demangler.Parse("_ZN3one3twoD0Ev")); |
| 94 | ASSERT_EQ("one::two::~two()", demangler.Parse("_ZN3one3twoD1Ev")); |
| 95 | ASSERT_EQ("one::two::~two()", demangler.Parse("_ZN3one3twoD2Ev")); |
| 96 | ASSERT_EQ("one::two::~two()", demangler.Parse("_ZN3one3twoD5Ev")); |
| 97 | ASSERT_EQ("one::two::three::~three()", demangler.Parse("_ZN3one3two5threeD0Ev")); |
| 98 | |
| 99 | ASSERT_EQ("_ZN3one3twoD3Ev", demangler.Parse("_ZN3one3twoD3Ev")); |
| 100 | ASSERT_EQ("_ZN3one3twoD4Ev", demangler.Parse("_ZN3one3twoD4Ev")); |
| 101 | ASSERT_EQ("_ZN3one3twoD6Ev", demangler.Parse("_ZN3one3twoD6Ev")); |
| 102 | ASSERT_EQ("_ZN3one3twoD7Ev", demangler.Parse("_ZN3one3twoD7Ev")); |
| 103 | ASSERT_EQ("_ZN3one3twoD8Ev", demangler.Parse("_ZN3one3twoD8Ev")); |
| 104 | ASSERT_EQ("_ZN3one3twoD9Ev", demangler.Parse("_ZN3one3twoD9Ev")); |
| 105 | |
| 106 | ASSERT_EQ("one::two<three::four>::~two()", demangler.Parse("_ZN3one3twoIN5three4fourEED2Ev")); |
| 107 | } |
| 108 | |
| 109 | TEST(DemangleTest, ConstructorValues) { |
| 110 | Demangler demangler; |
| 111 | |
| 112 | ASSERT_EQ("one::two::two()", demangler.Parse("_ZN3one3twoC1Ev")); |
| 113 | ASSERT_EQ("one::two::two()", demangler.Parse("_ZN3one3twoC2Ev")); |
| 114 | ASSERT_EQ("one::two::two()", demangler.Parse("_ZN3one3twoC3Ev")); |
| 115 | ASSERT_EQ("one::two::two()", demangler.Parse("_ZN3one3twoC5Ev")); |
| 116 | ASSERT_EQ("one::two::three::three()", demangler.Parse("_ZN3one3two5threeC1Ev")); |
| 117 | |
| 118 | ASSERT_EQ("_ZN3one3twoC0Ev", demangler.Parse("_ZN3one3twoC0Ev")); |
| 119 | ASSERT_EQ("_ZN3one3twoC4Ev", demangler.Parse("_ZN3one3twoC4Ev")); |
| 120 | ASSERT_EQ("_ZN3one3twoC6Ev", demangler.Parse("_ZN3one3twoC6Ev")); |
| 121 | ASSERT_EQ("_ZN3one3twoC7Ev", demangler.Parse("_ZN3one3twoC7Ev")); |
| 122 | ASSERT_EQ("_ZN3one3twoC8Ev", demangler.Parse("_ZN3one3twoC8Ev")); |
| 123 | ASSERT_EQ("_ZN3one3twoC9Ev", demangler.Parse("_ZN3one3twoC9Ev")); |
| 124 | |
| 125 | ASSERT_EQ("one::two<three::four>::two()", demangler.Parse("_ZN3one3twoIN5three4fourEEC1Ev")); |
| 126 | } |
| 127 | |
| 128 | TEST(DemangleTest, OperatorValues) { |
| 129 | Demangler demangler; |
| 130 | |
| 131 | ASSERT_EQ("operator&&()", demangler.Parse("_Zaav")); |
| 132 | ASSERT_EQ("operator&()", demangler.Parse("_Zadv")); |
| 133 | ASSERT_EQ("operator&()", demangler.Parse("_Zanv")); |
| 134 | ASSERT_EQ("operator&=()", demangler.Parse("_ZaNv")); |
| 135 | ASSERT_EQ("operator=()", demangler.Parse("_ZaSv")); |
| 136 | ASSERT_EQ("operator()()", demangler.Parse("_Zclv")); |
| 137 | ASSERT_EQ("operator,()", demangler.Parse("_Zcmv")); |
| 138 | ASSERT_EQ("operator~()", demangler.Parse("_Zcov")); |
| 139 | ASSERT_EQ("operator delete[]()", demangler.Parse("_Zdav")); |
| 140 | ASSERT_EQ("operator*()", demangler.Parse("_Zdev")); |
| 141 | ASSERT_EQ("operator delete()", demangler.Parse("_Zdlv")); |
| 142 | ASSERT_EQ("operator/()", demangler.Parse("_Zdvv")); |
| 143 | ASSERT_EQ("operator/=()", demangler.Parse("_ZdVv")); |
| 144 | ASSERT_EQ("operator^()", demangler.Parse("_Zeov")); |
| 145 | ASSERT_EQ("operator^=()", demangler.Parse("_ZeOv")); |
| 146 | ASSERT_EQ("operator==()", demangler.Parse("_Zeqv")); |
| 147 | ASSERT_EQ("operator>=()", demangler.Parse("_Zgev")); |
| 148 | ASSERT_EQ("operator>()", demangler.Parse("_Zgtv")); |
| 149 | ASSERT_EQ("operator[]()", demangler.Parse("_Zixv")); |
| 150 | ASSERT_EQ("operator<=()", demangler.Parse("_Zlev")); |
| 151 | ASSERT_EQ("operator<<()", demangler.Parse("_Zlsv")); |
| 152 | ASSERT_EQ("operator<<=()", demangler.Parse("_ZlSv")); |
| 153 | ASSERT_EQ("operator<()", demangler.Parse("_Zltv")); |
| 154 | ASSERT_EQ("operator-()", demangler.Parse("_Zmiv")); |
| 155 | ASSERT_EQ("operator-=()", demangler.Parse("_ZmIv")); |
| 156 | ASSERT_EQ("operator*()", demangler.Parse("_Zmlv")); |
| 157 | ASSERT_EQ("operator*=()", demangler.Parse("_ZmLv")); |
| 158 | ASSERT_EQ("operator--()", demangler.Parse("_Zmmv")); |
| 159 | ASSERT_EQ("operator new[]()", demangler.Parse("_Znav")); |
| 160 | ASSERT_EQ("operator!=()", demangler.Parse("_Znev")); |
| 161 | ASSERT_EQ("operator-()", demangler.Parse("_Zngv")); |
| 162 | ASSERT_EQ("operator!()", demangler.Parse("_Zntv")); |
| 163 | ASSERT_EQ("operator new()", demangler.Parse("_Znwv")); |
| 164 | ASSERT_EQ("operator||()", demangler.Parse("_Zoov")); |
| 165 | ASSERT_EQ("operator|()", demangler.Parse("_Zorv")); |
| 166 | ASSERT_EQ("operator|=()", demangler.Parse("_ZoRv")); |
| 167 | ASSERT_EQ("operator->*()", demangler.Parse("_Zpmv")); |
| 168 | ASSERT_EQ("operator+()", demangler.Parse("_Zplv")); |
| 169 | ASSERT_EQ("operator+=()", demangler.Parse("_ZpLv")); |
| 170 | ASSERT_EQ("operator++()", demangler.Parse("_Zppv")); |
| 171 | ASSERT_EQ("operator+()", demangler.Parse("_Zpsv")); |
| 172 | ASSERT_EQ("operator->()", demangler.Parse("_Zptv")); |
| 173 | ASSERT_EQ("operator?()", demangler.Parse("_Zquv")); |
| 174 | ASSERT_EQ("operator%()", demangler.Parse("_Zrmv")); |
| 175 | ASSERT_EQ("operator%=()", demangler.Parse("_ZrMv")); |
| 176 | ASSERT_EQ("operator>>()", demangler.Parse("_Zrsv")); |
| 177 | ASSERT_EQ("operator>>=()", demangler.Parse("_ZrSv")); |
| 178 | |
| 179 | // Spot check using an operator as part of function name. |
| 180 | ASSERT_EQ("operator&&()", demangler.Parse("_ZNaaEv")); |
| 181 | ASSERT_EQ("operator++()", demangler.Parse("_ZNppEv")); |
| 182 | ASSERT_EQ("one::operator++()", demangler.Parse("_ZN3oneppEv")); |
| 183 | |
| 184 | // Spot check using an operator in an argument name. |
| 185 | ASSERT_EQ("operator+(operator|=)", demangler.Parse("_ZNpsENoRE")); |
| 186 | ASSERT_EQ("operator==()", demangler.Parse("_Zeqv")); |
| 187 | ASSERT_EQ("one(arg1::operator|=, arg2::operator==)", |
| 188 | demangler.Parse("_ZN3oneEN4arg1oREN4arg2eqE")); |
| 189 | } |
| 190 | |
| 191 | TEST(DemangleTest, FunctionStartsWithNumber) { |
| 192 | Demangler demangler; |
| 193 | |
| 194 | ASSERT_EQ("value(char, int)", demangler.Parse("_Z5valueci")); |
| 195 | ASSERT_EQ("abcdefjklmn(signed char)", demangler.Parse("_Z11abcdefjklmna")); |
| 196 | ASSERT_EQ("value(one, signed char)", demangler.Parse("_Z5value3onea")); |
| 197 | } |
| 198 | |
Christopher Ferris | 4504bba | 2017-06-01 17:37:09 -0700 | [diff] [blame] | 199 | TEST(DemangleTest, FunctionStartsWithLPlusNumber) { |
| 200 | Demangler demangler; |
| 201 | |
| 202 | ASSERT_EQ("value(char, int)", demangler.Parse("_ZL5valueci")); |
| 203 | ASSERT_EQ("abcdefjklmn(signed char)", demangler.Parse("_ZL11abcdefjklmna")); |
| 204 | ASSERT_EQ("value(one, signed char)", demangler.Parse("_ZL5value3onea")); |
| 205 | } |
| 206 | |
Christopher Ferris | 9323b72 | 2017-03-03 17:43:14 -0800 | [diff] [blame] | 207 | TEST(DemangleTest, StdTypes) { |
| 208 | Demangler demangler; |
| 209 | |
| 210 | ASSERT_EQ("std::one", demangler.Parse("_ZNSt3oneE")); |
| 211 | ASSERT_EQ("std::one(std::two)", demangler.Parse("_ZNSt3oneESt3two")); |
| 212 | ASSERT_EQ("std::std::one(std::two)", demangler.Parse("_ZNStSt3oneESt3two")); |
| 213 | ASSERT_EQ("std()", demangler.Parse("_ZNStEv")); |
| 214 | ASSERT_EQ("one::std::std::two::~two(one::std::std::two)", |
| 215 | demangler.Parse("_ZN3oneStSt3twoD0ES0_")); |
| 216 | |
| 217 | ASSERT_EQ("std::allocator", demangler.Parse("_ZNSaE")); |
| 218 | ASSERT_EQ("std::basic_string", demangler.Parse("_ZNSbE")); |
| 219 | ASSERT_EQ("_ZNScE", demangler.Parse("_ZNScE")); |
| 220 | ASSERT_EQ("std::iostream", demangler.Parse("_ZNSdE")); |
| 221 | ASSERT_EQ("_ZNSeE", demangler.Parse("_ZNSeE")); |
| 222 | ASSERT_EQ("_ZNSfE", demangler.Parse("_ZNSfE")); |
| 223 | ASSERT_EQ("_ZNSgE", demangler.Parse("_ZNSgE")); |
| 224 | ASSERT_EQ("_ZNShE", demangler.Parse("_ZNShE")); |
| 225 | ASSERT_EQ("std::istream", demangler.Parse("_ZNSiE")); |
| 226 | ASSERT_EQ("_ZNSjE", demangler.Parse("_ZNSjE")); |
| 227 | ASSERT_EQ("_ZNSkE", demangler.Parse("_ZNSkE")); |
| 228 | ASSERT_EQ("_ZNSlE", demangler.Parse("_ZNSlE")); |
| 229 | ASSERT_EQ("_ZNSmE", demangler.Parse("_ZNSmE")); |
| 230 | ASSERT_EQ("_ZNSnE", demangler.Parse("_ZNSnE")); |
| 231 | ASSERT_EQ("std::ostream", demangler.Parse("_ZNSoE")); |
| 232 | ASSERT_EQ("_ZNSpE", demangler.Parse("_ZNSpE")); |
| 233 | ASSERT_EQ("_ZNSqE", demangler.Parse("_ZNSqE")); |
| 234 | ASSERT_EQ("_ZNSrE", demangler.Parse("_ZNSrE")); |
| 235 | ASSERT_EQ("std::string", demangler.Parse("_ZNSsE")); |
| 236 | ASSERT_EQ("_ZNSuE", demangler.Parse("_ZNSuE")); |
| 237 | ASSERT_EQ("_ZNSvE", demangler.Parse("_ZNSvE")); |
| 238 | ASSERT_EQ("_ZNSwE", demangler.Parse("_ZNSwE")); |
| 239 | ASSERT_EQ("_ZNSxE", demangler.Parse("_ZNSxE")); |
| 240 | ASSERT_EQ("_ZNSyE", demangler.Parse("_ZNSyE")); |
| 241 | ASSERT_EQ("_ZNSzE", demangler.Parse("_ZNSzE")); |
| 242 | } |
| 243 | |
| 244 | TEST(DemangleTest, SingleLetterArguments) { |
| 245 | Demangler demangler; |
| 246 | |
| 247 | ASSERT_EQ("func(signed char)", demangler.Parse("_ZN4funcEa")); |
| 248 | ASSERT_EQ("func(bool)", demangler.Parse("_ZN4funcEb")); |
| 249 | ASSERT_EQ("func(char)", demangler.Parse("_ZN4funcEc")); |
| 250 | ASSERT_EQ("func(double)", demangler.Parse("_ZN4funcEd")); |
| 251 | ASSERT_EQ("func(long double)", demangler.Parse("_ZN4funcEe")); |
| 252 | ASSERT_EQ("func(float)", demangler.Parse("_ZN4funcEf")); |
| 253 | ASSERT_EQ("func(__float128)", demangler.Parse("_ZN4funcEg")); |
| 254 | ASSERT_EQ("func(unsigned char)", demangler.Parse("_ZN4funcEh")); |
| 255 | ASSERT_EQ("func(int)", demangler.Parse("_ZN4funcEi")); |
| 256 | ASSERT_EQ("func(unsigned int)", demangler.Parse("_ZN4funcEj")); |
| 257 | ASSERT_EQ("_ZN4funcEk", demangler.Parse("_ZN4funcEk")); |
| 258 | ASSERT_EQ("func(long)", demangler.Parse("_ZN4funcEl")); |
| 259 | ASSERT_EQ("func(unsigned long)", demangler.Parse("_ZN4funcEm")); |
| 260 | ASSERT_EQ("func(__int128)", demangler.Parse("_ZN4funcEn")); |
| 261 | ASSERT_EQ("func(unsigned __int128)", demangler.Parse("_ZN4funcEo")); |
| 262 | ASSERT_EQ("_ZN4funcEp", demangler.Parse("_ZN4funcEp")); |
| 263 | ASSERT_EQ("_ZN4funcEq", demangler.Parse("_ZN4funcEq")); |
| 264 | ASSERT_EQ("_ZN4funcEr", demangler.Parse("_ZN4funcEr")); |
| 265 | ASSERT_EQ("func(short)", demangler.Parse("_ZN4funcEs")); |
| 266 | ASSERT_EQ("func(unsigned short)", demangler.Parse("_ZN4funcEt")); |
| 267 | ASSERT_EQ("_ZN4funcEu", demangler.Parse("_ZN4funcEu")); |
| 268 | ASSERT_EQ("func()", demangler.Parse("_ZN4funcEv")); |
| 269 | ASSERT_EQ("func(wchar_t)", demangler.Parse("_ZN4funcEw")); |
| 270 | ASSERT_EQ("func(long long)", demangler.Parse("_ZN4funcEx")); |
| 271 | ASSERT_EQ("func(unsigned long long)", demangler.Parse("_ZN4funcEy")); |
| 272 | ASSERT_EQ("func(...)", demangler.Parse("_ZN4funcEz")); |
| 273 | } |
| 274 | |
| 275 | TEST(DemangleTest, DArguments) { |
| 276 | Demangler demangler; |
| 277 | |
| 278 | ASSERT_EQ("func(auto)", demangler.Parse("_ZN4funcEDa")); |
| 279 | ASSERT_EQ("_ZN4funcEDb", demangler.Parse("_ZN4funcEDb")); |
| 280 | ASSERT_EQ("_ZN4funcEDc", demangler.Parse("_ZN4funcEDc")); |
| 281 | ASSERT_EQ("func(decimal64)", demangler.Parse("_ZN4funcEDd")); |
| 282 | ASSERT_EQ("func(decimal128)", demangler.Parse("_ZN4funcEDe")); |
| 283 | ASSERT_EQ("func(decimal32)", demangler.Parse("_ZN4funcEDf")); |
| 284 | ASSERT_EQ("_ZN4funcEDg", demangler.Parse("_ZN4funcEDg")); |
| 285 | ASSERT_EQ("func(half)", demangler.Parse("_ZN4funcEDh")); |
| 286 | ASSERT_EQ("func(char32_t)", demangler.Parse("_ZN4funcEDi")); |
| 287 | ASSERT_EQ("_ZN4funcEDj", demangler.Parse("_ZN4funcEDj")); |
| 288 | ASSERT_EQ("_ZN4funcEDk", demangler.Parse("_ZN4funcEDk")); |
| 289 | ASSERT_EQ("_ZN4funcEDl", demangler.Parse("_ZN4funcEDl")); |
| 290 | ASSERT_EQ("_ZN4funcEDm", demangler.Parse("_ZN4funcEDm")); |
| 291 | ASSERT_EQ("func(decltype(nullptr))", demangler.Parse("_ZN4funcEDn")); |
| 292 | ASSERT_EQ("_ZN4funcEDo", demangler.Parse("_ZN4funcEDo")); |
| 293 | ASSERT_EQ("_ZN4funcEDp", demangler.Parse("_ZN4funcEDp")); |
| 294 | ASSERT_EQ("_ZN4funcEDq", demangler.Parse("_ZN4funcEDq")); |
| 295 | ASSERT_EQ("_ZN4funcEDr", demangler.Parse("_ZN4funcEDr")); |
| 296 | ASSERT_EQ("func(char16_t)", demangler.Parse("_ZN4funcEDs")); |
| 297 | ASSERT_EQ("_ZN4funcEDt", demangler.Parse("_ZN4funcEDt")); |
| 298 | ASSERT_EQ("_ZN4funcEDu", demangler.Parse("_ZN4funcEDu")); |
| 299 | ASSERT_EQ("_ZN4funcEDv", demangler.Parse("_ZN4funcEDv")); |
| 300 | ASSERT_EQ("_ZN4funcEDw", demangler.Parse("_ZN4funcEDw")); |
| 301 | ASSERT_EQ("_ZN4funcEDx", demangler.Parse("_ZN4funcEDx")); |
| 302 | ASSERT_EQ("_ZN4funcEDy", demangler.Parse("_ZN4funcEDy")); |
| 303 | ASSERT_EQ("_ZN4funcEDz", demangler.Parse("_ZN4funcEDz")); |
| 304 | } |
| 305 | |
| 306 | TEST(DemangleTest, FunctionArguments) { |
| 307 | Demangler demangler; |
| 308 | |
| 309 | ASSERT_EQ("func(char ())", demangler.Parse("_ZN4funcEFcvE")); |
| 310 | ASSERT_EQ("func(char (*)())", demangler.Parse("_ZN4funcEPFcvE")); |
| 311 | ASSERT_EQ("func(char (&)())", demangler.Parse("_ZN4funcERFcvE")); |
| 312 | ASSERT_EQ("func(char (&)())", demangler.Parse("_ZN4funcERFcvE")); |
| 313 | ASSERT_EQ("func(char (*&)())", demangler.Parse("_ZN4funcERPFcvE")); |
| 314 | ASSERT_EQ("func(char (*)(int) const)", demangler.Parse("_ZN4funcEPKFciE")); |
| 315 | ASSERT_EQ("func(char (&)() const)", demangler.Parse("_ZN4funcERKFcvE")); |
| 316 | ASSERT_EQ("func(char (&)() volatile)", demangler.Parse("_ZN4funcERVFcvE")); |
| 317 | ASSERT_EQ("func(char (&)() volatile const)", demangler.Parse("_ZN4funcERKVFcvE")); |
| 318 | ASSERT_EQ("func(char (&)() const volatile)", demangler.Parse("_ZN4funcERVKFcvE")); |
| 319 | ASSERT_EQ("func(char (&)(int, signed char) const)", demangler.Parse("_ZN4funcERKFciaE")); |
| 320 | ASSERT_EQ("fake(char (&* volatile const)(void, void, signed char), signed char)", |
| 321 | demangler.Parse("_ZN4fakeEKVPRFcvvaEa")); |
| 322 | } |
| 323 | |
| 324 | TEST(DemangleTest, TemplateFunction) { |
| 325 | Demangler demangler; |
| 326 | |
| 327 | ASSERT_EQ("one<char>", demangler.Parse("_ZN3oneIcEE")); |
| 328 | ASSERT_EQ("one<void>", demangler.Parse("_ZN3oneIvEE")); |
| 329 | ASSERT_EQ("one<void*>", demangler.Parse("_ZN3oneIPvEE")); |
| 330 | ASSERT_EQ("one<void const>", demangler.Parse("_ZN3oneIKvEE")); |
| 331 | ASSERT_EQ("one<char, int, bool>", demangler.Parse("_ZN3oneIcibEE")); |
| 332 | ASSERT_EQ("one::two<three>", demangler.Parse("_ZN3one3twoIN5threeEEE")); |
| 333 | ASSERT_EQ("one<char, int, two::three>", demangler.Parse("_ZN3oneIciN3two5threeEEE")); |
| 334 | // Template within templates. |
| 335 | ASSERT_EQ("one::two<three<char, int>>", demangler.Parse("_ZN3one3twoIN5threeIciEEEE")); |
| 336 | ASSERT_EQ("one::two<three<char, four<int>>>", demangler.Parse("_ZN3one3twoIN5threeIcN4fourIiEEEEEE")); |
Christopher Ferris | 584333e | 2017-10-27 12:29:02 -0700 | [diff] [blame] | 337 | |
| 338 | ASSERT_EQ("one<char>", demangler.Parse("_Z3oneIcE")); |
| 339 | ASSERT_EQ("one<void>", demangler.Parse("_Z3oneIvE")); |
| 340 | ASSERT_EQ("one<void*>", demangler.Parse("_Z3oneIPvE")); |
| 341 | ASSERT_EQ("one<void const>", demangler.Parse("_Z3oneIKvE")); |
| 342 | ASSERT_EQ("one<char, int, bool>", demangler.Parse("_Z3oneIcibE")); |
| 343 | ASSERT_EQ("one(two<three>)", demangler.Parse("_Z3one3twoIN5threeEE")); |
| 344 | ASSERT_EQ("one<char, int, two::three>", demangler.Parse("_Z3oneIciN3two5threeEE")); |
| 345 | // Template within templates. |
| 346 | ASSERT_EQ("one(two<three<char, int>>)", demangler.Parse("_Z3one3twoIN5threeIciEEE")); |
| 347 | ASSERT_EQ("one(two<three<char, four<int>>>)", |
| 348 | demangler.Parse("_Z3one3twoIN5threeIcN4fourIiEEEEE")); |
| 349 | } |
| 350 | |
| 351 | TEST(DemangleTest, TemplateFunctionWithReturnType) { |
| 352 | Demangler demangler; |
| 353 | |
| 354 | ASSERT_EQ("char one<int>(char)", demangler.Parse("_Z3oneIiEcc")); |
| 355 | ASSERT_EQ("void one<int>()", demangler.Parse("_Z3oneIiEvv")); |
| 356 | ASSERT_EQ("char one<int>()", demangler.Parse("_Z3oneIiEcv")); |
| 357 | ASSERT_EQ("char one<int>(void, void)", demangler.Parse("_Z3oneIiEcvv")); |
| 358 | ASSERT_EQ("char one<int>()", demangler.Parse("_ZN3oneIiEEcv")); |
| 359 | ASSERT_EQ("char one<int>(void, void)", demangler.Parse("_ZN3oneIiEEcvv")); |
Christopher Ferris | 9323b72 | 2017-03-03 17:43:14 -0800 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | TEST(DemangleTest, TemplateArguments) { |
| 363 | Demangler demangler; |
| 364 | |
| 365 | ASSERT_EQ("one(two<char>)", demangler.Parse("_ZN3oneE3twoIcE")); |
| 366 | ASSERT_EQ("one(two<char, void>)", demangler.Parse("_ZN3oneE3twoIcvE")); |
| 367 | ASSERT_EQ("one(two<char, void, three<four, int>>)", |
| 368 | demangler.Parse("_ZN3oneE3twoIcv5threeI4fouriEE")); |
| 369 | } |
| 370 | |
| 371 | TEST(DemangleTest, SubstitutionUnderscore) { |
| 372 | Demangler demangler; |
| 373 | |
| 374 | ASSERT_EQ("a::a", demangler.Parse("_ZN1aS_E")); |
| 375 | ASSERT_EQ("one::one", demangler.Parse("_ZN3oneS_E")); |
| 376 | ASSERT_EQ("one::two::one", demangler.Parse("_ZN3one3twoS_E")); |
| 377 | ASSERT_EQ("one::two::three::one", demangler.Parse("_ZN3one3two5threeS_E")); |
| 378 | ASSERT_EQ("one::two(one)", demangler.Parse("_ZN3one3twoES_")); |
| 379 | ASSERT_EQ("one::two(three::one)", demangler.Parse("_ZN3one3twoEN5threeS_E")); |
| 380 | |
| 381 | // Special case that St is part of the saved value used in the substitution. |
| 382 | ASSERT_EQ("std::one::std::one", demangler.Parse("_ZNSt3oneS_E")); |
| 383 | |
| 384 | // Multiple substitutions in the string. |
| 385 | ASSERT_EQ("one::one(one, one)", demangler.Parse("_ZN3oneS_ES_S_")); |
| 386 | ASSERT_EQ("std::one::two::std::one(std::one)", demangler.Parse("_ZNSt3one3twoS_ES_")); |
| 387 | } |
| 388 | |
| 389 | TEST(DemangleTest, SubstitutionByNumber) { |
| 390 | Demangler demangler; |
| 391 | |
| 392 | // Basic substitution. |
| 393 | ASSERT_EQ("a::b::c(a::b)", demangler.Parse("_ZN1a1b1cES0_")); |
| 394 | ASSERT_EQ("_ZN1a1b1cES1_", demangler.Parse("_ZN1a1b1cES1_")); |
| 395 | ASSERT_EQ("a::b::c::d(a::b::c)", demangler.Parse("_ZN1a1b1c1dES1_")); |
| 396 | ASSERT_EQ("a::b::c::d::e::f::g::h::i::j::k::l::m::n::o::p::q(a::b::c::d::e::f::g::h::i::j::k::l)", |
| 397 | demangler.Parse("_ZN1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1qESA_")); |
| 398 | ASSERT_EQ("a::b::c::d::e::f::g::h::i::j::k::l::m::n::o::p::q(a::b::c::d::e::f::g::h::i::j::k::l::m)", |
| 399 | demangler.Parse("_ZN1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1qESB_")); |
| 400 | |
| 401 | // Verify argument modifiers are included in substitution list. |
| 402 | ASSERT_EQ("one::two(char&* volatile const, char&)", demangler.Parse("_ZN3one3twoEKVPRcS0_")); |
| 403 | ASSERT_EQ("one::two(char&* volatile const, char&*)", demangler.Parse("_ZN3one3twoEKVPRcS1_")); |
| 404 | ASSERT_EQ("one::two(char&* volatile const, char&* volatile const)", |
| 405 | demangler.Parse("_ZN3one3twoEKVPRcS2_")); |
| 406 | ASSERT_EQ("one::two(int&* volatile* const, int&)", demangler.Parse("_ZN3one3twoEKPVPRiS0_")); |
| 407 | ASSERT_EQ("one::two(int&* volatile const, int&*)", demangler.Parse("_ZN3one3twoEKVPRiS1_")); |
| 408 | ASSERT_EQ("one::two(int&* volatile const, int&* volatile const)", |
| 409 | demangler.Parse("_ZN3one3twoEKVPRiS2_")); |
| 410 | |
| 411 | // Verify Constructor/Destructor does properly save from function name. |
| 412 | ASSERT_EQ("_ZN1a1bES0_", demangler.Parse("_ZN1a1bES0_")); |
| 413 | ASSERT_EQ("a::b::b(a::b)", demangler.Parse("_ZN1a1bC1ES0_")); |
| 414 | ASSERT_EQ("a::b::~b(a::b)", demangler.Parse("_ZN1a1bD0ES0_")); |
| 415 | |
| 416 | // Make sure substitution values are not saved. |
| 417 | ASSERT_EQ("a::b::b(a::b, char*, char*)", demangler.Parse("_ZN1a1bC1ES0_PcS1_")); |
| 418 | } |
| 419 | |
| 420 | TEST(DemangleTest, ComplexSubstitution) { |
| 421 | Demangler demangler; |
| 422 | |
| 423 | ASSERT_EQ("one::two<one::three>::two()", demangler.Parse("_ZN3one3twoINS_5threeEEC1Ev")); |
| 424 | ASSERT_EQ("one::two::two(one::two const&, bool, one::three*)", |
| 425 | demangler.Parse("_ZN3one3twoC2ERKS0_bPNS_5threeE")); |
| 426 | ASSERT_EQ("one::two::three::four<one::five>::~four(one::two*)", |
| 427 | demangler.Parse("_ZN3one3two5three4fourINS_4fiveEED2EPS0_")); |
| 428 | ASSERT_EQ("one::two::three::four<one::five>::~four(one::two::three*)", |
| 429 | demangler.Parse("_ZN3one3two5three4fourINS_4fiveEED2EPS1_")); |
| 430 | ASSERT_EQ("one::two::three::four<one::five>::~four(one::two::three::four*)", |
| 431 | demangler.Parse("_ZN3one3two5three4fourINS_4fiveEED2EPS2_")); |
| 432 | ASSERT_EQ("one::two::three::four<one::five>::~four(one::five*)", |
| 433 | demangler.Parse("_ZN3one3two5three4fourINS_4fiveEED2EPS3_")); |
| 434 | } |
| 435 | |
Christopher Ferris | 584333e | 2017-10-27 12:29:02 -0700 | [diff] [blame] | 436 | TEST(DemangleTest, TemplateSubstitution) { |
| 437 | Demangler demangler; |
| 438 | |
| 439 | ASSERT_EQ("void one<int, double>(int)", demangler.Parse("_ZN3oneIidEEvT_")); |
| 440 | ASSERT_EQ("void one<int, double>(double)", demangler.Parse("_ZN3oneIidEEvT0_")); |
| 441 | ASSERT_EQ("void one<int, double, char, void>(char)", demangler.Parse("_ZN3oneIidcvEEvT1_")); |
| 442 | |
| 443 | ASSERT_EQ("void one<int, double>(int)", demangler.Parse("_Z3oneIidEvT_")); |
| 444 | ASSERT_EQ("void one<int, double>(double)", demangler.Parse("_Z3oneIidEvT0_")); |
| 445 | ASSERT_EQ("void one<int, double, char, void>(char)", demangler.Parse("_Z3oneIidcvEvT1_")); |
| 446 | |
| 447 | ASSERT_EQ("void one<a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r>(l)", |
| 448 | demangler.Parse("_ZN3oneI1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1rEEvT10_")); |
| 449 | ASSERT_EQ("void one<a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r>(m)", |
| 450 | demangler.Parse("_ZN3oneI1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1rEEvT11_")); |
| 451 | |
| 452 | ASSERT_EQ("void one<a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r>(l)", |
| 453 | demangler.Parse("_Z3oneI1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1rEvT10_")); |
| 454 | ASSERT_EQ("void one<a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r>(m)", |
| 455 | demangler.Parse("_Z3oneI1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1rEvT11_")); |
| 456 | } |
| 457 | |
Christopher Ferris | 9323b72 | 2017-03-03 17:43:14 -0800 | [diff] [blame] | 458 | TEST(DemangleTest, StringTooLong) { |
| 459 | Demangler demangler; |
| 460 | |
| 461 | ASSERT_EQ("_ZN3one3twoC2ERKS0_bPNS_5threeE", |
| 462 | demangler.Parse("_ZN3one3twoC2ERKS0_bPNS_5threeE", 10)); |
| 463 | ASSERT_EQ("_ZN3one3twoC2ERKS0_bPNS_5threeE", |
| 464 | demangler.Parse("_ZN3one3twoC2ERKS0_bPNS_5threeE", 30)); |
| 465 | ASSERT_EQ("one::two::two(one::two const&, bool, one::three*)", |
| 466 | demangler.Parse("_ZN3one3twoC2ERKS0_bPNS_5threeE", 31)); |
| 467 | |
| 468 | // Check the length check only occurs after the two letter value |
| 469 | // has been processed. |
| 470 | ASSERT_EQ("one::two(auto)", demangler.Parse("_ZN3one3twoEDa", 15)); |
| 471 | ASSERT_EQ("one::two(auto)", demangler.Parse("_ZN3one3twoEDa", 14)); |
| 472 | ASSERT_EQ("one::two(auto)", demangler.Parse("_ZN3one3twoEDa", 13)); |
| 473 | ASSERT_EQ("_ZN3one3twoEDa", demangler.Parse("_ZN3one3twoEDa", 12)); |
| 474 | } |
| 475 | |
Christopher Ferris | 0523275 | 2017-10-11 15:22:29 -0700 | [diff] [blame] | 476 | TEST(DemangleTest, BooleanLiterals) { |
| 477 | Demangler demangler; |
| 478 | |
| 479 | ASSERT_EQ("one<true>", demangler.Parse("_ZN3oneILb1EEE")); |
| 480 | ASSERT_EQ("one<false>", demangler.Parse("_ZN3oneILb0EEE")); |
| 481 | ASSERT_EQ("one<false, true>", demangler.Parse("_ZN3oneILb0ELb1EEE")); |
Christopher Ferris | 584333e | 2017-10-27 12:29:02 -0700 | [diff] [blame] | 482 | |
| 483 | ASSERT_EQ("one<true>", demangler.Parse("_Z3oneILb1EE")); |
| 484 | ASSERT_EQ("one<false>", demangler.Parse("_Z3oneILb0EE")); |
| 485 | ASSERT_EQ("one<false, true>", demangler.Parse("_Z3oneILb0ELb1EE")); |
| 486 | |
| 487 | ASSERT_EQ("one(two<three<four>, false, true>)", |
| 488 | demangler.Parse("_ZN3oneE3twoI5threeI4fourELb0ELb1EE")); |
Christopher Ferris | 0523275 | 2017-10-11 15:22:29 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Christopher Ferris | 5a72ea0 | 2017-11-01 16:22:09 -0700 | [diff] [blame] | 491 | TEST(DemangleTest, non_virtual_thunk) { |
| 492 | Demangler demangler; |
| 493 | |
| 494 | ASSERT_EQ("non-virtual thunk to one", demangler.Parse("_ZThn0_N3oneE")); |
| 495 | ASSERT_EQ("non-virtual thunk to two", demangler.Parse("_ZThn0_3two")); |
| 496 | ASSERT_EQ("non-virtual thunk to three", demangler.Parse("_ZTh0_5three")); |
| 497 | ASSERT_EQ("non-virtual thunk to four", demangler.Parse("_ZTh_4four")); |
| 498 | ASSERT_EQ("non-virtual thunk to five", demangler.Parse("_ZTh0123456789_4five")); |
| 499 | ASSERT_EQ("non-virtual thunk to six", demangler.Parse("_ZThn0123456789_3six")); |
| 500 | |
| 501 | ASSERT_EQ("_ZThn0N3oneE", demangler.Parse("_ZThn0N3oneE")); |
| 502 | ASSERT_EQ("_ZThn03two", demangler.Parse("_ZThn03two")); |
| 503 | ASSERT_EQ("_ZTh05three", demangler.Parse("_ZTh05three")); |
| 504 | ASSERT_EQ("_ZTh4four", demangler.Parse("_ZTh4four")); |
| 505 | ASSERT_EQ("_ZTh01234567894five", demangler.Parse("_ZTh01234567894five")); |
| 506 | ASSERT_EQ("_ZThn01234567893six", demangler.Parse("_ZThn01234567893six")); |
| 507 | ASSERT_EQ("_ZT_N3oneE", demangler.Parse("_ZT_N3oneE")); |
| 508 | ASSERT_EQ("_ZT0_N3oneE", demangler.Parse("_ZT0_N3oneE")); |
| 509 | ASSERT_EQ("_ZTH_N3oneE", demangler.Parse("_ZTH_N3oneE")); |
| 510 | } |
| 511 | |
Elliott Hughes | d7bb826 | 2018-02-09 17:30:14 -0800 | [diff] [blame] | 512 | TEST(DemangleTest, r_value_reference) { |
| 513 | Demangler demangler; |
| 514 | ASSERT_EQ( |
| 515 | "android::SurfaceComposerClient::Transaction::merge(android::SurfaceComposerClient::" |
| 516 | "Transaction&&)", |
| 517 | demangler.Parse("_ZN7android21SurfaceComposerClient11Transaction5mergeEOS1_")); |
| 518 | } |
| 519 | |
| 520 | TEST(DemangleTest, initial_St) { |
| 521 | Demangler demangler; |
| 522 | EXPECT_EQ("std::state", demangler.Parse("_ZSt5state")); |
| 523 | EXPECT_EQ("std::_In::ward", demangler.Parse("_ZNSt3_In4wardE")); |
| 524 | EXPECT_EQ("std::__terminate(void (*)())", demangler.Parse("_ZSt11__terminatePFvvE")); |
| 525 | } |
| 526 | |
| 527 | TEST(DemangleTest, cfi) { |
| 528 | Demangler demangler; |
| 529 | EXPECT_EQ("nfa_sys_ptim_timer_update(tPTIM_CB*)", |
| 530 | demangler.Parse("_Z25nfa_sys_ptim_timer_updateP8tPTIM_CB")); |
| 531 | EXPECT_EQ("nfa_sys_ptim_timer_update(tPTIM_CB*) [clone .cfi]", |
| 532 | demangler.Parse("_Z25nfa_sys_ptim_timer_updateP8tPTIM_CB.cfi")); |
| 533 | } |
| 534 | |
Christopher Ferris | 9323b72 | 2017-03-03 17:43:14 -0800 | [diff] [blame] | 535 | TEST(DemangleTest, demangle) { |
| 536 | std::string str; |
| 537 | |
| 538 | str = demangle("_ZN1a1b1cES0_"); |
| 539 | ASSERT_EQ("a::b::c(a::b)", str); |
| 540 | |
| 541 | str = demangle("_"); |
| 542 | ASSERT_EQ("_", str); |
| 543 | |
| 544 | str = demangle("_Z"); |
| 545 | ASSERT_EQ("_Z", str); |
| 546 | |
| 547 | str = demangle("_Za"); |
| 548 | ASSERT_EQ("_Za", str); |
| 549 | |
| 550 | str = demangle("_Zaa"); |
| 551 | ASSERT_EQ("operator&&", str); |
| 552 | |
| 553 | str = demangle("Xa"); |
| 554 | ASSERT_EQ("Xa", str); |
| 555 | } |