Exemple #1
0
DECLARE_TEST(error, context) {
	error_context_t* context = 0;

	context = error_context();
	if (context)
		EXPECT_EQ(context->depth, 0);

	error_context_push(STRING_CONST("error test"), STRING_CONST("data"));
	context = error_context();

#if BUILD_ENABLE_ERROR_CONTEXT
	EXPECT_NE(context, 0);
	EXPECT_EQ(context->depth, 1);
	EXPECT_CONSTSTRINGEQ(context->frame[0].name, string_const(STRING_CONST("error test")));
	EXPECT_CONSTSTRINGEQ(context->frame[0].data, string_const(STRING_CONST("data")));
#else
	EXPECT_EQ(context, 0);
#endif

	error_context_pop();
	context = error_context();

#if BUILD_ENABLE_ERROR_CONTEXT
	EXPECT_NE(context, 0);
	EXPECT_EQ(context->depth, 0);
#else
	EXPECT_EQ(context, 0);
#endif

	error_context_push(STRING_CONST("error test"), STRING_CONST("data"));
	error_context_push(STRING_CONST("another test"), STRING_CONST("more data"));
	context = error_context();

#if BUILD_ENABLE_ERROR_CONTEXT
	EXPECT_NE(context, 0);
	EXPECT_EQ(context->depth, 2);
	EXPECT_CONSTSTRINGEQ(context->frame[0].name, string_const(STRING_CONST("error test")));
	EXPECT_CONSTSTRINGEQ(context->frame[0].data, string_const(STRING_CONST("data")));
	EXPECT_CONSTSTRINGEQ(context->frame[1].name, string_const(STRING_CONST("another test")));
	EXPECT_CONSTSTRINGEQ(context->frame[1].data, string_const(STRING_CONST("more data")));
#else
	EXPECT_EQ(context, 0);
#endif

	error_context_pop();
	context = error_context();

#if BUILD_ENABLE_ERROR_CONTEXT
	EXPECT_NE(context, 0);
	EXPECT_EQ(context->depth, 1);
	EXPECT_CONSTSTRINGEQ(context->frame[0].name, string_const(STRING_CONST("error test")));
	EXPECT_CONSTSTRINGEQ(context->frame[0].data, string_const(STRING_CONST("data")));
#else
	EXPECT_EQ(context, 0);
#endif

	error_context_pop();

	return 0;
}
Exemple #2
0
static int mce_severity_intel(struct mce *m, int tolerant, char **msg, bool is_excp)
{
	enum exception excp = (is_excp ? EXCP_CONTEXT : NO_EXCP);
	enum context ctx = error_context(m);
	struct severity *s;

	for (s = severities;; s++) {
		if ((m->status & s->mask) != s->result)
			continue;
		if ((m->mcgstatus & s->mcgmask) != s->mcgres)
			continue;
		if (s->ser == SER_REQUIRED && !mca_cfg.ser)
			continue;
		if (s->ser == NO_SER && mca_cfg.ser)
			continue;
		if (s->context && ctx != s->context)
			continue;
		if (s->excp && excp != s->excp)
			continue;
		if (msg)
			*msg = s->msg;
		s->covered = 1;
		if (s->sev >= MCE_UC_SEVERITY && ctx == IN_KERNEL) {
			if (tolerant < 1)
				return MCE_PANIC_SEVERITY;
		}
		return s->sev;
	}
}
Exemple #3
0
int htmllex()
{
#ifdef HAVE_EXPAT
    static char *begin_html = "<HTML>";
    static char *end_html = "</HTML>";

    char *s;
    char *endp = 0;
    int len, llen;
    int rv;

    state.tok = 0;
    do {
	if (state.mode == 2)
	    return EOF;
	if (state.mode == 0) {
	    state.mode = 1;
	    s = begin_html;
	    len = strlen(s);
	    endp = 0;
	} else {
	    s = state.ptr;
	    if (*s == '\0') {
		state.mode = 2;
		s = end_html;
		len = strlen(s);
	    } else {
		endp = findNext(s,&state.lb);
		len = endp - s;
	    }
	}
	state.prevtok = state.currtok;
	state.prevtoklen = state.currtoklen;
	state.currtok = s;
	state.currtoklen = len;
	if ((llen = agxblen(&state.lb)))
	    rv = XML_Parse(state.parser, agxbuse(&state.lb),llen, 0);
	else
	    rv = XML_Parse(state.parser, s, len, (len ? 0 : 1));
	if (rv == XML_STATUS_ERROR) {
	    if (!state.error) {
		agerr(AGERR, "%s in line %d \n",
		      XML_ErrorString(XML_GetErrorCode(state.parser)),
		      htmllineno());
		error_context();
		state.error = 1;
		state.tok = T_error;
	    }
	}
	if (endp)
	    state.ptr = endp;
    } while (state.tok == 0);
#if DEBUG
    printTok (state.tok);
#endif
    return state.tok;
#else
    return EOF;
#endif
}
int mce_severity(struct mce *m, int tolerant, char **msg)
{
	enum context ctx = error_context(m);
	struct severity *s;

	for (s = severities;; s++) {
		if ((m->status & s->mask) != s->result)
			continue;
		if ((m->mcgstatus & s->mcgmask) != s->mcgres)
			continue;
		if (s->ser == SER_REQUIRED && !mce_ser)
			continue;
		if (s->ser == NO_SER && mce_ser)
			continue;
		if (s->context && ctx != s->context)
			continue;
		if (msg)
			*msg = s->msg;
		s->covered = 1;
		if (s->sev >= MCE_UC_SEVERITY && ctx == IN_KERNEL) {
			if (panic_on_oops || tolerant < 1)
				return MCE_PANIC_SEVERITY;
		}
		return s->sev;
	}
}
Exemple #5
0
/* htmlerror:
 * yyerror - called by yacc output
 */
