From: <ped...@us...> - 2008-10-09 00:51:21
|
Revision: 1200 http://cegcc.svn.sourceforge.net/cegcc/?rev=1200&view=rev Author: pedroalves Date: 2008-10-09 00:51:10 +0000 (Thu, 09 Oct 2008) Log Message: ----------- 2008-10-09 Pawel Veselov <paw...@gm...> newlib/ * libc/sys/wince/trace.c (__trace_closed): New. (get_level_name): New. (WCETRACE): Rename to... (__WCETrace): ... this. (WCETRACESET): Do not change the trace level if the tracing facilities have been closed. (WCETRACECLOSE): Print out a message that the tracing has closed. Reset tracing level to 0 after closing. (__WCETrace): Print out the tracing level along with the message. * libc/sys/wince/sys/wcetrace.h (WCETRACE): Define. (WCETRACE): Rename to ... (__WCETrace): ... this. (WCETRACING): Define. * libc/sys/wince/io.c (_write_r): When tracing out stdio/stderr buffer, send out as many bytes as are in the buffer, instead of using zero termination. Modified Paths: -------------- trunk/cegcc/src/newlib/ChangeLog.cegcc trunk/cegcc/src/newlib/newlib/libc/sys/wince/io.c trunk/cegcc/src/newlib/newlib/libc/sys/wince/sys/wcetrace.h trunk/cegcc/src/newlib/newlib/libc/sys/wince/trace.c Modified: trunk/cegcc/src/newlib/ChangeLog.cegcc =================================================================== --- trunk/cegcc/src/newlib/ChangeLog.cegcc 2008-10-07 17:03:04 UTC (rev 1199) +++ trunk/cegcc/src/newlib/ChangeLog.cegcc 2008-10-09 00:51:10 UTC (rev 1200) @@ -1,3 +1,23 @@ +2008-10-09 Pawel Veselov <paw...@gm...> + + newlib/ + * libc/sys/wince/trace.c (__trace_closed): New. + (get_level_name): New. + (WCETRACE): Rename to... + (__WCETrace): ... this. + (WCETRACESET): Do not change the trace level if the tracing + facilities have been closed. + (WCETRACECLOSE): Print out a message that the tracing has closed. + Reset tracing level to 0 after closing. + (__WCETrace): Print out the tracing level along with the message. + * libc/sys/wince/sys/wcetrace.h (WCETRACE): Define. + (WCETRACE): Rename to ... + (__WCETrace): ... this. + (WCETRACING): Define. + * libc/sys/wince/io.c (_write_r): When tracing out stdio/stderr + buffer, send out as many bytes as are in the buffer, instead of + using zero termination. + 2008-10-04 Pawel Veselov <paw...@gm...> newlib/ Modified: trunk/cegcc/src/newlib/newlib/libc/sys/wince/io.c =================================================================== --- trunk/cegcc/src/newlib/newlib/libc/sys/wince/io.c 2008-10-07 17:03:04 UTC (rev 1199) +++ trunk/cegcc/src/newlib/newlib/libc/sys/wince/io.c 2008-10-09 00:51:10 UTC (rev 1200) @@ -515,13 +515,14 @@ WCETRACE(WCE_IO, "write(%d, %d, %x)", fd, count, _fdtab[fd].hnd); EnterCriticalSection(&critsect); -#if 1 - if (fd == 2 || fd == 1) - { - const char* out = fd == 2?"stderr: ":"stdout: "; - WCETRACE(WCE_IO, "%s : %s", out, buf); + + if (WCETRACING(WCE_IO)) { + if (fd == 2 || fd == 1) { + char fmt[30]; + snprintf(fmt, 29, "%s : %%.%ds", fd == 2?"stderr":"stdout", count); + WCETRACE(WCE_IO, fmt, buf); + } } -#endif /* until we can call console stuff inside the PE loader */ if ((!__StdioInited) && (fd >= 0) && (fd <= 2)) Modified: trunk/cegcc/src/newlib/newlib/libc/sys/wince/sys/wcetrace.h =================================================================== --- trunk/cegcc/src/newlib/newlib/libc/sys/wince/sys/wcetrace.h 2008-10-07 17:03:04 UTC (rev 1199) +++ trunk/cegcc/src/newlib/newlib/libc/sys/wince/sys/wcetrace.h 2008-10-09 00:51:10 UTC (rev 1200) @@ -32,16 +32,26 @@ #endif #ifndef CE_NOTRACE + void WCETRACEGETENV(void); void WCETRACESET(int trace); int WCETRACEGET(void); -void WCETRACE(int level, const char *fmt, ...); +#define WCETRACING(LEVEL) \ + ((WCETRACE_DEBUGGER_GET() & (LEVEL)) || (WCETRACEGET() & (LEVEL))) +#define WCETRACE(LEVEL, FMT...) do { \ + if (WCETRACING(LEVEL)) \ + __WCETrace(LEVEL, FMT); \ + } while(0) + void WCETRACE_DEBUGGER_SET(int trace); int WCETRACE_DEBUGGER_GET(void); void WCETRACECLOSE(void); +void __WCETrace(int trace, const char * fmt, ...); void __WCETraceError(int level, unsigned long werr, const char* funct); #define WCETRACE_ERROR(T, ERR) __WCETraceError(T, ERR, __FUNCTION__) + #else + #define WCETRACEGETENV() do {} while (0) #define WCETRACESET(trace) do {} while (0) #define WCETRACEGET() do {} while (0) @@ -50,6 +60,8 @@ #define WCETRACE_DEBUGGER_GET() do {} while (0) #define WCETRACECLOSE() do {} while (0) #define WCETRACE_ERROR(T, ERR) do {} while (0) +#define WCETRACING(p) (0) + #endif #ifdef __cplusplus Modified: trunk/cegcc/src/newlib/newlib/libc/sys/wince/trace.c =================================================================== --- trunk/cegcc/src/newlib/newlib/libc/sys/wince/trace.c 2008-10-07 17:03:04 UTC (rev 1199) +++ trunk/cegcc/src/newlib/newlib/libc/sys/wince/trace.c 2008-10-09 00:51:10 UTC (rev 1200) @@ -15,15 +15,17 @@ static HANDLE __wcetracehnd = NULL; static int __wcetrace = 0; static int __wcetrace_debugger = 0; /* Used to be WCE_ALL */ +static int __trace_closed = 0; void WCETRACESET(int trace) { - __wcetrace = trace; + if (!__trace_closed) + __wcetrace = trace; } int -WCETRACEGET() +WCETRACEGET(void) { return(__wcetrace); } @@ -35,7 +37,7 @@ } int -WCETRACE_DEBUGGER_GET() +WCETRACE_DEBUGGER_GET(void) { return(__wcetrace_debugger); } @@ -46,23 +48,75 @@ int flag; } trace_entry; +/* This define specifies how long a buffer is needed for displaying + all the levels. It should be the sum of all names of level + lengths, plus the amount of level lengths (for the separation + commas) plus 6 (currently) digits for displaying the numeric value + of the level. And then add a terminating 0, and a safety padding. + The WCE_ALL is not accounted for, as it consumes all other levels, + and never shows in the output. */ + +#define MAX_LEVEL_BUF (41 + 9 + 6 + 10) + static const trace_entry trace_entries[] = { { "all", WCE_ALL }, - { "io", WCE_IO }, - { "network", WCE_NETWORK }, - { "signals", WCE_SIGNALS }, - { "fifos", WCE_FIFOS }, - { "time", WCE_TIME }, - { "synch", WCE_SYNCH }, - { "malloc", WCE_MALLOC }, - { "vm", WCE_VM }, - { "app", WCE_APP }, - + { "io", WCE_IO }, /* 2 = 2 */ + { "network", WCE_NETWORK }, /* 7 = 9 */ + { "signals", WCE_SIGNALS }, /* 7 = 16 */ + { "fifos", WCE_FIFOS }, /* 5 = 21 */ + { "time", WCE_TIME }, /* 4 = 25 */ + { "synch", WCE_SYNCH }, /* 5 = 30 */ + { "malloc", WCE_MALLOC }, /* 6 = 36 */ + { "vm", WCE_VM }, /* 2 = 38 */ + { "app", WCE_APP }, /* 3 = 41 */ + { NULL, 0 } }; +/* Convert LEVEL into a comma separated string, and store it in TO. + TO must be at least MAX_LEVEL_BUF long. */ + +static void +get_level_name(int level, char *to) +{ + int virgin = 1; + + const trace_entry *ent = trace_entries + 1; + for (; ent->str; ent++) + { + if (level & ent->flag) + { + int len; + + level &= ~ent->flag; + if (!virgin) + *(to++) = ','; + else + virgin = 0; + + len = strlen(ent->str); + memcpy(to, ent->str, len); + to += len; + } + } + + if (level) + { + int printed; + + /* There were some unresolved flags. */ + if (!virgin) + *(to++) = ','; + + printed = sprintf(to, "%#04.4x", level); + to += printed; + } + + *to = 0; +} + void NKDbgPrintfA(const char *fmt, ...); static void set_from_env(const char* env, int* what) @@ -111,33 +165,44 @@ } void -WCETRACEGETENV() +WCETRACEGETENV(void) { set_from_env("WCETRACE", &__wcetrace); set_from_env("WCETRACE_DEBUGGER", &__wcetrace_debugger); } void -WCETRACECLOSE() +WCETRACECLOSE(void) { if (__wcetracehnd != NULL && __wcetracehnd != INVALID_HANDLE_VALUE) { + __wcetrace = WCE_IO; + __WCETrace(WCE_IO, "Trace file is being closed"); FlushFileBuffers(__wcetracehnd); XCECloseHandle(__wcetracehnd); __wcetracehnd = NULL; + __trace_closed = 1; + __wcetrace = 0; } } void -WCETRACE(int level, const char *fmt, ...) +__WCETrace(int level, const char *fmt, ...) { + int len; + char level_name[MAX_LEVEL_BUF]; + char buf[1024]; + + va_list ap; + if (!(__wcetrace_debugger & level) && !(__wcetrace & level)) return; - char buf[1024]; - int len = sprintf(buf, "%08X:%08X: ", GetTickCount(), GetCurrentThreadId()); + get_level_name(level, level_name); + len = sprintf(buf, "%08X:%08X: [%s] ", + GetTickCount(), GetCurrentThreadId(), + level_name); - va_list ap; va_start(ap, fmt); vsprintf(buf + len, fmt, ap); strcat(buf, "\n"); @@ -148,7 +213,7 @@ wchar_t tracepathw[256]; const char* tmppath = getenv("TMP"); int pid = getpid(); - NKDbgPrintfW(L"pid is %d (%x)", pid, pid); + NKDbgPrintfW(L"pid is %d (%x)\n", pid, pid); if (!tmppath || strlen(tmppath) == 0) sprintf(tracepath, "/Temp/wcetrace%u.log", pid); else @@ -181,23 +246,26 @@ } } -void __WCETraceError(int trace, DWORD error, const char* func) +void +__WCETraceError(int trace, DWORD error, const char* func) { wchar_t* wbuf; + int len; + char* buf; FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (wchar_t*) &wbuf, - 0, NULL ); + 0, NULL); - int len = wcslen(wbuf); - char* buf = alloca(len); - wcstombs(buf, wbuf, len+1); + len = wcslen(wbuf); + buf = alloca(len + 1); + wcstombs(buf, wbuf, len + 1); LocalFree(wbuf); WCETRACE(trace, "%s failed with error %d: %s", func, (int)error, buf); printf("%s failed with error %d: %s\n", func, (int)error, buf); } -#endif // CE_NOTRACE +#endif /* CE_NOTRACE */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |