Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added stripping of ANSI escape sequences (include colorization) from inputs #1038

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

BOBAH1248
Copy link

I found that, when colorization enabled, the backtrace of exceptions may not parsed even if all looks fine:

Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x4008a7db  PS      : 0x00060d30  A0      : 0x800fa8bf  A1      : 0x3ffcfa20  
A2      : 0x3fff9bd4  A3      : 0x00000000  A4      : 0x00000001  A5      : 0x3ffcf860
A6      : 0x00000002  A7      : 0x3ffcf860  A8      : 0x00000000  A9      : 0x00000000  
A10     : 0x00000001  A11     : 0x000000a2  A12     : 0x00000001  A13     : 0x0000ff00
A14     : 0x00000001  A15     : 0x3ffcf884  SAR     : 0x0000001e  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x4008b249  LEND    : 0x4008b26d  LCOUNT  : 0x800d3622


Backtrace:0x4008a7d8:0x3ffcfa200x400fa8bc:0x3ffcfa40 0x400fa9e2:0x3ffcfa60 0x400d375d:0x3ffcfa80 0x400d3a08:0x3ffcfad0 0x400dc17b:0x3ffcfaf0 0x400dc264:0x3ffcfb60 0x400dc275:0x3ffcfb80 0x400926ab:0x3ffcfba0 

I added logs to script:

            line = text[last:idx]
            if self.buffer:
                line = self.buffer + line
                self.buffer = ""
            last = idx + 1

            sys.stderr.write(
                "%s: line='%s'\n" % (self.__class__.__name__, line.encode("ascii", "backslashreplace"))
            )
...

And catched the following string:

Esp32ExceptionDecoder: line='b'Backtrace:0x4008a7d8:0x3ffcfa200x400fa8bc:0x3ffcfa\x1b[37m4\x1b[37m0 0x400fa9e2:0x3ffcfa60 0x400d375d:0x3ffcfa80 0x400d3a08:0x3ffc\x1b[37mf\x1b[37mad0 0x400dc17b:0x3ffcfaf0 0x400dc264:0x3ffcfb60 0x400dc275:0x3f\x1b[37mf\x1b[37mcfb80 0x400926ab:0x3ffcfba0 \r''

My patch fixes this "annoying misunderstanding"

@valeros
Copy link
Member

valeros commented Mar 13, 2023

@BOBAH1248 Is this PR should be closed as well as #1039?

@BOBAH1248
Copy link
Author

BOBAH1248 commented Mar 13, 2023

@valeros the message "Backtrace:..." is part of ESP-IDF (.platformio/packages/framework-espidf/components/esp_system/eh_frame_parser.c:897, .platformio/packages/framework-espidf/components/esp_system/port/arch/xtensa/debug_helpers.c:76)
If I'm right, this framework used as precompiled library (in opposed to FrameworkArduino), that did not changed.
So, I have no ideas how may be added colors (<ESC>[37m) to outputs.
But I able to catch it, as shown in description.

And because this fix just cleanup such non-printable ANSI escape sequences (for backtrace processing only), I don’t see any reason to just in case not clear the backtrace string of garbage (which maybe in string, as once ruined a lot of nerves and time for me; but maybe not in string, because the reason for its appearance in output of a precompiled library has not been established by me).

@BOBAH1248
Copy link
Author

I noticed one feature - "color change sequences" appear with a frequency of 64 bytes.
Perhaps it was the buffer boundary of one of my usb2uart adapters. And improper use of filters (for example monitor_filters = colorize,...) could lead to a similar effect.
it seems that this problem is difficult to replicate due to the specific conditions of software and hardware dependencies, which cannot be called anything other than "apparently the stars have aligned such" or "the weather on Mars is not the same today"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants