[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 17 23:51:06 PDT 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 112e49b38150b8bfdef01434309d1b05204193e4 07e3a614c1a346c3a09dbf232328b83b744750b2 -- lldb/include/lldb/Core/Address.h lldb/include/lldb/Symbol/Symbol.h lldb/include/lldb/Symbol/SymbolContext.h lldb/source/Commands/CommandObjectTarget.cpp lldb/source/Core/Address.cpp lldb/source/Symbol/Symbol.cpp lldb/source/Symbol/SymbolContext.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/lldb/include/lldb/Core/Address.h b/lldb/include/lldb/Core/Address.h
index 4151817813c7..92355e88c6ea 100644
--- a/lldb/include/lldb/Core/Address.h
+++ b/lldb/include/lldb/Core/Address.h
@@ -249,9 +249,8 @@ public:
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,
+ 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;
diff --git a/lldb/include/lldb/Symbol/Symbol.h b/lldb/include/lldb/Symbol/Symbol.h
index a9e91fbac055..43aceeb0a2aa 100644
--- a/lldb/include/lldb/Symbol/Symbol.h
+++ b/lldb/include/lldb/Symbol/Symbol.h
@@ -177,8 +177,8 @@ public:
void GetDescription(Stream *s, lldb::DescriptionLevel level,
Target *target) const;
- void GetDescription(Stream *s, lldb::DescriptionLevel level,
- Target *target, const char* name) const;
+ void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target,
+ const char *name) 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 947c39eec96e..2ac5f4162c52 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -156,10 +156,8 @@ public:
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_arguments, bool show_function_name,
+ const char *name) const;
/// Get the address range contained within a symbol context.
///
@@ -228,8 +226,8 @@ public:
void GetDescription(Stream *s, lldb::DescriptionLevel level,
Target *target) const;
- void GetDescription(Stream *s, lldb::DescriptionLevel level,
- Target *target, const char* name) const;
+ void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target,
+ const char *name) const;
uint32_t GetResolvedMask() const;
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 8086474a32a9..dd833a57ddbf 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -56,6 +56,7 @@
#include "lldb/lldb-enumerations.h"
#include "lldb/lldb-private-enumerations.h"
+#include "lldb/Utility/AnsiTerminal.h"
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
@@ -63,7 +64,6 @@
#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;
@@ -1518,30 +1518,32 @@ 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) {
- 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;
-
- 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;
- }
+ 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;
- strm.PutCString(text); // Print any remaining 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;
+ }
+
+ 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.
+// 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) {
@@ -1554,15 +1556,15 @@ 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.
+ // 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);
+ so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext,
+ name, Address::DumpStyleInvalid, UINT32_MAX, all_ranges);
}
strm.IndentLess();
}
@@ -1613,7 +1615,8 @@ 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(), name);
+ 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 86f37ac5d7f5..cbab1a3ca6c3 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -36,10 +36,10 @@
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/StreamString.h"
+#include "lldb/Utility/AnsiTerminal.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include "llvm/TargetParser/Triple.h"
-#include "lldb/Utility/AnsiTerminal.h"
#include <cstdint>
#include <memory>
@@ -804,39 +804,41 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
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;
-
- 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;
- }
+ 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;
+
+ strm->Write(text, prefix_len);
+ strm->PutCString(red_start.c_str());
+ strm->Write(match, name_len);
+ strm->PutCString(reset_color.c_str());
- strm->PutCString(text); // Print any remaining text
+ 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.
+// 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,
- bool all_ranges) const {
+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());
@@ -902,7 +904,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
* 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();
@@ -1115,7 +1117,8 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
// address.
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);
} 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
@@ -1127,7 +1130,8 @@ 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);
+ return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size,
+ name);
return false;
}
break;
@@ -1196,7 +1200,8 @@ 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);
+ return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size,
+ name);
return false;
}
break;
@@ -1227,7 +1232,8 @@ 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);
+ return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size,
+ name);
return false;
} break;
}
@@ -1235,7 +1241,6 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
return true;
}
-
//==================================================================================
bool Address::SectionWasDeleted() const {
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index ad07426192bb..63f1ff05fe6b 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -17,10 +17,10 @@
#include "lldb/Symbol/Symtab.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
+#include "lldb/Utility/AnsiTerminal.h"
#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;
@@ -226,38 +226,39 @@ bool Symbol::IsTrampoline() const { return m_type == eSymbolTypeTrampoline; }
bool Symbol::IsIndirect() const { return m_type == eSymbolTypeResolver; }
-
//=======================================================================
// Similar to the other 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;
-
- 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;
- }
+ 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;
- strm->PutCString(text); // Print any remaining text
-}
+ 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());
-// 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.
+ text = match + name_len;
+ match = text;
+ }
+
+ 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 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,12 +286,12 @@ void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
m_addr_range.GetBaseAddress().GetOffset());
}
ConstString demangled = GetMangled().GetDemangledName();
- if (demangled){
+ if (demangled) {
// s->Printf(", name=\"%s\"", demangled.AsCString());
s->Printf(", name=");
PrintRed(s, demangled.AsCString(), name);
}
- if (m_mangled.GetMangledName()){
+ if (m_mangled.GetMangledName()) {
// s->Printf(", mangled=\"%s\"", m_mangled.GetMangledName().AsCString());
s->Printf(", mangled=");
PrintRed(s, m_mangled.GetMangledName().AsCString(), name);
@@ -299,7 +300,6 @@ void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level,
//========================================================================
-
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 084d7a4659cc..55011976fef0 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -21,11 +21,11 @@
#include "lldb/Symbol/Variable.h"
#include "lldb/Target/Language.h"
#include "lldb/Target/Target.h"
+#include "lldb/Utility/AnsiTerminal.h"
#include "lldb/Utility/LLDBLog.h"
#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;
@@ -187,31 +187,32 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
return dumped_something;
}
-
//===========================================================================
// Similar to the other 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;
-
- 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;
- }
+ 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);
- strm->PutCString(text); // Print any remaining text
+ 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;
+ }
+
+ strm->PutCString(text); // Print any remaining text
}
bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
@@ -219,7 +220,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) const {
bool dumped_something = false;
if (show_module && module_sp) {
if (show_fullpaths)
@@ -242,9 +243,9 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
name1 = function->GetNameNoArguments();
if (!name1)
name1 = function->GetName();
- if (name1){
+ if (name1) {
// name.Dump(s);
- PrintRed(s, name1.GetCString() , name);
+ PrintRed(s, name1.GetCString(), name);
}
}
@@ -336,9 +337,8 @@ 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 {
+ Target *target, const char *name) const {
if (module_sp) {
s->Indent(" Module: file = \"");
module_sp->GetFileSpec().Dump(s->AsRawOstream());
``````````
</details>
https://github.com/llvm/llvm-project/pull/69422
More information about the lldb-commits
mailing list