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

2023-12-12 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;

DavidSpickett wrote:

So in code that would be roughly:
```
struct information {
pattern, prefix, sufix
}

PutCStringHighlighted(., std::optional pattern_info);
```

Which tells the reader clearly that if they want to provide any one of the 3 
they must provide all 3. Otherwise they must provide none of them.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-12 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;

DavidSpickett wrote:

>When we use std::move(regex2) to pass it to test_func3, it's essentially 
>moved, and after the move, the regex2 in LookupSymbolInModule becomes garbage.

This is where I get on my Rust powered soapbox and preach about C++ move not 
being what you'd think it is. :)

Good research anyway. Sound like it's what I suspected is that the regex is 
carrying around the match "engine"'s state.

On the struct, yes, the struct itself would be optional. If you do pass an 
instance of it you must provide all 3.

To be honest, once we're packing all this into a struct, that's quite an 
obvious signal to the programmer that this is no ordinary string. So you could 
do just try the struct idea without using the `Regex` type.

And ok, it's not perfect because all 3 struct members have the same type still, 
but if making the pattern a `Regex` is this much trouble it's probably not 
worth it.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-12 Thread via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;

taalhaataahir0102 wrote:

Hi @DavidSpickett! Sorry for the delay 

`test_func3(strm, std::move(regex2))` works but it gives the following problem. 
When we use `std::move(regex2)` to pass it to `test_func3`, it's essentially 
moved, and after the move, the `regex2` in `LookupSymbolInModule` becomes 
garbage.

So in functions where pattern is moved multiple times like this:

```
static void DumpAddress(ExecutionContextScope *exe_scope,
const Address _addr, bool verbose, bool all_ranges,
Stream , std::optional pattern = 
std::nullopt) {
 ...
 ...
 so_addr.Dump(, exe_scope, Address::DumpStyleResolvedDescription,
   Address::DumpStyleInvalid, UINT32_MAX, false, 
std::move(pattern));
 ...
 ...
 if (verbose) {
strm.EOL();
so_addr.Dump(, exe_scope, Address::DumpStyleDetailedSymbolContext,
 Address::DumpStyleInvalid, UINT32_MAX, all_ranges, 
std::move(pattern));
  }
 ...
}
```
The second `std::move(pattern)`, does not move the original pattern value but 
some garbage value. The only way is to make a copy of the original pattern and 
then use it with `std::move(copy_pattern)` every time (which doesn't look okay 
:-/).

This is the example code and output if I couldn't explain it properly above:
CODE:
```
static void test_func3(Stream , const std::optional pattern = 
std::nullopt) {
  if (pattern.has_value() && pattern.value().match("main")) {
strm.Printf("Pattern matches 'main' inside test_func3\n");
}
}

static uint32_t LookupSymbolInModule(CommandInterpreter ,
 Stream , Module *module,
 const char *name, bool name_is_regex,
 bool verbose, bool all_ranges) {
  // test_func1(strm, std::make_optional(name));
  std::optional regex2 = std::make_optional(name);
  if (regex2.has_value()) {
strm.Printf("Pattern has a value\n");
if(regex2.value().match("main")) {
  strm.Printf("Pattern matches main\n");
}
else{
  strm.Printf("Pattern doesn't match main\n");
}
  } else {
strm.Printf("Pattern doesn't have a value\n");
  }
  test_func3(strm, std::move(regex2));
  if (regex2.has_value()) {
strm.Printf("Pattern has a value\n");
if(regex2.value().match("main")) {
  strm.Printf("Pattern matches main\n");
}
else{
  strm.Printf("Pattern doesn't match main\n");
}
  } else {
strm.Printf("Pattern doesn't have a value\n");
  }  ...
  ...
}
```
OUTPUT:
```
talha@talha-ROG-Strix-G513QE-G513QE:~/Desktop/LLDB/build/bin$ ./lldb a.out 
(lldb) target create "a.out"
Current executable set to '/home/talha/Desktop/LLDB/build/bin/a.out' (x86_64).
(lldb) image lookup -r -s main
Pattern has a value
Pattern matches main
Pattern matches 'main' inside test_func3
Pattern has a value
Pattern doesn't match main
...
...
```
So after `std::move(pattern)`, `pattern != "main"` within the same function 

Similarly passing `std::make_optional(name)` to func3 also causes 
problem problem:
i.e., `test_func3(strm, std::make_optional(name));`

When we directly pass `std::make_optional(name)`, it creates a 
temporary `std::optional` object that is passed directly to 
`test_func3`. This temporary object can be moved without requiring an explicit 
`std::move` because I guess temporaries are considered rvalues, and 
`std::optional` has appropriate move constructors to handle them.
But storing the result of `std::make_optional(name)` in a variable 
and then passing it without using `std::move`, if the variable is passed as an 
argument to the function, it attempts to perform a copy unless we use 
`std::move`. So, initially we can pass it directly to the next dumping function 
but further passing it will require `std::move` and the same problem comes 
back. 

Also 1 last thing for clarification, as discussed later i.e., 

> I think we may be able to reduce the boilerplate by putting the 
> prefix/suffix/pattern in a struct, and passing that as an optional assuming 
> we can figure out the move issue with regex. But this is for a future change 
> if at all.

The struct will be optional and not the 

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

2023-12-12 Thread via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


https://github.com/taalhaataahir0102 edited 
https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-08 Thread via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


taalhaataahir0102 wrote:

Sure will try to make it work for windows. Hoping it will be as easier to build 
lldb on windows as it's for linux 

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-08 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


DavidSpickett wrote:

Spoke too soon, had to disable the test on Windows: 
https://github.com/llvm/llvm-project/commit/810d09faf89af53025205c540ef9980e2286e687

Making it work there may require making function lookup work, not sure.

And Mac OS: 
https://github.com/llvm/llvm-project/commit/61f18255fab3c404dc43a59091a750c22e5d0ccb

Which I think is a matter of finding the right regex for the CHECK. If either 
of you have access to Windows/Mac, please give it a go.

Otherwise, @JDevlieghere could you (/one of your colleagues) try the test on 
Mac and see what can be done?

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-08 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


DavidSpickett wrote:

Ok bots look good, so congratulations on landing this change! :partying_face: 

(you will have some email from build bots, it's a good idea to go look at the 
failures just to see what they look like, but I have fixed them)

