Attention is currently required from: Raul Rangel, Jakub Czapiga, Grzegorz Bernacki.
Konrad Adamczyk has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/74742 )
Change subject: util/cbmem: Add REG_NEWLINE flag to fix matching pattern ......................................................................
Patch Set 1:
(1 comment)
Commit Message:
https://review.coreboot.org/c/coreboot/+/74742/comment/ac069d44_59a6ad4e PS1, Line 13: REG_NEWLINE
How was this working before? Did we change the banner?
TL;DR: `How was this working before?` - Match occured not on the first line, but until `Starting kernel...` log (basically, whole boot log). `Did we change the banner?` - Change of BANNER_REGEX was introduced in https://review.coreboot.org/c/coreboot/+/62720.
`-- Long version stars here --`: Before this CL, if `cbmem` buffer contained logs from two boots, match for regex occured three times: 1. Whole boot log (from `coreboot-` till `Starting kernel...` where three dots at the end matched BANNER_REGEX), 2. Second boot log (from `coreboot-` till `Starting kernel...`) (due to `.?`) 3. Second boot log again (from `coreboot-` till `Starting kernel...`)
Because the `.*` and `.?` matched characters including newlines (keep in mind that at the end of `Starting kernel...` there're `\n` characters)
It can be checked by looking at the `match.rm_so` and `match.rm_eo`.
`cbmem -c` showed whole log since the matching pattern is applied only `if (type != CONSOLE_PRINT_FULL)`.
For `cbmem -1`, the cursor position was set to the start of the second boot log (off by one `\n`), so we're fine (I believe no one noticed missing `\n` at the beginning of the boot log).
However, for the `cbmem -2`, we've hit: ``` if (type == CONSOLE_PRINT_PREVIOUS) { console_c[cursor] = '\0'; cursor = previous; } ```
where before this if statement, `cursor` was equal to `previous + 1`, so the next character in `console_c` buffer was NULL - that's why the `cbmem -2` was not working properly (due to `.?` in regex matched newlines).
Change from https://review.coreboot.org/c/coreboot/+/62720 introduced this issue (by switching to REG_EXTENDED syntax and using `.?`). Prior to this CL, `cbmem -2` worked fine since only two (instead of three) matches occured (no `.?` in BANNER_REGEX).
`-- Long version ends here --`
Nevertheless, please correct me if I'm wrong here - I believe that the intention was to not catch newlines with particular regex (since regex itself contains escaped `\n` characters to be matched explicitly). Moreover, I believe that this code shall match only the first line of boot log, not the whole boot log to `Starting kernel...`.
Adding REG_NEWLINE to `rexcomp` does exactly that (while keeping the loglevel markers support in place). If you think there's a better way to solve it, I'd be grateful to hear your ideas.