[Lldb-commits] [lldb] r182609 - Add ${ansi.XX} parsing to lldb prompt, use-color setting, and -no-use-colors command line options.

Michael Sartain mikesart at valvesoftware.com
Thu May 23 13:47:45 PDT 2013


Author: mikesart
Date: Thu May 23 15:47:45 2013
New Revision: 182609

URL: http://llvm.org/viewvc/llvm-project?rev=182609&view=rev
Log:
Add ${ansi.XX} parsing to lldb prompt, use-color setting, and -no-use-colors command line options.
settings set use-color [false|true]
settings set prompt "${ansi.bold}${ansi.fg.green}(lldb)${ansi.normal} "
also "--no-use-colors" on the command prompt


Modified:
    lldb/trunk/include/lldb/API/SBDebugger.h
    lldb/trunk/include/lldb/Core/Debugger.h
    lldb/trunk/include/lldb/Utility/AnsiTerminal.h
    lldb/trunk/source/API/SBDebugger.cpp
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/DataFormatters/LibCxx.cpp
    lldb/trunk/source/DataFormatters/TypeSummary.cpp
    lldb/trunk/source/Target/StackFrame.cpp
    lldb/trunk/source/Target/Thread.cpp
    lldb/trunk/tools/driver/Driver.cpp

Modified: lldb/trunk/include/lldb/API/SBDebugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDebugger.h?rev=182609&r1=182608&r2=182609&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBDebugger.h (original)
+++ lldb/trunk/include/lldb/API/SBDebugger.h Thu May 23 15:47:45 2013
@@ -172,6 +172,12 @@ public:
     bool 
     GetUseExternalEditor ();
 
+    bool
+    SetUseColor (bool use_color);
+
+    bool
+    GetUseColor () const;
+
     static bool
     GetDefaultArchitecture (char *arch_name, size_t arch_name_len);
 

Modified: lldb/trunk/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=182609&r1=182608&r2=182609&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Debugger.h (original)
+++ lldb/trunk/include/lldb/Core/Debugger.h Thu May 23 15:47:45 2013
@@ -236,7 +236,6 @@ public:
                   const ExecutionContext *exe_ctx,
                   const Address *addr,
                   Stream &s,
-                  const char **end,
                   ValueObject* valobj = NULL);
 
 
@@ -308,6 +307,12 @@ public:
     bool
     SetUseExternalEditor (bool use_external_editor_p);
     
+    bool
+    GetUseColor () const;
+    
+    bool
+    SetUseColor (bool use_color);
+    
     uint32_t
     GetStopSourceLineCount (bool before) const;
     

Modified: lldb/trunk/include/lldb/Utility/AnsiTerminal.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/AnsiTerminal.h?rev=182609&r1=182608&r2=182609&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/AnsiTerminal.h (original)
+++ lldb/trunk/include/lldb/Utility/AnsiTerminal.h Thu May 23 15:47:45 2013
@@ -21,7 +21,7 @@
 #define ANSI_BG_COLOR_BLACK         40
 #define ANSI_BG_COLOR_RED           41	
 #define ANSI_BG_COLOR_GREEN         42	
-#define ANSI_BG_COLOR_YELLOW        44	
+#define ANSI_BG_COLOR_YELLOW        43	
 #define ANSI_BG_COLOR_BLUE          44	
 #define ANSI_BG_COLOR_PURPLE        45	
 #define ANSI_BG_COLOR_CYAN          46	