Sounds like you already have ideas for follow ups. You should also add a 
release note 
(https://github.com/llvm/llvm-project/blob/main/llvm/docs/ReleaseNotes.rst#changes-to-lldb)
 at some point when you're happy with the feature overall. Or in other words, 
when it can be described in 1 or 2 sentences without a lot of caveats.

I'm trying the feature myself and noticing the thing you said about the symbol 
context. Even when looking up symbols on a running process, when we print a 
`Summary: ` line, `target_sp` is always nullptr. Surprising, and a bit annoying 
as a majority of the symbols in my searches didn't have a `Name: ` line.

(though one can work around this by adding `-v`)

Could be that there's never been a need for target here, and as you said, what 
you really want is the debugger settings. So perhaps the better route is to add 
a link back to those.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-08 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


DavidSpickett wrote:

https://github.com/llvm/llvm-project/commit/ffd61c1e96e9c8a472f305585930b45be0d639d3

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-08 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


DavidSpickett wrote:

This is failing tests but I'm pretty sure it's a missing nullptr check. I'll 
fix it.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-08 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


https://github.com/DavidSpickett closed 
https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-08 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -1618,12 +1621,19 @@ static uint32_t LookupSymbolInModule(CommandInterpreter 
,
 if (symbol->ValueIsAddress()) {
   DumpAddress(
   interpreter.GetExecutionContext().GetBestExecutionContextScope(),
-  symbol->GetAddressRef(), verbose, all_ranges, strm);
+  symbol->GetAddressRef(), verbose, all_ranges, strm,
+  use_color && name_is_regex ? name : nullptr);
   strm.EOL();
 } else {
   strm.IndentMore();
   strm.Indent("Name: ");
-  strm.PutCString(symbol->GetDisplayName().GetStringRef());
+  llvm::StringRef ansi_prefix =
+  interpreter.GetDebugger().GetRegexMatchAnsiPrefix();
+  llvm::StringRef ansi_suffix =
+  interpreter.GetDebugger().GetRegexMatchAnsiSuffix();

DavidSpickett wrote:

I think you might be mistaking putting the calls inside 
`PutCStringColorHighlighted` vs. putting the calls inside *the call* to 
`PutCStringColorHighlighted`.

I'm suggesting:
```
PutCStringColorHighlighted(<...>, 
interpreter.GetDebugger().GetRegexMatchAnsiPrefix(), 
interpreter.GetDebugger().GetRegexMatchAnsiSuffix())
```

(should have included that example in my first comment tbh :) )

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-07 Thread Jonas Devlieghere via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -1618,12 +1621,19 @@ static uint32_t LookupSymbolInModule(CommandInterpreter 
,
 if (symbol->ValueIsAddress()) {
   DumpAddress(
   interpreter.GetExecutionContext().GetBestExecutionContextScope(),
-  symbol->GetAddressRef(), verbose, all_ranges, strm);
+  symbol->GetAddressRef(), verbose, all_ranges, strm,
+  use_color && name_is_regex ? name : nullptr);
   strm.EOL();
 } else {
   strm.IndentMore();
   strm.Indent("Name: ");
-  strm.PutCString(symbol->GetDisplayName().GetStringRef());
+  llvm::StringRef ansi_prefix =
+  interpreter.GetDebugger().GetRegexMatchAnsiPrefix();
+  llvm::StringRef ansi_suffix =
+  interpreter.GetDebugger().GetRegexMatchAnsiSuffix();

JDevlieghere wrote:

I was about to suggest that too, but the `Stream` class lives in utility so you 
can't pass in the debugger or the target without breaking the layering. 

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-07 Thread José Lira Junior via lldb-commits

junior-jl wrote:

> > I tried this now and I guess it's not correct. For example, if I have a 
> > prefix (red color) and no suffix, the text does not go back to normal and 
> > will be forever red. Or am I doing something wrong?
> 
> This is expected. We don't expect many people to do this but if they do, 
> that's their mistake. A more realistic use might be prefix=`` and 
> suffix=`""`. If you wanted to "highlight" matches in a way that wasn't 
> colour, niche, but it's possible with the existing highlighters so might as 
> well go with it.

I see now. Thank you for the explanation.

The last commit adds the test cases and change the `if` condition.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-07 Thread José Lira Junior via lldb-commits

https://github.com/junior-jl updated 
https://github.com/llvm/llvm-project/pull/69422

From c416443a93f7113a7f57d337682ec4862438522d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20L=2E=20Junior?= 
Date: Tue, 7 Nov 2023 16:57:18 -0300
Subject: [PATCH 01/10] [lldb] colorize symbols in image lookup

This creates the method PutCStringColorHighlighted for Stream class,
which highlights searched symbols in red color for the image lookup command.

A new shell test was added to verify functionality. Relevant methods were
updated to accept the searched pattern/symbol as a parameter.

Co-authored-by: Talha 
---
 lldb/include/lldb/Core/Address.h  |  4 +-
 lldb/include/lldb/Symbol/Symbol.h |  4 +-
 lldb/include/lldb/Symbol/SymbolContext.h  |  8 ++--
 lldb/include/lldb/Utility/Stream.h| 16 
 lldb/source/Commands/CommandObjectTarget.cpp  | 16 +---
 lldb/source/Core/Address.cpp  | 21 ++
 lldb/source/Symbol/Symbol.cpp | 18 ++---
 lldb/source/Symbol/SymbolContext.cpp  | 16 +---
 lldb/source/Utility/Stream.cpp| 28 +
 .../Commands/command-image-lookup-color.test  | 39 +++
 10 files changed, 138 insertions(+), 32 deletions(-)
 create mode 100644 lldb/test/Shell/Commands/command-image-lookup-color.test

diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h
index b19e694427546..c3f2832be424e 100644
--- a/lldb/include/lldb/Core/Address.h
+++ b/lldb/include/lldb/Core/Address.h
@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;
 
   AddressClass GetAddressClass() const;
 
diff --git a/lldb/include/lldb/Symbol/Symbol.h 
b/lldb/include/lldb/Symbol/Symbol.h
index 44a2d560010fe..0e41cd95e0ef1 100644
--- a/lldb/include/lldb/Symbol/Symbol.h
+++ b/lldb/include/lldb/Symbol/Symbol.h
@@ -174,8 +174,8 @@ class Symbol : public SymbolContextScope {
 
   void SetFlags(uint32_t flags) { m_flags = flags; }
 
-  void GetDescription(Stream *s, lldb::DescriptionLevel level,
-  Target *target) const;
+  void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target,
+  const char *pattern = nullptr) const;
 
   bool IsSynthetic() const { return m_is_synthetic; }
 
diff --git a/lldb/include/lldb/Symbol/SymbolContext.h 
b/lldb/include/lldb/Symbol/SymbolContext.h
index b0f5ffead2a16..9567c3f4384c1 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -150,8 +150,8 @@ class SymbolContext {
   bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
const Address _addr, bool show_fullpaths,
bool show_module, bool show_inlined_frames,
-   bool show_function_arguments,
-   bool show_function_name) const;
+   bool show_function_arguments, bool show_function_name,
+   const char *pattern = nullptr) const;
 
   /// Get the address range contained within a symbol context.
   ///
@@ -217,8 +217,8 @@ class SymbolContext {
   /// The symbol that was found, or \b nullptr if none was found.
   const Symbol *FindBestGlobalDataSymbol(ConstString name, Status );
 
-  void GetDescription(Stream *s, lldb::DescriptionLevel level,
-  Target *target) const;
+  void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target,
+  const char *pattern = nullptr) const;
 
   uint32_t GetResolvedMask() const;
 
diff --git a/lldb/include/lldb/Utility/Stream.h 
b/lldb/include/lldb/Utility/Stream.h
index 1a5fd343e4df0..8e3fd48dfe705 100644
--- a/lldb/include/lldb/Utility/Stream.h
+++ b/lldb/include/lldb/Utility/Stream.h
@@ -231,6 +231,22 @@ class Stream {
   /// The string to be output to the stream.
   size_t PutCString(llvm::StringRef cstr);
 
+  /// Output a C string to the stream with color highlighting.
+  ///
+  /// Print a C string \a text to the stream, applying red color highlighting 
to
+  /// the portions of the string that match the regex pattern \a pattern. The
+  /// pattern is matched as many times as possible throughout the string. If \a
+  /// pattern is nullptr, then no highlighting is applied.
+  ///
+  /// \param[in] text
+  /// The string to be output to the stream.
+  ///
+  /// \param[in] pattern
+  /// The regex pattern to match against the \a text string. Portions of \a
+  /// text matching this pattern will be colorized. If this parameter is
+  /// nullptr, highlighting is not performed.
+  void 

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

2023-12-07 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


DavidSpickett wrote:

> I tried this now and I guess it's not correct. For example, if I have a 
> prefix (red color) and no suffix, the text does not go back to normal and 
> will be forever red. Or am I doing something wrong?

This is expected. We don't expect many people to do this but if they do, that's 
their mistake. A more realistic use might be prefix=`` and suffix=`""`. If 
you wanted to "highlight" matches in a way that wasn't colour, niche, but it's 
possible with the existing highlighters so might as well go with it.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-07 Thread José Lira Junior via lldb-commits

junior-jl wrote:

> I tried this now and I guess it's not correct. For example, if I have a 
> prefix (red color) and no suffix, the text does not go back to normal and 
> will be forever red. Or am I doing something wrong?

![image](https://github.com/llvm/llvm-project/assets/69206952/2ed63ec4-6f5d-4ae8-a7be-f95adba313f5)

The condition is: `if (pattern.empty() || (prefix.empty() && suffix.empty()))`

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-07 Thread José Lira Junior via lldb-commits

junior-jl wrote:

> If the prefix and suffix are empty. Not prefix or suffix is empty.

I tried this now and I guess it's not correct. For example, if I have a prefix 
(red color) and no suffix, the text does not go back to normal and will be 
forever red. Or am I doing something wrong?

> Or rather, set the suffix to "", prefix to "" and both to "" (since we 
> default to some red/normal sequence don't we).

Yes, I'm adding new tests like this now.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-07 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


DavidSpickett wrote:

Or rather, set the suffix to `""`, prefix to `""` and both to `""` (since we 
default to some red/normal sequence don't we).

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-07 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


DavidSpickett wrote:

Wait, one last thing :)

> If the prefix and suffix are empty, we can also take this shortcut, right?

If the prefix *and* suffix are empty. Not prefix or suffix is empty.

Also please add a couple of tests where you set only suffix, and only prefix. 
To validate that.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-07 Thread José Lira Junior via lldb-commits

junior-jl wrote:

> You could do:

  s->PutCStringColorHighlighted(symbol->GetName().GetStringRef(), pattern,
 target_sp ? target_sp->GetDebugger().GetRegexMatchAnsiPrefix() : 
"", 
 target_sp ? target_sp->GetDebugger().GetRegexMatchAnsiSuffix() : 
"");
 
 I really thought about doing this, but it looked too long, so I gave up, good 
to know it's ok.
 
 > Leave it as is. Sounds like you will end up refactoring it anyway.
 
 Nice! Thank you for all the help so far!

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-07 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


DavidSpickett wrote:

> Is it better if I declared llvm::StringRef ansi_prefix and llvm::StringRef 
> ansi_suffix outside the conditions even if they are not used?

As far as I can tell, that's how you must do it, or at least, one of the 
simpler ways.

You could do:
```
  s->PutCStringColorHighlighted(symbol->GetName().GetStringRef(), pattern,
 target_sp ? target_sp->GetDebugger().GetRegexMatchAnsiPrefix() : 
"", 
 target_sp ? target_sp->GetDebugger().GetRegexMatchAnsiSuffix() : 
"");
```

If you prefer. There's not much difference to it. One puts it all in a single 
call which is good because the scope of the values is limited. The other has 1 
conditional instead of two.

Leave it as is. Sounds like you will end up refactoring it anyway.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-07 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -1618,12 +1621,19 @@ static uint32_t LookupSymbolInModule(CommandInterpreter 
,
 if (symbol->ValueIsAddress()) {
   DumpAddress(
   interpreter.GetExecutionContext().GetBestExecutionContextScope(),
-  symbol->GetAddressRef(), verbose, all_ranges, strm);
+  symbol->GetAddressRef(), verbose, all_ranges, strm,
+  use_color && name_is_regex ? name : nullptr);
   strm.EOL();
 } else {
   strm.IndentMore();
   strm.Indent("Name: ");
-  strm.PutCString(symbol->GetDisplayName().GetStringRef());
+  llvm::StringRef ansi_prefix =
+  interpreter.GetDebugger().GetRegexMatchAnsiPrefix();
+  llvm::StringRef ansi_suffix =
+  interpreter.GetDebugger().GetRegexMatchAnsiSuffix();

DavidSpickett wrote:

If you are doing a follow up, I would put these calls inside the call to 
`PutCStringColorHighlighted`. To limit the scope of the values even more.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-07 Thread José Lira Junior via lldb-commits

junior-jl wrote:

In the last commit:

- Added the conditions `prefix.empty()` and `suffix.empty()` to the 'no color' 
path.
- Added missing arguments to `PutCStringColorHighlighted` call in 
`SymbolContext` (line 177).

I had to copy the same statements from line 99 here. Is it better if I declared 
`llvm::StringRef ansi_prefix` and `llvm::StringRef ansi_suffix` outside the 
conditions even if they are not used?

```cpp
  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(symbol->GetName().GetStringRef(), pattern,
ansi_prefix, ansi_suffix);
```

Also, since these changes were approved, we opted to finalize this PR like it 
is now. Since we are creating another PR to do the same thing for function 
search, we are planning on refactoring this with an optional struct and 
`llvm::Regex` type as suggested. This change would also make this `if 
(pattern.empty() || prefix.empty() || suffix.empty())` prettier, I guess. Is 
that good?

I would also like to understand better the relation between SymbolContext and 
the target (or another way of getting Debugger properties).

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-07 Thread José Lira Junior via lldb-commits

https://github.com/junior-jl updated 
https://github.com/llvm/llvm-project/pull/69422

From c416443a93f7113a7f57d337682ec4862438522d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20L=2E=20Junior?= 
Date: Tue, 7 Nov 2023 16:57:18 -0300
Subject: [PATCH 1/9] [lldb] colorize symbols in image lookup

This creates the method PutCStringColorHighlighted for Stream class,
which highlights searched symbols in red color for the image lookup command.

A new shell test was added to verify functionality. Relevant methods were
updated to accept the searched pattern/symbol as a parameter.

Co-authored-by: Talha 
---
 lldb/include/lldb/Core/Address.h  |  4 +-
 lldb/include/lldb/Symbol/Symbol.h |  4 +-
 lldb/include/lldb/Symbol/SymbolContext.h  |  8 ++--
 lldb/include/lldb/Utility/Stream.h| 16 
 lldb/source/Commands/CommandObjectTarget.cpp  | 16 +---
 lldb/source/Core/Address.cpp  | 21 ++
 lldb/source/Symbol/Symbol.cpp | 18 ++---
 lldb/source/Symbol/SymbolContext.cpp  | 16 +---
 lldb/source/Utility/Stream.cpp| 28 +
 .../Commands/command-image-lookup-color.test  | 39 +++
 10 files changed, 138 insertions(+), 32 deletions(-)
 create mode 100644 lldb/test/Shell/Commands/command-image-lookup-color.test

diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h
index b19e694427546..c3f2832be424e 100644
--- a/lldb/include/lldb/Core/Address.h
+++ b/lldb/include/lldb/Core/Address.h
@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;
 
   AddressClass GetAddressClass() const;
 
diff --git a/lldb/include/lldb/Symbol/Symbol.h 
b/lldb/include/lldb/Symbol/Symbol.h
index 44a2d560010fe..0e41cd95e0ef1 100644
--- a/lldb/include/lldb/Symbol/Symbol.h
+++ b/lldb/include/lldb/Symbol/Symbol.h
@@ -174,8 +174,8 @@ class Symbol : public SymbolContextScope {
 
   void SetFlags(uint32_t flags) { m_flags = flags; }
 
-  void GetDescription(Stream *s, lldb::DescriptionLevel level,
-  Target *target) const;
+  void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target,
+  const char *pattern = nullptr) const;
 
   bool IsSynthetic() const { return m_is_synthetic; }
 
diff --git a/lldb/include/lldb/Symbol/SymbolContext.h 
b/lldb/include/lldb/Symbol/SymbolContext.h
index b0f5ffead2a16..9567c3f4384c1 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -150,8 +150,8 @@ class SymbolContext {
   bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
const Address _addr, bool show_fullpaths,
bool show_module, bool show_inlined_frames,
-   bool show_function_arguments,
-   bool show_function_name) const;
+   bool show_function_arguments, bool show_function_name,
+   const char *pattern = nullptr) const;
 
   /// Get the address range contained within a symbol context.
   ///
@@ -217,8 +217,8 @@ class SymbolContext {
   /// The symbol that was found, or \b nullptr if none was found.
   const Symbol *FindBestGlobalDataSymbol(ConstString name, Status );
 
-  void GetDescription(Stream *s, lldb::DescriptionLevel level,
-  Target *target) const;
+  void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target,
+  const char *pattern = nullptr) const;
 
   uint32_t GetResolvedMask() const;
 
diff --git a/lldb/include/lldb/Utility/Stream.h 
b/lldb/include/lldb/Utility/Stream.h
index 1a5fd343e4df0..8e3fd48dfe705 100644
--- a/lldb/include/lldb/Utility/Stream.h
+++ b/lldb/include/lldb/Utility/Stream.h
@@ -231,6 +231,22 @@ class Stream {
   /// The string to be output to the stream.
   size_t PutCString(llvm::StringRef cstr);
 
+  /// Output a C string to the stream with color highlighting.
+  ///
+  /// Print a C string \a text to the stream, applying red color highlighting 
to
+  /// the portions of the string that match the regex pattern \a pattern. The
+  /// pattern is matched as many times as possible throughout the string. If \a
+  /// pattern is nullptr, then no highlighting is applied.
+  ///
+  /// \param[in] text
+  /// The string to be output to the stream.
+  ///
+  /// \param[in] pattern
+  /// The regex pattern to match against the \a text string. Portions of \a
+  /// text matching this pattern will be colorized. If this parameter is
+  /// nullptr, highlighting is not performed.
+  void 

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

2023-12-07 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


DavidSpickett wrote:

@JDevlieghere thanks for reviewing.

Once Jonas' last comment is addressed let me know if you're happy with the 
changes and PR message and I can merge this for you.

I think we may be able to reduce the boilerplate by putting the 
prefix/suffix/pattern in a struct, and passing that as an optional assuming we 
can figure out the move issue with regex. But this is for a future change if at 
all.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-06 Thread Jonas Devlieghere via lldb-commits
=?utf-8?q?Jos=C3=A9?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?Jos=C3=A9?= L. Junior ,
=?utf-8?q?Jos=C3=A9?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -70,6 +72,32 @@ size_t Stream::PutCString(llvm::StringRef str) {
   return bytes_written;
 }
 
+void Stream::PutCStringColorHighlighted(llvm::StringRef text,
+llvm::StringRef pattern,
+llvm::StringRef prefix,
+llvm::StringRef suffix) {
+  // If there is no pattern to match, we should not use color
+  if (pattern.empty()) {
+PutCString(text);
+return;
+  }

JDevlieghere wrote:

If the prefix and suffix are empty, we can also take this shortcut, right? 

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-06 Thread Jonas Devlieghere via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


https://github.com/JDevlieghere edited 
https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-06 Thread Jonas Devlieghere via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


https://github.com/JDevlieghere approved this pull request.

I didn't realize it was going to be so tedious to pass the prefix and suffix 
down, but I still think it's the right thing to do, so thanks for making that 
work. It would be awesome if we can make the `optional` work, but that's 
not a blocker so this LGTM.  

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-06 Thread José Lira Junior via lldb-commits

junior-jl wrote:

Addressed @JDevlieghere suggestions.

- A new debugger option was created for custom colors.
- The test needed some adaptation and we added a new case to test for other 
color option.
- The `SymbolContext` situtation is working as discussed with David: no color 
when there is no target.
- The recent changes are using `StringRef` for `pattern`. @taalhaataahir0102 is 
trying to make it work with `std::optional`.
- Some missing comments were added.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-06 Thread José Lira Junior via lldb-commits


@@ -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 matches;
+  llvm::StringRef remaining = text;
+  std::string format_str = lldb_private::ansi::FormatAnsiTerminalCodes(
+  "${ansi.fg.red}%.*s${ansi.normal}");

junior-jl wrote:

![image](https://github.com/llvm/llvm-project/assets/69206952/a9c34f6f-b671-4fc2-bc6c-abf8d9d489d2)

This is how it is working now. Basically no color for SymbolContext. IMO, it is 
a little weird, but the alternative option of forcing red color when no target 
is available could be weirder when the color was changed by the user.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-06 Thread José Lira Junior via lldb-commits

https://github.com/junior-jl updated 
https://github.com/llvm/llvm-project/pull/69422

From c416443a93f7113a7f57d337682ec4862438522d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20L=2E=20Junior?= 
Date: Tue, 7 Nov 2023 16:57:18 -0300
Subject: [PATCH 1/8] [lldb] colorize symbols in image lookup

This creates the method PutCStringColorHighlighted for Stream class,
which highlights searched symbols in red color for the image lookup command.

A new shell test was added to verify functionality. Relevant methods were
updated to accept the searched pattern/symbol as a parameter.

Co-authored-by: Talha 
---
 lldb/include/lldb/Core/Address.h  |  4 +-
 lldb/include/lldb/Symbol/Symbol.h |  4 +-
 lldb/include/lldb/Symbol/SymbolContext.h  |  8 ++--
 lldb/include/lldb/Utility/Stream.h| 16 
 lldb/source/Commands/CommandObjectTarget.cpp  | 16 +---
 lldb/source/Core/Address.cpp  | 21 ++
 lldb/source/Symbol/Symbol.cpp | 18 ++---
 lldb/source/Symbol/SymbolContext.cpp  | 16 +---
 lldb/source/Utility/Stream.cpp| 28 +
 .../Commands/command-image-lookup-color.test  | 39 +++
 10 files changed, 138 insertions(+), 32 deletions(-)
 create mode 100644 lldb/test/Shell/Commands/command-image-lookup-color.test

diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h
index b19e694427546..c3f2832be424e 100644
--- a/lldb/include/lldb/Core/Address.h
+++ b/lldb/include/lldb/Core/Address.h
@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;
 
   AddressClass GetAddressClass() const;
 
diff --git a/lldb/include/lldb/Symbol/Symbol.h 
b/lldb/include/lldb/Symbol/Symbol.h
index 44a2d560010fe..0e41cd95e0ef1 100644
--- a/lldb/include/lldb/Symbol/Symbol.h
+++ b/lldb/include/lldb/Symbol/Symbol.h
@@ -174,8 +174,8 @@ class Symbol : public SymbolContextScope {
 
   void SetFlags(uint32_t flags) { m_flags = flags; }
 
-  void GetDescription(Stream *s, lldb::DescriptionLevel level,
-  Target *target) const;
+  void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target,
+  const char *pattern = nullptr) const;
 
   bool IsSynthetic() const { return m_is_synthetic; }
 
diff --git a/lldb/include/lldb/Symbol/SymbolContext.h 
b/lldb/include/lldb/Symbol/SymbolContext.h
index b0f5ffead2a16..9567c3f4384c1 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -150,8 +150,8 @@ class SymbolContext {
   bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
const Address _addr, bool show_fullpaths,
bool show_module, bool show_inlined_frames,
-   bool show_function_arguments,
-   bool show_function_name) const;
+   bool show_function_arguments, bool show_function_name,
+   const char *pattern = nullptr) const;
 
   /// Get the address range contained within a symbol context.
   ///
@@ -217,8 +217,8 @@ class SymbolContext {
   /// The symbol that was found, or \b nullptr if none was found.
   const Symbol *FindBestGlobalDataSymbol(ConstString name, Status );
 
-  void GetDescription(Stream *s, lldb::DescriptionLevel level,
-  Target *target) const;
+  void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target,
+  const char *pattern = nullptr) const;
 
   uint32_t GetResolvedMask() const;
 
diff --git a/lldb/include/lldb/Utility/Stream.h 
b/lldb/include/lldb/Utility/Stream.h
index 1a5fd343e4df0..8e3fd48dfe705 100644
--- a/lldb/include/lldb/Utility/Stream.h
+++ b/lldb/include/lldb/Utility/Stream.h
@@ -231,6 +231,22 @@ class Stream {
   /// The string to be output to the stream.
   size_t PutCString(llvm::StringRef cstr);
 
+  /// Output a C string to the stream with color highlighting.
+  ///
+  /// Print a C string \a text to the stream, applying red color highlighting 
to
+  /// the portions of the string that match the regex pattern \a pattern. The
+  /// pattern is matched as many times as possible throughout the string. If \a
+  /// pattern is nullptr, then no highlighting is applied.
+  ///
+  /// \param[in] text
+  /// The string to be output to the stream.
+  ///
+  /// \param[in] pattern
+  /// The regex pattern to match against the \a text string. Portions of \a
+  /// text matching this pattern will be colorized. If this parameter is
+  /// nullptr, highlighting is not performed.
+  void 

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

2023-12-06 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;

DavidSpickett wrote:

I can't speak for Jonas here so just my interpretation - 

If you pass this as llvm::Regex, you're using the type system to signal to 
anyone reading this code that this is a regex pattern. Whereas using `const 
char*` and a comment that it is a regex could be missed by the reader.

test_func3 is the ideal here (though you may have to remove const, you'll find 
that out later). Deleting the copy constructor is usually done when you have a 
move only type, which is usually something that contains a resource where 
copying it doesn't make sense.

I think something like `test_func3(strm, std::move(regex2));` might fix it. At 
least, that's the obvious way to try to move construct the regex inside the 
optional.

Can you pass `std::make_optional(name)` to func3 maybe?

If all this is too much hassle in the end, using a pointer is the fallback 
option. As long as the lifetimes are ok which I'm guessing they are. By which I 
mean, nothing earlier in the callstack is going to destroy the pattern before 
you end up using it.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-06 Thread via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


https://github.com/taalhaataahir0102 edited 
https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-06 Thread via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


https://github.com/taalhaataahir0102 edited 
https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-06 Thread via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;

taalhaataahir0102 wrote:

Hi @DavidSpickett . Tried this incremental approach:

```
static void test_func1(Stream , llvm::Regex *regex_param = nullptr) {
  strm.Printf("Inside test_func1\n");
}

static void test_func2(Stream , llvm::Regex _param) {
  strm.Printf("Inside test_func2\n");
}

static void test_func3(Stream , const std::optional 
regex_param = std::nullopt) {
  strm.Printf("Inside test_func3\n");
}

static void test_func4(Stream , const std::optional 
_param = std::nullopt) {
  strm.Printf("Inside test_func4\n");
}

static uint32_t LookupSymbolInModule(CommandInterpreter ,
 Stream , Module *module,
 const char *name, bool name_is_regex,
 bool verbose, bool all_ranges) {
  llvm::Regex regex1(name);
  std::optional regex2 = std::make_optional(name);

  test_func1(strm, );
  test_func2(strm, regex1);
  // test_func3(strm, regex2);
  test_func4(strm, regex2);
  ...
  ...
  }
```

In test1, used the same logic like used previously i.e., function accepting 
pointer to `llvm::Regex` and default value is null pointer. 
In test2 passed `llvm::regex` by reference but could not give a default value. 
In test 3 used the `std::optional` but was getting the error 
mentioned above i.e., use of deleted functions. The exact error is:
```
error: use of deleted function ‘std::optional::optional(const 
std::optional&)’
 1611 |   test_func3(strm, regex2)
```
I believe it's due to the deletion of copy constructor which you mentioned. 
In test 4 passing the reference of `std::optional` to the function 
which is working fine as expected. Will use this one to pass the pattern now.
I'm a little confused. Right now, we're passing the pattern as 
`llvm::StringRef`, and finally when we reach `PutCStringColorHighlighted` we 
convert it to llvm::Regex:
`llvm::Regex reg_pattern(pattern);`
What will be the benefit of converting `const char* name` to 
`std::optional`  from the very beginning and than passing it till 
we reach `PutCStringColorHighlighted`? 樂

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-06 Thread via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


https://github.com/taalhaataahir0102 edited 
https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-06 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -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 matches;
+  llvm::StringRef remaining = text;
+  std::string format_str = lldb_private::ansi::FormatAnsiTerminalCodes(
+  "${ansi.fg.red}%.*s${ansi.normal}");

DavidSpickett wrote:

I assume if we have no target set we won't know whether to colour anything, so 
we'd default to no colours. Which means the prefix/suffix can default to empty 
string. Which is exactly what you've suggested.

Worst case in some situation it doesn't highlight and if the user cares they 
can open an issue for it.

I expect the SymbolContext can live without a target in some scenario, if you 
want to find out what, find somewhere in SymbolContext that null checks target, 
remove the check and see what tests fail.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-05 Thread José Lira Junior via lldb-commits


@@ -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 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
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-05 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -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 matches;
+  llvm::StringRef remaining = text;
+  std::string format_str = lldb_private::ansi::FormatAnsiTerminalCodes(
+  "${ansi.fg.red}%.*s${ansi.normal}");

DavidSpickett wrote:

I think it's either find another way to get to the settings, or assume no 
colour if the target isn't present.

Jonas may know a way to do it.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-05 Thread José Lira Junior via lldb-commits


@@ -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 matches;
+  llvm::StringRef remaining = text;
+  std::string format_str = lldb_private::ansi::FormatAnsiTerminalCodes(
+  "${ansi.fg.red}%.*s${ansi.normal}");

junior-jl wrote:

Actually, before pushing these, `check-lldb` failed because of this change.

You can check the log here: 
[https://pastebin.com/atfvLauV](https://pastebin.com/atfvLauV)

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-05 Thread José Lira Junior via lldb-commits


@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;

junior-jl wrote:

> Tbf I had to look up nullopt, I don't see it much.

I search this as well. Actually, I never used `std::optional` before.

> Can you post the error message(s)? Don't need to update the PR, just describe 
> how you're constructing and passing it, that'll likely be enough.

Okay. I'll update the PR with the recent changes and will try to replicate the 
error and post here.

> It may be caused by this https://godbolt.org/z/414Kzd18Y because llvm::Regex 
> deletes the copy constructor. This is I think because it contains state about 
> the matching. I think I should be able to move an llvm::Regex though but I 
> haven't been able to get that to work either.

This is interesting. I believe this is similar to the error we were getting.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-05 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;

DavidSpickett wrote:

Regex is put into an optional 
[here](https://github.com/llvm/llvm-project/blob/e4710872e98a931c6d5e89bc965b778746ead2c0/mlir/lib/IR/Diagnostics.cpp#L640)
 and in one other place. See also `clang-tools-extra/clangd/ConfigCompile.cpp`.

Tried to recreate that in a small example but failed. See what you can do with 
it.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-05 Thread José Lira Junior via lldb-commits


@@ -231,6 +231,25 @@ class Stream {
   /// The string to be output to the stream.
   size_t PutCString(llvm::StringRef cstr);
 
+  /// Output a C string to the stream with color highlighting.
+  ///
+  /// Print a C string \a text to the stream, applying red color highlighting 
to
+  /// the portions of the string that match the regex pattern \a pattern. The
+  /// pattern is matched as many times as possible throughout the string. If \a
+  /// pattern is nullptr, then no highlighting is applied.
+  ///
+  /// \param[in] text
+  /// The string to be output to the stream.
+  ///
+  /// \param[in] pattern
+  /// The regex pattern to match against the \a text string. Portions of \a
+  /// text matching this pattern will be colorized. If this parameter is
+  /// nullptr, highlighting is not performed.

junior-jl wrote:

Thank you. This also reminded me that we didn't update the comments in 
`SymbolContext.h` and `Address.h`. Added these as well.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-05 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;

DavidSpickett wrote:

It may be caused by this https://godbolt.org/z/414Kzd18Y because llvm::Regex 
deletes the copy constructor. This is I think because it contains state about 
the matching. I think I should be able to move an llvm::Regex though but I 
haven't been able to get that to work either.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-05 Thread José Lira Junior via lldb-commits


@@ -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 matches;
+  llvm::StringRef remaining = text;
+  std::string format_str = lldb_private::ansi::FormatAnsiTerminalCodes(
+  "${ansi.fg.red}%.*s${ansi.normal}");

junior-jl wrote:

I could have sworn I did this yesterday and it did not work. But I tried (again 
?) and it works now. Just checking if that's okay... This is how it is now: 

```cpp
llvm::StringRef ansi_prefix = 
exe_scope->CalculateTarget()->GetDebugger().GetRegexMatchAnsiPrefix();
llvm::StringRef ansi_suffix = 
exe_scope->CalculateTarget()->GetDebugger().GetRegexMatchAnsiSuffix();
```

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-05 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


https://github.com/DavidSpickett edited 
https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-05 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;

DavidSpickett wrote:

Tbf I had to look up nullopt, I don't see it much. `.value` returns a reference 
to the contained value (assuming it has one), `->` does the same so either is 
fine.

Can you post the error message(s)? Don't need to update this change, just 
describe how you're constructing and passing it, that'll likely be enough.


https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-05 Thread José Lira Junior via lldb-commits


@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;

junior-jl wrote:

I apologize, I should have noted the errors. But as far as I remember, it was 
related to use of deleted functions and type conversions. I also tried passing 
the parameter as a reference thinking the error could be caused by copying. 

> Remember that optionals are "pointer like" when you want to get at the value 
> within them, *foo, foo->method() etc. that trips me up sometimes.

Hmm, I was trying to get `pattern.value()`, perhaps that was part of the 
problem.

> Also the default value would be  = std::nullopt

At least I got that right.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-05 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;

DavidSpickett wrote:

What errors did you get?

Remember that optionals are "pointer like" when you want to get at the value 
within them, `*foo`, `foo->method()` etc. that trips me up sometimes. Also the 
default value would be ` = std::nullopt`.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-05 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -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 matches;
+  llvm::StringRef remaining = text;
+  std::string format_str = lldb_private::ansi::FormatAnsiTerminalCodes(
+  "${ansi.fg.red}%.*s${ansi.normal}");

DavidSpickett wrote:

You might be able to get it from the exe_scope like this does:
```
bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
   DumpStyle fallback_style, uint32_t addr_size,
   bool all_ranges) const {
```
But you won't always have a target. Which is a bit odd because there'd always 
be a settings object somewhere, if only you could get to it.

Seems like symbolcontext can have a target or not, and methods that definitely 
need one have it as a parameter. So that's the other way to go, add a parameter 
for it.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-05 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -231,6 +231,25 @@ class Stream {
   /// The string to be output to the stream.
   size_t PutCString(llvm::StringRef cstr);
 
+  /// Output a C string to the stream with color highlighting.
+  ///
+  /// Print a C string \a text to the stream, applying red color highlighting 
to
+  /// the portions of the string that match the regex pattern \a pattern. The
+  /// pattern is matched as many times as possible throughout the string. If \a
+  /// pattern is nullptr, then no highlighting is applied.
+  ///
+  /// \param[in] text
+  /// The string to be output to the stream.
+  ///
+  /// \param[in] pattern
+  /// The regex pattern to match against the \a text string. Portions of \a
+  /// text matching this pattern will be colorized. If this parameter is
+  /// nullptr, highlighting is not performed.

DavidSpickett wrote:

Reminder to update this comment once the other changes have settled.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-04 Thread José Lira Junior via lldb-commits


@@ -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 matches;
+  llvm::StringRef remaining = text;
+  std::string format_str = lldb_private::ansi::FormatAnsiTerminalCodes(
+  "${ansi.fg.red}%.*s${ansi.normal}");

junior-jl wrote:

Also, I was going to add a test case for different colors, but I will only add 
when that error is fixed.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-04 Thread José Lira Junior via lldb-commits


@@ -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 matches;
+  llvm::StringRef remaining = text;
+  std::string format_str = lldb_private::ansi::FormatAnsiTerminalCodes(
+  "${ansi.fg.red}%.*s${ansi.normal}");

junior-jl wrote:

I'm not sure if I got this suggestion right. What I did was:

1. Defined these properties in `lldb/source/Core/CoreProperties.td`:

```
def ShowRegexMatchAnsiPrefix: Property<"show-regex-match-ansi-prefix", 
"String">,
Global,
DefaultStringValue<"${ansi.fg.red}">,
Desc<"When displaying a regex match in a color-enabled terminal, use the 
ANSI terminal code specified in this format immediately before the match.">;
def ShowRegexMatchAnsiSuffix: Property<"show-regex-match-ansi-suffix", 
"String">,
Global,
DefaultStringValue<"${ansi.normal}">,
Desc<"When displaying a regex match in a color-enabled terminal, use the 
ANSI terminal code specified in this format immediately after the match.">;
```

2. Declared the getter functions in `Debugger.h` and defined them in 
`Debugger.cpp` following the pattern:

```cpp
llvm::StringRef Debugger::GetRegexMatchAnsiPrefix() const {
  const uint32_t idx = ePropertyShowRegexMatchAnsiPrefix;
  return GetPropertyAtIndexAs(
  idx, g_debugger_properties[idx].default_cstr_value);
}

llvm::StringRef Debugger::GetRegexMatchAnsiSuffix() const {
  const uint32_t idx = ePropertyShowRegexMatchAnsiSuffix;
  return GetPropertyAtIndexAs(
  idx, g_debugger_properties[idx].default_cstr_value);
}

```

3. Added two parameters to `Stream::PutCStringColorHighlighted`: `prefix` and 
`suffix`.
4. In `Address.cpp` and `Symbol.cpp`, there was a `Target` object that I used 
to get the debugger and its properties. In `CommandObjectTarget.cpp`, there was 
an `CommandInterpreter` object that was used for the same. But in 
`SymbolContext.cpp`, there was a `TargetSP` object and I tried using it to get 
the debugger properties, I got a segmentation fault, that's why I put the 
following two lines hard coded (while we don't solve this):

```
llvm::StringRef ansi_prefix = "${ansi.fg.red}";
llvm::StringRef ansi_suffix = "${ansi.normal}";
```

Please let me know if there's a better way to do this or if I completely 
misunderstood the suggestion.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-04 Thread José Lira Junior via lldb-commits


@@ -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

junior-jl wrote:

Nice. Changed this.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-04 Thread José Lira Junior via lldb-commits


@@ -1593,6 +1595,7 @@ static uint32_t LookupSymbolInModule(CommandInterpreter 
,
 return 0;
 
   SymbolContext sc;
+  bool use_color = interpreter.GetDebugger().GetUseColor();

junior-jl wrote:

Done.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-04 Thread José Lira Junior via lldb-commits


@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;

junior-jl wrote:

Changed to `StringRef`. I could not make it work with 
`std::optional`. Maybe I was doing something wrong.



https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-04 Thread José Lira Junior via lldb-commits

https://github.com/junior-jl updated 
https://github.com/llvm/llvm-project/pull/69422

From c416443a93f7113a7f57d337682ec4862438522d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20L=2E=20Junior?= 
Date: Tue, 7 Nov 2023 16:57:18 -0300
Subject: [PATCH 1/7] [lldb] colorize symbols in image lookup

This creates the method PutCStringColorHighlighted for Stream class,
which highlights searched symbols in red color for the image lookup command.

A new shell test was added to verify functionality. Relevant methods were
updated to accept the searched pattern/symbol as a parameter.

Co-authored-by: Talha 
---
 lldb/include/lldb/Core/Address.h  |  4 +-
 lldb/include/lldb/Symbol/Symbol.h |  4 +-
 lldb/include/lldb/Symbol/SymbolContext.h  |  8 ++--
 lldb/include/lldb/Utility/Stream.h| 16 
 lldb/source/Commands/CommandObjectTarget.cpp  | 16 +---
 lldb/source/Core/Address.cpp  | 21 ++
 lldb/source/Symbol/Symbol.cpp | 18 ++---
 lldb/source/Symbol/SymbolContext.cpp  | 16 +---
 lldb/source/Utility/Stream.cpp| 28 +
 .../Commands/command-image-lookup-color.test  | 39 +++
 10 files changed, 138 insertions(+), 32 deletions(-)
 create mode 100644 lldb/test/Shell/Commands/command-image-lookup-color.test

diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h
index b19e694427546..c3f2832be424e 100644
--- a/lldb/include/lldb/Core/Address.h
+++ b/lldb/include/lldb/Core/Address.h
@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;
 
   AddressClass GetAddressClass() const;
 
diff --git a/lldb/include/lldb/Symbol/Symbol.h 
b/lldb/include/lldb/Symbol/Symbol.h
index 44a2d560010fe..0e41cd95e0ef1 100644
--- a/lldb/include/lldb/Symbol/Symbol.h
+++ b/lldb/include/lldb/Symbol/Symbol.h
@@ -174,8 +174,8 @@ class Symbol : public SymbolContextScope {
 
   void SetFlags(uint32_t flags) { m_flags = flags; }
 
-  void GetDescription(Stream *s, lldb::DescriptionLevel level,
-  Target *target) const;
+  void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target,
+  const char *pattern = nullptr) const;
 
   bool IsSynthetic() const { return m_is_synthetic; }
 
diff --git a/lldb/include/lldb/Symbol/SymbolContext.h 
b/lldb/include/lldb/Symbol/SymbolContext.h
index b0f5ffead2a16..9567c3f4384c1 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -150,8 +150,8 @@ class SymbolContext {
   bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
const Address _addr, bool show_fullpaths,
bool show_module, bool show_inlined_frames,
-   bool show_function_arguments,
-   bool show_function_name) const;
+   bool show_function_arguments, bool show_function_name,
+   const char *pattern = nullptr) const;
 
   /// Get the address range contained within a symbol context.
   ///
@@ -217,8 +217,8 @@ class SymbolContext {
   /// The symbol that was found, or \b nullptr if none was found.
   const Symbol *FindBestGlobalDataSymbol(ConstString name, Status );
 
-  void GetDescription(Stream *s, lldb::DescriptionLevel level,
-  Target *target) const;
+  void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target,
+  const char *pattern = nullptr) const;
 
   uint32_t GetResolvedMask() const;
 
diff --git a/lldb/include/lldb/Utility/Stream.h 
b/lldb/include/lldb/Utility/Stream.h
index 1a5fd343e4df0..8e3fd48dfe705 100644
--- a/lldb/include/lldb/Utility/Stream.h
+++ b/lldb/include/lldb/Utility/Stream.h
@@ -231,6 +231,22 @@ class Stream {
   /// The string to be output to the stream.
   size_t PutCString(llvm::StringRef cstr);
 
+  /// Output a C string to the stream with color highlighting.
+  ///
+  /// Print a C string \a text to the stream, applying red color highlighting 
to
+  /// the portions of the string that match the regex pattern \a pattern. The
+  /// pattern is matched as many times as possible throughout the string. If \a
+  /// pattern is nullptr, then no highlighting is applied.
+  ///
+  /// \param[in] text
+  /// The string to be output to the stream.
+  ///
+  /// \param[in] pattern
+  /// The regex pattern to match against the \a text string. Portions of \a
+  /// text matching this pattern will be colorized. If this parameter is
+  /// nullptr, highlighting is not performed.
+  void 

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

2023-12-04 Thread Jonas Devlieghere via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>
Message-ID:
In-Reply-To: 



@@ -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 matches;
+  llvm::StringRef remaining = text;
+  std::string format_str = lldb_private::ansi::FormatAnsiTerminalCodes(
+  "${ansi.fg.red}%.*s${ansi.normal}");

JDevlieghere wrote:

Most (all?) other colors are configurable. I think this one should be too. Some 
examples of this are the `show-autosuggestion-ansi-prefix` and 
`show-progress-ansi-prefix`. This pattern should work here as well. 

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-04 Thread Jonas Devlieghere via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>
Message-ID:
In-Reply-To: 



@@ -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

JDevlieghere wrote:

Nit: seems more informative to have the inverse of this comment at the start of 
the function where we have an early return for the trivial case of not having a 
patter to highlight. 

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-04 Thread Jonas Devlieghere via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>
Message-ID:
In-Reply-To: 


https://github.com/JDevlieghere edited 
https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-04 Thread Jonas Devlieghere via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>
Message-ID:
In-Reply-To: 



@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;

JDevlieghere wrote:

Why is `pattern` a `const char*` and not a StringRef with an empty string as 
the default argument? Or potentially even better an 
`std::optional`?

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-04 Thread Jonas Devlieghere via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>
Message-ID:
In-Reply-To: 


https://github.com/JDevlieghere commented:

This is an awesome feature, thank you for working on this! I left a few 
comments but overall this PR is in pretty good shape.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-04 Thread Jonas Devlieghere via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>
Message-ID:
In-Reply-To: 



@@ -1593,6 +1595,7 @@ static uint32_t LookupSymbolInModule(CommandInterpreter 
,
 return 0;
 
   SymbolContext sc;
+  bool use_color = interpreter.GetDebugger().GetUseColor();

JDevlieghere wrote:

Unlike in llvm we do `const` variables (and there's examples of that in the 
surrounding code) so let's make this `const bool use_color`. 

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-03 Thread via lldb-commits
=?utf-8?q?Jos=C3=A9?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>
Message-ID:
In-Reply-To: 


taalhaataahir0102 wrote:

Hi @JDevlieghere! did you got a chance to look at the code 

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-12-03 Thread via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 <23100...@lums.edu.pk>
Message-ID:
In-Reply-To: 


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

>From c416443a93f7113a7f57d337682ec4862438522d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20L=2E=20Junior?= 
Date: Tue, 7 Nov 2023 16:57:18 -0300
Subject: [PATCH 1/6] [lldb] colorize symbols in image lookup

This creates the method PutCStringColorHighlighted for Stream class,
which highlights searched symbols in red color for the image lookup command.

A new shell test was added to verify functionality. Relevant methods were
updated to accept the searched pattern/symbol as a parameter.

Co-authored-by: Talha 
---
 lldb/include/lldb/Core/Address.h  |  4 +-
 lldb/include/lldb/Symbol/Symbol.h |  4 +-
 lldb/include/lldb/Symbol/SymbolContext.h  |  8 ++--
 lldb/include/lldb/Utility/Stream.h| 16 
 lldb/source/Commands/CommandObjectTarget.cpp  | 16 +---
 lldb/source/Core/Address.cpp  | 21 ++
 lldb/source/Symbol/Symbol.cpp | 18 ++---
 lldb/source/Symbol/SymbolContext.cpp  | 16 +---
 lldb/source/Utility/Stream.cpp| 28 +
 .../Commands/command-image-lookup-color.test  | 39 +++
 10 files changed, 138 insertions(+), 32 deletions(-)
 create mode 100644 lldb/test/Shell/Commands/command-image-lookup-color.test

diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h
index b19e694427546..c3f2832be424e 100644
--- a/lldb/include/lldb/Core/Address.h
+++ b/lldb/include/lldb/Core/Address.h
@@ -246,8 +246,8 @@ class Address {
   /// \see Address::DumpStyle
   bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 DumpStyle fallback_style = DumpStyleInvalid,
-uint32_t addr_byte_size = UINT32_MAX,
-bool all_ranges = false) const;
+uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false,
+const char *pattern = nullptr) const;
 
   AddressClass GetAddressClass() const;
 
diff --git a/lldb/include/lldb/Symbol/Symbol.h 
b/lldb/include/lldb/Symbol/Symbol.h
index 44a2d560010fe..0e41cd95e0ef1 100644
--- a/lldb/include/lldb/Symbol/Symbol.h
+++ b/lldb/include/lldb/Symbol/Symbol.h
@@ -174,8 +174,8 @@ class Symbol : public SymbolContextScope {
 
   void SetFlags(uint32_t flags) { m_flags = flags; }
 
-  void GetDescription(Stream *s, lldb::DescriptionLevel level,
-  Target *target) const;
+  void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target,
+  const char *pattern = nullptr) const;
 
   bool IsSynthetic() const { return m_is_synthetic; }
 
diff --git a/lldb/include/lldb/Symbol/SymbolContext.h 
b/lldb/include/lldb/Symbol/SymbolContext.h
index b0f5ffead2a16..9567c3f4384c1 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -150,8 +150,8 @@ class SymbolContext {
   bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
const Address _addr, bool show_fullpaths,
bool show_module, bool show_inlined_frames,
-   bool show_function_arguments,
-   bool show_function_name) const;
+   bool show_function_arguments, bool show_function_name,
+   const char *pattern = nullptr) const;
 
   /// Get the address range contained within a symbol context.
   ///
@@ -217,8 +217,8 @@ class SymbolContext {
   /// The symbol that was found, or \b nullptr if none was found.
   const Symbol *FindBestGlobalDataSymbol(ConstString name, Status );
 
-  void GetDescription(Stream *s, lldb::DescriptionLevel level,
-  Target *target) const;
+  void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target,
+  const char *pattern = nullptr) const;
 
   uint32_t GetResolvedMask() const;
 
diff --git a/lldb/include/lldb/Utility/Stream.h 
b/lldb/include/lldb/Utility/Stream.h
index 1a5fd343e4df0..8e3fd48dfe705 100644
--- a/lldb/include/lldb/Utility/Stream.h
+++ b/lldb/include/lldb/Utility/Stream.h
@@ -231,6 +231,22 @@ class Stream {
   /// The string to be output to the stream.
   size_t PutCString(llvm::StringRef cstr);
 
+  /// Output a C string to the stream with color highlighting.
+  ///
+  /// Print a C string \a text to the stream, applying red color highlighting 
to
+  /// the portions of the string that match the regex pattern \a pattern. The
+  /// pattern is matched as many times as possible throughout the string. If \a
+  /// pattern is nullptr, then no highlighting is applied.
+  ///
+  /// \param[in] text
+  /// The string to be output to the stream.
+  ///
+  /// \param[in] 

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

2023-11-30 Thread David Spickett via lldb-commits
=?utf-8?q?Jos=C3=A9?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>
Message-ID:
In-Reply-To: 


DavidSpickett wrote:

Nominating @JDevlieghere to review this.

https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-11-30 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,taalhaataahir0102
 <23100...@lums.edu.pk>,taalhaataahir0102 
<23100...@lums.edu.pk>,taalhaataahir0102
 <23100...@lums.edu.pk>
Message-ID:
In-Reply-To: 


https://github.com/DavidSpickett edited 
https://github.com/llvm/llvm-project/pull/69422
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits