Skip to content

Stop DWARF expression pattern matching at the end of the expression - #129

Open
SSE4 wants to merge 1 commit into
yandex:mainfrom
SSE4:dwarf-matcher-stop-at-end
Open

SSE4 wants to merge 1 commit into
yandex:mainfrom
SSE4:dwarf-matcher-stop-at-end

Conversation

@SSE4

@SSE4 SSE4 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

TDwarfExpressionPattern::Matches() keeps comparing pattern operations after the expression has run out.
A DWARFExpression end iterator still holds the last decoded operation (only its Error flag is set),
so a pattern that repeats the last operation matches a shorter expression:
[breg7 8, deref, deref] matches [breg7 8, deref].

None of the current CFA patterns repeat their last operation, so the unwind tables built today are not
affected. It matters for patterns that share a prefix, such as *(reg + offset) and
*(reg + offset) + bias added in #130.

Fix

Return false when the expression ends before the pattern does.

Testing

New agent/preprocessing/lib/ut with matcher tests: exact match with wildcards, operand mismatch,
expressions longer and shorter than the pattern, an empty expression, and a pattern repeating the last
operation. Without the fix, PatternRepeatingLastOperation fails:

Value of: Matches(pattern, {OP_breg7, 0x08, OP_deref})
  Actual: true
Expected: false

TDwarfExpressionPattern::Matches() kept comparing pattern operations
after the expression ran out. A DWARFExpression end iterator still holds
the last decoded operation, so a pattern that repeats the last operation
matched a shorter expression: [breg7 8, deref, deref] matched
[breg7 8, deref].

None of the current CFA patterns repeat their last operation, so this
does not change the unwind tables built today, but it makes adding
patterns that share a prefix safe. Add unit tests for the matcher.
@robot-magpie

robot-magpie Bot commented Nov 13, 2026

Copy link
Copy Markdown

✅ All contributors are covered under a CLA with Yandex

See CONTRIBUTING.md for more info about Yandex Contributor License Agreement.


The following contributors were found:
✅ e2ef2bb Author: @SSE4 (to*****de@gmail.com)

(Only the first commit for a unique contributor is listed)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant