Re: [RFC wayland 2/2] Add a wayland protocol dumper wayland-tracer

2014-07-20 Thread Marek Chalupa
Hi,

nice work! Some time ago I did the same, but didn't want to send it until
it's more mature (and haven't got on it since). My version works the very
same way, the only difference is that I have 'filters' there. The filter is
a function that is called for every data on socket and can be dynamically
(although now I have them statically) added to the dumper. I also use only
wl_connection (no wl_buffer)

I formated the patches for my dumper and I'm sending them here, if somebody
is interested in very similar yet different way how to do it.

Since I'm off next two weeks, feel free to do whatever you want with the
patches (or ignore them)

Regards,
Marek


On 20 July 2014 04:18, Boyan Ding  wrote:

> Signed-off-by: Boyan Ding 
> ---
>  .gitignore   |   1 +
>  Makefile.am  |  10 ++
>  configure.ac |   7 ++
>  src/tracer.c | 351
> +++
>  4 files changed, 369 insertions(+)
>  create mode 100644 src/tracer.c
>
> diff --git a/.gitignore b/.gitignore
> index c146bac..510b7ae 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -54,4 +54,5 @@ sanity-test
>  signal-test
>  socket-test
>  wayland-scanner
> +wayland-tracer
>  protocol/*.[ch]
> diff --git a/Makefile.am b/Makefile.am
> index c15d8b8..f234599 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -70,6 +70,16 @@ $(BUILT_SOURCES) : wayland-scanner
>  pkgconfig_DATA += src/wayland-scanner.pc
>  else
>  wayland_scanner = wayland-scanner
> +bin_PROGRAMS =
> +endif
> +
> +if ENABLE_TRACER
> +wayland_tracer = $(top_builddir)/wayland-tracer
> +bin_PROGRAMS += wayland-tracer
> +wayland_tracer_SOURCES = src/tracer.c
> +wayland_tracer_LDADD = libwayland-util.la $(FFI_LIBS)
> +else
> +wayland_tracer = wayland-tracer
>  endif
>
>  protocol/%-protocol.c : $(top_srcdir)/protocol/%.xml
> diff --git a/configure.ac b/configure.ac
> index e16c5b5..b3e81a7 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -64,7 +64,14 @@ AC_ARG_ENABLE([documentation],
>   [],
>   [enable_documentation=yes])
>
> +AC_ARG_ENABLE([tracer],
> +  [AC_HELP_STRING([--disable-tracer],
> +  [Disable compilation of wayland-tracer])],
> +  [],
> +  [enable_tracer=yes])
> +
>  AM_CONDITIONAL(ENABLE_SCANNER, test "x$enable_scanner" = xyes)
> +AM_CONDITIONAL(ENABLE_TRACER, test "x$enable_tracer" = xyes)
>
>  AC_ARG_WITH(icondir, [  --with-icondir=Look for cursor icons
> here],
>  [  ICONDIR=$withval],
> diff --git a/src/tracer.c b/src/tracer.c
> new file mode 100644
> index 000..23de75d
> --- /dev/null
> +++ b/src/tracer.c
> @@ -0,0 +1,351 @@
> +/*
> + * Copyright © 2014 Boyan Ding
> + *
> + * Permission to use, copy, modify, distribute, and sell this software
> and its
> + * documentation for any purpose is hereby granted without fee, provided
> that
> + * the above copyright notice appear in all copies and that both that
> copyright
> + * notice and this permission notice appear in supporting documentation,
> and
> + * that the name of the copyright holders not be used in advertising or
> + * publicity pertaining to distribution of the software without specific,
> + * written prior permission.  The copyright holders make no
> representations
> + * about the suitability of this software for any purpose.  It is
> provided "as
> + * is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
> SOFTWARE,
> + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
> + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT
> OR
> + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
> USE,
> + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
> + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
> PERFORMANCE
> + * OF THIS SOFTWARE.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "wayland-os.h"
> +#include "wayland-private.h"
> +#include "wayland-util.h"
> +
> +#define TRACER_SERVER_SIDE 0
> +#define TRACER_CLIENT_SIDE 1
> +
> +struct tracer_connection {
> +   struct wl_connection *wl_conn;
> +   struct tracer_connection *peer;
> +   int side;
> +};
> +
> +struct tracer {
> +   struct tracer_connection *client_conn;
> +   struct tracer_connection *server_conn;
> +   int32_t epollfd;
> +};
> +
> +static int
> +tracer_dump_bin(struct tracer_connection *connection)
> +{
> +   int i, len, fdlen, fd;
> +   char buf[4096];
> +   struct wl_connection *wl_conn= connection->wl_conn;
> +   struct tracer_connection *peer = connection->peer;
> +
> +   len = wl_buffer_size(&wl_conn->in);
> +   if (len == 0)
> +   return 0;
> +
> +   wl_connection_copy(wl_conn, buf, len);
> +
> +   printf("%s

Re: [RFC wayland 2/2] Add a wayland protocol dumper wayland-tracer

2014-07-20 Thread Silvan Jegen
Hi

and thanks for this! I hope to learn more about the protocol by using
this tool.

I encountered two simple issues when applying your patches (see below).

On Sun, Jul 20, 2014 at 10:18:03AM +0800, Boyan Ding wrote:
> Signed-off-by: Boyan Ding 
> ---
>  .gitignore   |   1 +
>  Makefile.am  |  10 ++
>  configure.ac |   7 ++
>  src/tracer.c | 351 
> +++
>  4 files changed, 369 insertions(+)
>  create mode 100644 src/tracer.c
> 
> diff --git a/.gitignore b/.gitignore
> index c146bac..510b7ae 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -54,4 +54,5 @@ sanity-test
>  signal-test
>  socket-test
>  wayland-scanner
> +wayland-tracer
>  protocol/*.[ch]
> diff --git a/Makefile.am b/Makefile.am
> index c15d8b8..f234599 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -70,6 +70,16 @@ $(BUILT_SOURCES) : wayland-scanner
>  pkgconfig_DATA += src/wayland-scanner.pc
>  else
>  wayland_scanner = wayland-scanner
> +bin_PROGRAMS =
> +endif
> +
> +if ENABLE_TRACER
> +wayland_tracer = $(top_builddir)/wayland-tracer
> +bin_PROGRAMS += wayland-tracer
> +wayland_tracer_SOURCES = src/tracer.c
> +wayland_tracer_LDADD = libwayland-util.la $(FFI_LIBS)

wayland-tracer wouldn't compile without including the -lrt switch (for
the time.h functions) like this.

wayland_tracer_LDADD = libwayland-util.la $(FFI_LIBS) -lrt

I am not sure whether this issue is specific to my setup or if this is
the best way to fix it.


> +else
> +wayland_tracer = wayland-tracer
>  endif
>  
>  protocol/%-protocol.c : $(top_srcdir)/protocol/%.xml
> diff --git a/configure.ac b/configure.ac
> index e16c5b5..b3e81a7 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -64,7 +64,14 @@ AC_ARG_ENABLE([documentation],
> [],
> [enable_documentation=yes])
>  
> +AC_ARG_ENABLE([tracer],
> +  [AC_HELP_STRING([--disable-tracer],
> +  [Disable compilation of wayland-tracer])],
> +  [],
> +  [enable_tracer=yes])
> +
>  AM_CONDITIONAL(ENABLE_SCANNER, test "x$enable_scanner" = xyes)
> +AM_CONDITIONAL(ENABLE_TRACER, test "x$enable_tracer" = xyes)
>  
>  AC_ARG_WITH(icondir, [  --with-icondir=Look for cursor icons here],
>[  ICONDIR=$withval],
> diff --git a/src/tracer.c b/src/tracer.c
> new file mode 100644
> index 000..23de75d
> --- /dev/null
> +++ b/src/tracer.c
> @@ -0,0 +1,351 @@
> +/*
> + * Copyright © 2014 Boyan Ding
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and 
> its
> + * documentation for any purpose is hereby granted without fee, provided that
> + * the above copyright notice appear in all copies and that both that 
> copyright
> + * notice and this permission notice appear in supporting documentation, and
> + * that the name of the copyright holders not be used in advertising or
> + * publicity pertaining to distribution of the software without specific,
> + * written prior permission.  The copyright holders make no representations
> + * about the suitability of this software for any purpose.  It is provided 
> "as
> + * is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS 
> SOFTWARE,
> + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
> + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
> + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 
> USE,
> + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
> + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 
> PERFORMANCE
> + * OF THIS SOFTWARE.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "wayland-os.h"
> +#include "wayland-private.h"
> +#include "wayland-util.h"
> +
> +#define TRACER_SERVER_SIDE 0
> +#define TRACER_CLIENT_SIDE 1
> +
> +struct tracer_connection {
> + struct wl_connection *wl_conn;
> + struct tracer_connection *peer;
> + int side;
> +};
> +
> +struct tracer {
> + struct tracer_connection *client_conn;
> + struct tracer_connection *server_conn;
> + int32_t epollfd;
> +};
> +
> +static int
> +tracer_dump_bin(struct tracer_connection *connection)
> +{
> + int i, len, fdlen, fd;
> + char buf[4096];
> + struct wl_connection *wl_conn= connection->wl_conn;
> + struct tracer_connection *peer = connection->peer;
> +
> + len = wl_buffer_size(&wl_conn->in);
> + if (len == 0) 

There is a trailing space here (git complained when applying the patch).


> + return 0;
> +
> + wl_connection_copy(wl_conn, buf, len);
> +
> + printf("%s Data dumped: %d bytes:\n",
> +connection->side == TRACER_SERVER_SIDE ? "=>" : "<=", len);
> + for (i = 0; i < len; i++) {
> + printf("%02x ", (unsigne

[RFC wayland 2/2] Add a wayland protocol dumper wayland-tracer

2014-07-19 Thread Boyan Ding
Signed-off-by: Boyan Ding 
---
 .gitignore   |   1 +
 Makefile.am  |  10 ++
 configure.ac |   7 ++
 src/tracer.c | 351 +++
 4 files changed, 369 insertions(+)
 create mode 100644 src/tracer.c

diff --git a/.gitignore b/.gitignore
index c146bac..510b7ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -54,4 +54,5 @@ sanity-test
 signal-test
 socket-test
 wayland-scanner
+wayland-tracer
 protocol/*.[ch]
diff --git a/Makefile.am b/Makefile.am
index c15d8b8..f234599 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -70,6 +70,16 @@ $(BUILT_SOURCES) : wayland-scanner
 pkgconfig_DATA += src/wayland-scanner.pc
 else
 wayland_scanner = wayland-scanner
+bin_PROGRAMS =
+endif
+
+if ENABLE_TRACER
+wayland_tracer = $(top_builddir)/wayland-tracer
+bin_PROGRAMS += wayland-tracer
+wayland_tracer_SOURCES = src/tracer.c
+wayland_tracer_LDADD = libwayland-util.la $(FFI_LIBS)
+else
+wayland_tracer = wayland-tracer
 endif
 
 protocol/%-protocol.c : $(top_srcdir)/protocol/%.xml
diff --git a/configure.ac b/configure.ac
index e16c5b5..b3e81a7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -64,7 +64,14 @@ AC_ARG_ENABLE([documentation],
  [],
  [enable_documentation=yes])
 
+AC_ARG_ENABLE([tracer],
+  [AC_HELP_STRING([--disable-tracer],
+  [Disable compilation of wayland-tracer])],
+  [],
+  [enable_tracer=yes])
+
 AM_CONDITIONAL(ENABLE_SCANNER, test "x$enable_scanner" = xyes)
+AM_CONDITIONAL(ENABLE_TRACER, test "x$enable_tracer" = xyes)
 
 AC_ARG_WITH(icondir, [  --with-icondir=Look for cursor icons here],
 [  ICONDIR=$withval],
diff --git a/src/tracer.c b/src/tracer.c
new file mode 100644
index 000..23de75d
--- /dev/null
+++ b/src/tracer.c
@@ -0,0 +1,351 @@
+/*
+ * Copyright © 2014 Boyan Ding
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "wayland-os.h"
+#include "wayland-private.h"
+#include "wayland-util.h"
+
+#define TRACER_SERVER_SIDE 0
+#define TRACER_CLIENT_SIDE 1
+
+struct tracer_connection {
+   struct wl_connection *wl_conn;
+   struct tracer_connection *peer;
+   int side;
+};
+
+struct tracer {
+   struct tracer_connection *client_conn;
+   struct tracer_connection *server_conn;
+   int32_t epollfd;
+};
+
+static int
+tracer_dump_bin(struct tracer_connection *connection)
+{
+   int i, len, fdlen, fd;
+   char buf[4096];
+   struct wl_connection *wl_conn= connection->wl_conn;
+   struct tracer_connection *peer = connection->peer;
+
+   len = wl_buffer_size(&wl_conn->in);
+   if (len == 0) 
+   return 0;
+
+   wl_connection_copy(wl_conn, buf, len);
+
+   printf("%s Data dumped: %d bytes:\n",
+  connection->side == TRACER_SERVER_SIDE ? "=>" : "<=", len);
+   for (i = 0; i < len; i++) {
+   printf("%02x ", (unsigned char)buf[i]);
+   }
+   printf("\n");
+   wl_connection_consume(wl_conn, len);
+   wl_connection_write(peer->wl_conn, buf, len);
+
+   fdlen = wl_buffer_size(&wl_conn->fds_in);
+
+   wl_buffer_copy(&wl_conn->fds_in, buf, fdlen);
+   fdlen /= sizeof(int32_t);
+
+   if (fdlen != 0)
+   printf("%d Fds in control data:", fdlen);
+
+   for (i = 0; i < fdlen; i++) {
+   fd = ((int *) buf)[i];
+   printf("%d ", fd);
+   wl_connection_put_fd(peer->wl_conn, fd);
+   }
+   printf("\n");
+
+   wl_conn->fds_in.tail += fdlen * sizeof(int32_t);
+   wl_connection_flush(peer->wl_conn);
+
+   return len;
+}
+
+/* The following two functions are taken from wayland-client.c*/
+static int
+tracer_connect_to_socket(con