[LLDB][NativePDB] Check string table in PDB files.
authorZequan Wu <zequanwu@google.com>
Wed, 1 Mar 2023 21:28:35 +0000 (16:28 -0500)
committerZequan Wu <zequanwu@google.com>
Mon, 6 Mar 2023 15:25:38 +0000 (10:25 -0500)
Usually PDB files have a string table (aka: Named Stream "/names" ). PDB for
some windows system libraries might not have that. This adds the check for it to
avoid crash in the absence of string table.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D145115

lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp

index e2e06491e8c17b86e2daec1ae546c2ac66bac89c..06cb720b1e9f7fbac8cf9989650c13c6e03f21b2 100644 (file)
@@ -162,9 +162,13 @@ CompilandIndexItem &CompileUnitIndex::GetOrCreateCompiland(uint16_t modi) {
   ParseExtendedInfo(m_index, *cci);
   ParseInlineeLineTableForCompileUnit(*cci);
 
-  cci->m_strings.initialize(cci->m_debug_stream.getSubsectionsArray());
-  PDBStringTable &strings = cantFail(m_index.pdb().getStringTable());
-  cci->m_strings.setStrings(strings.getStringTable());
+  auto strings = m_index.pdb().getStringTable();
+  if (strings) {
+    cci->m_strings.initialize(cci->m_debug_stream.getSubsectionsArray());
+    cci->m_strings.setStrings(strings->getStringTable());
+  } else {
+    consumeError(strings.takeError());
+  }
 
   // We want the main source file to always comes first.  Note that we can't
   // just push_back the main file onto the front because `GetMainSourceFile`
index 164bfa8b3726aced96af3e9f2ad83dc0c95bf463..888bd89a72625990256b1e20de7e2b8e2d19909d 100644 (file)
@@ -703,8 +703,12 @@ static bool GetFrameDataProgram(PdbIndex &index,
   if (frame_data_it == new_fpo_data.end())
     return false;
 
-  PDBStringTable &strings = cantFail(index.pdb().getStringTable());
-  out_program = cantFail(strings.getStringForID(frame_data_it->FrameFunc));
+  auto strings = index.pdb().getStringTable();
+  if (!strings) {
+    consumeError(strings.takeError());
+    return false;
+  }
+  out_program = cantFail(strings->getStringForID(frame_data_it->FrameFunc));
   return true;
 }
 
index 82d3707acfa4bb6f5fce6911bba12b8ff5c6448a..b99e9ec82f12698f8f92b23b18e90f3258dde3f3 100644 (file)
@@ -1341,6 +1341,9 @@ bool SymbolFileNativePDB::ParseDebugMacros(CompileUnit &comp_unit) {
 llvm::Expected<uint32_t>
 SymbolFileNativePDB::GetFileIndex(const CompilandIndexItem &cii,
                                   uint32_t file_id) {
+  if (!cii.m_strings.hasChecksums() || !cii.m_strings.hasStrings())
+    return llvm::make_error<RawError>(raw_error_code::no_entry);
+
   const auto &checksums = cii.m_strings.checksums().getArray();
   const auto &strings = cii.m_strings.strings();
   // Indices in this structure are actually offsets of records in the