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

via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 26 02:10:59 PDT 2023


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

>From 8e5e67ff640aa0ff14b1a0bd0110b88c539ccfe8 Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100293 at lums.edu.pk>
Date: Wed, 11 Oct 2023 14:27:15 +0500
Subject: [PATCH 1/9] colorization

---
 lldb/include/lldb/Core/Address.h             |   6 +
 lldb/include/lldb/Symbol/Symbol.h            |   3 +
 lldb/include/lldb/Symbol/SymbolContext.h     |  11 +
 lldb/source/Commands/CommandObjectTarget.cpp |  97 ++++-
 lldb/source/Core/Address.cpp                 | 428 +++++++++++++++++++
 lldb/source/Symbol/Symbol.cpp                |  68 +++
 lldb/source/Symbol/SymbolContext.cpp         | 248 +++++++++++
 7 files changed, 859 insertions(+), 2 deletions(-)

diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h
index b19e694427546f8..4151817813c7e35 100644
--- a/lldb/include/lldb/Core/Address.h
+++ b/lldb/include/lldb/Core/Address.h
@@ -249,6 +249,12 @@ class Address {
             uint32_t addr_byte_size = UINT32_MAX,
             bool all_ranges = false) const;
 
+
+  bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,const char* name,
+            DumpStyle fallback_style = DumpStyleInvalid,
+            uint32_t addr_byte_size = UINT32_MAX,
+            bool all_ranges = false) const;
+
   AddressClass GetAddressClass() const;
 
   /// Get the file address.
diff --git a/lldb/include/lldb/Symbol/Symbol.h b/lldb/include/lldb/Symbol/Symbol.h
index 44a2d560010fe40..a9e91fbac055a92 100644
--- a/lldb/include/lldb/Symbol/Symbol.h
+++ b/lldb/include/lldb/Symbol/Symbol.h
@@ -177,6 +177,9 @@ class Symbol : public SymbolContextScope {
   void GetDescription(Stream *s, lldb::DescriptionLevel level,
                       Target *target) const;
 
+  void GetDescription(Stream *s, lldb::DescriptionLevel level,
+                      Target *target, const char* name) const;
+
   bool IsSynthetic() const { return m_is_synthetic; }
 
   bool IsSyntheticWithAutoGeneratedName() const;
diff --git a/lldb/include/lldb/Symbol/SymbolContext.h b/lldb/include/lldb/Symbol/SymbolContext.h
index b0f5ffead2a1656..947c39eec96e53a 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -153,6 +153,14 @@ class SymbolContext {
                        bool show_function_arguments,
                        bool show_function_name) const;
 
+  bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
+                       const Address &so_addr, bool show_fullpaths,
+                       bool show_module, bool show_inlined_frames,
+                       bool show_function_arguments,
+                       bool show_function_name, 
+                       const char* name) const;
+                       
+
   /// Get the address range contained within a symbol context.
   ///
   /// Address range priority is as follows:
@@ -220,6 +228,9 @@ class SymbolContext {
   void GetDescription(Stream *s, lldb::DescriptionLevel level,
                       Target *target) const;
 
+  void GetDescription(Stream *s, lldb::DescriptionLevel level,
+                      Target *target, const char* name) const;
+
   uint32_t GetResolvedMask() const;
 
   lldb::LanguageType GetLanguage() const;
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 33330ef0926d61f..aa59e3680a37872 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1513,6 +1513,98 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
   return false;
 }
 
+//===========================================================================================
+static void PrintRed(Stream &strm, const char *text, const char *name) {
+    const char *red_start = "\033[31m";  // Set text color to red
+    const char *reset_color = "\033[0m";   // Reset text color to default
+
+    // Escape1(ansi.red)
+
+    const char *match = text;
+    size_t name_len = strlen(name);
+    
+    while ((match = strstr(match, name))) {
+        size_t prefix_len = match - text;
+
+        strm.Write(text, prefix_len);
+        strm.PutCString(red_start);
+        strm.Write(match, name_len);
+        strm.PutCString(reset_color);
+        
+        text = match + name_len;
+        match = text;
+    }
+
+    strm.PutCString(text); // Print any remaining text
+}
+
+
+// static void PrintRed(Stream &strm, const char *text, const char *name) {
+//     const char *red_start = "\033[31m";  // Set text color to red
+//     const char *reset_color = "\033[0m";   // Reset text color to default
+
+//     const char *match = text;
+    
+//     // Split the name into parts using the delimiter '|'
+//     std::vector<std::string> name_parts;
+//     const char *delimiter = "|";  // Delimiter for splitting the name
+//     const char *token = strtok(const_cast<char *>(name), delimiter);
+//     while (token) {
+//         name_parts.push_back(token);
+//         token = strtok(nullptr, delimiter);
+//     }
+
+//     // Initialize a variable to keep track of the current position in the text
+//     size_t current_pos = 0;
+
+//     // Iterate through each name part and apply colorization
+//     for (const std::string &part : name_parts) {
+//         match = text + current_pos;
+//         match = strstr(match, part.c_str());
+
+//         if (match) {
+//             size_t prefix_len = match - (text + current_pos);
+//             current_pos += prefix_len;
+            
+//             strm.Write(text + current_pos, prefix_len);
+//             strm.PutCString(red_start);
+//             strm.Write(match, part.length());
+//             strm.PutCString(reset_color);
+
+//             current_pos += part.length();
+//         }
+//     }
+
+//     // Print any remaining text
+//     if (current_pos < strlen(text)) {
+//         strm.PutCString(text + current_pos);
+//     }
+// }
+
+static void DumpAddress(ExecutionContextScope *exe_scope,
+                        const Address &so_addr, bool verbose, bool all_ranges,
+                        Stream &strm, const char *name) {
+  strm.IndentMore();
+  strm.Indent("    Address: ");
+  so_addr.Dump(&strm, exe_scope, Address::DumpStyleModuleWithFileAddress, name);
+  strm.PutCString(" (");
+  so_addr.Dump(&strm, exe_scope, Address::DumpStyleSectionNameOffset, name);
+  strm.PutCString(")\n");
+  strm.Indent("    Summary: ");
+  const uint32_t save_indent = strm.GetIndentLevel();
+  strm.SetIndentLevel(save_indent + 13);
+  so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription, name);
+  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, name,
+                 Address::DumpStyleInvalid, UINT32_MAX, all_ranges);
+  }
+  strm.IndentLess();
+}
+
+//===========================================================================================
 static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
                                      Stream &strm, Module *module,
                                      const char *name, bool name_is_regex,
@@ -1550,12 +1642,13 @@ 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, name);
           strm.EOL();
         } else {
           strm.IndentMore();
           strm.Indent("    Name: ");
-          strm.PutCString(symbol->GetDisplayName().GetStringRef());
+          // strm.PutCString(symbol->GetDisplayName().GetStringRef());
+          PrintRed(strm, symbol->GetDisplayName().GetStringRef().str().c_str(), name);
           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 189d50fe962a651..4a4a9ca01f39e72 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -802,6 +802,434 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
   return true;
 }
 
