Changeset 1d33ecab in rtems


Ignore:
Timestamp:
Jun 28, 2010, 10:13:55 PM (9 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.11, master
Children:
45fcb76
Parents:
89b897f0
Message:

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

  • 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.
Location:
cpukit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r89b897f0 r1d33ecab  
     12010-06-28      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * libcsupport/include/rtems/error.h, libcsupport/src/error.c: Clean up
     4        so rtems_panic() can be a noreturn method. This eliminates some
     5        unreachable and thus untestable code.
     6
    172010-06-28      Joel Sherrill <joel.sherrilL@OARcorp.com>
    28
  • cpukit/libcsupport/include/rtems/error.h

    r89b897f0 r1d33ecab  
    3535#endif
    3636
    37 #define RTEMS_ERROR_MASK  (RTEMS_ERROR_ERRNO | RTEMS_ERROR_ABORT | \
    38                             RTEMS_ERROR_PANIC) /* all */
     37#define RTEMS_ERROR_MASK \
     38  (RTEMS_ERROR_ERRNO | RTEMS_ERROR_ABORT | RTEMS_ERROR_PANIC) /* all */
    3939
    4040const char *rtems_status_text(rtems_status_code);
    41 int   rtems_error(rtems_error_code_t error_code, const char *printf_format, ...);
    42 #ifdef __GNUC__
    43 void  rtems_panic(const char *printf_format, ...);
    44 /*
    45  *  We should be able to use this attribute but gcc complains that
    46  *  rtems_panic does in fact return. :(
    47  *
    48  *      __attribute__ ((__noreturn__));
    49  */
    50 #else
    51 void  rtems_panic(const char *printf_format, ...);
    52 #endif
     41int   rtems_error(
     42  rtems_error_code_t error_code,
     43  const char *printf_format,
     44  ...
     45);
     46void rtems_panic(
     47  const char *printf_format,
     48  ...
     49) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
    5350
    5451extern int rtems_panic_in_progress;
  • cpukit/libcsupport/src/error.c

    r89b897f0 r1d33ecab  
    1717 * error_flag can be specified as any of the following:
    1818 *
    19  *      RTEMS_ERROR_ERRNO       -- include errno text in output
    20  *      RTEMS_ERROR_PANIC       -- halts local system after output
    21  *      RTEMS_ERROR_ABORT       -- abort after output
     19 *  RTEMS_ERROR_ERRNO       -- include errno text in output
     20 *  RTEMS_ERROR_PANIC       -- halts local system after output
     21 *  RTEMS_ERROR_ABORT       -- abort after output
    2222 *
    2323 * It can also include a rtems_status value which can be OR'd
     
    2525 *
    2626 * EXAMPLE
    27  *      #include <rtems.h>
    28  *      #include <rtems/error.h>
    29  *      rtems_error(0, "stray interrupt %d", intr);
     27 *  #include <rtems.h>
     28 *  #include <rtems/error.h>
     29 *  rtems_error(0, "stray interrupt %d", intr);
    3030 *
    3131 * EXAMPLE
     
    5555#include <stdlib.h>
    5656#include <string.h>
    57 #include <unistd.h>             /* _exit() */
     57#include <unistd.h>     /* _exit() */
    5858
    5959int          rtems_panic_in_progress;
    6060
    6161const rtems_assoc_t rtems_status_assoc[] = {
    62     { "successful completion",              RTEMS_SUCCESSFUL, 0 },
    63     { "returned from a thread",             RTEMS_TASK_EXITTED, 0 },
    64     { "multiprocessing not configured",     RTEMS_MP_NOT_CONFIGURED, 0 },
    65     { "invalid object name",                RTEMS_INVALID_NAME, 0 },
    66     { "invalid object id",                  RTEMS_INVALID_ID, 0 },
    67     { "too many",                           RTEMS_TOO_MANY, 0 },
    68     { "timed out waiting",                  RTEMS_TIMEOUT, 0 },
    69     { "object deleted while waiting",       RTEMS_OBJECT_WAS_DELETED, 0 },
    70     { "specified size was invalid",         RTEMS_INVALID_SIZE, 0 },
    71     { "address specified is invalid",       RTEMS_INVALID_ADDRESS, 0 },
    72     { "number was invalid",                 RTEMS_INVALID_NUMBER, 0 },
    73     { "item has not been initialized",      RTEMS_NOT_DEFINED, 0 },
    74     { "resources still outstanding",        RTEMS_RESOURCE_IN_USE, 0 },
    75     { "request not satisfied",              RTEMS_UNSATISFIED, 0 },
    76     { "thread is in wrong state",           RTEMS_INCORRECT_STATE, 0 },
    77     { "thread already in state",            RTEMS_ALREADY_SUSPENDED, 0 },
    78     { "illegal on calling thread",          RTEMS_ILLEGAL_ON_SELF, 0 },
    79     { "illegal for remote object",          RTEMS_ILLEGAL_ON_REMOTE_OBJECT, 0 },
    80     { "called from wrong environment",      RTEMS_CALLED_FROM_ISR, 0 },
    81     { "invalid thread priority",            RTEMS_INVALID_PRIORITY, 0 },
    82     { "invalid date/time",                  RTEMS_INVALID_CLOCK, 0 },
    83     { "invalid node id",                    RTEMS_INVALID_NODE, 0 },
    84     { "directive not configured",           RTEMS_NOT_CONFIGURED, 0 },
    85     { "not owner of resource",              RTEMS_NOT_OWNER_OF_RESOURCE , 0 },
    86     { "directive not implemented",          RTEMS_NOT_IMPLEMENTED, 0 },
    87     { "RTEMS inconsistency detected",       RTEMS_INTERNAL_ERROR, 0 },
    88     { "could not get enough memory",        RTEMS_NO_MEMORY, 0 },
    89     { "driver IO error",                    RTEMS_IO_ERROR, 0 },
    90     { "internal multiprocessing only",      THREAD_STATUS_PROXY_BLOCKING, 0 },
    91     { 0, 0, 0 },
     62  { "successful completion",              RTEMS_SUCCESSFUL, 0 },
     63  { "returned from a thread",             RTEMS_TASK_EXITTED, 0 },
     64  { "multiprocessing not configured",     RTEMS_MP_NOT_CONFIGURED, 0 },
     65  { "invalid object name",                RTEMS_INVALID_NAME, 0 },
     66  { "invalid object id",                  RTEMS_INVALID_ID, 0 },
     67  { "too many",                           RTEMS_TOO_MANY, 0 },
     68  { "timed out waiting",                  RTEMS_TIMEOUT, 0 },
     69  { "object deleted while waiting",       RTEMS_OBJECT_WAS_DELETED, 0 },
     70  { "specified size was invalid",         RTEMS_INVALID_SIZE, 0 },
     71  { "address specified is invalid",       RTEMS_INVALID_ADDRESS, 0 },
     72  { "number was invalid",                 RTEMS_INVALID_NUMBER, 0 },
     73  { "item has not been initialized",      RTEMS_NOT_DEFINED, 0 },
     74  { "resources still outstanding",        RTEMS_RESOURCE_IN_USE, 0 },
     75  { "request not satisfied",              RTEMS_UNSATISFIED, 0 },
     76  { "thread is in wrong state",           RTEMS_INCORRECT_STATE, 0 },
     77  { "thread already in state",            RTEMS_ALREADY_SUSPENDED, 0 },
     78  { "illegal on calling thread",          RTEMS_ILLEGAL_ON_SELF, 0 },
     79  { "illegal for remote object",          RTEMS_ILLEGAL_ON_REMOTE_OBJECT, 0 },
     80  { "called from wrong environment",      RTEMS_CALLED_FROM_ISR, 0 },
     81  { "invalid thread priority",            RTEMS_INVALID_PRIORITY, 0 },
     82  { "invalid date/time",                  RTEMS_INVALID_CLOCK, 0 },
     83  { "invalid node id",                    RTEMS_INVALID_NODE, 0 },
     84  { "directive not configured",           RTEMS_NOT_CONFIGURED, 0 },
     85  { "not owner of resource",              RTEMS_NOT_OWNER_OF_RESOURCE , 0 },
     86  { "directive not implemented",          RTEMS_NOT_IMPLEMENTED, 0 },
     87  { "RTEMS inconsistency detected",       RTEMS_INTERNAL_ERROR, 0 },
     88  { "could not get enough memory",        RTEMS_NO_MEMORY, 0 },
     89  { "driver IO error",                    RTEMS_IO_ERROR, 0 },
     90  { "internal multiprocessing only",      THREAD_STATUS_PROXY_BLOCKING, 0 },
     91  { 0, 0, 0 },
    9292};
    9393
    9494
    95 const char *
    96 rtems_status_text(
    97     rtems_status_code status
    98 )
    99 {
    100     return rtems_assoc_name_by_local(rtems_status_assoc, status);
     95const char *rtems_status_text(
     96  rtems_status_code status
     97)
     98{
     99  return rtems_assoc_name_by_local(rtems_status_assoc, status);
    101100}
    102101
    103102
    104103static int rtems_verror(
    105     rtems_error_code_t error_flag,
    106     const char   *printf_format,
    107     va_list      arglist
    108 )
    109 {
    110     int               local_errno = 0;
    111     int               chars_written = 0;
    112     rtems_status_code status;
    113 
    114     if (error_flag & RTEMS_ERROR_PANIC)
    115     {
    116         if (rtems_panic_in_progress++)
    117             _Thread_Disable_dispatch();       /* disable task switches */
    118 
    119         /* don't aggravate things */
    120         if (rtems_panic_in_progress > 2)
    121             return 0;
    122     }
    123 
    124     (void) fflush(stdout);          /* in case stdout/stderr same */
    125 
    126     status = error_flag & ~RTEMS_ERROR_MASK;
    127     if (error_flag & RTEMS_ERROR_ERRNO)     /* include errno? */
    128         local_errno = errno;
    129 
    130     #if defined(RTEMS_MULTIPROCESSING)
    131       if (_System_state_Is_multiprocessing)
    132         fprintf(stderr, "[%" PRIu32 "] ", _Configuration_MP_table->node);
    133     #endif
    134 
    135     chars_written += vfprintf(stderr, printf_format, arglist);
    136 
    137     if (status)
    138         chars_written += fprintf(stderr, " (status: %s)", rtems_status_text(status));
    139 
    140     if (local_errno)
    141     {
    142       if ((local_errno > 0) && *strerror(local_errno))
    143         chars_written += fprintf(stderr, " (errno: %s)", strerror(local_errno));
    144       else
    145         chars_written += fprintf(stderr, " (unknown errno=%d)", local_errno);
    146     }
    147 
    148     chars_written += fprintf(stderr, "\n");
    149 
    150     (void) fflush(stderr);
    151 
    152     if (error_flag & (RTEMS_ERROR_PANIC | RTEMS_ERROR_ABORT))
    153     {
    154         if (error_flag & RTEMS_ERROR_PANIC)
    155         {
    156             rtems_error(0, "fatal error, exiting");
    157             _exit(local_errno);
    158         }
    159         else
    160         {
    161             rtems_error(0, "fatal error, aborting");
    162             abort();
    163         }
    164     }
    165     return chars_written;
     104  rtems_error_code_t  error_flag,
     105  const char         *printf_format,
     106  va_list             arglist
     107)
     108{
     109  int               local_errno = 0;
     110  int               chars_written = 0;
     111  rtems_status_code status;
     112
     113  if (error_flag & RTEMS_ERROR_PANIC) {
     114    if (rtems_panic_in_progress++)
     115      _Thread_Disable_dispatch();       /* disable task switches */
     116
     117    /* don't aggravate things */
     118    if (rtems_panic_in_progress > 2)
     119      return 0;
     120  }
     121
     122  (void) fflush(stdout);            /* in case stdout/stderr same */
     123
     124  status = error_flag & ~RTEMS_ERROR_MASK;
     125  if (error_flag & RTEMS_ERROR_ERRNO)     /* include errno? */
     126    local_errno = errno;
     127
     128  #if defined(RTEMS_MULTIPROCESSING)
     129    if (_System_state_Is_multiprocessing)
     130      fprintf(stderr, "[%" PRIu32 "] ", _Configuration_MP_table->node);
     131  #endif
     132
     133  chars_written += vfprintf(stderr, printf_format, arglist);
     134
     135  if (status)
     136    chars_written +=
     137      fprintf(stderr, " (status: %s)", rtems_status_text(status));
     138
     139  if (local_errno) {
     140    if ((local_errno > 0) && *strerror(local_errno))
     141      chars_written += fprintf(stderr, " (errno: %s)", strerror(local_errno));
     142    else
     143      chars_written += fprintf(stderr, " (unknown errno=%d)", local_errno);
     144  }
     145
     146  chars_written += fprintf(stderr, "\n");
     147
     148  (void) fflush(stderr);
     149
     150  return chars_written;
    166151}
    167152
     
    176161
    177162int rtems_error(
    178     rtems_error_code_t error_flag,
    179     const char *printf_format,
    180     ...
    181   )
    182 {
    183     va_list arglist;
    184     int chars_written;
    185 
    186     va_start(arglist, printf_format);
    187     chars_written = rtems_verror(error_flag, printf_format, arglist);
    188     va_end(arglist);
    189 
    190     return chars_written;
     163  rtems_error_code_t error_flag,
     164  const char *printf_format,
     165  ...
     166)
     167{
     168  va_list arglist;
     169  int chars_written;
     170
     171  va_start(arglist, printf_format);
     172  chars_written = rtems_verror(error_flag, printf_format, arglist);
     173  va_end(arglist);
     174
     175  if (error_flag & RTEMS_ERROR_PANIC) {
     176    rtems_error(0, "fatal error, exiting");
     177    _exit(errno);
     178  }
     179  if (error_flag & RTEMS_ERROR_ABORT) {
     180    rtems_error(0, "fatal error, aborting");
     181    abort();
     182  }
     183
     184  return chars_written;
    191185}
    192186
     
    196190
    197191void rtems_panic(
    198     const char *printf_format,
    199     ...
    200   )
    201 {
    202     va_list arglist;
    203 
    204     va_start(arglist, printf_format);
    205     (void) rtems_verror(RTEMS_ERROR_PANIC, printf_format, arglist);
    206     va_end(arglist);
    207 }
     192  const char *printf_format,
     193  ...
     194)
     195{
     196  va_list arglist;
     197
     198  va_start(arglist, printf_format);
     199  (void) rtems_verror(RTEMS_ERROR_PANIC, printf_format, arglist);
     200  va_end(arglist);
     201
     202  rtems_error(0, "fatal error, exiting");
     203  _exit(errno);
     204}
Note: See TracChangeset for help on using the changeset viewer.