diff --git a/TracyLua.hpp b/TracyLua.hpp index b3c18003..64e7c10b 100644 --- a/TracyLua.hpp +++ b/TracyLua.hpp @@ -118,8 +118,8 @@ static inline int LuaZoneBegin( lua_State* L ) lua_getinfo( L, "Snl", &dbg ); const uint32_t line = dbg.currentline; - const auto name = dbg.name ? dbg.name : dbg.short_src; - const auto fsz = strlen( name ); + const auto func = dbg.name ? dbg.name : dbg.short_src; + const auto fsz = strlen( func ); const auto ssz = strlen( dbg.source ); // Data layout: @@ -129,13 +129,14 @@ static inline int LuaZoneBegin( lua_State* L ) // fsz function name // 1b null terminator // ssz source file name - const uint32_t sz = 4 + 4 + 4 + fsz + 1 + ssz; + // 1b null terminator + const uint32_t sz = 4 + 4 + 4 + fsz + 1 + ssz + 1; auto ptr = (char*)tracy_malloc( sz ); memcpy( ptr, &sz, 4 ); memcpy( ptr + 4, &color, 4 ); memcpy( ptr + 8, &line, 4 ); - memcpy( ptr + 12, name, fsz+1 ); - memcpy( ptr + 12 + fsz + 1, dbg.source, ssz ); + memcpy( ptr + 12, func, fsz+1 ); + memcpy( ptr + 12 + fsz + 1, dbg.source, ssz + 1 ); Magic magic; auto& token = s_token.ptr; @@ -158,8 +159,10 @@ static inline int LuaZoneBeginN( lua_State* L ) lua_getinfo( L, "Snl", &dbg ); const uint32_t line = dbg.currentline; - const auto name = dbg.name ? dbg.name : dbg.short_src; - const auto fsz = strlen( name ); + const auto func = dbg.name ? dbg.name : dbg.short_src; + size_t nsz; + const auto name = lua_tolstring( L, 1, &nsz ); + const auto fsz = strlen( func ); const auto ssz = strlen( dbg.source ); // Data layout: @@ -169,13 +172,16 @@ static inline int LuaZoneBeginN( lua_State* L ) // fsz function name // 1b null terminator // ssz source file name - const uint32_t sz = 4 + 4 + 4 + fsz + 1 + ssz; + // 1b null terminator + // nsz zone name + const uint32_t sz = 4 + 4 + 4 + fsz + 1 + ssz + 1 + nsz; auto ptr = (char*)tracy_malloc( sz ); memcpy( ptr, &sz, 4 ); memcpy( ptr + 4, &color, 4 ); memcpy( ptr + 8, &line, 4 ); - memcpy( ptr + 12, name, fsz+1 ); - memcpy( ptr + 12 + fsz + 1, dbg.source, ssz ); + memcpy( ptr + 12, func, fsz+1 ); + memcpy( ptr + 12 + fsz + 1, dbg.source, ssz + 1 ); + memcpy( ptr + 12 + fsz + 1 + ssz + 1, name, nsz ); Magic magic; auto& token = s_token.ptr; diff --git a/server/TracyView.cpp b/server/TracyView.cpp index f3f7ef6a..db765907 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -1020,14 +1020,19 @@ void View::AddSourceLocationPayload( uint64_t ptr, char* data, size_t sz ) memcpy( &line, data + 4, 4 ); data += 8; auto end = data; - while( *end ) end++; + while( *end ) end++; const auto func = StoreString( data, end - data ); end++; - const auto ssz = sz - ( end - start ); - const auto source = StoreString( end, ssz ); - SourceLocation srcloc { StringRef(), StringRef( StringRef::Idx, func.idx ), StringRef( StringRef::Idx, source.idx ), line, color }; + data = end; + while( *end ) end++; + const auto source = StoreString( data, end - data ); + end++; + + const auto nsz = sz - ( end - start ); + + SourceLocation srcloc { nsz == 0 ? StringRef() : StringRef( StringRef::Idx, StoreString( end, nsz ).idx ), StringRef( StringRef::Idx, func.idx ), StringRef( StringRef::Idx, source.idx ), line, color }; auto it = m_sourceLocationPayloadMap.find( &srcloc ); if( it == m_sourceLocationPayloadMap.end() ) {