Forum Discussion

BeB's avatar
BeB
Icon for Occasional Contributor rankOccasional Contributor
11 months ago

segmentation fault with nios2-terminal and printf/alt_printf statements

Hello,

I am running into segmentation faults using either alt_printf or printf to output debug messages from a nios 2 application via the nios2-terminal application.

The code runs fine without the debug print messages, and also runs fine with the debug print messages in debug mode with breakpoints at the troublesome debug print statements.

I will add that some debug print messages are printed normally, so it is not a systematic issue with printf / alt_printf. Changing the messages that fail still leads to a segmentation fault (reducing the size of the message or the nature of it - integer vs string for example).

It cannot be a code issue since it's running fine in debug mode. I am a bit lost here.

My RAM should be more than large enough:

$ nios2-elf-size nios_app.elf
text data bss dec hex filename
34892 884 376 36152 8d38 nios_app.elf

$ nios2-stackreport nios_app.elf
Info: (nios_app.elf) 35 KBytes program size (code + initialized data).
Info: 91 KBytes free for stack + heap.

I have the feeling that the issue comes from the JTAG uart. I have seen suggestions online to flush the stdout with fflush, but Eclipse fails to resolve the reference to fflush although stdio.h is included. Could be because I am running the economical Nios implementation?

Increasing the JTAG uart buffer size or decreasing it does not seem to make a difference.

Thank you for any suggestions!

Bertrand

10 Replies

  • tehjingy_Altera's avatar
    tehjingy_Altera
    Icon for Regular Contributor rankRegular Contributor

    Hi


    This is a weird behaviour.

    In the BSP setting did you select the JTAG Uart as the stdout for the print function?


    Regards

    Jingyang, Teh


    • BeB's avatar
      BeB
      Icon for Occasional Contributor rankOccasional Contributor

      Hello,

      Yes, stdout is the JTAG uart.

      Thank you,

      Bertrand

    • BeB's avatar
      BeB
      Icon for Occasional Contributor rankOccasional Contributor

      Hello,

      Sorry for the late reply.

      A simple 'hello world' works fine.

      It seems that changing the size of the stdout uart buffer solved the problem. A too large buffer causes the segmentation fault. Reducing the buffer size eliminated the issue (with the exact same code otherwise!).

      Thank you,

      Bertrand

    • BeB's avatar
      BeB
      Icon for Occasional Contributor rankOccasional Contributor

      Hello,

      Sorry for the late reply.

      It seems that changing the size of the stdout uart buffer solved the problem. A too large buffer causes the segmentation fault. Reducing the buffer size eliminated the issue (with the exact same code otherwise!).

      Thank you,

      Bertrand

  • tehjingy_Altera's avatar
    tehjingy_Altera
    Icon for Regular Contributor rankRegular Contributor

    Hi


    As we do not receive any response from you on the previous question/reply/answer that we have provided. Please login to ‘https://supporttickets.intel.com/s/?language=en_US’, view details of the desire request, and post a feed/response within the next 15 days to allow me to continue to support you. After 15 days, this thread will be transitioned to community support. The community users will be able to help you on your follow-up questions.


    Regards

    Jingyang, Teh



  • tehjingy_Altera's avatar
    tehjingy_Altera
    Icon for Regular Contributor rankRegular Contributor

    Hi


    If you mind sharing, what was the buffer size that you use initially? and what was the reduced size that managed to get it to work?


    Regards

    Jingyang, Teh


  • tehjingy_Altera's avatar
    tehjingy_Altera
    Icon for Regular Contributor rankRegular Contributor

    Hi


    As we did not receive any response from you on the previous question/reply/answer that we have provided. Please login to ‘https://supporttickets.intel.com/s/?language=en_US’, view details of the desire request, and post a feed/response within the next 15 days to allow me to continue to support you. After 15 days, this thread will be transitioned to community support. The community users will be able to help you on your follow-up questions.


    Regards

    Jingyang, Teh