where is the source code for printf?

Asked by Doug Turnbow

I'm trying to debug an issue with printf() related to the heap.
If I have less than about 1k of heap declared, printf() seems to work fine, if I have more than 1k of heap it causes a variety of problems including resetting the processor.

I believe this is the call tree that my application is taking. Where would I find the source code to these functions?
printf()
_vfprintf_r()
__swsetup_r()
__smakebuf_r()
_isatty_r()
_isatty()
initialise_monitor_handles()

So I'm looking for the URL and filename that I would need to get in order to have this source code.

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Thomas Preud'homme
Solved:
Last query:
Last reply:
Revision history for this message
Best Thomas Preud'homme (thomas-preudhomme) said :
#1

Hi Doug,

You can find source code for these functions at [1] in files:

libc/stdio/vprintf.c
libc/stdio/swsetup.c
libc/stdio/makebuf.c
libc/posix/_isatty.c
libc/reent/isattyr.c

respectively.

[1] https://sourceware.org/viewvc/src/newlib/

Hope this helps you find the bug you are experiencing.

Best regards.

Revision history for this message
Tony Liu (mrtoniliu) said :
#2

Hi,

I would suggest you to look up these functions in the Newlib source code.
For example, you can find most of these functions located in the directory of <path to newlib source>/newlib/libc, e.g:
 "__swsetup_r()" in <path to newlib source>/libc/stdio/wsetup.c
 "initialise_monitor_handles()" in <path to newlib source>/newlib/libc/sys/arm/syscalls.c

Regards,
Tony

Revision history for this message
Doug Turnbow (douglas-turnbow) said :
#3

Thanks I'll take a look

Revision history for this message
Doug Turnbow (douglas-turnbow) said :
#4

Thanks Thomas Preud'homme, that solved my question.