xlib集成调试(Tracing)

发布于 2024-08-22 20:23:31 字数 268 浏览 6 评论 0原文

Xlib (libX11.so) 中是否内置了任何调试选项?我可以获得 X11 lib 调用的列表吗?

我想从重型多线程、闭源程序中获取 xlib 函数调用的完整跟踪。它是一个非公开的嵌入式平台,因此我无法使用gdb进行多线程调试,并且该平台上没有ltrace。 另外,该程序无法通过 tcp/ip 连接到 x 服务器,只能通过 unix-socket 连接。我想跟踪 xlib 本身的 xlib 调用。

附: Xlib 来自相当现代的 xfree 甚至 xorg。来自 gnu linux

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

森林迷了鹿 2024-08-29 20:23:31

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.

街道布景 2024-08-29 20:23:31

您可以查看 xlibtrace,它跟踪 Xlib 和您的代码之间的接口,而不是 X Windows 有线协议。我已经执行了几个示例,它似乎有效。

源代码可在 http://kev.pulo.com.au/xlibtrace

我必须修改它以使其编译:

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__

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__
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文