mirror of
https://github.com/wolfpld/tracy
synced 2025-04-29 20:33:52 +00:00
make sure we always copy the image name in ImageCache
This commit is contained in:
parent
15f1b6b0b4
commit
ab1ec3f01c
@ -107,12 +107,9 @@ class ImageCache
|
|||||||
public:
|
public:
|
||||||
struct ImageEntry
|
struct ImageEntry
|
||||||
{
|
{
|
||||||
ImageEntry( void* startAddress, void* endAddress, const char* name )
|
void* m_startAddress = nullptr;
|
||||||
: m_startAddress( startAddress ), m_endAddress( endAddress ), m_name( name ) {}
|
void* m_endAddress = nullptr;
|
||||||
|
char* m_name = nullptr;
|
||||||
void* m_startAddress;
|
|
||||||
void* m_endAddress;
|
|
||||||
const char* m_name;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ImageCache()
|
ImageCache()
|
||||||
@ -125,10 +122,10 @@ public:
|
|||||||
|
|
||||||
~ImageCache()
|
~ImageCache()
|
||||||
{
|
{
|
||||||
|
Clear();
|
||||||
|
|
||||||
m_images->~FastVector<ImageEntry>();
|
m_images->~FastVector<ImageEntry>();
|
||||||
tracy_free( m_images );
|
tracy_free( m_images );
|
||||||
|
|
||||||
tracy_free( m_imageName );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ImageEntry* GetImageForAddress( void* address )
|
const ImageEntry* GetImageForAddress( void* address )
|
||||||
@ -145,7 +142,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
tracy::FastVector<ImageEntry>* m_images;
|
tracy::FastVector<ImageEntry>* m_images;
|
||||||
char* m_imageName = nullptr;
|
|
||||||
|
|
||||||
static int Callback( struct dl_phdr_info* info, size_t size, void* data )
|
static int Callback( struct dl_phdr_info* info, size_t size, void* data )
|
||||||
{
|
{
|
||||||
@ -158,25 +154,30 @@ private:
|
|||||||
image->m_endAddress = reinterpret_cast<void*>( info->dlpi_addr +
|
image->m_endAddress = reinterpret_cast<void*>( info->dlpi_addr +
|
||||||
info->dlpi_phdr[info->dlpi_phnum - 1].p_vaddr + info->dlpi_phdr[info->dlpi_phnum - 1].p_memsz);
|
info->dlpi_phdr[info->dlpi_phnum - 1].p_vaddr + info->dlpi_phdr[info->dlpi_phnum - 1].p_memsz);
|
||||||
|
|
||||||
// the base executable name isn't provided when iterating with dl_iterate_phdr,
|
const char* imageName = nullptr;
|
||||||
// so we must get it in an alternative way and cache it
|
// the base executable name isn't provided when iterating with dl_iterate_phdr, get it with dladdr()
|
||||||
if( info->dlpi_name && info->dlpi_name[0] != '\0' )
|
if( info->dlpi_name && info->dlpi_name[0] != '\0' )
|
||||||
{
|
{
|
||||||
image->m_name = info->dlpi_name;
|
imageName = info->dlpi_name;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if( !cache->m_imageName )
|
|
||||||
{
|
{
|
||||||
Dl_info dlInfo;
|
Dl_info dlInfo;
|
||||||
if( dladdr( (void *)info->dlpi_addr, &dlInfo ) )
|
if( dladdr( (void *)info->dlpi_addr, &dlInfo ) )
|
||||||
{
|
{
|
||||||
size_t sz = strlen( dlInfo.dli_fname ) + 1;
|
imageName = dlInfo.dli_fname;
|
||||||
cache->m_imageName = (char*)tracy_malloc( sz );
|
|
||||||
memcpy( (void*)cache->m_imageName, dlInfo.dli_fname, sz );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
image->m_name = cache->m_imageName;
|
|
||||||
|
if(imageName != nullptr)
|
||||||
|
{
|
||||||
|
size_t sz = strlen( imageName ) + 1;
|
||||||
|
image->m_name = (char*)tracy_malloc( sz );
|
||||||
|
memcpy( (void*)image->m_name, imageName, sz );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
image->m_name = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -184,7 +185,7 @@ private:
|
|||||||
|
|
||||||
void Refresh()
|
void Refresh()
|
||||||
{
|
{
|
||||||
m_images->clear();
|
Clear();
|
||||||
|
|
||||||
dl_iterate_phdr( Callback, this );
|
dl_iterate_phdr( Callback, this );
|
||||||
|
|
||||||
@ -203,6 +204,16 @@ private:
|
|||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Clear()
|
||||||
|
{
|
||||||
|
for( ImageEntry& entry : *m_images )
|
||||||
|
{
|
||||||
|
tracy_free( entry.m_name );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_images->clear();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
#endif //#ifdef TRACY_USE_IMAGE_CACHE
|
#endif //#ifdef TRACY_USE_IMAGE_CACHE
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user