1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 04:23:51 +00:00

Construct location table during disassembly.

This commit is contained in:
Bartosz Taudul 2020-05-09 14:58:06 +02:00
parent 281f13f4c3
commit 0de39a1d33
2 changed files with 15 additions and 13 deletions

View File

@ -490,6 +490,7 @@ static bool IsJumpConditionalX86( const char* op )
bool SourceView::Disassemble( uint64_t symAddr, const Worker& worker ) bool SourceView::Disassemble( uint64_t symAddr, const Worker& worker )
{ {
m_asm.clear(); m_asm.clear();
m_locMap.clear();
m_jumpTable.clear(); m_jumpTable.clear();
m_jumpOut.clear(); m_jumpOut.clear();
m_maxJumpLevel = 0; m_maxJumpLevel = 0;
@ -821,6 +822,15 @@ bool SourceView::Disassemble( uint64_t symAddr, const Worker& worker )
} }
if( level > m_maxJumpLevel ) m_maxJumpLevel = level; if( level > m_maxJumpLevel ) m_maxJumpLevel = level;
} }
uint32_t locNum = 0;
for( auto& v : m_asm )
{
if( m_jumpTable.find( v.addr ) != m_jumpTable.end() )
{
m_locMap.emplace( v.addr, locNum++ );
}
}
} }
} }
cs_close( &handle ); cs_close( &handle );
@ -1628,27 +1638,18 @@ uint64_t SourceView::RenderSymbolAsmView( uint32_t iptotal, unordered_flat_map<u
fprintf( f, "; Tracy Profiler disassembly of symbol %s [%s]\n\n", symName, worker.GetCaptureProgram() ); fprintf( f, "; Tracy Profiler disassembly of symbol %s [%s]\n\n", symName, worker.GetCaptureProgram() );
if( !m_atnt ) fprintf( f, ".intel_syntax\n\n" ); if( !m_atnt ) fprintf( f, ".intel_syntax\n\n" );
unordered_flat_map<uint64_t, uint32_t> locMap;
for( auto& v : m_asm ) for( auto& v : m_asm )
{ {
if( m_jumpTable.find( v.addr ) != m_jumpTable.end() ) auto it = m_locMap.find( v.addr );
{ if( it != m_locMap.end() )
const auto idx = locMap.size();
locMap.emplace( v.addr, idx );
}
}
for( auto& v : m_asm )
{
auto it = locMap.find( v.addr );
if( it != locMap.end() )
{ {
fprintf( f, ".LOC_%" PRIu32 ":\n", it->second ); fprintf( f, ".LOC_%" PRIu32 ":\n", it->second );
} }
bool hasJump = false; bool hasJump = false;
if( v.jumpAddr != 0 ) if( v.jumpAddr != 0 )
{ {
auto lit = locMap.find( v.jumpAddr ); auto lit = m_locMap.find( v.jumpAddr );
if( lit != locMap.end() ) if( lit != m_locMap.end() )
{ {
fprintf( f, "\t%-*s.LOC_%" PRIu32 "\n", m_maxMnemonicLen, v.mnemonic.c_str(), lit->second ); fprintf( f, "\t%-*s.LOC_%" PRIu32 "\n", m_maxMnemonicLen, v.mnemonic.c_str(), lit->second );
hasJump = true; hasJump = true;

View File

@ -206,6 +206,7 @@ private:
std::vector<Line> m_lines; std::vector<Line> m_lines;
std::vector<AsmLine> m_asm; std::vector<AsmLine> m_asm;
unordered_flat_map<uint64_t, uint32_t> m_locMap;
unordered_flat_map<uint64_t, JumpData> m_jumpTable; unordered_flat_map<uint64_t, JumpData> m_jumpTable;
unordered_flat_set<uint64_t> m_jumpOut; unordered_flat_set<uint64_t> m_jumpOut;
int m_maxJumpLevel; int m_maxJumpLevel;