openMSX debugging using tcl commands

By jepmsx

Master (243)

jepmsx's picture

30-10-2021, 18:22

Hi!

I want to run the emulator step by step and store the command that is running in a file for every step.

If I do these two steps after the emulator is in breaked state:

debug step
disasm

and iterate over them, I've got the command that is going to be run in each moment.

But when I do:

for {set k 0} {$k<500} {incr k} {
        debug step;             # 
        save_to_file out${k}.txt [disasm]
    }

the different files have the same disasm output, always running the same step, like debug step didn't run, it doesn't advance step by step, it is stopped at the same instruction.

What am I doing wrong?

Login or register to post comments

By Grauw

Ascended (10720)

Grauw's picture

30-10-2021, 19:45

You need to suspend the TCL execution to let the emulator actually run. The emulation is halted during TCL execution.

Not sure if there's an easy way to do that, probably you'll need to build an asynchronous loop using breakpoints...

By jepmsx

Master (243)

jepmsx's picture

30-10-2021, 19:39

Oh, I see. The problem is not the script.

Thanks Grauw for your answer.

So I think the best approach is to use a socket for communicating with the openMSX to control it remotely as it is explained in https://openmsx.org/manual/openmsx-control.html. I'll try to do it

By wouter_

Champion (510)

wouter_'s picture

30-10-2021, 22:34

Grauw is right, when the Tcl script is executing MSX emulation is paused. You can trigger a Tcl callback after each instruction using 'debug conditions' (for more info execute help debug set_condition in the openMSX console).

Though if your goal is to get a trace of the executed instructions, then using the cputrace setting may be simpler.

By jepmsx

Master (243)

jepmsx's picture

31-10-2021, 08:07

It's been easier than I thought.

I've found the socket as it is explained in control openmsx in my /tmp/openMSX-user/socket.XXXX and with python I've done:

import socket

s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect('/tmp/openmsx-jep/socket.4828')
s.send(bytes("debug step","utf-8"))
s.send(bytes("save_to_file out.txt [disasm]","utf-8"))
s.close()

and I can control it without problem from python