<div dir="ltr">Any particular reason this has the word Itanium baked into the name of the class and description?  MSVC doesn't use the Itanium ABI, but but AFAICT from looking at this code, it should work for MSVC's abi as well.  <div><br></div><div>Sicne this command isn't actually Itanium ABI specific, I don't think it should make references to Itanium ABI in its C++ class name or help / description</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Mar 25, 2016 at 4:19 PM Enrico Granata via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: enrico<br>
Date: Fri Mar 25 18:14:24 2016<br>
New Revision: 264474<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=264474&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=264474&view=rev</a><br>
Log:<br>
Add a 'language cplusplus demangle' command. This can be useful to provide a low-friction reproduction for issues with the LLDB demangling of C++ symbols<br>
<br>
Modified:<br>
    lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp<br>
<br>
Modified: lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp?rev=264474&r1=264473&r2=264474&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp?rev=264474&r1=264473&r2=264474&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp (original)<br>
+++ lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp Fri Mar 25 18:14:24 2016<br>
@@ -13,11 +13,15 @@<br>
 #include "lldb/Core/ConstString.h"<br>
 #include "lldb/Core/Error.h"<br>
 #include "lldb/Core/Log.h"<br>
+#include "lldb/Core/Mangled.h"<br>
 #include "lldb/Core/Module.h"<br>
 #include "lldb/Core/PluginManager.h"<br>
 #include "lldb/Core/Scalar.h"<br>
 #include "lldb/Core/ValueObject.h"<br>
 #include "lldb/Core/ValueObjectMemory.h"<br>
+#include "lldb/Interpreter/CommandObject.h"<br>
+#include "lldb/Interpreter/CommandObjectMultiword.h"<br>
+#include "lldb/Interpreter/CommandReturnObject.h"<br>
 #include "lldb/Symbol/ClangASTContext.h"<br>
 #include "lldb/Symbol/Symbol.h"<br>
 #include "lldb/Symbol/SymbolFile.h"<br>
@@ -340,12 +344,96 @@ ItaniumABILanguageRuntime::CreateInstanc<br>
         return NULL;<br>
 }<br>
<br>
+class CommandObjectMultiwordItaniumABI_Demangle : public CommandObjectParsed<br>
+{<br>
+public:<br>
+    CommandObjectMultiwordItaniumABI_Demangle (CommandInterpreter &interpreter) :<br>
+    CommandObjectParsed (interpreter,<br>
+                         "demangle",<br>
+                         "Demangle a C++ mangled name.",<br>
+                         "language cplusplus demangle")<br>
+    {<br>
+        CommandArgumentEntry arg;<br>
+        CommandArgumentData index_arg;<br>
+<br>
+        // Define the first (and only) variant of this arg.<br>
+        index_arg.arg_type = eArgTypeSymbol;<br>
+        index_arg.arg_repetition = eArgRepeatPlus;<br>
+<br>
+        // There is only one variant this argument could be; put it into the argument entry.<br>
+        arg.push_back (index_arg);<br>
+<br>
+        // Push the data for the first argument into the m_arguments vector.<br>
+        m_arguments.push_back (arg);<br>
+    }<br>
+<br>
+    ~CommandObjectMultiwordItaniumABI_Demangle() override = default;<br>
+<br>
+protected:<br>
+    bool<br>
+    DoExecute(Args& command, CommandReturnObject &result) override<br>
+    {<br>
+        bool demangled_any = false;<br>
+        bool error_any = false;<br>
+        for (size_t i = 0; i < command.GetArgumentCount(); i++)<br>
+        {<br>
+            auto arg = command.GetArgumentAtIndex(i);<br>
+            if (arg && *arg)<br>
+            {<br>
+                ConstString mangled_cs(arg);<br>
+<br>
+                // the actual Mangled class should be strict about this, but on the command line<br>
+                // if you're copying mangled names out of 'nm' on Darwin, they will come out with<br>
+                // an extra underscore - be willing to strip this on behalf of the user<br>
+                // This is the moral equivalent of the -_/-n options to c++filt<br>
+                if (mangled_cs.GetStringRef().startswith("__Z"))<br>
+                    mangled_cs.SetCString(arg+1);<br>
+<br>
+                Mangled mangled(mangled_cs, true);<br>
+                if (mangled.GuessLanguage() == lldb::eLanguageTypeC_plus_plus)<br>
+                {<br>
+                    ConstString demangled(mangled.GetDisplayDemangledName(lldb::eLanguageTypeC_plus_plus));<br>
+                    demangled_any = true;<br>
+                    result.AppendMessageWithFormat("%s ---> %s\n", arg, demangled.GetCString());<br>
+                }<br>
+                else<br>
+                {<br>
+                    error_any = true;<br>
+                    result.AppendErrorWithFormat("%s is not a valid C++ mangled name\n", arg);<br>
+                }<br>
+            }<br>
+        }<br>
+<br>
+        result.SetStatus(error_any ? lldb::eReturnStatusFailed :<br>
+                         (demangled_any ? lldb::eReturnStatusSuccessFinishResult : lldb::eReturnStatusSuccessFinishNoResult));<br>
+        return result.Succeeded();<br>
+    }<br>
+};<br>
+<br>
+class CommandObjectMultiwordItaniumABI : public CommandObjectMultiword<br>
+{<br>
+public:<br>
+    CommandObjectMultiwordItaniumABI (CommandInterpreter &interpreter) :<br>
+    CommandObjectMultiword (interpreter,<br>
+                            "cplusplus",<br>
+                            "A set of commands for operating on the C++ Language Runtime.",<br>
+                            "cplusplus <subcommand> [<subcommand-options>]")<br>
+    {<br>
+        LoadSubCommand ("demangle",   CommandObjectSP (new CommandObjectMultiwordItaniumABI_Demangle (interpreter)));<br>
+    }<br>
+<br>
+    ~CommandObjectMultiwordItaniumABI() override = default;<br>
+};<br>
+<br>
 void<br>
 ItaniumABILanguageRuntime::Initialize()<br>
 {<br>
     PluginManager::RegisterPlugin (GetPluginNameStatic(),<br>
                                    "Itanium ABI for the C++ language",<br>
-                                   CreateInstance);<br>
+                                   CreateInstance,<br>
+                                   [] (CommandInterpreter& interpreter) -> lldb::CommandObjectSP {<br>
+                                       return CommandObjectSP(new CommandObjectMultiwordItaniumABI(interpreter));<br>
+                                   });<br>
 }<br>
<br>
 void<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div>