2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>

* libcsupport/include/rtems/error.h, libcsupport/src/error.c: Clean up
	so rtems_panic() can be a noreturn method. This eliminates some
	unreachable and thus untestable code.
This commit is contained in:
Joel Sherrill
2010-06-28 22:13:55 +00:00
parent 89b897f020
commit 1d33ecab00
3 changed files with 120 additions and 120 deletions

View File

@@ -1,3 +1,9 @@
2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
* libcsupport/include/rtems/error.h, libcsupport/src/error.c: Clean up
so rtems_panic() can be a noreturn method. This eliminates some
unreachable and thus untestable code.
2010-06-28 Joel Sherrill <joel.sherrilL@OARcorp.com> 2010-06-28 Joel Sherrill <joel.sherrilL@OARcorp.com>
* libcsupport/src/termios.c: Formatting. * libcsupport/src/termios.c: Formatting.

View File

@@ -34,22 +34,19 @@ typedef Internal_errors_t rtems_error_code_t;
#define RTEMS_ERROR_ABORT (0x10000000) /* err is fatal; panic */ #define RTEMS_ERROR_ABORT (0x10000000) /* err is fatal; panic */
#endif #endif
#define RTEMS_ERROR_MASK (RTEMS_ERROR_ERRNO | RTEMS_ERROR_ABORT | \ #define RTEMS_ERROR_MASK \
RTEMS_ERROR_PANIC) /* all */ (RTEMS_ERROR_ERRNO | RTEMS_ERROR_ABORT | RTEMS_ERROR_PANIC) /* all */
const char *rtems_status_text(rtems_status_code); const char *rtems_status_text(rtems_status_code);
int rtems_error(rtems_error_code_t error_code, const char *printf_format, ...); int rtems_error(
#ifdef __GNUC__ rtems_error_code_t error_code,
void rtems_panic(const char *printf_format, ...); const char *printf_format,
/* ...
* We should be able to use this attribute but gcc complains that );
* rtems_panic does in fact return. :( void rtems_panic(
* const char *printf_format,
* __attribute__ ((__noreturn__)); ...
*/ ) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
#else
void rtems_panic(const char *printf_format, ...);
#endif
extern int rtems_panic_in_progress; extern int rtems_panic_in_progress;

View File

