[Lldb-commits] PATCH for REVIEW: parse ansi color codes for prompt, add use color settings

Malea, Daniel daniel.malea at intel.com
Thu May 23 12:34:15 PDT 2013


Hi Mike, this looks promising! I'm having some difficulty applying this patch on the latest trunk though; seeing a conflict in AnsiTerminal.h.

As an aside, lldb folk don't seem to use this much, but if you have a git workflow, I found LLVM reviews to be pretty painless through the "phabricator" instance that's been set up. If you haven't seen it, check out:

http://llvm-reviews.chandlerc.com

It's rather slick. Sending a patch for review and applying it is pretty seamless.



From: Michael Sartain <mikesart at valvesoftware.com<mailto:mikesart at valvesoftware.com>>
Date: Wednesday, 22 May, 2013 7:10 PM
To: "lldb-commits at cs.uiuc.edu<mailto:lldb-commits at cs.uiuc.edu>" <lldb-commits at cs.uiuc.edu<mailto:lldb-commits at cs.uiuc.edu>>
Subject: Re: [Lldb-commits] PATCH for REVIEW: parse ansi color codes for prompt, add use color settings

Just found a nasty bug with this patch where it was returning the address of the format string - which means we can't alloc new formats in there. The below should fix this.

This patch allows you to do the following:

settings set prompt "${ansi.bold}${ansi.fg.green}(lldb)${ansi.normal} "
settings set use-color false

It also adds a command line option (--no-use-colors).
 -Mike

Index: include/lldb/Core/Debugger.h
===================================================================
--- include/lldb/Core/Debugger.h(revision 182486)
+++ include/lldb/Core/Debugger.h(working copy)
@@ -236,7 +236,6 @@
                   const ExecutionContext *exe_ctx,
                   const Address *addr,
                   Stream &s,
-                  const char **end,
                   ValueObject* valobj = NULL);


@@ -308,6 +307,12 @@
     bool
     SetUseExternalEditor (bool use_external_editor_p);

+    bool
+    GetUseColor () const;
+
+    bool
+    SetUseColor (bool use_color);
+
     uint32_t
     GetStopSourceLineCount (bool before) const;

Index: include/lldb/Utility/AnsiTerminal.h
===================================================================
--- include/lldb/Utility/AnsiTerminal.h(revision 182486)
+++ include/lldb/Utility/AnsiTerminal.h(working copy)
@@ -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 @@
         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;
+        }
     }
 }
Index: source/Core/Debugger.cpp
===================================================================
--- source/Core/Debugger.cpp(revision 182486)
+++ source/Core/Debugger.cpp(working copy)
@@ -131,6 +131,7 @@
 {   "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 @@
     ePropertyStopLineCountBefore,
     ePropertyTerminalWidth,
     ePropertyThreadFormat,
-    ePropertyUseExternalEditor
+    ePropertyUseExternalEditor,
+    ePropertyUseColor,
 };

 //
@@ -186,9 +188,17 @@
         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 @@
     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 @@
     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 @@
     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 @@
     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 @@
     return item;
 }

-bool
-Debugger::FormatPrompt
+static bool
+FormatPromptRecurse
 (
     const char *format,
     const SymbolContext *sc,
@@ -1373,8 +1406,8 @@
             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());
@@ -1712,7 +1745,7 @@
                                         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)
                                         {
@@ -1736,214 +1769,6 @@
                                     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':
@@ -2632,6 +2457,24 @@
     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)
 {
Index: tools/driver/Driver.cpp
===================================================================
--- tools/driver/Driver.cpp(revision 182486)
+++ tools/driver/Driver.cpp(working copy)
@@ -105,7 +105,9 @@
         "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 @@
                         m_debugger.SkipAppInitFiles (true);
                         break;

+                    case 'o':
+                        m_debugger.SetUseColor (false);
+                        break;
+
                     case 'f':
                         {
                             SBFileSpec file(optarg);
Index: include/lldb/API/SBDebugger.h
===================================================================
--- include/lldb/API/SBDebugger.h(revision 182486)
+++ include/lldb/API/SBDebugger.h(working copy)
@@ -172,6 +172,12 @@
     bool
     GetUseExternalEditor ();

+    bool
+    SetUseColor (bool use_color);
+
+    bool
+    GetUseColor () const;
+
     static bool
     GetDefaultArchitecture (char *arch_name, size_t arch_name_len);

Index: source/API/SBDebugger.cpp
===================================================================
--- source/API/SBDebugger.cpp(revision 182486)
+++ source/API/SBDebugger.cpp(working copy)
@@ -1057,6 +1057,22 @@
 }

 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();
Index: source/DataFormatters/LibCxx.cpp
===================================================================
--- source/DataFormatters/LibCxx.cpp(revision 182486)
+++ source/DataFormatters/LibCxx.cpp(working copy)
@@ -516,5 +516,5 @@
             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);
 }
Index: source/DataFormatters/TypeSummary.cpp
===================================================================
--- source/DataFormatters/TypeSummary.cpp(revision 182486)
+++ source/DataFormatters/TypeSummary.cpp(working copy)
@@ -113,7 +113,7 @@
     }
     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;
Index: source/Target/StackFrame.cpp
===================================================================
--- source/Target/StackFrame.cpp(revision 182486)
+++ source/Target/StackFrame.cpp(working copy)
@@ -1282,13 +1282,12 @@

     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());
     }
Index: source/Target/Thread.cpp
===================================================================
--- source/Target/Thread.cpp(revision 182486)
+++ source/Target/Thread.cpp(working copy)
@@ -1747,13 +1747,11 @@

     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





More information about the lldb-commits mailing list