Пример #1
0
/**
 * Common error routines for wpi_assertEqual_impl and wpi_assertNotEqual_impl
 * This should not be called directly; it should only be used by
 * wpi_assertEqual_impl
 * and wpi_assertNotEqual_impl.
 */
void wpi_assertEqual_common_impl(const char *valueA, const char *valueB,
                                 const char *equalityType,
                                 const char *message,
                                 const char *fileName,
                                 uint32_t lineNumber,
                                 const char *funcName) {
  std::stringstream errorStream;

  errorStream << "Assertion \"" << valueA << " " << equalityType << " "
              << valueB << "\" ";
  errorStream << "on line " << lineNumber << " ";
  errorStream << "of " << basename(fileName) << " ";

  if (message[0] != '\0') {
    errorStream << "failed: " << message << std::endl;
  } else {
    errorStream << "failed." << std::endl;
  }

  errorStream << GetStackTrace(3);

  std::string error = errorStream.str();

  // Print the error and send it to the DriverStation
  std::cout << error << std::endl;
  HALSetErrorData(error.c_str(), error.size(), 100);
}
Пример #2
0
bool CLogFile::WriteCallStackLog(FontColor fc, const char* szFormat, va_list vlArgs)
{
    char szLogInfo[LOG_INFO_MAX_LEN];
    memset(szLogInfo, 0, LOG_INFO_MAX_LEN);
    int nLogInfoLen = FormatLogInfo(szLogInfo, szFormat, vlArgs);
    if (nLogInfoLen <= 0)
        return false;

    fwrite(szLogInfo, 1, nLogInfoLen, m_pLogFile);
    if (m_bWriteToStdout)
        WriteInfoToStdout(fc, szLogInfo);

#ifdef linux
    // 打印调用堆栈信息
    memset(szLogInfo, 0, LOG_INFO_MAX_LEN);
    int nBackTraceLen = GetStackTrace(szLogInfo);
    if (nBackTraceLen > 0)
    {
        fwrite(szLogInfo, 1, nBackTraceLen, m_pLogFile);
        if (m_bWriteToStdout)
            WriteInfoToStdout(fc, szLogInfo);
    }
#endif // linux

    return true;
}
Пример #3
0
/**
 * Assert implementation.
 * This allows breakpoints to be set on an assert.
 * The users don't call this, but instead use the wpi_assert macros in
 * Utility.h.
 */
bool wpi_assert_impl(bool conditionValue, const char *conditionText,
                     const char *message, const char *fileName,
                     uint32_t lineNumber, const char *funcName) {
  if (!conditionValue) {
    std::stringstream errorStream;

    errorStream << "Assertion \"" << conditionText << "\" ";
    errorStream << "on line " << lineNumber << " ";
    errorStream << "of " << basename(fileName) << " ";

    if (message[0] != '\0') {
      errorStream << "failed: " << message << std::endl;
    } else {
      errorStream << "failed." << std::endl;
    }

    errorStream << GetStackTrace(2);

    std::string error = errorStream.str();

    // Print the error and send it to the DriverStation
    std::cout << error << std::endl;
    HALSetErrorData(error.c_str(), error.size(), 100);
  }

  return conditionValue;
}
Пример #4
0
CObjectOStream::TFailFlags CObjectOStream::SetFailFlags(TFailFlags flags,
                                                        const char* message)
{
    TFailFlags old = m_Fail;
    m_Fail |= flags;
    if ( !old && flags ) {
        // first fail
        ERR_POST_X(5, "CObjectOStream: error at "<<
                   GetPosition()<<": "<<GetStackTrace() << ": " << message);
    }
    return old;
}
Пример #5
0
void Error::Report() {
  std::stringstream errorStream;

  errorStream << "Error on line " << m_lineNumber << " ";
  errorStream << "of " << basename(m_filename.c_str()) << ": ";
  errorStream << m_message << std::endl;
  errorStream << GetStackTrace(4);

  std::string error = errorStream.str();

  DriverStation::ReportError(error);
}
Пример #6
0
String *StackTraceFormatter::GetStackTrace(Thread *const thread)
{
	try
	{
		StringBuffer buf(STRING_BUFFER_CAPACITY);

		GetStackTrace(thread, buf);

		return buf.ToString(thread);
	}
	catch (std::exception&)
	{
		return nullptr;
	}
}
Пример #7
0
void Error::Report() {
  std::stringstream locStream;
  locStream << m_function << " [";

#if defined(_WIN32)
	const int MAX_DIR = 100;
	char basename[MAX_DIR];
	_splitpath_s(m_filename.c_str(), NULL, 0, basename, MAX_DIR, NULL, 0, NULL, 0);
	locStream << basename;
#else
	locStream << basename(m_filename.c_str());
#endif
  locStream << ":" << m_lineNumber << "]";

  DriverStation::ReportError(true, m_code, m_message, locStream.str(),
                             GetStackTrace(4));
}
Пример #8
0
	xgc_void DumpStackFrame()
	{
		StackFrameSequence FrameSequence;
		GetStackTrace( FrameSequence );

		xgc_char szSymbol[sizeof( SYMBOL_INFO ) + 1024];
		SYS_TIP( "---------------stack frame begin--------------" );

		for( UINT nCur = 0; nCur < FrameSequence.Count && FrameSequence.Frame[nCur]; ++nCur )
		{
			ZeroMemory( szSymbol, sizeof( szSymbol ) );
			PSYMBOL_INFO pSymInfo = (PSYMBOL_INFO) &szSymbol;

			pSymInfo->SizeOfStruct = sizeof( SYMBOL_INFO );
			pSymInfo->MaxNameLen = sizeof( szSymbol ) - sizeof( SYMBOL_INFO );

			// Get the function.
			DWORD64 dwDisp = 0;
			if( SymFromAddr( hProcess, (UINT_PTR)FrameSequence.Frame[nCur], &dwDisp, pSymInfo ) )
			{
				// If I got a symbol, give the source and line a whirl.
				IMAGEHLP_LINE lineInfo;
				lineInfo.SizeOfStruct = sizeof( lineInfo );

				DWORD dwDisplacement = 0;
				if( SymGetLineFromAddr( hProcess, (UINT_PTR)FrameSequence.Frame[nCur], &dwDisplacement, &lineInfo ) )
				{
					// Put this on the next line and indented a bit.
					LOG_EXT_FORMAT( SYS, lineInfo.FileName, pSymInfo->Name, lineInfo.LineNumber, "stack", "stack frame %p : %s", FrameSequence.Frame[nCur], pSymInfo->Name );
				}
				else
				{
					LOG_TAG_FORMAT( SYS, "stack", "LastError:[%u], stack frame %p", GetLastError(), FrameSequence.Frame[nCur], pSymInfo->Name );
				}
			}
			else
			{
				LOG_TAG_FORMAT( SYS, "stack", "stack frame %p", FrameSequence.Frame[nCur] );
			}
		}
		SYS_TIP( "---------------stack frame end--------------" );
	}
Пример #9
0
const std::string& ExceptionBase::ToString() const
{
    if (mWhat.empty())
    {
        if (mLine > 0)
            mWhat = std::string(mFile) + "(" + mLine + ")";
        else
            mWhat = "<unknown throw location>";
        mWhat += ": " + GetClassName();
        std::string customizedString = GetMessage();
        if (!customizedString.empty())
        {
            mWhat += ": " + customizedString;
        }
        mWhat += "\nStack trace:\n";
        mWhat += GetStackTrace();
        if (mNestedException.get())
        {
            mWhat += "Caused by:\n" + mNestedException->ToString();
        }
    }
    return mWhat;
}