osgx
osgx

Reputation: 94415

xlib integrated debugging (Tracing)

Is there any debugging options built-in in the Xlib (libX11.so)? Can I get list of X11 lib calls?

I want to get full trace of xlib function calls from heavy-multithreaded, closed-source program. It is one not-public embedded platform, so I can't use gdb for multithreaded debugging and there is no ltrace on the platform. Also, this program can't connect to x server over tcp/ip, only unix-socket. I want to do tracing of xlib calls from xlib itself.

ps. Xlib from rather modern xfree or even xorg. from gnu linux

Upvotes: 2

Views: 1540

Answers (2)

Dale
Dale

Reputation: 229

You might look into xlibtrace, which traces at the interface between Xlib and your code, rather than the X Windows wire protocol. I've executed a couple of the examples, and it seems to work.

The source is available at http://kev.pulo.com.au/xlibtrace

I had to modify it to get it to compile:

diff -u src/libxlibtrace-functions.h.sh.orig src/libxlibtrace-functions.h.sh
--- src/libxlibtrace-functions.h.sh.orig    2009-01-19 23:43:46.000000000 -0500
+++ src/libxlibtrace-functions.h.sh 2016-02-24 13:49:25.155556294 -0500
@@ -81,7 +81,7 @@
    return (t ~ /^[cC][oO][nN][sS][tT][     ]/);
 }

-function isarray(t) {
+function our_isarray(t) {
    return (t ~ /\[.*\]$/);
 }

@@ -90,7 +90,7 @@
        return sprintf("%s", t);
    } else if (isfunctionpointer(t)) {
        return gensub("^(.*\\(\\*)(\\).*)$", "\\1"n"\\2", "", t);
-   } else if (isarray(t)) {
+   } else if (our_isarray(t)) {
        return gensub("^(.*)(\\[.*\\])$", "\\1"n"\\2", "", t);
    } else {
        return sprintf("%s %s", t, n);
diff -u src/libxlibtrace-print-x.h.orig src/libxlibtrace-print-x.h
--- src/libxlibtrace-print-x.h.orig 2009-01-19 22:30:06.000000000 -0500
+++ src/libxlibtrace-print-x.h  2016-02-24 14:27:08.681352710 -0500
@@ -2415,6 +2415,20 @@
    dofflush(f);
 })

+// XGenericEventCookie
+#define __REALTYPE_XGenericEventCookie__    XGenericEventCookie
+#define __REALTYPE_XGenericEventCookie_p__  XGenericEventCookie *
+#define __REALTYPE_XGenericEventCookie_pp__ XGenericEventCookie **
+#define __TRACE_PRINT_TYPE_STRUCT_BODY_XGenericEventCookie__(safetype) \
+   __TRACE_PRINT_STRUCT_MEMBER__(f, safetype, *value, int, type) __PRINT_COMMA__(f) \
+   __TRACE_PRINT_STRUCT_MEMBER__(f, safetype, *value, unsigned_long, serial) __PRINT_COMMA__(f) \
+   __TRACE_PRINT_STRUCT_MEMBER__(f, safetype, *value, Bool, send_event) __PRINT_COMMA__(f) \
+   __TRACE_PRINT_STRUCT_MEMBER__(f, safetype, *value, Display_p, display) __PRINT_COMMA__(f) \
+   __TRACE_PRINT_STRUCT_MEMBER__(f, safetype, *value, int, extension) __PRINT_COMMA__(f) \
+   __TRACE_PRINT_STRUCT_MEMBER__(f, safetype, *value, int, evtype) __PRINT_COMMA__(f) \
+   __TRACE_PRINT_STRUCT_MEMBER__(f, safetype, *value, unsigned_int, cookie) __PRINT_COMMA__(f) \
+   __TRACE_PRINT_STRUCT_MEMBER__(f, safetype, *value, void_p, data)
+__INDIRECT_CALL_3__(__TRACE_PRINT_TYPE_STRUCT,__LIBXLIBTRACE_PRINT_X_SUFF__,__)(XGenericEventCookie)


 #undef __LIBXLIBTRACE_PRINT_X_BODY__

Upvotes: 1

alanc
alanc

Reputation: 4180

You may be able to use xscope to monitor the requests sent over a Unix socket, even when you can't send the X protocol over TCP to be able to use network monitoring tools like Wireshark.

Upvotes: 3

Related Questions