[PATCH weston 6/8] xwm: move FILE to the callers of dump_property()

Maniraj Devadoss external.mdevadoss at de.adit-jv.com
Thu Aug 24 14:16:20 UTC 2017


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 <external.mdevadoss at de.adit-jv.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 19a24d2..922f2ca 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 b66b787..9659c2a 100644
--- a/xwayland/window-manager.c
+++ b/xwayland/window-manager.c
@@ -207,23 +207,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)
 {
@@ -376,7 +359,7 @@ xcb_cursor_library_load_cursor(struct weston_wm *wm, const char *file)
 }
 
 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;
@@ -384,18 +367,11 @@ dump_property(struct weston_wm *wm,
 	xcb_atom_t *atom_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): ",
@@ -432,15 +408,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;
@@ -450,7 +421,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);
 }
@@ -1329,19 +1300,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 ca75f5b..52da678 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.7.4



More information about the wayland-devel mailing list