mamedev / mame

MAME
https://www.mamedev.org/
Other
7.95k stars 1.98k forks source link

Not possible to reconnect to gdbstub #9578

Open maziac opened 2 years ago

maziac commented 2 years ago

I'm working on a vscode extension to attach to MAME though the MAME gdbstub. I.e. I start MAME with

./mame -window  <some-rom> -debugger gdbstub -debug -debugger_port 12000 -verbose

MAME version is: 0.242 (on macOS)

I can connect to the gdbstub and execute commands. That is working fine. But as soon as I close the connection it is not possible to re-open it again. To do so I have to terminate MAME and restart it again.

It would be more helpful if after closing the connection it would be possible to connect once again. E.g. a debugger frontend could close and re-open a session. The way it is implemented currently requires that MAME is shutdown/re-opened every time.

To reproduce, simply use telnet to connect. Use the above command to start MAME, then in another terminal enter:

% telnet
telnet> open localhost 12000
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
^]
telnet> close
Connection closed.
telnet> open localhost 12000
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
telnet> 

As can be seen the 2nd connection attempt fails.

ramiropolla commented 1 month ago

Hi @maziac,

Could you write an example on how to reproduce this with VS Code? I'd like to check how it interacts with gdbstub so that I can support it.

Regards, Ramiro

holub commented 1 month ago

Hi @maziac,

Could you write an example on how to reproduce this with VS Code? I'd like to check how it interacts with gdbstub so that I can support it.

Regards, Ramiro

Does this help? https://github.com/maziac/z80-sample-program?tab=readme-ov-file#debug-with-mame

maziac commented 1 month ago

Wow, 2 years response time :-)

You don't need vscode. You can just open/close a connection with telnet, without sending any command.

ramiropolla commented 1 month ago

Wow, 2 years response time :-)

I get the issues through Morse Code on ticker tape, it takes a while to decode them :P

You don't need vscode. You can just open/close a connection with telnet, without sending any command.

I'm interested in knowing how frontends expect to reconnect. Do they expect to send the k command and reconnect again? Should MAME pause and wait for a new connection before continuing? Should MAME continue execution normally and listen for a new connection on the background? Should MAME reset the system on reconnect, or is the frontend responsible for that?

maziac commented 1 month ago

I would simply like to continue where I left off before the disconnect.

"Do they expect to send the k command and reconnect again?" -> dezog sends the k command as a workaround. Otherwise there is no need to send it. "Should MAME pause and wait for a new connection before continuing?" "Should MAME continue execution normally and listen for a new connection on the background?" -> Actually the other emulators just go on running the emulated game when the connection terminates. However, it does not matter. On the next connection everything will be setup/re-initialized as the first time. "Should MAME reset the system on reconnect, or is the frontend responsible for that?" -> Is a difficult question. The other emulators don't do that. But in their use cases the software is sent from dezog to the emulator and dezogs sets the PC to execute it. In MAME the scenario is different and probably we need to distinguish the reverse engineering use case from the original software development use case. But even for the rev-engineering use case it is probably enough that dezog resets the PC to 0x0000. (dezog is Z80 only and here I guess the world is often that simple.)