pyln-testing: use DEBUG_LIGHTNINGD to start gdb on lightningd during test.

We do this for DEBUG_SUBD already, but I wanted to debug the main lightningd.

(We rename --debugger to the more accurate --dev-debug-self)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-03-19 14:59:59 +10:30
parent 4a9b9b8b29
commit 7af045df4e
9 changed files with 26 additions and 8 deletions

View File

@ -196,7 +196,7 @@ bool daemon_developer_mode(char *argv[])
bool developer = false, debug = false;
for (int i = 1; argv[i]; i++) {
if (streq(argv[i], "--debugger"))
if (streq(argv[i], "--dev-debug-self"))
debug = true;
else if (streq(argv[i], "--developer"))
developer = true;

View File

@ -22,7 +22,7 @@ const char *backtrace_symname(const tal_t *ctx, const void *addr);
void daemon_shutdown(void);
/* If --developer is set, set up extra developer checks, kick in a
* debugger if they set --debugger, and return true. */
* debugger if they set --dev-debug-self, and return true. */
bool daemon_developer_mode(char *argv[]);
#endif /* LIGHTNING_COMMON_DAEMON_H */

View File

@ -789,6 +789,8 @@ class LightningNode(object):
self.daemon.opts["dev-no-version-checks"] = None
if os.getenv("DEBUG_SUBD"):
self.daemon.opts["dev-debugger"] = os.getenv("DEBUG_SUBD")
if os.getenv("DEBUG_LIGHTNINGD"):
self.daemon.opts["dev-debug-self"] = None
if valgrind:
self.daemon.env["LIGHTNINGD_DEV_NO_BACKTRACE"] = "1"
self.daemon.opts["dev-no-plugin-checksum"] = None

View File

@ -41,7 +41,7 @@ There are four kinds of tests:
`PYTHONPATH=contrib/pyln-client:contrib/pyln-testing:contrib/pyln-proto:contrib/pyln-grpc-proto py.test -v tests/`
You can also append `-k TESTNAME` to run a single test. Environment variables `DEBUG_SUBD=<subdaemon>` and `TIMEOUT=<seconds>` can be useful for debugging subdaemons on individual tests.
You can also append `-k TESTNAME` to run a single test. Environment variables `DEBUG_SUBD=<subdaemon>` and `TIMEOUT=<seconds>` can be useful for debugging subdaemons on individual tests, and `DEBUG_LIGHTNINGD` for attaching a debugger to each `lightningd` instance created.
- **pylightning tests** - will check contrib pylightning for codestyle and run the tests in `contrib/pylightning/tests` afterwards:

View File

@ -1068,6 +1068,12 @@ int main(int argc, char *argv[])
trace_span_start("lightningd/startup", argv);
/*~ What happens in strange locales should stay there. */
setup_locale();
/*~ This handles --dev-debug-self really early, which we otherwise ignore */
daemon_developer_mode(argv);
/*~ We fork out new processes very very often; every channel gets its
* own process, for example, and we have `hsmd` and `gossipd` and
* the plugins as well.
@ -1106,9 +1112,6 @@ int main(int argc, char *argv[])
*/
closefrom_limit(4096);
/*~ What happens in strange locales should stay there. */
setup_locale();
/*~ This sets up SIGCHLD to make sigchld_rfd readable. */
sigchld_rfd = setup_sig_handlers();

View File

@ -784,6 +784,11 @@ static char *opt_force_featureset(const char *optarg,
return NULL;
}
static char *opt_ignore(void *unused)
{
return NULL;
}
static void dev_register_opts(struct lightningd *ld)
{
/* We might want to debug plugins, which are started before normal
@ -915,6 +920,11 @@ static void dev_register_opts(struct lightningd *ld)
opt_set_bool,
&ld->dev_allow_shutdown_destination_change,
"Allow destination override on close, even if risky");
/* This is handled directly in daemon_developer_mode(), so we ignore it here */
clnopt_noarg("--dev-debug-self", OPT_DEV,
opt_ignore,
NULL,
"Fire up a terminal window with a debugger in it on initialization");
}
static const struct config testnet_config = {

View File

@ -1985,7 +1985,7 @@ const char *plugin_send_getmanifest(struct plugin *p, const char *cmd_id)
cmd = tal_arr(tmpctx, char *, 1);
cmd[0] = p->cmd;
if (debugging(p))
tal_arr_expand(&cmd, "--debugger");
tal_arr_expand(&cmd, "--dev-debug-self");
if (p->plugins->ld->developer)
tal_arr_expand(&cmd, "--developer");
tal_arr_expand(&cmd, NULL);

View File

@ -258,7 +258,7 @@ static int subd(const char *path, const char *name,
if (io_logging)
args[num_args++] = "--log-io";
if (debugging)
args[num_args++] = "--debugger";
args[num_args++] = "--dev-debug-self";
if (developer)
args[num_args++] = "--developer";
execv(args[0], args);

View File

@ -27,6 +27,9 @@ int connectd_init(struct lightningd *ld UNNEEDED)
/* Generated stub for connectd_start_shutdown */
void connectd_start_shutdown(struct subd *connectd UNNEEDED)
{ fprintf(stderr, "connectd_start_shutdown called!\n"); abort(); }
/* Generated stub for daemon_developer_mode */
bool daemon_developer_mode(char *argv[])
{ fprintf(stderr, "daemon_developer_mode called!\n"); abort(); }
/* Generated stub for daemon_poll */
int daemon_poll(struct pollfd *fds UNNEEDED, nfds_t nfds UNNEEDED, int timeout UNNEEDED)
{ fprintf(stderr, "daemon_poll called!\n"); abort(); }