Skip to content

[lldb][test] Test all libcxxabi demangler test-cases against TrackingOutputBuffer #137793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 31, 2025

Conversation

Michael137
Copy link
Member

@Michael137 Michael137 commented Apr 29, 2025

To test the infrastructure added in #131836 in would be nice to confirm that we can reconstruct all kinds of demangled names. The libcxxabi test-suite already has all those test-cases.

This patch copies those test-cases (taken from libcxxabi/test/test_demangle.pass.cpp), reconstructs the name like LLDB would when showing backtraces, and confirms that all demangled names can be fully reconstructed.

Two open questions:

  1. Do we really want a copy of all those test-cases in LLDB? It's
    unlikely to be kept in sync with the demangler test-suite. It includes 30,000+ test-cases
  2. Do we want to turn the GetDemangledBasename/GetDemangledScope/etc. into public APIs (e.g., on TrackingOutputBuffer) so that we can use the exact same method of extraction in the tests?

@llvmbot llvmbot added the lldb label Apr 29, 2025
@Michael137 Michael137 requested a review from labath April 29, 2025 11:58
@llvmbot
Copy link
Member

llvmbot commented Apr 29, 2025

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

To test the infrastructure added in #131836 in would be nice to confirm that we can reconstruct all kinds of demangled names. The libcxxabi test-suite already has all those test-cases.

This patch copies those test-cases (taken from libcxxabi/test/test_demangle.pass.cpp), reconstructs the name like LLDB would when showing backtraces, and confirms that all demangled names can be fully reconstructed.

Two open questions:

  1. Do we really want a copy of all those test-cases in LLDB? It's
    unlikely to be kept in sync with the demangler test-suite.
  2. Do we want to turn the GetDemangledBasename/GetDemangledScope/etc. into public APIs (e.g., on TrackingOutputBuffer) so that we can use the exact same method of extraction in the tests?

Patch is 5.03 MiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/137793.diff

2 Files Affected:

  • (added) lldb/unittests/Core/DemanglingCorrectness.inc (+30218)
  • (modified) lldb/unittests/Core/MangledTest.cpp (+56)
