Browse Source

subdaemon: make debugging a bit easier.

Use a volatile global, so debugger can flip it easily.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
1950583612
  1. 24
      common/subdaemon.c
  2. 4
      doc/HACKING.md

24
common/subdaemon.c

@ -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);
@ -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

4
doc/HACKING.md

@ -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.

Loading…
Cancel
Save