Skip to content

Commit d860fa6

Browse files
author
Zachary Turner
committed
Teach identify_file_magic to identify PDB files.
llvm-svn: 326924
1 parent f8c2dce commit d860fa6

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

llvm/include/llvm/BinaryFormat/Magic.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ struct file_magic {
4545
coff_import_library, ///< COFF import library
4646
pecoff_executable, ///< PECOFF executable file
4747
windows_resource, ///< Windows compiled resource file (.res)
48-
wasm_object ///< WebAssembly Object file
48+
wasm_object, ///< WebAssembly Object file
49+
pdb, ///< Windows PDB debug info file
4950
};
5051

5152
bool is_object() const { return V != unknown; }

llvm/lib/BinaryFormat/Magic.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,16 @@ file_magic llvm::identify_magic(StringRef Magic) {
181181
return file_magic::coff_object;
182182
break;
183183

184-
case 'M': // Possible MS-DOS stub on Windows PE file
184+
case 'M': // Possible MS-DOS stub on Windows PE file or MSF/PDB file.
185185
if (startswith(Magic, "MZ") && Magic.size() >= 0x3c + 4) {
186186
uint32_t off = read32le(Magic.data() + 0x3c);
187187
// PE/COFF file, either EXE or DLL.
188188
if (Magic.substr(off).startswith(
189189
StringRef(COFF::PEMagic, sizeof(COFF::PEMagic))))
190190
return file_magic::pecoff_executable;
191191
}
192+
if (Magic.startswith("Microsoft C/C++ MSF 7.00\r\n"))
193+
return file_magic::pdb;
192194
break;
193195

194196
case 0x64: // x86-64 or ARM64 Windows.

llvm/unittests/BinaryFormat/TestFileMagic.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ const char windows_resource[] =
8181
const char macho_dynamically_linked_shared_lib_stub[] =
8282
"\xfe\xed\xfa\xce........\x00\x00\x00\x09............";
8383
const char ms_dos_stub_broken[] = "\x4d\x5a\x20\x20";
84+
const char pdb[] = "Microsoft C/C++ MSF 7.00\r\n\x1a"
85+
"DS\x00\x00\x00";
8486

8587
TEST_F(MagicTest, Magic) {
8688
struct type {
@@ -110,6 +112,7 @@ TEST_F(MagicTest, Magic) {
110112
DEFINE(macho_dsym_companion),
111113
DEFINE(macho_kext_bundle),
112114
DEFINE(windows_resource),
115+
DEFINE(pdb),
113116
{"ms_dos_stub_broken", ms_dos_stub_broken, sizeof(ms_dos_stub_broken),
114117
file_magic::unknown},
115118
#undef DEFINE

0 commit comments

Comments
 (0)