<rdar://problem/13590152>

Providing a dummy RegisterContext to secure against faulty Python OS plugins that do not return a valid RegisterContext
The RegisterContextDummy exports a PC with a constant 0xFFFFFFFFFFFFFFFF value

llvm-svn: 180033
This commit is contained in:
Enrico Granata 2013-04-22 18:26:52 +00:00
parent 2ec1b100a4
commit cbd79b6c84
4 changed files with 230 additions and 0 deletions

View File

@ -522,6 +522,8 @@
941BCC8014E48C4000BB969C /* SBTypeFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 9461568714E355F2003A195C /* SBTypeFormat.h */; settings = {ATTRIBUTES = (Public, ); }; };
941BCC8114E48C4000BB969C /* SBTypeSummary.h in Headers */ = {isa = PBXBuildFile; fileRef = 9461568814E355F2003A195C /* SBTypeSummary.h */; settings = {ATTRIBUTES = (Public, ); }; };
941BCC8214E48C4000BB969C /* SBTypeSynthetic.h in Headers */ = {isa = PBXBuildFile; fileRef = 9461568914E355F2003A195C /* SBTypeSynthetic.h */; settings = {ATTRIBUTES = (Public, ); }; };
944372DC171F6B4300E57C32 /* RegisterContextDummy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 944372DA171F6B4300E57C32 /* RegisterContextDummy.cpp */; };
944372DD171F6B4300E57C32 /* RegisterContextDummy.h in Headers */ = {isa = PBXBuildFile; fileRef = 944372DB171F6B4300E57C32 /* RegisterContextDummy.h */; };
9443B122140C18C40013457C /* SBData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9443B121140C18C10013457C /* SBData.cpp */; };
9443B123140C26AB0013457C /* SBData.h in Headers */ = {isa = PBXBuildFile; fileRef = 9443B120140C18A90013457C /* SBData.h */; settings = {ATTRIBUTES = (Public, ); }; };
9452573A16262D0200325455 /* SBDeclaration.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9452573916262D0200325455 /* SBDeclaration.cpp */; };
@ -1557,6 +1559,8 @@
940DB8E116EA674000D3C2F1 /* Xcode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Xcode.cpp; sourceTree = "<group>"; };
940DB8E216EA674000D3C2F1 /* Xcode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Xcode.h; sourceTree = "<group>"; };
940DB8E616EA709400D3C2F1 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
944372DA171F6B4300E57C32 /* RegisterContextDummy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RegisterContextDummy.cpp; path = Utility/RegisterContextDummy.cpp; sourceTree = "<group>"; };
944372DB171F6B4300E57C32 /* RegisterContextDummy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RegisterContextDummy.h; path = Utility/RegisterContextDummy.h; sourceTree = "<group>"; };
9443B120140C18A90013457C /* SBData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SBData.h; path = include/lldb/API/SBData.h; sourceTree = "<group>"; };
9443B121140C18C10013457C /* SBData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBData.cpp; path = source/API/SBData.cpp; sourceTree = "<group>"; };
9452573616262CD000325455 /* SBDeclaration.i */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c.preprocessed; path = SBDeclaration.i; sourceTree = "<group>"; };
@ -2511,6 +2515,8 @@
26957D9513D381C900670048 /* RegisterContextDarwin_i386.h */,
26957D9613D381C900670048 /* RegisterContextDarwin_x86_64.cpp */,
26957D9713D381C900670048 /* RegisterContextDarwin_x86_64.h */,
944372DA171F6B4300E57C32 /* RegisterContextDummy.cpp */,
944372DB171F6B4300E57C32 /* RegisterContextDummy.h */,
AF68D2541255416E002FF25B /* RegisterContextLLDB.cpp */,
AF68D2551255416E002FF25B /* RegisterContextLLDB.h */,
262D24E413FB8710002D1960 /* RegisterContextMemory.cpp */,
@ -3599,6 +3605,7 @@
260D9B2715EC369500960137 /* ModuleSpec.h in Headers */,
947A1D651616476B0017C8D1 /* CommandObjectPlugin.h in Headers */,
262ED0051631FA2800879631 /* OptionGroupString.h in Headers */,
944372DD171F6B4300E57C32 /* RegisterContextDummy.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -4146,6 +4153,7 @@
268900CB13353E5F00698AC0 /* LogChannelDWARF.cpp in Sources */,
268900CC13353E5F00698AC0 /* SymbolFileDWARFDebugMap.cpp in Sources */,
268900CD13353E5F00698AC0 /* UniqueDWARFASTType.cpp in Sources */,
944372DC171F6B4300E57C32 /* RegisterContextDummy.cpp in Sources */,
268900CE13353E5F00698AC0 /* SymbolFileSymtab.cpp in Sources */,
268900CF13353E5F00698AC0 /* SymbolVendorMacOSX.cpp in Sources */,
268900D013353E6F00698AC0 /* Block.cpp in Sources */,

View File

@ -33,6 +33,7 @@
#include "lldb/Target/ThreadList.h"
#include "lldb/Target/Thread.h"
#include "Plugins/Process/Utility/DynamicRegisterInfo.h"
#include "Plugins/Process/Utility/RegisterContextDummy.h"
#include "Plugins/Process/Utility/RegisterContextMemory.h"
#include "Plugins/Process/Utility/ThreadMemory.h"
@ -333,6 +334,13 @@ OperatingSystemPython::CreateRegisterContextForThread (Thread *thread, addr_t re
}
}
}
// if we still have no register data, fallback on a dummy context to avoid crashing
if (!reg_ctx_sp)
{
if (log)
log->Printf ("OperatingSystemPython::CreateRegisterContextForThread (tid = 0x%" PRIx64 ") forcing a dummy register context", thread->GetID());
reg_ctx_sp.reset(new RegisterContextDummy(*thread,0,target.GetArchitecture().GetAddressByteSize()));
}
return reg_ctx_sp;
}