+
+//==================================================================================
+static void PrintRed(Stream *strm, const char *text, const char *name) {
+    const char *red_start = "\033[31m";  // Set text color to red
+    const char *reset_color = "\033[0m";   // Reset text color to default
+
+    const char *match = text;
+    size_t name_len = strlen(name);
+    
+    while ((match = strstr(match, name))) {
+        size_t prefix_len = match - text;
+
+        strm->Write(text, prefix_len);
+        strm->PutCString(red_start);
+        strm->Write(match, name_len);
+        strm->PutCString(reset_color);
+        
+        text = match + name_len;
+        match = text;
+    }
+
+    strm->PutCString(text); // Print any remaining text
+}
+
+
+bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, const char* name,
+                   DumpStyle fallback_style, uint32_t addr_size,
+                   bool all_ranges) 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());
+  if (!section_sp && style != DumpStyleResolvedPointerDescription)
+    style = DumpStyleLoadAddress;
+
+  ExecutionContext exe_ctx(exe_scope);
+  Target *target = exe_ctx.GetTargetPtr();
+  // If addr_byte_size is UINT32_MAX, then determine the correct address byte
+  // size for the process or default to the size of addr_t
+  if (addr_size == UINT32_MAX) {
+    if (target)
+      addr_size = target->GetArchitecture().GetAddressByteSize();
+    else
+      addr_size = sizeof(addr_t);
+  }
+
+  Address so_addr;
+  switch (style) {
+  case DumpStyleInvalid:
+    return false;
+
+  case DumpStyleSectionNameOffset:
+    if (section_sp) {
+      section_sp->DumpName(s->AsRawOstream());
+      s->Printf(" + %" PRIu64, m_offset);
+    } else {
+      DumpAddress(s->AsRawOstream(), m_offset, addr_size);
+    }
+    break;
+
+  case DumpStyleSectionPointerOffset:
+    s->Printf("(Section *)%p + ", static_cast<void *>(section_sp.get()));
+    DumpAddress(s->AsRawOstream(), m_offset, addr_size);
+    break;
+
+  case DumpStyleModuleWithFileAddress:
+    if (section_sp) {
+      ModuleSP module_sp = section_sp->GetModule();
+      if (module_sp)
+        s->Printf("%s[", module_sp->GetFileSpec().GetFilename().AsCString(
+                             "<Unknown>"));
+      else
+        s->Printf("%s[", "<Unknown>");
+    }
+    [[fallthrough]];
+  case DumpStyleFileAddress: {
+    addr_t file_addr = GetFileAddress();
+    if (file_addr == LLDB_INVALID_ADDRESS) {
+      if (fallback_style != DumpStyleInvalid)
+        return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
+      return false;
+    }
+    DumpAddress(s->AsRawOstream(), file_addr, addr_size);
+    if (style == DumpStyleModuleWithFileAddress && section_sp)
+      s->PutChar(']');
+  } break;
+
+  case DumpStyleLoadAddress: {
+    addr_t load_addr = GetLoadAddress(target);
+
+    /*
+     * MIPS:
+     * Display address in compressed form for MIPS16 or microMIPS
+     * if the address belongs to AddressClass::eCodeAlternateISA.
+    */
+    if (target) {
+      const llvm::Triple::ArchType llvm_arch =
+          target->GetArchitecture().GetMachine();
+      if (llvm_arch == llvm::Triple::mips ||
+          llvm_arch == llvm::Triple::mipsel ||
+          llvm_arch == llvm::Triple::mips64 ||
+          llvm_arch == llvm::Triple::mips64el)
+        load_addr = GetCallableLoadAddress(target);
+    }
+
+    if (load_addr == LLDB_INVALID_ADDRESS) {
+      if (fallback_style != DumpStyleInvalid)
+        return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
+      return false;
+    }
+    DumpAddress(s->AsRawOstream(), load_addr, addr_size);
+  } break;
+
+  case DumpStyleResolvedDescription:
+  case DumpStyleResolvedDescriptionNoModule:
+  case DumpStyleResolvedDescriptionNoFunctionArguments:
+  case DumpStyleNoFunctionName:
+    if (IsSectionOffset()) {
+      uint32_t pointer_size = 4;
+      ModuleSP module_sp(GetModule());
+      if (target)
+        pointer_size = target->GetArchitecture().GetAddressByteSize();
+      else if (module_sp)
+        pointer_size = module_sp->GetArchitecture().GetAddressByteSize();
+
+      bool showed_info = false;
+      if (section_sp) {
+        SectionType sect_type = section_sp->GetType();
+        switch (sect_type) {
+        case eSectionTypeData:
+          if (module_sp) {
+            if (Symtab *symtab = module_sp->GetSymtab()) {
+              const addr_t file_Addr = GetFileAddress();
+              Symbol *symbol =
+                  symtab->FindSymbolContainingFileAddress(file_Addr);
+              if (symbol) {
+                const char *symbol_name = symbol->GetName().AsCString();
+                if (symbol_name) {
+                  // s->printf(symbol_name)
+                  PrintRed(s, symbol_name, name);
+                  addr_t delta =
+                      file_Addr - symbol->GetAddressRef().GetFileAddress();
+                  if (delta)
+                    s->Printf(" + %" PRIu64, delta);
+                  showed_info = true;
+                }
+              }
+            }
+          }
+          break;
+
+        case eSectionTypeDataCString:
+          // Read the C string from memory and display it
+          showed_info = true;
+          ReadCStringFromMemory(exe_scope, *this, s);
+          break;
+
+        case eSectionTypeDataCStringPointers:
+          if (ReadAddress(exe_scope, *this, pointer_size, so_addr)) {
+#if VERBOSE_OUTPUT
+            s->PutCString("(char *)");
+            so_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
+                         DumpStyleFileAddress);
+            s->PutCString(": ");
+#endif
+            showed_info = true;
+            ReadCStringFromMemory(exe_scope, so_addr, s);
+          }
+          break;
+
+        case eSectionTypeDataObjCMessageRefs:
+          if (ReadAddress(exe_scope, *this, pointer_size, so_addr)) {
+            if (target && so_addr.IsSectionOffset()) {
+              SymbolContext func_sc;
+              target->GetImages().ResolveSymbolContextForAddress(
+                  so_addr, eSymbolContextEverything, func_sc);
+              if (func_sc.function != nullptr || func_sc.symbol != nullptr) {
+                showed_info = true;
+#if VERBOSE_OUTPUT
+                s->PutCString("(objc_msgref *) -> { (func*)");
+                so_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
+                             DumpStyleFileAddress);
+#else
+                s->PutCString("{ ");
+#endif
+                Address cstr_addr(*this);
+                cstr_addr.SetOffset(cstr_addr.GetOffset() + pointer_size);
+                func_sc.DumpStopContext(s, exe_scope, so_addr, true, true,
+                                        false, true, true);
+                if (ReadAddress(exe_scope, cstr_addr, pointer_size, so_addr)) {
+#if VERBOSE_OUTPUT
+                  s->PutCString("), (char *)");
+                  so_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
+                               DumpStyleFileAddress);
+                  s->PutCString(" (");
+#else
+                  s->PutCString(", ");
+#endif
+                  ReadCStringFromMemory(exe_scope, so_addr, s);
+                }
+#if VERBOSE_OUTPUT
+                s->PutCString(") }");
+#else
+                s->PutCString(" }");
+#endif
+              }
+            }
+          }
+          break;
+
+        case eSectionTypeDataObjCCFStrings: {
+          Address cfstring_data_addr(*this);
+          cfstring_data_addr.SetOffset(cfstring_data_addr.GetOffset() +
+                                       (2 * pointer_size));
+          if (ReadAddress(exe_scope, cfstring_data_addr, pointer_size,
+                          so_addr)) {
+#if VERBOSE_OUTPUT
+            s->PutCString("(CFString *) ");
+            cfstring_data_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
+                                    DumpStyleFileAddress);
+            s->PutCString(" -> @");
+#else
+            s->PutChar('@');
+#endif
+            if (so_addr.Dump(s, exe_scope, DumpStyleResolvedDescription))
+              showed_info = true;
+          }
+        } break;
+
+        case eSectionTypeData4:
+          // Read the 4 byte data and display it
+          showed_info = true;
+          s->PutCString("(uint32_t) ");
+          DumpUInt(exe_scope, *this, 4, s);
+          break;
+
+        case eSectionTypeData8:
+          // Read the 8 byte data and display it
+          showed_info = true;
+          s->PutCString("(uint64_t) ");
+          DumpUInt(exe_scope, *this, 8, s);
+          break;
+
+        case eSectionTypeData16:
+          // Read the 16 byte data and display it
+          showed_info = true;
+          s->PutCString("(uint128_t) ");
+          DumpUInt(exe_scope, *this, 16, s);
+          break;
+
+        case eSectionTypeDataPointers:
+          // Read the pointer data and display it
+          if (ReadAddress(exe_scope, *this, pointer_size, so_addr)) {
+            s->PutCString("(void *)");
+            so_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
+                         DumpStyleFileAddress);
+
+            showed_info = true;
+            if (so_addr.IsSectionOffset()) {
+              SymbolContext pointer_sc;
+              if (target) {
+                target->GetImages().ResolveSymbolContextForAddress(
+                    so_addr, eSymbolContextEverything, pointer_sc);
+                if (pointer_sc.function != nullptr ||
+                    pointer_sc.symbol != nullptr) {
+                  s->PutCString(": ");
+                  pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false,
+                                             false, true, true, name);
+                }
+              }
+            }
+          }
+          break;
+
+        default:
+          break;
+        }
+      }
+
+      if (!showed_info) {
+        if (module_sp) {
+          SymbolContext sc;
+          module_sp->ResolveSymbolContextForAddress(
+              *this, eSymbolContextEverything, sc);
+          if (sc.function || sc.symbol) {
+            bool show_stop_context = true;
+            const bool show_module = (style == DumpStyleResolvedDescription);
+            const bool show_fullpaths = false;
+            const bool show_inlined_frames = true;
+            const bool show_function_arguments =
+                (style != DumpStyleResolvedDescriptionNoFunctionArguments);
+            const bool show_function_name = (style != DumpStyleNoFunctionName);
+            if (sc.function == nullptr && sc.symbol != nullptr) {
+              // If we have just a symbol make sure it is in the right section
+              if (sc.symbol->ValueIsAddress()) {
+                if (sc.symbol->GetAddressRef().GetSection() != GetSection()) {
+                  // don't show the module if the symbol is a trampoline symbol
+                  show_stop_context = false;
+                }
+              }
+            }
+            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, 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, name);
+            }
+          }
+        }
+      }
+    } else {
+      if (fallback_style != DumpStyleInvalid)
+        return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, name);
+      return false;
+    }
+    break;
+
+  case DumpStyleDetailedSymbolContext:
+    if (IsSectionOffset()) {
+      ModuleSP module_sp(GetModule());
+      if (module_sp) {
+        SymbolContext sc;
+        module_sp->ResolveSymbolContextForAddress(
+            *this, eSymbolContextEverything | eSymbolContextVariable, sc);
+        if (sc.symbol) {
+          // If we have just a symbol make sure it is in the same section as
+          // our address. If it isn't, then we might have just found the last
+          // symbol that came before the address that we are looking up that
+          // has nothing to do with our address lookup.
+          if (sc.symbol->ValueIsAddress() &&
+              sc.symbol->GetAddressRef().GetSection() != GetSection())
+            sc.symbol = nullptr;
+        }
+        sc.GetDescription(s, eDescriptionLevelBrief, target, name);
+
+        if (sc.block) {
+          bool can_create = true;
+          bool get_parent_variables = true;
+          bool stop_if_block_is_inlined_function = false;
+          VariableList variable_list;
+          addr_t file_addr = GetFileAddress();
+          sc.block->AppendVariables(
+              can_create, get_parent_variables,
+              stop_if_block_is_inlined_function,
+              [&](Variable *var) {
+                return var && var->LocationIsValidForAddress(*this);
+              },
+              &variable_list);
+          ABISP abi =
+              ABI::FindPlugin(ProcessSP(), module_sp->GetArchitecture());
+          for (const VariableSP &var_sp : variable_list) {
+            s->Indent();
+            s->Printf("   Variable: id = {0x%8.8" PRIx64 "}, name = \"%s\"",
+                      var_sp->GetID(), var_sp->GetName().GetCString());
+            Type *type = var_sp->GetType();
+            if (type)
+              s->Printf(", type = \"%s\"", type->GetName().GetCString());
+            else
+              s->PutCString(", type = <unknown>");
+            s->PutCString(", valid ranges = ");
+            if (var_sp->GetScopeRange().IsEmpty())
+              s->PutCString("<block>");
+            else if (all_ranges) {
+              for (auto range : var_sp->GetScopeRange())
+                DumpAddressRange(s->AsRawOstream(), range.GetRangeBase(),
+                                 range.GetRangeEnd(), addr_size);
+            } else if (auto *range =
+                           var_sp->GetScopeRange().FindEntryThatContains(
+                               file_addr))
+              DumpAddressRange(s->AsRawOstream(), range->GetRangeBase(),
+                               range->GetRangeEnd(), addr_size);
+            s->PutCString(", location = ");
+            var_sp->DumpLocations(s, all_ranges ? LLDB_INVALID_ADDRESS : *this);
+            s->PutCString(", decl = ");
+            var_sp->GetDeclaration().DumpStopContext(s, false);
+            s->EOL();
+          }
+        }
+      }
+    } else {
+      if (fallback_style != DumpStyleInvalid)
+        return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, name);
+      return false;
+    }
+    break;
+
+  case DumpStyleResolvedPointerDescription: {
+    Process *process = exe_ctx.GetProcessPtr();
+    if (process) {
+      addr_t load_addr = GetLoadAddress(target);
+      if (load_addr != LLDB_INVALID_ADDRESS) {
+        Status memory_error;
+        addr_t dereferenced_load_addr =
+            process->ReadPointerFromMemory(load_addr, memory_error);
+        if (dereferenced_load_addr != LLDB_INVALID_ADDRESS) {
+          Address dereferenced_addr;
+          if (dereferenced_addr.SetLoadAddress(dereferenced_load_addr,
+                                               target)) {
+            StreamString strm;
+            if (dereferenced_addr.Dump(&strm, exe_scope,
+                                       DumpStyleResolvedDescription,
+                                       DumpStyleInvalid, addr_size)) {
+              DumpAddress(s->AsRawOstream(), dereferenced_load_addr, addr_size,
+                          " -> ", " ");
+              s->Write(strm.GetString().data(), strm.GetSize());
+              return true;
+            }
+          }
+        }
+      }
+    }
+    if (fallback_style != DumpStyleInvalid)
+      return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, name);
+    return false;
+  } break;
+  }
+
+  return true;
+}
+
+
+//==================================================================================
+
 bool Address::SectionWasDeleted() const {
   if (GetSection())
     return false;
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index 26b4c4d62ad9c24..c395cbc3e049d13 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -224,6 +224,74 @@ bool Symbol::IsTrampoline() const { return m_type == eSymbolTypeTrampoline; }
 
 bool Symbol::IsIndirect() const { return m_type == eSymbolTypeResolver; }
 
+
+//=======================================================================
+static void PrintRed(Stream *strm, const char *text, const char *name) {
+    const char *red_start = "\033[31m";  // Set text color to red
+    const char *reset_color = "\033[0m";   // Reset text color to default
+
+    const char *match = text;
+    size_t name_len = strlen(name);
+    
+    while ((match = strstr(match, name))) {
+        size_t prefix_len = match - text;
+
+        strm->Write(text, prefix_len);
+        strm->PutCString(red_start);
+        strm->Write(match, name_len);
+        strm->PutCString(reset_color);
+        
+        text = match + name_len;
+        match = text;
+    }
+
+    strm->PutCString(text); // Print any remaining text
+}
+
+void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
+                            Target *target, const char* name) const {
+  s->Printf("id = {0x%8.8x}", m_uid);
+
+  if (m_addr_range.GetBaseAddress().GetSection()) {
+    if (ValueIsAddress()) {
+      const lldb::addr_t byte_size = GetByteSize();
+      if (byte_size > 0) {
+        s->PutCString(", range = ");
+        m_addr_range.Dump(s, target, Address::DumpStyleLoadAddress,
+                          Address::DumpStyleFileAddress);
+      } else {
+        s->PutCString(", address = ");
+        m_addr_range.GetBaseAddress().Dump(s, target,
+                                           Address::DumpStyleLoadAddress,
+                                           Address::DumpStyleFileAddress);
+      }
+    } else
+      s->Printf(", value = 0x%16.16" PRIx64,
+                m_addr_range.GetBaseAddress().GetOffset());
+  } else {
+    if (m_size_is_sibling)
+      s->Printf(", sibling = %5" PRIu64,
+                m_addr_range.GetBaseAddress().GetOffset());
+    else
+      s->Printf(", value = 0x%16.16" PRIx64,
+                m_addr_range.GetBaseAddress().GetOffset());
+  }
+  ConstString demangled = GetMangled().GetDemangledName();
+  if (demangled){
+    // s->Printf(", name=\"%s\"", demangled.AsCString());
+    s->Printf(", name=");
+    PrintRed(s, demangled.AsCString(), name);
+  }
+  if (m_mangled.GetMangledName()){
+    // s->Printf(", mangled=\"%s\"", m_mangled.GetMangledName().AsCString());
+    s->Printf(", mangled=");
+    PrintRed(s, m_mangled.GetMangledName().AsCString(), name);
+  }
+}
+
+//========================================================================
+
+
 void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
                             Target *target) const {
   s->Printf("id = {0x%8.8x}", m_uid);
diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp
index 63968ec2d150670..3a2a25edbdc2d7e 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -185,6 +185,254 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
   return dumped_something;
 }
 