@@ -82,5 +82,75 @@ namespace lldb_utility {
         const char *k_ctrl_conceal	     = "8";
         const char *k_ctrl_crossed_out	 = "9";
 
+        inline std::string
+        FormatAnsiTerminalCodes(const char *format, bool do_color = true)
+        {
+            // Convert "${ansi.XXX}" tokens to ansi values or clear them if do_color is false.
+            static const struct
+            {
+                const char *name;
+                const char *value;
+            } g_color_tokens[] =
+            {
+        #define _TO_STR2(_val) #_val
+        #define _TO_STR(_val) _TO_STR2(_val)
+                { "fg.black}",        ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_BLACK)      ANSI_ESC_END },
+                { "fg.red}",          ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_RED)        ANSI_ESC_END },
+                { "fg.green}",        ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_GREEN)      ANSI_ESC_END },
+                { "fg.yellow}",       ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_YELLOW)     ANSI_ESC_END },
+                { "fg.blue}",         ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_BLUE)       ANSI_ESC_END },
+                { "fg.purple}",       ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_PURPLE)     ANSI_ESC_END },
+                { "fg.cyan}",         ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_CYAN)       ANSI_ESC_END },
+                { "fg.white}",        ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_WHITE)      ANSI_ESC_END },
+                { "bg.black}",        ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BLACK)      ANSI_ESC_END },
+                { "bg.red}",          ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_RED)        ANSI_ESC_END },
+                { "bg.green}",        ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_GREEN)      ANSI_ESC_END },
+                { "bg.yellow}",       ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_YELLOW)     ANSI_ESC_END },
+                { "bg.blue}",         ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BLUE)       ANSI_ESC_END },
+                { "bg.purple}",       ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_PURPLE)     ANSI_ESC_END },
+                { "bg.cyan}",         ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_CYAN)       ANSI_ESC_END },
+                { "bg.white}",        ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_WHITE)      ANSI_ESC_END },
+                { "normal}",          ANSI_ESC_START _TO_STR(ANSI_CTRL_NORMAL)         ANSI_ESC_END },
+                { "bold}",            ANSI_ESC_START _TO_STR(ANSI_CTRL_BOLD)           ANSI_ESC_END },
+                { "faint}",           ANSI_ESC_START _TO_STR(ANSI_CTRL_FAINT)          ANSI_ESC_END },
+                { "italic}",          ANSI_ESC_START _TO_STR(ANSI_CTRL_ITALIC)         ANSI_ESC_END },
+                { "underline}",       ANSI_ESC_START _TO_STR(ANSI_CTRL_UNDERLINE)      ANSI_ESC_END },
+                { "slow-blink}",      ANSI_ESC_START _TO_STR(ANSI_CTRL_SLOW_BLINK)     ANSI_ESC_END },
+                { "fast-blink}",      ANSI_ESC_START _TO_STR(ANSI_CTRL_FAST_BLINK)     ANSI_ESC_END },
+                { "negative}",        ANSI_ESC_START _TO_STR(ANSI_CTRL_IMAGE_NEGATIVE) ANSI_ESC_END },
+                { "conceal}",         ANSI_ESC_START _TO_STR(ANSI_CTRL_CONCEAL)        ANSI_ESC_END },
+                { "crossed-out}",     ANSI_ESC_START _TO_STR(ANSI_CTRL_CROSSED_OUT)    ANSI_ESC_END },
+        #undef _TO_STR
+        #undef _TO_STR2
+            };
+            static const char tok_hdr[] = "${ansi.";
+
+            std::string fmt;
+            for (const char *p = format; *p; ++p)
+            {
+                const char *tok_start = strstr (p, tok_hdr);
+                if (!tok_start)
+                {
+                    fmt.append (p, strlen(p));
+                    break;
+                }
+
+                fmt.append (p, tok_start - p);
+                p = tok_start;
+
+                const char *tok_str = tok_start + sizeof(tok_hdr) - 1;
+                for (size_t i = 0; i < sizeof(g_color_tokens) / sizeof(g_color_tokens[0]); ++i)
+                {
+                    if (!strncmp (tok_str, g_color_tokens[i].name, strlen(g_color_tokens[i].name)))
+                    {
+                        if (do_color)
+                            fmt.append (g_color_tokens[i].value);
+                        p = tok_str + strlen (g_color_tokens[i].name) - 1;
+                        break;
+                    }
+                }
+            }
+            return fmt;
+        }
     }
 }

Modified: lldb/trunk/source/API/SBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=182609&r1=182608&r2=182609&view=diff
==============================================================================
--- lldb/trunk/source/API/SBDebugger.cpp (original)
+++ lldb/trunk/source/API/SBDebugger.cpp Thu May 23 15:47:45 2013
@@ -1057,6 +1057,22 @@ SBDebugger::GetUseExternalEditor ()
 }
 
 bool
