kcomex | 21 June, 2008 14:38
During the debugging and unit test cases running phase, open source projects usually write error string or other information to STDERR file. Quite unluckily, we can not retrieve lines from STDERR in Symbian with Open C. The stdioserver program comes with Open C SDK only redirects STDOUT to a file located on disk, but left STDERR no where to check out.
So in my Mozilla porting days, I have to make a workaround for retrieving information written to STDERR because most of unit test cases write error information to STDERR. There are two workarounds which could be used according to different situation.
If you have only one or not so many .c source files to fix, then I would like to recommend the first way. That is to modify the source code, add these lines as the top most statement:
FILE* stderr_redirect = freopen("C:\\data\\stderr.log", "w", stderr); // Top most line
/* Begin of original code lines */
...
...
...
/* End of original code lines */
fclose(stderr_redirect); // Bottom most line
The other case is that you have many (maybe up to several hundreds) independent .c source files, so it's almost impossible to adopt the first way, like NSPR test cases. We have to figure out another solution. Here I did a small trick, that is modify the stdio.h in <EPOCROOT>\Epoc32\include\stdapis in Open C SDK. The stdio.h in looks like this:
...
...
#ifndef __SYMBIAN32__
#define stdin __stdinp
#define stdout __stdoutp
#define stderr __stderrp
#else
__BEGIN_DECLS
IMPORT_C FILE *__stdin (void);
IMPORT_C FILE *__stdout (void);
IMPORT_C FILE *__stderr (void);
IMPORT_C char * tmpdirname(void);
__END_DECLS
#define stdin (__stdin())
#define stdout (__stdout())
#ifdef STDERR_TO_STDOUT
#define stderr (__stdout())
#else
#define stderr (__stderr())
#endif
#endif
...
...
These lines are located around line 265 - 283 if you are using Open C SDK v1.3. With the lines shown as light yellow marked, you could know I just let the compiler treats STDERR as STDOUT, sothat information written to STDERR are all redirected to STDOUT. Of course we have to define MACRO STDERR_TO_STDOUT in that .MMP file. And because we don't want this trick infect other projects which don't have their STDERR touched, so we use this macro to mark the fence. Once STDERR is redirected to STDOUT, then you could use the original stdioserver program comes with the Open C SDK to check out original STDERR information in STDOUT file.
All two ways are easy to understand and use, although I felt the latter one is not so perfect because this requires changing a SDK file. Hope this tip will be helpful in your daily work, and just give me any comments when you get any idea about this.
update
kcomex | 15/07/2008, 21:14
while doing immigration work from .MMP to GNU make and autoconf tool chain. I found for emulator build you can pass "-nostderr" argument to the compiler (mwccsym2.exe) to produce the same result as the blog stated. But there is no option for GCCE compiler to take for this purpose.