Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/wolfpld/tracy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartosz Taudul <wolf@nereid.pl>2021-03-26 04:41:30 +0300
committerBartosz Taudul <wolf@nereid.pl>2021-03-26 04:42:15 +0300
commit0b5a923e91dfdf55420dc4419443dd43a34c18d6 (patch)
treebf7a99679e2f7eecf69c05a3b61da4a22a55916f
parentbd4335bace987fe72d2dce34ec2fdaafe85838e1 (diff)
Display preview of source code for assembly instructions.
-rw-r--r--server/TracySourceView.cpp58
-rw-r--r--server/TracySourceView.hpp1
2 files changed, 59 insertions, 0 deletions
diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp
index 74704339..8cf35a47 100644
--- a/server/TracySourceView.cpp
+++ b/server/TracySourceView.cpp
@@ -2184,6 +2184,19 @@ static const ImVec4 SyntaxColors[] = {
{ 0.21f, 0.69f, 0.89f, 1 }, // special
};
+static const ImVec4 SyntaxColorsDimmed[] = {
+ { 0.7f, 0.7f, 0.7f, 0.6f }, // default
+ { 0.45f, 0.68f, 0.32f, 0.6f }, // comment
+ { 0.72f, 0.37f, 0.12f, 0.6f }, // preprocessor
+ { 0.64f, 0.64f, 1, 0.6f }, // string
+ { 0.64f, 0.82f, 1, 0.6f }, // char literal
+ { 1, 0.91f, 0.53f, 0.6f }, // keyword
+ { 0.81f, 0.6f, 0.91f, 0.6f }, // number
+ { 0.9f, 0.9f, 0.9f, 0.6f }, // punctuation
+ { 0.78f, 0.46f, 0.75f, 0.6f }, // type
+ { 0.21f, 0.69f, 0.89f, 0.6f }, // special
+};
+
void SourceView::RenderLine( const Tokenizer::Line& line, int lineNum, uint32_t ipcnt, uint32_t iptotal, uint32_t ipmax, const Worker* worker )
{
const auto ty = ImGui::GetFontSize();
@@ -2557,6 +2570,51 @@ void SourceView::RenderAsmLine( AsmLine& line, uint32_t ipcnt, uint32_t iptotal,
ImGui::BeginTooltip();
TextFocused( "File:", fileName );
TextFocused( "Line:", RealToString( srcline ) );
+ if( SourceFileValid( fileName, worker.GetCaptureTime(), view, worker ) )
+ {
+ m_sourceTooltip.Parse( fileName, worker, view );
+ if( !m_sourceTooltip.empty() )
+ {
+ ImGui::Separator();
+ if( m_font ) ImGui::PushFont( m_font );
+ auto& lines = m_sourceTooltip.get();
+ const int start = std::max( 0, (int)srcline - 4 );
+ const int end = std::min<int>( m_sourceTooltip.get().size(), srcline + 3 );
+ for( int i=start; i<end; i++ )
+ {
+ auto& line = lines[i];
+ if( line.begin == line.end )
+ {
+ ImGui::TextUnformatted( "" );
+ }
+ else
+ {
+ auto ptr = line.begin;
+ auto it = line.tokens.begin();
+ while( ptr < line.end )
+ {
+ if( it == line.tokens.end() )
+ {
+ ImGui::TextUnformatted( ptr, line.end );
+ ImGui::SameLine( 0, 0 );
+ break;
+ }
+ if( ptr < it->begin )
+ {
+ ImGui::TextUnformatted( ptr, it->begin );
+ ImGui::SameLine( 0, 0 );
+ }
+ TextColoredUnformatted( i == srcline-1 ? SyntaxColors[(int)it->color] : SyntaxColorsDimmed[(int)it->color], it->begin, it->end );
+ ImGui::SameLine( 0, 0 );
+ ptr = it->end;
+ ++it;
+ }
+ ImGui::ItemSize( ImVec2( 0, 0 ), 0 );
+ }
+ }
+ if( m_font ) ImGui::PopFont();
+ }
+ }
ImGui::EndTooltip();
if( m_font ) ImGui::PushFont( m_font );
if( ImGui::IsItemClicked( 0 ) || ImGui::IsItemClicked( 1 ) )
diff --git a/server/TracySourceView.hpp b/server/TracySourceView.hpp
index 3c02085a..5e5d140c 100644
--- a/server/TracySourceView.hpp
+++ b/server/TracySourceView.hpp
@@ -171,6 +171,7 @@ private:
uint64_t m_jumpPopupAddr;
SourceContents m_source;
+ SourceContents m_sourceTooltip;
std::vector<AsmLine> m_asm;
unordered_flat_map<uint64_t, uint32_t> m_locMap;