[Lldb-commits] [lldb] [lldb] colorize symbols in image lookup with a regex pattern (PR #69422)

José Lira Junior via lldb-commits lldb-commits at lists.llvm.org
Tue Dec 5 13:07:16 PST 2023


================
@@ -70,6 +72,31 @@ size_t Stream::PutCString(llvm::StringRef str) {
   return bytes_written;
 }
 
+void Stream::PutCStringColorHighlighted(llvm::StringRef text,
+                                        const char *pattern) {
+  if (!pattern) {
+    PutCString(text);
+    return;
+  }
+
+  // If pattern is not nullptr, we should use color
+  llvm::Regex reg_pattern(pattern);
+  llvm::SmallVector<llvm::StringRef, 1> matches;
+  llvm::StringRef remaining = text;
+  std::string format_str = lldb_private::ansi::FormatAnsiTerminalCodes(
+      "${ansi.fg.red}%.*s${ansi.normal}");
----------------
junior-jl wrote:

What are your thoughts on this approach? (In `SymbolContext.cpp` - line 98). I tested it and it only fails on the new test this PR creates, so we would only need to adapt it.

```cpp
if (name) {
        llvm::StringRef ansi_prefix;
        llvm::StringRef ansi_suffix;
        if (target_sp) {
          ansi_prefix = target_sp->GetDebugger().GetRegexMatchAnsiPrefix();
          ansi_suffix = target_sp->GetDebugger().GetRegexMatchAnsiSuffix();
        }
        s->PutCStringColorHighlighted(name.GetStringRef(), pattern, ansi_prefix,
                                      ansi_suffix);
      }
```

Or even forcing the red color when there is no target? Honestly, I do not completely understand what would mean not having a target.

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


More information about the lldb-commits mailing list