+
+//===========================================================================
+static void PrintRed(Stream *strm, const char *text, const char *name) {
+    const char *red_start = "\033[31m";  // Set text color to red
+    const char *reset_color = "\033[0m";   // Reset text color to default
+
+    const char *match = text;
+    size_t name_len = strlen(name);
+    
+    while ((match = strstr(match, name))) {
+        size_t prefix_len = match - text;
+
+        strm->Write(text, prefix_len);
+        strm->PutCString(red_start);
+        strm->Write(match, name_len);
+        strm->PutCString(reset_color);
+        
+        text = match + name_len;
+        match = text;
+    }
+
+    strm->PutCString(text); // Print any remaining text
+}
+
+bool SymbolContext::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 char* name) const {
+  bool dumped_something = false;
+  if (show_module && module_sp) {
+    if (show_fullpaths)
+      *s << module_sp->GetFileSpec();
+    else
+      *s << module_sp->GetFileSpec().GetFilename();
+    s->PutChar('`');
+    dumped_something = true;
+  }
+
+  if (function != nullptr) {
+    SymbolContext inline_parent_sc;
+    Address inline_parent_addr;
+    if (!show_function_name) {
+      s->Printf("<");
+      dumped_something = true;
+    } else {
+      ConstString name1;
+      if (!show_function_arguments)
+        name1 = function->GetNameNoArguments();
+      if (!name1)
+        name1 = function->GetName();
+      if (name1){
+        // name.Dump(s);
+        PrintRed(s, name1.GetCString() , name);
+      }
+    }
+
+    if (addr.IsValid()) {
+      const addr_t function_offset =
+          addr.GetOffset() -
+          function->GetAddressRange().GetBaseAddress().GetOffset();
+      if (!show_function_name) {
+        // Print +offset even if offset is 0
+        dumped_something = true;
+        s->Printf("+%" PRIu64 ">", function_offset);
+      } else if (function_offset) {
+        dumped_something = true;
+        s->Printf(" + %" PRIu64, function_offset);
+      }
+    }
+
+    if (GetParentOfInlinedScope(addr, inline_parent_sc, inline_parent_addr)) {
+      dumped_something = true;
+      Block *inlined_block = block->GetContainingInlinedBlock();
+      const InlineFunctionInfo *inlined_block_info =
+          inlined_block->GetInlinedFunctionInfo();
+      s->Printf(" [inlined] %s", inlined_block_info->GetName().GetCString());
+
+      lldb_private::AddressRange block_range;
+      if (inlined_block->GetRangeContainingAddress(addr, block_range)) {
+        const addr_t inlined_function_offset =
+            addr.GetOffset() - block_range.GetBaseAddress().GetOffset();
+        if (inlined_function_offset) {
+          s->Printf(" + %" PRIu64, inlined_function_offset);
+        }
+      }
+      // "line_entry" will always be valid as GetParentOfInlinedScope(...) will
+      // fill it in correctly with the calling file and line. Previous code
+      // was extracting the calling file and line from inlined_block_info and
+      // using it right away which is not correct. On the first call to this
+      // function "line_entry" will contain the actual line table entry. On
+      // susequent calls "line_entry" will contain the calling file and line
+      // from the previous inline info.
+      if (line_entry.IsValid()) {
+        s->PutCString(" at ");
+        line_entry.DumpStopContext(s, show_fullpaths);
+      }
+
+      if (show_inlined_frames) {
+        s->EOL();
+        s->Indent();
+        const bool show_function_name = true;
+        return inline_parent_sc.DumpStopContext(
+            s, exe_scope, inline_parent_addr, show_fullpaths, show_module,
+            show_inlined_frames, show_function_arguments, show_function_name);
+      }
+    } else {
+      if (line_entry.IsValid()) {
+        dumped_something = true;
+        s->PutCString(" at ");
+        if (line_entry.DumpStopContext(s, show_fullpaths))
+          dumped_something = true;
+      }
+    }
+  } else if (symbol != nullptr) {
+    if (!show_function_name) {
+      s->Printf("<");
+      dumped_something = true;
+    } else if (symbol->GetName()) {
+      dumped_something = true;
+      if (symbol->GetType() == eSymbolTypeTrampoline)
+        s->PutCString("symbol stub for: ");
+      // symbol->GetName().Dump(s);
+      PrintRed(s, symbol->GetName().GetStringRef().str().c_str(), name);
+    }
+
+    if (addr.IsValid() && symbol->ValueIsAddress()) {
+      const addr_t symbol_offset =
+          addr.GetOffset() - symbol->GetAddressRef().GetOffset();
+      if (!show_function_name) {
+        // Print +offset even if offset is 0
+        dumped_something = true;
+        s->Printf("+%" PRIu64 ">", symbol_offset);
+      } else if (symbol_offset) {
+        dumped_something = true;
+        s->Printf(" + %" PRIu64, symbol_offset);
+      }
+    }
+  } else if (addr.IsValid()) {
+    addr.Dump(s, exe_scope, Address::DumpStyleModuleWithFileAddress);
+    dumped_something = true;
+  }
+  return dumped_something;
+}
+
+
+void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level,
+                                   Target *target, const char* name) const {
+  if (module_sp) {
+    s->Indent("     Module: file = \"");
+    module_sp->GetFileSpec().Dump(s->AsRawOstream());
+    *s << '"';
+    if (module_sp->GetArchitecture().IsValid())
+      s->Printf(", arch = \"%s\"",
+                module_sp->GetArchitecture().GetArchitectureName());
+    s->EOL();
+  }
+
+  if (comp_unit != nullptr) {
+    s->Indent("CompileUnit: ");
+    comp_unit->GetDescription(s, level);
+    s->EOL();
+  }
+
+  if (function != nullptr) {
+    s->Indent("   Function: ");
+    function->GetDescription(s, level, target);
+    s->EOL();
+
+    Type *func_type = function->GetType();
+    if (func_type) {
+      s->Indent("   FuncType: ");
+      func_type->GetDescription(s, level, false, target);
+      s->EOL();
+    }
+  }
+
+  if (block != nullptr) {
+    std::vector<Block *> blocks;
+    blocks.push_back(block);
+    Block *parent_block = block->GetParent();
+
+    while (parent_block) {
+      blocks.push_back(parent_block);
+      parent_block = parent_block->GetParent();
+    }
+    std::vector<Block *>::reverse_iterator pos;
+    std::vector<Block *>::reverse_iterator begin = blocks.rbegin();
+    std::vector<Block *>::reverse_iterator end = blocks.rend();
+    for (pos = begin; pos != end; ++pos) {
+      if (pos == begin)
+        s->Indent("     Blocks: ");
+      else
+        s->Indent("             ");
+      (*pos)->GetDescription(s, function, level, target);
+      s->EOL();
+    }
+  }
+
+  if (line_entry.IsValid()) {
+    s->Indent("  LineEntry: ");
+    line_entry.GetDescription(s, level, comp_unit, target, false);
+    s->EOL();
+  }
+
+  if (symbol != nullptr) {
+    s->Indent("     Symbol: ");
+    symbol->GetDescription(s, level, target, name);
+    s->EOL();
+  }
+
+  if (variable != nullptr) {
+    s->Indent("   Variable: ");
+
+    s->Printf("id = {0x%8.8" PRIx64 "}, ", variable->GetID());
+
+    switch (variable->GetScope()) {
+    case eValueTypeVariableGlobal:
+      s->PutCString("kind = global, ");
+      break;
+
+    case eValueTypeVariableStatic:
+      s->PutCString("kind = static, ");
+      break;
+
+    case eValueTypeVariableArgument:
+      s->PutCString("kind = argument, ");
+      break;
+
+    case eValueTypeVariableLocal:
+      s->PutCString("kind = local, ");
+      break;
+
+    case eValueTypeVariableThreadLocal:
+      s->PutCString("kind = thread local, ");
+      break;
+
+    default:
+      break;
+    }
+
+    s->Printf("name = \"%s\"\n", variable->GetName().GetCString());
+  }
+}
+
+//===========================================================================
+
 void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level,
                                    Target *target) const {
   if (module_sp) {

>From 14cf74105a358a028cd7e935b4304e16d6f901f2 Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100293 at lums.edu.pk>
Date: Mon, 16 Oct 2023 16:15:30 +0500
Subject: [PATCH 2/9] Comments

---
 lldb/source/Commands/CommandObjectTarget.cpp | 53 ++++----------------
 lldb/source/Core/Address.cpp                 |  7 +++
 lldb/source/Symbol/Symbol.cpp                |  3 ++
 lldb/source/Symbol/SymbolContext.cpp         |  1 +
 4 files changed, 21 insertions(+), 43 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index aa59e3680a37872..2b6439ab7b10758 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1514,6 +1514,9 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
 }
 
 //===========================================================================================
+
+// This function will print search the string name in string text and will colorize
+// the name found inside text on the terminal.
 static void PrintRed(Stream &strm, const char *text, const char *name) {
     const char *red_start = "\033[31m";  // Set text color to red
     const char *reset_color = "\033[0m";   // Reset text color to default
@@ -1538,49 +1541,9 @@ static void PrintRed(Stream &strm, const char *text, const char *name) {
     strm.PutCString(text); // Print any remaining text
 }
 
-
-// static void PrintRed(Stream &strm, const char *text, const char *name) {
-//     const char *red_start = "\033[31m";  // Set text color to red
-//     const char *reset_color = "\033[0m";   // Reset text color to default
-
-//     const char *match = text;
-    
-//     // Split the name into parts using the delimiter '|'
-//     std::vector<std::string> name_parts;
-//     const char *delimiter = "|";  // Delimiter for splitting the name
-//     const char *token = strtok(const_cast<char *>(name), delimiter);
-//     while (token) {
-//         name_parts.push_back(token);
-//         token = strtok(nullptr, delimiter);
-//     }
-
-//     // Initialize a variable to keep track of the current position in the text
-//     size_t current_pos = 0;
-
-//     // Iterate through each name part and apply colorization
-//     for (const std::string &part : name_parts) {
-//         match = text + current_pos;
-//         match = strstr(match, part.c_str());
-
-//         if (match) {
-//             size_t prefix_len = match - (text + current_pos);
-//             current_pos += prefix_len;
-            
-//             strm.Write(text + current_pos, prefix_len);
-//             strm.PutCString(red_start);
-//             strm.Write(match, part.length());
-//             strm.PutCString(reset_color);
-
-//             current_pos += part.length();
-//         }
-//     }
-
-//     // Print any remaining text
-//     if (current_pos < strlen(text)) {
-//         strm.PutCString(text + current_pos);
-//     }
-// }
-
+// This function is responsible for printing address and summary of the symbol found.
+// The seached regex symbol is passed to this function as well so that it can be colorized
+// in the summary as well.
 static void DumpAddress(ExecutionContextScope *exe_scope,
                         const Address &so_addr, bool verbose, bool all_ranges,
                         Stream &strm, const char *name) {
@@ -1593,6 +1556,8 @@ static void DumpAddress(ExecutionContextScope *exe_scope,
   strm.Indent("    Summary: ");
   const uint32_t save_indent = strm.GetIndentLevel();
   strm.SetIndentLevel(save_indent + 13);
+  // Using the new dump function for printing the summary where we've also passed
+  // the searched symbol as an argument.
   so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription, name);
   strm.SetIndentLevel(save_indent);
   // Print out detailed address information when verbose is enabled
@@ -1640,6 +1605,7 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
       Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]);
       if (symbol) {
         if (symbol->ValueIsAddress()) {
+          // Using the new dump function to add colors in the summary.
           DumpAddress(
               interpreter.GetExecutionContext().GetBestExecutionContextScope(),
               symbol->GetAddressRef(), verbose, all_ranges, strm, name);
@@ -1648,6 +1614,7 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
           strm.IndentMore();
           strm.Indent("    Name: ");
           // strm.PutCString(symbol->GetDisplayName().GetStringRef());
+          // Using the PrintRed function to colorize the searched symbol.
           PrintRed(strm, symbol->GetDisplayName().GetStringRef().str().c_str(), name);
           strm.EOL();
           strm.Indent("    Value: ");
diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp
index 4a4a9ca01f39e72..3da35a3be311051 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -804,6 +804,10 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 
 
 //==================================================================================
+
+// This function will print search the string name in string text and will colorize
+// the name found inside text on the terminal.
+
 static void PrintRed(Stream *strm, const char *text, const char *name) {
     const char *red_start = "\033[31m";  // Set text color to red
     const char *reset_color = "\033[0m";   // Reset text color to default
@@ -826,6 +830,8 @@ static void PrintRed(Stream *strm, const char *text, const char *name) {
     strm->PutCString(text); // Print any remaining text
 }
 
+// Similar to the DumpAddress function inside CommandObjectTarget.cpp, we've reinitialized this Dump function
+// by passing the searched symbol so that it can be colorized as well in the output stream.
 
 bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, const char* name,
                    DumpStyle fallback_style, uint32_t addr_size,
@@ -940,6 +946,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
                 const char *symbol_name = symbol->GetName().AsCString();
                 if (symbol_name) {
                   // s->printf(symbol_name)
+                  // Using the PrintRed function to colorize the symbol.
                   PrintRed(s, symbol_name, name);
                   addr_t delta =
                       file_Addr - symbol->GetAddressRef().GetFileAddress();
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index c395cbc3e049d13..ac99c63cc4d46ba 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -248,6 +248,9 @@ static void PrintRed(Stream *strm, const char *text, const char *name) {
     strm->PutCString(text); // Print any remaining text
 }
 
+
+// This function is used to display the details of searched symbol i.e., when verbose flag is used.
+// Adding colorization in this dump function as well usin the PrintRed function.
 void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
                             Target *target, const char* name) const {
   s->Printf("id = {0x%8.8x}", m_uid);
diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp
index 3a2a25edbdc2d7e..7c1db5cef75c4d2 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -187,6 +187,7 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
 
 
 //===========================================================================
+// Similar to the previous modules, using PrintRed and new dump function.
 static void PrintRed(Stream *strm, const char *text, const char *name) {
     const char *red_start = "\033[31m";  // Set text color to red
     const char *reset_color = "\033[0m";   // Reset text color to default

>From c387dae46deac35f9a28b90e1a1831c02681b021 Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100293 at lums.edu.pk>
Date: Mon, 16 Oct 2023 17:39:05 +0500
Subject: [PATCH 3/9] new PrintRed with | support

---
 lldb/source/Commands/CommandObjectTarget.cpp | 80 ++++++++++++++++----
 lldb/source/Core/Address.cpp                 | 77 +++++++++++++++----
 lldb/source/Symbol/SymbolContext.cpp         | 72 ++++++++++++++----
 3 files changed, 188 insertions(+), 41 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 2b6439ab7b10758..88905b39dec9f5d 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1515,32 +1515,84 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
 
 //===========================================================================================
 
+#include <iostream>
+#include <sstream>
+#include <vector>
+
+// Function to split the string on "|"
+std::vector<std::string> splitString(const std::string &s, char delimiter) {
+    std::vector<std::string> tokens;
+    std::stringstream ss(s);
+    std::string item;
+
+    while (std::getline(ss, item, delimiter)) {
+        tokens.push_back(item);
+    }
+
+    return tokens;
+}
+
 // This function will print search the string name in string text and will colorize
 // the name found inside text on the terminal.
 static void PrintRed(Stream &strm, const char *text, const char *name) {
     const char *red_start = "\033[31m";  // Set text color to red
     const char *reset_color = "\033[0m";   // Reset text color to default
 
-    // Escape1(ansi.red)
+    std::vector<std::string> parts = splitString(name, '|');
 
-    const char *match = text;
-    size_t name_len = strlen(name);
-    
-    while ((match = strstr(match, name))) {
-        size_t prefix_len = match - text;
+    size_t text_len = strlen(text);
+    size_t current_pos = 0;
 
-        strm.Write(text, prefix_len);
-        strm.PutCString(red_start);
-        strm.Write(match, name_len);
-        strm.PutCString(reset_color);
-        
-        text = match + name_len;
-        match = text;
+    for (const auto &part : parts) {
+        const char *match = text;
+        size_t name_len = part.size();
+
+        while ((match = strstr(match, part.c_str()))) {
+            size_t prefix_len = match - text + current_pos;
+
+            strm.Write(text + current_pos, prefix_len);
+            strm.PutCString(red_start);
+            strm.Write(match, name_len);
+            strm.PutCString(reset_color);
+
+            // Update the current position and the match pointer
+            current_pos = (match - text) + name_len;
+            match += name_len;
+        }
     }
 
-    strm.PutCString(text); // Print any remaining text
+    // Print any remaining text
+    strm.PutCString(text + current_pos);
 }
 
+
+
+// This function will print search the string name in string text and will colorize
+// the name found inside text on the terminal.
+// static void PrintRed(Stream &strm, const char *text, const char *name) {
+//     const char *red_start = "\033[31m";  // Set text color to red
+//     const char *reset_color = "\033[0m";   // Reset text color to default
+
+//     // Escape1(ansi.red)
+
+//     const char *match = text;
+//     size_t name_len = strlen(name);
+    
+//     while ((match = strstr(match, name))) {
+//         size_t prefix_len = match - text;
+
+//         strm.Write(text, prefix_len);
+//         strm.PutCString(red_start);
+//         strm.Write(match, name_len);
+//         strm.PutCString(reset_color);
+        
+//         text = match + name_len;
+//         match = text;
+//     }
+
+//     strm.PutCString(text); // Print any remaining text
+// }
+
 // This function is responsible for printing address and summary of the symbol found.
 // The seached regex symbol is passed to this function as well so that it can be colorized
 // in the summary as well.
diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp
index 3da35a3be311051..611086556c70989 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -805,31 +805,80 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 
 //==================================================================================
 
+#include <iostream>
+#include <sstream>
+#include <vector>
+
+// Function to split the string on "|"
+static std::vector<std::string> splitString(const std::string &s, char delimiter) {
+    std::vector<std::string> tokens;
+    std::stringstream ss(s);
+    std::string item;
+
+    while (std::getline(ss, item, delimiter)) {
+        tokens.push_back(item);
+    }
+
+    return tokens;
+}
+
 // This function will print search the string name in string text and will colorize
 // the name found inside text on the terminal.
-
 static void PrintRed(Stream *strm, const char *text, const char *name) {
     const char *red_start = "\033[31m";  // Set text color to red
     const char *reset_color = "\033[0m";   // Reset text color to default
 
-    const char *match = text;
-    size_t name_len = strlen(name);
-    
-    while ((match = strstr(match, name))) {
-        size_t prefix_len = match - text;
+    std::vector<std::string> parts = splitString(name, '|');
 
-        strm->Write(text, prefix_len);
-        strm->PutCString(red_start);
-        strm->Write(match, name_len);
-        strm->PutCString(reset_color);
-        
-        text = match + name_len;
-        match = text;
+    size_t text_len = strlen(text);
+    size_t current_pos = 0;
+
+    for (const auto &part : parts) {
+        const char *match = text;
+        size_t name_len = part.size();
+
+        while ((match = strstr(match, part.c_str()))) {
+            size_t prefix_len = match - text + current_pos;
+
+            strm->Write(text + current_pos, prefix_len);
+            strm->PutCString(red_start);
+            strm->Write(match, name_len);
+            strm->PutCString(reset_color);
+
+            // Update the current position and the match pointer
+            current_pos = (match - text) + name_len;
+            match += name_len;
+        }
     }
 
-    strm->PutCString(text); // Print any remaining text
+    // Print any remaining text
+    strm->PutCString(text + current_pos);
 }
 
+
+
+// static void PrintRed(Stream *strm, const char *text, const char *name) {
+//     const char *red_start = "\033[31m";  // Set text color to red
+//     const char *reset_color = "\033[0m";   // Reset text color to default
+
+//     const char *match = text;
+//     size_t name_len = strlen(name);
+    
+//     while ((match = strstr(match, name))) {
+//         size_t prefix_len = match - text;
+
+//         strm->Write(text, prefix_len);
+//         strm->PutCString(red_start);
+//         strm->Write(match, name_len);
+//         strm->PutCString(reset_color);
+        
+//         text = match + name_len;
+//         match = text;
+//     }
+
+//     strm->PutCString(text); // Print any remaining text
+// }
+
 // Similar to the DumpAddress function inside CommandObjectTarget.cpp, we've reinitialized this Dump function
 // by passing the searched symbol so that it can be colorized as well in the output stream.
 
diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp
index 7c1db5cef75c4d2..7b9276940be3943 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -187,29 +187,75 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
 
 
 //===========================================================================
+
+#include <sstream>
+// Function to split the string on "|"
+static std::vector<std::string> splitString(const std::string &s, char delimiter) {
+    std::vector<std::string> tokens;
+    std::stringstream ss(s);
+    std::string item;
+
+    while (std::getline(ss, item, delimiter)) {
+        tokens.push_back(item);
+    }
+
+    return tokens;
+}
+
 // Similar to the previous modules, using PrintRed and new dump function.
 static void PrintRed(Stream *strm, const char *text, const char *name) {
     const char *red_start = "\033[31m";  // Set text color to red
     const char *reset_color = "\033[0m";   // Reset text color to default
 
-    const char *match = text;
-    size_t name_len = strlen(name);
-    
-    while ((match = strstr(match, name))) {
-        size_t prefix_len = match - text;
+    std::vector<std::string> parts = splitString(name, '|');
 
-        strm->Write(text, prefix_len);
-        strm->PutCString(red_start);
-        strm->Write(match, name_len);
-        strm->PutCString(reset_color);
-        
-        text = match + name_len;
-        match = text;
+    size_t text_len = strlen(text);
+    size_t current_pos = 0;
+
+    for (const auto &part : parts) {
+        const char *match = text;
+        size_t name_len = part.size();
+
+        while ((match = strstr(match, part.c_str()))) {
+            size_t prefix_len = match - text + current_pos;
+
+            strm->Write(text + current_pos, prefix_len);
+            strm->PutCString(red_start);
+            strm->Write(match, name_len);
+            strm->PutCString(reset_color);
+
+            // Update the current position and the match pointer
+            current_pos = (match - text) + name_len;
+            match += name_len;
+        }
     }
 
-    strm->PutCString(text); // Print any remaining text
+    // Print any remaining text
+    strm->PutCString(text + current_pos);
 }
 
+// static void PrintRed(Stream *strm, const char *text, const char *name) {
+//     const char *red_start = "\033[31m";  // Set text color to red
+//     const char *reset_color = "\033[0m";   // Reset text color to default
+
+//     const char *match = text;
+//     size_t name_len = strlen(name);
+    
+//     while ((match = strstr(match, name))) {
+//         size_t prefix_len = match - text;
+
+//         strm->Write(text, prefix_len);
+//         strm->PutCString(red_start);
+//         strm->Write(match, name_len);
+//         strm->PutCString(reset_color);
+        
+//         text = match + name_len;
+//         match = text;
+//     }
+
+//     strm->PutCString(text); // Print any remaining text
+// }
+
 bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
                                     const Address &addr, bool show_fullpaths,
                                     bool show_module, bool show_inlined_frames,

>From 5fed6763fba7c398c9e9b0a39301489ea6b00374 Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100293 at lums.edu.pk>
Date: Tue, 17 Oct 2023 11:57:28 +0500
Subject: [PATCH 4/9] ANSI Library

---
 lldb/source/Commands/CommandObjectTarget.cpp | 70 +++++++++-----------
 lldb/source/Core/Address.cpp                 | 40 ++---------
 lldb/source/Symbol/Symbol.cpp                | 61 ++++++++++++-----
 lldb/source/Symbol/SymbolContext.cpp         | 34 ++--------
 4 files changed, 87 insertions(+), 118 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 88905b39dec9f5d..c71fd3718475d78 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -63,7 +63,8 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatAdapters.h"
-
+#include "lldb/Utility/AnsiTerminal.h"
+#include <sstream>
 
 using namespace lldb;
 using namespace lldb_private;
@@ -1515,9 +1516,30 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
 
 //===========================================================================================
 
-#include <iostream>
-#include <sstream>
-#include <vector>
+
+// static void PrintRed(Stream &strm, const char *text, const char *name) {
+//     const char *red_start = "\033[31m";  // Set text color to red
+//     const char *reset_color = "\033[0m";   // Reset text color to default
+
+//     // Escape1(ansi.red)
+
+//     const char *match = text;
+//     size_t name_len = strlen(name);
+    
+//     while ((match = strstr(match, name))) {
+//         size_t prefix_len = match - text;
+
+//         strm.Write(text, prefix_len);
+//         strm.PutCString(red_start);
+//         strm.Write(match, name_len);
+//         strm.PutCString(reset_color);
+        
+//         text = match + name_len;
+//         match = text;
+//     }
+
+//     strm.PutCString(text); // Print any remaining text
+// }
 
 // Function to split the string on "|"
 std::vector<std::string> splitString(const std::string &s, char delimiter) {
@@ -1532,15 +1554,14 @@ std::vector<std::string> splitString(const std::string &s, char delimiter) {
     return tokens;
 }
 
-// This function will print search the string name in string text and will colorize
+// This function will search the string name in string text and will colorize
 // the name found inside text on the terminal.
 static void PrintRed(Stream &strm, const char *text, const char *name) {
-    const char *red_start = "\033[31m";  // Set text color to red
-    const char *reset_color = "\033[0m";   // Reset text color to default
+    const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
+    const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_WHITE) + ANSI_ESC_END;
 
     std::vector<std::string> parts = splitString(name, '|');
 
-    size_t text_len = strlen(text);
     size_t current_pos = 0;
 
     for (const auto &part : parts) {
@@ -1551,48 +1572,19 @@ static void PrintRed(Stream &strm, const char *text, const char *name) {
             size_t prefix_len = match - text + current_pos;
 
             strm.Write(text + current_pos, prefix_len);
-            strm.PutCString(red_start);
+            strm.PutCString(red_start.c_str());
             strm.Write(match, name_len);
-            strm.PutCString(reset_color);
+            strm.PutCString(reset_color.c_str());
 
             // Update the current position and the match pointer
             current_pos = (match - text) + name_len;
             match += name_len;
         }
     }
-
     // Print any remaining text
     strm.PutCString(text + current_pos);
 }
 
-
-
-// This function will print search the string name in string text and will colorize
-// the name found inside text on the terminal.
-// static void PrintRed(Stream &strm, const char *text, const char *name) {
-//     const char *red_start = "\033[31m";  // Set text color to red
-//     const char *reset_color = "\033[0m";   // Reset text color to default
-
-//     // Escape1(ansi.red)
-
-//     const char *match = text;
-//     size_t name_len = strlen(name);
-    
-//     while ((match = strstr(match, name))) {
-//         size_t prefix_len = match - text;
-
-//         strm.Write(text, prefix_len);
-//         strm.PutCString(red_start);
-//         strm.Write(match, name_len);
-//         strm.PutCString(reset_color);
-        
-//         text = match + name_len;
-//         match = text;
-//     }
-
-//     strm.PutCString(text); // Print any remaining text
-// }
-
 // This function is responsible for printing address and summary of the symbol found.
 // The seached regex symbol is passed to this function as well so that it can be colorized
 // in the summary as well.
diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp
index 611086556c70989..f6130d993ef2f8c 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -39,6 +39,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/TargetParser/Triple.h"
+#include "lldb/Utility/AnsiTerminal.h"
 
 #include <cstdint>
 #include <memory>
@@ -47,6 +48,7 @@
 #include <cassert>
 #include <cinttypes>
 #include <cstring>
+#include <sstream>
 
 namespace lldb_private {
 class CompileUnit;
@@ -805,10 +807,6 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 
 //==================================================================================
 
-#include <iostream>
-#include <sstream>
-#include <vector>
-
 // Function to split the string on "|"
 static std::vector<std::string> splitString(const std::string &s, char delimiter) {
     std::vector<std::string> tokens;
@@ -822,15 +820,14 @@ static std::vector<std::string> splitString(const std::string &s, char delimiter
     return tokens;
 }
 
-// This function will print search the string name in string text and will colorize
+// This function will search the string name in string text and will colorize
 // the name found inside text on the terminal.
 static void PrintRed(Stream *strm, const char *text, const char *name) {
-    const char *red_start = "\033[31m";  // Set text color to red
-    const char *reset_color = "\033[0m";   // Reset text color to default
+    const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
+    const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_WHITE) + ANSI_ESC_END;
 
     std::vector<std::string> parts = splitString(name, '|');
 
-    size_t text_len = strlen(text);
     size_t current_pos = 0;
 
     for (const auto &part : parts) {
@@ -841,9 +838,9 @@ static void PrintRed(Stream *strm, const char *text, const char *name) {
             size_t prefix_len = match - text + current_pos;
 
             strm->Write(text + current_pos, prefix_len);
-            strm->PutCString(red_start);
+            strm->PutCString(red_start.c_str());
             strm->Write(match, name_len);
-            strm->PutCString(reset_color);
+            strm->PutCString(reset_color.c_str());
 
             // Update the current position and the match pointer
             current_pos = (match - text) + name_len;
@@ -856,29 +853,6 @@ static void PrintRed(Stream *strm, const char *text, const char *name) {
 }
 
 
-
-// static void PrintRed(Stream *strm, const char *text, const char *name) {
-//     const char *red_start = "\033[31m";  // Set text color to red
-//     const char *reset_color = "\033[0m";   // Reset text color to default
-
-//     const char *match = text;
-//     size_t name_len = strlen(name);
-    
-//     while ((match = strstr(match, name))) {
-//         size_t prefix_len = match - text;
-
-//         strm->Write(text, prefix_len);
-//         strm->PutCString(red_start);
-//         strm->Write(match, name_len);
-//         strm->PutCString(reset_color);
-        
-//         text = match + name_len;
-//         match = text;
-//     }
-
-//     strm->PutCString(text); // Print any remaining text
-// }
-
 // Similar to the DumpAddress function inside CommandObjectTarget.cpp, we've reinitialized this Dump function
 // by passing the searched symbol so that it can be colorized as well in the output stream.
 
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index ac99c63cc4d46ba..d959e51929a78b4 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -20,6 +20,8 @@
 #include "lldb/Utility/DataEncoder.h"
 #include "lldb/Utility/Stream.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "lldb/Utility/AnsiTerminal.h"
+#include <sstream>
 
 using namespace lldb;
 using namespace lldb_private;
@@ -226,31 +228,54 @@ bool Symbol::IsIndirect() const { return m_type == eSymbolTypeResolver; }
 
 
 //=======================================================================
+
+// Function to split the string on "|"
+static std::vector<std::string> splitString(const std::string &s, char delimiter) {
+    std::vector<std::string> tokens;
+    std::stringstream ss(s);
+    std::string item;
+
+    while (std::getline(ss, item, delimiter)) {
+        tokens.push_back(item);
+    }
+
+    return tokens;
+}
+
+// Similar to the previous modules, using PrintRed and new dump function.
 static void PrintRed(Stream *strm, const char *text, const char *name) {
-    const char *red_start = "\033[31m";  // Set text color to red
-    const char *reset_color = "\033[0m";   // Reset text color to default
-
-    const char *match = text;
-    size_t name_len = strlen(name);
-    
-    while ((match = strstr(match, name))) {
-        size_t prefix_len = match - text;
-
-        strm->Write(text, prefix_len);
-        strm->PutCString(red_start);
-        strm->Write(match, name_len);
-        strm->PutCString(reset_color);
-        
-        text = match + name_len;
-        match = text;
+    const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
+    const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_WHITE) + ANSI_ESC_END;
+
+    std::vector<std::string> parts = splitString(name, '|');
+
+    size_t current_pos = 0;
+
+    for (const auto &part : parts) {
+        const char *match = text;
+        size_t name_len = part.size();
+
+        while ((match = strstr(match, part.c_str()))) {
+            size_t prefix_len = match - text + current_pos;
+
+            strm->Write(text + current_pos, prefix_len);
+            strm->PutCString(red_start.c_str());
+            strm->Write(match, name_len);
+            strm->PutCString(reset_color.c_str());
+
+            // Update the current position and the match pointer
+            current_pos = (match - text) + name_len;
+            match += name_len;
+        }
     }
 
-    strm->PutCString(text); // Print any remaining text
+    // Print any remaining text
+    strm->PutCString(text + current_pos);
 }
 
 
 // This function is used to display the details of searched symbol i.e., when verbose flag is used.
-// Adding colorization in this dump function as well usin the PrintRed function.
+// Adding colorization in this dump function as well using the PrintRed function.
 void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
                             Target *target, const char* name) const {
   s->Printf("id = {0x%8.8x}", m_uid);
diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp
index 7b9276940be3943..6f976e69d86636d 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -25,6 +25,8 @@
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/StreamString.h"
 #include "lldb/lldb-enumerations.h"
+#include "lldb/Utility/AnsiTerminal.h"
+#include <sstream>
 
 using namespace lldb;
 using namespace lldb_private;
@@ -188,7 +190,6 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
 
 //===========================================================================
 
-#include <sstream>
 // Function to split the string on "|"
 static std::vector<std::string> splitString(const std::string &s, char delimiter) {
     std::vector<std::string> tokens;
@@ -204,12 +205,11 @@ static std::vector<std::string> splitString(const std::string &s, char delimiter
 
 // Similar to the previous modules, using PrintRed and new dump function.
 static void PrintRed(Stream *strm, const char *text, const char *name) {
-    const char *red_start = "\033[31m";  // Set text color to red
-    const char *reset_color = "\033[0m";   // Reset text color to default
+    const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
+    const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_WHITE) + ANSI_ESC_END;
 
     std::vector<std::string> parts = splitString(name, '|');
 
-    size_t text_len = strlen(text);
     size_t current_pos = 0;
 
     for (const auto &part : parts) {
@@ -220,9 +220,9 @@ static void PrintRed(Stream *strm, const char *text, const char *name) {
             size_t prefix_len = match - text + current_pos;
 
             strm->Write(text + current_pos, prefix_len);
-            strm->PutCString(red_start);
+            strm->PutCString(red_start.c_str());
             strm->Write(match, name_len);
-            strm->PutCString(reset_color);
+            strm->PutCString(reset_color.c_str());
 
             // Update the current position and the match pointer
             current_pos = (match - text) + name_len;
@@ -234,28 +234,6 @@ static void PrintRed(Stream *strm, const char *text, const char *name) {
     strm->PutCString(text + current_pos);
 }
 
-// static void PrintRed(Stream *strm, const char *text, const char *name) {
-//     const char *red_start = "\033[31m";  // Set text color to red
-//     const char *reset_color = "\033[0m";   // Reset text color to default
-
-//     const char *match = text;
-//     size_t name_len = strlen(name);
-    
-//     while ((match = strstr(match, name))) {
-//         size_t prefix_len = match - text;
-
-//         strm->Write(text, prefix_len);
-//         strm->PutCString(red_start);
-//         strm->Write(match, name_len);
-//         strm->PutCString(reset_color);
-        
-//         text = match + name_len;
-//         match = text;
-//     }
-
-//     strm->PutCString(text); // Print any remaining text
-// }
-
 bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
                                     const Address &addr, bool show_fullpaths,
                                     bool show_module, bool show_inlined_frames,

>From 884a1fec5a29880dcc8b49c482f44cbb6994d6ed Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100293 at lums.edu.pk>
Date: Tue, 17 Oct 2023 14:16:54 +0500
Subject: [PATCH 5/9] PrintRed updated

---
 lldb/source/Commands/CommandObjectTarget.cpp | 30 +++++++++++---------
 lldb/source/Core/Address.cpp                 | 29 ++++++++++---------
 lldb/source/Symbol/Symbol.cpp                | 29 ++++++++++---------
 lldb/source/Symbol/SymbolContext.cpp         | 29 ++++++++++---------
 4 files changed, 61 insertions(+), 56 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index c71fd3718475d78..6ab614268e3af5f 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1558,29 +1558,31 @@ std::vector<std::string> splitString(const std::string &s, char delimiter) {
 // the name found inside text on the terminal.
 static void PrintRed(Stream &strm, const char *text, const char *name) {
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
-    const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_WHITE) + ANSI_ESC_END;
+    const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
 
     std::vector<std::string> parts = splitString(name, '|');
 
     size_t current_pos = 0;
+    size_t text_len = strlen(text);
 
     for (const auto &part : parts) {
-        const char *match = text;
         size_t name_len = part.size();
-
-        while ((match = strstr(match, part.c_str()))) {
-            size_t prefix_len = match - text + current_pos;
-
-            strm.Write(text + current_pos, prefix_len);
-            strm.PutCString(red_start.c_str());
-            strm.Write(match, name_len);
-            strm.PutCString(reset_color.c_str());
-
-            // Update the current position and the match pointer
-            current_pos = (match - text) + name_len;
-            match += name_len;
+        size_t i = 0;
+
+        while (i <= text_len - name_len) {
+            if (strncmp(text + i, part.c_str(), name_len) == 0) {
+                strm.Write(text + current_pos, i - current_pos);
+                strm.PutCString(red_start.c_str());
+                strm.Write(text + i, name_len);
+                strm.PutCString(reset_color.c_str());
+                i += name_len;
+                current_pos = i;
+            } else {
+                i++;
+            }
         }
     }
+
     // Print any remaining text
     strm.PutCString(text + current_pos);
 }
diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp
index f6130d993ef2f8c..d0923e915becda2 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -824,27 +824,28 @@ static std::vector<std::string> splitString(const std::string &s, char delimiter
 // the name found inside text on the terminal.
 static void PrintRed(Stream *strm, const char *text, const char *name) {
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
-    const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_WHITE) + ANSI_ESC_END;
+    const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
 
     std::vector<std::string> parts = splitString(name, '|');
 
     size_t current_pos = 0;
+    size_t text_len = strlen(text);
 
     for (const auto &part : parts) {
-        const char *match = text;
         size_t name_len = part.size();
-
-        while ((match = strstr(match, part.c_str()))) {
-            size_t prefix_len = match - text + current_pos;
-
-            strm->Write(text + current_pos, prefix_len);
-            strm->PutCString(red_start.c_str());
-            strm->Write(match, name_len);
-            strm->PutCString(reset_color.c_str());
-
-            // Update the current position and the match pointer
-            current_pos = (match - text) + name_len;
-            match += name_len;
+        size_t i = 0;
+
+        while (i <= text_len - name_len) {
+            if (strncmp(text + i, part.c_str(), name_len) == 0) {
+                strm->Write(text + current_pos, i - current_pos);
+                strm->PutCString(red_start.c_str());
+                strm->Write(text + i, name_len);
+                strm->PutCString(reset_color.c_str());
+                i += name_len;
+                current_pos = i;
+            } else {
+                i++;
+            }
         }
     }
 
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index d959e51929a78b4..a16cb6d9c1ac363 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -245,27 +245,28 @@ static std::vector<std::string> splitString(const std::string &s, char delimiter
 // Similar to the previous modules, using PrintRed and new dump function.
 static void PrintRed(Stream *strm, const char *text, const char *name) {
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
-    const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_WHITE) + ANSI_ESC_END;
+    const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
 
     std::vector<std::string> parts = splitString(name, '|');
 
     size_t current_pos = 0;
+    size_t text_len = strlen(text);
 
     for (const auto &part : parts) {
-        const char *match = text;
         size_t name_len = part.size();
-
-        while ((match = strstr(match, part.c_str()))) {
-            size_t prefix_len = match - text + current_pos;
-
-            strm->Write(text + current_pos, prefix_len);
-            strm->PutCString(red_start.c_str());
-            strm->Write(match, name_len);
-            strm->PutCString(reset_color.c_str());
-
-            // Update the current position and the match pointer
-            current_pos = (match - text) + name_len;
-            match += name_len;
+        size_t i = 0;
+
+        while (i <= text_len - name_len) {
+            if (strncmp(text + i, part.c_str(), name_len) == 0) {
+                strm->Write(text + current_pos, i - current_pos);
+                strm->PutCString(red_start.c_str());
+                strm->Write(text + i, name_len);
+                strm->PutCString(reset_color.c_str());
+                i += name_len;
+                current_pos = i;
+            } else {
+                i++;
+            }
         }
     }
 
diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp
index 6f976e69d86636d..68323f26d7bcd7b 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -206,27 +206,28 @@ static std::vector<std::string> splitString(const std::string &s, char delimiter
 // Similar to the previous modules, using PrintRed and new dump function.
 static void PrintRed(Stream *strm, const char *text, const char *name) {
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
-    const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_WHITE) + ANSI_ESC_END;
+    const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
 
     std::vector<std::string> parts = splitString(name, '|');
 
     size_t current_pos = 0;
+    size_t text_len = strlen(text);
 
     for (const auto &part : parts) {
-        const char *match = text;
         size_t name_len = part.size();
-
-        while ((match = strstr(match, part.c_str()))) {
-            size_t prefix_len = match - text + current_pos;
-
-            strm->Write(text + current_pos, prefix_len);
-            strm->PutCString(red_start.c_str());
-            strm->Write(match, name_len);
-            strm->PutCString(reset_color.c_str());
-
-            // Update the current position and the match pointer
-            current_pos = (match - text) + name_len;
-            match += name_len;
+        size_t i = 0;
+
+        while (i <= text_len - name_len) {
+            if (strncmp(text + i, part.c_str(), name_len) == 0) {
+                strm->Write(text + current_pos, i - current_pos);
+                strm->PutCString(red_start.c_str());
+                strm->Write(text + i, name_len);
+                strm->PutCString(reset_color.c_str());
+                i += name_len;
+                current_pos = i;
+            } else {
+                i++;
+            }
         }
     }
 

>From 07e3a614c1a346c3a09dbf232328b83b744750b2 Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100293 at lums.edu.pk>
Date: Wed, 18 Oct 2023 11:26:26 +0500
Subject: [PATCH 6/9] Final

---
 lldb/source/Commands/CommandObjectTarget.cpp | 76 ++++----------------
 lldb/source/Core/Address.cpp                 | 53 ++++----------
 lldb/source/Symbol/Symbol.cpp                | 51 ++++---------
 lldb/source/Symbol/SymbolContext.cpp         | 51 ++++---------
 4 files changed, 59 insertions(+), 172 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 6ab614268e3af5f..8086474a32a9abd 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1516,75 +1516,27 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
 
 //===========================================================================================
 
-
-// static void PrintRed(Stream &strm, const char *text, const char *name) {
-//     const char *red_start = "\033[31m";  // Set text color to red
-//     const char *reset_color = "\033[0m";   // Reset text color to default
-
-//     // Escape1(ansi.red)
-
-//     const char *match = text;
-//     size_t name_len = strlen(name);
-    
-//     while ((match = strstr(match, name))) {
-//         size_t prefix_len = match - text;
-
-//         strm.Write(text, prefix_len);
-//         strm.PutCString(red_start);
-//         strm.Write(match, name_len);
-//         strm.PutCString(reset_color);
-        
-//         text = match + name_len;
-//         match = text;
-//     }
-
-//     strm.PutCString(text); // Print any remaining text
-// }
-
-// Function to split the string on "|"
-std::vector<std::string> splitString(const std::string &s, char delimiter) {
-    std::vector<std::string> tokens;
-    std::stringstream ss(s);
-    std::string item;
-
-    while (std::getline(ss, item, delimiter)) {
-        tokens.push_back(item);
-    }
-
-    return tokens;
-}
-
-// This function will search the string name in string text and will colorize
-// the name found inside text on the terminal.
+// This function is the one which colorizes the regex symbol searched
 static void PrintRed(Stream &strm, const char *text, const char *name) {
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
     const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
 
-    std::vector<std::string> parts = splitString(name, '|');
-
-    size_t current_pos = 0;
-    size_t text_len = strlen(text);
-
-    for (const auto &part : parts) {
-        size_t name_len = part.size();
-        size_t i = 0;
+    const char *match = text;
+    size_t name_len = strlen(name);
+    
+    while ((match = strstr(match, name))) {
+        size_t prefix_len = match - text;
 
-        while (i <= text_len - name_len) {
-            if (strncmp(text + i, part.c_str(), name_len) == 0) {
-                strm.Write(text + current_pos, i - current_pos);
-                strm.PutCString(red_start.c_str());
-                strm.Write(text + i, name_len);
-                strm.PutCString(reset_color.c_str());
-                i += name_len;
-                current_pos = i;
-            } else {
-                i++;
-            }
-        }
+        strm.Write(text, prefix_len);
+        strm.PutCString(red_start.c_str());
+        strm.Write(match, name_len);
+        strm.PutCString(reset_color.c_str());
+        
+        text = match + name_len;
+        match = text;
     }
 
-    // Print any remaining text
-    strm.PutCString(text + current_pos);
+    strm.PutCString(text); // Print any remaining text
 }
 
 // This function is responsible for printing address and summary of the symbol found.
diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp
index d0923e915becda2..86f37ac5d7f51fe 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -807,53 +807,30 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
 
 //==================================================================================
 
-// Function to split the string on "|"
-static std::vector<std::string> splitString(const std::string &s, char delimiter) {
-    std::vector<std::string> tokens;
-    std::stringstream ss(s);
-    std::string item;
-
-    while (std::getline(ss, item, delimiter)) {
-        tokens.push_back(item);
-    }
-
-    return tokens;
-}
+// Function to print the searched symbol in red color
 
-// This function will search the string name in string text and will colorize
-// the name found inside text on the terminal.
 static void PrintRed(Stream *strm, const char *text, const char *name) {
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
     const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
 
-    std::vector<std::string> parts = splitString(name, '|');
-
-    size_t current_pos = 0;
-    size_t text_len = strlen(text);
-
-    for (const auto &part : parts) {
-        size_t name_len = part.size();
-        size_t i = 0;
-
-        while (i <= text_len - name_len) {
-            if (strncmp(text + i, part.c_str(), name_len) == 0) {
-                strm->Write(text + current_pos, i - current_pos);
-                strm->PutCString(red_start.c_str());
-                strm->Write(text + i, name_len);
-                strm->PutCString(reset_color.c_str());
-                i += name_len;
-                current_pos = i;
-            } else {
-                i++;
-            }
-        }
+    const char *match = text;
+    size_t name_len = strlen(name);
+    
+    while ((match = strstr(match, name))) {
+        size_t prefix_len = match - text;
+
+        strm->Write(text, prefix_len);
+        strm->PutCString(red_start.c_str());
+        strm->Write(match, name_len);
+        strm->PutCString(reset_color.c_str());
+        
+        text = match + name_len;
+        match = text;
     }
 
-    // Print any remaining text
-    strm->PutCString(text + current_pos);
+    strm->PutCString(text); // Print any remaining text
 }
 
-
 // Similar to the DumpAddress function inside CommandObjectTarget.cpp, we've reinitialized this Dump function
 // by passing the searched symbol so that it can be colorized as well in the output stream.
 
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index a16cb6d9c1ac363..ad07426192bb13f 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -229,49 +229,28 @@ bool Symbol::IsIndirect() const { return m_type == eSymbolTypeResolver; }
 
 //=======================================================================
 
-// Function to split the string on "|"
-static std::vector<std::string> splitString(const std::string &s, char delimiter) {
-    std::vector<std::string> tokens;
-    std::stringstream ss(s);
-    std::string item;
-
-    while (std::getline(ss, item, delimiter)) {
-        tokens.push_back(item);
-    }
-
-    return tokens;
-}
+// Similar to the other modules, using PrintRed and new dump function.
 
-// Similar to the previous modules, using PrintRed and new dump function.
 static void PrintRed(Stream *strm, const char *text, const char *name) {
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
     const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
 
-    std::vector<std::string> parts = splitString(name, '|');
-
-    size_t current_pos = 0;
-    size_t text_len = strlen(text);
-
-    for (const auto &part : parts) {
-        size_t name_len = part.size();
-        size_t i = 0;
-
-        while (i <= text_len - name_len) {
-            if (strncmp(text + i, part.c_str(), name_len) == 0) {
-                strm->Write(text + current_pos, i - current_pos);
-                strm->PutCString(red_start.c_str());
-                strm->Write(text + i, name_len);
-                strm->PutCString(reset_color.c_str());
-                i += name_len;
-                current_pos = i;
-            } else {
-                i++;
-            }
-        }
+    const char *match = text;
+    size_t name_len = strlen(name);
+    
+    while ((match = strstr(match, name))) {
+        size_t prefix_len = match - text;
+
+        strm->Write(text, prefix_len);
+        strm->PutCString(red_start.c_str());
+        strm->Write(match, name_len);
+        strm->PutCString(reset_color.c_str());
+        
+        text = match + name_len;
+        match = text;
     }
 
-    // Print any remaining text
-    strm->PutCString(text + current_pos);
+    strm->PutCString(text); // Print any remaining text
 }
 
 
diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp
index 68323f26d7bcd7b..084d7a4659ccd19 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -190,49 +190,28 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
 
 //===========================================================================
 
-// Function to split the string on "|"
-static std::vector<std::string> splitString(const std::string &s, char delimiter) {
-    std::vector<std::string> tokens;
-    std::stringstream ss(s);
-    std::string item;
-
-    while (std::getline(ss, item, delimiter)) {
-        tokens.push_back(item);
-    }
-
-    return tokens;
-}
+// Similar to the other modules, using PrintRed and new dump function.
 
-// Similar to the previous modules, using PrintRed and new dump function.
 static void PrintRed(Stream *strm, const char *text, const char *name) {
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
     const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
 
-    std::vector<std::string> parts = splitString(name, '|');
-
-    size_t current_pos = 0;
-    size_t text_len = strlen(text);
-
-    for (const auto &part : parts) {
-        size_t name_len = part.size();
-        size_t i = 0;
-
-        while (i <= text_len - name_len) {
-            if (strncmp(text + i, part.c_str(), name_len) == 0) {
-                strm->Write(text + current_pos, i - current_pos);
-                strm->PutCString(red_start.c_str());
-                strm->Write(text + i, name_len);
-                strm->PutCString(reset_color.c_str());
-                i += name_len;
-                current_pos = i;
-            } else {
-                i++;
-            }
-        }
+    const char *match = text;
+    size_t name_len = strlen(name);
+    
+    while ((match = strstr(match, name))) {
+        size_t prefix_len = match - text;
+
+        strm->Write(text, prefix_len);
+        strm->PutCString(red_start.c_str());
+        strm->Write(match, name_len);
+        strm->PutCString(reset_color.c_str());
+        
+        text = match + name_len;
+        match = text;
     }
 
-    // Print any remaining text
-    strm->PutCString(text + current_pos);
+    strm->PutCString(text); // Print any remaining text
 }
 
 bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,

>From 52695ab3ae608377582453bd5d2da77e7fe10dee Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100293 at lums.edu.pk>
Date: Mon, 23 Oct 2023 11:03:07 +0500
Subject: [PATCH 7/9] Updated existing dump functions

---
 lldb/include/lldb/Core/Address.h             |  11 +-
 lldb/include/lldb/Symbol/Symbol.h            |   9 +-
 lldb/include/lldb/Symbol/SymbolContext.h     |  10 +-
 lldb/source/Commands/CommandObjectTarget.cpp |  44 +-
 lldb/source/Core/Address.cpp                 | 476 +++----------------
 lldb/source/Symbol/Symbol.cpp                |  59 +--
 lldb/source/Symbol/SymbolContext.cpp         | 155 +-----
 7 files changed, 117 insertions(+), 647 deletions(-)

diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h
index 4151817813c7e35..16ea2037afb0e4a 100644
--- a/lldb/include/lldb/Core/Address.h
+++ b/lldb/include/lldb/Core/Address.h
@@ -247,13 +247,14 @@ 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) const;
+            bool all_ranges = false,
+            const char* name = nullptr) const;
 
 
-  bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,const char* name,
-            DumpStyle fallback_style = DumpStyleInvalid,
-            uint32_t addr_byte_size = UINT32_MAX,
-            bool all_ranges = false) const;
+  // bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,const char* name,
+  //           DumpStyle fallback_style = DumpStyleInvalid,
+  //           uint32_t addr_byte_size = UINT32_MAX,
+  //           bool all_ranges = false) const;
 
   AddressClass GetAddressClass() const;
 
diff --git a/lldb/include/lldb/Symbol/Symbol.h b/lldb/include/lldb/Symbol/Symbol.h
index a9e91fbac055a92..0084aec8b67a7ea 100644
--- a/lldb/include/lldb/Symbol/Symbol.h
+++ b/lldb/include/lldb/Symbol/Symbol.h
@@ -174,11 +174,14 @@ 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;
 
+  // Updated the GetDescription function. It takes a null string as an argument.
+  // This argument is the regex symbol searched.
   void GetDescription(Stream *s, lldb::DescriptionLevel level,
-                      Target *target, const char* name) const;
+                      Target *target,
+                      const char *name = 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 947c39eec96e53a..07800341e200e05 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -147,18 +147,14 @@ class SymbolContext {
   ///
   /// \return
   ///     \b true if some text was dumped, \b false otherwise.
-  bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
-                       const Address &so_addr, bool show_fullpaths,
-                       bool show_module, bool show_inlined_frames,
-                       bool show_function_arguments,
-                       bool show_function_name) const;
 
+  // Passing Null pointer as a default value of char* name (which stores the searched symbol)
   bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
                        const Address &so_addr, bool show_fullpaths,
                        bool show_module, bool show_inlined_frames,
                        bool show_function_arguments,
-                       bool show_function_name, 
-                       const char* name) const;
+                       bool show_function_name,
+                       const char* name = nullptr) const;
                        
 
   /// Get the address range contained within a symbol context.
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 8086474a32a9abd..29cacbc54d2881a 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1463,9 +1463,13 @@ static bool DumpModuleSymbolFile(Stream &strm, Module *module) {
   return false;
 }
 
+// This function is responsible for printing address and summary of the symbol found.
+// The seached regex symbol is passed to this function as well so that it can be colorized
+// in the summary as well.
+
 static void DumpAddress(ExecutionContextScope *exe_scope,
                         const Address &so_addr, bool verbose, bool all_ranges,
-                        Stream &strm) {
+                        Stream &strm, const char *name) {
   strm.IndentMore();
   strm.Indent("    Address: ");
   so_addr.Dump(&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
@@ -1475,13 +1479,15 @@ 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);
+  // Using the new dump function for printing the summary where we've also passed
+  // the searched symbol as an argument.
+  so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription, Address::DumpStyleInvalid, UINT32_MAX, false, name);
   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, name);
   }
   strm.IndentLess();
 }
@@ -1507,7 +1513,7 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
 
     ExecutionContextScope *exe_scope =
         interpreter.GetExecutionContext().GetBestExecutionContextScope();
-    DumpAddress(exe_scope, so_addr, verbose, all_ranges, strm);
+    DumpAddress(exe_scope, so_addr, verbose, all_ranges, strm, nullptr);
     return true;
   }
 
@@ -1539,34 +1545,6 @@ static void PrintRed(Stream &strm, const char *text, const char *name) {
     strm.PutCString(text); // Print any remaining text
 }
 
-// This function is responsible for printing address and summary of the symbol found.
-// The seached regex symbol is passed to this function as well so that it can be colorized
-// in the summary as well.
-static void DumpAddress(ExecutionContextScope *exe_scope,
-                        const Address &so_addr, bool verbose, bool all_ranges,
-                        Stream &strm, const char *name) {
-  strm.IndentMore();
-  strm.Indent("    Address: ");
-  so_addr.Dump(&strm, exe_scope, Address::DumpStyleModuleWithFileAddress, name);
-  strm.PutCString(" (");
-  so_addr.Dump(&strm, exe_scope, Address::DumpStyleSectionNameOffset, name);
-  strm.PutCString(")\n");
-  strm.Indent("    Summary: ");
-  const uint32_t save_indent = strm.GetIndentLevel();
-  strm.SetIndentLevel(save_indent + 13);
-  // Using the new dump function for printing the summary where we've also passed
-  // the searched symbol as an argument.
-  so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription, name);
-  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, name,
-                 Address::DumpStyleInvalid, UINT32_MAX, all_ranges);
-  }
-  strm.IndentLess();
-}
-
 //===========================================================================================
 static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
                                      Stream &strm, Module *module,
@@ -1644,7 +1622,7 @@ static void DumpSymbolContextList(ExecutionContextScope *exe_scope,
 
     sc.GetAddressRange(eSymbolContextEverything, 0, true, range);
 
-    DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm);
+    DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm, nullptr);
     first_module = false;
   }
   strm.IndentLess();
diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp
index 86f37ac5d7f51fe..504fb0c6e132e88 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -405,410 +405,9 @@ bool Address::GetDescription(Stream &s, Target &target,
   return false;
 }
 
-bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
-                   DumpStyle fallback_style, uint32_t addr_size,
-                   bool all_ranges) 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());
-  if (!section_sp && style != DumpStyleResolvedPointerDescription)
-    style = DumpStyleLoadAddress;
-
-  ExecutionContext exe_ctx(exe_scope);
-  Target *target = exe_ctx.GetTargetPtr();
-  // If addr_byte_size is UINT32_MAX, then determine the correct address byte
-  // size for the process or default to the size of addr_t
-  if (addr_size == UINT32_MAX) {
-    if (target)
-      addr_size = target->GetArchitecture().GetAddressByteSize();
-    else
-      addr_size = sizeof(addr_t);
-  }
-
-  Address so_addr;
-  switch (style) {
-  case DumpStyleInvalid:
-    return false;
-
-  case DumpStyleSectionNameOffset:
-    if (section_sp) {
-      section_sp->DumpName(s->AsRawOstream());
-      s->Printf(" + %" PRIu64, m_offset);
-    } else {
-      DumpAddress(s->AsRawOstream(), m_offset, addr_size);
-    }
-    break;
-
-  case DumpStyleSectionPointerOffset:
-    s->Printf("(Section *)%p + ", static_cast<void *>(section_sp.get()));
-    DumpAddress(s->AsRawOstream(), m_offset, addr_size);
-    break;
-
-  case DumpStyleModuleWithFileAddress:
-    if (section_sp) {
-      ModuleSP module_sp = section_sp->GetModule();
-      if (module_sp)
-        s->Printf("%s[", module_sp->GetFileSpec().GetFilename().AsCString(
-                             "<Unknown>"));
-      else
-        s->Printf("%s[", "<Unknown>");
-    }
-    [[fallthrough]];
-  case DumpStyleFileAddress: {
-    addr_t file_addr = GetFileAddress();
-    if (file_addr == LLDB_INVALID_ADDRESS) {
-      if (fallback_style != DumpStyleInvalid)
-        return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
-      return false;
-    }
-    DumpAddress(s->AsRawOstream(), file_addr, addr_size);
-    if (style == DumpStyleModuleWithFileAddress && section_sp)
-      s->PutChar(']');
-  } break;
-
-  case DumpStyleLoadAddress: {
-    addr_t load_addr = GetLoadAddress(target);
-
-    /*
-     * MIPS:
-     * Display address in compressed form for MIPS16 or microMIPS
-     * if the address belongs to AddressClass::eCodeAlternateISA.
-    */
-    if (target) {
-      const llvm::Triple::ArchType llvm_arch =
-          target->GetArchitecture().GetMachine();
-      if (llvm_arch == llvm::Triple::mips ||
-          llvm_arch == llvm::Triple::mipsel ||
-          llvm_arch == llvm::Triple::mips64 ||
-          llvm_arch == llvm::Triple::mips64el)
-        load_addr = GetCallableLoadAddress(target);
-    }
-
-    if (load_addr == LLDB_INVALID_ADDRESS) {
-      if (fallback_style != DumpStyleInvalid)
-        return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
-      return false;
-    }
-    DumpAddress(s->AsRawOstream(), load_addr, addr_size);
-  } break;
-
-  case DumpStyleResolvedDescription:
-  case DumpStyleResolvedDescriptionNoModule:
-  case DumpStyleResolvedDescriptionNoFunctionArguments:
-  case DumpStyleNoFunctionName:
-    if (IsSectionOffset()) {
-      uint32_t pointer_size = 4;
-      ModuleSP module_sp(GetModule());
-      if (target)
-        pointer_size = target->GetArchitecture().GetAddressByteSize();
-      else if (module_sp)
-        pointer_size = module_sp->GetArchitecture().GetAddressByteSize();
-
-      bool showed_info = false;
-      if (section_sp) {
-        SectionType sect_type = section_sp->GetType();
-        switch (sect_type) {
-        case eSectionTypeData:
-          if (module_sp) {
-            if (Symtab *symtab = module_sp->GetSymtab()) {
-              const addr_t file_Addr = GetFileAddress();
-              Symbol *symbol =
-                  symtab->FindSymbolContainingFileAddress(file_Addr);
-              if (symbol) {
-                const char *symbol_name = symbol->GetName().AsCString();
-                if (symbol_name) {
-                  s->PutCString(symbol_name);
-                  addr_t delta =
-                      file_Addr - symbol->GetAddressRef().GetFileAddress();
-                  if (delta)
-                    s->Printf(" + %" PRIu64, delta);
-                  showed_info = true;
-                }
-              }
-            }
-          }
-          break;
-
-        case eSectionTypeDataCString:
-          // Read the C string from memory and display it
-          showed_info = true;
-          ReadCStringFromMemory(exe_scope, *this, s);
-          break;
-
-        case eSectionTypeDataCStringPointers:
-          if (ReadAddress(exe_scope, *this, pointer_size, so_addr)) {
-#if VERBOSE_OUTPUT
-            s->PutCString("(char *)");
-            so_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
-                         DumpStyleFileAddress);
-            s->PutCString(": ");
-#endif
-            showed_info = true;
-            ReadCStringFromMemory(exe_scope, so_addr, s);
-          }
-          break;
-
-        case eSectionTypeDataObjCMessageRefs:
-          if (ReadAddress(exe_scope, *this, pointer_size, so_addr)) {
-            if (target && so_addr.IsSectionOffset()) {
-              SymbolContext func_sc;
-              target->GetImages().ResolveSymbolContextForAddress(
-                  so_addr, eSymbolContextEverything, func_sc);
-              if (func_sc.function != nullptr || func_sc.symbol != nullptr) {
-                showed_info = true;
-#if VERBOSE_OUTPUT
-                s->PutCString("(objc_msgref *) -> { (func*)");
-                so_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
-                             DumpStyleFileAddress);
-#else
-                s->PutCString("{ ");
-#endif
-                Address cstr_addr(*this);
-                cstr_addr.SetOffset(cstr_addr.GetOffset() + pointer_size);
-                func_sc.DumpStopContext(s, exe_scope, so_addr, true, true,
-                                        false, true, true);
-                if (ReadAddress(exe_scope, cstr_addr, pointer_size, so_addr)) {
-#if VERBOSE_OUTPUT
-                  s->PutCString("), (char *)");
-                  so_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
-                               DumpStyleFileAddress);
-                  s->PutCString(" (");
-#else
-                  s->PutCString(", ");
-#endif
-                  ReadCStringFromMemory(exe_scope, so_addr, s);
-                }
-#if VERBOSE_OUTPUT
-                s->PutCString(") }");
-#else
-                s->PutCString(" }");
-#endif
-              }
-            }
-          }
-          break;
-
-        case eSectionTypeDataObjCCFStrings: {
-          Address cfstring_data_addr(*this);
-          cfstring_data_addr.SetOffset(cfstring_data_addr.GetOffset() +
-                                       (2 * pointer_size));
-          if (ReadAddress(exe_scope, cfstring_data_addr, pointer_size,
-                          so_addr)) {
-#if VERBOSE_OUTPUT
-            s->PutCString("(CFString *) ");
-            cfstring_data_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
-                                    DumpStyleFileAddress);
-            s->PutCString(" -> @");
-#else
-            s->PutChar('@');
-#endif
-            if (so_addr.Dump(s, exe_scope, DumpStyleResolvedDescription))
-              showed_info = true;
-          }
-        } break;
-
-        case eSectionTypeData4:
-          // Read the 4 byte data and display it
-          showed_info = true;
-          s->PutCString("(uint32_t) ");
-          DumpUInt(exe_scope, *this, 4, s);
-          break;
-
-        case eSectionTypeData8:
-          // Read the 8 byte data and display it
-          showed_info = true;
-          s->PutCString("(uint64_t) ");
-          DumpUInt(exe_scope, *this, 8, s);
-          break;
-
-        case eSectionTypeData16:
-          // Read the 16 byte data and display it
-          showed_info = true;
-          s->PutCString("(uint128_t) ");
-          DumpUInt(exe_scope, *this, 16, s);
-          break;
-
-        case eSectionTypeDataPointers:
-          // Read the pointer data and display it
-          if (ReadAddress(exe_scope, *this, pointer_size, so_addr)) {
-            s->PutCString("(void *)");
-            so_addr.Dump(s, exe_scope, DumpStyleLoadAddress,
-                         DumpStyleFileAddress);
-
-            showed_info = true;
-            if (so_addr.IsSectionOffset()) {
-              SymbolContext pointer_sc;
-              if (target) {
-                target->GetImages().ResolveSymbolContextForAddress(
-                    so_addr, eSymbolContextEverything, pointer_sc);
-                if (pointer_sc.function != nullptr ||
-                    pointer_sc.symbol != nullptr) {
-                  s->PutCString(": ");
-                  pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false,
-                                             false, true, true);
-                }
-              }
-            }
-          }
-          break;
-
-        default:
-          break;
-        }
-      }
-
-      if (!showed_info) {
-        if (module_sp) {
-          SymbolContext sc;
-          module_sp->ResolveSymbolContextForAddress(
-              *this, eSymbolContextEverything, sc);
-          if (sc.function || sc.symbol) {
-            bool show_stop_context = true;
-            const bool show_module = (style == DumpStyleResolvedDescription);
-            const bool show_fullpaths = false;
-            const bool show_inlined_frames = true;
-            const bool show_function_arguments =
-                (style != DumpStyleResolvedDescriptionNoFunctionArguments);
-            const bool show_function_name = (style != DumpStyleNoFunctionName);
-            if (sc.function == nullptr && sc.symbol != nullptr) {
-              // If we have just a symbol make sure it is in the right section
-              if (sc.symbol->ValueIsAddress()) {
-                if (sc.symbol->GetAddressRef().GetSection() != GetSection()) {
-                  // don't show the module if the symbol is a trampoline symbol
-                  show_stop_context = false;
-                }
-              }
-            }
-            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);
-            } 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);
-            }
-          }
-        }
-      }
-    } else {
-      if (fallback_style != DumpStyleInvalid)
-        return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
-      return false;
-    }
-    break;
-
-  case DumpStyleDetailedSymbolContext:
-    if (IsSectionOffset()) {
-      ModuleSP module_sp(GetModule());
-      if (module_sp) {
-        SymbolContext sc;
-        module_sp->ResolveSymbolContextForAddress(
-            *this, eSymbolContextEverything | eSymbolContextVariable, sc);
-        if (sc.symbol) {
-          // If we have just a symbol make sure it is in the same section as
-          // our address. If it isn't, then we might have just found the last
-          // symbol that came before the address that we are looking up that
-          // has nothing to do with our address lookup.
-          if (sc.symbol->ValueIsAddress() &&
-              sc.symbol->GetAddressRef().GetSection() != GetSection())
-            sc.symbol = nullptr;
-        }
-        sc.GetDescription(s, eDescriptionLevelBrief, target);
-
-        if (sc.block) {
-          bool can_create = true;
-          bool get_parent_variables = true;
-          bool stop_if_block_is_inlined_function = false;
-          VariableList variable_list;
-          addr_t file_addr = GetFileAddress();
-          sc.block->AppendVariables(
-              can_create, get_parent_variables,
-              stop_if_block_is_inlined_function,
-              [&](Variable *var) {
-                return var && var->LocationIsValidForAddress(*this);
-              },
-              &variable_list);
-          ABISP abi =
-              ABI::FindPlugin(ProcessSP(), module_sp->GetArchitecture());
-          for (const VariableSP &var_sp : variable_list) {
-            s->Indent();
-            s->Printf("   Variable: id = {0x%8.8" PRIx64 "}, name = \"%s\"",
-                      var_sp->GetID(), var_sp->GetName().GetCString());
-            Type *type = var_sp->GetType();
-            if (type)
-              s->Printf(", type = \"%s\"", type->GetName().GetCString());
-            else
-              s->PutCString(", type = <unknown>");
-            s->PutCString(", valid ranges = ");
-            if (var_sp->GetScopeRange().IsEmpty())
-              s->PutCString("<block>");
-            else if (all_ranges) {
-              for (auto range : var_sp->GetScopeRange())
-                DumpAddressRange(s->AsRawOstream(), range.GetRangeBase(),
-                                 range.GetRangeEnd(), addr_size);
-            } else if (auto *range =
-                           var_sp->GetScopeRange().FindEntryThatContains(
-                               file_addr))
-              DumpAddressRange(s->AsRawOstream(), range->GetRangeBase(),
-                               range->GetRangeEnd(), addr_size);
-            s->PutCString(", location = ");
-            var_sp->DumpLocations(s, all_ranges ? LLDB_INVALID_ADDRESS : *this);
-            s->PutCString(", decl = ");
-            var_sp->GetDeclaration().DumpStopContext(s, false);
-            s->EOL();
-          }
-        }
-      }
-    } else {
-      if (fallback_style != DumpStyleInvalid)
-        return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
-      return false;
-    }
-    break;
-
-  case DumpStyleResolvedPointerDescription: {
-    Process *process = exe_ctx.GetProcessPtr();
-    if (process) {
-      addr_t load_addr = GetLoadAddress(target);
-      if (load_addr != LLDB_INVALID_ADDRESS) {
-        Status memory_error;
-        addr_t dereferenced_load_addr =
-            process->ReadPointerFromMemory(load_addr, memory_error);
-        if (dereferenced_load_addr != LLDB_INVALID_ADDRESS) {
-          Address dereferenced_addr;
-          if (dereferenced_addr.SetLoadAddress(dereferenced_load_addr,
-                                               target)) {
-            StreamString strm;
-            if (dereferenced_addr.Dump(&strm, exe_scope,
-                                       DumpStyleResolvedDescription,
-                                       DumpStyleInvalid, addr_size)) {
-              DumpAddress(s->AsRawOstream(), dereferenced_load_addr, addr_size,
-                          " -> ", " ");
-              s->Write(strm.GetString().data(), strm.GetSize());
-              return true;
-            }
-          }
-        }
-      }
-    }
-    if (fallback_style != DumpStyleInvalid)
-      return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
-    return false;
-  } break;
-  }
-
-  return true;
-}
-
-
 //==================================================================================
 
 // Function to print the searched symbol in red color
-
 static void PrintRed(Stream *strm, const char *text, const char *name) {
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
     const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
@@ -830,13 +429,15 @@ static void PrintRed(Stream *strm, const char *text, const char *name) {
 
     strm->PutCString(text); // Print any remaining text
 }
+//==================================================================================
 
-// Similar to the DumpAddress function inside CommandObjectTarget.cpp, we've reinitialized this Dump function
-// by passing the searched symbol so that it can be colorized as well in the output stream.
+// Similar to the DumpAddress function inside CommandObjectTarget.cpp, we've updated this Dump function
+// by passing the searched symbol so that it can be colorized as well in the output stream. In the header
+// file, nullprt is passed as a default argument for const char* name.
 
-bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, const char* name,
+bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
                    DumpStyle fallback_style, uint32_t addr_size,
-                   bool all_ranges) const {
+                   bool all_ranges, const char* name) 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());
@@ -946,9 +547,13 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
               if (symbol) {
                 const char *symbol_name = symbol->GetName().AsCString();
                 if (symbol_name) {
-                  // s->printf(symbol_name)
-                  // Using the PrintRed function to colorize the symbol.
-                  PrintRed(s, symbol_name, name);
+                  // Using the PrintRed function to colorize the symbol if name not equal to nullptr
+                  if(name){
+                    PrintRed(s, symbol_name, name);
+                  }
+                  else{
+                    s->PutCString(symbol_name);
+                  }
                   addr_t delta =
                       file_Addr - symbol->GetAddressRef().GetFileAddress();
                   if (delta)
@@ -1075,8 +680,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,
+                  if(name)
+                    pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false,
                                              false, true, true, name);
+                  else
+                    pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false,
+                                             false, true, true);
                 }
               }
             }
