mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
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>
This commit is contained in:
parent
3e3dbfdd1b
commit
1950583612
@ -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
|
||||
|
@ -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…
Reference in New Issue
Block a user