1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 20:33:52 +00:00

More concise machine code display.

This commit is contained in:
Bartosz Taudul 2022-08-09 01:13:06 +02:00
parent 849e58bfb3
commit baea6ddf11
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -2133,7 +2133,7 @@ void SourceView::RenderSymbolSourceView( const AddrStatData& as, Worker& worker,
static constexpr char HexPrint[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; static constexpr char HexPrint[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
static int PrintHexBytesRaw( char* buf, const uint8_t* bytes, size_t len ) static int FormatHexBytesRaw( char* buf, const uint8_t* bytes, size_t len )
{ {
const auto start = buf; const auto start = buf;
for( size_t i=0; i<len; i++ ) for( size_t i=0; i<len; i++ )
@ -2147,31 +2147,49 @@ static int PrintHexBytesRaw( char* buf, const uint8_t* bytes, size_t len )
return buf - start; return buf - start;
} }
static int PrintHexBytesArm( char* buf, const uint8_t* bytes ) static int PrintHexBytesRaw( const uint8_t* bytes, size_t len )
{ {
const auto start = buf; char buf[2];
for( int i=3; i>=0; i-- ) bool first = true;
for( size_t i=0; i<len; i++ )
{ {
if( first ) first = false;
else ImGui::SameLine( 0, 0 );
const auto byte = bytes[i]; const auto byte = bytes[i];
*buf++ = HexPrint[byte >> 4]; buf[0] = HexPrint[byte >> 4];
*buf++ = HexPrint[byte & 0xF]; buf[1] = HexPrint[byte & 0xF];
*buf++ = ' '; TextColoredUnformatted( (i%2 == 0) ? 0xFFFFBBBB : 0xFFBB7777, buf, buf+2 );
} }
*--buf = '\0'; return len * 2;
return buf - start;
} }
static int PrintHexBytes( char* buf, const uint8_t* bytes, size_t len, CpuArchitecture arch ) static int PrintHexBytesArm( const uint8_t* bytes )
{
char buf[2];
bool first = true;
for( int i=3; i>=0; i-- )
{
if( first ) first = false;
else ImGui::SameLine( 0, 0 );
const auto byte = bytes[i];
buf[0] = HexPrint[byte >> 4];
buf[1] = HexPrint[byte & 0xF];
TextColoredUnformatted( (i%2 != 0) ? 0xFFFFBBBB : 0xFFBB7777, buf, buf+2 );
}
return 8;
}
static int PrintHexBytes( const uint8_t* bytes, size_t len, CpuArchitecture arch )
{ {
switch( arch ) switch( arch )
{ {
case CpuArchX86: case CpuArchX86:
case CpuArchX64: case CpuArchX64:
return PrintHexBytesRaw( buf, bytes, len ); return PrintHexBytesRaw( bytes, len );
case CpuArchArm32: case CpuArchArm32:
case CpuArchArm64: case CpuArchArm64:
assert( len == 4 ); assert( len == 4 );
return PrintHexBytesArm( buf, bytes ); return PrintHexBytesArm( bytes );
default: default:
assert( false ); assert( false );
return 0; return 0;
@ -2198,7 +2216,7 @@ uint64_t SourceView::RenderSymbolAsmView( const AddrStatData& as, Worker& worker
auto bytesLeft = std::min( 16u, m_codeLen - m_disasmFail ); auto bytesLeft = std::min( 16u, m_codeLen - m_disasmFail );
auto code = worker.GetSymbolCode( m_baseAddr, m_codeLen ); auto code = worker.GetSymbolCode( m_baseAddr, m_codeLen );
assert( code ); assert( code );
PrintHexBytesRaw( tmp, (const uint8_t*)code, bytesLeft ); FormatHexBytesRaw( tmp, (const uint8_t*)code, bytesLeft );
TextFocused( "Failure bytes:", tmp ); TextFocused( "Failure bytes:", tmp );
TextDisabledUnformatted( "Click to copy to clipboard." ); TextDisabledUnformatted( "Click to copy to clipboard." );
ImGui::EndTooltip(); ImGui::EndTooltip();
@ -3612,12 +3630,10 @@ void SourceView::RenderAsmLine( AsmLine& line, const AddrStat& ipcnt, const Addr
{ {
auto code = (const uint8_t*)worker.GetSymbolCode( m_baseAddr, m_codeLen ); auto code = (const uint8_t*)worker.GetSymbolCode( m_baseAddr, m_codeLen );
assert( code ); assert( code );
char tmp[64];
const auto len = PrintHexBytes( tmp, code + line.addr - m_baseAddr, line.len, worker.GetCpuArch() );
ImGui::SameLine(); ImGui::SameLine();
TextColoredUnformatted( ImVec4( 0.5, 0.5, 1, 1 ), tmp ); const auto len = PrintHexBytes( code + line.addr - m_baseAddr, line.len, worker.GetCpuArch() );
ImGui::SameLine( 0, 0 ); ImGui::SameLine( 0, 0 );
ImGui::ItemSize( ImVec2( stw * ( m_maxAsmBytes*3 - len ), ty ), 0 ); ImGui::ItemSize( ImVec2( stw * ( m_maxAsmBytes*2 - len ), ty ), 0 );
} }
if( m_showJumps ) if( m_showJumps )
{ {