Implement search for symbol matching function name when opening source view.

This commit is contained in:
Bartosz Taudul 2024-01-02 15:07:44 +01:00
parent cf412bfb2e
commit 9a5fb0bb51
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 51 additions and 0 deletions

View File

@ -159,6 +159,56 @@ void View::ViewSource( const char* fileName, int line )
m_sourceView->OpenSource( fileName, line, *this, m_worker ); m_sourceView->OpenSource( fileName, line, *this, m_worker );
} }
void View::ViewSource( const char* fileName, int line, const char* functionName )
{
assert( functionName );
uint64_t addr = 0;
uint64_t base = 0;
const auto fnsz = strlen( functionName );
auto& symMap = m_worker.GetSymbolMap();
for( auto& sym : symMap )
{
const auto name = m_worker.GetString( sym.second.name );
const auto ptr = strstr( name, functionName );
if( ptr &&
( ptr[fnsz] == 0 || ptr[fnsz] == '(' || ptr[fnsz] == '<' ) &&
( ptr == name || ( ptr[-1] == ' ' || ptr[-1] == ':' ) ) )
{
if( addr != 0 )
{
// Ambiguous function name. Bail out.
ViewSource( fileName, line );
return;
}
else
{
addr = sym.first;
if( sym.second.isInline )
{
base = m_worker.GetSymbolForAddress( addr );
if( base == 0 )
{
addr = 0;
}
}
else
{
base = addr;
}
}
}
}
if( addr != 0 && base != 0 )
{
ViewSymbol( fileName, line, base, addr );
}
else
{
ViewSource( fileName, line );
}
}
void View::ViewSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr ) void View::ViewSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr )
{ {
assert( fileName || symAddr ); assert( fileName || symAddr );

View File

@ -112,6 +112,7 @@ public:
void NotifyRootWindowSize( float w, float h ) { m_rootWidth = w; m_rootHeight = h; } void NotifyRootWindowSize( float w, float h ) { m_rootWidth = w; m_rootHeight = h; }
void ViewSource( const char* fileName, int line ); void ViewSource( const char* fileName, int line );
void ViewSource( const char* fileName, int line, const char* functionName );
void ViewSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr ); void ViewSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr );
bool ViewDispatch( const char* fileName, int line, uint64_t symAddr ); bool ViewDispatch( const char* fileName, int line, uint64_t symAddr );