Allow viewing assembly without corresponding source code.

This commit is contained in:
Bartosz Taudul 2020-03-27 01:47:06 +01:00
parent 10ca8b5440
commit 089681267f
2 changed files with 65 additions and 38 deletions

View File

@ -43,6 +43,9 @@ void SourceView::Open( const char* fileName, int line, uint64_t symAddr, const W
if( m_file != fileName ) if( m_file != fileName )
{ {
m_file = fileName; m_file = fileName;
m_lines.clear();
if( fileName )
{
FILE* f = fopen( fileName, "rb" ); FILE* f = fopen( fileName, "rb" );
fseek( f, 0, SEEK_END ); fseek( f, 0, SEEK_END );
const auto sz = ftell( f ); const auto sz = ftell( f );
@ -57,7 +60,6 @@ void SourceView::Open( const char* fileName, int line, uint64_t symAddr, const W
m_data[sz] = '\0'; m_data[sz] = '\0';
fclose( f ); fclose( f );
m_lines.clear();
auto txt = m_data; auto txt = m_data;
for(;;) for(;;)
{ {
@ -78,8 +80,11 @@ void SourceView::Open( const char* fileName, int line, uint64_t symAddr, const W
txt = end; txt = end;
} }
} }
}
if( m_lines.empty() ) m_showAsm = true;
if( !Disassemble( symAddr, worker ) ) m_showAsm = false; if( !Disassemble( symAddr, worker ) ) m_showAsm = false;
assert( m_showAsm || !m_lines.empty() );
} }
bool SourceView::Disassemble( uint64_t symAddr, const Worker& worker ) bool SourceView::Disassemble( uint64_t symAddr, const Worker& worker )
@ -130,7 +135,7 @@ bool SourceView::Disassemble( uint64_t symAddr, const Worker& worker )
void SourceView::Render( const Worker& worker ) void SourceView::Render( const Worker& worker )
{ {
if( !m_asm.empty() ) if( !m_asm.empty() && !m_lines.empty() )
{ {
if( SmallCheckbox( ICON_FA_MICROCHIP " Show assembly", &m_showAsm ) ) if( SmallCheckbox( ICON_FA_MICROCHIP " Show assembly", &m_showAsm ) )
{ {
@ -143,9 +148,15 @@ void SourceView::Render( const Worker& worker )
m_targetLine = m_selectedLine; m_targetLine = m_selectedLine;
} }
} }
}
if( !m_asm.empty() )
{
if( !m_lines.empty() )
{
ImGui::SameLine(); ImGui::SameLine();
ImGui::Spacing(); ImGui::Spacing();
ImGui::SameLine(); ImGui::SameLine();
}
TextFocused( "Code size:", MemSizeToString( m_codeLen ) ); TextFocused( "Code size:", MemSizeToString( m_codeLen ) );
} }

View File

@ -194,7 +194,8 @@ void View::InitTextEditor( ImFont* font )
void View::SetTextEditorFile( const char* fileName, int line, uint64_t symAddr ) void View::SetTextEditorFile( const char* fileName, int line, uint64_t symAddr )
{ {
m_sourceViewFile = fileName; assert( fileName || symAddr );
m_sourceViewFile = fileName ? fileName : (const char*)~uint64_t( 0 );
m_sourceView->Open( fileName, line, symAddr, m_worker ); m_sourceView->Open( fileName, line, symAddr, m_worker );
} }
@ -11418,6 +11419,18 @@ void View::DrawStatistics()
{ {
SetTextEditorFile( file, line, v.symAddr ); SetTextEditorFile( file, line, v.symAddr );
} }
else if( symlen != 0 )
{
uint32_t len;
if( m_worker.GetSymbolCode( v.symAddr, len ) )
{
SetTextEditorFile( nullptr, 0, v.symAddr );
}
else
{
m_statBuzzAnim.Enable( v.symAddr, 0.5f );
}
}
else else
{ {
m_statBuzzAnim.Enable( v.symAddr, 0.5f ); m_statBuzzAnim.Enable( v.symAddr, 0.5f );
@ -12636,12 +12649,15 @@ void View::DrawTextEditor()
ImGui::SetNextWindowSize( ImVec2( 700, 800 ), ImGuiCond_FirstUseEver ); ImGui::SetNextWindowSize( ImVec2( 700, 800 ), ImGuiCond_FirstUseEver );
bool show = true; bool show = true;
ImGui::Begin( "Source view", &show ); ImGui::Begin( "Source view", &show );
if( m_sourceViewFile != (const char*)~uint64_t( 0 ) )
{
TextColoredUnformatted( ImVec4( 1.f, 1.f, 0.2f, 1.f ), ICON_FA_EXCLAMATION_TRIANGLE ); TextColoredUnformatted( ImVec4( 1.f, 1.f, 0.2f, 1.f ), ICON_FA_EXCLAMATION_TRIANGLE );
ImGui::SameLine(); ImGui::SameLine();
TextColoredUnformatted( ImVec4( 1.f, 0.3f, 0.3f, 1.f ), "The source file contents might not reflect the actual profiled code!" ); TextColoredUnformatted( ImVec4( 1.f, 0.3f, 0.3f, 1.f ), "The source file contents might not reflect the actual profiled code!" );
ImGui::SameLine(); ImGui::SameLine();
TextColoredUnformatted( ImVec4( 1.f, 1.f, 0.2f, 1.f ), ICON_FA_EXCLAMATION_TRIANGLE ); TextColoredUnformatted( ImVec4( 1.f, 1.f, 0.2f, 1.f ), ICON_FA_EXCLAMATION_TRIANGLE );
TextFocused( "File:", m_sourceViewFile ); TextFocused( "File:", m_sourceViewFile );
}
m_sourceView->Render( m_worker ); m_sourceView->Render( m_worker );
ImGui::End(); ImGui::End();
if( !show ) m_sourceViewFile = nullptr; if( !show ) m_sourceViewFile = nullptr;