[lldb] Test parsing the symtab with indirect symbols from the shared cache
authorJonas Devlieghere <jonas@devlieghere.com>
Thu, 24 Mar 2022 04:00:57 +0000 (21:00 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Thu, 24 Mar 2022 04:13:55 +0000 (21:13 -0700)
This patch adds a test for b0dc2fae6025. That commit fixed a bug where
we could increment the indirect symbol offset every time we parsed the
symbol table.

lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp

index 119be38..0ef2d0b 100644 (file)
@@ -76,4 +76,22 @@ TEST_F(ObjectFileMachOTest, ModuleFromSharedCacheInfo) {
   // ... and one from the __DATA segment
   check_symbol("OBJC_CLASS_$_NSObject");
 }
+
+TEST_F(ObjectFileMachOTest, IndirectSymbolsInTheSharedCache) {
+  SharedCacheImageInfo image_info = HostInfo::GetSharedCacheImageInfo(
+      "/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit");
+  ModuleSpec spec(FileSpec(), UUID(), image_info.data_sp);
+  lldb::ModuleSP module = std::make_shared<Module>(spec);
+
+  ObjectFile *OF = module->GetObjectFile();
+  ASSERT_TRUE(llvm::isa<ObjectFileMachO>(OF));
+  EXPECT_TRUE(
+      OF->GetArchitecture().IsCompatibleMatch(HostInfo::GetArchitecture()));
+
+  // Check that we can parse the symbol table several times over without
+  // crashing.
+  Symtab symtab(OF);
+  for (size_t i = 0; i < 10; i++)
+    OF->ParseSymtab(symtab);
+}
 #endif