jingoro2112 / wrench

practical embedded script interpreter
MIT License
106 stars 9 forks source link

WRD_DebugOut breaks code debugging #43

Open darksotmoon opened 3 months ago

darksotmoon commented 3 months ago

Test script

debug::print("debug out");
str::printf("end");

The first single step will stop on line 1 as expected. Client sends WRD_RequestStepInto, server executes script and sends back WRD_Ok.

Then the next single step will fail. What happens is that the client WRDebugClientInterfacePrivate::trapRunOutput will send WRD_RequestStepInto, then the server executes the code, which involves sending back WRD_DebugOut then WRD_Ok.

WRDebugClientInterfacePrivate::trapRunOutput will receive WRD_DebugOut in the loop and then send the WRD_RequestStepInto again. The server executes this and sends back WRD_Ok so the client ends up with three WRD_Ok replies. Not sure where the third WRD_Ok comes from.

The problem is that WRDebugClientInterfacePrivate::transmit is really transmit_receive so it can't receive two packets ( WRD_DebugOut then WRD_Ok) without transmitting again.

I renamed transmit to transmit_receive and then added transmit and receive functions. Then WRDebugClientInterfacePrivate::trapRunOutput looks like:

if(transmit( WrenchPacketScoped(WrenchPacket::alloc(packet)) ))
{
    bool done = false;
    while(!done)
    {
        WrenchPacket *reply = receive();
        if(reply)
        {
            if( reply->_type == WRD_DebugOut )
            {
                printf( "%s", (char*)reply->payload() );
            }
            else
                done = true;
            g_free( reply );
        }
    }
}
jingoro2112 commented 3 months ago

okay I'll look into this as soon as I can, but I am off for the week :)

On Tue, Jul 2, 2024 at 10:23 PM darksotmoon @.***> wrote:

Test script

debug::print("debug out"); str::printf("end");

The first single step will stop on line 1 as expected. Client sends WRD_RequestStepInto, server executes script and sends back WRD_Ok.

Then the next single step will fail. What happens is that the client WRDebugClientInterfacePrivate::trapRunOutput will send WRD_RequestStepInto, then the server executes the code, which involves sending back WRD_DebugOut then WRD_Ok.

WRDebugClientInterfacePrivate::trapRunOutput will receive WRD_DebugOut in the loop and then send the WRD_RequestStepInto again. The server executes this and sends back WRD_Ok so the client ends up with three WRD_Ok replies. Not sure where the third WRD_Ok comes from.

The problem is that WRDebugClientInterfacePrivate::transmit is really transmit_receive so it can't receive two packets ( WRD_DebugOut then WRD_Ok) without transmitting again.

I renamed transmit to transmit_receive and then added transmit and receive functions. Then WRDebugClientInterfacePrivate::trapRunOutput looks like:

if(transmit( WrenchPacketScoped(WrenchPacket::alloc(packet)) )) { bool done = false; while(!done) { WrenchPacket reply = receive(); if(reply) { if( reply->_type == WRD_DebugOut ) { printf( "%s", (char)reply->payload() ); } else done = true; g_free( reply ); } } }

— Reply to this email directly, view it on GitHub https://github.com/jingoro2112/wrench/issues/43, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALIKAZ7I2SGJYPSA5FLI7LZKNOANAVCNFSM6AAAAABKIUGZJCVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM4DONBZGU2TANQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>