[PATCH wayland] connection: Print the content of arrays in closures

Emmanuel Gil Peyrot emmanuel.peyrot at collabora.com
Mon Jul 10 18:28:22 UTC 2017


The current behaviour when WAYLAND_DEBUG is set is to print “array”,
which is quite unhelpful.

This patch prints a list of the bytes present in the array.  It doesn’t
try to interpret it as uint32_t or anything, leaving that to the reader
because this information isn’t present in the protocol description.

Signed-off-by: Emmanuel Gil Peyrot <emmanuel.peyrot at collabora.com>
---
 src/connection.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 5c3d187..d616ddd 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1170,11 +1170,13 @@ wl_closure_queue(struct wl_closure *closure, struct wl_connection *connection)
 void
 wl_closure_print(struct wl_closure *closure, struct wl_object *target, int send)
 {
-	int i;
+	int i, j;
 	struct argument_details arg;
 	const char *signature = closure->message->signature;
 	struct timespec tp;
 	unsigned int time;
+	size_t size;
+	char *data;
 
 	clock_gettime(CLOCK_REALTIME, &tp);
 	time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
@@ -1223,7 +1225,15 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target, int send)
 				fprintf(stderr, "nil");
 			break;
 		case 'a':
-			fprintf(stderr, "array");
+			fprintf(stderr, "array(");
+			size = closure->args[i].a->size;
+			data = (char*)closure->args[i].a->data;
+			if (size) {
+				for (j = 0; j < (int)size - 1; j++)
+					fprintf(stderr, "0x%02x, ", data[j]);
+				fprintf(stderr, "0x%02x", data[size - 1]);
+			}
+			fprintf(stderr, ")");
 			break;
 		case 'h':
 			fprintf(stderr, "fd %d", closure->args[i].h);
-- 
2.13.2



More information about the wayland-devel mailing list