Skip to content

Commit 60fcfac

Browse files
committed
local: KNDEBUG hook to attach a debugger to a running replica
If the KNDEBUG environment variable is set, PlumedMain's constructor spins on a volatile flag so you can attach a debugger to an already-running MD job and then release it by flipping holdToDebug from the debugger. Inert otherwise: one getenv and one branch. Not upstreamable in this form -- an unbounded sleep loop in a library constructor is not something PLUMED would accept, and the commented-out `simulationIndex > 0` condition shows it was meant to be replica-specific. A polished version (documented, bounded timeout, opt-in at configure time) could be proposed separately.
1 parent 064731d commit 60fcfac

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/core/PlumedMain.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include <optional>
6868
#include <variant>
6969
#include <filesystem>
70+
#include <unistd.h>
7071

7172
namespace PLMD {
7273

@@ -289,6 +290,19 @@ PlumedMain::PlumedMain():
289290
stopwatch_fwd(log),
290291
actionSet_fwd(*this),
291292
passtools(DataPassingTools::create(sizeof(double))) {
293+
294+
bool debug = false;
295+
const char* debug_val = std::getenv("KNDEBUG");
296+
if (debug_val != nullptr) {
297+
debug = true;
298+
}
299+
300+
volatile bool holdToDebug = true;
301+
while (/*simulationIndex > 0 &&*/ debug && holdToDebug) {
302+
sleep(1);
303+
}
304+
305+
292306
passtools->usingNaturalUnits=false;
293307
increaseReferenceCounter();
294308
log.link(comm);

0 commit comments

Comments
 (0)