This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Fix that trailing backslashes in source lines break the Clang highlighter
ClosedPublic

Authored by teemperor on Nov 13 2019, 6:24 AM.

Details

Summary

Clang's raw Lexer doesn't produce any tokens for trailing backslashes in a line. This doesn't work with
LLDB's Clang highlighter which builds the source code to display from the list of tokens the Lexer returns.
This causes that lines with trailing backslashes are lacking the backslash and the following newline when
rendering source code in LLDB.

This patch removes the trailing newline from the current line we are highlighting. This way Clang doesn't
drop the backslash token and we just restore the newline after tokenising.

Fixes rdar://57091487

Diff Detail

Event Timeline

teemperor created this revision.Nov 13 2019, 6:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 13 2019, 6:24 AM
labath added a subscriber: labath.Nov 13 2019, 6:40 AM
labath added inline comments.
lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp
150

technically, this trim might remove additional spurious carriage return characters that will not be restored correctly afterwards. What I'd do is replace endswith with consume_back which will also remove the suffix while testing for it's presence.

teemperor updated this revision to Diff 229087.Nov 13 2019, 6:50 AM
  • Moved to consume_back
labath accepted this revision.Nov 13 2019, 7:02 AM
This revision is now accepted and ready to land.Nov 13 2019, 7:02 AM
labath added inline comments.Nov 13 2019, 7:06 AM
lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp
149

= line_had_lf && consume_back(\r)

JDevlieghere accepted this revision.Nov 13 2019, 8:55 AM

LGTM with Pavel's comment. Thanks for the quick turnaround on this!

  • Turns out \r is also a new line that can be escaped, so that is now also handled. Also moved to a variable storing the line ending instead of three bools.
This revision was automatically updated to reflect the committed changes.