Verify we have a correct ELF or Mach core file before we return a valid instace of ProcessElfCore or ProcessMachCore respectively.

llvm-svn: 203274
This commit is contained in:
Greg Clayton 2014-03-07 19:24:39 +00:00
parent 05f44b4d1c
commit 9cbd3c628c
3 changed files with 41 additions and 6 deletions

View File

@ -162,14 +162,13 @@ public:
virtual uint32_t
GetSDKVersion (uint32_t *versions, uint32_t num_versions);
protected:
static bool
ParseHeader (lldb_private::DataExtractor &data,
lldb::offset_t *data_offset_ptr,
llvm::MachO::mach_header &header);
protected:
static bool
GetUUID (const llvm::MachO::mach_header &header,

View File

@ -19,6 +19,9 @@
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/DynamicLoader.h"
#include "llvm/Support/ELF.h"
#include "ProcessPOSIXLog.h"
#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
@ -54,8 +57,24 @@ lldb::ProcessSP
ProcessElfCore::CreateInstance (Target &target, Listener &listener, const FileSpec *crash_file)
{
lldb::ProcessSP process_sp;
if (crash_file)
process_sp.reset(new ProcessElfCore (target, listener, *crash_file));
if (crash_file)
{
// Read enough data for a ELF32 header or ELF64 header
const size_t header_size = sizeof(llvm::ELF::Elf64_Ehdr);
lldb::DataBufferSP data_sp (crash_file->ReadFileContents(0, header_size));
if (data_sp->GetByteSize() == header_size)
{
elf::ELFHeader elf_header;
DataExtractor data(data_sp, lldb::eByteOrderLittle, 4);
lldb::offset_t data_offset = 0;
if (elf_header.Parse(data, &data_offset))
{
if (elf_header.e_type == llvm::ELF::ET_CORE)
process_sp.reset(new ProcessElfCore (target, listener, *crash_file));
}
}
}
return process_sp;
}

View File

@ -35,6 +35,7 @@
// Needed for the plug-in names for the dynamic loaders.
#include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
#include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
using namespace lldb;
using namespace lldb_private;
@ -64,7 +65,23 @@ ProcessMachCore::CreateInstance (Target &target, Listener &listener, const FileS
{
lldb::ProcessSP process_sp;
if (crash_file)
process_sp.reset(new ProcessMachCore (target, listener, *crash_file));
{
const size_t header_size = sizeof(llvm::MachO::mach_header);
lldb::DataBufferSP data_sp (crash_file->ReadFileContents(0, header_size));
if (data_sp->GetByteSize() == header_size)
{
DataExtractor data(data_sp, lldb::eByteOrderLittle, 4);
lldb::offset_t data_offset = 0;
llvm::MachO::mach_header mach_header;
if (ObjectFileMachO::ParseHeader(data, &data_offset, mach_header))
{
if (mach_header.filetype == llvm::MachO::MH_CORE)
process_sp.reset(new ProcessMachCore (target, listener, *crash_file));
}
}
}
return process_sp;
}