+SBDebugger::SetUseColor (bool value)
+{
+    if (m_opaque_sp)
+        return m_opaque_sp->SetUseColor (value);
+    return false;
+}
+
+bool
+SBDebugger::GetUseColor () const
+{
+    if (m_opaque_sp)
+        return m_opaque_sp->GetUseColor ();
+    return false;
+}
+
+bool
 SBDebugger::GetDescription (SBStream &description)
 {
     Stream &strm = description.ref();

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=182609&r1=182608&r2=182609&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Thu May 23 15:47:45 2013
@@ -131,6 +131,7 @@ g_properties[] =
 {   "term-width",               OptionValue::eTypeSInt64 , true, 80   , NULL, NULL, "The maximum number of columns to use for displaying text." },
 {   "thread-format",            OptionValue::eTypeString , true, 0    , DEFAULT_THREAD_FORMAT, NULL, "The default thread format string to use when displaying thread information." },
 {   "use-external-editor",      OptionValue::eTypeBoolean, true, false, NULL, NULL, "Whether to use an external editor or not." },
+{   "use-color",                OptionValue::eTypeBoolean, true, true , NULL, NULL, "Whether to use Ansi color codes or not." },
 
     {   NULL,                       OptionValue::eTypeInvalid, true, 0    , NULL, NULL, NULL }
 };
@@ -148,7 +149,8 @@ enum
     ePropertyStopLineCountBefore,
     ePropertyTerminalWidth,
     ePropertyThreadFormat,
-    ePropertyUseExternalEditor
+    ePropertyUseExternalEditor,
+    ePropertyUseColor,
 };
 
 //
@@ -186,9 +188,17 @@ Debugger::SetPropertyValue (const Execut
         if (strcmp(property_path, g_properties[ePropertyPrompt].name) == 0)
         {
             const char *new_prompt = GetPrompt();
+            std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
+            if (str.length())
+                new_prompt = str.c_str();
             EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt)));
             GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp);
         }
+        else if (strcmp(property_path, g_properties[ePropertyUseColor].name) == 0)
+        {
+			// use-color changed. Ping the prompt so it can reset the ansi terminal codes.
+            SetPrompt (GetPrompt());
+        }
         else if (is_load_script && target_sp && load_script_old_value == eLoadScriptFromSymFileWarn)
         {
             if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() == eLoadScriptFromSymFileTrue)
@@ -244,6 +254,9 @@ Debugger::SetPrompt(const char *p)
     const uint32_t idx = ePropertyPrompt;
     m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
     const char *new_prompt = GetPrompt();
+    std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
+    if (str.length())
+        new_prompt = str.c_str();
     EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt)));;
     GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp);
 }
@@ -297,6 +310,22 @@ Debugger::SetUseExternalEditor (bool b)
     return m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
 }
 
+bool
+Debugger::GetUseColor () const
+{
+    const uint32_t idx = ePropertyUseColor;
+    return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
+}
+
+bool
+Debugger::SetUseColor (bool b)
+{
+    const uint32_t idx = ePropertyUseColor;
+    bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
+    SetPrompt (GetPrompt());
+    return ret;
+}
+
 uint32_t
 Debugger::GetStopSourceLineCount (bool before) const
 {
@@ -629,6 +658,11 @@ Debugger::Debugger (lldb::LogOutputCallb
     OptionValueSInt64 *term_width = m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64 (NULL, ePropertyTerminalWidth);
     term_width->SetMinimumValue(10);
     term_width->SetMaximumValue(1024);
+
+    // Turn off use-color if this is a dumb terminal.
+    const char *term = getenv ("TERM");
+    if (term && !strcmp (term, "dumb"))
+        SetUseColor (false);
 }
 
 Debugger::~Debugger ()
@@ -1140,13 +1174,12 @@ TestPromptFormats (StackFrame *frame)
     ExecutionContext exe_ctx;
     frame->CalculateExecutionContext(exe_ctx);
     const char *end = NULL;
-    if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
+    if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s))
     {
         printf("%s\n", s.GetData());
     }
     else
     {
-        printf ("error: at '%s'\n", end);
         printf ("what we got: %s\n", s.GetData());
     }
 }
