util: added samba_start_debugger()
authorAndrew Tridgell <tridge@samba.org>
Tue, 20 Jul 2010 05:31:49 +0000 (15:31 +1000)
committerAndrew Tridgell <tridge@samba.org>
Sat, 4 Sep 2010 02:29:10 +0000 (12:29 +1000)
This developer function is useful for debugging unusual error
conditions

lib/util/util.c
lib/util/util.h

index d645f7edc91c7e73081d593f50ac568014055bc6..c0af4b0116244bf0b170585eca760219337d2315 100644 (file)
@@ -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
index 8383344cd5f092001f02223765f5c2fe64b80b82..994fad04d3b12b2ac7cea7e30708e46ce236657f 100644 (file)
@@ -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_ */