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:
Rusty Russell
2018-12-08 11:00:56 +10:30
parent b484933b40
commit 6323cc1898
11 changed files with 60 additions and 34 deletions

View File

@@ -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 */
}