dingusdev / dingusppc

An experimental emulator
GNU General Public License v3.0
200 stars 21 forks source link

debugger: Gracefully exit upon EOF #94

Closed dressupgeekout closed 2 weeks ago

dressupgeekout commented 2 weeks ago

Typing "quit" isn't the only way to leave the REPL. This change prevents the REPL from spiralling in an endless loop when you hit ^D in the terminal.

Maybe there's a more C++-esque way of expressing what I'm trying to do here -- it works as expected on Linux, at least.

joevt commented 2 weeks ago

This fix behaves like typing quit at the dingusdbg> prompt. Without this fix, the dingusdbg> prompt gets output in an endless loop if the user types Control-D at the prompt.

I think the feof(stdin) check should be moved to before the cmd_repeat = cmd.empty() && !last_cmd.empty(); statement like this:

        if (feof(stdin)) {
            printf("eof -> quit\n");
            cmd = "quit";
        }

because feof(stdin) causes ss >> cmd to be empty which causes the last command to be repeated (if it was a command that is repeatable, such as si).

dingusdev commented 2 weeks ago

The fix was added with dingusdev/dingusppc@c0e28b81a8a2ab193e72a361bfe714153e3f1b6e