[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 2 08:43:12 PDT 2023


================
@@ -1506,13 +1514,50 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
 
     ExecutionContextScope *exe_scope =
         interpreter.GetExecutionContext().GetBestExecutionContextScope();
-    DumpAddress(exe_scope, so_addr, verbose, all_ranges, strm);
+    DumpAddress(exe_scope, so_addr, verbose, all_ranges, strm, nullptr);
     return true;
   }
 
   return false;
 }
 
+//===========================================================================================
+
+// This function is the one which colorizes the regex symbol searched
+static void PrintRed(Stream &strm, const char *text, const char *name, CommandInterpreter *interpreter= nullptr) {
+    if (!name) {
+        strm.PutCString(text);
+        return;
+    }
+
+    bool use_color = interpreter->GetDebugger().GetUseColor();
----------------
DavidSpickett wrote:

1. If we only need this one part of the CommandInterpreter, we should only be passing that one thing down.
    Try to find the earliest place you can to do the GetUseColor call, then pass the result down to here.

2. You can combine that approach with one observation, that if `name` is nullptr, this will never use colour regardless of the setting. Therefore instead of having another parameter you could just set name to nullptr if colours are disabled.

As in:
* No regex search - name is nullptr, colour setting is unused
* Regex search - name is not nullptr, colour setting must be read

So if early in the callstack you know that GetUseColor returns false, you could just pass name=nullptr. No extra parameters needed. So it becomes something like:
```
interpreter->GetDebugger().GetUseColor() ? name : nullptr;
```

https://github.com/llvm/llvm-project/pull/69422


More information about the lldb-commits mailing list