add stop column highlighting support

This change introduces optional marking of the column within a source
line where a thread is stopped.  This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.

There are two separate methods for handling the marking of the stop
column:

* via ANSI terminal codes, which are added inline to the source line
  display.  The default ANSI mark-up is to underline the column.

* via a pure text-based caret that is added in the appropriate column
  in a newly-inserted blank line underneath the source line in
  question.

There are some new options that control how this all works.

* settings set stop-show-column

  This takes one of 4 values:

  * ansi-or-caret: use the ANSI terminal code mechanism if LLDB
    is running with color enabled; if not, use the caret-based,
    pure text method (see the "caret" mode below).

  * ansi: only use the ANSI terminal code mechanism to highlight
    the stop line.  If LLDB is running with color disabled, no
    stop column marking will occur.

  * caret: only use the pure text caret method, which introduces
    a newly-inserted line underneath the current line, where
    the only character in the new line is a caret that highlights
    the stop column in question.

  * none: no stop column marking will be attempted.

* settings set stop-show-column-ansi-prefix

  This is a text format that indicates the ANSI formatting
  code to insert into the stream immediately preceding the
  column where the stop column character will be marked up.
  It defaults to ${ansi.underline}; however, it can contain
  any valid LLDB format codes, e.g.

      ${ansi.fg.red}${ansi.bold}${ansi.underline}

* settings set stop-show-column-ansi-suffix

  This is the text format that specifies the ANSI terminal
  codes to end the markup that was started with the prefix
  described above.  It defaults to: ${ansi.normal}.  This
  should be sufficient for the common cases.

Significant leg-work was done by Adrian Prantl.  (Thanks, Adrian!)

differential review: https://reviews.llvm.org/D20835

reviewers: clayborg, jingham
llvm-svn: 282105
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 835f803..7a72747 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -140,6 +140,24 @@
 // {${function.initial-function}{${module.file.basename}`}{${function.name-without-args}}:\n}{${function.changed}\n{${module.file.basename}`}{${function.name-without-args}}:\n}{${current-pc-arrow}
 // }{${addr-file-or-load}}:
 
+#define DEFAULT_STOP_SHOW_COLUMN_ANSI_PREFIX "${ansi.underline}"
+#define DEFAULT_STOP_SHOW_COLUMN_ANSI_SUFFIX "${ansi.normal}"
+
+static OptionEnumValueElement s_stop_show_column_values[] = {
+    {eStopShowColumnAnsiOrCaret, "ansi-or-caret",
+     "Highlight the stop column with ANSI terminal codes when color/ANSI mode "
+     "is enabled; otherwise, fall back to using a text-only caret (^) as if "
+     "\"caret-only\" mode was selected."},
+    {eStopShowColumnAnsi, "ansi", "Highlight the stop column with ANSI "
+                                  "terminal codes when running LLDB with "
+                                  "color/ANSI enabled."},
+    {eStopShowColumnCaret, "caret",
+     "Highlight the stop column with a caret character (^) underneath the stop "
+     "column. This method introduces a new line in source listings that "
+     "display thread stop locations."},
+    {eStopShowColumnNone, "none", "Do not highlight the stop column."},
+    {0, nullptr, nullptr}};
+
 static PropertyDefinition g_properties[] = {
     {"auto-confirm", OptionValue::eTypeBoolean, true, false, nullptr, nullptr,
      "If true all confirmation prompts will receive their default reply."},
@@ -173,6 +191,20 @@
     {"stop-line-count-before", OptionValue::eTypeSInt64, true, 3, nullptr,
      nullptr, "The number of sources lines to display that come before the "
               "current source line when displaying a stopped context."},
+    {"stop-show-column", OptionValue::eTypeEnum, false,
+     eStopShowColumnAnsiOrCaret, nullptr, s_stop_show_column_values,
+     "If true, LLDB will use the column information from the debug info to "
+     "mark the current position when displaying a stopped context."},
+    {"stop-show-column-ansi-prefix", OptionValue::eTypeFormatEntity, true, 0,
+     DEFAULT_STOP_SHOW_COLUMN_ANSI_PREFIX, nullptr,
+     "When displaying the column marker in a color-enabled (i.e. ANSI) "
+     "terminal, use the ANSI terminal code specified in this format at the "
+     "immediately before the column to be marked."},
+    {"stop-show-column-ansi-suffix", OptionValue::eTypeFormatEntity, true, 0,
+     DEFAULT_STOP_SHOW_COLUMN_ANSI_SUFFIX, nullptr,
+     "When displaying the column marker in a color-enabled (i.e. ANSI) "
+     "terminal, use the ANSI terminal code specified in this format "
+     "immediately after the column to be marked."},
     {"term-width", OptionValue::eTypeSInt64, true, 80, nullptr, nullptr,
      "The maximum number of columns to use for displaying text."},
     {"thread-format", OptionValue::eTypeFormatEntity, true, 0,
@@ -210,6 +242,9 @@
   ePropertyStopDisassemblyDisplay,
   ePropertyStopLineCountAfter,
   ePropertyStopLineCountBefore,
+  ePropertyStopShowColumn,
+  ePropertyStopShowColumnAnsiPrefix,
+  ePropertyStopShowColumnAnsiSuffix,
   ePropertyTerminalWidth,
   ePropertyThreadFormat,
   ePropertyUseExternalEditor,
@@ -371,6 +406,22 @@
   return ret;
 }
 
+StopShowColumn Debugger::GetStopShowColumn() const {
+  const uint32_t idx = ePropertyStopShowColumn;
+  return (lldb::StopShowColumn)m_collection_sp->GetPropertyAtIndexAsEnumeration(
+      nullptr, idx, g_properties[idx].default_uint_value);
+}
+
+const FormatEntity::Entry *Debugger::GetStopShowColumnAnsiPrefix() const {
+  const uint32_t idx = ePropertyStopShowColumnAnsiPrefix;
+  return m_collection_sp->GetPropertyAtIndexAsFormatEntity(nullptr, idx);
+}
+
+const FormatEntity::Entry *Debugger::GetStopShowColumnAnsiSuffix() const {
+  const uint32_t idx = ePropertyStopShowColumnAnsiSuffix;
+  return m_collection_sp->GetPropertyAtIndexAsFormatEntity(nullptr, idx);
+}
+
 uint32_t Debugger::GetStopSourceLineCount(bool before) const {
   const uint32_t idx =
       before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter;