mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-22 22:44:34 +00:00
- Fix formatting
- delete CreateResolver/DestroySymbolResolver
This commit is contained in:
parent
687d681764
commit
5c0513931a
@ -24,21 +24,15 @@ bool ApplyPathSubstitutions(std::string& path, const PathSubstitutionList& pathS
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: use string hash map to reduce duplication or use some worker string internal hashing
|
||||
tracy::StringIdx AddSymbolString(tracy::Worker& worker, const char* str)
|
||||
tracy::StringIdx AddSymbolString( tracy::Worker& worker, const std::string& str )
|
||||
{
|
||||
uint32_t newStringIdx = worker.AddNewString( str );
|
||||
return tracy::StringIdx( newStringIdx );
|
||||
// TODO: use string hash map to reduce potential string duplication?
|
||||
tracy::StringLocation location = worker.StoreString( str.c_str(), str.length() );
|
||||
return tracy::StringIdx( location.idx );
|
||||
}
|
||||
|
||||
bool PatchSymbols(SymbolResolver* resolver, tracy::Worker& worker,
|
||||
const PathSubstitutionList& pathSubstituionlist, bool verbose)
|
||||
bool PatchSymbols( tracy::Worker& worker, const PathSubstitutionList& pathSubstituionlist, bool verbose )
|
||||
{
|
||||
if( !resolver )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t callstackFrameCount = worker.GetCallstackFrameCount();
|
||||
std::string relativeSoNameMatch = "[unresolved]";
|
||||
|
||||
@ -89,10 +83,8 @@ bool PatchSymbols(SymbolResolver* resolver, tracy::Worker& worker,
|
||||
std::string imagePath = worker.GetString( imageIdx );
|
||||
|
||||
FrameEntryList& entries = imageIt->second;
|
||||
if (!entries.size())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if( !entries.size() ) continue;
|
||||
|
||||
std::cout << "Resolving " << entries.size() << " symbols for image: '"
|
||||
<< imagePath << "'" << std::endl;
|
||||
@ -103,7 +95,7 @@ bool PatchSymbols(SymbolResolver* resolver, tracy::Worker& worker,
|
||||
}
|
||||
|
||||
SymbolEntryList resolvedEntries;
|
||||
ResolveSymbols( resolver, imagePath, entries, resolvedEntries );
|
||||
ResolveSymbols( imagePath, entries, resolvedEntries );
|
||||
|
||||
if( resolvedEntries.size() != entries.size() )
|
||||
{
|
||||
@ -119,10 +111,8 @@ bool PatchSymbols(SymbolResolver* resolver, tracy::Worker& worker,
|
||||
const SymbolEntry& symbolEntry = resolvedEntries[i];
|
||||
|
||||
tracy::CallstackFrame& frame = *frameEntry.frame;
|
||||
if (!symbolEntry.name.length())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if( !symbolEntry.name.length() ) continue;
|
||||
|
||||
if( verbose )
|
||||
{
|
||||
@ -131,12 +121,12 @@ bool PatchSymbols(SymbolResolver* resolver, tracy::Worker& worker,
|
||||
<< "' -> '" << symbolEntry.name << "'" << std::endl;
|
||||
}
|
||||
|
||||
frame.name = AddSymbolString( worker, symbolEntry.name.c_str() );
|
||||
frame.name = AddSymbolString( worker, symbolEntry.name );
|
||||
const char* newName = worker.GetString( frame.name );
|
||||
|
||||
if( symbolEntry.file.length() )
|
||||
{
|
||||
frame.file = AddSymbolString( worker, symbolEntry.file.c_str() );
|
||||
frame.file = AddSymbolString( worker, symbolEntry.file );
|
||||
frame.line = symbolEntry.line;
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,6 @@ namespace tracy
|
||||
class Worker;
|
||||
}
|
||||
|
||||
class SymbolResolver;
|
||||
|
||||
SymbolResolver* CreateResolver();
|
||||
void DestroySymbolResolver(SymbolResolver* resolver);
|
||||
|
||||
struct FrameEntry
|
||||
{
|
||||
tracy::CallstackFrame* frame = nullptr;
|
||||
@ -33,13 +28,11 @@ struct SymbolEntry
|
||||
|
||||
using SymbolEntryList = std::vector<SymbolEntry>;
|
||||
|
||||
bool ResolveSymbols(SymbolResolver* resolver, const std::string& imagePath,
|
||||
const FrameEntryList& inputEntryList,
|
||||
bool ResolveSymbols( const std::string& imagePath, const FrameEntryList& inputEntryList,
|
||||
SymbolEntryList& resolvedEntries );
|
||||
|
||||
using PathSubstitutionList = std::vector<std::pair<std::regex, std::string> >;
|
||||
|
||||
bool PatchSymbols(SymbolResolver* resolver, tracy::Worker& worker,
|
||||
const PathSubstitutionList& pathSubstituionlist, bool verbose = false);
|
||||
bool PatchSymbols( tracy::Worker& worker, const PathSubstitutionList& pathSubstituionlist, bool verbose = false );
|
||||
|
||||
#endif // __SYMBOLRESOLVER_HPP__
|
@ -30,12 +30,25 @@ class SymbolResolver
|
||||
{
|
||||
public:
|
||||
SymbolResolver( const std::string& addr2linePath )
|
||||
: m_addr2LinePath(addr2linePath)
|
||||
{}
|
||||
{
|
||||
std::stringstream result(ExecShellCommand("which addr2line"));
|
||||
std::getline(result, m_addr2LinePath);
|
||||
|
||||
if( !m_addr2LinePath.length() )
|
||||
{
|
||||
std::cerr << "'addr2line' was not found in the system, please installed it" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Using 'addr2line' found at: '" << m_addr2LinePath.c_str() << "'" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
bool ResolveSymbols( const std::string& imagePath, const FrameEntryList& inputEntryList,
|
||||
SymbolEntryList& resolvedEntries )
|
||||
{
|
||||
if (!m_addr2LinePath.length()) return false;
|
||||
|
||||
// generate a single addr2line cmd line for all addresses in one invocation
|
||||
std::stringstream ss;
|
||||
ss << m_addr2LinePath << " -C -f -e " << imagePath << " -a ";
|
||||
@ -91,34 +104,11 @@ private:
|
||||
std::string m_addr2LinePath;
|
||||
};
|
||||
|
||||
SymbolResolver* CreateResolver()
|
||||
bool ResolveSymbols( const std::string& imagePath, const FrameEntryList& inputEntryList,
|
||||
SymbolEntryList& resolvedEntries )
|
||||
{
|
||||
std::stringstream result( ExecShellCommand("which addr2line") );
|
||||
std::string addr2LinePath;
|
||||
std::getline( result, addr2LinePath );
|
||||
|
||||
if(!addr2LinePath.length())
|
||||
{
|
||||
std::cerr << "'addr2line' was not found in the system, please installed it" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
std::cout << "Using 'addr2line' found at: '" << addr2LinePath.c_str() << "'" << std::endl;
|
||||
return new SymbolResolver{addr2LinePath};
|
||||
}
|
||||
|
||||
void DestroySymbolResolver(SymbolResolver* resolver)
|
||||
{
|
||||
delete resolver;
|
||||
}
|
||||
|
||||
bool ResolveSymbols(SymbolResolver* resolver, const std::string& imagePath,
|
||||
const FrameEntryList& inputEntryList, SymbolEntryList& resolvedEntries)
|
||||
{
|
||||
if (resolver)
|
||||
{
|
||||
return resolver->ResolveSymbols( imagePath, inputEntryList, resolvedEntries );
|
||||
}
|
||||
return false;
|
||||
static SymbolResolver symbolResolver;
|
||||
return symbolResolver.ResolveSymbols( imagePath, inputEntryList, resolvedEntries );
|
||||
}
|
||||
|
||||
#endif // #ifndef _WIN32
|
@ -29,8 +29,9 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
const DWORD symopts = SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_DEBUG | SYMOPT_LOAD_LINES;
|
||||
const DWORD symopts = SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_LOAD_LINES;
|
||||
SymSetOptions( symopts );
|
||||
m_dbgHelpInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,6 +43,8 @@ public:
|
||||
bool ResolveSymbolsForModule( const std::string& imagePath, const FrameEntryList& inputEntryList,
|
||||
SymbolEntryList& resolvedEntries )
|
||||
{
|
||||
if( !m_dbgHelpInitialized ) return false;
|
||||
|
||||
ULONG64 moduleBase = SymLoadModuleEx( m_procHandle, NULL, imagePath.c_str(), NULL, 0, 0, NULL, 0 );
|
||||
if( !moduleBase )
|
||||
{
|
||||
@ -111,32 +114,17 @@ private:
|
||||
return message;
|
||||
}
|
||||
|
||||
bool m_dbgHelpInitialized = false;
|
||||
HANDLE m_procHandle = nullptr;
|
||||
};
|
||||
|
||||
char SymbolResolver::s_symbolResolutionBuffer[symbolResolutionBufferSize];
|
||||
|
||||
|
||||
SymbolResolver* CreateResolver()
|
||||
{
|
||||
SymbolResolver* resolver = new SymbolResolver();
|
||||
return resolver;
|
||||
}
|
||||
|
||||
void DestroySymbolResolver(SymbolResolver* resolver)
|
||||
{
|
||||
delete resolver;
|
||||
}
|
||||
|
||||
bool ResolveSymbols(SymbolResolver* resolver, const std::string& imagePath,
|
||||
const FrameEntryList& inputEntryList,
|
||||
bool ResolveSymbols( const std::string& imagePath, const FrameEntryList& inputEntryList,
|
||||
SymbolEntryList& resolvedEntries )
|
||||
{
|
||||
if( resolver )
|
||||
{
|
||||
return resolver->ResolveSymbolsForModule( imagePath, inputEntryList, resolvedEntries );
|
||||
}
|
||||
return false;
|
||||
static SymbolResolver resolver;
|
||||
return resolver.ResolveSymbolsForModule( imagePath, inputEntryList, resolvedEntries );
|
||||
}
|
||||
|
||||
#endif // #ifdef _WIN32
|
@ -206,15 +206,8 @@ void PatchSymbols(tracy::Worker& worker, const Args& args)
|
||||
}
|
||||
}
|
||||
|
||||
SymbolResolver* resolver = CreateResolver();
|
||||
if (resolver)
|
||||
if( !PatchSymbols( worker, pathSubstitutionList, args.verbose ) )
|
||||
{
|
||||
PatchSymbols(resolver, worker, pathSubstitutionList, args.verbose);
|
||||
|
||||
DestroySymbolResolver(resolver);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Failed to create symbol resolver - skipping resolving" << std::endl;
|
||||
std::cerr << "Failed to patch symbols" << std::endl;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user