This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Prevent double new lines behind errors/warning/messages from LLDB commands
ClosedPublic

Authored by teemperor on Feb 18 2021, 2:31 AM.

Details

Summary

The current API for printing errors/warnings/messages from LLDB commands sometimes
adds newlines behind the messages for the caller. However, this happens unconditionally
so when the caller already specified a trailing newline in the error message (or is trying to print
a generated error message that ends in a newline), LLDB ends up printing both the automatically
added newline and the one that was in the error message string. This leads to all the randomly
appearing new lines in error such as:

(lldb) command a
error: 'command alias' requires at least two arguments
(lldb) apropos a b
error: 'apropos' must be called with exactly one argument.

(lldb) why is there an empty line behind the second error?

This code adds a check that only appends the new line if the passed message doesn't already
contain a trailing new line.

Also removes the AppendRawWarning which had only one caller and doesn't serve any
purpose now.

Diff Detail

Event Timeline

teemperor created this revision.Feb 18 2021, 2:31 AM
teemperor requested review of this revision.Feb 18 2021, 2:31 AM
teemperor edited the summary of this revision. (Show Details)
mib accepted this revision.Feb 18 2021, 2:35 AM
mib added a subscriber: mib.

LGTM!

This revision is now accepted and ready to land.Feb 18 2021, 2:35 AM

FWIW, I am very interested in finding out how we can over-engineer this. I do believe there is potential to let tablegen generate the error message strings which then could also check the new lines for us.

Also I'm going to clean the existing error messages from redundant newlines in a separate NFC commit.

Thanks for looking at this, I had the same confusion adding some new commands.

JDevlieghere added inline comments.Feb 19 2021, 3:09 PM
lldb/source/Interpreter/CommandReturnObject.cpp
93

How about rstripping any trailing \n and then always adding one?

teemperor added inline comments.Feb 24 2021, 5:42 AM
lldb/source/Interpreter/CommandReturnObject.cpp
93

I actually like the idea even more. I updated to rstrip and then just add a newline.