forked from OSchip/llvm-project
Cleaned up code that was getting SBData for an SBInstruction.
llvm-svn: 154535
This commit is contained in:
parent
aaf4d69ac1
commit
d1411e1aa2
|
@ -204,6 +204,9 @@ namespace lldb_private {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
GetData (DataExtractor &data) const;
|
||||
|
||||
|
||||
protected:
|
||||
|
|
|
@ -139,19 +139,9 @@ SBInstruction::GetData (SBTarget target)
|
|||
lldb::SBData sb_data;
|
||||
if (m_opaque_sp)
|
||||
{
|
||||
const Opcode &opcode = m_opaque_sp->GetOpcode();
|
||||
const void *opcode_data = opcode.GetOpcodeBytes();
|
||||
const uint32_t opcode_data_size = opcode.GetByteSize();
|
||||
if (opcode_data && opcode_data_size > 0)
|
||||
DataExtractorSP data_extractor_sp (new DataExtractor());
|
||||
if (m_opaque_sp->GetOpcode().GetData (*data_extractor_sp))
|
||||
{
|
||||
ByteOrder data_byte_order = opcode.GetDataByteOrder();
|
||||
TargetSP target_sp (target.GetSP());
|
||||
if (data_byte_order == eByteOrderInvalid && target_sp)
|
||||
data_byte_order = target_sp->GetArchitecture().GetByteOrder();
|
||||
DataBufferSP data_buffer_sp (new DataBufferHeap (opcode_data, opcode_data_size));
|
||||
DataExtractorSP data_extractor_sp (new DataExtractor (data_buffer_sp,
|
||||
data_byte_order,
|
||||
target_sp ? target_sp->GetArchitecture().GetAddressByteSize() : sizeof(void*)));
|
||||
sb_data.SetOpaque (data_extractor_sp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
// C++ Includes
|
||||
// Other libraries and framework includes
|
||||
// Project includes
|
||||
#include "lldb/Core/DataBufferHeap.h"
|
||||
#include "lldb/Core/DataExtractor.h"
|
||||
#include "lldb/Core/Stream.h"
|
||||
#include "lldb/Host/Endian.h"
|
||||
|
||||
|
@ -79,3 +81,36 @@ Opcode::GetDataByteOrder () const
|
|||
return eByteOrderInvalid;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Opcode::GetData (DataExtractor &data) const
|
||||
{
|
||||
uint32_t byte_size = GetByteSize ();
|
||||
DataBufferSP buffer_sp;
|
||||
if (byte_size > 0)
|
||||
{
|
||||
switch (m_type)
|
||||
{
|
||||
case Opcode::eTypeInvalid:
|
||||
break;
|
||||
|
||||
case Opcode::eType8: buffer_sp.reset (new DataBufferHeap (&m_data.inst8, byte_size)); break;
|
||||
case Opcode::eType16: buffer_sp.reset (new DataBufferHeap (&m_data.inst16, byte_size)); break;
|
||||
case Opcode::eType32: buffer_sp.reset (new DataBufferHeap (&m_data.inst32, byte_size)); break;
|
||||
case Opcode::eType64: buffer_sp.reset (new DataBufferHeap (&m_data.inst64, byte_size)); break;
|
||||
case Opcode::eTypeBytes:buffer_sp.reset (new DataBufferHeap (GetOpcodeBytes(), byte_size)); break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer_sp)
|
||||
{
|
||||
data.SetByteOrder(GetDataByteOrder());
|
||||
data.SetData (buffer_sp);
|
||||
return byte_size;
|
||||
}
|
||||
data.Clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -207,49 +207,64 @@ protected:
|
|||
uint32_t offset,
|
||||
size_t inst_size)
|
||||
{
|
||||
llvm::Triple::ArchType arch = m_disasm.GetArchitecture().GetMachine();
|
||||
const ArchSpec &arch = m_disasm.GetArchitecture();
|
||||
llvm::Triple::ArchType machine = arch.GetMachine();
|
||||
|
||||
switch (arch)
|
||||
switch (machine)
|
||||
{
|
||||
default:
|
||||
case llvm::Triple::x86:
|
||||
case llvm::Triple::x86_64:
|
||||
m_opcode.SetOpcodeBytes(extractor.PeekData(offset, inst_size), inst_size);
|
||||
break;
|
||||
return;
|
||||
|
||||
case llvm::Triple::arm:
|
||||
case llvm::Triple::thumb:
|
||||
switch (inst_size)
|
||||
{
|
||||
case 2:
|
||||
{
|
||||
m_opcode.SetOpcode16 (extractor.GetU16 (&offset));
|
||||
break;
|
||||
}
|
||||
m_opcode.SetOpcode16 (extractor.GetU16 (&offset));
|
||||
break;
|
||||
case 4:
|
||||
if (machine == llvm::Triple::arm && m_address_class == eAddressClassCodeAlternateISA)
|
||||
{
|
||||
if (arch == llvm::Triple::arm &&
|
||||
m_address_class == eAddressClassCodeAlternateISA)
|
||||
{
|
||||
// If it is a 32-bit THUMB instruction, we need to swap the upper & lower halves.
|
||||
uint32_t orig_bytes = extractor.GetU32 (&offset);
|
||||
uint16_t upper_bits = (orig_bytes >> 16) & ((1u << 16) - 1);
|
||||
uint16_t lower_bits = orig_bytes & ((1u << 16) - 1);
|
||||
uint32_t swapped = (lower_bits << 16) | upper_bits;
|
||||
m_opcode.SetOpcode32 (swapped);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_opcode.SetOpcode32 (extractor.GetU32 (&offset));
|
||||
}
|
||||
// If it is a 32-bit THUMB instruction, we need to swap the upper & lower halves.
|
||||
uint32_t orig_bytes = extractor.GetU32 (&offset);
|
||||
uint16_t upper_bits = (orig_bytes >> 16) & ((1u << 16) - 1);
|
||||
uint16_t lower_bits = orig_bytes & ((1u << 16) - 1);
|
||||
uint32_t swapped = (lower_bits << 16) | upper_bits;
|
||||
m_opcode.SetOpcode32 (swapped);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_opcode.SetOpcode32 (extractor.GetU32 (&offset));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert (!"Invalid ARM opcode size");
|
||||
break;
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Handle the default cases here.
|
||||
const uint32_t min_op_byte_size = arch.GetMinimumOpcodeByteSize();
|
||||
const uint32_t max_op_byte_size = arch.GetMaximumOpcodeByteSize();
|
||||
if (min_op_byte_size == max_op_byte_size)
|
||||
{
|
||||
assert (inst_size == min_op_byte_size);
|
||||
switch (inst_size)
|
||||
{
|
||||
case 1: m_opcode.SetOpcode8 (extractor.GetU8 (&offset)); return;
|
||||
case 2: m_opcode.SetOpcode16 (extractor.GetU16 (&offset)); return;
|
||||
case 4: m_opcode.SetOpcode32 (extractor.GetU32 (&offset)); return;
|
||||
case 8: m_opcode.SetOpcode64 (extractor.GetU64 (&offset)); return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_opcode.SetOpcodeBytes(extractor.PeekData(offset, inst_size), inst_size);
|
||||
}
|
||||
|
||||
bool StringRepresentsBranch (const char *data, size_t size)
|
||||
|
|
Loading…
Reference in New Issue