Index: lldb/include/lldb/Core/FormatEntity.h =================================================================== --- lldb/include/lldb/Core/FormatEntity.h +++ lldb/include/lldb/Core/FormatEntity.h @@ -41,7 +41,7 @@ Invalid, ParentNumber, ParentString, - InsertString, + EscapeCode, Root, String, Scope, Index: lldb/lit/Settings/Inputs/main.c =================================================================== --- /dev/null +++ lldb/lit/Settings/Inputs/main.c @@ -0,0 +1,2 @@ +int foo() { return 0; } +int main() { return foo(); } Index: lldb/lit/Settings/TestFrameFormatColor.test =================================================================== --- /dev/null +++ lldb/lit/Settings/TestFrameFormatColor.test @@ -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:  Index: lldb/lit/Settings/TestFrameFormatNoColor.test =================================================================== --- /dev/null +++ lldb/lit/Settings/TestFrameFormatNoColor.test @@ -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:  Index: lldb/source/Core/FormatEntity.cpp =================================================================== --- lldb/source/Core/FormatEntity.cpp +++ lldb/source/Core/FormatEntity.cpp @@ -94,7 +94,7 @@ static_cast(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 @@ 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 @@ // 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 @@ 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 @@ 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;