mirror of
https://github.com/wolfpld/tracy
synced 2025-04-29 12:23:53 +00:00
Extract asm saving to a separate function.
This commit is contained in:
parent
a30a0b852f
commit
9d5d116014
@ -1598,80 +1598,7 @@ uint64_t SourceView::RenderSymbolAsmView( uint32_t iptotal, unordered_flat_map<u
|
|||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if( ImGui::SmallButton( ICON_FA_FILE_IMPORT " Save" ) )
|
if( ImGui::SmallButton( ICON_FA_FILE_IMPORT " Save" ) )
|
||||||
{
|
{
|
||||||
nfdchar_t* fn;
|
Save( worker );
|
||||||
auto res = NFD_SaveDialog( "asm", nullptr, &fn );
|
|
||||||
if( res == NFD_OKAY )
|
|
||||||
{
|
|
||||||
FILE* f = nullptr;
|
|
||||||
const auto sz = strlen( fn );
|
|
||||||
if( sz < 5 || memcmp( fn + sz - 4, ".asm", 4 ) != 0 )
|
|
||||||
{
|
|
||||||
char tmp[1024];
|
|
||||||
sprintf( tmp, "%s.asm", fn );
|
|
||||||
f = fopen( tmp, "wb" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
f = fopen( fn, "wb" );
|
|
||||||
}
|
|
||||||
if( f )
|
|
||||||
{
|
|
||||||
char tmp[16];
|
|
||||||
auto sym = worker.GetSymbolData( m_symAddr );
|
|
||||||
assert( sym );
|
|
||||||
const char* symName;
|
|
||||||
if( sym->isInline )
|
|
||||||
{
|
|
||||||
auto parent = worker.GetSymbolData( m_baseAddr );
|
|
||||||
if( parent )
|
|
||||||
{
|
|
||||||
symName = worker.GetString( parent->name );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprintf( tmp, "0x%" PRIx64, m_baseAddr );
|
|
||||||
symName = tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
symName = worker.GetString( sym->name );
|
|
||||||
}
|
|
||||||
fprintf( f, "; Tracy Profiler disassembly of symbol %s [%s]\n\n", symName, worker.GetCaptureProgram().c_str() );
|
|
||||||
if( !m_atnt ) fprintf( f, ".intel_syntax\n\n" );
|
|
||||||
|
|
||||||
for( auto& v : m_asm )
|
|
||||||
{
|
|
||||||
auto it = m_locMap.find( v.addr );
|
|
||||||
if( it != m_locMap.end() )
|
|
||||||
{
|
|
||||||
fprintf( f, ".L%" PRIu32 ":\n", it->second );
|
|
||||||
}
|
|
||||||
bool hasJump = false;
|
|
||||||
if( v.jumpAddr != 0 )
|
|
||||||
{
|
|
||||||
auto lit = m_locMap.find( v.jumpAddr );
|
|
||||||
if( lit != m_locMap.end() )
|
|
||||||
{
|
|
||||||
fprintf( f, "\t%-*s.L%" PRIu32 "\n", m_maxMnemonicLen, v.mnemonic.c_str(), lit->second );
|
|
||||||
hasJump = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( !hasJump )
|
|
||||||
{
|
|
||||||
if( v.operands.empty() )
|
|
||||||
{
|
|
||||||
fprintf( f, "\t%s\n", v.mnemonic.c_str() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf( f, "\t%-*s%s\n", m_maxMnemonicLen, v.mnemonic.c_str(), v.operands.c_str() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose( f );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -3494,4 +3421,82 @@ void SourceView::CheckWrite( int line, RegsX86 reg, int limit )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SourceView::Save( const Worker& worker )
|
||||||
|
{
|
||||||
|
nfdchar_t* fn;
|
||||||
|
auto res = NFD_SaveDialog( "asm", nullptr, &fn );
|
||||||
|
if( res == NFD_OKAY )
|
||||||
|
{
|
||||||
|
FILE* f = nullptr;
|
||||||
|
const auto sz = strlen( fn );
|
||||||
|
if( sz < 5 || memcmp( fn + sz - 4, ".asm", 4 ) != 0 )
|
||||||
|
{
|
||||||
|
char tmp[1024];
|
||||||
|
sprintf( tmp, "%s.asm", fn );
|
||||||
|
f = fopen( tmp, "wb" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
f = fopen( fn, "wb" );
|
||||||
|
}
|
||||||
|
if( f )
|
||||||
|
{
|
||||||
|
char tmp[16];
|
||||||
|
auto sym = worker.GetSymbolData( m_symAddr );
|
||||||
|
assert( sym );
|
||||||
|
const char* symName;
|
||||||
|
if( sym->isInline )
|
||||||
|
{
|
||||||
|
auto parent = worker.GetSymbolData( m_baseAddr );
|
||||||
|
if( parent )
|
||||||
|
{
|
||||||
|
symName = worker.GetString( parent->name );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sprintf( tmp, "0x%" PRIx64, m_baseAddr );
|
||||||
|
symName = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
symName = worker.GetString( sym->name );
|
||||||
|
}
|
||||||
|
fprintf( f, "; Tracy Profiler disassembly of symbol %s [%s]\n\n", symName, worker.GetCaptureProgram().c_str() );
|
||||||
|
if( !m_atnt ) fprintf( f, ".intel_syntax\n\n" );
|
||||||
|
|
||||||
|
for( auto& v : m_asm )
|
||||||
|
{
|
||||||
|
auto it = m_locMap.find( v.addr );
|
||||||
|
if( it != m_locMap.end() )
|
||||||
|
{
|
||||||
|
fprintf( f, ".L%" PRIu32 ":\n", it->second );
|
||||||
|
}
|
||||||
|
bool hasJump = false;
|
||||||
|
if( v.jumpAddr != 0 )
|
||||||
|
{
|
||||||
|
auto lit = m_locMap.find( v.jumpAddr );
|
||||||
|
if( lit != m_locMap.end() )
|
||||||
|
{
|
||||||
|
fprintf( f, "\t%-*s.L%" PRIu32 "\n", m_maxMnemonicLen, v.mnemonic.c_str(), lit->second );
|
||||||
|
hasJump = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( !hasJump )
|
||||||
|
{
|
||||||
|
if( v.operands.empty() )
|
||||||
|
{
|
||||||
|
fprintf( f, "\t%s\n", v.mnemonic.c_str() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf( f, "\t%-*s%s\n", m_maxMnemonicLen, v.mnemonic.c_str(), v.operands.c_str() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose( f );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -167,6 +167,8 @@ private:
|
|||||||
void CheckRead( int line, RegsX86 reg, int limit );
|
void CheckRead( int line, RegsX86 reg, int limit );
|
||||||
void CheckWrite( int line, RegsX86 reg, int limit );
|
void CheckWrite( int line, RegsX86 reg, int limit );
|
||||||
|
|
||||||
|
void Save( const Worker& worker );
|
||||||
|
|
||||||
struct TokenizerState
|
struct TokenizerState
|
||||||
{
|
{
|
||||||
void Reset()
|
void Reset()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user