<div dir="ltr">Ahh, I didn't notice that our C++ Language Runtime is already called the Itanium ABI Runtime.  Kind of unfortunate.<div><br></div><div>I wonder how it would work if a process had modules loaded with different languages.  Right now we seem to assume 1 language runtime per process, but really it's more like 1 per module.</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Mar 25, 2016 at 4:49 PM Enrico Granata <<a href="mailto:egranata@apple.com">egranata@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On Mar 25, 2016, at 4:39 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:</div><br><div><div dir="ltr">Any particular reason this has the word Itanium baked into the name of the class </div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>The name of the C++ language runtime is ItaniumABI</div><div>I don’t think we have a language runtime for the C++ MSVC ABI</div><div>We can revisit where this command lives at that time</div><br><blockquote type="cite"><div><div dir="ltr">and description?</div></div></blockquote><div><br></div><div>It shouldn’t - it should be “language cplusplus demangle”, no mention of Itanium</div><div>If you are referring to the description of the plugin overall, that is correct, and should stay as-is</div><div><br></div><div>Again, the hierarchy can be revisited when a C++ MSVC ABI runtime plugin exists.</div></div></div><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div><div dir="ltr">  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></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>I have no way to test it, but I would assume so, yes.</div></div></div><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div><div dir="ltr"><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 </div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>This seems nitpicking to me, since the entire file is named ItaniumABILanguageRuntime.cpp</div><br><blockquote type="cite"><div><div dir="ltr"><div>or help / description</div></div></div></blockquote><div><br></div><div>I don’t think it does</div></div></div><div style="word-wrap:break-word"><div><br><blockquote type="cite"><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" target="_blank">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>
</div></blockquote></div></div><div style="word-wrap:break-word"><div></div><br><div>
<div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br>Thanks,</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><i>- Enrico</i><br>📩 egranata@<font color="#ff2600"></font>.com ☎️ 27683</div>
</div>
<br></div></blockquote></div>