Exemplo n.º 1
0
    xNO_INLINE static void_t
    onInfo(int_t a_signal, siginfo_t *a_info, void_t *a_context)
    {
        xTEST_EQ(a_signal, a_info->si_signo);
        xUNUSED((ucontext_t *)a_context);

        xTRACE_FUNC;

        Trace() << Signal::infoDescription(*a_info) << "\n";
        Trace() << Signal::decription(0) << "\n";

        FileLog log(FileLog::lsDefaultMb);
        log.setFilePath(xT("crash.log"));

        std::ctstring_t msg = Format::str(
            xT("Crash info:\n\n")
            xT("Signal:\n{}\n\n")
            xT("StackTrace:\n{}"),
            Signal::infoDescription(*a_info),
            StackTrace().toString());

        log.write(xT("%s\n"), msg.c_str());

        std::tcout << StackTrace().toString() << std::endl;

        Application::exit(EXIT_FAILURE);
    }
Exemplo n.º 2
0
void *operator new(size_t bytes)
{
    if (gInstrumented)
    {
        
        if (!gExpectAllocations)
        {
            // Only flag the first unexpected allocation, so we don't end up 
            // with thousands of failures.

            gInstrumented = false;
            
            std::cout << "***************************************" << std::endl;
            std::cout << "Unexpected memory allocation. Call stack:" << std::endl;

            std::cout << StackTrace().toString() << std::endl;

            std::cout << "***************************************" << std::endl;

            RCF_CHECK(0 && "Unexpected memory allocation.");

        }
        ++gnAllocations;
    }
    return malloc(bytes);
}
Exemplo n.º 3
0
    static void_t onSignals(int a_signal)
    {
        Trace() << xFUNCTION << "\nStack trace:\n " << StackTrace().toString();

        switch (a_signal) {
        case SIGABRT:
            Trace() << "Caught SIGABRT: usually caused by an abort() or assert()";
            break;
        case SIGFPE:
            Trace() << "Caught SIGFPE: arithmetic exception, such as divide by zero";
            break;
        case SIGILL:
            Trace() << "Caught SIGILL: illegal instruction";
            break;
        case SIGINT:
            Trace() << "Caught SIGINT: interactive attention signal, probably a ctrl+c";
            break;
        case SIGSEGV:
            Trace() << "Caught SIGSEGV: segfault";
            break;
        case SIGTERM:
        default:
            Trace() << "Caught SIGTERM: a termination request was sent to the program";
            break;
        }

        ::_exit(EXIT_FAILURE);
    }
Exemplo n.º 4
0
void psLinearMovement::SetPosition (const csVector3& pos, float yrot,
	const iSector* sector)
{
    if (!sector)
    {
        StackTrace("Setting position without sector");
    }

//    Debug4(LOG_CELPERSIST,0,"DEBUG: psLinearMovement::SetPosition %s current transform: %s scale %f \n", mesh->QueryObject()->GetName(), mesh->GetMovable()->GetTransform().Description().GetData(),scale);

    // Position and Sector
    mesh->GetMovable ()->SetPosition ((iSector *)sector,pos);

    // at first loading scale may not be yet set
    if (scale>0) {
        // Rotation and scale
        csMatrix3 rotMatrix = (csMatrix3) csYRotMatrix3 (yrot);
        csMatrix3 scaleMatrix = csMatrix3 (1/scale,0,0, 0,1/scale,0, 0,0,1/scale);
        mesh->GetMovable ()->GetTransform ().SetO2T (scaleMatrix*rotMatrix);
    } else  {
        // Rotation only
        csMatrix3 rotMatrix = (csMatrix3) csYRotMatrix3 (yrot);
        mesh->GetMovable ()->GetTransform ().SetO2T (rotMatrix);
    }

    mesh->GetMovable ()->UpdateMove ();
}
Exemplo n.º 5
0
 void i_lexit (
     TExitLevel exit_level,
     int linenum,
     const char *filename,
     const char *functionname)
 {
   if (exit_level==df)
     exit_level= DEFAULT_EXIT_LEVEL;
   if (exit_level!=success && exit_level!=th)
     std::cerr<<ioscc::green<<"------"<<std::endl
       <<ioscc::green<<"the program is terminated"<<std::endl
       <<ioscc::green<<"  at "<<ioscc::blue<<filename<<ioscc::green<<":"
                             <<ioscc::blue<<linenum<<ioscc::green<<":"<<std::endl
       <<ioscc::green<<"  within the function: "<<ioscc::blue<<functionname<<std::endl;
   switch (exit_level)
   {
     case success :
       std::exit(EXIT_SUCCESS);
     case qfail   :
       std::exit(EXIT_FAILURE);
     case btfail  :
       std::cerr<<"backtrace:"<<std::endl;
       StackTrace();
       std::exit(EXIT_FAILURE);
     case abort   :
       std::abort();
     case th      :
       throw TException(linenum,filename,functionname);
     default      :
       std::cerr<<"improper usage of lexit(exit_level); invalid exit_level: "
         <<static_cast<int>(exit_level)<<std::endl;
       std::exit(EXIT_FAILURE);
   }
 }
