Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!bbn.com!metasoft!alan From: alan@metasoft.UUCP (Alan Epstein) Newsgroups: comp.windows.x Subject: Re: Debugging X11/Motif Message-ID: <2150@metasoft.UUCP> Date: 8 May 91 09:16:11 GMT References: <259@picker.picker.com> Distribution: na Organization: Meta Software Corporation, Cambridge MA Lines: 90 kobetitsch@picker.picker.com (harry kobetitsch) writes: >I would like to know how to approach debugging X11/Motif applications... > X Protocol error: BadFont, invalid Font Parameter... >Are there debugging guides out there for X11/Motif ? >How does one interpret the above error message? IMHO these protocol errors are just fine for server writers, but don't help much with application level debugging. One easy method of learning more about who did what wrong is to implement the following: 1- Add an X protocol error handler in your application. This allows access to the error without terminating your application. Sometime after starting up your X connection, execute: XSetErrorHandler(My_XErrorHandler); My_XErrorHandler gets called instead of the normal error dumper, and you can breakpoint there for further information. My_XErrorHandler(), which is really a copy of the X error dumper, follows at the end of this message. 2- In order for My_XErrorHandler to be really useful, it is necessary to synchronize the display, probably after setting up the error routine. This is due to the asynchronicity of the protocol, wherein messages are not exchanged sequentially. Synching means that when the error handler is called, the backtrace will be accurate as far as who made the offending X call. call: XSynchronize((Display *) dpy, 1) 'dpy' can be obtained via: TopLevel = XtInitialize(NULL, MyClassName, XtCommandLine, XtNumber(XtCommandLine), argcP, argv); dpy = XtDisplay(TopLevel); Hope this helps. ----------------------------- Alan Epstein Meta Software Corp UUCP: ...bbn!metasoft!alan 150 Cambridgepark Dr Internet/ARPA: alan%metasoft@bbn.com Cambridge, MA 02140 USA ----------------------------- ___________________________ cut here _____________________________________ int My_XErrorHandler(Display * dpy, XErrorEvent * event) { #ifdef DEBUG char buffer[BUFSIZ]; char mesg[BUFSIZ]; char number[32]; char *mtype = "XlibMessage"; FILE *fp = stderr; XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); (void) fprintf(fp, "%s: %s\n ", mesg, buffer); XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); (void) fprintf(fp, mesg, event->request_code); sprintf(number, "%d", event->request_code); XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); (void) fprintf(fp, " (%s)", buffer); fputs("\n ", fp); XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code", mesg, BUFSIZ); (void) fprintf(fp, mesg, event->minor_code); fputs("\n ", fp); XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", mesg, BUFSIZ); (void) fprintf(fp, mesg, event->resourceid); fputs("\n ", fp); XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", mesg, BUFSIZ); (void) fprintf(fp, mesg, event->serial); fputs("\n ", fp); XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d", mesg, BUFSIZ); (void) fprintf(fp, mesg, dpy->request); fputs("\n", fp); #endif return 0; }