MCPcopy Create free account
hub / github.com/Overload-Technologies/Overload / SendLuaCallstack

Function SendLuaCallstack

Dependencies/tracy/tracy/TracyLua.hpp:147–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145
146#ifdef TRACY_HAS_CALLSTACK
147static tracy_force_inline void SendLuaCallstack( lua_State* L, uint32_t depth )
148{
149 assert( depth <= 64 );
150 lua_Debug dbg[64];
151 const char* func[64];
152 uint32_t fsz[64];
153 uint32_t ssz[64];
154
155 uint8_t cnt;
156 uint16_t spaceNeeded = sizeof( cnt );
157 for( cnt=0; cnt<depth; cnt++ )
158 {
159 if( lua_getstack( L, cnt+1, dbg+cnt ) == 0 ) break;
160 lua_getinfo( L, "Snl", dbg+cnt );
161 func[cnt] = dbg[cnt].name ? dbg[cnt].name : dbg[cnt].short_src;
162 fsz[cnt] = uint32_t( strlen( func[cnt] ) );
163 ssz[cnt] = uint32_t( strlen( dbg[cnt].source ) );
164 spaceNeeded += fsz[cnt] + ssz[cnt];
165 }
166 spaceNeeded += cnt * ( 4 + 2 + 2 ); // source line, function string length, source string length
167
168 auto ptr = (char*)tracy_malloc( spaceNeeded + 2 );
169 auto dst = ptr;
170 memcpy( dst, &spaceNeeded, 2 ); dst += 2;
171 memcpy( dst, &cnt, 1 ); dst++;
172 for( uint8_t i=0; i<cnt; i++ )
173 {
174 const uint32_t line = dbg[i].currentline;
175 memcpy( dst, &line, 4 ); dst += 4;
176 assert( fsz[i] <= (std::numeric_limits<uint16_t>::max)() );
177 memcpy( dst, fsz+i, 2 ); dst += 2;
178 memcpy( dst, func[i], fsz[i] ); dst += fsz[i];
179 assert( ssz[i] <= (std::numeric_limits<uint16_t>::max)() );
180 memcpy( dst, ssz+i, 2 ); dst += 2;
181 memcpy( dst, dbg[i].source, ssz[i] ), dst += ssz[i];
182 }
183 assert( dst - ptr == spaceNeeded + 2 );
184
185 TracyQueuePrepare( QueueType::CallstackAlloc );
186 MemWrite( &item->callstackAllocFat.ptr, (uint64_t)ptr );
187 MemWrite( &item->callstackAllocFat.nativePtr, (uint64_t)Callstack( depth ) );
188 TracyQueueCommit( callstackAllocFatThread );
189}
190
191static inline void LuaShortenSrc( char* dst, const char* src )
192{

Callers 2

LuaZoneBeginSFunction · 0.85
LuaZoneBeginNSFunction · 0.85

Calls 5

lua_getstackFunction · 0.85
lua_getinfoFunction · 0.85
tracy_mallocFunction · 0.85
MemWriteFunction · 0.85
CallstackFunction · 0.85

Tested by

no test coverage detected