diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index 372b8d61..7d3e54dc 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -18,6 +18,7 @@ SourceView::SourceView( ImFont* font ) : m_font( font ) , m_file( nullptr ) , m_symAddr( 0 ) + , m_currentAddr( 0 ) , m_targetAddr( 0 ) , m_data( nullptr ) , m_dataSize( 0 ) @@ -25,6 +26,7 @@ SourceView::SourceView( ImFont* font ) , m_selectedLine( 0 ) , m_showAsm( false ) , m_codeLen( 0 ) + , m_highlightAddr( 0 ) { } @@ -40,6 +42,7 @@ void SourceView::Open( const char* fileName, int line, uint64_t baseAddr, uint64 m_targetAddr = symAddr; m_baseAddr = baseAddr; m_symAddr = symAddr; + m_currentAddr = symAddr; if( m_file != fileName ) { @@ -206,6 +209,8 @@ bool SourceView::Disassemble( uint64_t symAddr, const Worker& worker ) void SourceView::Render( const Worker& worker ) { + m_highlightAddr.Decay( 0 ); + if( m_file ) TextFocused( "File:", m_file ); if( !m_asm.empty() && !m_lines.empty() ) @@ -314,7 +319,7 @@ void SourceView::Render( const Worker& worker ) m_targetAddr = 0; ImGui::SetScrollHereY(); } - RenderAsmLine( line, 0, iptotal ); + RenderAsmLine( line, 0, iptotal, worker ); } } else @@ -326,7 +331,7 @@ void SourceView::Render( const Worker& worker ) { for( auto i=clipper.DisplayStart; isecond; - RenderAsmLine( line, ipcnt, iptotal ); + RenderAsmLine( line, ipcnt, iptotal, worker ); } } } @@ -429,16 +434,20 @@ void SourceView::RenderLine( const Line& line, int lineNum, uint32_t ipcnt, uint draw->AddLine( wpos + ImVec2( 0, ty+2 ), wpos + ImVec2( w, ty+2 ), 0x08FFFFFF ); } -void SourceView::RenderAsmLine( const AsmLine& line, uint32_t ipcnt, uint32_t iptotal ) +void SourceView::RenderAsmLine( const AsmLine& line, uint32_t ipcnt, uint32_t iptotal, const Worker& worker ) { const auto ty = ImGui::GetFontSize(); auto draw = ImGui::GetWindowDrawList(); const auto w = ImGui::GetWindowWidth(); const auto wpos = ImGui::GetCursorScreenPos(); - if( line.addr == m_symAddr ) + if( line.addr == m_currentAddr ) { draw->AddRectFilled( wpos, wpos + ImVec2( w, ty+1 ), 0xFF333322 ); } + if( line.addr == m_highlightAddr ) + { + draw->AddRectFilled( wpos, wpos + ImVec2( w, ty+1 ), 0xFF222233 ); + } if( iptotal != 0 ) { @@ -475,6 +484,36 @@ void SourceView::RenderAsmLine( const AsmLine& line, uint32_t ipcnt, uint32_t ip memcpy( buf+16, line.operands.c_str(), line.operands.size() + 1 ); ImGui::TextUnformatted( buf ); + if( line.jumpAddr != 0 ) + { + uint32_t offset = 0; + const auto base = worker.GetSymbolForAddress( line.jumpAddr, offset ); + auto sym = base == 0 ? worker.GetSymbolData( line.jumpAddr ) : worker.GetSymbolData( base ); + if( sym ) + { + ImGui::SameLine(); + ImGui::Spacing(); + ImGui::SameLine(); + if( base == m_baseAddr ) + { + ImGui::TextDisabled( "-> [%s+%" PRIu32"]", worker.GetString( sym->name ), offset ); + if( ImGui::IsItemHovered() ) + { + m_highlightAddr = line.jumpAddr; + if( ImGui::IsItemClicked() ) + { + m_targetAddr = line.jumpAddr; + m_currentAddr = line.jumpAddr; + } + } + } + else + { + ImGui::TextDisabled( "[%s+%" PRIu32"]", worker.GetString( sym->name ), offset ); + } + } + } + draw->AddLine( wpos + ImVec2( 0, ty+2 ), wpos + ImVec2( w, ty+2 ), 0x08FFFFFF ); } diff --git a/server/TracySourceView.hpp b/server/TracySourceView.hpp index 0639b6ea..c27b18dd 100644 --- a/server/TracySourceView.hpp +++ b/server/TracySourceView.hpp @@ -1,6 +1,8 @@ #include #include +#include "TracyDecayValue.hpp" + struct ImFont; namespace tracy @@ -33,13 +35,14 @@ public: private: void RenderLine( const Line& line, int lineNum, uint32_t ipcnt, uint32_t iptotal ); - void RenderAsmLine( const AsmLine& line, uint32_t ipcnt, uint32_t iptotal ); + void RenderAsmLine( const AsmLine& line, uint32_t ipcnt, uint32_t iptotal, const Worker& worker ); bool Disassemble( uint64_t symAddr, const Worker& worker ); ImFont* m_font; const char* m_file; uint64_t m_symAddr; + uint64_t m_currentAddr; uint64_t m_baseAddr; uint64_t m_targetAddr; char* m_data; @@ -48,6 +51,7 @@ private: int m_selectedLine; bool m_showAsm; uint32_t m_codeLen; + DecayValue m_highlightAddr; std::vector m_lines; std::vector m_asm;