mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 08:04:26 +01:00
plugins: allow --dev-debugger=<pluginname>.
This currently just invokes GDB, but we could generalize it (though pdb doesn't allow attaching to a running process, other python debuggers seem to). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <ccan/err/err.h>
|
||||
#include <ccan/io/io.h>
|
||||
#include <ccan/str/str.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <common/daemon.h>
|
||||
#include <common/memleak.h>
|
||||
#include <common/status.h>
|
||||
@@ -150,3 +151,23 @@ void daemon_shutdown(void)
|
||||
tal_free(tmpctx);
|
||||
wally_cleanup(0);
|
||||
}
|
||||
|
||||
void daemon_maybe_debug(int argc, char *argv[])
|
||||
{
|
||||
#if DEVELOPER
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (!streq(argv[i], "--debugger"))
|
||||
continue;
|
||||
|
||||
/* Don't let this mess up stdout, so redir to /dev/null */
|
||||
char *cmd = tal_fmt(NULL, "${DEBUG_TERM:-gnome-terminal --} gdb -ex 'attach %u' %s >/dev/null &", getpid(), argv[0]);
|
||||
fprintf(stderr, "Running %s\n", cmd);
|
||||
/* warn_unused_result is fascist bullshit.
|
||||
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 */
|
||||
if (system(cmd))
|
||||
;
|
||||
/* Continue in the debugger. */
|
||||
kill(getpid(), SIGSTOP);
|
||||
}
|
||||
#endif /* DEVELOPER */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user