[PATCH weston v5 08/14] xwm: move FILE to the callers of dump_property()

Daniel Stone daniels at collabora.com
Fri Jul 20 19:03:29 UTC 2018


From: Pekka Paalanen <pq at iki.fi>

This is preparation for using the weston-debug infrastructure for
WM_DEBUG. dump_property() may be called from different debugging
contexts and often needs to be prefixed with more information.

An alternative to this patch would be to pass in the weston_debug_scope
as an argument to dump_property(), but then all callers would need to be
converted to weston-debug infra in a single commit.

Therefore require the callers to provide the FILE* to print to.

Signed-off-by: Pekka Paalanen <pq at iki.fi>
Signed-off-by: Maniraj Devadoss <Maniraj.Devadoss at in.bosch.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
Reviewed-by: Daniel Stone <daniels at collabora.com>
---
 xwayland/selection.c      | 39 +++++++++++++++++++++--
 xwayland/window-manager.c | 67 ++++++++++++++++-----------------------
 xwayland/xwayland.h       |  3 +-
 3 files changed, 65 insertions(+), 44 deletions(-)

diff --git a/xwayland/selection.c b/xwayland/selection.c
index a75557044..85c320c29 100644
--- a/xwayland/selection.c
+++ b/xwayland/selection.c
@@ -34,6 +34,12 @@
 #include "xwayland.h"
 #include "shared/helpers.h"
 