Exemplo n.º 6
0
//---------------------------------------------------------------------------
static TStrings * __fastcall StackInfoListToStrings(
  TJclStackInfoList * StackInfoList)
{
  std::unique_ptr<TStrings> StackTrace(new TStringList());
  StackInfoList->AddToStrings(StackTrace.get(), true, false, true, false);
  // get rid of __fastcall declarations that are included in .map
  StackTrace->Text = ReplaceStr(StackTrace->Text, L"__fastcall ", L"");
  return StackTrace.release();
}
Exemplo n.º 7
0
void CrashHandler(int sig)
{
  /* Reinstall default handler to prevent race conditions */
  signal(sig, SIG_DFL);
  /* Print the stack trace */
  StackTrace();
  /* And exit because we may have corrupted the internal
   * memory allocation lists. Use abort() if we want to
   * generate a core dump. */
  _exit(EXIT_FAILURE);
}
Exemplo n.º 8
0
void HttpConnection::handshakeComplete(Socket *)
{
	TRACE("handshakeComplete() socketState=%s", socket_->state_str());

	if (socket_->state() == Socket::Operational)
		watchInput(worker_->server_.maxReadIdle());
	else
	{
		TRACE("handshakeComplete(): handshake failed\n%s", StackTrace().c_str());
		close();
	}
}
Exemplo n.º 9
0
/*
============
idInterpreter::Error

Aborts the currently executing function
============
*/
void idInterpreter::Error( char *fmt, ... ) const {
	va_list argptr;
	char	text[ 1024 ];
	va_start( argptr, fmt );
	vsprintf( text, fmt, argptr );
	va_end( argptr );
	StackTrace();
	if( ( instructionPointer >= 0 ) && ( instructionPointer < gameLocal.program.NumStatements() ) ) {
		statement_t &line = gameLocal.program.GetStatement( instructionPointer );
		common->Error( "%s(%d): Thread '%s': %s\n", gameLocal.program.GetFilename( line.file ), line.linenumber, thread->GetThreadName(), text );
	} else {
		common->Error( "Thread '%s': %s\n", thread->GetThreadName(), text );
	}
}
Exemplo n.º 10
0
int crtAllocationHook(
    int allocType, 
    void    *userData, 
    size_t size, 
    int blockType, 
    long    requestNumber, 
    const unsigned char *filename, // Can't be UNICODE
    int lineNumber)
{
    // Check for unexpected memory allocations.
    if (    gInstrumented
        &&  (allocType == _HOOK_ALLOC || allocType == _HOOK_REALLOC)
        && !gExpectAllocations)
    {
        // Only flag the first unexpected allocation, so we don't end up 
        // with thousands of failures.

        gInstrumented = false;

        // If we do want to track further allocations, uncomment this.
        //gInstrumented = true;

        std::cout << "***************************************" << std::endl;
        std::cout << "Unexpected memory allocation. Call stack:" << std::endl;
        
        std::cout << StackTrace().toString() << std::endl;

        std::cout << "***************************************" << std::endl;

        RCF_CHECK(0 && "Unexpected memory allocation.");
    }

    if (allocType == _HOOK_ALLOC || allocType == _HOOK_REALLOC)
    {
        ++gnAllocations;
    }

    return pfnOldCrtAllocHook(
        allocType, 
        userData, 
        size, 
        blockType, 
        requestNumber, 
        filename, 
        lineNumber);
}
Exemplo n.º 11
0
/** Closes this HttpConnection, possibly deleting this object (or propagating delayed delete).
 */
