[ECOS] Re: uSTL hello world

cetoni GmbH - Uwe Kindler uwe.kindler@cetoni.de
Wed Sep 9 07:00:00 GMT 2009


Hi John,

> The file descriptor (fd) is unchanged between working and non-working
> code which suggests that the relevant descriptor table entry is not
> being initialised. Try planting breakpoints at cyg_fd_assign() and
> cyg_fd_alloc(). I expect these will be called in the case where cout is
> working and the call stack may provide a clue as to what is triggering
> the correct behaviour.

O.k. I followed your suggestions and that are my results.

If printf exists in main.cpp then both functions cyg_fd_assign() and 
cyg_fd_alloc() will get called for stdin and stdout. At the end of this 
message there is the call stack for stdin.

If printf is not present in main, then both functions will not get 
called for stdin and stdout and I think I now know why. In the ustl 
package in ofstream.cpp the streams are not created because the streams 
(cout, cin, cerr) are declared this way:

ifstream cin  (STDIN_FILENO);
ofstream cout (STDOUT_FILENO);
ofstream cerr (STDERR_FILENO);

That means they use the fileno to open the streams - they do not create 
them. But the streams are not present, because no function uses stdout, 
stdin, that means there are no references and the linker throws stdout 
and stdin away. This is the reason why the static constructors of stdout 
and stdin are never get called.

Here is my proposal to solve this problem. I changed the declaration of 
cout, cin and cerr this way:

ifstream cin  (((Cyg_StdioStream *)stdin)->get_dev());
ofstream cout (((Cyg_StdioStream *)stdout)->get_dev());
ofstream cerr (((Cyg_StdioStream *)stderr)->get_dev());

This ensures that stdout, stdin and stderr are created. After this 
change cyg_fd_assign() and cyg_fd_alloc() will get called if there is no 
printf function in main.cpp. The call cout << "Hello world!\n" works 
now. I noticed that the message is already printed before cout.flush() 
is called. So it seems cout.flush() is not required if a proper serial 
driver is used. If I use the diagnostic serial driver, then I always 
needed to call cout.flush().

If you agree to my proposal then I will provide a patch.

Regards, Uwe



Thread [1] (Suspended: Breakpoint hit.)	
7 cyg_fd_alloc() 
opt\ecos\ecos\packages\io\fileio\current\src\fd.cxx:230 0xa011d3a8	
6 open() \opt\ecos\ecos\packages\io\fileio\current\src\file.cxx:205 
0xa011f448	
5 cyg_stdio_open() 
\home\Nutzer\final_ustl_0D_install\include\cyg\libc\stdio\io.inl:101 
0xa0130228	
4 Cyg_libc_stdio_find_filename() 
\opt\ecos\ecos\packages\language\c\libc\stdio\current\src\common\stdiosupp.cxx:76 
0xa01302c0	
3 __static_initialization_and_destruction_0() 
\opt\ecos\ecos\packages\language\c\libc\stdio\current\src\common\stdin.cxx:86 
0xa013000c	
2 _GLOBAL__I.56000_cyg_libc_stdio_stdin() 
\opt\ecos\ecos\packages\language\c\libc\stdio\current\src\common\stdin.cxx:107 
0xa01300c4	
1 cyg_hal_invoke_constructors() 
\opt\ecos\ecos\packages\hal\arm\arch\current\src\hal_misc.c:213 0xa0104458

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss



More information about the Ecos-discuss mailing list