[llvm] r326924 - Teach identify_file_magic to identify PDB files.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 7 10:40:41 PST 2018
Author: zturner
Date: Wed Mar 7 10:40:41 2018
New Revision: 326924
URL: http://llvm.org/viewvc/llvm-project?rev=326924&view=rev
Log:
Teach identify_file_magic to identify PDB files.
Modified:
llvm/trunk/include/llvm/BinaryFormat/Magic.h
llvm/trunk/lib/BinaryFormat/Magic.cpp
llvm/trunk/unittests/BinaryFormat/TestFileMagic.cpp
Modified: llvm/trunk/include/llvm/BinaryFormat/Magic.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BinaryFormat/Magic.h?rev=326924&r1=326923&r2=326924&view=diff
==============================================================================
--- llvm/trunk/include/llvm/BinaryFormat/Magic.h (original)
+++ llvm/trunk/include/llvm/BinaryFormat/Magic.h Wed Mar 7 10:40:41 2018
@@ -45,7 +45,8 @@ struct file_magic {
coff_import_library, ///< COFF import library
pecoff_executable, ///< PECOFF executable file
windows_resource, ///< Windows compiled resource file (.res)
- wasm_object ///< WebAssembly Object file
+ wasm_object, ///< WebAssembly Object file
+ pdb, ///< Windows PDB debug info file
};
bool is_object() const { return V != unknown; }
Modified: llvm/trunk/lib/BinaryFormat/Magic.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/BinaryFormat/Magic.cpp?rev=326924&r1=326923&r2=326924&view=diff
==============================================================================
--- llvm/trunk/lib/BinaryFormat/Magic.cpp (original)
+++ llvm/trunk/lib/BinaryFormat/Magic.cpp Wed Mar 7 10:40:41 2018
@@ -181,7 +181,7 @@ file_magic llvm::identify_magic(StringRe
return file_magic::coff_object;
break;
- case 'M': // Possible MS-DOS stub on Windows PE file
+ case 'M': // Possible MS-DOS stub on Windows PE file or MSF/PDB file.
if (startswith(Magic, "MZ") && Magic.size() >= 0x3c + 4) {
uint32_t off = read32le(Magic.data() + 0x3c);
// PE/COFF file, either EXE or DLL.
@@ -189,6 +189,8 @@ file_magic llvm::identify_magic(StringRe
StringRef(COFF::PEMagic, sizeof(COFF::PEMagic))))
return file_magic::pecoff_executable;
}
+ if (Magic.startswith("Microsoft C/C++ MSF 7.00\r\n"))
+ return file_magic::pdb;
break;
case 0x64: // x86-64 or ARM64 Windows.
Modified: llvm/trunk/unittests/BinaryFormat/TestFileMagic.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/BinaryFormat/TestFileMagic.cpp?rev=326924&r1=326923&r2=326924&view=diff
==============================================================================
--- llvm/trunk/unittests/BinaryFormat/TestFileMagic.cpp (original)
+++ llvm/trunk/unittests/BinaryFormat/TestFileMagic.cpp Wed Mar 7 10:40:41 2018
@@ -81,6 +81,8 @@ const char windows_resource[] =
const char macho_dynamically_linked_shared_lib_stub[] =
"\xfe\xed\xfa\xce........\x00\x00\x00\x09............";
const char ms_dos_stub_broken[] = "\x4d\x5a\x20\x20";
+const char pdb[] = "Microsoft C/C++ MSF 7.00\r\n\x1a"
+ "DS\x00\x00\x00";
TEST_F(MagicTest, Magic) {
struct type {
@@ -110,6 +112,7 @@ TEST_F(MagicTest, Magic) {
DEFINE(macho_dsym_companion),
DEFINE(macho_kext_bundle),
DEFINE(windows_resource),
+ DEFINE(pdb),
{"ms_dos_stub_broken", ms_dos_stub_broken, sizeof(ms_dos_stub_broken),
file_magic::unknown},
#undef DEFINE
More information about the llvm-commits
mailing list