@@ -1113,21 +722,33 @@ 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, name);
+              // Using the same logic, hecking if searched symbol passed to this function or if it using the defualt nullptr
+              if(name)
+                sc.DumpStopContext(s, exe_scope, *this, show_fullpaths,
+                                  show_module, show_inlined_frames,
+                                  show_function_arguments, show_function_name, name);
+              else
+                sc.DumpStopContext(s, exe_scope, *this, show_fullpaths,
+                                  show_module, show_inlined_frames,
+                                  show_function_arguments, show_function_name, 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, name);
+              if(name)
+                Dump(s, exe_scope, DumpStyleSectionNameOffset, DumpStyleInvalid, UINT32_MAX, false, name);
+              else
+                Dump(s, exe_scope, DumpStyleSectionNameOffset);
             }
           }
         }
       }
     } else {
-      if (fallback_style != DumpStyleInvalid)
-        return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, name);
+      if (fallback_style != DumpStyleInvalid && !name)
+        return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
+      else if(fallback_style != DumpStyleInvalid && name){
+        return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, name);
+      }
       return false;
     }
     break;
@@ -1148,7 +769,14 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
               sc.symbol->GetAddressRef().GetSection() != GetSection())
             sc.symbol = nullptr;
         }
-        sc.GetDescription(s, eDescriptionLevelBrief, target, name);
+        if(name){
+          // printf("Here bro\n");
+          sc.GetDescription(s, eDescriptionLevelBrief, target, name);
+        }
+        else{
+          // printf("Here\n")
+          sc.GetDescription(s, eDescriptionLevelBrief, target);
+        }
 
         if (sc.block) {
           bool can_create = true;
@@ -1195,8 +823,11 @@ 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, name);
+      if (fallback_style != DumpStyleInvalid && !name)
+        return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
+      else if(fallback_style != DumpStyleInvalid && name){
+        return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, name);
+      }
       return false;
     }
     break;
