This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to get printf() output?


Kai Ruottu wrote:

Toralf Lund <toralf@procaptura.com>



It works. I'm 100% sure about that. write() could be incorrect, as I haven't tested its functionality thoroughly - I've been focusing on checking whether it is called or not, and I think it isn't ;-(



I produced my test executable with gcc-2.95.3 when the 'specs' in my gcc-3.3.1 hadn't any default target board edited into it...

The peculiar thing with gcc-3.x has been that it magically replaces
'printf()'s with 'puts()', ie. "printf("Hello World");" will be changed
to be "puts("Hello World");". Producing the assembly file shows this:



[ ... ]



when gcc-2.95.3 still didn't edit whole functions away...


That's fun ;-)

I'm using gcc-2.95.3, though, as the code doesn't compile yet with gcc-3.1 and/or I didn't find out how to disable some of the strict checking that causes the failure...

So maybe you even haven't the 'printf()' in your executable but
something else and that really doesn't output via 'write()' at all...

In this "Hello World" case the 'replaced printf()'s, also output'ed
via '_write_r()' and then via 'write()', ie. these were linked into
the executable, so replacing 'printf()'s with 'puts()'s isn't the
reason for your problem...

Looking at the assembly output for the C code and seeing whether those
printf()'s are replaced with something else, can be one way to find
some sanity... In my "Hello World" case one looking at the disassembly
listing and trying to find the call to 'printf()' from it, could lead
into one soon going up the walls ;-)


A bit like looking at the source code of printf and its friends and try to figure out how it all works, or try to trace its functionality via the disassembler output, I guess...

Anyhow: I just figured it out. I had by mistake left the following function around in one of the C files:

int fflush(fp)
int fp;                /* dummy argument */
{
 /* do nothing */

 return 0;
}

This was required earlier when using a different clib.c. When removing this, everything works fine. Don't ask me why. Stranger still, it turned out that the printf() didn't fail completely in the original version, but would somehow mimic the sprintf() behaviour, so I could get my output by sticking a character buffer in front of the format string, and subsequently write this to the TTY.

- Toralf


------ Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/ Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]