Hi,
here is the patch for it. Sank a lot of time trying to understand why
the trace files had a malloc output in the beginning, overwriting the
first line. Turned out tracing was called after epilogue code has
closed the tracing. That would explain some of the changes in the
diff.
Thanks!
Pawel.
On Sun, Sep 14, 2008 at 12:38 PM, Pawel Veselov <[EMAIL PROTECTED]> wrote:
> Hi,
>
> That will also mean that the functions will change, and if there were
> binaries compiled against the old library, and they used the WCETRACE
> functions, they won't work anymore until they have been recompiled.
> Just wanted to check that's acceptable.
>
> Thanks,
> Pawel.
>
>
> On Fri, Sep 12, 2008 at 9:53 PM, Danny Backx <[EMAIL PROTECTED]> wrote:
>> On Fri, 2008-09-12 at 15:29 -0700, Pawel Veselov wrote:
>>> would it be interesting if I did the following changes to wcetrace
>>> facilities:
>>>
>>> * replace WCETRACE with the define that first evaluates the current
>>> level and only then calls the trace printout. This will prevent
>>> arguments from being evaluated if the tracing is off for the specified
>>> level.
>>> * Print out the level on the trace line
>>> * Add a WCEDOTRACE(level,code) define that can be used to execute code
>>> if the trace level "level" is active.
>>
>> Looks good. Be sure to keep things stable, this kind of code is hard to
>> debug when things go wrong.
>>
>> Danny
>> --
>> Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info
>>
>>
>
>
>
> --
> With best of best regards
> Pawel S. Veselov
>
--
With best of best regards
Pawel S. Veselov
Index: src/newlib/newlib/libc/sys/wince/trace.c
===================================================================
--- src/newlib/newlib/libc/sys/wince/trace.c (revision 1198)
+++ src/newlib/newlib/libc/sys/wince/trace.c (working copy)
@@ -15,11 +15,15 @@
static HANDLE __wcetracehnd = NULL;
static int __wcetrace = 0;
static int __wcetrace_debugger = 0; /* Used to be WCE_ALL */
+static int __trace_closed = 0;
+static void get_level_name(int, char *);
void
WCETRACESET(int trace)
{
- __wcetrace = trace;
+ if (!__trace_closed) {
+ __wcetrace = trace;
+ }
}
int
@@ -46,19 +50,29 @@ typedef struct
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 counted, 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 }
};
@@ -122,22 +136,31 @@ WCETRACECLOSE()
{
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, ...)
{
if (!(__wcetrace_debugger & level) && !(__wcetrace & level))
return;
+ int len;
+ char level_name[MAX_LEVEL_BUF];
char buf[1024];
- int len = sprintf(buf, "%08X:%08X: ", GetTickCount(), GetCurrentThreadId());
va_list ap;
+
+ get_level_name(level, level_name);
+ len = sprintf(buf, "%08X:%08X: [%s] ", GetTickCount(), GetCurrentThreadId(), level_name);
+
va_start(ap, fmt);
vsprintf(buf + len, fmt, ap);
strcat(buf, "\n");
@@ -148,7 +171,7 @@ WCETRACE(int level, const char *fmt, ...
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
@@ -200,4 +223,38 @@ void __WCETraceError(int trace, DWORD er
printf("%s failed with error %d: %s\n", func, (int)error, buf);
}
-#endif // CE_NOTRACE
+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 str_len;
+ level &= ~ent->flag;
+ if (!virgin) {
+ *(to++) = ',';
+ } else {
+ virgin = 0;
+ }
+ str_len = strlen(ent->str);
+ memcpy(to, ent->str, str_len);
+ to += str_len;
+ }
+ }
+
+ if (level) {
+ int printed;
+ /* there were some unresolved flags */
+ if (!virgin) {
+ *(to++) = ',';
+ }
+ printed = sprintf(to, "%#04.4x", level);
+ to += printed;
+ }
+
+ *to = 0;
+
+}
+
+#endif /* CE_NOTRACE */
Index: src/newlib/newlib/libc/sys/wince/sys/wcetrace.h
===================================================================
--- src/newlib/newlib/libc/sys/wince/sys/wcetrace.h (revision 1198)
+++ src/newlib/newlib/libc/sys/wince/sys/wcetrace.h (working copy)
@@ -32,13 +32,21 @@ extern "C" {
#endif
#ifndef CE_NOTRACE
+
void WCETRACEGETENV(void);
void WCETRACESET(int trace);
int WCETRACEGET(void);
-void WCETRACE(int level, const char *fmt, ...);
+#define TRACING(level) ((WCETRACE_DEBUGGER_GET() & level) || \
+ (WCETRACEGET() & level))
+#define WCETRACE(level, fmt...) do { \
+ if (TRACING(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
@@ -50,6 +58,7 @@ void __WCETraceError(int level, unsigned
#define WCETRACE_DEBUGGER_GET() do {} while (0)
#define WCETRACECLOSE() do {} while (0)
#define WCETRACE_ERROR(T, ERR) do {} while (0)
+#define TRACING(p) (0)
#endif
#ifdef __cplusplus
Index: src/newlib/newlib/libc/sys/wince/io.c
===================================================================
--- src/newlib/newlib/libc/sys/wince/io.c (revision 1198)
+++ src/newlib/newlib/libc/sys/wince/io.c (working copy)
@@ -515,13 +515,14 @@ _write_r(struct _reent *reent, int fd, c
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 (TRACING(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))
Index: src/newlib/ChangeLog.cegcc
===================================================================
--- src/newlib/ChangeLog.cegcc (revision 1198)
+++ src/newlib/ChangeLog.cegcc (working copy)
@@ -1,3 +1,23 @@
+2008-10-06 Pawel Veselov <[EMAIL PROTECTED]>
+
+ newlib/
+ * libc/sys/wince/trace.c : Defined __trace_closed to check for when
+ tracing has been closed. Define and implement get_level_name() to
+ convert trace level into a string. Made level variables static so
+ outside code can not change them. Renamed WCETRACE to __WCETrace.
+ * libc/sys/wince/trace.c (WCETRACESET) : do not cange the trace level
+ if the tracing facilities have been closed.
+ * libc/sys/wince/trace.c (WCETRACECLOSE) : print out a message that
+ the tracing has closed. Reset tracing level to 0 after closing.
+ * libc/sys/wince/trace.c (__WCETrace) : print out the tracing level
+ along with the message.
+ * libc/sys/wince/sys/wcetrace.h : Define WCETRACE define, renamed old
+ WCETRACE function to __WCETrace. Define TRACING that check for whether
+ tracing is enabled for the specified level.
+ * 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 <[EMAIL PROTECTED]>
newlib/
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Cegcc-devel mailing list
Cegcc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cegcc-devel