@@ -1226,8 +857,10 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
         }
       }
     }
-    if (fallback_style != DumpStyleInvalid)
-      return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, name);
+    if (fallback_style != DumpStyleInvalid && !name)
+      return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
+    else if(fallback_style != DumpStyleInvalid && name)
+      return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, name);
     return false;
   } break;
   }
@@ -1235,9 +868,6 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
   return true;
 }
 
-
-//==================================================================================
-
 bool Address::SectionWasDeleted() const {
   if (GetSection())
     return false;
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index ad07426192bb13f..eef3545685b1f19 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -229,7 +229,7 @@ bool Symbol::IsIndirect() const { return m_type == eSymbolTypeResolver; }
 
 //=======================================================================
 
-// Similar to the other modules, using PrintRed and new dump function.
+// Similar to the other modules, using PrintRed function.
 
 static void PrintRed(Stream *strm, const char *text, const char *name) {
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
@@ -253,11 +253,13 @@ static void PrintRed(Stream *strm, const char *text, const char *name) {
     strm->PutCString(text); // Print any remaining text
 }
 
+//========================================================================
+
+// For the image lookup command, This function is called when verbose flag 
+// is passed to print addition iformation of the symbol
 
-// This function is used to display the details of searched symbol i.e., when verbose flag is used.
-// Adding colorization in this dump function as well using the PrintRed function.
 void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
-                            Target *target, const char* name) const {
+                            Target *target, const char *name) const {
   s->Printf("id = {0x%8.8x}", m_uid);
 
   if (m_addr_range.GetBaseAddress().GetSection()) {
@@ -285,53 +287,20 @@ void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
                 m_addr_range.GetBaseAddress().GetOffset());
   }
   ConstString demangled = GetMangled().GetDemangledName();
-  if (demangled){
-    // s->Printf(", name=\"%s\"", demangled.AsCString());
+
+  // Checking if the name (i.e., searched symbol is passed as an argument to the function)
+  // In that case, we use the PrintRed function to colorize the symbol.
+  if (demangled && name){
     s->Printf(", name=");
     PrintRed(s, demangled.AsCString(), name);
   }
-  if (m_mangled.GetMangledName()){
-    // s->Printf(", mangled=\"%s\"", m_mangled.GetMangledName().AsCString());
+  else if(demangled && name == nullptr)
+    s->Printf(", name=\"%s\"", demangled.AsCString());
+  if (m_mangled.GetMangledName() && name){
     s->Printf(", mangled=");
     PrintRed(s, m_mangled.GetMangledName().AsCString(), name);
   }
-}
-
-//========================================================================
-
-
-void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
-                            Target *target) const {
-  s->Printf("id = {0x%8.8x}", m_uid);
-
-  if (m_addr_range.GetBaseAddress().GetSection()) {
-    if (ValueIsAddress()) {
-      const lldb::addr_t byte_size = GetByteSize();
-      if (byte_size > 0) {
-        s->PutCString(", range = ");
-        m_addr_range.Dump(s, target, Address::DumpStyleLoadAddress,
-                          Address::DumpStyleFileAddress);
-      } else {
-        s->PutCString(", address = ");
-        m_addr_range.GetBaseAddress().Dump(s, target,
-                                           Address::DumpStyleLoadAddress,
-                                           Address::DumpStyleFileAddress);
-      }
-    } else
-      s->Printf(", value = 0x%16.16" PRIx64,
-                m_addr_range.GetBaseAddress().GetOffset());
-  } else {
-    if (m_size_is_sibling)
-      s->Printf(", sibling = %5" PRIu64,
-                m_addr_range.GetBaseAddress().GetOffset());
-    else
-      s->Printf(", value = 0x%16.16" PRIx64,
-                m_addr_range.GetBaseAddress().GetOffset());
-  }
-  ConstString demangled = GetMangled().GetDemangledName();
-  if (demangled)
-    s->Printf(", name=\"%s\"", demangled.AsCString());
-  if (m_mangled.GetMangledName())
+  else if(m_mangled.GetMangledName() && name == nullptr)
     s->Printf(", mangled=\"%s\"", m_mangled.GetMangledName().AsCString());
 }
 
diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp
index 084d7a4659ccd19..97c288ad6dbcfde 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -69,128 +69,9 @@ void SymbolContext::Clear(bool clear_target) {
   variable = nullptr;
 }
 
-bool SymbolContext::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 dumped_something = false;
-  if (show_module && module_sp) {
-    if (show_fullpaths)
-      *s << module_sp->GetFileSpec();
-    else
-      *s << module_sp->GetFileSpec().GetFilename();
-    s->PutChar('`');
-    dumped_something = true;
-  }
-
-  if (function != nullptr) {
-    SymbolContext inline_parent_sc;
-    Address inline_parent_addr;
-    if (!show_function_name) {
-      s->Printf("<");
-      dumped_something = true;
-    } else {
-      ConstString name;
-      if (!show_function_arguments)
-        name = function->GetNameNoArguments();
-      if (!name)
-        name = function->GetName();
-      if (name)
-        name.Dump(s);
-    }
-
-    if (addr.IsValid()) {
-      const addr_t function_offset =
-          addr.GetOffset() -
-          function->GetAddressRange().GetBaseAddress().GetOffset();
-      if (!show_function_name) {
-        // Print +offset even if offset is 0
-        dumped_something = true;
-        s->Printf("+%" PRIu64 ">", function_offset);
-      } else if (function_offset) {
-        dumped_something = true;
-        s->Printf(" + %" PRIu64, function_offset);
-      }
-    }
-
-    if (GetParentOfInlinedScope(addr, inline_parent_sc, inline_parent_addr)) {
-      dumped_something = true;
-      Block *inlined_block = block->GetContainingInlinedBlock();
-      const InlineFunctionInfo *inlined_block_info =
-          inlined_block->GetInlinedFunctionInfo();
-      s->Printf(" [inlined] %s", inlined_block_info->GetName().GetCString());
-
-      lldb_private::AddressRange block_range;
-      if (inlined_block->GetRangeContainingAddress(addr, block_range)) {
-        const addr_t inlined_function_offset =
-            addr.GetOffset() - block_range.GetBaseAddress().GetOffset();
-        if (inlined_function_offset) {
-          s->Printf(" + %" PRIu64, inlined_function_offset);
-        }
-      }
-      // "line_entry" will always be valid as GetParentOfInlinedScope(...) will
-      // fill it in correctly with the calling file and line. Previous code
-      // was extracting the calling file and line from inlined_block_info and
-      // using it right away which is not correct. On the first call to this
-      // function "line_entry" will contain the actual line table entry. On
-      // susequent calls "line_entry" will contain the calling file and line
-      // from the previous inline info.
-      if (line_entry.IsValid()) {
-        s->PutCString(" at ");
-        line_entry.DumpStopContext(s, show_fullpaths);
-      }
-
-      if (show_inlined_frames) {
-        s->EOL();
-        s->Indent();
-        const bool show_function_name = true;
-        return inline_parent_sc.DumpStopContext(
-            s, exe_scope, inline_parent_addr, show_fullpaths, show_module,
-            show_inlined_frames, show_function_arguments, show_function_name);
-      }
-    } else {
-      if (line_entry.IsValid()) {
-        dumped_something = true;
-        s->PutCString(" at ");
-        if (line_entry.DumpStopContext(s, show_fullpaths))
-          dumped_something = true;
-      }
-    }
-  } else if (symbol != nullptr) {
-    if (!show_function_name) {
-      s->Printf("<");
-      dumped_something = true;
-    } else if (symbol->GetName()) {
-      dumped_something = true;
-      if (symbol->GetType() == eSymbolTypeTrampoline)
-        s->PutCString("symbol stub for: ");
-      symbol->GetName().Dump(s);
-    }
-
-    if (addr.IsValid() && symbol->ValueIsAddress()) {
-      const addr_t symbol_offset =
-          addr.GetOffset() - symbol->GetAddressRef().GetOffset();
-      if (!show_function_name) {
-        // Print +offset even if offset is 0
-        dumped_something = true;
-        s->Printf("+%" PRIu64 ">", symbol_offset);
-      } else if (symbol_offset) {
-        dumped_something = true;
-        s->Printf(" + %" PRIu64, symbol_offset);
-      }
-    }
-  } else if (addr.IsValid()) {
-    addr.Dump(s, exe_scope, Address::DumpStyleModuleWithFileAddress);
-    dumped_something = true;
-  }
-  return dumped_something;
-}
-
-
 //===========================================================================
 