View File

@ -0,0 +1,137 @@
//===-- RegisterContextDummy.cpp ---------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/lldb-private.h"
#include "lldb/Core/Address.h"
#include "lldb/Core/AddressRange.h"
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Value.h"
#include "lldb/Expression/DWARFExpression.h"
#include "lldb/Symbol/FuncUnwinders.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Target/ABI.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/DynamicLoader.h"
#include "RegisterContextDummy.h"
using namespace lldb;
using namespace lldb_private;
RegisterContextDummy::RegisterContextDummy (Thread &thread, uint32_t concrete_frame_idx, uint32_t address_byte_size) :
RegisterContext (thread, concrete_frame_idx)
{
m_reg_set0.name = "General Purpose Registers";
m_reg_set0.short_name = "GPR";
m_reg_set0.num_registers = 1;
m_reg_set0.registers = new uint32_t(0);
m_pc_reg_info.name = "pc";
m_pc_reg_info.alt_name = "pc";
m_pc_reg_info.byte_offset = 0;
m_pc_reg_info.byte_size = address_byte_size;
m_pc_reg_info.encoding = eEncodingUint;
m_pc_reg_info.format = eFormatPointer;
m_pc_reg_info.invalidate_regs = NULL;
m_pc_reg_info.value_regs = NULL;
m_pc_reg_info.kinds[eRegisterKindGCC] = LLDB_INVALID_REGNUM;
m_pc_reg_info.kinds[eRegisterKindDWARF] = LLDB_INVALID_REGNUM;
m_pc_reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_PC;
m_pc_reg_info.kinds[eRegisterKindGDB] = LLDB_INVALID_REGNUM;
m_pc_reg_info.kinds[eRegisterKindLLDB] = LLDB_INVALID_REGNUM;
}
RegisterContextDummy::~RegisterContextDummy ()
{
delete m_reg_set0.registers;
delete m_pc_reg_info.invalidate_regs;
delete m_pc_reg_info.value_regs;
}
void
RegisterContextDummy::InvalidateAllRegisters () {}
size_t
RegisterContextDummy::GetRegisterCount ()
{
return 1;
}
const lldb_private::RegisterInfo *
RegisterContextDummy::GetRegisterInfoAtIndex (size_t reg)
{
if (reg)
return NULL;
return &m_pc_reg_info;
}
size_t
RegisterContextDummy::GetRegisterSetCount ()
{
return 1;
}
const lldb_private::RegisterSet *
RegisterContextDummy::GetRegisterSet (size_t reg_set)
{
if (reg_set)
return NULL;
return &m_reg_set0;
}
bool
RegisterContextDummy::ReadRegister (const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value)
{
if (!reg_info)
return false;
uint32_t reg_number = reg_info->kinds[eRegisterKindGeneric];
if (reg_number == LLDB_REGNUM_GENERIC_PC)
{
value.SetUInt(LLDB_INVALID_ADDRESS, reg_info->byte_size);
return true;
}
return false;
}
bool
RegisterContextDummy::WriteRegister (const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value)
{
return false;
}
bool
RegisterContextDummy::ReadAllRegisterValues (lldb::DataBufferSP &data_sp)
{
return false;
}
bool
RegisterContextDummy::WriteAllRegisterValues (const lldb::DataBufferSP &data_sp)
{
return false;
}
uint32_t
RegisterContextDummy::ConvertRegisterKindToRegisterNumber (uint32_t kind, uint32_t num)
{
if (kind == eRegisterKindGeneric && num == LLDB_REGNUM_GENERIC_PC)
return 0;
return LLDB_INVALID_REGNUM;
}

View File

@ -0,0 +1,77 @@
//===-- RegisterContextDummy.h ----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef lldb_RegisterContextDummy_h_
#define lldb_RegisterContextDummy_h_
#include <vector>
#include "lldb/lldb-private.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Symbol/SymbolContext.h"
namespace lldb_private {
class RegisterContextDummy : public lldb_private::RegisterContext
{
public:
typedef std::shared_ptr<RegisterContextDummy> SharedPtr;
RegisterContextDummy (Thread &thread, uint32_t concrete_frame_idx, uint32_t address_byte_size);
///
// pure virtual functions from the base class that we must implement
///
virtual
~RegisterContextDummy ();
virtual void
InvalidateAllRegisters ();
virtual size_t
GetRegisterCount ();
virtual const lldb_private::RegisterInfo *
GetRegisterInfoAtIndex (size_t reg);
virtual size_t
GetRegisterSetCount ();
virtual const lldb_private::RegisterSet *
GetRegisterSet (size_t reg_set);
virtual bool
ReadRegister (const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value);
virtual bool
WriteRegister (const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value);
virtual bool
ReadAllRegisterValues (lldb::DataBufferSP &data_sp);
virtual bool
WriteAllRegisterValues (const lldb::DataBufferSP &data_sp);
virtual uint32_t
ConvertRegisterKindToRegisterNumber (uint32_t kind, uint32_t num);
private:
//------------------------------------------------------------------
// For RegisterContextLLDB only
//------------------------------------------------------------------
lldb_private::RegisterSet m_reg_set0; // register set 0 (PC only)
lldb_private::RegisterInfo m_pc_reg_info;
DISALLOW_COPY_AND_ASSIGN (RegisterContextDummy);
};
} // namespace lldb_private
#endif // lldb_RegisterContextDummy_h_