OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [libcsupport/] [src/] [error.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *  report errors and panics to RTEMS' stderr.
3
 *  Currently just used by RTEMS monitor.
4
 *
5
 *  error.c,v 1.13 2001/01/08 18:26:44 joel Exp
6
 */
7
 
8
#if HAVE_CONFIG_H
9
#include "config.h"
10
#endif
11
 
12
/*
13
 * These routines provide general purpose error reporting.
14
 * rtems_error reports an error to stderr and allows use of
15
 * printf style formatting.  A newline is appended to all messages.
16
 *
17
 * error_flag can be specified as any of the following:
18
 *
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
22
 *
23
 * It can also include a rtems_status value which can be OR'd
24
 * with the above flags. *
25
 *
26
 * EXAMPLE
27
 *      #include <rtems.h>
28
 *      #include <rtems/error.h>
29
 *      rtems_error(0, "stray interrupt %d", intr);
30
 *
31
 * EXAMPLE
32
 *        if ((status = rtems_task_create(...)) != RTEMS_SUCCCESSFUL)
33
 *        {
34
 *            rtems_error(status | RTEMS_ERROR_ABORT,
35
 *                        "could not create task");
36
 *        }
37
 *
38
 * EXAMPLE
39
 *        if ((fd = open(pathname, O_RDNLY)) < 0)
40
 *        {
41
 *            rtems_error(RTEMS_ERROR_ERRNO, "open of '%s' failed", pathname);
42
 *            goto failed;
43
 *        }
44
 */
45
 
46
#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
47
#include <rtems.h>
48
 
49
#include <rtems/error.h>
50
#include <rtems/assoc.h>
51
 
52
#include <stdio.h>
53
#include <stdarg.h>
54
#include <errno.h>
55
#include <stdlib.h>
56
#include <string.h>
57
#include <unistd.h>             /* _exit() */
58
 
59
/* bug in hpux <errno.h>: no prototypes unless you are C++ */
60
#ifdef hpux9
61
char *strerror(int);
62
#endif
63
 
64
extern char *rtems_progname;
65
int          rtems_panic_in_progress;
66
 
67
rtems_assoc_t rtems_status_assoc[] = {
68
    { "successful completion",              RTEMS_SUCCESSFUL, },
69
    { "returned from a thread",             RTEMS_TASK_EXITTED, },
70
    { "multiprocessing not configured",     RTEMS_MP_NOT_CONFIGURED, },
71
    { "invalid object name",                RTEMS_INVALID_NAME, },
72
    { "invalid object id",                  RTEMS_INVALID_ID, },
73
    { "too many",                           RTEMS_TOO_MANY, },
74
    { "timed out waiting",                  RTEMS_TIMEOUT, },
75
    { "object deleted while waiting",       RTEMS_OBJECT_WAS_DELETED, },
76
    { "specified size was invalid",         RTEMS_INVALID_SIZE, },
77
    { "address specified is invalid",       RTEMS_INVALID_ADDRESS, },
78
    { "number was invalid",                 RTEMS_INVALID_NUMBER, },
79
    { "item has not been initialized",      RTEMS_NOT_DEFINED, },
80
    { "resources still outstanding",        RTEMS_RESOURCE_IN_USE, },
81
    { "request not satisfied",              RTEMS_UNSATISFIED, },
82
    { "thread is in wrong state",           RTEMS_INCORRECT_STATE, },
83
    { "thread already in state",            RTEMS_ALREADY_SUSPENDED, },
84
    { "illegal on calling thread",          RTEMS_ILLEGAL_ON_SELF, },
85
    { "illegal for remote object",          RTEMS_ILLEGAL_ON_REMOTE_OBJECT, },
86
    { "called from wrong environment",      RTEMS_CALLED_FROM_ISR, },
87
    { "invalid thread priority",            RTEMS_INVALID_PRIORITY, },
88
    { "invalid date/time",                  RTEMS_INVALID_CLOCK, },
89
    { "invalid node id",                    RTEMS_INVALID_NODE, },
90
    { "directive not configured",           RTEMS_NOT_CONFIGURED, },
91
    { "not owner of resource",              RTEMS_NOT_OWNER_OF_RESOURCE , },
92
    { "directive not implemented",          RTEMS_NOT_IMPLEMENTED, },
93
    { "RTEMS inconsistency detected",       RTEMS_INTERNAL_ERROR, },
94
    { "could not get enough memory",        RTEMS_NO_MEMORY, },
95
    { "driver IO error",                    RTEMS_IO_ERROR, },
96
    { "internal multiprocessing only",      THREAD_STATUS_PROXY_BLOCKING, },
97
    { 0, 0, 0 },
98
};
99
 
100
 
101
const char *
102
rtems_status_text(
103
    rtems_status_code status
104
)
105
{
106
    return rtems_assoc_name_by_local(rtems_status_assoc, status);
107
}
108
 
109
 
110
static int rtems_verror(
111
    unsigned32   error_flag,
112
    const char   *printf_format,
113
    va_list      arglist
114
)
115
{
116
    int               local_errno = 0;
117
    int               chars_written = 0;
118
    rtems_status_code status;
119
 
120
    if (error_flag & RTEMS_ERROR_PANIC)
121
    {
122
        if (rtems_panic_in_progress++)
123
            _Thread_Disable_dispatch();       /* disable task switches */
124
 
125
        /* don't aggravate things */
126
        if (rtems_panic_in_progress > 2)
127
            return 0;
128
    }
129
 
130
    (void) fflush(stdout);          /* in case stdout/stderr same */
131
 
132
    status = error_flag & ~RTEMS_ERROR_MASK;
133
    if (error_flag & RTEMS_ERROR_ERRNO)     /* include errno? */
134
        local_errno = errno;
135
 
136
    if (_System_state_Is_multiprocessing)
137
        fprintf(stderr, "[%d] ", _Configuration_MP_table->node);
138
 
139
    if (rtems_progname && *rtems_progname)
140
        chars_written += fprintf(stderr, "%s: ", rtems_progname);
141
    chars_written += vfprintf(stderr, printf_format, arglist);
142
 
143
    if (status)
144
        chars_written += fprintf(stderr, " (status: %s)", rtems_status_text(status));
145
 
146
    if (local_errno)
147
    {
148
      if ((local_errno > 0) && *strerror(local_errno))
149
        chars_written += fprintf(stderr, " (errno: %s)", strerror(local_errno));
150
      else
151
        chars_written += fprintf(stderr, " (unknown errno=%d)", local_errno);
152
    }
153
 
154
    chars_written += fprintf(stderr, "\n");
155
 
156
    (void) fflush(stderr);
157
 
158
    if (error_flag & (RTEMS_ERROR_PANIC | RTEMS_ERROR_ABORT))
159
    {
160
        if (error_flag & RTEMS_ERROR_PANIC)
161
        {
162
            rtems_error(0, "fatal error, exiting");
163
            _exit(local_errno);
164
        }
165
        else
166
        {
167
            rtems_error(0, "fatal error, aborting");
168
            abort();
169
        }
170
    }
171
    return chars_written;
172
}
173
 
174
 
175
/*
176
 * Report an error.
177
 * error_flag is as above; printf_format is a normal
178
 * printf(3) format string, with its concommitant arguments.
179
 *
180
 * Returns the number of characters written.
181
 */
182
 
183
int rtems_error(
184
    int   error_flag,
185
    const char *printf_format,
186
    ...
187
  )
188
{
189
    va_list arglist;
190
    int chars_written;
191
 
192
    va_start(arglist, printf_format);
193
    chars_written = rtems_verror(error_flag, printf_format, arglist);
194
    va_end(arglist);
195
 
196
    return chars_written;
197
}
198
 
199
/*
200
 * rtems_panic is shorthand for rtems_error(RTEMS_ERROR_PANIC, ...)
201
 */
202
 
203
void rtems_panic(
204
    const char *printf_format,
205
    ...
206
  )
207
{
208
    va_list arglist;
209
 
210
    va_start(arglist, printf_format);
211
    (void) rtems_verror(RTEMS_ERROR_PANIC, printf_format, arglist);
212
    va_end(arglist);
213
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.