@@ -16,17 +16,17 @@
* *
* error_flag can be specified as any of the following: * error_flag can be specified as any of the following:
* *
* RTEMS_ERROR_ERRNO -- include errno text in output * RTEMS_ERROR_ERRNO -- include errno text in output
* RTEMS_ERROR_PANIC -- halts local system after output * RTEMS_ERROR_PANIC -- halts local system after output
* RTEMS_ERROR_ABORT -- abort after output * RTEMS_ERROR_ABORT -- abort after output
* *
* It can also include a rtems_status value which can be OR'd * It can also include a rtems_status value which can be OR'd
* with the above flags. * * with the above flags. *
* *
* EXAMPLE * EXAMPLE
* #include <rtems.h> * #include <rtems.h>
* #include <rtems/error.h> * #include <rtems/error.h>
* rtems_error(0, "stray interrupt %d", intr); * rtems_error(0, "stray interrupt %d", intr);
* *
* EXAMPLE * EXAMPLE
* if ((status = rtems_task_create(...)) != RTEMS_SUCCCESSFUL) * if ((status = rtems_task_create(...)) != RTEMS_SUCCCESSFUL)
@@ -54,115 +54,100 @@
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> /* _exit() */ #include <unistd.h> /* _exit() */
int rtems_panic_in_progress; int rtems_panic_in_progress;
const rtems_assoc_t rtems_status_assoc[] = { const rtems_assoc_t rtems_status_assoc[] = {
{ "successful completion", RTEMS_SUCCESSFUL, 0 }, { "successful completion", RTEMS_SUCCESSFUL, 0 },
{ "returned from a thread", RTEMS_TASK_EXITTED, 0 }, { "returned from a thread", RTEMS_TASK_EXITTED, 0 },
{ "multiprocessing not configured", RTEMS_MP_NOT_CONFIGURED, 0 }, { "multiprocessing not configured", RTEMS_MP_NOT_CONFIGURED, 0 },
{ "invalid object name", RTEMS_INVALID_NAME, 0 }, { "invalid object name", RTEMS_INVALID_NAME, 0 },
{ "invalid object id", RTEMS_INVALID_ID, 0 }, { "invalid object id", RTEMS_INVALID_ID, 0 },
{ "too many", RTEMS_TOO_MANY, 0 }, { "too many", RTEMS_TOO_MANY, 0 },
{ "timed out waiting", RTEMS_TIMEOUT, 0 }, { "timed out waiting", RTEMS_TIMEOUT, 0 },
{ "object deleted while waiting", RTEMS_OBJECT_WAS_DELETED, 0 }, { "object deleted while waiting", RTEMS_OBJECT_WAS_DELETED, 0 },
{ "specified size was invalid", RTEMS_INVALID_SIZE, 0 }, { "specified size was invalid", RTEMS_INVALID_SIZE, 0 },
{ "address specified is invalid", RTEMS_INVALID_ADDRESS, 0 }, { "address specified is invalid", RTEMS_INVALID_ADDRESS, 0 },
{ "number was invalid", RTEMS_INVALID_NUMBER, 0 }, { "number was invalid", RTEMS_INVALID_NUMBER, 0 },
{ "item has not been initialized", RTEMS_NOT_DEFINED, 0 }, { "item has not been initialized", RTEMS_NOT_DEFINED, 0 },
{ "resources still outstanding", RTEMS_RESOURCE_IN_USE, 0 }, { "resources still outstanding", RTEMS_RESOURCE_IN_USE, 0 },
{ "request not satisfied", RTEMS_UNSATISFIED, 0 }, { "request not satisfied", RTEMS_UNSATISFIED, 0 },
{ "thread is in wrong state", RTEMS_INCORRECT_STATE, 0 }, { "thread is in wrong state", RTEMS_INCORRECT_STATE, 0 },
{ "thread already in state", RTEMS_ALREADY_SUSPENDED, 0 }, { "thread already in state", RTEMS_ALREADY_SUSPENDED, 0 },
{ "illegal on calling thread", RTEMS_ILLEGAL_ON_SELF, 0 }, { "illegal on calling thread", RTEMS_ILLEGAL_ON_SELF, 0 },
{ "illegal for remote object", RTEMS_ILLEGAL_ON_REMOTE_OBJECT, 0 }, { "illegal for remote object", RTEMS_ILLEGAL_ON_REMOTE_OBJECT, 0 },
{ "called from wrong environment", RTEMS_CALLED_FROM_ISR, 0 }, { "called from wrong environment", RTEMS_CALLED_FROM_ISR, 0 },
{ "invalid thread priority", RTEMS_INVALID_PRIORITY, 0 }, { "invalid thread priority", RTEMS_INVALID_PRIORITY, 0 },
{ "invalid date/time", RTEMS_INVALID_CLOCK, 0 }, { "invalid date/time", RTEMS_INVALID_CLOCK, 0 },
{ "invalid node id", RTEMS_INVALID_NODE, 0 }, { "invalid node id", RTEMS_INVALID_NODE, 0 },
{ "directive not configured", RTEMS_NOT_CONFIGURED, 0 }, { "directive not configured", RTEMS_NOT_CONFIGURED, 0 },
{ "not owner of resource", RTEMS_NOT_OWNER_OF_RESOURCE , 0 }, { "not owner of resource", RTEMS_NOT_OWNER_OF_RESOURCE , 0 },
{ "directive not implemented", RTEMS_NOT_IMPLEMENTED, 0 }, { "directive not implemented", RTEMS_NOT_IMPLEMENTED, 0 },
{ "RTEMS inconsistency detected", RTEMS_INTERNAL_ERROR, 0 }, { "RTEMS inconsistency detected", RTEMS_INTERNAL_ERROR, 0 },
{ "could not get enough memory", RTEMS_NO_MEMORY, 0 }, { "could not get enough memory", RTEMS_NO_MEMORY, 0 },
{ "driver IO error", RTEMS_IO_ERROR, 0 }, { "driver IO error", RTEMS_IO_ERROR, 0 },
{ "internal multiprocessing only", THREAD_STATUS_PROXY_BLOCKING, 0 }, { "internal multiprocessing only", THREAD_STATUS_PROXY_BLOCKING, 0 },
{ 0, 0, 0 }, { 0, 0, 0 },
}; };
const char * const char *rtems_status_text(
rtems_status_text( rtems_status_code status
rtems_status_code status
) )
{ {
return rtems_assoc_name_by_local(rtems_status_assoc, status); return rtems_assoc_name_by_local(rtems_status_assoc, status);
} }
static int rtems_verror( static int rtems_verror(
rtems_error_code_t error_flag, rtems_error_code_t error_flag,
const char *printf_format, const char *printf_format,
va_list arglist va_list arglist
) )
{ {
int local_errno = 0; int local_errno = 0;
int chars_written = 0; int chars_written = 0;
rtems_status_code status; rtems_status_code status;
if (error_flag & RTEMS_ERROR_PANIC) if (error_flag & RTEMS_ERROR_PANIC) {
{ if (rtems_panic_in_progress++)
if (rtems_panic_in_progress++) _Thread_Disable_dispatch(); /* disable task switches */
_Thread_Disable_dispatch(); /* disable task switches */
/* don't aggravate things */ /* don't aggravate things */
if (rtems_panic_in_progress > 2) if (rtems_panic_in_progress > 2)
return 0; return 0;
} }
(void) fflush(stdout); /* in case stdout/stderr same */ (void) fflush(stdout); /* in case stdout/stderr same */
status = error_flag & ~RTEMS_ERROR_MASK; status = error_flag & ~RTEMS_ERROR_MASK;
if (error_flag & RTEMS_ERROR_ERRNO) /* include errno? */ if (error_flag & RTEMS_ERROR_ERRNO) /* include errno? */
local_errno = errno; local_errno = errno;
#if defined(RTEMS_MULTIPROCESSING) #if defined(RTEMS_MULTIPROCESSING)
if (_System_state_Is_multiprocessing) if (_System_state_Is_multiprocessing)
fprintf(stderr, "[%" PRIu32 "] ", _Configuration_MP_table->node); fprintf(stderr, "[%" PRIu32 "] ", _Configuration_MP_table->node);
#endif #endif
chars_written += vfprintf(stderr, printf_format, arglist); chars_written += vfprintf(stderr, printf_format, arglist);
if (status) if (status)
chars_written += fprintf(stderr, " (status: %s)", rtems_status_text(status)); chars_written +=
fprintf(stderr, " (status: %s)", rtems_status_text(status));
if (local_errno) if (local_errno) {
{ if ((local_errno > 0) && *strerror(local_errno))
if ((local_errno > 0) && *strerror(local_errno)) chars_written += fprintf(stderr, " (errno: %s)", strerror(local_errno));
chars_written += fprintf(stderr, " (errno: %s)", strerror(local_errno)); else
else chars_written += fprintf(stderr, " (unknown errno=%d)", local_errno);
chars_written += fprintf(stderr, " (unknown errno=%d)", local_errno); }
}
chars_written += fprintf(stderr, "\n"); chars_written += fprintf(stderr, "\n");
(void) fflush(stderr); (void) fflush(stderr);
if (error_flag & (RTEMS_ERROR_PANIC | RTEMS_ERROR_ABORT)) return chars_written;
{
if (error_flag & RTEMS_ERROR_PANIC)
{
rtems_error(0, "fatal error, exiting");
_exit(local_errno);
}
else
{
rtems_error(0, "fatal error, aborting");
abort();
}
}
return chars_written;
} }
@@ -175,19 +160,28 @@ static int rtems_verror(
*/ */
int rtems_error( int rtems_error(
rtems_error_code_t error_flag, rtems_error_code_t error_flag,
const char *printf_format, const char *printf_format,
... ...
) )
{ {
va_list arglist; va_list arglist;
int chars_written; int chars_written;
va_start(arglist, printf_format); va_start(arglist, printf_format);
chars_written = rtems_verror(error_flag, printf_format, arglist); chars_written = rtems_verror(error_flag, printf_format, arglist);
va_end(arglist); va_end(arglist);
return chars_written; if (error_flag & RTEMS_ERROR_PANIC) {
rtems_error(0, "fatal error, exiting");
_exit(errno);
}
if (error_flag & RTEMS_ERROR_ABORT) {
rtems_error(0, "fatal error, aborting");
abort();
}
return chars_written;
} }
/* /*
@@ -195,13 +189,16 @@ int rtems_error(
*/ */
void rtems_panic( void rtems_panic(
const char *printf_format, const char *printf_format,
... ...
) )
{ {
va_list arglist; va_list arglist;
va_start(arglist, printf_format); va_start(arglist, printf_format);
(void) rtems_verror(RTEMS_ERROR_PANIC, printf_format, arglist); (void) rtems_verror(RTEMS_ERROR_PANIC, printf_format, arglist);
va_end(arglist); va_end(arglist);
rtems_error(0, "fatal error, exiting");
_exit(errno);
} }