diff --git a/lldb/unittests/Core/DemanglingCorrectness.inc b/lldb/unittests/Core/DemanglingCorrectness.inc
new file mode 100644
index 0000000000000..dee9de083c037
--- /dev/null
+++ b/lldb/unittests/Core/DemanglingCorrectness.inc
@@ -0,0 +1,30218 @@
+// Taken from libcxxabi/test/test_demangle.pass.cpp
+{"_Z1A", "A"},
+{"_Z1Av", "A()"},
+{"_Z1A1B1C", "A(B, C)"},
+{"_Z1fDB3_", "f(_BitInt(3))"},
+{"_Z1fDU10_", "f(unsigned _BitInt(10))"},
+{"_Z1fIfEvDUstPT__", "void f<float>(unsigned _BitInt(sizeof (float*)))"},
+{"_Z1fIiEvDBstPT__", "void f<int>(_BitInt(sizeof (int*)))"},
+{"_Z4testI1A1BE1Cv", "C test<A, B>()"},
+{"_Z4testI1A1BET0_T_S3_", "B test<A, B>(A, A)"},
+{"_ZN1SgtEi", "S::operator>(int)"},
+{"_ZrsI1QEiT_i", "int operator>><Q>(Q, int)"},
+{"_ZN13dyldbootstrap5startEPK12macho_headeriPPKcl", "dyldbootstrap::start(macho_header const*, int, char const**, long)"},
+{"_ZN4dyld17getExecutablePathEv", "dyld::getExecutablePath()"},
+{"_ZN4dyld22mainExecutablePreboundEv", "dyld::mainExecutablePrebound()"},
+{"_ZN4dyld14mainExecutableEv", "dyld::mainExecutable()"},
+{"_ZN4dyld21findImageByMachHeaderEPK11mach_header", "dyld::findImageByMachHeader(mach_header const*)"},
+{"_ZN4dyld26findImageContainingAddressEPKv", "dyld::findImageContainingAddress(void const*)"},
+{"_ZN4dyld17clearErrorMessageEv", "dyld::clearErrorMessage()"},
+{"_ZN4dyld15getErrorMessageEv", "dyld::getErrorMessage()"},
+{"_ZN4dyld24registerUndefinedHandlerEPFvPKcE", "dyld::registerUndefinedHandler(void (*)(char const*))"},
+{"_ZN4dyld19openSharedCacheFileEv", "dyld::openSharedCacheFile()"},
+{"_ZN4dyld15setErrorMessageEPKc", "dyld::setErrorMessage(char const*)"},
+{"_ZN4dyld22registerRemoveCallbackEPFvPK11mach_headerlE", "dyld::registerRemoveCallback(void (*)(mach_header const*, long))"},
+{"_ZN4dyld13inSharedCacheEPKc", "dyld::inSharedCache(char const*)"},
+{"_ZN4dyld15runInitializersEP11ImageLoader", "dyld::runInitializers(ImageLoader*)"},
+{"_ZN4dyld27findCoalescedExportedSymbolEPKcPPKN11ImageLoader6SymbolEPPKS2_", "dyld::findCoalescedExportedSymbol(char const*, ImageLoader::Symbol const**, ImageLoader const**)"},
+{"_ZN4dyld22flatFindExportedSymbolEPKcPPKN11ImageLoader6SymbolEPPKS2_", "dyld::flatFindExportedSymbol(char const*, ImageLoader::Symbol const**, ImageLoader const**)"},
+{"_ZN4dyld15findLoadedImageERK4stat", "dyld::findLoadedImage(stat const&)"},
+{"_ZN4dyld24initializeMainExecutableEv", "dyld::initializeMainExecutable()"},
+{"_ZN4dyld4warnEPKcz", "dyld::warn(char const*, ...)"},
+{"_ZN4dyld29processDyldEnvironmentVaribleEPKcS1_", "dyld::processDyldEnvironmentVarible(char const*, char const*)"},
+{"_ZN4dyld3logEPKcz", "dyld::log(char const*, ...)"},
+{"_ZN4dyld6throwfEPKcz", "dyld::throwf(char const*, ...)"},
+{"_ZN4dyld9mkstringfEPKcz", "dyld::mkstringf(char const*, ...)"},
+{"_ZN4dyld14addMappedRangeEP11ImageLoadermm", "dyld::addMappedRange(ImageLoader*, unsigned long, unsigned long)"},
+{"_Z28coresymbolication_load_imageP25CSCppDyldSharedMemoryPagePK11ImageLoadery", "coresymbolication_load_image(CSCppDyldSharedMemoryPage*, ImageLoader const*, unsigned long long)"},
+{"_Z30coresymbolication_unload_imageP25CSCppDyldSharedMemoryPagePK11ImageLoader", "coresymbolication_unload_image(CSCppDyldSharedMemoryPage*, ImageLoader const*)"},
+{"_ZN4dyld18getCoalescedImagesEPP11ImageLoader", "dyld::getCoalescedImages(ImageLoader**)"},
+{"_ZN4dyld25findImageContainingSymbolEPKv", "dyld::findImageContainingSymbol(void const*)"},
+{"_ZN4dyld19registerAddCallbackEPFvPK11mach_headerlE", "dyld::registerAddCallback(void (*)(mach_header const*, long))"},
+{"_ZN4dyld14forEachImageDoEPFvP11ImageLoaderPvES2_", "dyld::forEachImageDo(void (*)(ImageLoader*, void*), void*)"},
+{"_ZN4dyld15getIndexedImageEj", "dyld::getIndexedImage(unsigned int)"},
+{"_ZN4dyld13getImageCountEv", "dyld::getImageCount()"},
+{"_ZN4dyld10validImageEPK11ImageLoader", "dyld::validImage(ImageLoader const*)"},
+{"_ZN4dyld30flatFindExportedSymbolWithHintEPKcS1_PPKN11ImageLoader6SymbolEPPKS2_", "dyld::flatFindExportedSymbolWithHint(char const*, char const*, ImageLoader::Symbol const**, ImageLoader const**)"},
+{"_ZN4dyld14loadFromMemoryEPKhyPKc", "dyld::loadFromMemory(unsigned char const*, unsigned long long, char const*)"},
+{"_ZN4dyld36registerImageStateBatchChangeHandlerE17dyld_image_statesPFPKcS0_jPK15dyld_image_infoE", "dyld::registerImageStateBatchChangeHandler(dyld_image_states, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*))"},
+{"_ZN4dyld37registerImageStateSingleChangeHandlerE17dyld_image_statesPFPKcS0_jPK15dyld_image_infoE", "dyld::registerImageStateSingleChangeHandler(dyld_image_states, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*))"},
+{"_ZN4dyld4haltEPKc", "dyld::halt(char const*)"},
+{"_ZN4dyld18fastBindLazySymbolEPP11ImageLoaderm", "dyld::fastBindLazySymbol(ImageLoader**, unsigned long)"},
+{"_ZN4dyld14bindLazySymbolEPK11mach_headerPm", "dyld::bindLazySymbol(mach_header const*, unsigned long*)"},
+{"_ZN4dyld14runTerminatorsEPv", "dyld::runTerminators(void*)"},
+{"_ZN4dyld11removeImageEP11ImageLoader", "dyld::removeImage(ImageLoader*)"},
+{"_ZN4dyld20garbageCollectImagesEv", "dyld::garbageCollectImages()"},
+{"_ZN4dyld9preflightEP11ImageLoaderRKNS0_10RPathChainE", "dyld::preflight(ImageLoader*, ImageLoader::RPathChain const&)"},
+{"_ZN4dyld4linkEP11ImageLoaderbRKNS0_10RPathChainE", "dyld::link(ImageLoader*, bool, ImageLoader::RPathChain const&)"},
+{"_ZN4dyld10cloneImageEP11ImageLoader", "dyld::cloneImage(ImageLoader*)"},
+{"_ZN4dyld4loadEPKcRKNS_11LoadContextE", "dyld::load(char const*, dyld::LoadContext const&)"},
+{"_ZN4dyld5_mainEPK12macho_headermiPPKcS5_S5_", "dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**)"},
+{"_ZNSt6vectorIN4dyld13RegisteredDOFESaIS1_EE5eraseEN9__gnu_cxx17__normal_iteratorIPS1_S3_EE", "std::vector<dyld::RegisteredDOF, std::allocator<dyld::RegisteredDOF>>::erase(__gnu_cxx::__normal_iterator<dyld::RegisteredDOF*, std::vector<dyld::RegisteredDOF, std::allocator<dyld::RegisteredDOF>>>)"},
+{"_ZNSt12_Vector_baseIPKcSaIS1_EED2Ev", "std::_Vector_base<char const*, std::allocator<char const*>>::~_Vector_base()"},
+{"_ZNSt6vectorIPKcSaIS1_EED2Ev", "std::vector<char const*, std::allocator<char const*>>::~vector()"},
+{"_ZNSt12_Vector_baseIPFPKc17dyld_image_statesjPK15dyld_image_infoESaIS7_EED2Ev", "std::_Vector_base<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)>>::~_Vector_base()"},
+{"_ZNSt6vectorIPFPKc17dyld_image_statesjPK15dyld_image_infoESaIS7_EED2Ev", "std::vector<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)>>::~vector()"},
+{"_ZNSt12_Vector_baseIPFvPK11mach_headerlESaIS4_EED2Ev", "std::_Vector_base<void (*)(mach_header const*, long), std::allocator<void (*)(mach_header const*, long)>>::~_Vector_base()"},
+{"_ZNSt6vectorIPFvPK11mach_headerlESaIS4_EED2Ev", "std::vector<void (*)(mach_header const*, long), std::allocator<void (*)(mach_header const*, long)>>::~vector()"},
+{"_ZNSt12_Vector_baseIN4dyld13RegisteredDOFESaIS1_EED2Ev", "std::_Vector_base<dyld::RegisteredDOF, std::allocator<dyld::RegisteredDOF>>::~_Vector_base()"},
+{"_ZNSt6vectorIN4dyld13RegisteredDOFESaIS1_EED2Ev", "std::vector<dyld::RegisteredDOF, std::allocator<dyld::RegisteredDOF>>::~vector()"},
+{"_ZNSt12_Vector_baseIP11ImageLoaderSaIS1_EED2Ev", "std::_Vector_base<ImageLoader*, std::allocator<ImageLoader*>>::~_Vector_base()"},
+{"_ZNSt6vectorIP11ImageLoaderSaIS1_EED2Ev", "std::vector<ImageLoader*, std::allocator<ImageLoader*>>::~vector()"},
+{"_ZN9__gnu_cxx13new_allocatorIPFPKc17dyld_image_statesjPK15dyld_image_infoEE8allocateEmPKv", "__gnu_cxx::new_allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)>::allocate(unsigned long, void const*)"},
+{"_ZN9__gnu_cxx13new_allocatorIPFvPK11mach_headerlEE8allocateEmPKv", "__gnu_cxx::new_allocator<void (*)(mach_header const*, long)>::allocate(unsigned long, void const*)"},
+{"_ZN9__gnu_cxx13new_allocatorIPKcE8allocateEmPKv", "__gnu_cxx::new_allocator<char const*>::allocate(unsigned long, void const*)"},
+{"_ZN9__gnu_cxx13new_allocatorIP11ImageLoaderE8allocateEmPKv", "__gnu_cxx::new_allocator<ImageLoader*>::allocate(unsigned long, void const*)"},
+{"_ZN9__gnu_cxx13new_allocatorIN4dyld13RegisteredDOFEE8allocateEmPKv", "__gnu_cxx::new_allocator<dyld::RegisteredDOF>::allocate(unsigned long, void const*)"},
+{"_ZNSt6vectorIN4dyld13RegisteredDOFESaIS1_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS1_S3_EERKS1_", "std::vector<dyld::RegisteredDOF, std::allocator<dyld::RegisteredDOF>>::_M_insert_aux(__gnu_cxx::__normal_iterator<dyld::RegisteredDOF*, std::vector<dyld::RegisteredDOF, std::allocator<dyld::RegisteredDOF>>>, dyld::RegisteredDOF const&)"},
+{"_ZNSt6vectorIN4dyld13RegisteredDOFESaIS1_EE9push_backERKS1_", "std::vector<dyld::RegisteredDOF, std::allocator<dyld::RegisteredDOF>>::push_back(dyld::RegisteredDOF const&)"},
+{"_ZSt18uninitialized_copyIPPFPKc17dyld_image_statesjPK15dyld_image_infoES8_ET0_T_SA_S9_", "char const* (**std::uninitialized_copy<char const* (**)(dyld_image_states, unsigned int, dyld_image_info const*), char const* (**)(dyld_image_states, unsigned int, dyld_image_info const*)>(char const* (**)(dyld_image_states, unsigned int, dyld_image_info const*), char const* (**)(dyld_image_states, unsigned int, dyld_image_info const*), char const* (**)(dyld_image_states, unsigned int, dyld_image_info const*)))(dyld_image_states, unsigned int, dyld_image_info const*)"},
+{"_ZSt18uninitialized_copyIPPFvPK11mach_headerlES5_ET0_T_S7_S6_", "void (**std::uninitialized_copy<void (**)(mach_header const*, long), void (**)(mach_header const*, long)>(void (**)(mach_header const*, long), void (**)(mach_header const*, long), void (**)(mach_header const*, long)))(mach_header const*, long)"},
+{"_ZSt18uninitialized_copyIPPKcS2_ET0_T_S4_S3_", "char const** std::uninitialized_copy<char const**, char const**>(char const**, char const**, char const**)"},
+{"_ZNSt15__copy_backwardILb1ESt26random_access_iterator_tagE8__copy_bIPFPKc17dyld_image_statesjPK15dyld_image_infoEEEPT_PKSB_SE_SC_", "char const* (**std::__copy_backward<true, std::random_access_iterator_tag>::__copy_b<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)>(char const* (* const*)(dyld_image_states, unsigned int, dyld_image_info const*), char const* (* const*)(dyld_image_states, unsigned int, dyld_image_info const*), char const* (**)(dyld_image_states, unsigned int, dyld_image_info const*)))(dyld_image_states, unsigned int, dyld_image_info const*)"},
+{"_ZNSt6vectorIPFPKc17dyld_image_statesjPK15dyld_image_infoESaIS7_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS7_S9_EERKS7_", "std::vector<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)>>::_M_insert_aux(__gnu_cxx::__normal_iterator<char const* (**)(dyld_image_states, unsigned int, dyld_image_info const*), std::vector<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)>>>, char const* (* const&)(dyld_image_states, unsigned int, dyld_image_info const*))"},
+{"_ZNSt6vectorIPFPKc17dyld_image_statesjPK15dyld_image_infoESaIS7_EE6insertEN9__gnu_cxx17__normal_iteratorIPS7_S9_EERKS7_", "std::vector<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)>>::insert(__gnu_cxx::__normal_iterator<char const* (**)(dyld_image_states, unsigned int, dyld_image_info const*), std::vector<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)>>>, char const* (* const&)(dyld_image_states, unsigned int, dyld_image_info const*))"},
+{"_ZNSt6vectorIPFPKc17dyld_image_statesjPK15dyld_image_infoESaIS7_EE9push_backERKS7_", "std::vector<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)>>::push_back(char const* (* const&)(dyld_image_states, unsigned int, dyld_image_info const*))"},
+{"_ZNSt15__copy_backwardILb1ESt26random_access_iterator_tagE8__copy_bIPFvPK11mach_headerlEEEPT_PKS8_SB_S9_", "void (**std::__copy_backward<true, std::random_access_iterator_tag>::__copy_b<void (*)(mach_header const*, long)>(void (* const*)(mach_header const*, long), void (* const*)(mach_header const*, long), void (**)(mach_header const*, long)))(mach_header const*, long)"},
+{"_ZNSt6vectorIPFvPK11mach_headerlESaIS4_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS4_S6_EERKS4_", "std::vector<void (*)(mach_header const*, long), std::allocator<void (*)(mach_header const*, long)>>::_M_insert_aux(__gnu_cxx::__normal_iterator<void (**)(mach_header const*, long), std::vector<void (*)(mach_header const*, long), std::allocator<void (*)(mach_header const*, long)>>>, void (* const&)(mach_header const*, long))"},
+{"_ZNSt6vectorIPFvPK11mach_headerlESaIS4_EE9push_backERKS4_", "std::vector<void (*)(mach_header const*, long), std::allocator<void (*)(mach_header const*, long)>>::push_back(void (* const&)(mach_header const*, long))"},
+{"_ZNSt15__copy_backwardILb1ESt26random_access_iterator_tagE8__copy_bIPKcEEPT_PKS5_S8_S6_", "char const** std::__copy_backward<true, std::random_access_iterator_tag>::__copy_b<char const*>(char const* const*, char const* const*, char const**)"},
+{"_ZNSt6vectorIPKcSaIS1_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS1_S3_EERKS1_", "std::vector<char const*, std::allocator<char const*>>::_M_insert_aux(__gnu_cxx::__normal_iterator<char const**, std::vector<char const*, std::allocator<char const*>>>, char const* const&)"},
+{"_ZNSt6vectorIPKcSaIS1_EE9push_backERKS1_", "std::vector<char const*, std::allocator<char const*>>::push_back(char const* const&)"},
+{"_ZNSt15__copy_backwardILb1ESt26random_access_iterator_tagE8__copy_bIP11ImageLoaderEEPT_PKS5_S8_S6_", "ImageLoader** std::__copy_backward<true, std::random_access_iterator_tag>::__copy_b<ImageLoader*>(ImageLoader* const*, ImageLoader* const*, ImageLoader**)"},
+{"_ZNSt6vectorIPFvPK11mach_headerlESaIS4_EE20_M_allocate_and_copyIPS4_EES8_mT_S9_", "void (**std::vector<void (*)(mach_header const*, long), std::allocator<void (*)(mach_header const*, long)>>::_M_allocate_and_copy<void (**)(mach_header const*, long)>(unsigned long, void (**)(mach_header const*, long), void (**)(mach_header const*, long)))(mach_header const*, long)"},
+{"_ZNSt6vectorIPFvPK11mach_headerlESaIS4_EE7reserveEm", "std::vector<void (*)(mach_header const*, long), std::allocator<void (*)(mach_header const*, long)>>::reserve(unsigned long)"},
+{"_ZNSt6vectorIN4dyld13RegisteredDOFESaIS1_EE20_M_allocate_and_copyIPS1_EES5_mT_S6_", "dyld::RegisteredDOF* std::vector<dyld::RegisteredDOF, std::allocator<dyld::RegisteredDOF>>::_M_allocate_and_copy<dyld::RegisteredDOF*>(unsigned long, dyld::RegisteredDOF*, dyld::RegisteredDOF*)"},
+{"_ZNSt6vectorIN4dyld13RegisteredDOFESaIS1_EE7reserveEm", "std::vector<dyld::RegisteredDOF, std::allocator<dyld::RegisteredDOF>>::reserve(unsigned long)"},
+{"_ZSt18uninitialized_copyIPP11ImageLoaderS2_ET0_T_S4_S3_", "ImageLoader** std::uninitialized_copy<ImageLoader**, ImageLoader**>(ImageLoader**, ImageLoader**, ImageLoader**)"},
+{"_ZNSt6vectorIP11ImageLoaderSaIS1_EE20_M_allocate_and_copyIPS1_EES5_mT_S6_", "ImageLoader** std::vector<ImageLoader*, std::allocator<ImageLoader*>>::_M_allocate_and_copy<ImageLoader**>(unsigned long, ImageLoader**, ImageLoader**)"},
+{"_ZNSt6vectorIP11ImageLoaderSaIS1_EE7reserveEm", "std::vector<ImageLoader*, std::allocator<ImageLoader*>>::reserve(unsigned long)"},
+{"_ZNSt6vectorIP11ImageLoaderSaIS1_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS1_S3_EERKS1_", "std::vector<ImageLoader*, std::allocator<ImageLoader*>>::_M_insert_aux(__gnu_cxx::__normal_iterator<ImageLoader**, std::vector<ImageLoader*, std::allocator<ImageLoader*>>>, ImageLoader* const&)"},
+{"_ZNSt6vectorIP11ImageLoaderSaIS1_EE9push_backERKS1_", "std::vector<ImageLoader*, std::allocator<ImageLoader*>>::push_back(ImageLoader* const&)"},
+{"_ZNSt6vectorIP11ImageLoaderSaIS1_EE5eraseEN9__gnu_cxx17__normal_iteratorIPS1_S3_EE", "std::vector<ImageLoader*, std::allocator<ImageLoader*>>::erase(__gnu_cxx::__normal_iterator<ImageLoader**, std::vector<ImageLoader*, std::allocator<ImageLoader*>>>)"},
+{"_Z18lookupDyldFunctionPKcPm", "lookupDyldFunction(char const*, unsigned long*)"},
+{"_ZNSt12_Vector_baseIP19__NSObjectFileImageSaIS1_EED2Ev", "std::_Vector_base<__NSObjectFileImage*, std::allocator<__NSObjectFileImage*>>::~_Vector_base()"},
+{"_ZNSt6vectorIP19__NSObjectFileImageSaIS1_EED2Ev", "std::vector<__NSObjectFileImage*, std::allocator<__NSObjectFileImage*>>::~vector()"},
+{"_ZNSt15__copy_backwardILb1ESt26random_access_iterator_tagE8__copy_bIP19__NSObjectFileImageEEPT_PKS5_S8_S6_", "__NSObjectFileImage** std::__copy_backward<true, std::random_access_iterator_tag>::__copy_b<__NSObjectFileImage*>(__NSObjectFileImage* const*, __NSObjectFileImage* const*, __NSObjectFileImage**)"},
+{"_ZN9__gnu_cxx13new_allocatorIP19__NSObjectFileImageE8allocateEmPKv", "__gnu_cxx::new_allocator<__NSObjectFileImage*>::allocate(unsigned long, void const*)"},
+{"_ZNSt6vectorIP19__NSObjectFileImageSaIS1_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS1_S3_EERKS1_", "std::vector<__NSObjectFileImage*, std::allocator<__NSObjectFileImage*>>::_M_insert_aux(__gnu_cxx::__normal_iterator<__NSObjectFileImage**, std::vector<__NSObjectFileImage*, std::allocator<__NSObjectFileImage*>>>, __NSObjectFileImage* const&)"},
+{"_ZNSt6vectorIP19__NSObjectFileImageSaIS1_EE9push_backERKS1_", "std::vector<__NSObjectFileImage*, std::allocator<__NSObjectFileImage*>>::push_back(__NSObjectFileImage* const&)"},
+{"_ZNSt6vectorIP19__NSObjectFileImageSaIS1_EE5eraseEN9__gnu_cxx17__normal_iteratorIPS1_S3_EE", "std::vector<__NSObjectFileImage*, std::allocator<__NSObjectFileImage*>>::erase(__gnu_cxx::__normal_iterator<__NSObjectFileImage**, std::vector<__NSObjectFileImage*, std::allocator<__NSObjectFileImage*>>>)"},
+{"_Z19setAlImageInfosHaltPKcm", "setAlImageInfosHalt(char const*, unsigned long)"},
+{"_Z24removeImageFromAllImagesPK11mach_header", "removeImageFromAllImages(mach_header const*)"},
+{"_Z20addImagesToAllImagesjPK15dyld_image_info", "addImagesToAllImages(unsigned int, dyld_image_info const*)"},
+{"_ZNSt6vectorI15dyld_image_infoSaIS0_EE5eraseEN9__gnu_cxx17__normal_iteratorIPS0_S2_EE", "std::vector<dyld_image_info, std::allocator<dyld_image_info>>::erase(__gnu_cxx::__normal_iterator<dyld_image_info*, std::vector<dyld_image_info, std::allocator<dyld_image_info>>>)"},
+{"_ZNSt12_Vector_baseI15dyld_image_infoSaIS0_EED2Ev", "std::_Vector_base<dyld_image_info, std::allocator<dyld_image_info>>::~_Vector_base()"},
+{"_ZNSt6vectorI15dyld_image_infoSaIS0_EED2Ev", "std::vector<dyld_image_info, std::allocator<dyld_image_info>>::~vector()"},
+{"_ZN9__gnu_cxx13new_allocatorI15dyld_image_infoE8allocateEmPKv", "__gnu_cxx::new_allocator<dyld_image_info>::allocate(unsigned long, void const*)"},
+{"_ZNSt6vectorI15dyld_image_infoSaIS0_EE20_M_allocate_and_copyIPS0_EES4_mT_S5_", "dyld_image_info* std::vector<dyld_image_info, std::allocator<dyld_image_info>>::_M_allocate_and_copy<dyld_image_info*>(unsigned long, dyld_image_info*, dyld_image_info*)"},
+{"_ZNSt6vectorI15dyld_image_infoSaIS0_EE7reserveEm", "std::vector<dyld_image_info, std::allocator<dyld_image_info>>::reserve(unsigned long)"},
+{"_ZNSt6vectorI15dyld_image_infoSaIS0_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS0_S2_EERKS0_", "std::vector<dyld_image_info, std::allocator<dyld_image_info>>::_M_insert_aux(__gnu_cxx::__normal_iterator<dyld_image_info*, std::vector<dyld_image_info, std::allocator<dyld_image_info>>>, dyld_image_info const&)"},
+{"_ZNSt6vectorI15dyld_image_infoSaIS0_EE9push_backERKS0_", "std::vector<dyld_image_info, std::allocator<dyld_image_info>>::push_back(dyld_image_info const&)"},
+{"_ZN10__cxxabiv112__unexpectedEPFvvE", "__cxxabiv1::__unexpected(void (*)())"},
+{"_ZN10__cxxabiv111__terminateEPFvvE", "__cxxabiv1::__terminate(void (*)())"},
+{"_ZSt10unexpectedv", "std::unexpected()"},
+{"_ZSt9terminat...
[truncated]

Copy link

github-actions bot commented Apr 29, 2025

✅ With the latest revision this PR passed the undef deprecator.

@Michael137 Michael137 force-pushed the lldb/demangler-correctness-tests branch 2 times, most recently from 04bd72c to fd1526d Compare April 29, 2025 12:02
Copy link

github-actions bot commented Apr 29, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@Michael137 Michael137 force-pushed the lldb/demangler-correctness-tests branch from fd1526d to dcbaa3b Compare April 29, 2025 13:25
@adrian-prantl
Copy link
Collaborator

Do we really want a copy of all those test-cases in LLDB?

Is it also in the monorepo? Can we just use a relative path to the file?

@Michael137
Copy link
Member Author

Do we really want a copy of all those test-cases in LLDB?

Is it also in the monorepo? Can we just use a relative path to the file?

Yup it is in the libcxxabi subdirectory. Is there precendent for such cross-project references ? (i guess header includes would be an example :) ). Happy to do that if that's acceptable

