I've written a patch for this. But currently, it's not enabled because putting arbitrary non-printing characters into the trace_printk() buffer seems to be a good recipe for chaos.
So this issue also depends on PR22330.
Committed a patch which allows all non-printing characters except '\0' (which is dropped silently). This allows ansi_colors examples to work with stapbpf.
Closing this PR, will open new ones if any edge cases come up.
Commit 9f888f1630cce8527f14d93d8b638952e4c45f71 seems to work fine for the ansi_colors and ansi_colors2 examples and they now work with the bpf backend.