mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-11 01:27:58 +01:00
subdaemon: better GDB support.
It was annoying me, so I made it much nicer to use. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
ae61f645ab
commit
7b9341e762
3 changed files with 15 additions and 18 deletions
|
@ -1,3 +1,4 @@
|
|||
#include <ccan/tal/str/str.h>
|
||||
#include <common/dev_disconnect.h>
|
||||
#include <common/status.h>
|
||||
#include <common/subdaemon.h>
|
||||
|
@ -24,11 +25,6 @@ static void status_backtrace_exit(void)
|
|||
status_failed(STATUS_FAIL_INTERNAL_ERROR, "FATAL SIGNAL");
|
||||
}
|
||||
|
||||
#if DEVELOPER
|
||||
extern volatile bool debugger_connected;
|
||||
volatile bool debugger_connected;
|
||||
#endif
|
||||
|
||||
void subdaemon_setup(int argc, char *argv[])
|
||||
{
|
||||
if (argc == 2 && streq(argv[1], "--version")) {
|
||||
|
@ -45,10 +41,11 @@ void subdaemon_setup(int argc, char *argv[])
|
|||
/* From debugger, set debugger_spin to 0. */
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (streq(argv[i], "--debugger")) {
|
||||
fprintf(stderr, "gdb -ex 'attach %u' -ex 'p debugger_connected=1' %s\n",
|
||||
getpid(), argv[0]);
|
||||
while (!debugger_connected)
|
||||
usleep(10000);
|
||||
char *cmd = tal_fmt(NULL, "${DEBUG_TERM:-gnome-terminal --} gdb -ex 'attach %u' %s &", getpid(), argv[0]);
|
||||
fprintf(stderr, "Running %s\n", cmd);
|
||||
system(cmd);
|
||||
/* Continue in the debugger. */
|
||||
kill(getpid(), SIGSTOP);
|
||||
}
|
||||
if (strstarts(argv[i], "--dev-disconnect=")) {
|
||||
dev_disconnect_init(atoi(argv[i]
|
||||
|
|
|
@ -92,15 +92,15 @@ Debugging
|
|||
You can build c-lightning with DEVELOPER=1 to use dev commands listed in ``cli/lightning-cli help``. ``./configure --enable-developer`` will do that. You can log console messages with log_info() in lightningd and status_trace() in other subdaemons.
|
||||
|
||||
You can debug crashing subdaemons with the argument
|
||||
`--dev-debugger=lightning_channeld`, where `channeld` is the subdaemon name.
|
||||
It will print out (to stderr) a command such as:
|
||||
`--dev-debugger=channeld`, where `channeld` is the subdaemon name. It
|
||||
will run `gnome-terminal` by default with a gdb attached to the
|
||||
subdaemon when it starts. You can change the terminal used by setting
|
||||
the `DEBUG_TERM` environment variable, such as `DEBUG_TERM="xterm -e"`
|
||||
or `DEBUG_TERM="konsole -e"`.
|
||||
|
||||
gdb -ex 'attach 22398' -ex 'p debugger_connected=1' \
|
||||
lightningd/lightning_hsmd
|
||||
|
||||
Run this command to start debugging.
|
||||
You may need to type `return` one more time to exit the infinite while
|
||||
loop, otherwise you can type `continue` to begin.
|
||||
It will also print out (to stderr) the gdb command for manual connection. The
|
||||
subdaemon will be stopped (it sends itself a SIGSTOP); you'll need to
|
||||
`continue` in gdb.
|
||||
|
||||
Database
|
||||
--------
|
||||
|
|
|
@ -406,7 +406,7 @@ static void dev_register_opts(struct lightningd *ld)
|
|||
opt_register_noarg("--dev-fail-on-subdaemon-fail", opt_set_bool,
|
||||
&ld->dev_subdaemon_fail, opt_hidden);
|
||||
opt_register_arg("--dev-debugger=<subdaemon>", opt_subd_debug, NULL,
|
||||
ld, "Wait for gdb attach at start of <subdaemon>");
|
||||
ld, "Invoke gdb at start of <subdaemon>");
|
||||
opt_register_arg("--dev-broadcast-interval=<ms>", opt_set_uintval,
|
||||
opt_show_uintval, &ld->config.broadcast_interval,
|
||||
"Time between gossip broadcasts in milliseconds");
|
||||
|
|
Loading…
Add table
Reference in a new issue