@@ -1323,8 +1356,8 @@ ExpandIndexedExpression (ValueObject* va
     return item;
 }
 
-bool
-Debugger::FormatPrompt 
+static bool
+FormatPromptRecurse
 (
     const char *format,
     const SymbolContext *sc,
@@ -1339,6 +1372,7 @@ Debugger::FormatPrompt
     bool success = true;
     const char *p;
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
+
     for (p = format; *p != '\0'; ++p)
     {
         if (realvalobj)
@@ -1372,8 +1406,8 @@ Debugger::FormatPrompt
             StreamString sub_strm;
 
             ++p;  // Skip the '{'
-            
-            if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p, valobj))
+
+            if (FormatPromptRecurse (p, sc, exe_ctx, addr, sub_strm, &p, valobj))
             {
                 // The stream had all it needed
                 s.Write(sub_strm.GetData(), sub_strm.GetSize());
@@ -1711,7 +1745,7 @@ Debugger::FormatPrompt
                                         if (!special_directions)
                                             var_success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
                                         else
-                                            var_success &= FormatPrompt(special_directions, sc, exe_ctx, addr, s, NULL, item);
+                                            var_success &= FormatPromptRecurse(special_directions, sc, exe_ctx, addr, s, NULL, item);
                                         
                                         if (--max_num_children == 0)
                                         {
@@ -1735,214 +1769,6 @@ Debugger::FormatPrompt
                                     format_addr = *addr;
                                 }
                             }
