Author: jdevlieghere Date: Fri May 31 09:27:44 2019 New Revision: 362240 URL: http://llvm.org/viewvc/llvm-project?rev=362240&view=rev Log: [FormatEntity] Ignore ASCII escape sequences when colors are disabled.
This patch makes the FormatEntity honor the debugger's color settings by not inserting ASCII escape sequences when colors are disabled. Differential revision: https://reviews.llvm.org/D62714 Added: lldb/trunk/lit/Settings/Inputs/main.c lldb/trunk/lit/Settings/TestFrameFormatColor.test lldb/trunk/lit/Settings/TestFrameFormatNoColor.test Modified: lldb/trunk/include/lldb/Core/FormatEntity.h lldb/trunk/source/Core/FormatEntity.cpp Modified: lldb/trunk/include/lldb/Core/FormatEntity.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FormatEntity.h?rev=362240&r1=362239&r2=362240&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/FormatEntity.h (original) +++ lldb/trunk/include/lldb/Core/FormatEntity.h Fri May 31 09:27:44 2019 @@ -41,7 +41,7 @@ public: Invalid, ParentNumber, ParentString, - InsertString, + EscapeCode, Root, String, Scope, Added: lldb/trunk/lit/Settings/Inputs/main.c URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Settings/Inputs/main.c?rev=362240&view=auto ============================================================================== --- lldb/trunk/lit/Settings/Inputs/main.c (added) +++ lldb/trunk/lit/Settings/Inputs/main.c Fri May 31 09:27:44 2019 @@ -0,0 +1,2 @@ +int foo() { return 0; } +int main() { return foo(); } Added: lldb/trunk/lit/Settings/TestFrameFormatColor.test URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Settings/TestFrameFormatColor.test?rev=362240&view=auto ============================================================================== --- lldb/trunk/lit/Settings/TestFrameFormatColor.test (added) +++ lldb/trunk/lit/Settings/TestFrameFormatColor.test Fri May 31 09:27:44 2019 @@ -0,0 +1,12 @@ +# RUN: %clang -g -O0 %S/Inputs/main.c -o %t.out +# RUN: %lldb -x -b -s %s %t.out | FileCheck %s +settings set use-color true +settings set -f frame-format "frame #${frame.index}: \`${ansi.fg.green}{${function.name-with-args}${ansi.normal}\n" +b foo +run +bt +c +q + +# Check the ASCII escape code +# CHECK: Added: lldb/trunk/lit/Settings/TestFrameFormatNoColor.test URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Settings/TestFrameFormatNoColor.test?rev=362240&view=auto ============================================================================== --- lldb/trunk/lit/Settings/TestFrameFormatNoColor.test (added) +++ lldb/trunk/lit/Settings/TestFrameFormatNoColor.test Fri May 31 09:27:44 2019 @@ -0,0 +1,12 @@ +# RUN: %clang -g -O0 %S/Inputs/main.c -o %t.out +# RUN: %lldb -x -b -s %s %t.out | FileCheck %s +settings set use-color false +settings set -f frame-format "frame #${frame.index}: \`${ansi.fg.green}{${function.name-with-args}${ansi.normal}\n" +b foo +run +bt +c +q + +# Check the ASCII escape code +# CHECK-NOT: Modified: lldb/trunk/source/Core/FormatEntity.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatEntity.cpp?rev=362240&r1=362239&r2=362240&view=diff ============================================================================== --- lldb/trunk/source/Core/FormatEntity.cpp (original) +++ lldb/trunk/source/Core/FormatEntity.cpp Fri May 31 09:27:44 2019 @@ -94,7 +94,7 @@ enum FileKind { FileError = 0, Basename, static_cast<uint32_t>(llvm::array_lengthof(c)), c, true \ } #define ENTRY_STRING(n, s) \ - { n, s, FormatEntity::Entry::Type::InsertString, 0, 0, nullptr, false } + { n, s, FormatEntity::Entry::Type::EscapeCode, 0, 0, nullptr, false } static FormatEntity::Entry::Definition g_string_entry[] = { ENTRY("*", ParentString)}; @@ -307,7 +307,7 @@ const char *FormatEntity::Entry::TypeToC ENUM_TO_CSTR(Invalid); ENUM_TO_CSTR(ParentNumber); ENUM_TO_CSTR(ParentString); - ENUM_TO_CSTR(InsertString); + ENUM_TO_CSTR(EscapeCode); ENUM_TO_CSTR(Root); ENUM_TO_CSTR(String); ENUM_TO_CSTR(Scope); @@ -1102,8 +1102,17 @@ bool FormatEntity::Format(const Entry &e // FormatEntity::Entry::Definition encoding case Entry::Type::ParentString: // Only used for // FormatEntity::Entry::Definition encoding - case Entry::Type::InsertString: // Only used for - // FormatEntity::Entry::Definition encoding + return false; + case Entry::Type::EscapeCode: + if (exe_ctx) { + if (Target *target = exe_ctx->GetTargetPtr()) { + Debugger &debugger = target->GetDebugger(); + if (debugger.GetUseColor()) { + s.PutCString(entry.string); + return true; + } + } + } return false; case Entry::Type::Root: @@ -1896,7 +1905,7 @@ static Status ParseEntry(const llvm::Str entry.number = entry_def->data; return error; // Success - case FormatEntity::Entry::Type::InsertString: + case FormatEntity::Entry::Type::EscapeCode: entry.type = entry_def->type; entry.string = entry_def->string; return error; // Success @@ -2265,13 +2274,7 @@ Status FormatEntity::ParseInternal(llvm: return error; } } - // Check if this entry just wants to insert a constant string value - // into the parent_entry, if so, insert the string with AppendText, - // else append the entry to the parent_entry. - if (entry.type == Entry::Type::InsertString) - parent_entry.AppendText(entry.string.c_str()); - else - parent_entry.AppendEntry(std::move(entry)); + parent_entry.AppendEntry(std::move(entry)); } } break; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits