Skip to content

Commit 5b06c22

Browse files
committedAug 20, 2018
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
1 parent 7515e75 commit 5b06c22

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed
 

‎lldb/source/Core/Opcode.cpp

+14-13
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,41 @@ using namespace lldb;
2323
using namespace lldb_private;
2424

2525
int Opcode::Dump(Stream *s, uint32_t min_byte_width) {
26-
int bytes_written = 0;
26+
const uint32_t previous_bytes = s->GetWrittenBytes();
2727
switch (m_type) {
2828
case Opcode::eTypeInvalid:
29-
bytes_written = s->PutCString("<invalid>");
29+
s->PutCString("<invalid>");
3030
break;
3131
case Opcode::eType8:
32-
bytes_written = s->Printf("0x%2.2x", m_data.inst8);
32+
s->Printf("0x%2.2x", m_data.inst8);
3333
break;
3434
case Opcode::eType16:
35-
bytes_written = s->Printf("0x%4.4x", m_data.inst16);
35+
s->Printf("0x%4.4x", m_data.inst16);
3636
break;
3737
case Opcode::eType16_2:
3838
case Opcode::eType32:
39-
bytes_written = s->Printf("0x%8.8x", m_data.inst32);
39+
s->Printf("0x%8.8x", m_data.inst32);
4040
break;
4141

4242
case Opcode::eType64:
43-
bytes_written = s->Printf("0x%16.16" PRIx64, m_data.inst64);
43+
s->Printf("0x%16.16" PRIx64, m_data.inst64);
4444
break;
4545

4646
case Opcode::eTypeBytes:
4747
for (uint32_t i = 0; i < m_data.inst.length; ++i) {
4848
if (i > 0)
49-
bytes_written += s->PutChar(' ');
50-
bytes_written += s->Printf("%2.2x", m_data.inst.bytes[i]);
49+
s->PutChar(' ');
50+
s->Printf("%2.2x", m_data.inst.bytes[i]);
5151
}
5252
break;
5353
}
5454

55-
// Add spaces to make sure bytes dispay comes out even in case opcodes aren't
56-
// all the same size
57-
if (static_cast<uint32_t>(bytes_written) < min_byte_width)
58-
bytes_written = s->Printf("%*s", min_byte_width - bytes_written, "");
59-
return bytes_written;
55+
uint32_t bytes_written_so_far = s->GetWrittenBytes() - previous_bytes;
56+
// Add spaces to make sure bytes display comes out even in case opcodes aren't
57+
// all the same size.
58+
if (bytes_written_so_far < min_byte_width)
59+
s->Printf("%*s", min_byte_width - bytes_written_so_far, "");
60+
return s->GetWrittenBytes() - previous_bytes;
6061
}
6162

6263
lldb::ByteOrder Opcode::GetDataByteOrder() const {

0 commit comments

Comments
 (0)
Please sign in to comment.