1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-27 15:43:23 +00:00

Dump Cobalt's internal state on timeouts

Closes #1180
This commit is contained in:
Jonathan Coates 2022-10-09 11:17:55 +01:00
parent cbfd83c2ba
commit 12b8a0393f
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
6 changed files with 46 additions and 5 deletions

View File

@ -141,7 +141,7 @@ accessTransformer file('src/testMod/resources/META-INF/accesstransformer.cfg')
extraModsCompileOnly fg.deobf("com.blamejared.crafttweaker:CraftTweaker-1.16.5:7.1.0.313")
extraModsCompileOnly fg.deobf("commoble.morered:morered-1.16.5:2.1.1.0")
shade 'org.squiddev:Cobalt:0.5.5'
shade 'org.squiddev:Cobalt:0.5.7'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.0'

View File

@ -625,6 +625,15 @@ else if( event != null )
}
}
void printState( StringBuilder out )
{
out.append( "Enqueued command: " ).append( command ).append( '\n' );
out.append( "Enqueued events: " ).append( eventQueue.size() ).append( '\n' );
ILuaMachine machine = this.machine;
if( machine != null ) machine.printExecutionState( out );
}
private void displayFailure( String message, String extra )
{
Terminal terminal = computer.getTerminal();

View File

@ -575,18 +575,22 @@ private void reportTimeout( ComputerExecutor executor, long time )
StringBuilder builder = new StringBuilder()
.append( "Terminating computer #" ).append( executor.getComputer().getID() )
.append( " due to timeout (running for " ).append( time * 1e-9 )
.append( " seconds). This is NOT a bug, but may mean a computer is misbehaving. " )
.append( " seconds). This is NOT a bug, but may mean a computer is misbehaving.\n" )
.append( "Thread " )
.append( owner.getName() )
.append( " is currently " )
.append( owner.getState() );
.append( owner.getState() )
.append( '\n' );
Object blocking = LockSupport.getBlocker( owner );
if( blocking != null ) builder.append( "\n on " ).append( blocking );
if( blocking != null ) builder.append( " on " ).append( blocking ).append( '\n' );
for( StackTraceElement element : owner.getStackTrace() )
{
builder.append( "\n at " ).append( element );
builder.append( " at " ).append( element ).append( '\n' );
}
executor.printState( builder );
ComputerCraft.log.warn( builder.toString() );
}
}

View File

@ -214,6 +214,20 @@ public MachineResult handleEvent( String eventName, Object[] arguments )
}
}
@Override
public void printExecutionState( StringBuilder out )
{
LuaState state = this.state;
if( state == null )
{
out.append( "CobaltLuaMachine is terminated\n" );
}
else
{
state.printExecutionState( out );
}
}
@Override
public void close()
{

View File

@ -61,6 +61,15 @@ public interface ILuaMachine
*/
MachineResult handleEvent( @Nullable String eventName, @Nullable Object[] arguments );
/**
* Print some information about the internal execution state.
* <p>
* This function is purely intended for debugging, its output should not be relied on in any way.
*
* @param out The buffer to write to.
*/
void printExecutionState( StringBuilder out );
/**
* Close the Lua machine, aborting any running functions and deleting the internal state.
*/

View File

@ -211,6 +211,11 @@ public MachineResult handleEvent( @Nullable String eventName, @Nullable Object[]
}
}
@Override
public void printExecutionState( StringBuilder out )
{
}
@Override
public void close()
{