Skip to content

Commit d10ce06

Browse files
committed
[lldb] Remove redundant severity substring within a diagnostic message.
For example, the following message has the severity string "error: " twice. > "error: <EXPR>:3:1: error: cannot find 'bogus' in scope This method already appends the severity string in the beginning, but with this fix, it also removes a secondary instance, if applicable. Note that this change only removes the *first* redundant substring. I considered putting the removal logic in a loop, but I decided that if something is generating more than one redundant severity substring, then that's a problem the message's source should probably fix. rdar://114203423
1 parent 07d6fbf commit d10ce06

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lldb/source/Expression/DiagnosticManager.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,20 @@ static const char *StringForSeverity(DiagnosticSeverity severity) {
4646

4747
std::string DiagnosticManager::GetString(char separator) {
4848
std::string ret;
49+
llvm::raw_string_ostream stream(ret);
4950

5051
for (const auto &diagnostic : Diagnostics()) {
51-
ret.append(StringForSeverity(diagnostic->GetSeverity()));
52-
ret.append(std::string(diagnostic->GetMessage()));
53-
ret.push_back(separator);
52+
llvm::StringRef severity = StringForSeverity(diagnostic->GetSeverity());
53+
stream << severity;
54+
55+
llvm::StringRef message = diagnostic->GetMessage();
56+
std::string searchable_message = message.lower();
57+
auto severity_pos = message.find(severity);
58+
stream << message.take_front(severity_pos);
59+
60+
if (severity_pos != llvm::StringRef::npos)
61+
stream << message.drop_front(severity_pos + severity.size());
62+
stream << separator;
5463
}
5564

5665
return ret;

lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test(self):
2121
"expr @import LLDBTestModule",
2222
error=True,
2323
substrs=[
24-
"module.h:4:1: error: use of undeclared identifier 'syntax_error_for_lldb_to_find'",
24+
"module.h:4:1: use of undeclared identifier 'syntax_error_for_lldb_to_find'",
2525
"syntax_error_for_lldb_to_find // comment that tests source printing",
2626
"could not build module 'LLDBTestModule'",
2727
],

0 commit comments

Comments
 (0)