Look up/show name of request causing error.

SVN revision: 47920
This commit is contained in:
Kim Woelders 2010-04-11 11:42:57 +00:00
parent 17588aa5e0
commit 0cc43fd186
5 changed files with 48 additions and 14 deletions

View File

@ -355,6 +355,40 @@ EventsInit(void)
EventFdRegister(ConnectionNumber(disp), NULL);
}
static const char *
EventsGetExtensionName(int req)
{
unsigned int i;
EServerExtData *exd;
for (i = 0; i < sizeof(Extensions) / sizeof(EServerExt); i++)
{
exd = ExtData + Extensions[i].ix;
if (req == exd->major_op)
return Extensions[i].name;
}
return "?";
}
void
EventShowError(const XErrorEvent * ev)
{
Display *dpy = disp;
char buf[64], buf1[64];
if (ev->request_code < 128)
Esnprintf(buf, sizeof(buf), "%d", ev->request_code);
else
Esnprintf(buf, sizeof(buf), "%s.%d",
EventsGetExtensionName(ev->request_code), ev->minor_code);
XGetErrorDatabaseText(dpy, "XRequest", buf, "", buf1, sizeof(buf1));
XGetErrorText(dpy, ev->error_code, buf, sizeof(buf));
Eprintf("*** ERROR: xid=%#lx req=%i/%i err=%i: %s: %s\n",
ev->resourceid, ev->request_code, ev->minor_code,
ev->error_code, buf1, buf);
}
int
EventsUpdateXY(int *px, int *py)
{

View File

@ -40,6 +40,7 @@
void EventsInit(void);
void EventsMain(void);
void EventShow(const XEvent * ev);
void EventShowError(const XErrorEvent * ev);
typedef struct _EventFdDesc EventFdDesc;
typedef void (EventFdHandler) (void);

View File

@ -125,7 +125,7 @@ SetupX(const char *dstr)
Dpy.pixel_black = BlackPixel(disp, Dpy.screen);
Dpy.pixel_white = WhitePixel(disp, Dpy.screen);
EDisplaySetErrorHandlers(HandleXIOError);
EDisplaySetErrorHandlers(EventShowError, HandleXIOError);
/* Root defaults */
RROOT = ERegisterWindow(DefaultRootWindow(disp), NULL);

21
src/x.c
View File

@ -1754,18 +1754,13 @@ EDisplayDisconnect(void)
disp = NULL;
}
static int
HandleXError(Display * dpy, XErrorEvent * ev)
{
char buf[64];
static void (*EXErrorFunc) (const XErrorEvent * ev) = NULL;
if (EDebug(1))
{
XGetErrorText(dpy, ev->error_code, buf, 63);
Eprintf("*** ERROR: xid=%#lx error=%i req=%i/%i: %s\n",
ev->resourceid, ev->error_code,
ev->request_code, ev->minor_code, buf);
}
static int
HandleXError(Display * dpy __UNUSED__, XErrorEvent * ev)
{
if (EDebug(1) && EXErrorFunc)
EXErrorFunc(ev);
Dpy.last_error_code = ev->error_code;
@ -1786,9 +1781,11 @@ HandleXIOError(Display * dpy __UNUSED__)
}
void
EDisplaySetErrorHandlers(void (*fatal) (void))
EDisplaySetErrorHandlers(void (*error) (const XErrorEvent *),
void (*fatal) (void))
{
/* set up an error handler for then E would normally have fatal X errors */
EXErrorFunc = error;
XSetErrorHandler(HandleXError);
/* set up a handler for when the X Connection goes down */

View File

@ -54,7 +54,9 @@ void EXInit(void);
int EDisplayOpen(const char *dstr, int scr);
void EDisplayClose(void);
void EDisplayDisconnect(void);
void EDisplaySetErrorHandlers(void (*fatal) (void));
void
EDisplaySetErrorHandlers(void (*error) (const XErrorEvent *),
void (*fatal) (void));
void EGrabServer(void);
void EUngrabServer(void);