From ac9b97319a26d448c9af51eb6ab9e9fd7ca13bfd Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 29 Apr 2021 20:08:18 +0200 Subject: [PATCH] Extract jump name retrieval. --- server/TracySourceView.cpp | 51 +++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index 46819a61..0642f8c4 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -3025,6 +3025,17 @@ void SourceView::RenderAsmLine( AsmLine& line, const AddrStat& ipcnt, const Addr ImGui::TextUnformatted( buf ); } + uint32_t jumpOffset; + uint64_t jumpBase; + const char* jumpName = nullptr; + if( line.jumpAddr != 0 ) + { + jumpOffset = 0; + jumpBase = worker.GetSymbolForAddress( line.jumpAddr, jumpOffset ); + auto jumpSym = jumpBase == 0 ? worker.GetSymbolData( line.jumpAddr ) : worker.GetSymbolData( jumpBase ); + if( jumpSym ) jumpName = worker.GetString( jumpSym->name ); + } + if( ImGui::IsItemHovered() ) { if( asmVar ) @@ -3274,35 +3285,29 @@ void SourceView::RenderAsmLine( AsmLine& line, const AddrStat& ipcnt, const Addr TextColoredUnformatted( ImVec4( 0.5f, 0.5, 1, 1 ), "}" ); } - if( line.jumpAddr != 0 ) + if( jumpName ) { - 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( jumpBase == m_baseAddr ) { - ImGui::SameLine(); - ImGui::Spacing(); - ImGui::SameLine(); - if( base == m_baseAddr ) + ImGui::TextDisabled( "-> [%s+%" PRIu32"]", jumpName, jumpOffset ); + if( ImGui::IsItemHovered() ) { - ImGui::TextDisabled( "-> [%s+%" PRIu32"]", worker.GetString( sym->name ), offset ); - if( ImGui::IsItemHovered() ) + m_highlightAddr = line.jumpAddr; + if( ImGui::IsItemClicked() ) { - m_highlightAddr = line.jumpAddr; - if( ImGui::IsItemClicked() ) - { - m_targetAddr = line.jumpAddr; - m_selectedAddresses.clear(); - m_selectedAddresses.emplace( line.jumpAddr ); - } + m_targetAddr = line.jumpAddr; + m_selectedAddresses.clear(); + m_selectedAddresses.emplace( line.jumpAddr ); } } - else - { - ImGui::TextDisabled( "[%s+%" PRIu32"]", worker.GetString( sym->name ), offset ); - if( ImGui::IsItemClicked() ) jumpOut = line.jumpAddr; - } + } + else + { + ImGui::TextDisabled( "[%s+%" PRIu32"]", jumpName, jumpOffset ); + if( ImGui::IsItemClicked() ) jumpOut = line.jumpAddr; } }