2010-02-25 01:25:16 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-02-25 01:25:16 +03:00
|
|
|
|
|
|
|
#include "nsX11ErrorHandler.h"
|
|
|
|
|
|
|
|
#include "prenv.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
#include "nsExceptionHandler.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
|
2010-06-22 00:35:49 +04:00
|
|
|
#include "mozilla/X11Util.h"
|
2010-03-17 09:31:49 +03:00
|
|
|
#include <X11/Xlib.h>
|
2010-02-25 01:25:16 +03:00
|
|
|
|
|
|
|
#define BUFSIZE 2048 // What Xlib uses with XGetErrorDatabaseText
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
int X11Error(Display* display, XErrorEvent* event) {
|
|
|
|
// Get an indication of how long ago the request that caused the error was
|
2011-03-25 06:38:59 +03:00
|
|
|
// made.
|
2010-02-25 01:25:16 +03:00
|
|
|
unsigned long age = NextRequest(display) - event->serial;
|
|
|
|
|
|
|
|
// Get a string to represent the request that caused the error.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString message;
|
2010-02-25 01:25:16 +03:00
|
|
|
if (event->request_code < 128) {
|
|
|
|
// Core protocol request
|
|
|
|
message.AppendInt(event->request_code);
|
|
|
|
} else {
|
|
|
|
// Extension request
|
2011-03-25 06:38:59 +03:00
|
|
|
|
|
|
|
// man XSetErrorHandler says "the error handler should not call any
|
|
|
|
// functions (directly or indirectly) on the display that will generate
|
|
|
|
// protocol requests or that will look for input events" so we use another
|
|
|
|
// temporary Display to request extension information. This assumes on
|
|
|
|
// the DISPLAY environment variable has been set and matches what was used
|
|
|
|
// to open |display|.
|
2013-10-11 00:36:42 +04:00
|
|
|
Display* tmpDisplay = XOpenDisplay(nullptr);
|
2011-03-25 06:38:59 +03:00
|
|
|
if (tmpDisplay) {
|
|
|
|
int nExts;
|
|
|
|
char** extNames = XListExtensions(tmpDisplay, &nExts);
|
2011-03-25 06:38:59 +03:00
|
|
|
int first_error;
|
2011-03-25 06:38:59 +03:00
|
|
|
if (extNames) {
|
|
|
|
for (int i = 0; i < nExts; ++i) {
|
2011-03-25 06:38:59 +03:00
|
|
|
int major_opcode, first_event;
|
2011-03-25 06:38:59 +03:00
|
|
|
if (XQueryExtension(tmpDisplay, extNames[i], &major_opcode,
|
|
|
|
&first_event, &first_error) &&
|
|
|
|
major_opcode == event->request_code) {
|
|
|
|
message.Append(extNames[i]);
|
|
|
|
message.Append('.');
|
|
|
|
message.AppendInt(event->minor_code);
|
|
|
|
break;
|
|
|
|
}
|
2010-02-25 01:25:16 +03:00
|
|
|
}
|
|
|
|
|
2011-03-25 06:38:59 +03:00
|
|
|
XFreeExtensionList(extNames);
|
|
|
|
}
|
|
|
|
XCloseDisplay(tmpDisplay);
|
2010-02-25 01:25:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-25 06:38:59 +03:00
|
|
|
char buffer[BUFSIZE];
|
2010-02-25 01:25:16 +03:00
|
|
|
if (message.IsEmpty()) {
|
|
|
|
buffer[0] = '\0';
|
|
|
|
} else {
|
|
|
|
XGetErrorDatabaseText(display, "XRequest", message.get(), "", buffer,
|
|
|
|
sizeof(buffer));
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString notes;
|
2010-02-25 01:25:16 +03:00
|
|
|
if (buffer[0]) {
|
|
|
|
notes.Append(buffer);
|
|
|
|
} else {
|
2014-05-22 07:48:51 +04:00
|
|
|
notes.AppendLiteral("Request ");
|
2010-02-25 01:25:16 +03:00
|
|
|
notes.AppendInt(event->request_code);
|
|
|
|
notes.Append('.');
|
|
|
|
notes.AppendInt(event->minor_code);
|
|
|
|
}
|
|
|
|
|
2014-05-22 07:48:51 +04:00
|
|
|
notes.AppendLiteral(": ");
|
2010-02-25 01:25:16 +03:00
|
|
|
|
|
|
|
// Get a string to describe the error.
|
|
|
|
XGetErrorText(display, event->error_code, buffer, sizeof(buffer));
|
|
|
|
notes.Append(buffer);
|
|
|
|
|
|
|
|
// For requests where Xlib gets the reply synchronously, |age| will be 1
|
|
|
|
// and the stack will include the function making the request. For
|
|
|
|
// asynchronous requests, the current stack will often be unrelated to the
|
|
|
|
// point of making the request, even if |age| is 1, but sometimes this may
|
|
|
|
// help us count back to the point of the request. With XSynchronize on,
|
|
|
|
// the stack will include the function making the request, even though
|
|
|
|
// |age| will be 2 for asynchronous requests because XSynchronize is
|
|
|
|
// implemented by an empty request from an XSync, which has not yet been
|
|
|
|
// processed.
|
|
|
|
if (age > 1) {
|
|
|
|
// XSynchronize returns the previous "after function". If a second
|
|
|
|
// XSynchronize call returns the same function after an enable call then
|
|
|
|
// synchronization must have already been enabled.
|
2019-03-25 01:13:52 +03:00
|
|
|
if (XSynchronize(display, X11True) == XSynchronize(display, X11False)) {
|
2014-05-22 07:48:51 +04:00
|
|
|
notes.AppendLiteral("; sync");
|
2010-02-25 01:25:16 +03:00
|
|
|
} else {
|
2014-05-22 07:48:51 +04:00
|
|
|
notes.AppendLiteral("; ");
|
2012-08-22 19:56:38 +04:00
|
|
|
notes.AppendInt(uint32_t(age));
|
2014-05-22 07:48:51 +04:00
|
|
|
notes.AppendLiteral(" requests ago");
|
2010-02-25 01:25:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (XRE_GetProcessType()) {
|
|
|
|
case GeckoProcessType_Default:
|
|
|
|
case GeckoProcessType_Plugin:
|
2011-06-08 23:56:31 +04:00
|
|
|
case GeckoProcessType_Content:
|
|
|
|
CrashReporter::AppendAppNotesToCrashReport(notes);
|
2010-02-25 01:25:16 +03:00
|
|
|
break;
|
|
|
|
default:; // crash report notes not supported.
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// The resource id is unlikely to be useful in a crash report without
|
|
|
|
// context of other ids, but add it to the debug console output.
|
2014-05-22 07:48:51 +04:00
|
|
|
notes.AppendLiteral("; id=0x");
|
2012-08-22 19:56:38 +04:00
|
|
|
notes.AppendInt(uint32_t(event->resourceid), 16);
|
2010-03-07 14:06:40 +03:00
|
|
|
# ifdef MOZ_X11
|
2010-02-25 01:25:16 +03:00
|
|
|
// Actually, for requests where Xlib gets the reply synchronously,
|
|
|
|
// MOZ_X_SYNC=1 will not be necessary, but we don't have a table to tell us
|
|
|
|
// which requests get a synchronous reply.
|
|
|
|
if (!PR_GetEnv("MOZ_X_SYNC")) {
|
2014-05-22 07:48:51 +04:00
|
|
|
notes.AppendLiteral(
|
|
|
|
"\nRe-running with MOZ_X_SYNC=1 in the environment may give a more "
|
|
|
|
"helpful backtrace.");
|
2010-02-25 01:25:16 +03:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2019-02-03 11:09:37 +03:00
|
|
|
MOZ_CRASH_UNSAFE(notes.get());
|
2010-02-25 01:25:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InstallX11ErrorHandler() {
|
|
|
|
XSetErrorHandler(X11Error);
|
|
|
|
|
2010-06-22 00:35:49 +04:00
|
|
|
Display* display = mozilla::DefaultXDisplay();
|
2010-03-07 14:06:40 +03:00
|
|
|
NS_ASSERTION(display, "No X display");
|
2010-02-25 01:25:16 +03:00
|
|
|
if (PR_GetEnv("MOZ_X_SYNC")) {
|
2019-03-25 01:13:52 +03:00
|
|
|
XSynchronize(display, X11True);
|
2010-02-25 01:25:16 +03:00
|
|
|
}
|
|
|
|
}
|