Annotate assembly dumps with source line information.

This commit is contained in:
Bartosz Taudul 2023-01-01 16:19:37 +01:00
parent bb8393c918
commit 6c699d293e
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -5581,12 +5581,13 @@ void SourceView::Save( const Worker& worker, size_t start, size_t stop )
fprintf( f, ".L%" PRIu32 ":\n", it->second ); fprintf( f, ".L%" PRIu32 ":\n", it->second );
} }
bool hasJump = false; bool hasJump = false;
int psz = 0;
if( v.jumpAddr != 0 ) if( v.jumpAddr != 0 )
{ {
auto lit = m_locMap.find( v.jumpAddr ); auto lit = m_locMap.find( v.jumpAddr );
if( lit != m_locMap.end() ) if( lit != m_locMap.end() )
{ {
fprintf( f, "\t%-*s.L%" PRIu32 "\n", m_maxMnemonicLen, v.mnemonic.c_str(), lit->second ); psz = fprintf( f, "\t%-*s.L%" PRIu32, m_maxMnemonicLen, v.mnemonic.c_str(), lit->second );
hasJump = true; hasJump = true;
} }
} }
@ -5594,13 +5595,25 @@ void SourceView::Save( const Worker& worker, size_t start, size_t stop )
{ {
if( v.operands.empty() ) if( v.operands.empty() )
{ {
fprintf( f, "\t%s\n", v.mnemonic.c_str() ); psz = fprintf( f, "\t%s", v.mnemonic.c_str() );
} }
else else
{ {
fprintf( f, "\t%-*s%s\n", m_maxMnemonicLen, v.mnemonic.c_str(), v.operands.c_str() ); psz = fprintf( f, "\t%-*s%s", m_maxMnemonicLen, v.mnemonic.c_str(), v.operands.c_str() );
} }
} }
uint32_t srcline;
const auto srcidx = worker.GetLocationForAddress( v.addr, srcline );
if( srcline != 0 && psz > 0 )
{
int spaces = std::max( m_maxMnemonicLen + m_maxOperandLen - psz, 0 ) + 1;
while( spaces-- ) fputc( ' ', f );
fprintf( f, "# %s:%i\n", worker.GetString( srcidx ), srcline );
}
else
{
fputc( '\n', f );
}
} }
fclose( f ); fclose( f );
} ); } );