-                            else if (::strncmp (var_name_begin, "ansi.", strlen("ansi.")) == 0)
-                            {
-                                var_success = true;
-                                var_name_begin += strlen("ansi."); // Skip the "ansi."
-                                if (::strncmp (var_name_begin, "fg.", strlen("fg.")) == 0)
-                                {
-                                    var_name_begin += strlen("fg."); // Skip the "fg."
-                                    if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_fg_black,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_fg_red,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_fg_green,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_fg_yellow,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_fg_blue,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_fg_purple,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_fg_cyan,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_fg_white,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else
-                                    {
-                                        var_success = false;
-                                    }
-                                }
-                                else if (::strncmp (var_name_begin, "bg.", strlen("bg.")) == 0)
-                                {
-                                    var_name_begin += strlen("bg."); // Skip the "bg."
-                                    if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_bg_black,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_bg_red,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_bg_green,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_bg_yellow,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_bg_blue,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_bg_purple,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_bg_cyan,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
-                                    {
-                                        s.Printf ("%s%s%s", 
-                                                  lldb_utility::ansi::k_escape_start, 
-                                                  lldb_utility::ansi::k_bg_white,
-                                                  lldb_utility::ansi::k_escape_end);
-                                    }
-                                    else
-                                    {
-                                        var_success = false;
-                                    }
-                                }
-                                else if (::strncmp (var_name_begin, "normal}", strlen ("normal}")) == 0)
-                                {
-                                    s.Printf ("%s%s%s", 
-                                              lldb_utility::ansi::k_escape_start, 
-                                              lldb_utility::ansi::k_ctrl_normal,
-                                              lldb_utility::ansi::k_escape_end);
-                                }
-                                else if (::strncmp (var_name_begin, "bold}", strlen("bold}")) == 0)
-                                {
-                                    s.Printf ("%s%s%s", 
-                                              lldb_utility::ansi::k_escape_start, 
-                                              lldb_utility::ansi::k_ctrl_bold,
-                                              lldb_utility::ansi::k_escape_end);
-                                }
-                                else if (::strncmp (var_name_begin, "faint}", strlen("faint}")) == 0)
-                                {
-                                    s.Printf ("%s%s%s", 
-                                              lldb_utility::ansi::k_escape_start, 
-                                              lldb_utility::ansi::k_ctrl_faint,
-                                              lldb_utility::ansi::k_escape_end);
-                                }
-                                else if (::strncmp (var_name_begin, "italic}", strlen("italic}")) == 0)
-                                {
-                                    s.Printf ("%s%s%s", 
-                                              lldb_utility::ansi::k_escape_start, 
-                                              lldb_utility::ansi::k_ctrl_italic,
-                                              lldb_utility::ansi::k_escape_end);
-                                }
-                                else if (::strncmp (var_name_begin, "underline}", strlen("underline}")) == 0)
-                                {
-                                    s.Printf ("%s%s%s", 
-                                              lldb_utility::ansi::k_escape_start, 
-                                              lldb_utility::ansi::k_ctrl_underline,
-                                              lldb_utility::ansi::k_escape_end);
-                                }
-                                else if (::strncmp (var_name_begin, "slow-blink}", strlen("slow-blink}")) == 0)
-                                {
-                                    s.Printf ("%s%s%s", 
-                                              lldb_utility::ansi::k_escape_start, 
-                                              lldb_utility::ansi::k_ctrl_slow_blink,
-                                              lldb_utility::ansi::k_escape_end);
-                                }
-                                else if (::strncmp (var_name_begin, "fast-blink}", strlen("fast-blink}")) == 0)
-                                {
-                                    s.Printf ("%s%s%s", 
-                                              lldb_utility::ansi::k_escape_start, 
-                                              lldb_utility::ansi::k_ctrl_fast_blink,
-                                              lldb_utility::ansi::k_escape_end);
-                                }
-                                else if (::strncmp (var_name_begin, "negative}", strlen("negative}")) == 0)
-                                {
-                                    s.Printf ("%s%s%s", 
-                                              lldb_utility::ansi::k_escape_start, 
-                                              lldb_utility::ansi::k_ctrl_negative,
-                                              lldb_utility::ansi::k_escape_end);
-                                }
-                                else if (::strncmp (var_name_begin, "conceal}", strlen("conceal}")) == 0)
-                                {
-                                    s.Printf ("%s%s%s", 
-                                              lldb_utility::ansi::k_escape_start, 
-                                              lldb_utility::ansi::k_ctrl_conceal,
-                                              lldb_utility::ansi::k_escape_end);
-
-                                }
-                                else if (::strncmp (var_name_begin, "crossed-out}", strlen("crossed-out}")) == 0)
-                                {
-                                    s.Printf ("%s%s%s", 
-                                              lldb_utility::ansi::k_escape_start, 
-                                              lldb_utility::ansi::k_ctrl_crossed_out,
-                                              lldb_utility::ansi::k_escape_end);
-                                }
-                                else
-                                {
-                                    var_success = false;
-                                }
-                            }
                             break;
 
                         case 'p':
@@ -2631,6 +2457,24 @@ Debugger::FormatPrompt
     return success;
 }
 
+bool
+Debugger::FormatPrompt
+(
+    const char *format,
+    const SymbolContext *sc,
+    const ExecutionContext *exe_ctx,
+    const Address *addr,
+    Stream &s,
+    ValueObject* valobj
+)
+{
+    bool use_color = exe_ctx ? exe_ctx->GetTargetRef().GetDebugger().GetUseColor() : true;
+    std::string format_str = lldb_utility::ansi::FormatAnsiTerminalCodes (format, use_color);
+    if (format_str.length())
+        format = format_str.c_str();
+    return FormatPromptRecurse (format, sc, exe_ctx, addr, s, NULL, valobj);
+}
+
 void
 Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
 {

Modified: lldb/trunk/source/DataFormatters/LibCxx.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/LibCxx.cpp?rev=182609&r1=182608&r2=182609&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/LibCxx.cpp (original)
+++ lldb/trunk/source/DataFormatters/LibCxx.cpp Thu May 23 15:47:45 2013
@@ -516,5 +516,5 @@ lldb_private::formatters::LibcxxContaine
             return false;
         stream.Printf("0x%016llx ", value);
     }
