From b58bfb351025816b18389ac2377c429b8a777dde Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 20 Jul 2010 15:31:49 +1000 Subject: util: added samba_start_debugger() This developer function is useful for debugging unusual error conditions --- lib/util/util.c | 14 ++++++++++++++ lib/util/util.h | 4 ++++ 2 files changed, 18 insertions(+) (limited to 'lib/util') diff --git a/lib/util/util.c b/lib/util/util.c index d645f7edc9..c0af4b0116 100644 --- a/lib/util/util.c +++ b/lib/util/util.c @@ -891,3 +891,17 @@ void *allocate_anonymous_shared(size_t bufsz) } +#ifdef DEVELOPER +/* used when you want a debugger started at a particular point in the + code. Mostly useful in code that runs as a child process, where + normal gdb attach is harder to organise. +*/ +void samba_start_debugger(void) +{ + char *cmd = NULL; + asprintf(&cmd, "xterm -e \"gdb --pid %u\"&", getpid()); + system(cmd); + free(cmd); + sleep(2); +} +#endif diff --git a/lib/util/util.h b/lib/util/util.h index 8383344cd5..994fad04d3 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -877,4 +877,8 @@ struct tevent_req *samba_runcmd_send(TALLOC_CTX *mem_ctx, const char * const *argv0, ...); int samba_runcmd_recv(struct tevent_req *req, int *perrno); +#ifdef DEVELOPER +void samba_start_debugger(void); +#endif + #endif /* _SAMBA_UTIL_H_ */ -- cgit