Skip to content

Commit 9a5fb0b

Browse files
committed
Implement search for symbol matching function name when opening source view.
1 parent cf412bf commit 9a5fb0b

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

‎server/TracyView.cpp‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,56 @@ void View::ViewSource( const char* fileName, int line )
159159
m_sourceView->OpenSource( fileName, line, *this, m_worker );
160160
}
161161

162+
void View::ViewSource( const char* fileName, int line, const char* functionName )
163+
{
164+
assert( functionName );
165+
166+
uint64_t addr = 0;
167+
uint64_t base = 0;
168+
const auto fnsz = strlen( functionName );
169+
auto& symMap = m_worker.GetSymbolMap();
170+
for( auto& sym : symMap )
171+
{
172+
const auto name = m_worker.GetString( sym.second.name );
173+
const auto ptr = strstr( name, functionName );
174+
if( ptr &&
175+
( ptr[fnsz] == 0 || ptr[fnsz] == '(' || ptr[fnsz] == '<' ) &&
176+
( ptr == name || ( ptr[-1] == ' ' || ptr[-1] == ':' ) ) )
177+
{
178+
if( addr != 0 )
179+
{
180+
// Ambiguous function name. Bail out.
181+
ViewSource( fileName, line );
182+
return;
183+
}
184+
else
185+
{
186+
addr = sym.first;
187+
if( sym.second.isInline )
188+
{
189+
base = m_worker.GetSymbolForAddress( addr );
190+
if( base == 0 )
191+
{
192+
addr = 0;
193+
}
194+
}
195+
else
196+
{
197+
base = addr;
198+
}
199+
}
200+
}
201+
}
202+
if( addr != 0 && base != 0 )
203+
{
204+
ViewSymbol( fileName, line, base, addr );
205+
}
206+
else
207+
{
208+
ViewSource( fileName, line );
209+
}
210+
}
211+
162212
void View::ViewSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr )
163213
{
164214
assert( fileName || symAddr );

‎server/TracyView.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class View
112112

113113
void NotifyRootWindowSize( float w, float h ) { m_rootWidth = w; m_rootHeight = h; }
114114
void ViewSource( const char* fileName, int line );
115+
void ViewSource( const char* fileName, int line, const char* functionName );
115116
void ViewSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr );
116117
bool ViewDispatch( const char* fileName, int line, uint64_t symAddr );
117118

0 commit comments

Comments
 (0)