-    return Debugger::FormatPrompt("size=${svar%#}", NULL, NULL, NULL, stream, NULL, &valobj);
+    return Debugger::FormatPrompt("size=${svar%#}", NULL, NULL, NULL, stream, &valobj);
 }

Modified: lldb/trunk/source/DataFormatters/TypeSummary.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/TypeSummary.cpp?rev=182609&r1=182608&r2=182609&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/TypeSummary.cpp (original)
+++ lldb/trunk/source/DataFormatters/TypeSummary.cpp Thu May 23 15:47:45 2013
@@ -113,7 +113,7 @@ StringSummaryFormat::FormatObject (Value
     }
     else
     {
-        if (Debugger::FormatPrompt(m_format.c_str(), &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, NULL, valobj))
+        if (Debugger::FormatPrompt(m_format.c_str(), &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, valobj))
         {
             retval.assign(s.GetString());
             return true;

Modified: lldb/trunk/source/Target/StackFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StackFrame.cpp?rev=182609&r1=182608&r2=182609&view=diff
==============================================================================
--- lldb/trunk/source/Target/StackFrame.cpp (original)
+++ lldb/trunk/source/Target/StackFrame.cpp Thu May 23 15:47:45 2013
@@ -1282,13 +1282,12 @@ StackFrame::DumpUsingSettingsFormat (Str
 
     GetSymbolContext(eSymbolContextEverything);
     ExecutionContext exe_ctx (shared_from_this());
-    const char *end = NULL;
     StreamString s;
     const char *frame_format = NULL;
     Target *target = exe_ctx.GetTargetPtr();
     if (target)
         frame_format = target->GetDebugger().GetFrameFormat();
-    if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end))
+    if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s))
     {
         strm->Write(s.GetData(), s.GetSize());
     }

Modified: lldb/trunk/source/Target/Thread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=182609&r1=182608&r2=182609&view=diff
==============================================================================
--- lldb/trunk/source/Target/Thread.cpp (original)
+++ lldb/trunk/source/Target/Thread.cpp Thu May 23 15:47:45 2013
@@ -1747,13 +1747,11 @@ Thread::DumpUsingSettingsFormat (Stream
 
     const char *thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat();
     assert (thread_format);
-    const char *end = NULL;
     Debugger::FormatPrompt (thread_format, 
                             frame_sp ? &frame_sc : NULL,
                             &exe_ctx, 
                             NULL,
-                            strm, 
-                            &end);
+                            strm);
 }
 
 void

Modified: lldb/trunk/tools/driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=182609&r1=182608&r2=182609&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Driver.cpp (original)
+++ lldb/trunk/tools/driver/Driver.cpp Thu May 23 15:47:45 2013
@@ -105,7 +105,9 @@ static OptionDefinition g_options[] =
         "Tells the debugger to open source files using the host's \"external editor\" mechanism." },
     { LLDB_3_TO_5,       false, "no-lldbinit"    , 'x', no_argument      , 0,  eArgTypeNone,
         "Do not automatically parse any '.lldbinit' files." },
-    { LLDB_OPT_SET_6,    true , "python-path"        , 'P', no_argument      , 0,  eArgTypeNone,
+    { LLDB_3_TO_5,       false, "no-use-colors"  , 'o', no_argument      , 0,  eArgTypeNone,
+        "Do not use colors." },
+    { LLDB_OPT_SET_6,    true , "python-path"    , 'P', no_argument      , 0,  eArgTypeNone,
         "Prints out the path to the lldb.py file for this version of lldb." },
     { 0,                 false, NULL             , 0  , 0                , 0,  eArgTypeNone,         NULL }
 };
@@ -621,6 +623,10 @@ Driver::ParseArgs (int argc, const char
                         m_debugger.SkipAppInitFiles (true);
                         break;
 
+                    case 'o':
+                        m_debugger.SetUseColor (false);
+                        break;
+
                     case 'f':
                         {
                             SBFileSpec file(optarg);





More information about the lldb-commits mailing list