-// Similar to the other modules, using PrintRed and new dump function.
+// Similar to the other modules, using PrintRed function.
 
 static void PrintRed(Stream *strm, const char *text, const char *name) {
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
@@ -214,6 +95,8 @@ static void PrintRed(Stream *strm, const char *text, const char *name) {
     strm->PutCString(text); // Print any remaining text
 }
 
+//===========================================================================
+
 bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
                                     const Address &addr, bool show_fullpaths,
                                     bool show_module, bool show_inlined_frames,
@@ -237,14 +120,16 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
       s->Printf("<");
       dumped_something = true;
     } else {
-      ConstString name1;
+      ConstString name_func;
       if (!show_function_arguments)
-        name1 = function->GetNameNoArguments();
-      if (!name1)
-        name1 = function->GetName();
-      if (name1){
-        // name.Dump(s);
-        PrintRed(s, name1.GetCString() , name);
+        name_func = function->GetNameNoArguments();
+      if (!name_func)
+        name_func = function->GetName();
+      // Using PrintRed function if regex searched symbol (i.e., char* name) is passed to this function
+      if (name_func && !name)
+        name_func.Dump(s);
+      else if(name_func && name){
+        PrintRed(s, name_func.GetCString() , name);
       }
     }
 
@@ -313,8 +198,13 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
       dumped_something = true;
       if (symbol->GetType() == eSymbolTypeTrampoline)
         s->PutCString("symbol stub for: ");
-      // symbol->GetName().Dump(s);
-      PrintRed(s, symbol->GetName().GetStringRef().str().c_str(), name);
+
+      // Similar here, Using PrintRed if the function is called by regex symbol search command
+      if(name){
+        PrintRed(s, symbol->GetName().GetStringRef().str().c_str(), name);
+      }
+      else
+      symbol->GetName().Dump(s);
     }
 
     if (addr.IsValid() && symbol->ValueIsAddress()) {
@@ -336,7 +226,6 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
   return dumped_something;
 }
 
