diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index 1335b986..30deab70 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -45,7 +45,21 @@ SourceView::~SourceView() delete[] m_data; } -void SourceView::Open( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr, const Worker& worker ) +void SourceView::OpenSource( const char* fileName, int line ) +{ + m_targetLine = line; + m_selectedLine = line; + m_targetAddr = 0; + m_baseAddr = 0; + m_symAddr = 0; + m_currentAddr = 0; + m_showAsm = false; + + ParseSource( fileName, nullptr ); + assert( !m_lines.empty() ); +} + +void SourceView::OpenSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr, const Worker& worker ) { m_targetLine = line; m_selectedLine = line; @@ -54,10 +68,19 @@ void SourceView::Open( const char* fileName, int line, uint64_t baseAddr, uint64 m_symAddr = symAddr; m_currentAddr = symAddr; + ParseSource( fileName, &worker ); + + if( m_lines.empty() ) m_showAsm = true; + if( !Disassemble( baseAddr, worker ) ) m_showAsm = false; + assert( m_showAsm || !m_lines.empty() ); +} + +void SourceView::ParseSource( const char* fileName, const Worker* worker ) +{ if( m_file != fileName ) { m_file = fileName; - m_fileStringIdx = worker.FindStringIdx( fileName ); + m_fileStringIdx = worker ? worker->FindStringIdx( fileName ) : 0; m_lines.clear(); if( fileName ) { @@ -96,10 +119,6 @@ void SourceView::Open( const char* fileName, int line, uint64_t baseAddr, uint64 } } } - - if( m_lines.empty() ) m_showAsm = true; - if( !Disassemble( baseAddr, worker ) ) m_showAsm = false; - assert( m_showAsm || !m_lines.empty() ); } bool SourceView::Disassemble( uint64_t symAddr, const Worker& worker ) @@ -587,7 +606,7 @@ void SourceView::RenderSymbolView( const Worker& worker ) } if( line > 0 || sym->size.Val() > 0 ) { - Open( file, line, jumpOut, jumpOut, worker ); + OpenSymbol( file, line, jumpOut, jumpOut, worker ); } } } diff --git a/server/TracySourceView.hpp b/server/TracySourceView.hpp index b1108d1c..16aa01e9 100644 --- a/server/TracySourceView.hpp +++ b/server/TracySourceView.hpp @@ -42,18 +42,20 @@ public: SourceView( ImFont* font ); ~SourceView(); - void Open( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr, const Worker& worker ); + void OpenSource( const char* fileName, int line ); + void OpenSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr, const Worker& worker ); void Render( const Worker& worker ); private: + void ParseSource( const char* fileName, const Worker* worker ); + bool Disassemble( uint64_t symAddr, const Worker& worker ); + void RenderSimpleSourceView(); void RenderSymbolView( const Worker& worker ); void RenderLine( const Line& line, int lineNum, uint32_t ipcnt, uint32_t iptotal, const Worker* worker ); void RenderAsmLine( const AsmLine& line, uint32_t ipcnt, uint32_t iptotal, const Worker& worker, uint64_t& jumpOut ); - bool Disassemble( uint64_t symAddr, const Worker& worker ); - ImFont* m_font; const char* m_file; uint32_t m_fileStringIdx; diff --git a/server/TracyView.cpp b/server/TracyView.cpp index f562fcae..5b5ddaca 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -193,14 +193,21 @@ void View::InitTextEditor( ImFont* font ) m_sourceViewFile = nullptr; } -void View::SetTextEditorFile( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr ) +void View::ViewSource( const char* fileName, int line ) +{ + assert( fileName ); + m_sourceViewFile = fileName; + m_sourceView->OpenSource( fileName, line ); +} + +void View::ViewSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr ) { assert( fileName || symAddr ); m_sourceViewFile = fileName ? fileName : (const char*)~uint64_t( 0 ); - m_sourceView->Open( fileName, line, baseAddr, symAddr, m_worker ); + m_sourceView->OpenSymbol( fileName, line, baseAddr, symAddr, m_worker ); } -bool View::SetTextEditorFile( const char* fileName, int line, uint64_t symAddr ) +bool View::ViewDispatch( const char* fileName, int line, uint64_t symAddr ) { if( line == 0 ) { @@ -218,7 +225,7 @@ bool View::SetTextEditorFile( const char* fileName, int line, uint64_t symAddr ) { if( line != 0 ) { - SetTextEditorFile( fileName, line, 0, 0 ); + ViewSource( fileName, line ); return true; } return false; @@ -242,7 +249,7 @@ bool View::SetTextEditorFile( const char* fileName, int line, uint64_t symAddr ) } if( symlen != 0 || line != 0 ) { - SetTextEditorFile( fileName, line, baseAddr, symAddr ); + ViewSymbol( fileName, line, baseAddr, symAddr ); return true; } return false; @@ -3504,7 +3511,7 @@ int View::DrawGhostLevel( const Vector& vec, bool hover, double pxns, if( ImGui::IsMouseClicked( 0 ) ) { - SetTextEditorFile( file, line, frame->data[i].symAddr ); + ViewDispatch( file, line, frame->data[i].symAddr ); } else if( !m_zoomAnim.active && ImGui::IsMouseClicked( 2 ) ) { @@ -6001,7 +6008,7 @@ void DrawZoneTrace( T zone, const std::vector& trace, const Worker& worker, B } if( ImGui::IsItemClicked( 1 ) ) { - if( !view.SetTextEditorFile( fileName, frame->line, frame->symAddr ) ) + if( !view.ViewDispatch( fileName, frame->line, frame->symAddr ) ) { anim.Enable( frame, 0.5f ); } @@ -6059,7 +6066,7 @@ void DrawZoneTrace( T zone, const std::vector& trace, const Worker& worker, B } if( ImGui::IsItemClicked( 1 ) ) { - if( !view.SetTextEditorFile( fileName, frame->line, frame->symAddr ) ) + if( !view.ViewDispatch( fileName, frame->line, frame->symAddr ) ) { anim.Enable( frame, 0.5f ); } @@ -6235,7 +6242,7 @@ void View::DrawZoneInfoWindow() } if( ImGui::Button( ICON_FA_FILE_ALT " Source" ) ) { - SetTextEditorFile( fileName, srcloc.line, 0 ); + ViewSource( fileName, srcloc.line ); } if( hilite ) { @@ -6758,7 +6765,7 @@ void View::DrawZoneInfoWindow() { if( SourceFileValid( fileName, m_worker.GetCaptureTime() ) ) { - SetTextEditorFile( fileName, srcloc.line, 0 ); + ViewSource( fileName, srcloc.line ); } else { @@ -7188,7 +7195,7 @@ void View::DrawGpuInfoWindow() } if( ImGui::Button( ICON_FA_FILE_ALT " Source" ) ) { - SetTextEditorFile( fileName, srcloc.line, 0 ); + ViewSource( fileName, srcloc.line ); } if( hilite ) { @@ -7295,7 +7302,7 @@ void View::DrawGpuInfoWindow() { if( SourceFileValid( fileName, m_worker.GetCaptureTime() ) ) { - SetTextEditorFile( fileName, srcloc.line, 0 ); + ViewSource( fileName, srcloc.line ); } else { @@ -7871,7 +7878,7 @@ void View::DrawOptions() { if( SourceFileValid( fileName, m_worker.GetCaptureTime() ) ) { - SetTextEditorFile( fileName, sl.line, 0 ); + ViewSource( fileName, sl.line ); } else { @@ -7945,7 +7952,7 @@ void View::DrawOptions() { if( SourceFileValid( fileName, m_worker.GetCaptureTime() ) ) { - SetTextEditorFile( fileName, sl.line, 0 ); + ViewSource( fileName, sl.line ); } else { @@ -8019,7 +8026,7 @@ void View::DrawOptions() { if( SourceFileValid( fileName, m_worker.GetCaptureTime() ) ) { - SetTextEditorFile( fileName, sl.line, 0 ); + ViewSource( fileName, sl.line ); } else { @@ -8590,7 +8597,7 @@ void View::DrawFindZone() { if( SourceFileValid( fileName, m_worker.GetCaptureTime() ) ) { - SetTextEditorFile( fileName, srcloc.line, 0 ); + ViewSource( fileName, srcloc.line ); } else { @@ -11213,7 +11220,7 @@ void View::DrawStatistics() { if( SourceFileValid( file, m_worker.GetCaptureTime() ) ) { - SetTextEditorFile( file, srcloc.line, 0 ); + ViewSource( file, srcloc.line ); } else { @@ -11541,14 +11548,14 @@ void View::DrawStatistics() { if( SourceFileValid( file, m_worker.GetCaptureTime() ) ) { - SetTextEditorFile( file, line, codeAddr, v.symAddr ); + ViewSymbol( file, line, codeAddr, v.symAddr ); } else if( symlen != 0 ) { uint32_t len; if( m_worker.GetSymbolCode( codeAddr, len ) ) { - SetTextEditorFile( nullptr, 0, codeAddr, v.symAddr ); + ViewSymbol( nullptr, 0, codeAddr, v.symAddr ); } else { @@ -11837,7 +11844,7 @@ void View::DrawCallstackWindow() if( sym ) { const auto symtxt = m_worker.GetString( sym->file ); - if( !SetTextEditorFile( symtxt, sym->line, frame.symAddr ) ) + if( !ViewDispatch( symtxt, sym->line, frame.symAddr ) ) { m_callstackBuzzAnim.Enable( bidx, 0.5f ); } @@ -11849,7 +11856,7 @@ void View::DrawCallstackWindow() } else { - if( !SetTextEditorFile( txt, frame.line, frame.symAddr ) ) + if( !ViewDispatch( txt, frame.line, frame.symAddr ) ) { m_callstackBuzzAnim.Enable( bidx, 0.5f ); } @@ -12902,7 +12909,11 @@ void View::DrawLockInfoWindow() ImGui::Text( "%s:%i", fileName, srcloc.line ); if( ImGui::IsItemClicked( 1 ) ) { - if( !SetTextEditorFile( fileName, srcloc.line, 0 ) ) + if( SourceFileValid( fileName, m_worker.GetCaptureTime() ) ) + { + ViewSource( fileName, srcloc.line ); + } + else { m_lockInfoAnim.Enable( m_lockInfoWindow, 0.5f ); } @@ -13474,7 +13485,7 @@ void View::DrawSampleParents() } if( ImGui::IsItemClicked( 1 ) ) { - SetTextEditorFile( callFile, symbol->callLine, m_sampleParents.symAddr ); + ViewDispatch( callFile, symbol->callLine, m_sampleParents.symAddr ); } TextDisabledUnformatted( "Entry point:" ); ImGui::SameLine(); @@ -13489,7 +13500,7 @@ void View::DrawSampleParents() } if( ImGui::IsItemClicked( 1 ) ) { - SetTextEditorFile( file, symbol->line, m_sampleParents.symAddr ); + ViewDispatch( file, symbol->line, m_sampleParents.symAddr ); } ImGui::SameLine(); ImGui::Spacing(); @@ -13695,7 +13706,7 @@ void View::DrawSampleParents() if( sym ) { const auto symtxt = m_worker.GetString( sym->file ); - if( !SetTextEditorFile( symtxt, sym->line, frame.symAddr ) ) + if( !ViewDispatch( symtxt, sym->line, frame.symAddr ) ) { m_sampleParentBuzzAnim.Enable( bidx, 0.5f ); } @@ -13707,7 +13718,7 @@ void View::DrawSampleParents() } else { - if( !SetTextEditorFile( txt, frame.line, frame.symAddr ) ) + if( !ViewDispatch( txt, frame.line, frame.symAddr ) ) { m_sampleParentBuzzAnim.Enable( bidx, 0.5f ); } @@ -14688,7 +14699,7 @@ void View::DrawFrameTreeLevel( const unordered_flat_map