Function to run scsynth in gdb

Here’s a function I didn’t expect to need to write:

(
~bootServerInGdb = { |server(Server.default)|
	var p = Server.program, newp;
	if(server === Server.internal) {
		Error("Cannot run internal server in gdb").throw;
	};
	if(thisProcess.platform.name == \windows) {
		if(p.contains("gdb").not) {
			newp = "gdb --eval-command=run --args " ++ p;
		};
	} {
		if(p.contains("exec")) {
			newp = p.replace("exec ", "gdb --eval-command=run --args ");
		} {
			if(p.contains("gdb").not) {
				"Server.program did not contain expected keyword \"exec\"".warn;
			};
		};
	};
	Server.program = newp;
	fork {
		var watcher, cond = CondVar.new;
		server.bootInTerminal;
		server.startAliveThread;
		watcher = SimpleController(server)
		.put(\serverRunning, {
			if(server.serverRunning) {
				watcher.remove;
				cond.signalAll;
			}
		});
		cond.waitFor(20.0);
		if(server.serverRunning) {
			server.connectSharedMemory;
		} {
			"Server didn't respond within 20 seconds".warn;
		};
		Server.program = p;
	};
};
)

The context is that the server crashed on me twice within about 48 hours – not typical behavior (no idea why – the first time I thought it might have been the DWG UGens in sc3-plugins, but the second time, I wasn’t using any of those). I don’t know when it will happen again, so the only way to be ready is to run the server under gdb all the time. That’s just inconvenient enough to do manually that it was worth automating.

hjh

1 Like