DemangleTest.cpp 25 KB

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