+#ifdef WM_DEBUG
+#define wm_log(...) weston_log(__VA_ARGS__)
+#else
+#define wm_log(...) do {} while (0)
+#endif
+
 static int
 writable_callback(int fd, uint32_t mask, void *data)
 {
@@ -102,6 +108,9 @@ weston_wm_get_incr_chunk(struct weston_wm *wm)
 {
 	xcb_get_property_cookie_t cookie;
 	xcb_get_property_reply_t *reply;
+	FILE *fp;
+	char *logstr;
+	size_t logsize;
 
 	cookie = xcb_get_property(wm->conn,
 				  0, /* delete */
@@ -115,7 +124,13 @@ weston_wm_get_incr_chunk(struct weston_wm *wm)
 	if (reply == NULL)
 		return;
 
-	dump_property(wm, wm->atom.wl_selection, reply);
+	fp = open_memstream(&logstr, &logsize);
+	if (fp) {
+		dump_property(fp, wm, wm->atom.wl_selection, reply);
+		if (fclose(fp) == 0)
+			wm_log("%s", logstr);
+		free(logstr);
+	}
 
 	if (xcb_get_property_value_length(reply) > 0) {
 		/* reply's ownership is transferred to wm, which is responsible
@@ -178,6 +193,9 @@ weston_wm_get_selection_targets(struct weston_wm *wm)
 	xcb_atom_t *value;
 	char **p;
 	uint32_t i;
+	FILE *fp;
+	char *logstr;
+	size_t logsize;
 
 	cookie = xcb_get_property(wm->conn,
 				  1, /* delete */
@@ -191,7 +209,13 @@ weston_wm_get_selection_targets(struct weston_wm *wm)
 	if (reply == NULL)
 		return;
 
-	dump_property(wm, wm->atom.wl_selection, reply);
+	fp = open_memstream(&logstr, &logsize);
+	if (fp) {
+		dump_property(fp, wm, wm->atom.wl_selection, reply);
+		if (fclose(fp) == 0)
+			wm_log("%s", logstr);
+		free(logstr);
+	}
 
 	if (reply->type != XCB_ATOM_ATOM) {
 		free(reply);
@@ -232,6 +256,9 @@ weston_wm_get_selection_data(struct weston_wm *wm)
 {
 	xcb_get_property_cookie_t cookie;
 	xcb_get_property_reply_t *reply;
+	FILE *fp;
+	char *logstr;
+	size_t logsize;
 
 	cookie = xcb_get_property(wm->conn,
 				  1, /* delete */
@@ -243,7 +270,13 @@ weston_wm_get_selection_data(struct weston_wm *wm)
 
 	reply = xcb_get_property_reply(wm->conn, cookie, NULL);
 
-	dump_property(wm, wm->atom.wl_selection, reply);
+	fp = open_memstream(&logstr, &logsize);
+	if (fp) {
+		dump_property(fp, wm, wm->atom.wl_selection, reply);
+		if (fclose(fp) == 0)
+			wm_log("%s", logstr);
+		free(logstr);
+	}
 
 	if (reply == NULL) {
 		return;
diff --git a/xwayland/window-manager.c b/xwayland/window-manager.c
index 3bf323a42..4a26f6e7f 100644
--- a/xwayland/window-manager.c
+++ b/xwayland/window-manager.c
@@ -210,23 +210,6 @@ wm_log(const char *fmt, ...)
 #endif
 }
 
-static int __attribute__ ((format (printf, 1, 2)))
-wm_log_continue(const char *fmt, ...)
-{
-#ifdef WM_DEBUG
-	int l;
-	va_list argp;
-
-	va_start(argp, fmt);
-	l = weston_vlog_continue(fmt, argp);
-	va_end(argp);
-
-	return l;
-#else
-	return 0;
-#endif
-}
-
 static void
 weston_output_weak_ref_init(struct weston_output_weak_ref *ref)
 {
@@ -430,7 +413,7 @@ dump_cardinal_array(FILE *fp, xcb_get_property_reply_t *reply)
 }
 
 void
-dump_property(struct weston_wm *wm,
+dump_property(FILE *fp, struct weston_wm *wm,
 	      xcb_atom_t property, xcb_get_property_reply_t *reply)
 {
 	int32_t *incr_value;
@@ -439,18 +422,11 @@ dump_property(struct weston_wm *wm,
 	xcb_window_t *window_value;
 	int width, len;
 	uint32_t i;
-	FILE *fp;
-	char *logstr;
-	size_t logsize;
-
-	fp = open_memstream(&logstr, &logsize);
-	if (!fp)
-		return;
 
 	width = fprintf(fp, "%s: ", get_atom_name(wm->conn, property));
 	if (reply == NULL) {
 		fprintf(fp, "(no reply)\n");
-		goto out;
+		return;
 	}
 
 	width += fprintf(fp, "%s/%d, length %d (value_len %d): ",
@@ -492,15 +468,10 @@ dump_property(struct weston_wm *wm,
 	} else {
 		fprintf(fp, "huh?\n");
 	}
-
-out:
-	if (fclose(fp) == 0)
-		wm_log_continue("%s", logstr);
-	free(logstr);
 }
 
 static void
-read_and_dump_property(struct weston_wm *wm,
+read_and_dump_property(FILE *fp, struct weston_wm *wm,
 		       xcb_window_t window, xcb_atom_t property)
 {
 	xcb_get_property_reply_t *reply;
@@ -510,7 +481,7 @@ read_and_dump_property(struct weston_wm *wm,
 				  property, XCB_ATOM_ANY, 0, 2048);
 	reply = xcb_get_property_reply(wm->conn, cookie, NULL);
 
-	dump_property(wm, property, reply);
+	dump_property(fp, wm, property, reply);
 
 	free(reply);
 }
@@ -1389,19 +1360,35 @@ weston_wm_handle_property_notify(struct weston_wm *wm, xcb_generic_event_t *even
 	xcb_property_notify_event_t *property_notify =
 		(xcb_property_notify_event_t *) event;
 	struct weston_wm_window *window;
+	FILE *fp;
+	char *logstr;
+	size_t logsize;
 
 	if (!wm_lookup_window(wm, property_notify->window, &window))
 		return;
 
 	window->properties_dirty = 1;
 
-	wm_log("XCB_PROPERTY_NOTIFY: window %d, ", property_notify->window);
-	if (property_notify->state == XCB_PROPERTY_DELETE)
-		wm_log_continue("deleted %s\n",
-				get_atom_name(wm->conn, property_notify->atom));
-	else
-		read_and_dump_property(wm, property_notify->window,
-				       property_notify->atom);
+	fp = open_memstream(&logstr, &logsize);
+	if (fp) {
+		fprintf(fp, "XCB_PROPERTY_NOTIFY: window %d, ", property_notify->window);
+		if (property_notify->state == XCB_PROPERTY_DELETE)
+			fprintf(fp, "deleted %s\n",
+					get_atom_name(wm->conn, property_notify->atom));
+		else
+			read_and_dump_property(fp, wm, property_notify->window,
+					       property_notify->atom);
+
+		if (fclose(fp) == 0)
+			wm_log("%s", logstr);
+		free(logstr);
+	} else {
+		/* read_and_dump_property() is a X11 roundtrip.
+		 * Mimic it to maintain ordering semantics between debug
+		 * and non-debug paths.
+		 */
+		get_atom_name(wm->conn, property_notify->atom);
+	}
 
 	if (property_notify->atom == wm->atom.net_wm_name ||
 	    property_notify->atom == XCB_ATOM_WM_NAME)
diff --git a/xwayland/xwayland.h b/xwayland/xwayland.h
index ca75f5b7c..52da67869 100644
--- a/xwayland/xwayland.h
+++ b/xwayland/xwayland.h
@@ -23,6 +23,7 @@
  * SOFTWARE.
  */
 
+#include <stdio.h>
 #include <wayland-server.h>
 #include <xcb/xcb.h>
 #include <xcb/xfixes.h>
@@ -159,7 +160,7 @@ struct weston_wm {
 };
 
 void
-dump_property(struct weston_wm *wm, xcb_atom_t property,
+dump_property(FILE *fp, struct weston_wm *wm, xcb_atom_t property,
 	      xcb_get_property_reply_t *reply);
 
 const char *
-- 
2.17.1



More information about the wayland-devel mailing list