[PATCH] D93720: [llvm-pdbutil] Don't crash when printing unknown CodeView type records
Alexandre Ganea via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 7 12:45:22 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGce7f30b2a874: [llvm-pdbutil] Don't crash when printing unknown CodeView type records (authored by aganea).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93720/new/
https://reviews.llvm.org/D93720
Files:
llvm/test/tools/llvm-pdbutil/Inputs/unknown-record.obj
llvm/test/tools/llvm-pdbutil/unknown-records.test
llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
llvm/tools/llvm-pdbutil/FormatUtil.cpp
llvm/tools/llvm-pdbutil/FormatUtil.h
Index: llvm/tools/llvm-pdbutil/FormatUtil.h
===================================================================
--- llvm/tools/llvm-pdbutil/FormatUtil.h
+++ llvm/tools/llvm-pdbutil/FormatUtil.h
@@ -66,7 +66,7 @@
std::string formatChunkKind(codeview::DebugSubsectionKind Kind,
bool Friendly = true);
std::string formatSymbolKind(codeview::SymbolKind K);
-StringRef formatTypeLeafKind(codeview::TypeLeafKind K);
+std::string formatTypeLeafKind(codeview::TypeLeafKind K);
/// Returns the number of digits in the given integer.
inline int NumDigits(uint64_t N) {
Index: llvm/tools/llvm-pdbutil/FormatUtil.cpp
===================================================================
--- llvm/tools/llvm-pdbutil/FormatUtil.cpp
+++ llvm/tools/llvm-pdbutil/FormatUtil.cpp
@@ -156,16 +156,17 @@
return formatUnknownEnum(K);
}
-StringRef llvm::pdb::formatTypeLeafKind(TypeLeafKind K) {
+std::string llvm::pdb::formatTypeLeafKind(TypeLeafKind K) {
switch (K) {
#define TYPE_RECORD(EnumName, value, name) \
case EnumName: \
return #EnumName;
#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
default:
- llvm_unreachable("Unknown type leaf kind!");
+ return formatv("UNKNOWN RECORD ({0:X})",
+ static_cast<std::underlying_type_t<TypeLeafKind>>(K))
+ .str();
}
- return "";
}
std::string llvm::pdb::formatSegmentOffset(uint16_t Segment, uint32_t Offset) {
Index: llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
===================================================================
--- llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
+++ llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
@@ -738,21 +738,17 @@
constexpr uint32_t kNoneUdtKind = 0;
constexpr uint32_t kSimpleUdtKind = 1;
constexpr uint32_t kUnknownUdtKind = 2;
-const StringRef NoneLabel("<none type>");
-const StringRef SimpleLabel("<simple type>");
-const StringRef UnknownLabel("<unknown type>");
-
} // namespace
-static StringRef getUdtStatLabel(uint32_t Kind) {
+static std::string getUdtStatLabel(uint32_t Kind) {
if (Kind == kNoneUdtKind)
- return NoneLabel;
+ return "<none type>";
if (Kind == kSimpleUdtKind)
- return SimpleLabel;
+ return "<simple type>";
if (Kind == kUnknownUdtKind)
- return UnknownLabel;
+ return "<unknown type>";
return formatTypeLeafKind(static_cast<TypeLeafKind>(Kind));
}
@@ -760,7 +756,7 @@
static uint32_t getLongestTypeLeafName(const StatCollection &Stats) {
size_t L = 0;
for (const auto &Stat : Stats.Individual) {
- StringRef Label = getUdtStatLabel(Stat.first);
+ std::string Label = getUdtStatLabel(Stat.first);
L = std::max(L, Label.size());
}
return static_cast<uint32_t>(L);
@@ -869,7 +865,7 @@
P.formatLine("{0}", fmt_repeat('-', TableWidth));
for (const auto &Stat : UdtTargetStats.getStatsSortedBySize()) {
- StringRef Label = getUdtStatLabel(Stat.first);
+ std::string Label = getUdtStatLabel(Stat.first);
P.formatLine("{0} | {1:N} {2:N}",
fmt_align(Label, AlignStyle::Right, FieldWidth),
fmt_align(Stat.second.Count, AlignStyle::Right, CD),
Index: llvm/test/tools/llvm-pdbutil/unknown-records.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-pdbutil/unknown-records.test
@@ -0,0 +1,3 @@
+; REQUIRES: diasdk
+; RUN: llvm-pdbutil dump -all %p/Inputs/unknown-record.obj | FileCheck %s
+; CHECK: UNKNOWN RECORD (0x1609)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93720.315214.patch
Type: text/x-patch
Size: 3580 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210107/8c3f1dbb/attachment.bin>
More information about the llvm-commits
mailing list