@DavidSpickett
Copy link
Collaborator

i guess header includes would be an example

Headers like ADT and so on are included in installed copies of LLVM but testing files are not.

So would this break testing a standalone LLDB build? Or do we expect "standalone" to mean you configure from lldb/ but you do have the rest of the monorepo there as well.

There are those per-project tar files for each release but I'm not sure what we intend people to do with them.

...but maybe you can sidestep that by saying that libcxx must be available?

@labath
Copy link
Collaborator

labath commented Apr 30, 2025

Including a random file from the libc++ subproject sounds like a bad idea to me. I certainly hope we don't have a precedent for that.

For the way you're using these files (as a gtest unit test), I think it'd be best if the tests were in llvm/include/llvm/Testing/Demangle. That would most likely be a problem for libc++ since they don't want to depend on llvm (even the demangler is copied into the llvm tree instead of being reused somehow). According to this, it might be possible to move the test to llvm and then you could do what I suggest. I don't know what's the amount of wishful thinking in that comment though...

Just a note, that if you do decide to copy the tests, it may be better to just copy the inputs (mangled names) and then compare the "normal" demangled names with the ones you reconstructed. This avoids needing to update two places in case e.g. the demangler produces extra spaces somewhere.

@Michael137
Copy link
Member Author

For the way you're using these files (as a gtest unit test), I think it'd be best if the tests were in llvm/include/llvm/Testing/Demangle.