void htmlerror(const char *msg)
{
    if (state.error)
	return;
    state.error = 1;
    agerr(AGERR, "%s in line %d \n", msg, htmllineno());
    error_context();
}
Exemple #6
0
bool check_error()
{
	if (error_is_valid) {
		struct local_error *context = error_context();
		return context->is_error;
	}
	else {
		return false;
	}
}
Exemple #7
0
void log_error_context( uint64_t context, error_level_t error_level )
{
	int i;
	error_context_t* err_context = error_context();
	if( err_context && ( log_suppress( context ) < error_level ) )
	{
		error_frame_t* frame = err_context->frame;
		for( i = 0; i < err_context->depth; ++i, ++frame )
			_log_error_contextf( context, error_level, error_level > ERRORLEVEL_WARNING ? stderr : stdout, "When %s: %s", frame->name ? frame->name : "<something>", frame->data ? frame->data : "" );
	}
}
Exemple #8
0
const wchar_t *clear_error()
{
	if (error_is_valid) {
		struct local_error *context = error_context();
		if (context->is_error) {
			context->is_error = false;
			return context->error_message;
		}
	}
	return NULL;
}
Exemple #9
0
/*
 * See AMD Error Scope Hierarchy table in a newer BKDG. For example
 * 49125_15h_Models_30h-3Fh_BKDG.pdf, section "RAS Features"
 */
