[gtk+] X11: Decode extension names in the error handler



commit cc517f116adb9dfe424994c11933a98da111da5e
Author: Adam Jackson <ajax redhat com>
Date:   Mon Feb 3 20:37:00 2014 +0000

    X11: Decode extension names in the error handler
    
    This commit uses the Xlib cache to obtain the name of the X extension
    for the request that caused the error.
    
    https://bugzilla.gnome.org/review?bug=723555

 gdk/x11/gdkdisplay-x11.c |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)
---
diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c
index 8142e1b..34e84af 100644
--- a/gdk/x11/gdkdisplay-x11.c
+++ b/gdk/x11/gdkdisplay-x11.c
@@ -46,6 +46,7 @@
 #include <unistd.h>
 
 #include <X11/Xatom.h>
+#include <X11/Xlibint.h>
 
 #ifdef HAVE_XKB
 #include <X11/XKBlib.h>
@@ -2472,6 +2473,27 @@ gdk_x11_register_standard_event_type (GdkDisplay *display,
   display_x11->event_types = g_slist_prepend (display_x11->event_types, event_type);
 }
 
+/* look up the extension name for a given major opcode.  grubs around in
+ * xlib to do it since a) it's already cached there b) XQueryExtension
+ * emits protocol so we can't use it in an error handler.
+ */
+static const char *
+_gdk_x11_decode_request_code(Display *dpy, int code)
+{
+  _XExtension *ext;
+
+  if (code < 128)
+    return "core protocol";
+
+  for (ext = dpy->ext_procs; ext; ext = ext->next)
+    {
+      if (ext->codes.major_opcode == code)
+        return ext->name;
+    }
+
+  return "unknown";
+}
+
 /* compare X sequence numbers handling wraparound */
 #define SEQUENCE_COMPARE(a,op,b) (((long) (a) - (long) (b)) op 0)
 
@@ -2516,7 +2538,7 @@ _gdk_x11_display_error_event (GdkDisplay  *display,
         g_strdup_printf ("The program '%s' received an X Window System error.\n"
                          "This probably reflects a bug in the program.\n"
                          "The error was '%s'.\n"
-                         "  (Details: serial %ld error_code %d request_code %d minor_code %d)\n"
+                         "  (Details: serial %ld error_code %d request_code %d (%s) minor_code %d)\n"
                          "  (Note to programmers: normally, X errors are reported asynchronously;\n"
                          "   that is, you will receive the error a while after causing it.\n"
                          "   To debug your program, run it with the GDK_SYNCHRONIZE environment\n"
@@ -2527,6 +2549,8 @@ _gdk_x11_display_error_event (GdkDisplay  *display,
                          error->serial,
                          error->error_code,
                          error->request_code,
+                         _gdk_x11_decode_request_code(display_x11->xdisplay,
+                                                      error->request_code),
                          error->minor_code);
 
 #ifdef G_ENABLE_DEBUG


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]