Let me try proposing moving the test and see what they say. Making changes to the demangler you have to run two sets of test-suites already anyway (check-cxxabi and check-llvm-demangle, and there's other demangling tests sprinkled around llvm). Just having to run one target would be nice.

Just a note, that if you do decide to copy the tests, it may be better to just copy the inputs (mangled names) and then compare the "normal" demangled names with the ones you reconstructed. This avoids needing to update two places in case e.g. the demangler produces extra spaces somewhere.

Good point, will do!

@Michael137
Copy link
Member Author

Proposed moving the tests here: #137947

Michael137 added a commit that referenced this pull request May 30, 2025
…c into LLVM (#137947)

This patch turns the `libcxxabi/test/test_demangle.pass.cpp` into gtest
unit-tests in `llvm/unittests/Demangle`. The main motivation for this is
#137793, where we want to
re-use the test-cases from the ItaniumDemangler to test our OutputBuffer
implementation.

`libcxxabi/test/test_demangle.pass.cpp` now only tests the
`__cxa_demangle` API surface, not the underlying ItaniumDemangle
implementation.
…OutputBuffer

To test the infrastructure added in llvm#131836 in would be nice to confirm that we can reconstruct all kinds of demangled names. The libcxxabi test-suite already has all those test-cases.

This patch copies those test-cases (taken from `libcxxabi/test/test_demangle.pass.cpp`), reconstructs the name like LLDB would when showing backtraces, and confirms that all demangled names can be fully reconstructed.

Two open questions:
1. Do we really want a copy of all those test-cases in LLDB? It's
   unlikely to be kept in sync with the demangler test-suite.
2. Do we want to turn the `GetDemangledBasename`/`GetDemangledScope`/etc. into public APIs (e.g., on `TrackingOutputBuffer`) so that we can use the exact same method of extraction in the tests?
@Michael137 Michael137 force-pushed the lldb/demangler-correctness-tests branch from 09a1110 to 5b23209 Compare May 30, 2025 19:03
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request May 30, 2025
…ile and sync into LLVM (#137947)

This patch turns the `libcxxabi/test/test_demangle.pass.cpp` into gtest
unit-tests in `llvm/unittests/Demangle`. The main motivation for this is
llvm/llvm-project#137793, where we want to
re-use the test-cases from the ItaniumDemangler to test our OutputBuffer
implementation.

`libcxxabi/test/test_demangle.pass.cpp` now only tests the
`__cxa_demangle` API surface, not the underlying ItaniumDemangle
implementation.
@Michael137 Michael137 merged commit f669b9c into llvm:main May 31, 2025
10 checks passed
@Michael137 Michael137 deleted the lldb/demangler-correctness-tests branch May 31, 2025 08:05
@llvm-ci
Copy link
Collaborator

llvm-ci commented May 31, 2025

LLVM Buildbot has detected a new failure on builder lldb-arm-ubuntu running on linaro-lldb-arm-ubuntu while building lldb at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/16847

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: functionalities/breakpoint/breakpoint_on_overload/TestBreakOnOverload.py (310 of 3230)
PASS: lldb-api :: functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py (311 of 3230)
PASS: lldb-api :: functionalities/breakpoint/breakpoint_reset_upon_run/TestBreakpointResetUponRun.py (312 of 3230)
PASS: lldb-api :: functionalities/breakpoint/breakpoint_options/TestBreakpointOptions.py (313 of 3230)
PASS: lldb-api :: functionalities/breakpoint/breakpoint_with_realpath_and_source_map/TestBreakpoint.py (314 of 3230)
PASS: lldb-api :: functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py (315 of 3230)
PASS: lldb-api :: functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py (316 of 3230)
PASS: lldb-api :: functionalities/breakpoint/breakpoint_set_restart/TestBreakpointSetRestart.py (317 of 3230)
UNSUPPORTED: lldb-api :: functionalities/breakpoint/debugbreak/TestDebugBreak.py (318 of 3230)
UNRESOLVED: lldb-api :: commands/gui/spawn-threads/TestGuiSpawnThreads.py (319 of 3230)
******************** TEST 'lldb-api :: commands/gui/spawn-threads/TestGuiSpawnThreads.py' FAILED ********************
Script:
--
/usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --arch armv8l --build-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --cmake-build-type Release /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/commands/gui/spawn-threads -p TestGuiSpawnThreads.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision f669b9c3eca9438d33259aefb8156f977f1df382)
  clang revision f669b9c3eca9438d33259aefb8156f977f1df382
  llvm revision f669b9c3eca9438d33259aefb8156f977f1df382
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
FAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_gui (TestGuiSpawnThreads.TestGuiSpawnThreadsTest)
======================================================================
ERROR: test_gui (TestGuiSpawnThreads.TestGuiSpawnThreadsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/decorators.py", line 148, in wrapper
    return func(*args, **kwargs)
  File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/commands/gui/spawn-threads/TestGuiSpawnThreads.py", line 44, in test_gui
    self.child.expect_exact(f"thread #{i + 2}: tid =")
  File "/usr/local/lib/python3.10/dist-packages/pexpect/spawnbase.py", line 432, in expect_exact
    return exp.expect_loop(timeout)
  File "/usr/local/lib/python3.10/dist-packages/pexpect/expect.py", line 181, in expect_loop
    return self.timeout(e)
  File "/usr/local/lib/python3.10/dist-packages/pexpect/expect.py", line 144, in timeout
    raise exc
pexpect.exceptions.TIMEOUT: Timeout exceeded.
<pexpect.pty_spawn.spawn object at 0xea01b628>
command: /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/lldb
args: ['/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/lldb', '--no-lldbinit', '--no-use-colors', '-O', 'settings clear --all', '-O', 'settings set symbols.enable-external-lookup false', '-O', 'settings set target.inherit-tcc true', '-O', 'settings set target.disable-aslr false', '-O', 'settings set target.detach-on-error false', '-O', 'settings set target.auto-apply-fixits false', '-O', 'settings set plugin.process.gdb-remote.packet-timeout 60', '-O', 'settings set symbols.clang-modules-cache-path "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api"', '-O', 'settings set use-color false', '-O', 'settings set show-statusline false', '--file', '/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/commands/gui/spawn-threads/TestGuiSpawnThreads.test_gui/a.out']
buffer (last 100 chars): b'0000000680ee8\x1b[H'
before (last 100 chars): b'(Init) std::__ioinit\x1b[2B\x1b[5Dstopped\x1b[100;41HThread: 375182\x1b[6CFrame:   0  PC = 0x0000000000680ee8\x1b[H'
after: <class 'pexpect.exceptions.TIMEOUT'>

rupprecht added a commit that referenced this pull request Jun 4, 2025
Test case added by f669b9c / #137793.
Note that the `DemanglingParts` case above also frees the buffer; this
new test case is inconsistent.
rorth pushed a commit to rorth/llvm-project that referenced this pull request Jun 11, 2025
…2676)

Test case added by f669b9c / llvm#137793.
Note that the `DemanglingParts` case above also frees the buffer; this
new test case is inconsistent.
DhruvSrivastavaX pushed a commit to DhruvSrivastavaX/lldb-for-aix that referenced this pull request Jun 12, 2025
…OutputBuffer (llvm#137793)

To test the infrastructure added in
llvm#131836 in would be nice to
confirm that we can reconstruct all kinds of demangled names. The
libcxxabi test-suite already has all those test-cases.

This patch copies those test-cases (taken from
`libcxxabi/test/test_demangle.pass.cpp`), reconstructs the name like
LLDB would when showing backtraces, and confirms that all demangled
names can be fully reconstructed.

Two open questions:
1. Do we really want a copy of all those test-cases in LLDB? It's
unlikely to be kept in sync with the demangler test-suite. It includes
30,000+ test-cases
2. Do we want to turn the
`GetDemangledBasename`/`GetDemangledScope`/etc. into public APIs (e.g.,
on `TrackingOutputBuffer`) so that we can use the exact same method of
extraction in the tests?
DhruvSrivastavaX pushed a commit to DhruvSrivastavaX/lldb-for-aix that referenced this pull request Jun 12, 2025
…2676)

Test case added by f669b9c / llvm#137793.
Note that the `DemanglingParts` case above also frees the buffer; this
new test case is inconsistent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants