[DWARF] Don't assume optional always has a value.
authorJonas Devlieghere <jonas@devlieghere.com>
Fri, 3 Jan 2020 17:30:20 +0000 (09:30 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Fri, 3 Jan 2020 17:53:44 +0000 (09:53 -0800)
When getting the file name form the line table prologue we assume that a
valid string form value can always be extracted as a string. If you look
at the implementation of DWARFormValue this is not necessarily true. I
hit this assertion from LLDB when I create a "dummy" DWARFContext that
was missing the string section.

llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp

index 5c86858..51535e8 100644 (file)
@@ -1026,7 +1026,10 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(
   if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
     return false;
   const FileNameEntry &Entry = getFileNameEntry(FileIndex);
-  StringRef FileName = Entry.Name.getAsCString().getValue();
+  Optional<const char *> Name = Entry.Name.getAsCString();
+  if (!Name)
+    return false;
+  StringRef FileName = *Name;
   if (Kind != FileLineInfoKind::AbsoluteFilePath ||
       isPathAbsoluteOnWindowsOrPosix(FileName)) {
     Result = FileName;