llvm-dwarfdump: Make the "is debug info section" heuristic stricter so it doesn't accidentaly picks up the wrong section.
Also add some validation code to the aranges section parser.
Fixes PR10926.
llvm-svn: 139701
diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
index 076dcd1..ef9a47b 100644
--- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
+++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
@@ -62,13 +62,17 @@
i->getName(name);
StringRef data;
i->getContents(data);
- if (name.endswith("debug_info"))
+
+ if (name.startswith("__DWARF,"))
+ name = name.substr(8); // Skip "__DWARF," prefix.
+ name = name.substr(name.find_first_not_of("._")); // Skip . and _ prefixes.
+ if (name == "debug_info")
DebugInfoSection = data;
- else if (name.endswith("debug_abbrev"))
+ else if (name == "debug_abbrev")
DebugAbbrevSection = data;
- else if (name.endswith("debug_line"))
+ else if (name == "debug_line")
DebugLineSection = data;
- else if (name.endswith("debug_aranges"))
+ else if (name == "debug_aranges")
DebugArangesSection = data;
}