From f1e7bd384c48a7c7531539ef4dedbe6b384a7609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Tue, 7 Sep 2010 10:58:19 -0400 Subject: [PATCH] Add protocol debugging facility --- connection.c | 43 +++++++++++++++++++++++++++++++++++++++++++ connection.h | 2 ++ wayland-server.c | 11 +++++++++++ 3 files changed, 56 insertions(+) diff --git a/connection.c b/connection.c index 8d4f19f4..42ec038c 100644 --- a/connection.c +++ b/connection.c @@ -563,6 +563,49 @@ wl_closure_invoke(struct wl_closure *closure, ffi_call(&closure->cif, func, &result, closure->args); } +void +wl_closure_print(struct wl_closure *closure, struct wl_object *target) +{ + struct wl_object *object; + int i; + + fprintf(stderr, "%s(%d).%s(", + target->interface->name, target->id, + closure->message->name); + + for (i = 2; i < closure->count; i++) { + if (i > 2) + fprintf(stderr, ", "); + switch (closure->message->signature[i - 2]) { + case 'u': + fprintf(stderr, "%u", closure->values[i].uint32); + break; + case 'i': + fprintf(stderr, "%d", closure->values[i].uint32); + break; + case 's': + fprintf(stderr, "\"%s\"", closure->values[i].string); + break; + case 'o': + object = closure->values[i].object; + fprintf(stderr, "object %u", object ? object->id : 0); + break; + case 'n': + fprintf(stderr, "new id %u", + closure->values[i].uint32); + break; + case 'a': + fprintf(stderr, "array"); + break; + case 'h': + fprintf(stderr, "fd %d", closure->values[i].uint32); + break; + } + } + + fprintf(stderr, ")\n"); +} + void wl_closure_destroy(struct wl_closure *closure) { diff --git a/connection.h b/connection.h index 5f288889..c087d82a 100644 --- a/connection.h +++ b/connection.h @@ -58,6 +58,8 @@ void wl_closure_invoke(struct wl_closure *closure, struct wl_object *target, void (*func)(void), void *data); void +wl_closure_print(struct wl_closure *closure, struct wl_object *target); +void wl_closure_destroy(struct wl_closure *closure); #endif diff --git a/wayland-server.c b/wayland-server.c index ac87bb30..90346e34 100644 --- a/wayland-server.c +++ b/wayland-server.c @@ -73,6 +73,8 @@ struct wl_global { WL_EXPORT struct wl_surface wl_grab_surface; +static int wl_debug = 0; + WL_EXPORT void wl_client_post_event(struct wl_client *client, struct wl_object *sender, uint32_t opcode, ...) @@ -149,6 +151,10 @@ wl_client_connection_data(int fd, uint32_t mask, void *data) continue; } + + if (wl_debug) + wl_closure_print(closure, object); + wl_closure_invoke(closure, object, object->implementation[opcode], client); @@ -331,6 +337,11 @@ WL_EXPORT struct wl_display * wl_display_create(void) { struct wl_display *display; + const char *debug; + + debug = getenv("WAYLAND_DEBUG"); + if (debug) + wl_debug = 1; display = malloc(sizeof *display); if (display == NULL)