[bug #52181] assert should make Serial.flush() before calling abort()

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[bug #52181] assert should make Serial.flush() before calling abort()

Joerg Wunsch-6
URL:
  <http://savannah.nongnu.org/bugs/?52181>

                 Summary: assert should make Serial.flush() before calling
abort()
                 Project: AVR C Runtime Library
            Submitted by: pukuri
            Submitted on: Sat 07 Oct 2017 02:58:08 AM UTC
                Category: Library
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: libc code
                  Status: None
        Percent Complete: 0%
             Assigned to: None
        Originator Email:
             Open/Closed: Open
         Discussion Lock: Any
                 Release: Any
           Fixed Release: None

    _______________________________________________________

Details:

I'm quite new to this project, hopefully I'm submitting this bug at the corect
place, if not, please point me in the right direction...

if the expression in the assert function fails, a fprintf to stderr is made
and then the function abort() is called which runs in an endless loop.

The problem is, because the abort() function disables all interrupts (which is
fine), the remaining bytes in the buffer for the serial interface will not be
printed (not so good). Only the very first couple of bytes will be seen.

recomended solution: just before calling abort think about calling
Serial.flush(), or similar...

Problem with this solution is, that Serial.flush comes from the Arduino
environment and has nothing to do with libc, but on the other hand fflush()
does nothing

So, I have no real solution for this problem, but hopefully the insiders might
come up with something.

Right now the assert function is useless, because one get no information where
and why the program stops.




    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?52181>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/


_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|

[bug #52181] assert should make Serial.flush() before calling abort()

Joerg Wunsch-6
Follow-up Comment #1, bug #52181 (project avr-libc):

This is not an avr-libc problem.  The stdio routines like prinf are fully
synchronous, and there is no buffering.

Hence any buffering must emerge from the applicaton's stream implementation,
i.e. from the callbacks you are providing with FDEV_SETUP_STREAM or by similar
means.

One fix is to provide a destructor for your static buffering object.  abort
will call _exit which will run all the static destructors and all the
functions registered with atexit.

Beside thar, gnu tools allow to provide own static destructors even for C, and
avr tool allow to override abort, _exit and exit and to run own shutdown code
located in dedicated sections .fini9 ... .fini0.

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?52181>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/


_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|

[bug #52181] assert should make Serial.flush() before calling abort()

Joerg Wunsch-6
Update of bug #52181 (project avr-libc):

                  Status:                    None => Wont Fix              
             Open/Closed:                    Open => Closed                

    _______________________________________________________

Follow-up Comment #2:

I agree with Johann on that. There's nothing avr-libc could do about it.

If Arduino (which I think is what you are talking about) needs
a Serial.flush() before disabling interrupts, I think it would
be best if the Arduino environment would override abort() by
their own implementation. While this is not really covered by
the C standard (library functions must not be reimplemented by
the application), I think it will work well here. If not, we
could always resort to implementing an overridable _Abort()
backend function that can then be reimplemented by the Arduino
environment.


    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?52181>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/


_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|

[bug #52181] assert should make Serial.flush() before calling abort()

Joerg Wunsch-6
Follow-up Comment #3, bug #52181 (project avr-libc):

Thanks a lot for your help and pointing me in the right direction!

Added a Destructor to the Serial class, temporarily enabled the interrupts, to
print out the last bytes, freed some resources and it worked like a charm.

Sadly it showed me again how buggy the Arduino environment is...


    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?52181>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/


_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev