This revision was automatically updated to reflect the committed changes.
Closed by commit rL362240: [FormatEntity] Ignore ASCII escape sequences when 
colors are disabled. (authored by JDevlieghere, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62714?vs=202354&id=202452#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62714/new/

https://reviews.llvm.org/D62714

Files:
  lldb/trunk/include/lldb/Core/FormatEntity.h
  lldb/trunk/lit/Settings/Inputs/main.c
  lldb/trunk/lit/Settings/TestFrameFormatColor.test
  lldb/trunk/lit/Settings/TestFrameFormatNoColor.test
  lldb/trunk/source/Core/FormatEntity.cpp

Index: lldb/trunk/source/Core/FormatEntity.cpp
===================================================================
--- lldb/trunk/source/Core/FormatEntity.cpp
+++ lldb/trunk/source/Core/FormatEntity.cpp
@@ -94,7 +94,7 @@
         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 @@
     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;
Index: lldb/trunk/lit/Settings/Inputs/main.c
===================================================================
--- lldb/trunk/lit/Settings/Inputs/main.c
+++ lldb/trunk/lit/Settings/Inputs/main.c
@@ -0,0 +1,2 @@
+int foo() { return 0; }
+int main() { return foo(); }
Index: lldb/trunk/lit/Settings/TestFrameFormatColor.test
===================================================================
--- lldb/trunk/lit/Settings/TestFrameFormatColor.test
+++ lldb/trunk/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/trunk/lit/Settings/TestFrameFormatNoColor.test
===================================================================
--- lldb/trunk/lit/Settings/TestFrameFormatNoColor.test
+++ lldb/trunk/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/trunk/include/lldb/Core/FormatEntity.h
===================================================================
--- lldb/trunk/include/lldb/Core/FormatEntity.h
+++ lldb/trunk/include/lldb/Core/FormatEntity.h
@@ -41,7 +41,7 @@
       Invalid,
       ParentNumber,
       ParentString,
-      InsertString,
+      EscapeCode,
       Root,
       String,
       Scope,
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to