Add protocol debugging facility
authorKristian Høgsberg <krh@bitplanet.net>
Tue, 7 Sep 2010 14:58:19 +0000 (10:58 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Tue, 7 Sep 2010 19:58:29 +0000 (15:58 -0400)
connection.c
connection.h
wayland-server.c

index 8d4f19f..42ec038 100644 (file)
@@ -564,6 +564,49 @@ wl_closure_invoke(struct wl_closure *closure,
 }
 
 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)
 {
        int i;
index 5f28888..c087d82 100644 (file)
@@ -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
index ac87bb3..90346e3 100644 (file)
@@ -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)