aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectTarget.cpp
diff options
context:
space:
mode:
authortaalhaataahir0102 <77788288+taalhaataahir0102@users.noreply.github.com>2023-12-08 16:09:04 +0500
committerGitHub <noreply@github.com>2023-12-08 11:09:04 +0000
commitc90cb6eee8296953c097fcc9fc6e61f739c0dad3 (patch)
tree8a710839b64e2a6d830b5fcbb025760be6650534 /lldb/source/Commands/CommandObjectTarget.cpp
parentfaecc736e2ac3cd8c77bebf41b1ed2e2d8cb575f (diff)
downloadllvm-c90cb6eee8296953c097fcc9fc6e61f739c0dad3.zip
llvm-c90cb6eee8296953c097fcc9fc6e61f739c0dad3.tar.gz
llvm-c90cb6eee8296953c097fcc9fc6e61f739c0dad3.tar.bz2
[lldb] colorize symbols in image lookup with a regex pattern (#69422)
Fixes https://github.com/llvm/llvm-project/issues/57372 Previously some work has already been done on this. A PR was generated but it remained in review: https://reviews.llvm.org/D136462 In short previous approach was following: Changing the symbol names (making the searched part colorized) -> printing them -> restoring the symbol names back in their original form. The reviewers suggested that instead of changing the symbol table, this colorization should be done in the dump functions itself. Our strategy involves passing the searched regex pattern to the existing dump functions responsible for printing information about the searched symbol. This pattern is propagated until it reaches the line in the dump functions responsible for displaying symbol information on screen. At this point, we've introduced a new function called "PutCStringColorHighlighted," which takes the searched pattern, a prefix and suffix, and the text and applies colorization to highlight the pattern in the output. This approach aims to streamline the symbol search process to improve readability of search results. Co-authored-by: José L. Junior <josejunior@10xengineers.ai>
Diffstat (limited to 'lldb/source/Commands/CommandObjectTarget.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectTarget.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 58785cd..63232c2 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -8,6 +8,7 @@
#include "CommandObjectTarget.h"
+#include "lldb/Core/Address.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/IOHandler.h"
#include "lldb/Core/Module.h"
@@ -1532,7 +1533,7 @@ static void DumpOsoFilesTable(Stream &strm,
static void DumpAddress(ExecutionContextScope *exe_scope,
const Address &so_addr, bool verbose, bool all_ranges,
- Stream &strm) {
+ Stream &strm, llvm::StringRef pattern = "") {
strm.IndentMore();
strm.Indent(" Address: ");
so_addr.Dump(&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
@@ -1542,13 +1543,14 @@ static void DumpAddress(ExecutionContextScope *exe_scope,
strm.Indent(" Summary: ");
const uint32_t save_indent = strm.GetIndentLevel();
strm.SetIndentLevel(save_indent + 13);
- so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription);
+ so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription,
+ Address::DumpStyleInvalid, UINT32_MAX, false, pattern);
strm.SetIndentLevel(save_indent);
// Print out detailed address information when verbose is enabled
if (verbose) {
strm.EOL();
so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext,
- Address::DumpStyleInvalid, UINT32_MAX, all_ranges);
+ Address::DumpStyleInvalid, UINT32_MAX, all_ranges, pattern);
}
strm.IndentLess();
}
@@ -1593,6 +1595,7 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
return 0;
SymbolContext sc;
+ const bool use_color = interpreter.GetDebugger().GetUseColor();
std::vector<uint32_t> match_indexes;
ConstString symbol_name(name);
uint32_t num_matches = 0;
@@ -1618,12 +1621,19 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
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();
+ strm.PutCStringColorHighlighted(
+ symbol->GetDisplayName().GetStringRef(),
+ use_color ? name : nullptr, ansi_prefix, ansi_suffix);
strm.EOL();
strm.Indent(" Value: ");
strm.Printf("0x%16.16" PRIx64 "\n", symbol->GetRawValue());