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