void HttpConnection::close()
{
	TRACE(1, "close()");
	TRACE(2, "Stack Trace:%s\n", StackTrace().c_str());

	if (isClosed())
		// XXX should we treat this as a bug?
		return;

	flags_ |= IsClosed;

	if (status_ == SendingReplyDone) {
		// usercode has issued a request->finish() but it didn't come to finalize it yet.
		request_->finalize();
	}
	status_ = Undefined;

	unref(); // <-- this refers to ref() in start()
}
Exemplo n.º 12
0
//---------------------------------------------------------------------------
static void __fastcall DoExceptNotify(TObject * ExceptObj, void * ExceptAddr,
  bool OSException, void * BaseOfStack)
{
  if (ExceptObj != NULL)
  {
    Exception * E = dynamic_cast<Exception *>(ExceptObj);
    if ((E != NULL) && IsInternalException(E)) // optimization
    {
      DoExceptionStackTrace(ExceptObj, ExceptAddr, OSException, BaseOfStack);

      TJclStackInfoList * StackInfoList = JclLastExceptStackList();

      if (ALWAYS_TRUE(StackInfoList != NULL))
      {
        std::unique_ptr<TStrings> StackTrace(StackInfoListToStrings(StackInfoList));

        DWORD ThreadID = GetCurrentThreadId();

        TGuard Guard(StackTraceCriticalSection.get());

        TStackTraceMap::iterator Iterator = StackTraceMap.find(ThreadID);
        if (Iterator != StackTraceMap.end())
        {
          Iterator->second->Add(L"");
          Iterator->second->AddStrings(StackTrace.get());
        }
        else
        {
          StackTraceMap.insert(std::make_pair(ThreadID, StackTrace.release()));
        }

        // this chains so that JclLastExceptStackList() returns NULL the next time
        // for the current thread
        delete StackInfoList;
      }
    }
  }
}
Exemplo n.º 13
0
PyObject * wipe_StackTrace(PyObject * self, PyObject * args)
{
	ULONG ulFramePointer;
	ULONG ulStackPointer;
	ULONG ulProgramCounter;
	ULONG ulFrames;
	EXTSTACKTRACE taFrames[1024];
	PyObject * ptFrameList = NULL;
	PyObject * ptFrame = NULL;
	ULONG i;

	if (!PyArg_ParseTuple(args, "kkk", &ulFramePointer, &ulStackPointer, &ulProgramCounter))
	{
		return NULL;
	}

	ptFrameList = Py_BuildValue("[]");

	ulFrames = StackTrace(ulFramePointer, ulStackPointer, ulProgramCounter, taFrames, 1024);
	
	for (i = 0; i < ulFrames; i++)
	{
		ptFrame = Py_BuildValue("(kkkN)", 
								taFrames[i].FramePointer,
								taFrames[i].ProgramCounter,
								taFrames[i].ReturnAddress,
								Py_BuildValue("(kkkk)", 
											  taFrames[i].Args[0],
											  taFrames[i].Args[1],
											  taFrames[i].Args[2],
											  taFrames[i].Args[3]));
		PyList_Append(ptFrameList, ptFrame);
		// PyList_Append adds a ref
		Py_DECREF(ptFrame);
	}

	return ptFrameList;
}
Exemplo n.º 14
0
void psLinearMovement::SetFullPosition (const csVector3& pos, float yrot,
	const iSector* sector)
{
  // Position
  csVector3 newpos;

    if (!sector)
    {
        StackTrace("Setting position without sector");
    }

  
  newpos = pos;
  mesh->GetMovable ()->SetPosition ((iSector *)sector, newpos);

  // Rotation
  csMatrix3 matrix = (csMatrix3) csYRotMatrix3 (yrot);
  // @@@ Not correct if anchor is transformed!!!
  mesh->GetMovable ()->GetTransform ().SetO2T (matrix);

  // Sector
  mesh->GetMovable ()->UpdateMove ();
}
Exemplo n.º 15
0
VOID
DoStackTrace(
    ULONG           FramePointer,
    ULONG           StackPointer,
    ULONG           InstructionPointer,
    ULONG           NumFrames,
    ULONG           TraceType
    )
{
    LPSTACKFRAME  StackFrames;
    DWORD         FrameCount;
    DWORD         i;
    DWORD         displacement;
    CHAR          symbuf[512];
    USHORT        StdCallArgs;

    if (NumFrames == 0) {
        NumFrames = 20;
    }

    StackFrames = malloc( sizeof(STACKFRAME) * NumFrames );
    if (!StackFrames) {
        dprintf( "could not allocate memory for stack trace\n" );
        return;
    }

    FrameCount = StackTrace( FramePointer,
                             StackPointer,
                             InstructionPointer,
                             StackFrames,
                             NumFrames,
                             0
                           );

    if (FrameCount == 0) {
        dprintf( "could not fetch any stack frames\n" );
        return;
    }

#if defined(TARGET_i386)
    dprintf( "ChildEBP RetAddr" );
    if (TraceType) {
        dprintf("  Args to Child");
    }
    dprintf("\n");
#else
    if (TraceType==1) {
        dprintf("\nCallee-SP   Arguments to Callee                 Call Site\n\n");
    } else {
        dprintf("\nCallee-SP Return-RA  Call Site\n\n");
    }
#endif

    for (i=0; i<FrameCount; i++) {

        GetSymbolStdCall( StackFrames[i].AddrPC.Offset,
                   symbuf,
                   &displacement,
                   &StdCallArgs
                   );

#if defined(TARGET_i386)
        dprintf( "%08x %08x ",
                 StackFrames[i].AddrFrame.Offset,
                 StackFrames[i].AddrReturn.Offset
               );

        if (TraceType > 0) {
            dprintf( "%08x %08x %08x ",
                     StackFrames[i].Params[0],
                     StackFrames[i].Params[1],
                     StackFrames[i].Params[2]
                   );
        }

        if (*symbuf) {
            dprintf( "%s", symbuf );
            if (displacement) {
                dprintf("+");
            }
        }
        if (displacement) {
            dprintf("0x%x", displacement);
        }

        if (TraceType == 2 && !StackFrames[i].FuncTableEntry) {
            if (StdCallArgs != 0xffff) {
                dprintf(" [Stdcall: %d]", StdCallArgs);
            }
        } else
        if (TraceType == 2 && StackFrames[i].FuncTableEntry) {
            PFPO_DATA pFpoData = (PFPO_DATA)StackFrames[i].FuncTableEntry;
            switch (pFpoData->cbFrame) {
                case FRAME_FPO:
                    if (pFpoData->fHasSEH) {
                        dprintf("(FPO: [SEH])");
                    } else {
                        dprintf(" (FPO:");
                        if (pFpoData->fUseBP) {
                            dprintf(" [EBP 0x%08x]", SAVE_EBP(StackFrames[i]));
                        }
                        dprintf(" [%d,%d,%d])", pFpoData->cdwParams,
                                                pFpoData->cdwLocals,
                                                pFpoData->cbRegs);
                    }
                    break;

                case FRAME_NONFPO:
                    dprintf("(FPO: [Non-Fpo]" );
                    break;

#ifdef KERNEL
                case FRAME_TRAP:
                    dprintf(" (FPO: [%d,%d] TrapFrame%s @ %08lx)",
                        pFpoData->cdwParams,
                        pFpoData->cdwLocals,
                        TRAP_EDITED(StackFrames[i]) ? "" : "-EDITED",
                        SAVE_TRAP(StackFrames[i]) );
                    break;
                case FRAME_TSS:
                    dprintf(" (FPO: TaskGate %lx:0)", TRAP_TSS(StackFrames[i]));
                    break;
#endif
                default:
                    dprintf("(UKNOWN FPO TYPE)");
                    break;
            }
        }
        dprintf( "\n" );
#else
        if (TraceType == 1) {
            dprintf( " %08lx : ",
                     StackFrames[i].AddrFrame.Offset
                   );
        } else {
            dprintf( " %08lx %08lx : ",
                     StackFrames[i].AddrFrame.Offset,
                     StackFrames[i].AddrReturn.Offset
                   );
        }

        if (TraceType == 1) {
            dprintf( "%08lx %08lx %08lx %08lx ",
                     StackFrames[i].Params[0],
                     StackFrames[i].Params[1],
                     StackFrames[i].Params[2],
                     StackFrames[i].Params[3]
                   );
        }

        dprintf( "%s", symbuf );
        if (displacement) {
            dprintf("+0x%lx ", displacement);
        }

        dprintf( "\n" );
#endif
    }

    free( StackFrames );

    return;
}
Exemplo n.º 16
0
LONG __stdcall DCUnhandledExceptionFilter( LPEXCEPTION_POINTERS e )
{
#ifdef __DEBUG
    MessageBox(NULL, _T("If you would like to debug DCUnhandledExceptionFilter - attach to this process now"), _T(APPNAME), MB_OK);
#endif
    Lock l(cs);

    if(recursion++ > 30)
        exit(-1);

#ifndef _DEBUG
#if _MSC_VER == 1200
    __pfnDliFailureHook = FailHook;
#elif _MSC_VER == 1300 || _MSC_VER == 1310 || _MSC_VER == 1400
    __pfnDliFailureHook2 = FailHook;
#else
#error Unknown Compiler version
#endif

    // The release version loads the dll and pdb:s here...
    InitSymInfo(Text::toT(Util::getDataPath()).c_str());

#endif
    TCHAR pdbPath[MAX_PATH];
    GetModuleFileName(NULL, pdbPath, sizeof(pdbPath));
    TCHAR* dotPtr = _tcschr(pdbPath, '.');
    if (dotPtr != NULL) {
        _tcscpy(dotPtr, _T(".pdb"));
    }

    if (GetFileAttributes(pdbPath) == INVALID_FILE_ATTRIBUTES) {
        // No debug symbols, we're not interested...
        ::MessageBox(WinUtil::mainWnd, _T(APPNAME) _T(" has crashed and you don't have .PDB file installed. Hence, I can't find out why it crashed, so don't report this as a bug unless you find a solution..."), _T(APPNAME) _T(" has crashed"), MB_OK);
#ifndef _DEBUG
        exit(1);
#else
        return EXCEPTION_CONTINUE_SEARCH;
#endif
    }
    File f(Util::getConfigPath() + "exceptioninfo.txt", File::WRITE, File::OPEN | File::CREATE);
    f.setEndPos(0);

    char buf[DEBUG_BUFSIZE];
    sprintf(buf,
            "Code: %x (%s)\r\n"
            "Version: %d (%s)\r\n",
            e->ExceptionRecord->ExceptionCode,
            getExceptionName(e->ExceptionRecord->ExceptionCode),
            BUILDID,
            Util::getCompileDate().c_str());

    tstring exceptioninfo = Text::toT(buf);
    f.write(buf, strlen(buf));

    OSVERSIONINFOEX ver;
    WinUtil::getVersionInfo(ver);
    const char *productType;
    if (ver.wProductType == VER_NT_DOMAIN_CONTROLLER) {
        productType = "domain controller";
    }
    else if (ver.wProductType == VER_NT_SERVER) {
        productType = "server";
    }
    else if (ver.wProductType == VER_NT_WORKSTATION) {
        productType = "workstation";
    }
    else {
        productType = "unknown product type";
    }

    sprintf(buf, "OS Version: %d.%d build %d service pack %d %s\r\n",
            (DWORD)ver.dwMajorVersion, (DWORD)ver.dwMinorVersion, (DWORD)ver.dwBuildNumber,
            (DWORD)ver.wServicePackMajor, productType);

    exceptioninfo += Text::toT(buf);
    f.write(buf, strlen(buf));

    time_t now;
    time(&now);
    strftime(buf, DEBUG_BUFSIZE, "Time: %Y-%m-%d %H:%M:%S\r\n", localtime(&now));

    exceptioninfo += Text::toT(buf);
    f.write(buf, strlen(buf));

#if 0
    WinUtil::exceptioninfo += LIT(_T("TTH: "));
    WinUtil::exceptioninfo += Text::toT(tth);
    WinUtil::exceptioninfo += LIT(_T("\r\n\r\n"));
#endif

    f.write(LIT("\r\n"));
    exceptioninfo += _T("\r\n");

    // !SMT!
    sprintf(buf,
            "exception code %08X at eip=%08X, nested: %08X\r\n"
            "eax=%08X ebx=%08X ecx=%08X edx=%08X\r\n"
            "esi=%08X edi=%08X ebp=%08X esp=%08X\r\n",
            e->ExceptionRecord->ExceptionCode,
            e->ExceptionRecord->ExceptionAddress,
            e->ExceptionRecord->ExceptionRecord,
            e->ContextRecord->Eax,
            e->ContextRecord->Ebx,
            e->ContextRecord->Ecx,
            e->ContextRecord->Edx,
            e->ContextRecord->Esi,
            e->ContextRecord->Edi,
            e->ContextRecord->Ebp,
            e->ContextRecord->Esp);
    exceptioninfo += Text::toT(buf);
    f.write(buf, strlen(buf));

    const tstring trace = StackTrace(GetCurrentThread(), e->ContextRecord);

    f.write(LIT("\r\n"));
    f.write(Text::fromT(trace));
    f.close();

#if 0
    memcpy(&CurrExceptionRecord, e->ExceptionRecord, sizeof(EXCEPTION_RECORD));
    memcpy(&CurrContext, e->ContextRecord, sizeof(CONTEXT));
#endif

    exceptioninfo += _T("\r\n");
    exceptioninfo += trace;

    Sounds::PlaySound(SettingsManager::SOUND_EXC);

    if (WinUtil::mainWnd != NULL) {
        NOTIFYICONDATA m_nid = {0};
        m_nid.cbSize = sizeof(NOTIFYICONDATA);
        m_nid.hWnd = WinUtil::mainWnd;
        m_nid.uID = 0;
        m_nid.uFlags = NIF_INFO;
        m_nid.uTimeout = 5000;
        m_nid.dwInfoFlags = NIIF_WARNING;
        _tcsncpy(m_nid.szInfo, _T("exceptioninfo.txt was generated"), 255);
        _tcsncpy(m_nid.szInfoTitle, _T(APPNAME) _T(" has crashed"), 63);
        Shell_NotifyIcon(NIM_MODIFY, &m_nid);
    }

    CExceptionDlg dlg(exceptioninfo);
    int iLastExceptionDlgResult = dlg.DoModal(WinUtil::mainWnd);
    if (iLastExceptionDlgResult == IDCANCEL) {
        ExitProcess(1);
    }

#ifndef _DEBUG
    UninitSymInfo();

    return EXCEPTION_CONTINUE_EXECUTION;
#else
    return EXCEPTION_CONTINUE_SEARCH;
#endif
}
Exemplo n.º 17
0
/* Callback for the exception handler
 * Parameters:
 *  e - The exception information
 * Returns:
 *  EXCEPTION_EXECUTE_HANDLER to terminate the process
 * Side Effects:
 *  unrealircd.PID.core is created
 *  If not running in service mode, a message box is displayed, 
 *   else output is written to service.log
 */
