Skip to content

Commit 7b9341e

Browse files
rustyrussellcdecker
authored andcommitted
subdaemon: better GDB support.
It was annoying me, so I made it much nicer to use. Signed-off-by: Rusty Russell <[email protected]>
1 parent ae61f64 commit 7b9341e

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

common/subdaemon.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <ccan/tal/str/str.h>
12
#include <common/dev_disconnect.h>
23
#include <common/status.h>
34
#include <common/subdaemon.h>
@@ -24,11 +25,6 @@ static void status_backtrace_exit(void)
2425
status_failed(STATUS_FAIL_INTERNAL_ERROR, "FATAL SIGNAL");
2526
}
2627

27-
#if DEVELOPER
28-
extern volatile bool debugger_connected;
29-
volatile bool debugger_connected;
30-
#endif
31-
3228
void subdaemon_setup(int argc, char *argv[])
3329
{
3430
if (argc == 2 && streq(argv[1], "--version")) {
@@ -45,10 +41,11 @@ void subdaemon_setup(int argc, char *argv[])
4541
/* From debugger, set debugger_spin to 0. */
4642
for (int i = 1; i < argc; i++) {
4743
if (streq(argv[i], "--debugger")) {
48-
fprintf(stderr, "gdb -ex 'attach %u' -ex 'p debugger_connected=1' %s\n",
49-
getpid(), argv[0]);
50-
while (!debugger_connected)
51-
usleep(10000);
44+
char *cmd = tal_fmt(NULL, "${DEBUG_TERM:-gnome-terminal --} gdb -ex 'attach %u' %s &", getpid(), argv[0]);
45+
fprintf(stderr, "Running %s\n", cmd);
46+
system(cmd);
47+
/* Continue in the debugger. */
48+
kill(getpid(), SIGSTOP);
5249
}
5350
if (strstarts(argv[i], "--dev-disconnect=")) {
5451
dev_disconnect_init(atoi(argv[i]

doc/HACKING.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ Debugging
9292
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.
9393

9494
You can debug crashing subdaemons with the argument
95-
`--dev-debugger=lightning_channeld`, where `channeld` is the subdaemon name.
96-
It will print out (to stderr) a command such as:
97-
98-
gdb -ex 'attach 22398' -ex 'p debugger_connected=1' \
99-
lightningd/lightning_hsmd
100-
101-
Run this command to start debugging.
102-
You may need to type `return` one more time to exit the infinite while
103-
loop, otherwise you can type `continue` to begin.
95+
`--dev-debugger=channeld`, where `channeld` is the subdaemon name. It
96+
will run `gnome-terminal` by default with a gdb attached to the
97+
subdaemon when it starts. You can change the terminal used by setting
98+
the `DEBUG_TERM` environment variable, such as `DEBUG_TERM="xterm -e"`
99+
or `DEBUG_TERM="konsole -e"`.
100+
101+
It will also print out (to stderr) the gdb command for manual connection. The
102+
subdaemon will be stopped (it sends itself a SIGSTOP); you'll need to
103+
`continue` in gdb.
104104

105105
Database
106106
--------

lightningd/options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ static void dev_register_opts(struct lightningd *ld)
406406
opt_register_noarg("--dev-fail-on-subdaemon-fail", opt_set_bool,
407407
&ld->dev_subdaemon_fail, opt_hidden);
408408
opt_register_arg("--dev-debugger=<subdaemon>", opt_subd_debug, NULL,
409-
ld, "Wait for gdb attach at start of <subdaemon>");
409+
ld, "Invoke gdb at start of <subdaemon>");
410410
opt_register_arg("--dev-broadcast-interval=<ms>", opt_set_uintval,
411411
opt_show_uintval, &ld->config.broadcast_interval,
412412
"Time between gossip broadcasts in milliseconds");

0 commit comments

Comments
 (0)