[Lldb-commits] [PATCH] D145115: [LLDB][NativePDB] Check string table in PDB files.

Zequan Wu via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 1 13:44:13 PST 2023


zequanwu created this revision.
zequanwu added a reviewer: labath.
Herald added a subscriber: arphaman.
Herald added a project: All.
zequanwu requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145115

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


Index: lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -1341,6 +1341,9 @@
 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
Index: lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
@@ -703,8 +703,12 @@
   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: lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
@@ -162,9 +162,13 @@
   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`


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145115.501656.patch
Type: text/x-patch
Size: 2466 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230301/cdc24214/attachment.bin>


More information about the lldb-commits mailing list