Skip to content

Commit

Permalink
subdaemon: make debugging a bit easier.
Browse files Browse the repository at this point in the history
Use a volatile global, so debugger can flip it easily.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jan 15, 2018
1 parent 3e3dbfd commit 1950583
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions common/subdaemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ static void crashlog_activate(void)
sigaction(SIGBUS, &sa, NULL);
}

void subdaemon_setup(int argc, char *argv[])
{
#if DEVELOPER
int i;
bool printed = false;
extern volatile bool debugger_connected;
volatile bool debugger_connected;
#endif

void subdaemon_setup(int argc, char *argv[])
{
if (argc == 2 && streq(argv[1], "--version")) {
printf("%s\n", version());
exit(0);
Expand All @@ -72,20 +72,20 @@ void subdaemon_setup(int argc, char *argv[])
| SECP256K1_CONTEXT_SIGN);

#if DEVELOPER
for (i = 1; i < argc; i++) {
for (int i = 1; i < argc; i++) {
if (strstarts(argv[i], "--dev-disconnect=")) {
dev_disconnect_init(atoi(argv[i]
+ strlen("--dev-disconnect=")));
}
}

/* From debugger, tell gdb "return". */
for (i = 1; i < argc; i++) {
while (streq(argv[i], "--debugger")) {
if (!printed)
fprintf(stderr, "gdb -ex 'attach %u' %s -ex return\n",
getpid(), argv[0]);
printed = true;
/* 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);
}
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions doc/HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ Debugging

You can debug crashing subdaemons with the argument
`--dev-debugger=lightning_channeld`, where `channeld` is the subdaemon name. It
will print out a command such as:
will print out (to stderr) a command such as:

gdb -ex 'attach 22398' lightning_channeld -ex return
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.
Expand Down

0 comments on commit 1950583

Please sign in to comment.