static int mce_severity_amd(struct mce *m, int tolerant, char **msg, bool is_excp)
{
	enum context ctx = error_context(m);

	/* Processor Context Corrupt, no need to fumble too much, die! */
	if (m->status & MCI_STATUS_PCC)
		return MCE_PANIC_SEVERITY;

	if (m->status & MCI_STATUS_UC) {

		/*
		 * On older systems where overflow_recov flag is not present, we
		 * should simply panic if an error overflow occurs. If
		 * overflow_recov flag is present and set, then software can try
		 * to at least kill process to prolong system operation.
		 */
		if (mce_flags.overflow_recov) {
			if (mce_flags.smca)
				return mce_severity_amd_smca(m, ctx);

			/* software can try to contain */
			if (!(m->mcgstatus & MCG_STATUS_RIPV) && (ctx == IN_KERNEL))
				return MCE_PANIC_SEVERITY;

			/* kill current process */
			return MCE_AR_SEVERITY;
		} else {
			/* at least one error was not logged */
			if (m->status & MCI_STATUS_OVER)
				return MCE_PANIC_SEVERITY;
		}

		/*
		 * For any other case, return MCE_UC_SEVERITY so that we log the
		 * error and exit #MC handler.
		 */
		return MCE_UC_SEVERITY;
	}

	/*
	 * deferred error: poll handler catches these and adds to mce_ring so
	 * memory-failure can take recovery actions.
	 */
	if (m->status & MCI_STATUS_DEFERRED)
		return MCE_DEFERRED_SEVERITY;

	/*
	 * corrected error: poll handler catches these and passes responsibility
	 * of decoding the error to EDAC
	 */
	return MCE_KEEP_SEVERITY;
}
Exemple #10
0
const char *errno_error(int err)
{
	if (error_is_valid) {
		struct local_error *context = error_context();
#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
		if (strerror_r(err, context->errno_message, HAKA_ERROR_SIZE) == 0) {
			context->error_message[HAKA_ERROR_SIZE-1] = 0;
			return context->errno_message;
		}
#else
		const char *res = strerror_r(err, context->errno_message, HAKA_ERROR_SIZE);
		if (res) return res;
#endif
	}

	return "Unknown error";
}
Exemple #11
0
void error(const wchar_t *error, ...)
{
	if (error_is_valid) {
		struct local_error *context = error_context();
		if (!context->is_error) {
			va_list ap;
			va_start(ap, error);
			vswprintf(context->error_message, HAKA_ERROR_SIZE, error, ap);
			context->error_message[HAKA_ERROR_SIZE-1] = 0;
			va_end(ap);

			context->is_error = true;

			BREAKPOINT;
		}
	}
}
Exemple #12
0
static void*
error_test_thread(void) {
	error_context_t* context = 0;

	EXPECT_EQ(error(), ERROR_NONE);
	EXPECT_EQ(error(), ERROR_NONE);

	error_report(ERRORLEVEL_WARNING, ERROR_ACCESS_DENIED);
	EXPECT_EQ(error(), ERROR_ACCESS_DENIED);
	EXPECT_EQ(error(), ERROR_NONE);

	error_report(ERRORLEVEL_ERROR, ERROR_INVALID_VALUE);
	EXPECT_EQ(error(), ERROR_INVALID_VALUE);
	EXPECT_EQ(error(), ERROR_NONE);

	context = error_context();
	if (context)
		EXPECT_EQ(context->depth, 0);

	error_context_push(STRING_CONST("error test"), STRING_CONST("data"));
	context = error_context();

#if BUILD_ENABLE_ERROR_CONTEXT
	EXPECT_NE(context, 0);
	EXPECT_EQ(context->depth, 1);
	EXPECT_CONSTSTRINGEQ(context->frame[0].name, string_const(STRING_CONST("error test")));
	EXPECT_CONSTSTRINGEQ(context->frame[0].data, string_const(STRING_CONST("data")));
#else
	EXPECT_EQ(context, 0);
#endif

	error_context_pop();
	context = error_context();

#if BUILD_ENABLE_ERROR_CONTEXT
	EXPECT_NE(context, 0);
	EXPECT_EQ(context->depth, 0);
#else
	EXPECT_EQ(context, 0);
#endif

	error_context_push(STRING_CONST("error test"), STRING_CONST("data"));
	error_context_push(STRING_CONST("another test"), STRING_CONST("more data"));
	context = error_context();

#if BUILD_ENABLE_ERROR_CONTEXT
	EXPECT_NE(context, 0);
	EXPECT_EQ(context->depth, 2);
	EXPECT_CONSTSTRINGEQ(context->frame[0].name, string_const(STRING_CONST("error test")));
	EXPECT_CONSTSTRINGEQ(context->frame[0].data, string_const(STRING_CONST("data")));
	EXPECT_CONSTSTRINGEQ(context->frame[1].name, string_const(STRING_CONST("another test")));
	EXPECT_CONSTSTRINGEQ(context->frame[1].data, string_const(STRING_CONST("more data")));
#else
	EXPECT_EQ(context, 0);
#endif

	error_context_pop();
	context = error_context();

#if BUILD_ENABLE_ERROR_CONTEXT
	EXPECT_NE(context, 0);
	EXPECT_EQ(context->depth, 1);
	EXPECT_CONSTSTRINGEQ(context->frame[0].name, string_const(STRING_CONST("error test")));
	EXPECT_CONSTSTRINGEQ(context->frame[0].data, string_const(STRING_CONST("data")));
#else
	EXPECT_EQ(context, 0);
#endif

	error_context_pop();

	return 0;
}
Exemple #13
0
DECLARE_TEST( error, context )
{
	error_context_t* context = 0;

	context = error_context();
	if( context )
		EXPECT_EQ( context->depth, 0 );

	error_context_push( "error test", "data" );
	context = error_context();

#if BUILD_ENABLE_ERROR_CONTEXT
	EXPECT_NE( context, 0 );
	EXPECT_EQ( context->depth, 1 );
	EXPECT_STREQ( context->frame[0].name, "error test" );
	EXPECT_STREQ( context->frame[0].data, "data" );
#else
	EXPECT_EQ( context, 0 );
#endif

	error_context_pop();
	context = error_context();

#if BUILD_ENABLE_ERROR_CONTEXT
	EXPECT_NE( context, 0 );
	EXPECT_EQ( context->depth, 0 );
#else
	EXPECT_EQ( context, 0 );
#endif

	error_context_push( "error test", "data" );
	error_context_push( "another test", "more data" );
	context = error_context();

#if BUILD_ENABLE_ERROR_CONTEXT
	EXPECT_NE( context, 0 );
	EXPECT_EQ( context->depth, 2 );
	EXPECT_STREQ( context->frame[0].name, "error test" );
	EXPECT_STREQ( context->frame[0].data, "data" );
	EXPECT_STREQ( context->frame[1].name, "another test" );
	EXPECT_STREQ( context->frame[1].data, "more data" );
#else
	EXPECT_EQ( context, 0 );
#endif

	error_context_pop();
	context = error_context();

#if BUILD_ENABLE_ERROR_CONTEXT
	EXPECT_NE( context, 0 );
	EXPECT_EQ( context->depth, 1 );
	EXPECT_STREQ( context->frame[0].name, "error test" );
	EXPECT_STREQ( context->frame[0].data, "data" );
#else
	EXPECT_EQ( context, 0 );
#endif

	error_context_pop();

	return 0;
}
Exemple #14
0
 void DisassemblerContext::print_functional_term(const ValuePtr<FunctionalValue>& term, bool bracket) {
   if (ValuePtr<BooleanValue> bool_value = dyn_cast<BooleanValue>(term)) {
     *m_output << (bool_value->value() ? "true" : "false");
   } else if (ValuePtr<IntegerType> int_type = dyn_cast<IntegerType>(term)) {
     if (!int_type->is_signed())
       *m_output << 'u';
     *m_output << 'i';
     const char *width;
     switch (int_type->width()) {
     case IntegerType::i8: width = "8"; break;
     case IntegerType::i16: width = "16"; break;
     case IntegerType::i32: width = "32"; break;
     case IntegerType::i64: width = "64"; break;
     case IntegerType::i128: width = "128"; break;
     case IntegerType::iptr: width = "ptr"; break;
     default: PSI_FAIL("unknown integer width");
     }
     *m_output << width;
   } else if (ValuePtr<IntegerValue> int_value = dyn_cast<IntegerValue>(term)) {
     ValuePtr<IntegerType> type = int_value->type();
     *m_output << '#';
     if (!type->is_signed())
       *m_output << 'u';
     char width;
     switch (type->width()) {
     case IntegerType::i8: width = 'b'; break;
     case IntegerType::i16: width = 's'; break;
     case IntegerType::i32: width = 'i'; break;
     case IntegerType::i64: width = 'l'; break;
     case IntegerType::i128: width = 'q'; break;
     case IntegerType::iptr: width = 'p'; break;
     default: PSI_FAIL("unknown integer width");
     }
     *m_output << width;
     int_value->value().print(error_context().bind(term->location()), *m_output, type->is_signed());
   } else if (ValuePtr<FloatType> float_type = dyn_cast<FloatType>(term)) {
     const char *width;
     switch (float_type->width()) {
     case FloatType::fp32: width = "fp32"; break;
     case FloatType::fp64: width = "fp64"; break;
     case FloatType::fp128: width = "fp128"; break;
     case FloatType::fp_x86_80: width = "fp-x86-80"; break;
     case FloatType::fp_ppc_128: width = "fp-ppc-128"; break;
     default: PSI_FAIL("unknown integer width");
     }
     *m_output << width;
   } else if (ValuePtr<ResolvedParameter> resolved_param = dyn_cast<ResolvedParameter>(term)) {
     ParameterNameList::reverse_iterator it = m_parameter_names.rbegin();
     if (resolved_param->depth() < m_parameter_names.size()) {
       std::advance(it, resolved_param->depth());
       PSI_ASSERT(resolved_param->index() < it->size());
       *m_output << (*it)[resolved_param->index()];
     } else {
       *m_output << "[unknown parameter : ";
       print_term(resolved_param->type(), false);
       *m_output << "]";
     }
   } else if (ValuePtr<UnwrapParameter> unwrap_param = dyn_cast<UnwrapParameter>(term)) {
     *m_output << "unwrap_param ";
     print_term(unwrap_param->value(), true);
     *m_output << " " << unwrap_param->index();
   } else {
     class MyVisitor : public FunctionalValueVisitor {
       DisassemblerContext *m_self;
       const char *m_operation;
       bool m_bracket;
       bool m_first;
       
     public:
       MyVisitor(DisassemblerContext *self, const char *operation, bool bracket)
       : m_self(self), m_operation(operation), m_bracket(bracket), m_first(true) {}
       
       virtual void next(const ValuePtr<>& ptr) {
         if (m_first) {
           if (m_bracket)
             *m_self->m_output << '(';
           *m_self->m_output << m_operation;
           m_first = false;
         }
         
         *m_self->m_output << ' ';
         m_self->print_term(ptr, true);
       }
       
       bool empty() const {return m_first;}
     };
     
     MyVisitor my_visitor(this, term->operation_name(), bracket);
     term->functional_visit(my_visitor);
     
     if (my_visitor.empty()) {
       *m_output << term->operation_name();
     } else if (bracket) {
       *m_output << ')';
     }
   }
 }
