2019-10-14 14:00 EDT


View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0002674FSSCPscriptingpublic2012-07-15 11:54
Reporterm_m 
Assigned Tom_m 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
Product Version3.6.13 
Target Version3.6.13Fixed in Version3.6.13 
Summary0002674: Lua Debug Call stacks are incomplete when too long
DescriptionWhen an error happens inside a lua script and the stack is longer than four functions calls then some call stack information is dropped because the scripting system can only hold four different call locations at a time.
The attached patch fixes that behavior by using the built-in debug.traceback function which has given very good results. If the debug library (for what reason ever) isn't available then the call stack is generated using the old way.
TagsNo tags attached.
Attached Files
  • patch file icon luaCallStack.patch (1,253 bytes) 2012-06-27 12:19 -
    Index: code/globalincs/windebug.cpp
    ===================================================================
    --- code/globalincs/windebug.cpp	(revision 8916)
    +++ code/globalincs/windebug.cpp	(working copy)
    @@ -1105,12 +1105,35 @@
     
     	AssertText2[0] = '\0';
     	dumpBuffer.Printf(Separator);
    -	dumpBuffer.Printf("LUA Stack:\r\n");
    -	int i;
    -	for (i = 0; i < 4; i++) {
    -		if (debug_stack[i][0] != '\0')
    -			dumpBuffer.Printf("\t%s\r\n", debug_stack[i]);
    +	
    +	// Get the stack via the debug.traceback() function
    +	lua_getglobal(L, LUA_DBLIBNAME);
    +
    +	if (!lua_isnil(L, -1))
    +	{
    +		dumpBuffer.Printf( "\r\n" );
    +		lua_getfield(L, -1, "traceback");
    +		lua_remove(L, -2);
    +
    +		if (lua_pcall(L, 0, 1, 0) != 0)
    +			dumpBuffer.Printf("Error while retrieving stack: %s", lua_tostring(L, -1));
    +		else
    +			dumpBuffer.Printf(lua_tostring(L, -1));
    +
    +		lua_pop(L, 1);
     	}
    +	else
    +	{
    +		// If the debug library is nil then fall back to the default debug stack
    +		dumpBuffer.Printf("LUA Stack:\r\n");
    +		int i;
    +		for (i = 0; i < 4; i++) {
    +			if (debug_stack[i][0] != '\0')
    +				dumpBuffer.Printf("\t%s\r\n", debug_stack[i]);
    +		}
    +	}
    +	dumpBuffer.Printf( "\r\n" );
    +
     	dumpBuffer.Printf(Separator);
     	ade_stackdump(L, AssertText2);
     	dumpBuffer.Printf( AssertText2 );
    
    patch file icon luaCallStack.patch (1,253 bytes) 2012-06-27 12:19 +

-Relationships
+Relationships

-Notes

~0013866

Echelon9 (developer)

Committed to trunk, revision 9016.

Thanks for the useful patch.
+Notes

-Issue History
Date Modified Username Field Change
2012-06-27 12:19 m_m New Issue
2012-06-27 12:19 m_m Status new => assigned
2012-06-27 12:19 m_m Assigned To => m_m
2012-06-27 12:19 m_m File Added: luaCallStack.patch
2012-06-27 12:19 m_m Status assigned => feedback
2012-06-27 12:20 m_m Status feedback => code review
2012-07-15 11:54 Echelon9 Note Added: 0013866
2012-07-15 11:54 Echelon9 Status code review => resolved
2012-07-15 11:54 Echelon9 Fixed in Version => 3.6.13
2012-07-15 11:54 Echelon9 Resolution open => fixed
+Issue History