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

José Lira Junior via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 13 10:24:40 PST 2023


================
@@ -253,9 +264,20 @@ void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
                 m_addr_range.GetBaseAddress().GetOffset());
   }
   ConstString demangled = GetMangled().GetDemangledName();
-  if (demangled)
+
+  // Checking if the name (i.e., searched symbol is passed as an argument to the function)
+  // In that case, we use the re_pattern function to colorize the symbol.
+  if (demangled && name){
+    s->Printf(", name=");
+    Address::re_pattern(s, demangled.AsCString(), name);
+  }
+  else if(demangled && name == nullptr)
     s->Printf(", name=\"%s\"", demangled.AsCString());
-  if (m_mangled.GetMangledName())
+  if (m_mangled.GetMangledName() && name){
+    s->Printf(", mangled=");
+    Address::re_pattern(s, m_mangled.GetMangledName().AsCString(), name);
+  }
+  else if(m_mangled.GetMangledName() && name == nullptr)
----------------
junior-jl wrote:

I realize now I might have misinterpreted this suggestion. The mangled name is now shown before the demangled one. Is that what you were meaning here? This is how the code is now.

```cpp
if (ConstString mangled_name = m_mangled.GetMangledName()) {
    s->Printf(", mangled=\"");
    Address::DumpName(s, mangled_name.GetStringRef(), pattern);
    s->Printf("\"");
  }
  if (ConstString demangled = m_mangled.GetDemangledName()) {
    s->Printf(", name=\"");
    Address::DumpName(s, demangled.GetStringRef(), pattern);
    s->Printf("\"");
  }
```

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


More information about the lldb-commits mailing list