-
 void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level,
                                    Target *target, const char* name) const {
   if (module_sp) {
@@ -398,7 +287,11 @@ void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level,
 
   if (symbol != nullptr) {
     s->Indent("     Symbol: ");
-    symbol->GetDescription(s, level, target, name);
+    // Passing name to the symbol Description (-v flag) function if name != nullptr
+    if(name)
+      symbol->GetDescription(s, level, target, name);
+    else
+      symbol->GetDescription(s, level, target);
     s->EOL();
   }
 

>From e5861a3486798e96bdf68bbfb8432bd67440f8f0 Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100293 at lums.edu.pk>
Date: Mon, 23 Oct 2023 11:12:49 +0500
Subject: [PATCH 8/9] Updated existing dump functions (minor updates)

---
 lldb/source/Core/Address.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp
index 504fb0c6e132e88..5e44d0ce106ad03 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -730,7 +730,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
               else
                 sc.DumpStopContext(s, exe_scope, *this, show_fullpaths,
                                   show_module, show_inlined_frames,
-                                  show_function_arguments, show_function_name, name);
+                                  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

>From 1970b40bc3c38600ae821c553275e45951724933 Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100293 at lums.edu.pk>
Date: Thu, 26 Oct 2023 14:10:14 +0500
Subject: [PATCH 9/9] TestCases and feedback incorporated

---
 lldb/include/lldb/Interpreter/CommandObject.h |   1 +
 lldb/include/lldb/Symbol/SymbolContext.h      |   4 +-
 lldb/source/Commands/CommandObjectTarget.cpp  |   6 +-
 lldb/source/Core/Address.cpp                  |  30 ++---
 lldb/source/Symbol/Symbol.cpp                 |   4 +
 lldb/source/Symbol/SymbolContext.cpp          | 111 +-----------------
 .../Shell/Commands/TestImageLookupColor.test  |  23 ++++
 .../command-target-modules-lookup.test        |   2 +
 8 files changed, 51 insertions(+), 130 deletions(-)
 create mode 100644 lldb/test/Shell/Commands/TestImageLookupColor.test

diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h
index d8358435a483bab..ccb76a6a1aafb75 100644
--- a/lldb/include/lldb/Interpreter/CommandObject.h
+++ b/lldb/include/lldb/Interpreter/CommandObject.h
@@ -325,6 +325,7 @@ class CommandObject : public std::enable_shared_from_this<CommandObject> {
   }
 
   virtual const char *GetInvalidProcessDescription() {
+    printf("Reached here\n");
     return "Command requires a current process.";
   }
 
diff --git a/lldb/include/lldb/Symbol/SymbolContext.h b/lldb/include/lldb/Symbol/SymbolContext.h
index 07800341e200e05..e7d14fa2a91bbe3 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -221,11 +221,9 @@ class SymbolContext {
   ///     The symbol that was found, or \b nullptr if none was found.
   const Symbol *FindBestGlobalDataSymbol(ConstString name, Status &error);
 
-  void GetDescription(Stream *s, lldb::DescriptionLevel level,
-                      Target *target) const;
 
   void GetDescription(Stream *s, lldb::DescriptionLevel level,
-                      Target *target, const char* name) const;
+                      Target *target, const char* name=nullptr) const;
 
   uint32_t GetResolvedMask() const;
 
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 29cacbc54d2881a..5e865c2030c55bf 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1469,7 +1469,7 @@ static bool DumpModuleSymbolFile(Stream &strm, Module *module) {
 
 static void DumpAddress(ExecutionContextScope *exe_scope,
                         const Address &so_addr, bool verbose, bool all_ranges,
-                        Stream &strm, const char *name) {
+                        Stream &strm, const char *name=nullptr) {
   strm.IndentMore();
   strm.Indent("    Address: ");
   so_addr.Dump(&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
@@ -1524,6 +1524,10 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
 
 // This function is the one which colorizes the regex symbol searched
 static void PrintRed(Stream &strm, const char *text, const char *name) {
+    if (!name){
+      strm.PutCString(text);
+      return;
+    }
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
     const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
 
diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp
index 5e44d0ce106ad03..74a42c03d92e28d 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -409,6 +409,10 @@ bool Address::GetDescription(Stream &s, Target &target,
 
 // Function to print the searched symbol in red color
 static void PrintRed(Stream *strm, const char *text, const char *name) {
+    if (!name){
+      strm->PutCString(text);
+      return;
+    }
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
     const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
 
@@ -680,12 +684,8 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
                 if (pointer_sc.function != nullptr ||
                     pointer_sc.symbol != nullptr) {
                   s->PutCString(": ");
-                  if(name)
-                    pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false,
-                                             false, true, true, name);
-                  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, name);
                 }
               }
             }
@@ -735,18 +735,13 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
               // 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(name)
-                Dump(s, exe_scope, DumpStyleSectionNameOffset, DumpStyleInvalid, UINT32_MAX, false, name);
-              else
-                Dump(s, exe_scope, DumpStyleSectionNameOffset);
+              Dump(s, exe_scope, DumpStyleSectionNameOffset, DumpStyleInvalid, UINT32_MAX, false, name);
             }
           }
         }
       }
     } else {
-      if (fallback_style != DumpStyleInvalid && !name)
-        return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
-      else if(fallback_style != DumpStyleInvalid && name){
+      if(fallback_style != DumpStyleInvalid){
         return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, name);
       }
       return false;
@@ -769,14 +764,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
               sc.symbol->GetAddressRef().GetSection() != GetSection())
             sc.symbol = nullptr;
         }
