Remove manual byte counting from Opcode::Dump
Summary: Stream now has byte-counting functionality, so let's use this instead of manual byte counting. Reviewers: clayborg, davide Reviewed By: davide Subscribers: davide, lldb-commits Differential Revision: https://reviews.llvm.org/D50677 llvm-svn: 340179
This commit is contained in:
parent
7515e75bc2
commit
5b06c228af
|
@ -23,40 +23,41 @@ using namespace lldb;
|
||||||
using namespace lldb_private;
|
using namespace lldb_private;
|
||||||
|
|
||||||
int Opcode::Dump(Stream *s, uint32_t min_byte_width) {
|
int Opcode::Dump(Stream *s, uint32_t min_byte_width) {
|
||||||
int bytes_written = 0;
|
const uint32_t previous_bytes = s->GetWrittenBytes();
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case Opcode::eTypeInvalid:
|
case Opcode::eTypeInvalid:
|
||||||
bytes_written = s->PutCString("<invalid>");
|
s->PutCString("<invalid>");
|
||||||
break;
|
break;
|
||||||
case Opcode::eType8:
|
case Opcode::eType8:
|
||||||
bytes_written = s->Printf("0x%2.2x", m_data.inst8);
|
s->Printf("0x%2.2x", m_data.inst8);
|
||||||
break;
|
break;
|
||||||
case Opcode::eType16:
|
case Opcode::eType16:
|
||||||
bytes_written = s->Printf("0x%4.4x", m_data.inst16);
|
s->Printf("0x%4.4x", m_data.inst16);
|
||||||
break;
|
break;
|
||||||
case Opcode::eType16_2:
|
case Opcode::eType16_2:
|
||||||
case Opcode::eType32:
|
case Opcode::eType32:
|
||||||
bytes_written = s->Printf("0x%8.8x", m_data.inst32);
|
s->Printf("0x%8.8x", m_data.inst32);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Opcode::eType64:
|
case Opcode::eType64:
|
||||||
bytes_written = s->Printf("0x%16.16" PRIx64, m_data.inst64);
|
s->Printf("0x%16.16" PRIx64, m_data.inst64);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Opcode::eTypeBytes:
|
case Opcode::eTypeBytes:
|
||||||
for (uint32_t i = 0; i < m_data.inst.length; ++i) {
|
for (uint32_t i = 0; i < m_data.inst.length; ++i) {
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
bytes_written += s->PutChar(' ');
|
s->PutChar(' ');
|
||||||
bytes_written += s->Printf("%2.2x", m_data.inst.bytes[i]);
|
s->Printf("%2.2x", m_data.inst.bytes[i]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add spaces to make sure bytes dispay comes out even in case opcodes aren't
|
uint32_t bytes_written_so_far = s->GetWrittenBytes() - previous_bytes;
|
||||||
// all the same size
|
// Add spaces to make sure bytes display comes out even in case opcodes aren't
|
||||||
if (static_cast<uint32_t>(bytes_written) < min_byte_width)
|
// all the same size.
|
||||||
bytes_written = s->Printf("%*s", min_byte_width - bytes_written, "");
|
if (bytes_written_so_far < min_byte_width)
|
||||||
return bytes_written;
|
s->Printf("%*s", min_byte_width - bytes_written_so_far, "");
|
||||||
|
return s->GetWrittenBytes() - previous_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
lldb::ByteOrder Opcode::GetDataByteOrder() const {
|
lldb::ByteOrder Opcode::GetDataByteOrder() const {
|
||||||
|
|
Loading…
Reference in New Issue