Ejemplo n.º 1
0
void dumpBacktrace(int dumpFile, CrashData crash)
{
#ifdef Q_OS_UNIX
	// Variables for storing crash info.
	void* trace[BT_SIZE]; 	// Backtrace frames
	size_t size; 			// The backtrace size

	// Get the backtrace.
	size = backtrace(trace, BT_SIZE);

	// Dump the backtrace
	dprintf(dumpFile, "---- BEGIN BACKTRACE ----\n");
	backtrace_symbols_fd(trace, size, dumpFile);
	dprintf(dumpFile, "---- END BACKTRACE ----\n");
#elif defined Q_OS_WIN32
	dprintf(dumpFile, "---- BEGIN BACKTRACE ----\n");

	StackFrame stack[BT_SIZE];
	size_t size;

	SYMBOL_INFO *symbol;
	HANDLE process;

	size = getBacktrace(stack, BT_SIZE, *crash.context);

	// FIXME: Accessing heap memory is supposedly "dangerous",
	// but I can't find another way of doing this.

	// Initialize
	process = GetCurrentProcess();
	if (!SymInitialize(process, NULL, true))
	{
		dprintf(dumpFile, "Failed to initialize symbol handler. Can't print stack trace.\n");
		dprintf(dumpFile, "Here's a list of addresses in the call stack instead:\n");
		for(int i = 0; i < size; i++)
		{
			dprintf(dumpFile, "0x%0X\n", (DWORD64)stack[i].address);
		}
	} else {
		// Allocate memory... ._.
		symbol = (SYMBOL_INFO *) calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1);
		symbol->MaxNameLen = 255;
		symbol->SizeOfStruct = sizeof(SYMBOL_INFO);

		// Dump stacktrace
		for(int i = 0; i < size; i++)
		{
			DWORD64 addr = (DWORD64)stack[i].address;
			if (!SymFromAddr(process, (DWORD64)(addr), 0, symbol))
				dprintf(dumpFile, "?? - 0x%0X\n", addr);
			else
				dprintf(dumpFile, "%s - 0x%0X\n", symbol->Name, symbol->Address);
		}

		free(symbol);
	}

	dprintf(dumpFile, "---- END BACKTRACE ----\n");
#endif
}
Ejemplo n.º 2
0
void crashHandler(int sig)
{
    std::lock_guard<std::mutex> lock(mutex);

    initLoggingSystem();

    switch (sig)
    {
    case SIGSEGV:
    {
        logFatal("SIGSEGV\nBacktrace:\n");
        break;
    }
    case SIGABRT:
    {
        logFatal("SIGABRT\nBacktrace:\n");
        break;
    }
    }

    unsigned int depth = 0;
    const char **backtrace = getBacktrace(depth);

    for (size_t i = 0; i < depth-1; ++i)
    {
        logFatal("    %s\n", backtrace[i]);
    }

    deinitLoggingSystem();

    std::exit(1);
}
Ejemplo n.º 3
0
std::pair<String, int> ExtendedException::getFileAndLine() const {
  String file = empty_string();
  int line = 0;
  Array bt = getBacktrace();
  if (!bt.empty()) {
    Array top = bt.rvalAt(0).toArray();
    if (top.exists(s_file)) file = top.rvalAt(s_file).toString();
    if (top.exists(s_line)) line = top.rvalAt(s_line).toInt64();
  }
  return std::make_pair(file, line);
}
Ejemplo n.º 4
0
void dumpBacktrace()
{
#ifndef _WIN32
    vector<string> sFuncs;
    getBacktrace(sFuncs);
    vector<string>::iterator it = sFuncs.begin();
    ++it;
    for (; it != sFuncs.end(); ++it) {
        cerr << "  " << *it << endl;
    }
#endif
}
Ejemplo n.º 5
0
void print_backtrace(const char* title, const char *where, const char *assertion, const char *file, int line){
	print_message(title, where, assertion, file, line,"Prepare to print backtrace:\n");
	QString bt = getBacktrace();
	static int count = 1;
	QFile tf(QDir::tempPath() + QString("/texstudio_backtrace%1.txt").arg(count++));
	if (tf.open(QFile::WriteOnly)){
		tf.write(QString("%1 %2 in %3: %4\r\n").arg(title).arg(assertion).arg(file).arg(line).toLocal8Bit());
		tf.write(bt.toLocal8Bit());
		tf.close();
	};
	qDebug() << bt;
	fprintf(stderr, "%s\r\n", qPrintable(bt));
}
Ejemplo n.º 6
0
void fpeHandler(int sig)
{
    std::lock_guard<std::mutex> lock(mutex);

    initLoggingSystem();

    logWarning("SIGFPE\nBacktrace:\n");

    unsigned int depth = 0;
    const char **backtrace = getBacktrace(depth);

    for (size_t i = 0; i < depth-1; ++i)
    {
        logWarning("    %s\n", backtrace[i]);
    }
}