-        if(name){
-          // printf("Here bro\n");
-          sc.GetDescription(s, eDescriptionLevelBrief, target, name);
-        }
-        else{
-          // printf("Here\n")
-          sc.GetDescription(s, eDescriptionLevelBrief, target);
-        }
+        sc.GetDescription(s, eDescriptionLevelBrief, target, name);
 
         if (sc.block) {
           bool can_create = true;
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index eef3545685b1f19..abc9615b6a6eea9 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -232,6 +232,10 @@ bool Symbol::IsIndirect() const { return m_type == eSymbolTypeResolver; }
 // Similar to the other modules, using PrintRed function.
 
 static void PrintRed(Stream *strm, const char *text, const char *name) {
+    if (!name){
+      strm->PutCString(text);
+      return;
+    }
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
     const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
 
diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp
index 97c288ad6dbcfde..de6c51e33aedc2a 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -74,6 +74,10 @@ void SymbolContext::Clear(bool clear_target) {
 // Similar to the other modules, using PrintRed function.
 
 static void PrintRed(Stream *strm, const char *text, const char *name) {
+    if (!name){
+      strm->PutCString(text);
+      return;
+    }
     const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
     const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
 
@@ -226,113 +230,10 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
   return dumped_something;
 }
 
-void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level,
-                                   Target *target, const char* name) const {
-  if (module_sp) {
-    s->Indent("     Module: file = \"");
-    module_sp->GetFileSpec().Dump(s->AsRawOstream());
-    *s << '"';
-    if (module_sp->GetArchitecture().IsValid())
-      s->Printf(", arch = \"%s\"",
-                module_sp->GetArchitecture().GetArchitectureName());
-    s->EOL();
-  }
-
-  if (comp_unit != nullptr) {
-    s->Indent("CompileUnit: ");
-    comp_unit->GetDescription(s, level);
-    s->EOL();
-  }
-
-  if (function != nullptr) {
-    s->Indent("   Function: ");
-    function->GetDescription(s, level, target);
-    s->EOL();
-
-    Type *func_type = function->GetType();
-    if (func_type) {
-      s->Indent("   FuncType: ");
-      func_type->GetDescription(s, level, false, target);
-      s->EOL();
-    }
-  }
-
-  if (block != nullptr) {
-    std::vector<Block *> blocks;
-    blocks.push_back(block);
-    Block *parent_block = block->GetParent();
-
-    while (parent_block) {
-      blocks.push_back(parent_block);
-      parent_block = parent_block->GetParent();
-    }
-    std::vector<Block *>::reverse_iterator pos;
-    std::vector<Block *>::reverse_iterator begin = blocks.rbegin();
-    std::vector<Block *>::reverse_iterator end = blocks.rend();
-    for (pos = begin; pos != end; ++pos) {
-      if (pos == begin)
-        s->Indent("     Blocks: ");
-      else
-        s->Indent("             ");
-      (*pos)->GetDescription(s, function, level, target);
-      s->EOL();
-    }
-  }
-
-  if (line_entry.IsValid()) {
-    s->Indent("  LineEntry: ");
-    line_entry.GetDescription(s, level, comp_unit, target, false);
-    s->EOL();
-  }
-
-  if (symbol != nullptr) {
-    s->Indent("     Symbol: ");
-    // Passing name to the symbol Description (-v flag) function if name != nullptr
-    if(name)
-      symbol->GetDescription(s, level, target, name);
-    else
-      symbol->GetDescription(s, level, target);
-    s->EOL();
-  }
-
-  if (variable != nullptr) {
-    s->Indent("   Variable: ");
-
-    s->Printf("id = {0x%8.8" PRIx64 "}, ", variable->GetID());
-
-    switch (variable->GetScope()) {
-    case eValueTypeVariableGlobal:
-      s->PutCString("kind = global, ");
-      break;
-
-    case eValueTypeVariableStatic:
-      s->PutCString("kind = static, ");
-      break;
-
-    case eValueTypeVariableArgument:
-      s->PutCString("kind = argument, ");
-      break;
-
-    case eValueTypeVariableLocal:
-      s->PutCString("kind = local, ");
-      break;
-
-    case eValueTypeVariableThreadLocal:
-      s->PutCString("kind = thread local, ");
-      break;
-
-    default:
-      break;
-    }
-
-    s->Printf("name = \"%s\"\n", variable->GetName().GetCString());
-  }
-}
-
 //===========================================================================
 
 void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level,
-                                   Target *target) const {
+                                   Target *target, const char* name) const {
   if (module_sp) {
     s->Indent("     Module: file = \"");
     module_sp->GetFileSpec().Dump(s->AsRawOstream());
@@ -392,7 +293,7 @@ void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level,
 
   if (symbol != nullptr) {
     s->Indent("     Symbol: ");
-    symbol->GetDescription(s, level, target);
+    symbol->GetDescription(s, level, target, name);
     s->EOL();
   }
 
diff --git a/lldb/test/Shell/Commands/TestImageLookupColor.test b/lldb/test/Shell/Commands/TestImageLookupColor.test
new file mode 100644
index 000000000000000..4b3be6cd9cf3abb
--- /dev/null
+++ b/lldb/test/Shell/Commands/TestImageLookupColor.test
@@ -0,0 +1,23 @@
+UNSUPPORTED: system-windows
+
+# RUN: %clang_host -g %S/Inputs/main.c -o %t
+# RUN: %lldb %t -b -o 'image lookup -r -s ma' | FileCheck %s
+
+# CHECK: 3 symbols match the regular expression 'ma' in {{.*}}
+# The [[ confuses FileCheck so regex match it.
+# CHECK-NEXT:         Name: {{.+}}31mma{{.+}}0min.c
+# CHECK-NEXT:         Value: 0x0000000000000000
+# CHECK-NEXT:         Size: 0x0000000000000000
+# CHECK-NEXT:         Name: __libc_start_{{.+}}31mma{{.+}}0min at GLIBC_2.34
+# CHECK-NEXT:         Value: 0x0000000000000000
+# CHECK-NEXT:         Address: {{.+}}[0x0000000000001140] ({{.+}}.PT_LOAD[1]..text + 256)
+# CHECK-NEXT:         Summary: {{.+}}`{{.+}}31mma{{.+}}0min at main.c:2
+
+# RUN: %lldb %t -b -o 'image lookup -r -s main.c|foo' | FileCheck %s --check-prefix CHECKFN
+
+# CHECKFN: 2 symbols match the regular expression 'main.c|foo' in {{.*}}
+# CHECKFN-NEXT:         Name: {{.+}}31mmain.c{{.+}}0m
+# CHECKFN-NEXT:         Value: 0x0000000000000000
+# CHECKFN-NEXT:         Size: 0x0000000000000000
+# CHECKFN-NEXT:         Address: {{.+}}[0x0000000000001130] ({{.+}}.PT_LOAD[1]..text + 240)
+# CHECKFN-NEXT:         Summary: {{.+}}`{{.+}}31mfoo{{.+}}0m at {{.+}}31mmain.c{{.+}}0m:1
\ No newline at end of file
diff --git a/lldb/test/Shell/Commands/command-target-modules-lookup.test b/lldb/test/Shell/Commands/command-target-modules-lookup.test
index a3e3837303822b1..3f62fedd2da8f8f 100644
--- a/lldb/test/Shell/Commands/command-target-modules-lookup.test
+++ b/lldb/test/Shell/Commands/command-target-modules-lookup.test
@@ -1,6 +1,7 @@
 # RUN: yaml2obj %S/Inputs/symbols.yaml -o %t
 
 # RUN: %lldb %t -b -o "target modules lookup -A -r -s some" | FileCheck %s -DMODULE=%basename_t.tmp --implicit-check-not ignoreThisFunction
+
 # CHECK:      4 symbols match the regular expression 'some' in {{.*}}[[MODULE]]:
 # CHECK-NEXT: Address: [[MODULE]][0x0000000000000000] ([[MODULE]]..text + 0)
 # CHECK-NEXT: Summary: [[MODULE]]`someFunc(int, int, int)
@@ -12,6 +13,7 @@
 # CHECK-NEXT: Summary: [[MODULE]]`someOtherFunc(double)
 
 # RUN: %lldb %t -b -o "target modules lookup -r -n \".*someFunc\"" | FileCheck %s -DMODULE=%basename_t.tmp --check-prefix CHECKFN
+
 # CHECKFN:     2 matches found in {{.*}}[[MODULE]]:
 # CHECKFN-NEXT: Address: [[MODULE]][0x0000000000000000] ([[MODULE]]..text + 0)
 # CHECKFN-NEXT: Summary: [[MODULE]]`someFunc(int, int, int)



More information about the lldb-commits mailing list