2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: Debug.c /main/5 1998/04/06 13:32:19 mgreess $ */
28 #include <X11/Intrinsic.h>
29 #include <X11/Xlibint.h>
31 #define INT_MESSAGE3 "XIO: fatal IO error %d (%s) on X server \"%s\"\r\n"
32 #define INT_MESSAGE4 " after %lu requests (%lu known processed) with %d events remaining.\r\n"
33 #define INT_MESSAGE5 " The connection was probably broken by a server shudown or KillClient.\r\n"
35 static int PrintXError(Display *dpy, XErrorEvent *event, FILE *fp);
36 static char *SysErrorMsg(int n);
39 static int XIOError(Display *dpy);
40 static int XError(Display *dpy, XErrorEvent *event);
41 static void _XtError(String);
43 static Boolean G_DumpCore;
47 XtAppContext app_context
50 XSetErrorHandler(XError);
51 XSetIOErrorHandler(XIOError);
52 XtAppSetErrorHandler(app_context, _XtError);
67 if (PrintXError(dpy, event, stderr) == 0)
70 kill(getpid(), SIGQUIT);
85 fprintf(stderr, INT_MESSAGE3,
86 errno, SysErrorMsg (errno), DisplayString (dpy));
87 fprintf(stderr, INT_MESSAGE4,
88 NextRequest(dpy) - 1, LastKnownRequestProcessed(dpy), QLength(dpy));
91 fprintf(stderr, INT_MESSAGE5);
93 kill(getpid(), SIGQUIT);
109 extern char *sys_errlist[];
112 char *s = ((n >= 0 && n < sys_nerr) ? sys_errlist[n] : "unknown error");
113 return (s ? s : "no such error");
131 char *mtype = "XlibMessage";
132 register _XExtension *ext = (_XExtension *)NULL;
133 _XExtension *bext = (_XExtension *)NULL;
134 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
135 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
136 fprintf(fp, "%s: %s\n ", mesg, buffer);
137 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d",
139 fprintf(fp, mesg, event->request_code);
140 if (event->request_code < 128)
142 sprintf(number, "%d", event->request_code);
143 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
147 for (ext = dpy->ext_procs;
148 ext && (ext->codes.major_opcode != event->request_code);
152 strcpy(buffer, ext->name);
156 fprintf(fp, " (%s)\n", buffer);
157 if (event->request_code >= 128)
159 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
162 fprintf(fp, mesg, event->minor_code);
165 sprintf(mesg, "%s.%d", ext->name, event->minor_code);
166 XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ);
167 fprintf(fp, " (%s)", buffer);
171 if (event->error_code >= 128)
173 /* kludge, try to find the extension that caused it */
175 for (ext = dpy->ext_procs; ext; ext = ext->next)
177 if (ext->error_string)
178 (*ext->error_string)(dpy, event->error_code, &ext->codes,
185 if (ext->codes.first_error &&
186 ext->codes.first_error < (int)event->error_code &&
187 (!bext || ext->codes.first_error > bext->codes.first_error))
191 sprintf(buffer, "%s.%d", bext->name,
192 event->error_code - bext->codes.first_error);
194 strcpy(buffer, "Value");
195 XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ);
199 fprintf(fp, mesg, event->resourceid);
202 /* let extensions try to print the values */
203 for (ext = dpy->ext_procs; ext; ext = ext->next)
205 if (ext->error_values)
206 (*ext->error_values)(dpy, event, fp);
209 else if ((event->error_code == BadWindow) ||
210 (event->error_code == BadPixmap) ||
211 (event->error_code == BadCursor) ||
212 (event->error_code == BadFont) ||
213 (event->error_code == BadDrawable) ||
214 (event->error_code == BadColor) ||
215 (event->error_code == BadGC) ||
216 (event->error_code == BadIDChoice) ||
217 (event->error_code == BadValue) ||
218 (event->error_code == BadAtom))
220 if (event->error_code == BadValue)
221 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%lx",
223 else if (event->error_code == BadAtom)
224 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%lx",
227 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%lx",
230 fprintf(fp, mesg, event->resourceid);
233 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%ld",
236 fprintf(fp, mesg, event->serial);
237 XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%ld",
240 fprintf(fp, mesg, dpy->request);
242 if (event->error_code == BadImplementation)
257 (void)fprintf(stderr, "XtToolkit Error: %s\n", string);
259 kill(getpid(), SIGQUIT);