Exemple #15
0
DECLARE_TEST(exception, error) {
    error_handler_fn handler;
    int ret;

    error();
    EXPECT_EQ(error(), ERROR_NONE);

    error_report(ERRORLEVEL_ERROR, ERROR_NONE);
    EXPECT_EQ(error(), ERROR_NONE);

    error_report(ERRORLEVEL_ERROR, ERROR_EXCEPTION);
    EXPECT_EQ(error(), ERROR_EXCEPTION);

    handler = error_handler();
    error_set_handler(_error_handler_test);

    ret = error_report(ERRORLEVEL_WARNING, ERROR_INVALID_VALUE);
    EXPECT_EQ(error(), ERROR_INVALID_VALUE);
    EXPECT_EQ(ret, 2);
    EXPECT_EQ(_error_level_test, ERRORLEVEL_WARNING);
    EXPECT_EQ(_error_test, ERROR_INVALID_VALUE);
    EXPECT_EQ(error_handler(), _error_handler_test);

    error_set_handler(handler);

    {
#if BUILD_ENABLE_ERROR_CONTEXT
        const char context_data[] = "another message";
#endif
        char context_buffer[512];
        string_t contextstr;
        error_context_clear();
        error_context_push(STRING_CONST("test context"), STRING_CONST("some message"));
        error_context_push(STRING_CONST("foo bar"), 0, 0);
        error_context_pop();
        error_context_pop();
        error_context_pop();
        error_context_push(STRING_CONST("test context"), STRING_CONST(context_data));

#if BUILD_ENABLE_ERROR_CONTEXT
        EXPECT_NE(error_context(), 0);
        EXPECT_EQ(error_context()->depth, 1);
        EXPECT_CONSTSTRINGEQ(error_context()->frame[0].name, string_const(STRING_CONST("test context")));
        EXPECT_EQ(error_context()->frame[0].data.str, context_data);
        EXPECT_EQ(error_context()->frame[0].data.length, sizeof(context_data) - 1);
#endif

        contextstr = error_context_buffer(context_buffer, 512);
#if BUILD_ENABLE_ERROR_CONTEXT
        EXPECT_NE_MSGFORMAT(string_find_string(STRING_ARGS(contextstr), STRING_CONST("test context"), 0),
                            STRING_NPOS, "context name 'test context' not found in buffer: %s", context_buffer);
        EXPECT_NE_MSGFORMAT(string_find_string(STRING_ARGS(contextstr), STRING_CONST(context_data), 0),
                            STRING_NPOS, "context data '%s' not found in buffer: %s", context_data, context_buffer);
#else
        EXPECT_EQ(contextstr.length, 0);
#endif

        error_context_clear();
        contextstr = error_context_buffer(context_buffer, 512);
#if BUILD_ENABLE_ERROR_CONTEXT
        EXPECT_STRINGEQ(contextstr, string_empty());
#endif
    }

    return 0;
}