https://github.com/junior-jl created https://github.com/llvm/llvm-project/pull/76112
Follow-up to #69422. This commit builds upon the previous contribution that introduced symbol colorization in the image lookup command when using regex. In response to feedback from reviewers, this follow-up refines the colorization mechanism based on their recommendations. Changes: - Refactors symbol colorization logic to incorporate feedback from the previous commit. - Extends colorization to functions in addition to symbols for a more comprehensive visual representation. Co-authored-by: Talha Tahir <talha.ta...@10xengineers.ai> From b2d254fabcaacb849ba48e342c62abf7ecd9779a Mon Sep 17 00:00:00 2001 From: taalhaataahir0102 <23100...@lums.edu.pk> Date: Wed, 13 Dec 2023 15:12:29 +0500 Subject: [PATCH 1/4] Using struct for transfering pattern information --- lldb/include/lldb/Core/Address.h | 4 +- lldb/include/lldb/Symbol/Symbol.h | 3 +- lldb/include/lldb/Symbol/SymbolContext.h | 5 +- lldb/include/lldb/Utility/Stream.h | 10 +++- lldb/source/Commands/CommandObjectTarget.cpp | 35 ++++++++---- lldb/source/Core/Address.cpp | 59 ++++++++++++++------ lldb/source/Symbol/Symbol.cpp | 14 +++-- lldb/source/Symbol/SymbolContext.cpp | 22 +++++--- lldb/source/Utility/Stream.cpp | 10 ++-- 9 files changed, 110 insertions(+), 52 deletions(-) diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h index 725b5d9f91d3d5..c5a47321c774e7 100644 --- a/lldb/include/lldb/Core/Address.h +++ b/lldb/include/lldb/Core/Address.h @@ -13,6 +13,7 @@ #include "lldb/lldb-forward.h" #include "lldb/lldb-private-enumerations.h" #include "lldb/lldb-types.h" +#include "lldb/Utility/Stream.h" #include "llvm/ADT/StringRef.h" @@ -255,7 +256,8 @@ class Address { bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style = DumpStyleInvalid, uint32_t addr_byte_size = UINT32_MAX, bool all_ranges = false, - llvm::StringRef pattern = "") const; + std::optional<Information> pattern_info = std::nullopt) const; + AddressClass GetAddressClass() const; diff --git a/lldb/include/lldb/Symbol/Symbol.h b/lldb/include/lldb/Symbol/Symbol.h index e6c0b495bcf28c..96ba7ba282a01c 100644 --- a/lldb/include/lldb/Symbol/Symbol.h +++ b/lldb/include/lldb/Symbol/Symbol.h @@ -16,6 +16,7 @@ #include "lldb/Utility/UserID.h" #include "lldb/lldb-private.h" #include "llvm/Support/JSON.h" +#include "lldb/Utility/Stream.h" namespace lldb_private { @@ -175,7 +176,7 @@ class Symbol : public SymbolContextScope { void SetFlags(uint32_t flags) { m_flags = flags; } void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target, - llvm::StringRef pattern = "") const; + std::optional<Information> pattern_info = std::nullopt) 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 26f3bac09a9626..529dc9630840b7 100644 --- a/lldb/include/lldb/Symbol/SymbolContext.h +++ b/lldb/include/lldb/Symbol/SymbolContext.h @@ -17,6 +17,7 @@ #include "lldb/Core/Mangled.h" #include "lldb/Symbol/LineEntry.h" #include "lldb/Utility/Iterable.h" +#include "lldb/Utility/Stream.h" #include "lldb/lldb-private.h" namespace lldb_private { @@ -157,7 +158,7 @@ class SymbolContext { const Address &so_addr, bool show_fullpaths, bool show_module, bool show_inlined_frames, bool show_function_arguments, bool show_function_name, - llvm::StringRef pattern = "") const; + std::optional<Information> pattern_info = std::nullopt) const; /// Get the address range contained within a symbol context. /// @@ -224,7 +225,7 @@ class SymbolContext { const Symbol *FindBestGlobalDataSymbol(ConstString name, Status &error); void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target, - llvm::StringRef pattern = "") const; + std::optional<Information> pattern_info = std::nullopt) const; uint32_t GetResolvedMask() const; diff --git a/lldb/include/lldb/Utility/Stream.h b/lldb/include/lldb/Utility/Stream.h index 20c55ac4597ae6..accbdb3b3fed35 100644 --- a/lldb/include/lldb/Utility/Stream.h +++ b/lldb/include/lldb/Utility/Stream.h @@ -23,6 +23,12 @@ namespace lldb_private { +struct Information { + llvm::StringRef pattern; + llvm::StringRef prefix; + llvm::StringRef suffix; +}; + /// \class Stream Stream.h "lldb/Utility/Stream.h" /// A stream class that can stream formatted output to a file. class Stream { @@ -261,9 +267,7 @@ class Stream { /// environment-dependent. void PutCStringColorHighlighted(llvm::StringRef text, - llvm::StringRef pattern = "", - llvm::StringRef prefix = "", - llvm::StringRef suffix = ""); + std::optional<Information> pattern_info = std::nullopt); /// Output and End of Line character to the stream. size_t EOL(); diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index bc8bc51356c8ca..96c7b2f5930cd1 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -55,6 +55,7 @@ #include "lldb/Utility/State.h" #include "lldb/Utility/StructuredData.h" #include "lldb/Utility/Timer.h" +#include "lldb/Utility/Stream.h" #include "lldb/lldb-enumerations.h" #include "lldb/lldb-private-enumerations.h" @@ -1533,7 +1534,7 @@ static void DumpOsoFilesTable(Stream &strm, static void DumpAddress(ExecutionContextScope *exe_scope, const Address &so_addr, bool verbose, bool all_ranges, - Stream &strm, llvm::StringRef pattern = "") { + Stream &strm, std::optional<Information> pattern_info = std::nullopt) { strm.IndentMore(); strm.Indent(" Address: "); so_addr.Dump(&strm, exe_scope, Address::DumpStyleModuleWithFileAddress); @@ -1543,14 +1544,22 @@ 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, - Address::DumpStyleInvalid, UINT32_MAX, false, pattern); + if (pattern_info.has_value()) + so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription, + Address::DumpStyleInvalid, UINT32_MAX, false, pattern_info); + else + so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription, + Address::DumpStyleInvalid, UINT32_MAX, false); 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, pattern); + if(pattern_info.has_value()) + so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext, + Address::DumpStyleInvalid, UINT32_MAX, all_ranges, pattern_info); + else + so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext, + Address::DumpStyleInvalid, UINT32_MAX, all_ranges); } strm.IndentLess(); } @@ -1618,22 +1627,26 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter, for (uint32_t i = 0; i < num_matches; ++i) { Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]); if (symbol) { + Information info; + llvm::StringRef ansi_prefix = + interpreter.GetDebugger().GetRegexMatchAnsiPrefix(); + llvm::StringRef ansi_suffix = + interpreter.GetDebugger().GetRegexMatchAnsiSuffix(); + info.pattern = name; + info.prefix = ansi_prefix; + info.suffix = ansi_suffix; if (symbol->ValueIsAddress()) { DumpAddress( interpreter.GetExecutionContext().GetBestExecutionContextScope(), symbol->GetAddressRef(), verbose, all_ranges, strm, - use_color && name_is_regex ? name : nullptr); + use_color && name_is_regex ? std::optional<Information>{info} : std::nullopt); strm.EOL(); } else { strm.IndentMore(); strm.Indent(" Name: "); - 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); + use_color ? std::optional<Information>{info} : std::nullopt); strm.EOL(); strm.Indent(" Value: "); strm.Printf("0x%16.16" PRIx64 "\n", symbol->GetRawValue()); diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp index 19d34db44ea55c..740df9dc490f5c 100644 --- a/lldb/source/Core/Address.cpp +++ b/lldb/source/Core/Address.cpp @@ -407,7 +407,7 @@ bool Address::GetDescription(Stream &s, Target &target, bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style, uint32_t addr_size, - bool all_ranges, llvm::StringRef pattern) const { + bool all_ranges, std::optional<Information> pattern_info) const { // If the section was nullptr, only load address is going to work unless we // are trying to deref a pointer SectionSP section_sp(GetSection()); @@ -524,8 +524,10 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, ansi_suffix = target->GetDebugger().GetRegexMatchAnsiSuffix(); } - s->PutCStringColorHighlighted(symbol_name, pattern, - ansi_prefix, ansi_suffix); + if (pattern_info.has_value()) + s->PutCStringColorHighlighted(symbol_name, pattern_info); + else + s->PutCStringColorHighlighted(symbol_name); addr_t delta = file_Addr - symbol->GetAddressRef().GetFileAddress(); if (delta) @@ -652,8 +654,12 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, if (pointer_sc.function != nullptr || pointer_sc.symbol != nullptr) { s->PutCString(": "); - pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, - false, true, true, pattern); + if (pattern_info.has_value()) + pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, + false, true, true, pattern_info); + else + pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, + false, true, true); } } } @@ -690,24 +696,38 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, if (show_stop_context) { // We have a function or a symbol from the same sections as this // address. - sc.DumpStopContext(s, exe_scope, *this, show_fullpaths, - show_module, show_inlined_frames, - show_function_arguments, show_function_name, - pattern); + + if (pattern_info.has_value()) + sc.DumpStopContext(s, exe_scope, *this, show_fullpaths, + show_module, show_inlined_frames, + show_function_arguments, show_function_name, + pattern_info); + else + sc.DumpStopContext(s, exe_scope, *this, show_fullpaths, + show_module, show_inlined_frames, + show_function_arguments, show_function_name); } else { // We found a symbol but it was in a different section so it // isn't the symbol we should be showing, just show the section // name + offset - Dump(s, exe_scope, DumpStyleSectionNameOffset, DumpStyleInvalid, - UINT32_MAX, false, pattern); + if (pattern_info.has_value()) + Dump(s, exe_scope, DumpStyleSectionNameOffset, DumpStyleInvalid, + UINT32_MAX, false, pattern_info); + else + Dump(s, exe_scope, DumpStyleSectionNameOffset, DumpStyleInvalid, + UINT32_MAX, false); } } } } } else { if (fallback_style != DumpStyleInvalid) - return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, - false, pattern); + if (pattern_info.has_value()) + return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, + false, pattern_info); + else + return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, + false); return false; } break; @@ -728,7 +748,10 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, sc.symbol->GetAddressRef().GetSection() != GetSection()) sc.symbol = nullptr; } - sc.GetDescription(s, eDescriptionLevelBrief, target, pattern); + if (pattern_info.has_value()) + sc.GetDescription(s, eDescriptionLevelBrief, target, pattern_info); + else + sc.GetDescription(s, eDescriptionLevelBrief, target); if (sc.block) { bool can_create = true; @@ -776,8 +799,12 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, } } else { if (fallback_style != DumpStyleInvalid) - return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, - false, pattern); + if (pattern_info.has_value()) + return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, + false, pattern_info); + else + return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, + false); return false; } break; diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp index fcc45f861c2255..e33577b9256e5e 100644 --- a/lldb/source/Symbol/Symbol.cpp +++ b/lldb/source/Symbol/Symbol.cpp @@ -227,7 +227,7 @@ bool Symbol::IsTrampoline() const { return m_type == eSymbolTypeTrampoline; } bool Symbol::IsIndirect() const { return m_type == eSymbolTypeResolver; } void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level, - Target *target, llvm::StringRef pattern) const { + Target *target, std::optional<Information> pattern_info) const { s->Printf("id = {0x%8.8x}", m_uid); if (m_addr_range.GetBaseAddress().GetSection()) { @@ -262,14 +262,18 @@ void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level, } if (ConstString demangled = m_mangled.GetDemangledName()) { s->PutCString(", name=\""); - s->PutCStringColorHighlighted(demangled.GetStringRef(), pattern, - ansi_prefix, ansi_suffix); + if (pattern_info.has_value()) + s->PutCStringColorHighlighted(demangled.GetStringRef(), pattern_info); + else + s->PutCStringColorHighlighted(demangled.GetStringRef()); s->PutCString("\""); } if (ConstString mangled_name = m_mangled.GetMangledName()) { s->PutCString(", mangled=\""); - s->PutCStringColorHighlighted(mangled_name.GetStringRef(), pattern, - ansi_prefix, ansi_suffix); + if (pattern_info.has_value()) + s->PutCStringColorHighlighted(mangled_name.GetStringRef(), pattern_info); + else + s->PutCStringColorHighlighted(mangled_name.GetStringRef()); s->PutCString("\""); } } diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp index 9fd40b5ca567f8..c00960913bf103 100644 --- a/lldb/source/Symbol/SymbolContext.cpp +++ b/lldb/source/Symbol/SymbolContext.cpp @@ -25,6 +25,7 @@ #include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/StreamString.h" +#include "lldb/Utility/Stream.h" #include "lldb/lldb-enumerations.h" using namespace lldb; @@ -73,7 +74,7 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope, bool show_module, bool show_inlined_frames, bool show_function_arguments, bool show_function_name, - llvm::StringRef pattern) const { + std::optional<Information> pattern_info) const { bool dumped_something = false; if (show_module && module_sp) { if (show_fullpaths) @@ -102,8 +103,10 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope, ansi_prefix = target_sp->GetDebugger().GetRegexMatchAnsiPrefix(); ansi_suffix = target_sp->GetDebugger().GetRegexMatchAnsiSuffix(); } - s->PutCStringColorHighlighted(name.GetStringRef(), pattern, ansi_prefix, - ansi_suffix); + if (pattern_info.has_value()) + s->PutCStringColorHighlighted(name.GetStringRef(), pattern_info); + else + s->PutCStringColorHighlighted(name.GetStringRef()); } } @@ -178,8 +181,10 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope, ansi_prefix = target_sp->GetDebugger().GetRegexMatchAnsiPrefix(); ansi_suffix = target_sp->GetDebugger().GetRegexMatchAnsiSuffix(); } - s->PutCStringColorHighlighted(symbol->GetName().GetStringRef(), pattern, - ansi_prefix, ansi_suffix); + if (pattern_info.has_value()) + s->PutCStringColorHighlighted(symbol->GetName().GetStringRef(), pattern_info); + else + s->PutCStringColorHighlighted(symbol->GetName().GetStringRef()); } if (addr.IsValid() && symbol->ValueIsAddress()) { @@ -203,7 +208,7 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope, void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target, - llvm::StringRef pattern) const { + std::optional<Information> pattern_info) const { if (module_sp) { s->Indent(" Module: file = \""); module_sp->GetFileSpec().Dump(s->AsRawOstream()); @@ -263,7 +268,10 @@ void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level, if (symbol != nullptr) { s->Indent(" Symbol: "); - symbol->GetDescription(s, level, target, pattern); + if (pattern_info.has_value()) + symbol->GetDescription(s, level, target, pattern_info); + else + symbol->GetDescription(s, level, target); s->EOL(); } diff --git a/lldb/source/Utility/Stream.cpp b/lldb/source/Utility/Stream.cpp index 62e061e9d09c07..9a670ea9b54d8b 100644 --- a/lldb/source/Utility/Stream.cpp +++ b/lldb/source/Utility/Stream.cpp @@ -73,22 +73,20 @@ size_t Stream::PutCString(llvm::StringRef str) { } void Stream::PutCStringColorHighlighted(llvm::StringRef text, - llvm::StringRef pattern, - llvm::StringRef prefix, - llvm::StringRef suffix) { + std::optional<Information> pattern_info) { // Only apply color formatting when a pattern is present and both prefix and // suffix are specified. In the absence of these conditions, output the text // without color formatting. - if (pattern.empty() || (prefix.empty() && suffix.empty())) { + if (!pattern_info.has_value()) { PutCString(text); return; } - llvm::Regex reg_pattern(pattern); + llvm::Regex reg_pattern(pattern_info.value().pattern); llvm::SmallVector<llvm::StringRef, 1> matches; llvm::StringRef remaining = text; std::string format_str = lldb_private::ansi::FormatAnsiTerminalCodes( - prefix.str() + "%.*s" + suffix.str()); + pattern_info.value().prefix.str() + "%.*s" + pattern_info.value().suffix.str()); while (reg_pattern.match(remaining, &matches)) { llvm::StringRef match = matches[0]; size_t match_start_pos = match.data() - remaining.data(); From 95a2d617fc72b0641fb710f7e6dc2c01b68a0b3a Mon Sep 17 00:00:00 2001 From: taalhaataahir0102 <23100...@lums.edu.pk> Date: Wed, 13 Dec 2023 16:08:52 +0500 Subject: [PATCH 2/4] Added colorization for regex function search --- lldb/include/lldb/Utility/Stream.h | 4 +++ lldb/source/Commands/CommandObjectTarget.cpp | 30 +++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lldb/include/lldb/Utility/Stream.h b/lldb/include/lldb/Utility/Stream.h index accbdb3b3fed35..7aed0a831631bd 100644 --- a/lldb/include/lldb/Utility/Stream.h +++ b/lldb/include/lldb/Utility/Stream.h @@ -27,6 +27,10 @@ struct Information { llvm::StringRef pattern; llvm::StringRef prefix; llvm::StringRef suffix; + + // Constructor + Information(llvm::StringRef p, llvm::StringRef pre, llvm::StringRef suf) + : pattern(p), prefix(pre), suffix(suf) {} }; /// \class Stream Stream.h "lldb/Utility/Stream.h" diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index 96c7b2f5930cd1..0a89014c42912d 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -1618,6 +1618,11 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter, } if (num_matches > 0) { + llvm::StringRef ansi_prefix = + interpreter.GetDebugger().GetRegexMatchAnsiPrefix(); + llvm::StringRef ansi_suffix = + interpreter.GetDebugger().GetRegexMatchAnsiSuffix(); + Information info(name, ansi_prefix, ansi_suffix); strm.Indent(); strm.Printf("%u symbols match %s'%s' in ", num_matches, name_is_regex ? "the regular expression " : "", name); @@ -1627,14 +1632,6 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter, for (uint32_t i = 0; i < num_matches; ++i) { Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]); if (symbol) { - Information info; - llvm::StringRef ansi_prefix = - interpreter.GetDebugger().GetRegexMatchAnsiPrefix(); - llvm::StringRef ansi_suffix = - interpreter.GetDebugger().GetRegexMatchAnsiSuffix(); - info.pattern = name; - info.prefix = ansi_prefix; - info.suffix = ansi_suffix; if (symbol->ValueIsAddress()) { DumpAddress( interpreter.GetExecutionContext().GetBestExecutionContextScope(), @@ -1666,7 +1663,8 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter, static void DumpSymbolContextList(ExecutionContextScope *exe_scope, Stream &strm, const SymbolContextList &sc_list, - bool verbose, bool all_ranges) { + bool verbose, bool all_ranges, + std::optional<Information> pattern_info = std::nullopt) { strm.IndentMore(); bool first_module = true; for (const SymbolContext &sc : sc_list) { @@ -1677,7 +1675,10 @@ static void DumpSymbolContextList(ExecutionContextScope *exe_scope, sc.GetAddressRange(eSymbolContextEverything, 0, true, range); - DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm); + if (pattern_info.has_value()) + DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm, pattern_info); + else + DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm); first_module = false; } strm.IndentLess(); @@ -1688,6 +1689,7 @@ static size_t LookupFunctionInModule(CommandInterpreter &interpreter, const char *name, bool name_is_regex, const ModuleFunctionSearchOptions &options, bool verbose, bool all_ranges) { + const bool use_color = interpreter.GetDebugger().GetUseColor(); if (module && name && name[0]) { SymbolContextList sc_list; size_t num_matches = 0; @@ -1701,6 +1703,11 @@ static size_t LookupFunctionInModule(CommandInterpreter &interpreter, } num_matches = sc_list.GetSize(); if (num_matches) { + llvm::StringRef ansi_prefix = + interpreter.GetDebugger().GetRegexMatchAnsiPrefix(); + llvm::StringRef ansi_suffix = + interpreter.GetDebugger().GetRegexMatchAnsiSuffix(); + Information info(name, ansi_prefix, ansi_suffix); strm.Indent(); strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches, num_matches > 1 ? "es" : ""); @@ -1708,7 +1715,8 @@ static size_t LookupFunctionInModule(CommandInterpreter &interpreter, strm.PutCString(":\n"); DumpSymbolContextList( interpreter.GetExecutionContext().GetBestExecutionContextScope(), - strm, sc_list, verbose, all_ranges); + strm, sc_list, verbose, all_ranges, + use_color && name_is_regex ? std::optional<Information>{info} : std::nullopt); } return num_matches; } From d70a8dc31f1e224a3bfcd694244cd350bca4d6ba Mon Sep 17 00:00:00 2001 From: taalhaataahir0102 <23100...@lums.edu.pk> Date: Thu, 14 Dec 2023 13:33:29 +0500 Subject: [PATCH 3/4] Removing unnecessary if conditions --- lldb/source/Commands/CommandObjectTarget.cpp | 23 ++------ lldb/source/Core/Address.cpp | 57 ++++++-------------- lldb/source/Symbol/Symbol.cpp | 10 +--- lldb/source/Symbol/SymbolContext.cpp | 15 ++---- 4 files changed, 25 insertions(+), 80 deletions(-) diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index 0a89014c42912d..e972135658c681 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -1544,22 +1544,14 @@ static void DumpAddress(ExecutionContextScope *exe_scope, strm.Indent(" Summary: "); const uint32_t save_indent = strm.GetIndentLevel(); strm.SetIndentLevel(save_indent + 13); - if (pattern_info.has_value()) - so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription, - Address::DumpStyleInvalid, UINT32_MAX, false, pattern_info); - else - so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription, - Address::DumpStyleInvalid, UINT32_MAX, false); + so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription, + Address::DumpStyleInvalid, UINT32_MAX, false, pattern_info); strm.SetIndentLevel(save_indent); // Print out detailed address information when verbose is enabled if (verbose) { strm.EOL(); - if(pattern_info.has_value()) - so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext, - Address::DumpStyleInvalid, UINT32_MAX, all_ranges, pattern_info); - else - so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext, - Address::DumpStyleInvalid, UINT32_MAX, all_ranges); + so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext, + Address::DumpStyleInvalid, UINT32_MAX, all_ranges, pattern_info); } strm.IndentLess(); } @@ -1672,13 +1664,8 @@ static void DumpSymbolContextList(ExecutionContextScope *exe_scope, strm.EOL(); AddressRange range; - sc.GetAddressRange(eSymbolContextEverything, 0, true, range); - - if (pattern_info.has_value()) - DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm, pattern_info); - else - DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm); + DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm, pattern_info); first_module = false; } strm.IndentLess(); diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp index 740df9dc490f5c..a17d60b329f52c 100644 --- a/lldb/source/Core/Address.cpp +++ b/lldb/source/Core/Address.cpp @@ -524,10 +524,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, ansi_suffix = target->GetDebugger().GetRegexMatchAnsiSuffix(); } - if (pattern_info.has_value()) - s->PutCStringColorHighlighted(symbol_name, pattern_info); - else - s->PutCStringColorHighlighted(symbol_name); + s->PutCStringColorHighlighted(symbol_name, pattern_info); addr_t delta = file_Addr - symbol->GetAddressRef().GetFileAddress(); if (delta) @@ -654,12 +651,8 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, if (pointer_sc.function != nullptr || pointer_sc.symbol != nullptr) { s->PutCString(": "); - if (pattern_info.has_value()) - pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, - false, true, true, pattern_info); - else - pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, - false, true, true); + pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, + false, true, true, pattern_info); } } } @@ -696,38 +689,24 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, if (show_stop_context) { // We have a function or a symbol from the same sections as this // address. - - if (pattern_info.has_value()) - sc.DumpStopContext(s, exe_scope, *this, show_fullpaths, - show_module, show_inlined_frames, - show_function_arguments, show_function_name, - pattern_info); - else - sc.DumpStopContext(s, exe_scope, *this, show_fullpaths, - show_module, show_inlined_frames, - show_function_arguments, show_function_name); + sc.DumpStopContext(s, exe_scope, *this, show_fullpaths, + show_module, show_inlined_frames, + show_function_arguments, show_function_name, + pattern_info); } else { // We found a symbol but it was in a different section so it // isn't the symbol we should be showing, just show the section // name + offset - if (pattern_info.has_value()) - Dump(s, exe_scope, DumpStyleSectionNameOffset, DumpStyleInvalid, - UINT32_MAX, false, pattern_info); - else - Dump(s, exe_scope, DumpStyleSectionNameOffset, DumpStyleInvalid, - UINT32_MAX, false); + Dump(s, exe_scope, DumpStyleSectionNameOffset, DumpStyleInvalid, + UINT32_MAX, false, pattern_info); } } } } } else { if (fallback_style != DumpStyleInvalid) - if (pattern_info.has_value()) - return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, - false, pattern_info); - else - return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, - false); + return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, + false, pattern_info); return false; } break; @@ -748,10 +727,8 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, sc.symbol->GetAddressRef().GetSection() != GetSection()) sc.symbol = nullptr; } - if (pattern_info.has_value()) - sc.GetDescription(s, eDescriptionLevelBrief, target, pattern_info); - else - sc.GetDescription(s, eDescriptionLevelBrief, target); + + sc.GetDescription(s, eDescriptionLevelBrief, target, pattern_info); if (sc.block) { bool can_create = true; @@ -799,12 +776,8 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, } } else { if (fallback_style != DumpStyleInvalid) - if (pattern_info.has_value()) - return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, - false, pattern_info); - else - return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, - false); + return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, + false, pattern_info); return false; } break; diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp index e33577b9256e5e..60763f878b8368 100644 --- a/lldb/source/Symbol/Symbol.cpp +++ b/lldb/source/Symbol/Symbol.cpp @@ -262,18 +262,12 @@ void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level, } if (ConstString demangled = m_mangled.GetDemangledName()) { s->PutCString(", name=\""); - if (pattern_info.has_value()) - s->PutCStringColorHighlighted(demangled.GetStringRef(), pattern_info); - else - s->PutCStringColorHighlighted(demangled.GetStringRef()); + s->PutCStringColorHighlighted(demangled.GetStringRef(), pattern_info); s->PutCString("\""); } if (ConstString mangled_name = m_mangled.GetMangledName()) { s->PutCString(", mangled=\""); - if (pattern_info.has_value()) - s->PutCStringColorHighlighted(mangled_name.GetStringRef(), pattern_info); - else - s->PutCStringColorHighlighted(mangled_name.GetStringRef()); + s->PutCStringColorHighlighted(mangled_name.GetStringRef(), pattern_info); s->PutCString("\""); } } diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp index c00960913bf103..a4620946fa4bd4 100644 --- a/lldb/source/Symbol/SymbolContext.cpp +++ b/lldb/source/Symbol/SymbolContext.cpp @@ -103,10 +103,7 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope, ansi_prefix = target_sp->GetDebugger().GetRegexMatchAnsiPrefix(); ansi_suffix = target_sp->GetDebugger().GetRegexMatchAnsiSuffix(); } - if (pattern_info.has_value()) - s->PutCStringColorHighlighted(name.GetStringRef(), pattern_info); - else - s->PutCStringColorHighlighted(name.GetStringRef()); + s->PutCStringColorHighlighted(name.GetStringRef(), pattern_info); } } @@ -181,10 +178,7 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope, ansi_prefix = target_sp->GetDebugger().GetRegexMatchAnsiPrefix(); ansi_suffix = target_sp->GetDebugger().GetRegexMatchAnsiSuffix(); } - if (pattern_info.has_value()) - s->PutCStringColorHighlighted(symbol->GetName().GetStringRef(), pattern_info); - else - s->PutCStringColorHighlighted(symbol->GetName().GetStringRef()); + s->PutCStringColorHighlighted(symbol->GetName().GetStringRef(), pattern_info); } if (addr.IsValid() && symbol->ValueIsAddress()) { @@ -268,10 +262,7 @@ void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level, if (symbol != nullptr) { s->Indent(" Symbol: "); - if (pattern_info.has_value()) - symbol->GetDescription(s, level, target, pattern_info); - else - symbol->GetDescription(s, level, target); + symbol->GetDescription(s, level, target, pattern_info); s->EOL(); } From 648ec67f79e91ad4baaec40df3f07bf60fe5f8a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20L=2E=20Junior?= <jljunio...@gmail.com> Date: Wed, 20 Dec 2023 19:00:18 -0300 Subject: [PATCH 4/4] apply formatting --- lldb/source/Commands/CommandObjectTarget.cpp | 8 +++++--- lldb/source/Core/Address.cpp | 12 ++++++------ lldb/source/Symbol/SymbolContext.cpp | 3 ++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index e972135658c681..ed2e3fee191b57 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -1545,13 +1545,14 @@ static void DumpAddress(ExecutionContextScope *exe_scope, const uint32_t save_indent = strm.GetIndentLevel(); strm.SetIndentLevel(save_indent + 13); so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription, - Address::DumpStyleInvalid, UINT32_MAX, false, pattern_info); + Address::DumpStyleInvalid, UINT32_MAX, false, pattern_info); 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, pattern_info); + Address::DumpStyleInvalid, UINT32_MAX, all_ranges, + pattern_info); } strm.IndentLess(); } @@ -1665,7 +1666,8 @@ static void DumpSymbolContextList(ExecutionContextScope *exe_scope, AddressRange range; sc.GetAddressRange(eSymbolContextEverything, 0, true, range); - DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm, pattern_info); + DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm, + pattern_info); first_module = false; } strm.IndentLess(); diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp index a17d60b329f52c..fe6ec00ad2b955 100644 --- a/lldb/source/Core/Address.cpp +++ b/lldb/source/Core/Address.cpp @@ -652,7 +652,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, pointer_sc.symbol != nullptr) { s->PutCString(": "); pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, - false, true, true, pattern_info); + false, true, true, pattern_info); } } } @@ -690,15 +690,15 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, // We have a function or a symbol from the same sections as this // address. sc.DumpStopContext(s, exe_scope, *this, show_fullpaths, - show_module, show_inlined_frames, - show_function_arguments, show_function_name, - pattern_info); + show_module, show_inlined_frames, + show_function_arguments, show_function_name, + pattern_info); } else { // We found a symbol but it was in a different section so it // isn't the symbol we should be showing, just show the section // name + offset Dump(s, exe_scope, DumpStyleSectionNameOffset, DumpStyleInvalid, - UINT32_MAX, false, pattern_info); + UINT32_MAX, false, pattern_info); } } } @@ -727,7 +727,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, sc.symbol->GetAddressRef().GetSection() != GetSection()) sc.symbol = nullptr; } - + sc.GetDescription(s, eDescriptionLevelBrief, target, pattern_info); if (sc.block) { diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp index a4620946fa4bd4..10dc266c008487 100644 --- a/lldb/source/Symbol/SymbolContext.cpp +++ b/lldb/source/Symbol/SymbolContext.cpp @@ -178,7 +178,8 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope, ansi_prefix = target_sp->GetDebugger().GetRegexMatchAnsiPrefix(); ansi_suffix = target_sp->GetDebugger().GetRegexMatchAnsiSuffix(); } - s->PutCStringColorHighlighted(symbol->GetName().GetStringRef(), pattern_info); + s->PutCStringColorHighlighted(symbol->GetName().GetStringRef(), + pattern_info); } if (addr.IsValid() && symbol->ValueIsAddress()) { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits