[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)
via lldb-commits
lldb-commits at lists.llvm.org
Mon Nov 6 01:07:18 PST 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 01/14] 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 02/14] 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 03/14] 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 04/14] 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 05/14] 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 06/14] 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 07/14] 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 08/14] 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 09/14] 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)
>From 86f1dc035b6029dc2c804167238a938e974ce38c Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100293 at lums.edu.pk>
Date: Mon, 30 Oct 2023 16:19:10 +0500
Subject: [PATCH 10/14] Updated Test-cases and use-color settings
---
lldb/include/lldb/Core/Address.h | 2 +-
lldb/include/lldb/Symbol/Symbol.h | 3 +-
lldb/include/lldb/Symbol/SymbolContext.h | 6 +-
lldb/source/Commands/CommandObjectTarget.cpp | 47 +++++++++-------
lldb/source/Core/Address.cpp | 55 +++++++++++--------
lldb/source/Symbol/Symbol.cpp | 47 +++++++++-------
lldb/source/Symbol/SymbolContext.cpp | 52 +++++++++++-------
.../Shell/Commands/TestImageLookupColor.test | 48 +++++++++-------
8 files changed, 154 insertions(+), 106 deletions(-)
diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h
index 16ea2037afb0e4a..adff6ede6c3fc1a 100644
--- a/lldb/include/lldb/Core/Address.h
+++ b/lldb/include/lldb/Core/Address.h
@@ -248,7 +248,7 @@ class Address {
DumpStyle fallback_style = DumpStyleInvalid,
uint32_t addr_byte_size = UINT32_MAX,
bool all_ranges = false,
- const char* name = nullptr) const;
+ const char* name = nullptr, CommandInterpreter *interpreter = nullptr) const;
// bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,const char* name,
diff --git a/lldb/include/lldb/Symbol/Symbol.h b/lldb/include/lldb/Symbol/Symbol.h
index 0084aec8b67a7ea..97635c7b34a7d8a 100644
--- a/lldb/include/lldb/Symbol/Symbol.h
+++ b/lldb/include/lldb/Symbol/Symbol.h
@@ -181,7 +181,8 @@ class Symbol : public SymbolContextScope {
// This argument is the regex symbol searched.
void GetDescription(Stream *s, lldb::DescriptionLevel level,
Target *target,
- const char *name = nullptr) const;
+ const char *name = nullptr,
+ CommandInterpreter *interpreter = 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 e7d14fa2a91bbe3..47decf0d419eff5 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -154,7 +154,8 @@ class SymbolContext {
bool show_module, bool show_inlined_frames,
bool show_function_arguments,
bool show_function_name,
- const char* name = nullptr) const;
+ const char* name = nullptr,
+ CommandInterpreter *interpreter = nullptr) const;
/// Get the address range contained within a symbol context.
@@ -223,7 +224,8 @@ class SymbolContext {
void GetDescription(Stream *s, lldb::DescriptionLevel level,
- Target *target, const char* name=nullptr) const;
+ Target *target, const char* name=nullptr,
+ CommandInterpreter *interpreter = nullptr) const;
uint32_t GetResolvedMask() const;
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 5e865c2030c55bf..2cfe7edd0b20a70 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -65,6 +65,7 @@
#include "llvm/Support/FormatAdapters.h"
#include "lldb/Utility/AnsiTerminal.h"
#include <sstream>
+#include <regex>
using namespace lldb;
using namespace lldb_private;
@@ -1469,7 +1470,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=nullptr) {
+ Stream &strm, const char *name=nullptr, CommandInterpreter *interpreter= nullptr) {
strm.IndentMore();
strm.Indent(" Address: ");
so_addr.Dump(&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
@@ -1481,7 +1482,7 @@ static void DumpAddress(ExecutionContextScope *exe_scope,
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, Address::DumpStyleInvalid, UINT32_MAX, false, name);
+ so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription, Address::DumpStyleInvalid, UINT32_MAX, false, name, interpreter);
strm.SetIndentLevel(save_indent);
// Print out detailed address information when verbose is enabled
if (verbose) {
@@ -1523,30 +1524,37 @@ 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;
+static void PrintRed(Stream &strm, const char *text, const char *name, CommandInterpreter *interpreter= nullptr) {
+ 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;
- const char *match = text;
- size_t name_len = strlen(name);
+ bool use_color = interpreter->GetDebugger().GetUseColor();
- while ((match = strstr(match, name))) {
- size_t prefix_len = match - text;
+ std::string str_text(text);
+ std::regex reg_name(name);
+ std::sregex_iterator next(str_text.begin(), str_text.end(), reg_name);
+ std::sregex_iterator end;
+
+ std::string red_start = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.fg.red}", use_color);
+ std::string reset_color = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.normal}", use_color);
+
+ size_t last_pos = 0;
+ while (next != end) {
+ std::smatch match = *next;
+ size_t prefix_len = match.position() - last_pos;
strm.Write(text, prefix_len);
strm.PutCString(red_start.c_str());
- strm.Write(match, name_len);
+ strm.Write(text + match.position(), match.length());
strm.PutCString(reset_color.c_str());
-
- text = match + name_len;
- match = text;
+
+ last_pos = match.position() + match.length();
+ ++next;
}
- strm.PutCString(text); // Print any remaining text
+ strm.PutCString(text + last_pos); // Print any remaining text
}
//===========================================================================================
@@ -1588,14 +1596,15 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
// Using the new dump function to add colors in the summary.
DumpAddress(
interpreter.GetExecutionContext().GetBestExecutionContextScope(),
- symbol->GetAddressRef(), verbose, all_ranges, strm, name);
+ symbol->GetAddressRef(), verbose, all_ranges, strm, name, &interpreter);
strm.EOL();
} else {
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);
+ PrintRed(strm, symbol->GetDisplayName().GetStringRef().str().c_str(), name,
+ &interpreter);
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 74a42c03d92e28d..40d672150ea148c 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -35,6 +35,7 @@
#include "lldb/Utility/Status.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/StreamString.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
@@ -49,6 +50,7 @@
#include <cinttypes>
#include <cstring>
#include <sstream>
+#include <regex>
namespace lldb_private {
class CompileUnit;
@@ -408,30 +410,37 @@ 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;
+static void PrintRed(Stream *strm, const char *text, const char *name, CommandInterpreter *interpreter = nullptr) {
+ 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;
- const char *match = text;
- size_t name_len = strlen(name);
+ bool use_color = interpreter->GetDebugger().GetUseColor();
- while ((match = strstr(match, name))) {
- size_t prefix_len = match - text;
+ std::string str_text(text);
+ std::regex reg_name(name);
+ std::sregex_iterator next(str_text.begin(), str_text.end(), reg_name);
+ std::sregex_iterator end;
+
+ std::string red_start = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.fg.red}", use_color);
+ std::string reset_color = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.normal}", use_color);
+
+ size_t last_pos = 0;
+ while (next != end) {
+ std::smatch match = *next;
+ size_t prefix_len = match.position() - last_pos;
strm->Write(text, prefix_len);
strm->PutCString(red_start.c_str());
- strm->Write(match, name_len);
+ strm->Write(text + match.position(), match.length());
strm->PutCString(reset_color.c_str());
-
- text = match + name_len;
- match = text;
+
+ last_pos = match.position() + match.length();
+ ++next;
}
- strm->PutCString(text); // Print any remaining text
+ strm->PutCString(text + last_pos); // Print any remaining text
}
//==================================================================================
@@ -441,7 +450,7 @@ static void PrintRed(Stream *strm, const char *text, const char *name) {
bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
DumpStyle fallback_style, uint32_t addr_size,
- bool all_ranges, const char* name) const {
+ bool all_ranges, const char* name, CommandInterpreter *interpreter) 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());
@@ -553,7 +562,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
if (symbol_name) {
// Using the PrintRed function to colorize the symbol if name not equal to nullptr
if(name){
- PrintRed(s, symbol_name, name);
+ PrintRed(s, symbol_name, name, interpreter);
}
else{
s->PutCString(symbol_name);
@@ -685,7 +694,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
pointer_sc.symbol != nullptr) {
s->PutCString(": ");
pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false,
- false, true, true, name);
+ false, true, true, name, interpreter);
}
}
}
@@ -726,7 +735,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
if(name)
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, name, interpreter);
else
sc.DumpStopContext(s, exe_scope, *this, show_fullpaths,
show_module, show_inlined_frames,
@@ -742,7 +751,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
}
} else {
if(fallback_style != DumpStyleInvalid){
- return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, name);
+ return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, name, interpreter);
}
return false;
}
@@ -764,7 +773,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
sc.symbol->GetAddressRef().GetSection() != GetSection())
sc.symbol = nullptr;
}
- sc.GetDescription(s, eDescriptionLevelBrief, target, name);
+ sc.GetDescription(s, eDescriptionLevelBrief, target, name, interpreter);
if (sc.block) {
bool can_create = true;
@@ -814,7 +823,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
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 Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, name, interpreter);
}
return false;
}
@@ -848,7 +857,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
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 Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, name, interpreter);
return false;
} break;
}
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index abc9615b6a6eea9..17e9212ac4d8a97 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -21,7 +21,9 @@
#include "lldb/Utility/Stream.h"
#include "llvm/ADT/StringSwitch.h"
#include "lldb/Utility/AnsiTerminal.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
#include <sstream>
+#include <regex>
using namespace lldb;
using namespace lldb_private;
@@ -230,31 +232,37 @@ 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;
+static void PrintRed(Stream *strm, const char *text, const char *name, CommandInterpreter *interpreter) {
+ 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;
- const char *match = text;
- size_t name_len = strlen(name);
+ bool use_color = interpreter->GetDebugger().GetUseColor();
- while ((match = strstr(match, name))) {
- size_t prefix_len = match - text;
+ std::string str_text(text);
+ std::regex reg_name(name);
+ std::sregex_iterator next(str_text.begin(), str_text.end(), reg_name);
+ std::sregex_iterator end;
+
+ std::string red_start = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.fg.red}", use_color);
+ std::string reset_color = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.normal}", use_color);
+
+ size_t last_pos = 0;
+ while (next != end) {
+ std::smatch match = *next;
+ size_t prefix_len = match.position() - last_pos;
strm->Write(text, prefix_len);
strm->PutCString(red_start.c_str());
- strm->Write(match, name_len);
+ strm->Write(text + match.position(), match.length());
strm->PutCString(reset_color.c_str());
-
- text = match + name_len;
- match = text;
+
+ last_pos = match.position() + match.length();
+ ++next;
}
- strm->PutCString(text); // Print any remaining text
+ strm->PutCString(text + last_pos); // Print any remaining text
}
//========================================================================
@@ -263,7 +271,8 @@ static void PrintRed(Stream *strm, const char *text, const char *name) {
// is passed to print addition iformation of the symbol
void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
- Target *target, const char *name) const {
+ Target *target, const char *name,
+ CommandInterpreter *interpreter) const {
s->Printf("id = {0x%8.8x}", m_uid);
if (m_addr_range.GetBaseAddress().GetSection()) {
@@ -296,13 +305,13 @@ void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
// In that case, we use the PrintRed function to colorize the symbol.
if (demangled && name){
s->Printf(", name=");
- PrintRed(s, demangled.AsCString(), name);
+ PrintRed(s, demangled.AsCString(), name, interpreter);
}
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);
+ PrintRed(s, m_mangled.GetMangledName().AsCString(), name, interpreter);
}
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 de6c51e33aedc2a..553deed76833a66 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -26,7 +26,9 @@
#include "lldb/Utility/StreamString.h"
#include "lldb/lldb-enumerations.h"
#include "lldb/Utility/AnsiTerminal.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
#include <sstream>
+#include <regex>
using namespace lldb;
using namespace lldb_private;
@@ -73,30 +75,37 @@ 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;
+static void PrintRed(Stream *strm, const char *text, const char *name, CommandInterpreter *interpreter) {
+ 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;
-
- const char *match = text;
- size_t name_len = strlen(name);
- while ((match = strstr(match, name))) {
- size_t prefix_len = match - text;
+ bool use_color = interpreter->GetDebugger().GetUseColor();
+
+ std::string str_text(text);
+ std::regex reg_name(name);
+ std::sregex_iterator next(str_text.begin(), str_text.end(), reg_name);
+ std::sregex_iterator end;
+
+ std::string red_start = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.fg.red}", use_color);
+ std::string reset_color = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.normal}", use_color);
+
+ size_t last_pos = 0;
+ while (next != end) {
+ std::smatch match = *next;
+ size_t prefix_len = match.position() - last_pos;
strm->Write(text, prefix_len);
strm->PutCString(red_start.c_str());
- strm->Write(match, name_len);
+ strm->Write(text + match.position(), match.length());
strm->PutCString(reset_color.c_str());
-
- text = match + name_len;
- match = text;
+
+ last_pos = match.position() + match.length();
+ ++next;
}
- strm->PutCString(text); // Print any remaining text
+ strm->PutCString(text + last_pos); // Print any remaining text
}
//===========================================================================
@@ -106,7 +115,7 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
bool show_module, bool show_inlined_frames,
bool show_function_arguments,
bool show_function_name,
- const char* name) const {
+ const char* name, CommandInterpreter *interpreter) const {
bool dumped_something = false;
if (show_module && module_sp) {
if (show_fullpaths)
@@ -133,7 +142,7 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
if (name_func && !name)
name_func.Dump(s);
else if(name_func && name){
- PrintRed(s, name_func.GetCString() , name);
+ PrintRed(s, name_func.GetCString(), name, interpreter);
}
}
@@ -205,7 +214,7 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
// 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);
+ PrintRed(s, symbol->GetName().GetStringRef().str().c_str(), name, interpreter);
}
else
symbol->GetName().Dump(s);
@@ -233,7 +242,8 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
//===========================================================================
void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level,
- Target *target, const char* name) const {
+ Target *target, const char* name,
+ CommandInterpreter *interpreter) const {
if (module_sp) {
s->Indent(" Module: file = \"");
module_sp->GetFileSpec().Dump(s->AsRawOstream());
@@ -293,7 +303,7 @@ void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level,
if (symbol != nullptr) {
s->Indent(" Symbol: ");
- symbol->GetDescription(s, level, target, name);
+ symbol->GetDescription(s, level, target, name, interpreter);
s->EOL();
}
diff --git a/lldb/test/Shell/Commands/TestImageLookupColor.test b/lldb/test/Shell/Commands/TestImageLookupColor.test
index 4b3be6cd9cf3abb..248e1a8ab2d0dfd 100644
--- a/lldb/test/Shell/Commands/TestImageLookupColor.test
+++ b/lldb/test/Shell/Commands/TestImageLookupColor.test
@@ -1,23 +1,31 @@
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
+# RUN: %lldb %t -b -o 'settings set use-color true' -o 'image lookup -r -s ma' | FileCheck %s --check-prefix CHECK1
+
+# CHECK1: 3 symbols match the regular expression 'ma' in {{.*}}
+# CHECK1: Name: {{.+}}31mma{{.+}}0min.c
+# CHECK1: Summary: {{.+}}`{{.+}}31mma{{.+}}0min at main.c:2
+
+# RUN: %lldb %t -b -o 'settings set use-color true' -o 'image lookup -r -s main.c|foo' | FileCheck %s --check-prefix CHECK2
+
+# CHECK2: 2 symbols match the regular expression 'main.c|foo' in {{.*}}
+# CHECK2: Name: {{.+}}31mmain.c{{.+}}0m
+# CHECK2: Summary: {{.+}}`{{.+}}31mfoo{{.+}}0m at main.c:1
+
+# RUN: %lldb %t -b -o 'settings set use-color true' -o 'image lookup -r -s m[abc]' | FileCheck %s --check-prefix CHECK3
+
+# CHECK3: 5 symbols match the regular expression 'm[abc]' in {{.*}}
+# CHECK3: Name: {{.+}}31mma{{.+}}0min.c
+# CHECK3: Summary: {{.+}}`{{.+}}31mma{{.+}}0min at main.c:2
+# CHECK3: Summary: {{.+}}`___lldb_unnamed_sy{{.+}}31mmb{{.+}}0mol36
+# CHECK3: Summary: {{.+}}`___lldb_unnamed_sy{{.+}}31mmb{{.+}}0mol37
+
+
+# RUN: %lldb %t -b -o 'settings set use-color true' -o 'image lookup -r -s [0-9]' | FileCheck %s --check-prefix CHECK4
+
+# CHECK4: 6 symbols match the regular expression '[0-9]' in {{.*}}
+# CHECK4: Name: Scrt{{.+}}31m1{{.+}}0m.o
+# CHECK4: Summary: {{.+}}`completed.{{.+}}31m0{{.+}}0m
+# CHECK4: Name: __libc_start_main at GLIBC_{{.+}}31m2{{.+}}0m_{{.+}}31m3{{.+}}0m{{.+}}31m4{{.+}}0m
+# CHECK4: Name: __cxa_finalize at GLIBC_{{.+}}31m2{{.+}}0m_{{.+}}31m2{{.+}}0m_{{.+}}31m5{{.+}}0m
>From 1b493e2ec44585c474eb84cc4854c5f143dda108 Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100293 at lums.edu.pk>
Date: Tue, 31 Oct 2023 14:17:00 +0500
Subject: [PATCH 11/14] Updated test cases
---
lldb/source/Commands/CommandObjectTarget.cpp | 2 +-
lldb/source/Symbol/Symbol.cpp | 2 +-
lldb/test/Shell/Commands/TestImageLookupColor.test | 11 +++++++++++
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 2cfe7edd0b20a70..2c5148cce46a987 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1488,7 +1488,7 @@ static void DumpAddress(ExecutionContextScope *exe_scope,
if (verbose) {
strm.EOL();
so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext,
- Address::DumpStyleInvalid, UINT32_MAX, all_ranges, name);
+ Address::DumpStyleInvalid, UINT32_MAX, all_ranges, name, interpreter);
}
strm.IndentLess();
}
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index 17e9212ac4d8a97..b849768f731668b 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -271,7 +271,7 @@ static void PrintRed(Stream *strm, const char *text, const char *name, CommandIn
// is passed to print addition iformation of the symbol
void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
- Target *target, const char *name,
+ Target *target, const char *name,
CommandInterpreter *interpreter) const {
s->Printf("id = {0x%8.8x}", m_uid);
diff --git a/lldb/test/Shell/Commands/TestImageLookupColor.test b/lldb/test/Shell/Commands/TestImageLookupColor.test
index 248e1a8ab2d0dfd..85eb2d0f3811a1d 100644
--- a/lldb/test/Shell/Commands/TestImageLookupColor.test
+++ b/lldb/test/Shell/Commands/TestImageLookupColor.test
@@ -29,3 +29,14 @@ UNSUPPORTED: system-windows
# CHECK4: Summary: {{.+}}`completed.{{.+}}31m0{{.+}}0m
# CHECK4: Name: __libc_start_main at GLIBC_{{.+}}31m2{{.+}}0m_{{.+}}31m3{{.+}}0m{{.+}}31m4{{.+}}0m
# CHECK4: Name: __cxa_finalize at GLIBC_{{.+}}31m2{{.+}}0m_{{.+}}31m2{{.+}}0m_{{.+}}31m5{{.+}}0m
+
+# RUN: %lldb %t -b -o 'settings set use-color true' -o 'image lookup -r -s ^f.*' | FileCheck %s --check-prefix CHECK5
+
+# CHECK5: 2 symbols match the regular expression '^f.*' in {{.*}}
+# CHECK5: Summary: {{.+}}`{{.+}}31mframe_dummy{{.+}}0m
+# CHECK5: Summary: {{.+}}`{{.+}}31mfoo{{.+}}0m at main.c:1
+
+# RUN: %lldb %t -b -o 'settings set use-color true' -o 'image lookup -r -s .*m.*n$' | FileCheck %s --check-prefix CHECK6
+
+# CHECK6: 1 symbols match the regular expression '.*m.*n$' in {{.*}}
+# CHECK6: Summary: {{.+}}`{{.+}}31mmain{{.+}}0m at main.c:2
\ No newline at end of file
>From 13c909fa2a82aaa89799d628c7c0752c08d565f9 Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100293 at lums.edu.pk>
Date: Thu, 2 Nov 2023 13:34:05 +0500
Subject: [PATCH 12/14] updated use-color settings
---
lldb/include/lldb/Core/Address.h | 2 +-
lldb/include/lldb/Symbol/Symbol.h | 3 +-
lldb/include/lldb/Symbol/SymbolContext.h | 7 ++--
lldb/source/Commands/CommandObjectTarget.cpp | 35 +++++++++++++-----
lldb/source/Core/Address.cpp | 37 ++++++++++----------
lldb/source/Symbol/Symbol.cpp | 23 ++++++------
lldb/source/Symbol/SymbolContext.cpp | 28 ++++++++-------
7 files changed, 77 insertions(+), 58 deletions(-)
diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h
index adff6ede6c3fc1a..a26562fa67d2292 100644
--- a/lldb/include/lldb/Core/Address.h
+++ b/lldb/include/lldb/Core/Address.h
@@ -248,7 +248,7 @@ class Address {
DumpStyle fallback_style = DumpStyleInvalid,
uint32_t addr_byte_size = UINT32_MAX,
bool all_ranges = false,
- const char* name = nullptr, CommandInterpreter *interpreter = nullptr) const;
+ std::vector<std::pair<bool, const char*>>* info = nullptr) const;
// bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,const char* name,
diff --git a/lldb/include/lldb/Symbol/Symbol.h b/lldb/include/lldb/Symbol/Symbol.h
index 97635c7b34a7d8a..3f10cd2c33c08fc 100644
--- a/lldb/include/lldb/Symbol/Symbol.h
+++ b/lldb/include/lldb/Symbol/Symbol.h
@@ -181,8 +181,7 @@ class Symbol : public SymbolContextScope {
// This argument is the regex symbol searched.
void GetDescription(Stream *s, lldb::DescriptionLevel level,
Target *target,
- const char *name = nullptr,
- CommandInterpreter *interpreter = nullptr) const;
+ std::vector<std::pair<bool, const char*>> *info = 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 47decf0d419eff5..682e13fd5fde0db 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -154,8 +154,7 @@ class SymbolContext {
bool show_module, bool show_inlined_frames,
bool show_function_arguments,
bool show_function_name,
- const char* name = nullptr,
- CommandInterpreter *interpreter = nullptr) const;
+ std::vector<std::pair<bool, const char*>>* info = nullptr) const;
/// Get the address range contained within a symbol context.
@@ -224,8 +223,8 @@ class SymbolContext {
void GetDescription(Stream *s, lldb::DescriptionLevel level,
- Target *target, const char* name=nullptr,
- CommandInterpreter *interpreter = nullptr) const;
+ Target *target,
+ std::vector<std::pair<bool, const char*>>* info = nullptr) const;
uint32_t GetResolvedMask() const;
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 2c5148cce46a987..493067dcce70d81 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -66,6 +66,7 @@
#include "lldb/Utility/AnsiTerminal.h"
#include <sstream>
#include <regex>
+#include <vector>
using namespace lldb;
using namespace lldb_private;
@@ -1470,7 +1471,8 @@ 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=nullptr, CommandInterpreter *interpreter= nullptr) {
+ Stream &strm,
+ std::vector<std::pair<bool, const char*>>* info = nullptr) {
strm.IndentMore();
strm.Indent(" Address: ");
so_addr.Dump(&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
@@ -1482,13 +1484,13 @@ static void DumpAddress(ExecutionContextScope *exe_scope,
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, Address::DumpStyleInvalid, UINT32_MAX, false, name, interpreter);
+ so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription, Address::DumpStyleInvalid, UINT32_MAX, false, info);
strm.SetIndentLevel(save_indent);
// Print out detailed address information when verbose is enabled
if (verbose) {
strm.EOL();
so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext,
- Address::DumpStyleInvalid, UINT32_MAX, all_ranges, name, interpreter);
+ Address::DumpStyleInvalid, UINT32_MAX, all_ranges, info);
}
strm.IndentLess();
}
@@ -1524,13 +1526,14 @@ 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, CommandInterpreter *interpreter= nullptr) {
- if (!name) {
+static void PrintRed(Stream &strm, const char *text, std::vector<std::pair<bool, const char*>> *info) {
+ if (!info) {
strm.PutCString(text);
return;
}
- bool use_color = interpreter->GetDebugger().GetUseColor();
+ const char* name = (*info)[0].second;
+ bool use_color = (*info)[0].first;
std::string str_text(text);
std::regex reg_name(name);
@@ -1570,6 +1573,15 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
return 0;
SymbolContext sc;
+
+ std::vector<std::pair<bool, const char*>> info;
+ bool use_color = interpreter.GetDebugger().GetUseColor();
+ info.push_back(std::make_pair(use_color, name));
+
+ // if (!info.empty()) {
+ // printf("Bool Value: %d, Char Value: %s\n", info[0].first, info[0].second);
+ // }
+
std::vector<uint32_t> match_indexes;
ConstString symbol_name(name);
uint32_t num_matches = 0;
@@ -1582,6 +1594,12 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
symtab->AppendSymbolIndexesWithName(symbol_name, match_indexes);
}
+ // for (uint32_t i = 0; i < match_indexes.size(); ++i) {
+ // printf("%d", match_indexes[i]);
+ // printf(", ");
+ // }
+ // printf("\n");
+
if (num_matches > 0) {
strm.Indent();
strm.Printf("%u symbols match %s'%s' in ", num_matches,
@@ -1596,15 +1614,14 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
// Using the new dump function to add colors in the summary.
DumpAddress(
interpreter.GetExecutionContext().GetBestExecutionContextScope(),
- symbol->GetAddressRef(), verbose, all_ranges, strm, name, &interpreter);
+ symbol->GetAddressRef(), verbose, all_ranges, strm, &info);
strm.EOL();
} else {
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,
- &interpreter);
+ PrintRed(strm, symbol->GetDisplayName().GetStringRef().str().c_str(), &info);
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 40d672150ea148c..5743fa261f14da7 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -410,13 +410,14 @@ 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, CommandInterpreter *interpreter = nullptr) {
- if (!name) {
+static void PrintRed(Stream *strm, const char *text, std::vector<std::pair<bool, const char*>>* info = nullptr) {
+ if (!info) {
strm->PutCString(text);
return;
}
- bool use_color = interpreter->GetDebugger().GetUseColor();
+ const char* name = (*info)[0].second;
+ bool use_color = (*info)[0].first;
std::string str_text(text);
std::regex reg_name(name);
@@ -450,7 +451,7 @@ static void PrintRed(Stream *strm, const char *text, const char *name, CommandIn
bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
DumpStyle fallback_style, uint32_t addr_size,
- bool all_ranges, const char* name, CommandInterpreter *interpreter) const {
+ bool all_ranges, std::vector<std::pair<bool, const char*>>* info) const {
// If the section was nullptr, only load address is going to work unless we
// are trying to deref a pointer
SectionSP section_sp(GetSection());
@@ -561,8 +562,8 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
const char *symbol_name = symbol->GetName().AsCString();
if (symbol_name) {
// Using the PrintRed function to colorize the symbol if name not equal to nullptr
- if(name){
- PrintRed(s, symbol_name, name, interpreter);
+ if(info){
+ PrintRed(s, symbol_name, info);
}
else{
s->PutCString(symbol_name);
@@ -694,7 +695,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
pointer_sc.symbol != nullptr) {
s->PutCString(": ");
pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false,
- false, true, true, name, interpreter);
+ false, true, true, info);
}
}
}
@@ -732,10 +733,10 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
// We have a function or a symbol from the same sections as this
// address.
// Using the same logic, hecking if searched symbol passed to this function or if it using the defualt nullptr
- if(name)
+ if(info)
sc.DumpStopContext(s, exe_scope, *this, show_fullpaths,
show_module, show_inlined_frames,
- show_function_arguments, show_function_name, name, interpreter);
+ show_function_arguments, show_function_name, info);
else
sc.DumpStopContext(s, exe_scope, *this, show_fullpaths,
show_module, show_inlined_frames,
@@ -744,14 +745,14 @@ 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
- Dump(s, exe_scope, DumpStyleSectionNameOffset, DumpStyleInvalid, UINT32_MAX, false, name);
+ Dump(s, exe_scope, DumpStyleSectionNameOffset, DumpStyleInvalid, UINT32_MAX, false, info);
}
}
}
}
} else {
if(fallback_style != DumpStyleInvalid){
- return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, name, interpreter);
+ return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, info);
}
return false;
}
@@ -773,7 +774,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
sc.symbol->GetAddressRef().GetSection() != GetSection())
sc.symbol = nullptr;
}
- sc.GetDescription(s, eDescriptionLevelBrief, target, name, interpreter);
+ sc.GetDescription(s, eDescriptionLevelBrief, target, info);
if (sc.block) {
bool can_create = true;
@@ -820,10 +821,10 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
}
}
} else {
- if (fallback_style != DumpStyleInvalid && !name)
+ if (fallback_style != DumpStyleInvalid && !info)
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, interpreter);
+ else if(fallback_style != DumpStyleInvalid && info){
+ return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, info);
}
return false;
}
@@ -854,10 +855,10 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
}
}
}
- if (fallback_style != DumpStyleInvalid && !name)
+ if (fallback_style != DumpStyleInvalid && !info)
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, interpreter);
+ else if(fallback_style != DumpStyleInvalid && info)
+ return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, info);
return false;
} break;
}
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index b849768f731668b..01d965e7bd6b92f 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -24,6 +24,7 @@
#include "lldb/Interpreter/CommandInterpreter.h"
#include <sstream>
#include <regex>
+#include <vector>
using namespace lldb;
using namespace lldb_private;
@@ -232,13 +233,14 @@ 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, CommandInterpreter *interpreter) {
- if (!name) {
+static void PrintRed(Stream *strm, const char *text, std::vector<std::pair<bool, const char*>> *info) {
+ if (!info) {
strm->PutCString(text);
return;
}
- bool use_color = interpreter->GetDebugger().GetUseColor();
+ const char* name = (*info)[0].second;
+ bool use_color = (*info)[0].first;
std::string str_text(text);
std::regex reg_name(name);
@@ -271,8 +273,7 @@ static void PrintRed(Stream *strm, const char *text, const char *name, CommandIn
// is passed to print addition iformation of the symbol
void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
- Target *target, const char *name,
- CommandInterpreter *interpreter) const {
+ Target *target, std::vector<std::pair<bool, const char*>> *info) const {
s->Printf("id = {0x%8.8x}", m_uid);
if (m_addr_range.GetBaseAddress().GetSection()) {
@@ -303,17 +304,17 @@ void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
// 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){
+ if (demangled && info){
s->Printf(", name=");
- PrintRed(s, demangled.AsCString(), name, interpreter);
+ PrintRed(s, demangled.AsCString(), info);
}
- else if(demangled && name == nullptr)
+ else if(demangled && info == nullptr)
s->Printf(", name=\"%s\"", demangled.AsCString());
- if (m_mangled.GetMangledName() && name){
+ if (m_mangled.GetMangledName() && info){
s->Printf(", mangled=");
- PrintRed(s, m_mangled.GetMangledName().AsCString(), name, interpreter);
+ PrintRed(s, m_mangled.GetMangledName().AsCString(), info);
}
- else if(m_mangled.GetMangledName() && name == nullptr)
+ else if(m_mangled.GetMangledName() && info == nullptr)
s->Printf(", mangled=\"%s\"", m_mangled.GetMangledName().AsCString());
}
diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp
index 553deed76833a66..063a8eca49e6c0c 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -29,6 +29,7 @@
#include "lldb/Interpreter/CommandInterpreter.h"
#include <sstream>
#include <regex>
+#include <vector>
using namespace lldb;
using namespace lldb_private;
@@ -75,13 +76,14 @@ 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, CommandInterpreter *interpreter) {
- if (!name) {
+static void PrintRed(Stream *strm, const char *text, std::vector<std::pair<bool, const char*>> *info) {
+ if (!info) {
strm->PutCString(text);
return;
}
-
- bool use_color = interpreter->GetDebugger().GetUseColor();
+
+ const char* name = (*info)[0].second;
+ bool use_color = (*info)[0].first;
std::string str_text(text);
std::regex reg_name(name);
@@ -115,7 +117,7 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
bool show_module, bool show_inlined_frames,
bool show_function_arguments,
bool show_function_name,
- const char* name, CommandInterpreter *interpreter) const {
+ std::vector<std::pair<bool, const char*>> *info) const {
bool dumped_something = false;
if (show_module && module_sp) {
if (show_fullpaths)
@@ -139,10 +141,10 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
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)
+ if (name_func && !info)
name_func.Dump(s);
- else if(name_func && name){
- PrintRed(s, name_func.GetCString(), name, interpreter);
+ else if(name_func && info){
+ PrintRed(s, name_func.GetCString(), info);
}
}
@@ -213,8 +215,8 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
s->PutCString("symbol stub for: ");
// 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, interpreter);
+ if(info){
+ PrintRed(s, symbol->GetName().GetStringRef().str().c_str(), info);
}
else
symbol->GetName().Dump(s);
@@ -242,8 +244,8 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
//===========================================================================
void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level,
- Target *target, const char* name,
- CommandInterpreter *interpreter) const {
+ Target *target,
+ std::vector<std::pair<bool, const char*>> *info) const {
if (module_sp) {
s->Indent(" Module: file = \"");
module_sp->GetFileSpec().Dump(s->AsRawOstream());
@@ -303,7 +305,7 @@ void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level,
if (symbol != nullptr) {
s->Indent(" Symbol: ");
- symbol->GetDescription(s, level, target, name, interpreter);
+ symbol->GetDescription(s, level, target, info);
s->EOL();
}
>From 05e00cdcb0d526037860bf54914542c1ff020491 Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100293 at lums.edu.pk>
Date: Thu, 2 Nov 2023 16:12:59 +0500
Subject: [PATCH 13/14] Single PrintRed formatting function
---
lldb/include/lldb/Core/Address.h | 3 ++
lldb/source/Commands/CommandObjectTarget.cpp | 51 +-------------------
lldb/source/Core/Address.cpp | 2 +-
lldb/source/Symbol/Symbol.cpp | 43 ++---------------
lldb/source/Symbol/SymbolContext.cpp | 43 ++---------------
5 files changed, 12 insertions(+), 130 deletions(-)
diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h
index a26562fa67d2292..cfe34ada7e89079 100644
--- a/lldb/include/lldb/Core/Address.h
+++ b/lldb/include/lldb/Core/Address.h
@@ -249,6 +249,9 @@ class Address {
uint32_t addr_byte_size = UINT32_MAX,
bool all_ranges = false,
std::vector<std::pair<bool, const char*>>* info = nullptr) const;
+
+ static void PrintRed(Stream *strm, const char *text,
+ std::vector<std::pair<bool, const char*>>* info = nullptr);
// bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,const char* name,
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 493067dcce70d81..a7d90076b158721 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -9,6 +9,7 @@
#include "CommandObjectTarget.h"
#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Address.h"
#include "lldb/Core/IOHandler.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
@@ -1522,44 +1523,6 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
return false;
}
-
-//===========================================================================================
-
-// This function is the one which colorizes the regex symbol searched
-static void PrintRed(Stream &strm, const char *text, std::vector<std::pair<bool, const char*>> *info) {
- if (!info) {
- strm.PutCString(text);
- return;
- }
-
- const char* name = (*info)[0].second;
- bool use_color = (*info)[0].first;
-
- std::string str_text(text);
- std::regex reg_name(name);
- std::sregex_iterator next(str_text.begin(), str_text.end(), reg_name);
- std::sregex_iterator end;
-
- std::string red_start = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.fg.red}", use_color);
- std::string reset_color = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.normal}", use_color);
-
- size_t last_pos = 0;
- while (next != end) {
- std::smatch match = *next;
- size_t prefix_len = match.position() - last_pos;
-
- strm.Write(text, prefix_len);
- strm.PutCString(red_start.c_str());
- strm.Write(text + match.position(), match.length());
- strm.PutCString(reset_color.c_str());
-
- last_pos = match.position() + match.length();
- ++next;
- }
-
- strm.PutCString(text + last_pos); // Print any remaining text
-}
-
//===========================================================================================
static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
Stream &strm, Module *module,
@@ -1578,10 +1541,6 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
bool use_color = interpreter.GetDebugger().GetUseColor();
info.push_back(std::make_pair(use_color, name));
- // if (!info.empty()) {
- // printf("Bool Value: %d, Char Value: %s\n", info[0].first, info[0].second);
- // }
-
std::vector<uint32_t> match_indexes;
ConstString symbol_name(name);
uint32_t num_matches = 0;
@@ -1594,12 +1553,6 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
symtab->AppendSymbolIndexesWithName(symbol_name, match_indexes);
}
- // for (uint32_t i = 0; i < match_indexes.size(); ++i) {
- // printf("%d", match_indexes[i]);
- // printf(", ");
- // }
- // printf("\n");
-
if (num_matches > 0) {
strm.Indent();
strm.Printf("%u symbols match %s'%s' in ", num_matches,
@@ -1621,7 +1574,7 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
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(), &info);
+ Address::PrintRed(&strm, symbol->GetDisplayName().GetStringRef().str().c_str(), &info);
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 5743fa261f14da7..ca6e2cc08dba280 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -410,7 +410,7 @@ bool Address::GetDescription(Stream &s, Target &target,
//==================================================================================
// Function to print the searched symbol in red color
-static void PrintRed(Stream *strm, const char *text, std::vector<std::pair<bool, const char*>>* info = nullptr) {
+void Address::PrintRed(Stream *strm, const char *text, std::vector<std::pair<bool, const char*>>* info){
if (!info) {
strm->PutCString(text);
return;
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index 01d965e7bd6b92f..5fea38d81aef3a0 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -9,6 +9,7 @@
#include "lldb/Symbol/Symbol.h"
#include "lldb/Core/Module.h"
+#include "lldb/Core/Address.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/Section.h"
#include "lldb/Symbol/Function.h"
@@ -229,44 +230,6 @@ bool Symbol::IsTrampoline() const { return m_type == eSymbolTypeTrampoline; }
bool Symbol::IsIndirect() const { return m_type == eSymbolTypeResolver; }
-
-//=======================================================================
-
-// Similar to the other modules, using PrintRed function.
-static void PrintRed(Stream *strm, const char *text, std::vector<std::pair<bool, const char*>> *info) {
- if (!info) {
- strm->PutCString(text);
- return;
- }
-
- const char* name = (*info)[0].second;
- bool use_color = (*info)[0].first;
-
- std::string str_text(text);
- std::regex reg_name(name);
- std::sregex_iterator next(str_text.begin(), str_text.end(), reg_name);
- std::sregex_iterator end;
-
- std::string red_start = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.fg.red}", use_color);
- std::string reset_color = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.normal}", use_color);
-
- size_t last_pos = 0;
- while (next != end) {
- std::smatch match = *next;
- size_t prefix_len = match.position() - last_pos;
-
- strm->Write(text, prefix_len);
- strm->PutCString(red_start.c_str());
- strm->Write(text + match.position(), match.length());
- strm->PutCString(reset_color.c_str());
-
- last_pos = match.position() + match.length();
- ++next;
- }
-
- strm->PutCString(text + last_pos); // Print any remaining text
-}
-
//========================================================================
// For the image lookup command, This function is called when verbose flag
@@ -306,13 +269,13 @@ void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
// In that case, we use the PrintRed function to colorize the symbol.
if (demangled && info){
s->Printf(", name=");
- PrintRed(s, demangled.AsCString(), info);
+ Address::PrintRed(s, demangled.AsCString(), info);
}
else if(demangled && info == nullptr)
s->Printf(", name=\"%s\"", demangled.AsCString());
if (m_mangled.GetMangledName() && info){
s->Printf(", mangled=");
- PrintRed(s, m_mangled.GetMangledName().AsCString(), info);
+ Address::PrintRed(s, m_mangled.GetMangledName().AsCString(), info);
}
else if(m_mangled.GetMangledName() && info == nullptr)
s->Printf(", mangled=\"%s\"", m_mangled.GetMangledName().AsCString());
diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp
index 063a8eca49e6c0c..0ca2673f9d8774d 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -9,6 +9,7 @@
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Address.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Host/Host.h"
@@ -74,44 +75,6 @@ void SymbolContext::Clear(bool clear_target) {
//===========================================================================
-// Similar to the other modules, using PrintRed function.
-
-static void PrintRed(Stream *strm, const char *text, std::vector<std::pair<bool, const char*>> *info) {
- if (!info) {
- strm->PutCString(text);
- return;
- }
-
- const char* name = (*info)[0].second;
- bool use_color = (*info)[0].first;
-
- std::string str_text(text);
- std::regex reg_name(name);
- std::sregex_iterator next(str_text.begin(), str_text.end(), reg_name);
- std::sregex_iterator end;
-
- std::string red_start = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.fg.red}", use_color);
- std::string reset_color = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.normal}", use_color);
-
- size_t last_pos = 0;
- while (next != end) {
- std::smatch match = *next;
- size_t prefix_len = match.position() - last_pos;
-
- strm->Write(text, prefix_len);
- strm->PutCString(red_start.c_str());
- strm->Write(text + match.position(), match.length());
- strm->PutCString(reset_color.c_str());
-
- last_pos = match.position() + match.length();
- ++next;
- }
-
- strm->PutCString(text + last_pos); // 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,
@@ -144,7 +107,7 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
if (name_func && !info)
name_func.Dump(s);
else if(name_func && info){
- PrintRed(s, name_func.GetCString(), info);
+ Address::PrintRed(s, name_func.GetCString(), info);
}
}
@@ -216,7 +179,7 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
// Similar here, Using PrintRed if the function is called by regex symbol search command
if(info){
- PrintRed(s, symbol->GetName().GetStringRef().str().c_str(), info);
+ Address::PrintRed(s, symbol->GetName().GetStringRef().str().c_str(), info);
}
else
symbol->GetName().Dump(s);
>From 7a6ede9811ee9065591d45898428540cb3c9da23 Mon Sep 17 00:00:00 2001
From: taalhaataahir0102 <23100293 at lums.edu.pk>
Date: Mon, 6 Nov 2023 14:05:37 +0500
Subject: [PATCH 14/14] updated use-color
---
lldb/include/lldb/Core/Address.h | 7 ++-
lldb/include/lldb/Symbol/Symbol.h | 2 +-
lldb/include/lldb/Symbol/SymbolContext.h | 4 +-
lldb/source/Commands/CommandObjectTarget.cpp | 34 ++++++++++----
lldb/source/Core/Address.cpp | 47 +++++++++----------
lldb/source/Symbol/Symbol.cpp | 16 +++----
lldb/source/Symbol/SymbolContext.cpp | 22 ++++-----
.../test/Shell/Commands/ImageLookupColor.test | 25 ++++++++++
8 files changed, 95 insertions(+), 62 deletions(-)
create mode 100644 lldb/test/Shell/Commands/ImageLookupColor.test
diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h
index cfe34ada7e89079..fea3ba467e8dc9b 100644
--- a/lldb/include/lldb/Core/Address.h
+++ b/lldb/include/lldb/Core/Address.h
@@ -247,11 +247,10 @@ 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,
- std::vector<std::pair<bool, const char*>>* info = nullptr) const;
+ bool all_ranges = false, const char *name = nullptr) const;
- static void PrintRed(Stream *strm, const char *text,
- std::vector<std::pair<bool, const char*>>* info = nullptr);
+ static void re_pattern(Stream *strm, const char *text,
+ const char *name = nullptr);
// bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,const char* name,
diff --git a/lldb/include/lldb/Symbol/Symbol.h b/lldb/include/lldb/Symbol/Symbol.h
index 3f10cd2c33c08fc..0084aec8b67a7ea 100644
--- a/lldb/include/lldb/Symbol/Symbol.h
+++ b/lldb/include/lldb/Symbol/Symbol.h
@@ -181,7 +181,7 @@ class Symbol : public SymbolContextScope {
// This argument is the regex symbol searched.
void GetDescription(Stream *s, lldb::DescriptionLevel level,
Target *target,
- std::vector<std::pair<bool, const char*>> *info = nullptr) const;
+ 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 682e13fd5fde0db..db050bc43c0239a 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -154,7 +154,7 @@ class SymbolContext {
bool show_module, bool show_inlined_frames,
bool show_function_arguments,
bool show_function_name,
- std::vector<std::pair<bool, const char*>>* info = nullptr) const;
+ const char *name = nullptr) const;
/// Get the address range contained within a symbol context.
@@ -224,7 +224,7 @@ class SymbolContext {
void GetDescription(Stream *s, lldb::DescriptionLevel level,
Target *target,
- std::vector<std::pair<bool, const char*>>* info = nullptr) const;
+ const char *name = nullptr) const;
uint32_t GetResolvedMask() const;
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index a7d90076b158721..a621017e92283a2 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1472,8 +1472,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,
- std::vector<std::pair<bool, const char*>>* info = nullptr) {
+ Stream &strm, const char *name = nullptr) {
strm.IndentMore();
strm.Indent(" Address: ");
so_addr.Dump(&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
@@ -1485,13 +1484,18 @@ static void DumpAddress(ExecutionContextScope *exe_scope,
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, Address::DumpStyleInvalid, UINT32_MAX, false, info);
+ 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) {
+ if (verbose && name) {
strm.EOL();
so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext,
- Address::DumpStyleInvalid, UINT32_MAX, all_ranges, info);
+ Address::DumpStyleInvalid, UINT32_MAX, all_ranges, name);
+ }
+ else if(verbose){
+ strm.EOL();
+ so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext,
+ Address::DumpStyleInvalid, UINT32_MAX, all_ranges);
}
strm.IndentLess();
}
@@ -1537,9 +1541,7 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
SymbolContext sc;
- std::vector<std::pair<bool, const char*>> info;
bool use_color = interpreter.GetDebugger().GetUseColor();
- info.push_back(std::make_pair(use_color, name));
std::vector<uint32_t> match_indexes;
ConstString symbol_name(name);
@@ -1565,16 +1567,28 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
if (symbol) {
if (symbol->ValueIsAddress()) {
// Using the new dump function to add colors in the summary.
+ if (name && use_color){
DumpAddress(
interpreter.GetExecutionContext().GetBestExecutionContextScope(),
- symbol->GetAddressRef(), verbose, all_ranges, strm, &info);
+ symbol->GetAddressRef(), verbose, all_ranges, strm, name);
+ }
+ else{
+ DumpAddress(
+ interpreter.GetExecutionContext().GetBestExecutionContextScope(),
+ symbol->GetAddressRef(), verbose, all_ranges, strm);
+ }
strm.EOL();
} else {
strm.IndentMore();
strm.Indent(" Name: ");
// strm.PutCString(symbol->GetDisplayName().GetStringRef());
- // Using the PrintRed function to colorize the searched symbol.
- Address::PrintRed(&strm, symbol->GetDisplayName().GetStringRef().str().c_str(), &info);
+ // Using the re_pattern function to colorize the searched symbol.
+ if (name && use_color){
+ Address::re_pattern(&strm, symbol->GetDisplayName().GetStringRef().str().c_str(), name);
+ }
+ else{
+ strm.PutCString(symbol->GetDisplayName().GetStringRef());
+ }
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 ca6e2cc08dba280..a2595ac26eaee85 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -410,25 +410,22 @@ bool Address::GetDescription(Stream &s, Target &target,
//==================================================================================
// Function to print the searched symbol in red color
-void Address::PrintRed(Stream *strm, const char *text, std::vector<std::pair<bool, const char*>>* info){
- if (!info) {
+void Address::re_pattern(Stream *strm, const char *text, const char *name) {
+ if (!name) {
strm->PutCString(text);
return;
}
- const char* name = (*info)[0].second;
- bool use_color = (*info)[0].first;
-
std::string str_text(text);
std::regex reg_name(name);
std::sregex_iterator next(str_text.begin(), str_text.end(), reg_name);
std::sregex_iterator end;
- std::string red_start = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.fg.red}", use_color);
- std::string reset_color = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.normal}", use_color);
+ std::string red_start = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.fg.red}");
+ std::string reset_color = lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.normal}");
size_t last_pos = 0;
- while (next != end) {
+ for (; next != end; ++next) {
std::smatch match = *next;
size_t prefix_len = match.position() - last_pos;
@@ -438,11 +435,11 @@ void Address::PrintRed(Stream *strm, const char *text, std::vector<std::pair<boo
strm->PutCString(reset_color.c_str());
last_pos = match.position() + match.length();
- ++next;
}
strm->PutCString(text + last_pos); // Print any remaining text
}
+
//==================================================================================
// Similar to the DumpAddress function inside CommandObjectTarget.cpp, we've updated this Dump function
@@ -451,7 +448,7 @@ void Address::PrintRed(Stream *strm, const char *text, std::vector<std::pair<boo
bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
DumpStyle fallback_style, uint32_t addr_size,
- bool all_ranges, std::vector<std::pair<bool, const char*>>* info) 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());
@@ -561,9 +558,9 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
if (symbol) {
const char *symbol_name = symbol->GetName().AsCString();
if (symbol_name) {
- // Using the PrintRed function to colorize the symbol if name not equal to nullptr
- if(info){
- PrintRed(s, symbol_name, info);
+ // Using the re_pattern function to colorize the symbol if name not equal to nullptr
+ if(name){
+ re_pattern(s, symbol_name, name);
}
else{
s->PutCString(symbol_name);
@@ -695,7 +692,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
pointer_sc.symbol != nullptr) {
s->PutCString(": ");
pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false,
- false, true, true, info);
+ false, true, true, name);
}
}
}
@@ -733,10 +730,10 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
// We have a function or a symbol from the same sections as this
// address.
// Using the same logic, hecking if searched symbol passed to this function or if it using the defualt nullptr
- if(info)
+ if(name)
sc.DumpStopContext(s, exe_scope, *this, show_fullpaths,
show_module, show_inlined_frames,
- show_function_arguments, show_function_name, info);
+ show_function_arguments, show_function_name, name);
else
sc.DumpStopContext(s, exe_scope, *this, show_fullpaths,
show_module, show_inlined_frames,
@@ -745,14 +742,14 @@ 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
- Dump(s, exe_scope, DumpStyleSectionNameOffset, DumpStyleInvalid, UINT32_MAX, false, info);
+ Dump(s, exe_scope, DumpStyleSectionNameOffset, DumpStyleInvalid, UINT32_MAX, false, name);
}
}
}
}
} else {
if(fallback_style != DumpStyleInvalid){
- return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, info);
+ return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, name);
}
return false;
}
@@ -774,7 +771,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
sc.symbol->GetAddressRef().GetSection() != GetSection())
sc.symbol = nullptr;
}
- sc.GetDescription(s, eDescriptionLevelBrief, target, info);
+ sc.GetDescription(s, eDescriptionLevelBrief, target, name);
if (sc.block) {
bool can_create = true;
@@ -821,10 +818,10 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
}
}
} else {
- if (fallback_style != DumpStyleInvalid && !info)
+ if (fallback_style != DumpStyleInvalid && !name)
return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
- else if(fallback_style != DumpStyleInvalid && info){
- return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, info);
+ else if(fallback_style != DumpStyleInvalid && name){
+ return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, name);
}
return false;
}
@@ -855,10 +852,10 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
}
}
}
- if (fallback_style != DumpStyleInvalid && !info)
+ if (fallback_style != DumpStyleInvalid && !name)
return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
- else if(fallback_style != DumpStyleInvalid && info)
- return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, info);
+ else if(fallback_style != DumpStyleInvalid && name)
+ return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, name);
return false;
} break;
}
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index 5fea38d81aef3a0..a64da0d02432366 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -236,7 +236,7 @@ bool Symbol::IsIndirect() const { return m_type == eSymbolTypeResolver; }
// is passed to print addition iformation of the symbol
void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
- Target *target, std::vector<std::pair<bool, const char*>> *info) const {
+ Target *target, const char *name) const {
s->Printf("id = {0x%8.8x}", m_uid);
if (m_addr_range.GetBaseAddress().GetSection()) {
@@ -266,18 +266,18 @@ void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
ConstString demangled = GetMangled().GetDemangledName();
// 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 && info){
+ // In that case, we use the re_pattern function to colorize the symbol.
+ if (demangled && name){
s->Printf(", name=");
- Address::PrintRed(s, demangled.AsCString(), info);
+ Address::re_pattern(s, demangled.AsCString(), name);
}
- else if(demangled && info == nullptr)
+ else if(demangled && name == nullptr)
s->Printf(", name=\"%s\"", demangled.AsCString());
- if (m_mangled.GetMangledName() && info){
+ if (m_mangled.GetMangledName() && name){
s->Printf(", mangled=");
- Address::PrintRed(s, m_mangled.GetMangledName().AsCString(), info);
+ Address::re_pattern(s, m_mangled.GetMangledName().AsCString(), name);
}
- else if(m_mangled.GetMangledName() && info == nullptr)
+ 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 0ca2673f9d8774d..f554408dbeb1c6a 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -79,8 +79,7 @@ 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,
- std::vector<std::pair<bool, const char*>> *info) const {
+ bool show_function_name, const char *name) const {
bool dumped_something = false;
if (show_module && module_sp) {
if (show_fullpaths)
@@ -103,11 +102,11 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
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 && !info)
+ // Using re_pattern 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 && info){
- Address::PrintRed(s, name_func.GetCString(), info);
+ else if(name_func && name){
+ Address::re_pattern(s, name_func.GetCString(), name);
}
}
@@ -177,9 +176,9 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
if (symbol->GetType() == eSymbolTypeTrampoline)
s->PutCString("symbol stub for: ");
- // Similar here, Using PrintRed if the function is called by regex symbol search command
- if(info){
- Address::PrintRed(s, symbol->GetName().GetStringRef().str().c_str(), info);
+ // Similar here, Using re_pattern if the function is called by regex symbol search command
+ if(name){
+ Address::re_pattern(s, symbol->GetName().GetStringRef().str().c_str(), name);
}
else
symbol->GetName().Dump(s);
@@ -207,8 +206,7 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
//===========================================================================
void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level,
- Target *target,
- std::vector<std::pair<bool, const char*>> *info) const {
+ Target *target,const char *name) const {
if (module_sp) {
s->Indent(" Module: file = \"");
module_sp->GetFileSpec().Dump(s->AsRawOstream());
@@ -268,7 +266,7 @@ void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level,
if (symbol != nullptr) {
s->Indent(" Symbol: ");
- symbol->GetDescription(s, level, target, info);
+ symbol->GetDescription(s, level, target, name);
s->EOL();
}
diff --git a/lldb/test/Shell/Commands/ImageLookupColor.test b/lldb/test/Shell/Commands/ImageLookupColor.test
new file mode 100644
index 000000000000000..c34feb14acc30ac
--- /dev/null
+++ b/lldb/test/Shell/Commands/ImageLookupColor.test
@@ -0,0 +1,25 @@
+# RUN: %clang_host -g %S/Inputs/main.c -o %t
+
+# Checking simple search
+
+# RUN: %lldb %t -b -o 'settings set use-color true' -o 'image lookup -r -s ma' | FileCheck %s --check-prefix CHECK1
+# CHECK1: Name: {{.+}}31mma{{.+}}0min.c
+# CHECK1: Summary: {{.+}}`{{.+}}31mma{{.+}}0min at main.c:2
+
+# Checking for regex searches
+
+# RUN: %lldb %t -b -o 'settings set use-color true' -o 'image lookup -r -s main.c|foo' | FileCheck %s --check-prefix CHECK2
+# CHECK2: Name: {{.+}}31mmain.c{{.+}}0m
+# CHECK2: Summary: {{.+}}`{{.+}}31mfoo{{.+}}0m at main.c:1
+
+# RUN: %lldb %t -b -o 'settings set use-color true' -o 'image lookup -r -s m[abc]' | FileCheck %s --check-prefix CHECK3
+# CHECK3: Name: {{.+}}31mma{{.+}}0min.c
+# CHECK3: Summary: {{.+}}`{{.+}}31mma{{.+}}0min at main.c:2
+
+# Checking tail match
+
+# RUN: %lldb %t -b -o 'settings set use-color true' -o 'image lookup -r -s .*o$' | FileCheck %s --check-prefix CHECK4
+# CHECK4: Summary: {{.+}}`{{.+}}31mfoo{{.+}}0m at main.c:1
+
+# RUN: %lldb %t -b -o 'settings set use-color true' -o 'image lookup -r -s .*o132we$' | FileCheck %s --check-prefix CHECK5
+# CHECK5-EMPTY:
\ No newline at end of file
More information about the lldb-commits
mailing list