LONG __stdcall ExceptionFilter(EXCEPTION_POINTERS *e) 
{
	MEMORYSTATUS memStats;
	char file[512], text[1024], minidumpf[512];
	FILE *fd;
	time_t timet = time(NULL);
#ifndef NOMINIDUMP
	HANDLE hDump;
	HMODULE hDll = NULL;
#endif

	sprintf(file, "unrealircd.%d.core", getpid());
	fd = fopen(file, "w");
	GlobalMemoryStatus(&memStats);
	fprintf(fd, "Generated at %s\n%s (%d.%d.%d)\n%s[%s%s%s] (%s)\n"
		    "-----------------\nMemory Information:\n"
		    "\tPhysical: (Available:%ldMB/Total:%ldMB)\n"
		    "\tVirtual: (Available:%ldMB/Total:%ldMB)\n"
		    "-----------------\nException:\n\t%s\n-----------------\n"
		    "Backup Buffer:\n\t%s\n-----------------\nRegisters:\n"
		    "%s-----------------\nStack Trace:\n%s",
		     asctime(gmtime(&timet)), OSName, VerInfo.dwMajorVersion,
		     VerInfo.dwMinorVersion, VerInfo.dwBuildNumber, IRCDTOTALVERSION,
		     serveropts, extraflags ? extraflags : "", tainted ? "3" : "",
		     buildid, memStats.dwAvailPhys/1048576, memStats.dwTotalPhys/1048576, 
		     memStats.dwAvailVirtual/1048576, memStats.dwTotalVirtual/1048576, 
		     GetException(e->ExceptionRecord->ExceptionCode), backupbuf, 
		     GetRegisters(e->ContextRecord), StackTrace(e));

	sprintf(text, "UnrealIRCd has encountered a fatal error. Debugging information has been dumped to %s.", file);
	fclose(fd);

#ifndef NOMINIDUMP
	hDll = LoadLibrary("DBGHELP.DLL");
	if (hDll)
	{
		MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)GetProcAddress(hDll, "MiniDumpWriteDump");
		if (pDump)
		{
			MINIDUMP_EXCEPTION_INFORMATION ExInfo;
			sprintf(minidumpf, "unrealircd.%d.mdmp", getpid());
			hDump = CreateFile(minidumpf, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
			if (hDump != INVALID_HANDLE_VALUE)
			{
				ExInfo.ThreadId = GetCurrentThreadId();
				ExInfo.ExceptionPointers = e;
				ExInfo.ClientPointers = 0;

				if (pDump(GetCurrentProcess(), GetCurrentProcessId(), hDump, MiniDumpNormal, &ExInfo, NULL, NULL))
				{
					sprintf(text, "UnrealIRCd has encountered a fatal error. Debugging information has been dumped to %s and %s.", file, minidumpf);
				}
				CloseHandle(hDump);
			}
			sprintf(minidumpf, "unrealircd.%d.full.mdmp", getpid());
			hDump = CreateFile(minidumpf, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
			if (hDump != INVALID_HANDLE_VALUE)
			{
				ExInfo.ThreadId = GetCurrentThreadId();
				ExInfo.ExceptionPointers = e;
				ExInfo.ClientPointers = 0;

				CloseHandle(hDump);
			}
		}
	}
#endif
	
	if (!IsService)
	{
		MessageBox(NULL, text, "Fatal Error", MB_OK);
		StartCrashReporter();
	}
	else 
	{
		FILE *fd = fopen("service.log", "a");

		if (fd)
		{
			fprintf(fd, "UnrealIRCd has encountered a fatal error. Debugging information "
					"has been dumped to unrealircd.%d.core, please file a bug and upload "
					"this file to http://bugs.unrealircd.org/.", getpid());
			fclose(fd);
		}
	}
	CleanUp();
	return EXCEPTION_EXECUTE_HANDLER;
}
Exemplo n.º 18
0
  Exception::Exception(const std::string& err, 
		       const std::string &file, int line) throw()
  {
    _trace.push_back(StackTrace(err, file, line));
  }
Exemplo n.º 19
0
// Do the actual move
int psLinearMovement::MoveV (float delta)
{
  if (velBody < SMALL_EPSILON && velWorld < SMALL_EPSILON && (!colldet || colldet->IsOnGround ()))
    return PS_MOVE_DONTMOVE;  // didn't move anywhere

  int ret = PS_MOVE_SUCCEED;
  iMovable* movable = mesh->GetMovable ();
  if (movable->GetSectors ()->GetCount () <= 0)
    return PS_MOVE_DONTMOVE;  // didn't move anywhere

  csMatrix3 mat;

  // To test collision detection we use absolute position and transformation
  // (this is relevant if we are anchored). Later on we will correct that.
  csReversibleTransform fulltransf = movable->GetFullTransform ();
  mat = fulltransf.GetT2O ();

  csVector3 worldVel (fulltransf.This2OtherRelative (velBody) + velWorld);
  csVector3 oldpos (fulltransf.GetOrigin ());
  csVector3 newpos (worldVel*delta + oldpos);
  csVector3 bufpos = newpos;
  float dist = (newpos - oldpos).Norm ();

  // @@@ Magodra: In some cases the newpos seams to be invalid. Not sure about
  //              the reason, but the FollowSegment function will not work later
  //              in this function. So check for that condidtion, give warning,
  //              and halt the movement.
  if (CS::IsNaN(newpos.x) || CS::IsNaN(newpos.y) || CS::IsNaN(newpos.z))
  {
      printf("From old position %s ",toString(oldpos,movable->GetSectors()->Get(0)).GetDataSafe());
      StackTrace("LinearMovement to a NAN position.");
      return PS_MOVE_DONTMOVE;  // didn't move anywhere
  }

  // Check for collisions and adjust position
  if (colldet)
  {
    if (!colldet->AdjustForCollisions (oldpos, newpos, worldVel,
    	delta, movable))
    {
      ret = PS_MOVE_FAIL;
      newpos = oldpos;
    }
    else
    {
      // check if we collided, did move less than 9/10 of the distance
      if ((newpos - bufpos).Norm () > dist/10.0)
      {
        ret = PS_MOVE_PARTIAL;
      }
    }
  }

  csVector3 origNewpos = newpos;
  bool mirror = false;

  // Update position to account for portals
  iSector* new_sector = movable->GetSectors ()->Get (0);
  iSector* old_sector = new_sector;

  // @@@ Jorrit: had to do this add!
  // We need to measure slightly above the position of the actor or else
  // we won't really cross a portal.
  float height5 = (bottomSize.y + topSize.y) / 10.0f;
  newpos.y += height5;
  csMatrix3 id;
  csOrthoTransform transform_oldpos (id, oldpos +
  	csVector3 (0.0f, height5, 0.0f));

  new_sector = new_sector->FollowSegment (transform_oldpos, newpos, mirror,
  	PS_LINMOVE_FOLLOW_ONLY_PORTALS);
  newpos.y -= height5;
  if (new_sector != old_sector)
    movable->SetSector (new_sector);

  portalDisplaced += newpos - origNewpos;
  if(!IsOnGround ())
  {
	  //printf("Applying gravity: velY: %g.\n", velWorld.y);
    // gravity! move down!
    velWorld.y  -= gravity * delta;
    /*
     * Terminal velocity
     *   ((120 miles/hour  / 3600 second/hour) * 5280 feet/mile)
     *   / 3.28 feet/meter = 53.65 m/s
     */
    // The body velocity is figured in here too.
    if (velWorld.y < 0)
    {

      if (fulltransf.This2OtherRelative (velBody).y
      	+ velWorld.y < -(ABS_MAX_FREEFALL_VELOCITY))
      	velWorld.y = -(ABS_MAX_FREEFALL_VELOCITY)
      	- fulltransf.This2OtherRelative (velBody).y;
      if (velWorld.y > 0)
      {
	      // printf("Reset other y %g\n", fulltransf.This2OtherRelative (velBody).y);
        velWorld.y = 0;
      }
    }  
  }
  else
  {
    if(velWorld.y < 0)
    {
      velWorld.y = 0;
    }

    if (hugGround)
      HugGround (newpos, new_sector);
  }

  // Move to the new position. If we have an anchor we have to convert
  // the new position from absolute to relative.
  movable->GetTransform ().SetOrigin (newpos);
  movable->GetTransform ().SetT2O(
  	movable->GetTransform ().GetT2O () * transform_oldpos.GetT2O ());

  if (colldet)
  {
    // Part 4: Add us to all nearby sectors.
    mesh->PlaceMesh ();
  }

  movable->UpdateMove ();

  return ret;
}
Exemplo n.º 20
0
    static void_t onTerminate()
    {
        Trace() << xFUNCTION << "\nStack trace:\n" << StackTrace().toString();

        // std::abort();  // forces abnormal termination
    }
Exemplo n.º 21
0
extern "C" void  __stdcall StackTraceVB(int numSkip, int depth, TraceCallbackFunction pFunction, CONTEXT *pContext, void *data)
{
	StackTrace(numSkip, depth, pFunction, pContext, data);
}
Exemplo n.º 22
0
void TraceProcessState(const TargetInfo& ti)
{
    std::printf("ghd: Attempting to run stack trace\n");

    // Initialize atos late to reduce startup time and make sure our child
    // has actually run exec()
    std::auto_ptr<SymbolManager> symbol =
        std::auto_ptr<SymbolManager>(new SymbolManager(ti.m_pid));

    // List of threads
    thread_act_port_array_t thread_list;
    mach_msg_type_number_t thread_count;
    if (task_threads(ti.m_task_port, &thread_list, &thread_count) != KERN_SUCCESS)
        assert(!"Can't obtain thread list");

    for (uint thread_idx=0; thread_idx<thread_count; thread_idx++)
    {
        // Query thread scheduling etc. information
        thread_basic_info tbi;
        mach_msg_type_number_t thread_info_count = THREAD_BASIC_INFO_COUNT;
        if (thread_info(thread_list[thread_idx],
                        THREAD_BASIC_INFO,
                        (thread_info_t) &tbi,
                        &thread_info_count) != KERN_SUCCESS)
        {
            assert(!"thread_info() failed");
        }

        // Only show threads which were running, remove to show all threads
        if (tbi.flags & TH_FLAGS_SWAPPED)
            continue;

        std::printf("ghd: ---------------\n");
        std::printf("ghd: Thread %i of %i\n", thread_idx + 1, thread_count);
        std::printf("ghd: ---------------\n");

        std::printf("ghd: Status - ");
        switch (tbi.run_state)
        {
            case TH_STATE_RUNNING:         std::printf("Running");         break;
            case TH_STATE_STOPPED:         std::printf("Stopped");         break;
            case TH_STATE_WAITING:         std::printf("Waiting");         break;
            case TH_STATE_UNINTERRUPTIBLE: std::printf("Uninterruptible"); break;
            case TH_STATE_HALTED:          std::printf("Halted");          break;
            default:                       std::printf("(Unknown)");       break;
        }
        if (tbi.flags & TH_FLAGS_SWAPPED)
            std::printf(" (swapped out)");
        if (tbi.flags & TH_FLAGS_IDLE)
            std::printf(" (idle)");
        std::printf("\n");

        // Query thread exception information
        x86_exception_state32_t x86es32;
        mach_msg_type_number_t exception_state_count32 = x86_EXCEPTION_STATE32_COUNT;
        if (thread_get_state(thread_list[thread_idx],
                             x86_EXCEPTION_STATE32,
                             (thread_state_t) &x86es32,
                             &exception_state_count32) != KERN_SUCCESS)
        {
            assert(!"thread_get_state() failed");
        }
        const char *trap_err_str = "";
        switch (x86es32.__trapno)
        {
            case EXC_I386_DIVERR   :
                trap_err_str = " (EXC_I386_DIVERR - divide by 0 error)"; break;
            case EXC_I386_SGLSTP   :
                trap_err_str = " (EXC_I386_SGLSTP - single step)"; break;
            case EXC_I386_NMIFLT   :
                trap_err_str = " (EXC_I386_NMIFLT - NMI)"; break;
            case EXC_I386_BPTFLT   :
                trap_err_str = " (EXC_I386_BPTFLT - breakpoint fault)"; break;
            case EXC_I386_INTOFLT  :
                trap_err_str = " (EXC_I386_INTOFLT - INTO overflow fault)"; break;
            case EXC_I386_BOUNDFLT :
                trap_err_str = " (EXC_I386_BOUNDFLT - BOUND instruction fault)"; break;
            case EXC_I386_INVOPFLT :
                trap_err_str = " (EXC_I386_INVOPFLT - invalid opcode fault)"; break;
            case EXC_I386_NOEXTFLT :
                trap_err_str = " (EXC_I386_NOEXTFLT - extension not available fault)"; break;
            case EXC_I386_DBLFLT   :
                trap_err_str = " (EXC_I386_DBLFLT - double fault)"; break;
            case EXC_I386_EXTOVRFLT:
                trap_err_str = " (EXC_I386_EXTOVRFLT - extension overrun fault)"; break;
            case EXC_I386_INVTSSFLT:
                trap_err_str = " (EXC_I386_INVTSSFLT - invalid TSS fault)"; break;
            case EXC_I386_SEGNPFLT :
                trap_err_str = " (EXC_I386_SEGNPFLT - segment not present fault)"; break;
            case EXC_I386_STKFLT   :
                trap_err_str = " (EXC_I386_STKFLT - stack fault)"; break;
            case EXC_I386_GPFLT    :
                trap_err_str = " (EXC_I386_GPFLT - general protection fault)"; break;
            case EXC_I386_PGFLT    :
                trap_err_str = " (EXC_I386_PGFLT - page fault)"; break;
            case EXC_I386_EXTERRFLT:
                trap_err_str = " (EXC_I386_EXTERRFLT - extension error fault)"; break;
            case EXC_I386_ALIGNFLT :
                trap_err_str = " (EXC_I386_ALIGNFLT - alignment fault)"; break;
            case EXC_I386_ENDPERR  :
                trap_err_str = " (EXC_I386_ENDPERR - emulated extension error flt)"; break;
            case EXC_I386_ENOEXTFLT:
                trap_err_str = " (EXC_I386_ENOEXTFLT - emulated ext not present)"; break;
        }
        std::printf("ghd: ExceptionState - trapno: %u%s, err: %u, faultvaddr: 0x%x\n",
            x86es32.__trapno,
            trap_err_str,
            x86es32.__err,
            x86es32.__faultvaddr);

        // Query thread registers
        x86_thread_state32_t x86ts32;
        mach_msg_type_number_t thread_state_count32 = x86_THREAD_STATE32_COUNT;
        if (thread_get_state(thread_list[thread_idx],
                             x86_THREAD_STATE32,
                             (thread_state_t) &x86ts32,
                             &thread_state_count32) != KERN_SUCCESS)
        {
            assert(!"thread_get_state() failed");
        }
        std::printf("ghd: Registers\n" \
                    "ghd:   eax: %u, ebx: %u, ecx: %u, edx: %u, edi: %u, esi: %u, ebp: 0x%x\n" \
                    "ghd:   esp: 0x%x, ss: %u, eflags: %u, eip: 0x%x <%s>, cs: %u, ds: %u\n" \
                    "ghd:   es: %u, fs: %u, gs: %u\n",
            x86ts32.__eax,
            x86ts32.__ebx,
            x86ts32.__ecx,
            x86ts32.__edx,
            x86ts32.__edi,
            x86ts32.__esi,
            x86ts32.__ebp,
            x86ts32.__esp,
            x86ts32.__ss,
            x86ts32.__eflags,
            x86ts32.__eip,
            symbol->SymbolIDToName(symbol->AddressToSymbolID(x86ts32.__eip)),
            x86ts32.__cs,
            x86ts32.__ds,
            x86ts32.__es,
            x86ts32.__fs,
            x86ts32.__gs);

        // Traverse stack
        StackTrace(ti, symbol.get(), x86ts32.__ebp, x86ts32.__eip);
    }

    // Cleanup
    std::printf("ghd: Stack trace done, exiting\n");
    DeallocateThreadList(thread_list, thread_count);
}