[Lldb-commits] [lldb] db98ac0 - [Demangle] convert microsoftDemangle to take a std::string_view

Nick Desaulniers via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 5 13:01:21 PDT 2023


Author: Nick Desaulniers
Date: 2023-06-05T13:00:20-07:00
New Revision: db98ac082744880a6e352b2d4a97d8896d9a7694

URL: https://github.com/llvm/llvm-project/commit/db98ac082744880a6e352b2d4a97d8896d9a7694
DIFF: https://github.com/llvm/llvm-project/commit/db98ac082744880a6e352b2d4a97d8896d9a7694.diff

LOG: [Demangle] convert microsoftDemangle to take a std::string_view

This should be last of the "bottom-up conversions" of various demanglers
to accept std::string_view.  After this, D149104 may be revisited.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D152176

Added: 
    

Modified: 
    lldb/source/Core/Mangled.cpp
    llvm/include/llvm/Demangle/Demangle.h
    llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
    llvm/lib/Demangle/MicrosoftDemangle.cpp
    llvm/tools/llvm-objdump/COFFDump.cpp
    llvm/tools/llvm-undname/llvm-undname.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp
index 3294b246ae743..d1973a9a8f7f6 100644
--- a/lldb/source/Core/Mangled.cpp
+++ b/lldb/source/Core/Mangled.cpp
@@ -107,7 +107,7 @@ void Mangled::SetValue(ConstString name) {
 }
 
 // Local helpers for 
diff erent demangling implementations.
-static char *GetMSVCDemangledStr(const char *M) {
+static char *GetMSVCDemangledStr(std::string_view M) {
   char *demangled_cstr = llvm::microsoftDemangle(
       M, nullptr, nullptr,
       llvm::MSDemangleFlags(
@@ -116,9 +116,9 @@ static char *GetMSVCDemangledStr(const char *M) {
 
   if (Log *log = GetLog(LLDBLog::Demangle)) {
     if (demangled_cstr && demangled_cstr[0])
-      LLDB_LOGF(log, "demangled msvc: %s -> \"%s\"", M, demangled_cstr);
+      LLDB_LOGF(log, "demangled msvc: %s -> \"%s\"", M.data(), demangled_cstr);
     else
-      LLDB_LOGF(log, "demangled msvc: %s -> error", M);
+      LLDB_LOGF(log, "demangled msvc: %s -> error", M.data());
   }
 
   return demangled_cstr;
@@ -204,7 +204,7 @@ bool Mangled::GetRichManglingInfo(RichManglingContext &context,
     // We have no rich mangling for MSVC-mangled names yet, so first try to
     // demangle it if necessary.
     if (!m_demangled && !m_mangled.GetMangledCounterpart(m_demangled)) {
-      if (char *d = GetMSVCDemangledStr(m_mangled.GetCString())) {
+      if (char *d = GetMSVCDemangledStr(m_mangled)) {
         // Without the rich mangling info we have to demangle the full name.
         // Copy it to string pool and connect the counterparts to accelerate
         // later access in GetDemangledName().

diff  --git a/llvm/include/llvm/Demangle/Demangle.h b/llvm/include/llvm/Demangle/Demangle.h
index d9b830c660047..9140c94ac3cc0 100644
--- a/llvm/include/llvm/Demangle/Demangle.h
+++ b/llvm/include/llvm/Demangle/Demangle.h
@@ -51,8 +51,8 @@ enum MSDemangleFlags {
 /// bytes of the input string were consumed.
 /// status receives one of the demangle_ enum entries above if it's not nullptr.
 /// Flags controls various details of the demangled representation.
-char *microsoftDemangle(const char *mangled_name, size_t *n_read, int *status,
-                        MSDemangleFlags Flags = MSDF_None);
+char *microsoftDemangle(std::string_view mangled_name, size_t *n_read,
+                        int *status, MSDemangleFlags Flags = MSDF_None);
 
 // Demangles a Rust v0 mangled symbol.
 char *rustDemangle(std::string_view MangledName);

diff  --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
index aaee4f11af446..459baf7b83640 100644
--- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
@@ -686,7 +686,7 @@ LLVMSymbolizer::DemangleName(const std::string &Name,
     // Only do MSVC C++ demangling on symbols starting with '?'.
     int status = 0;
     char *DemangledName = microsoftDemangle(
-        Name.c_str(), nullptr, &status,
+        Name, nullptr, &status,
         MSDemangleFlags(MSDF_NoAccessSpecifier | MSDF_NoCallingConvention |
                         MSDF_NoMemberType | MSDF_NoReturnType));
     if (status != 0)

diff  --git a/llvm/lib/Demangle/MicrosoftDemangle.cpp b/llvm/lib/Demangle/MicrosoftDemangle.cpp
index c3713a7dbd3ad..b38b8a1e479da 100644
--- a/llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ b/llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -2397,14 +2397,14 @@ void Demangler::dumpBackReferences() {
     std::printf("\n");
 }
 
-char *llvm::microsoftDemangle(const char *MangledName, size_t *NMangled,
+char *llvm::microsoftDemangle(std::string_view MangledName, size_t *NMangled,
                               int *Status, MSDemangleFlags Flags) {
   Demangler D;
 
   std::string_view Name{MangledName};
   SymbolNode *AST = D.parse(Name);
   if (!D.Error && NMangled)
-    *NMangled = Name.empty() ? 0 : &*Name.begin() - MangledName;
+    *NMangled = Name.empty() ? 0 : &*Name.begin() - &*MangledName.begin();
 
   if (Flags & MSDF_DumpBackrefs)
     D.dumpBackReferences();

diff  --git a/llvm/tools/llvm-objdump/COFFDump.cpp b/llvm/tools/llvm-objdump/COFFDump.cpp
index a7052cb3fb3cd..b1beedcc324ce 100644
--- a/llvm/tools/llvm-objdump/COFFDump.cpp
+++ b/llvm/tools/llvm-objdump/COFFDump.cpp
@@ -852,7 +852,7 @@ void objdump::printCOFFSymbolTable(const COFFObjectFile &coff) {
            << Name;
     if (Demangle && Name.startswith("?")) {
       int Status = -1;
-      char *DemangledSymbol = microsoftDemangle(Name.data(), nullptr, &Status);
+      char *DemangledSymbol = microsoftDemangle(Name, nullptr, &Status);
 
       if (Status == 0 && DemangledSymbol) {
         outs() << " (" << StringRef(DemangledSymbol) << ")";

diff  --git a/llvm/tools/llvm-undname/llvm-undname.cpp b/llvm/tools/llvm-undname/llvm-undname.cpp
index 915ae219d7649..96f031abe9c1f 100644
--- a/llvm/tools/llvm-undname/llvm-undname.cpp
+++ b/llvm/tools/llvm-undname/llvm-undname.cpp
@@ -75,7 +75,7 @@ static bool msDemangle(const std::string &S) {
     Flags = MSDemangleFlags(Flags | MSDF_NoVariableType);
 
   size_t NRead;
-  char *ResultBuf = microsoftDemangle(S.c_str(), &NRead, &Status, Flags);
+  char *ResultBuf = microsoftDemangle(S, &NRead, &Status, Flags);
   if (Status == llvm::demangle_success) {
     outs() << ResultBuf << "\n";
     outs().flush();


        


More information about the lldb-commits mailing list