[Lldb-commits] [lldb] r264474 - 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

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 25 16:49:07 PDT 2016


> On Mar 25, 2016, at 4:39 PM, Zachary Turner <zturner at google.com> wrote:
> 
> Any particular reason this has the word Itanium baked into the name of the class

The name of the C++ language runtime is ItaniumABI
I don’t think we have a language runtime for the C++ MSVC ABI
We can revisit where this command lives at that time

> and description?

It shouldn’t - it should be “language cplusplus demangle”, no mention of Itanium
If you are referring to the description of the plugin overall, that is correct, and should stay as-is

Again, the hierarchy can be revisited when a C++ MSVC ABI runtime plugin exists.

>   MSVC doesn't use the Itanium ABI, but but AFAICT from looking at this code, it should work for MSVC's abi as well.  
> 

I have no way to test it, but I would assume so, yes.

> 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

This seems nitpicking to me, since the entire file is named ItaniumABILanguageRuntime.cpp

> or help / description

I don’t think it does

> 
> On Fri, Mar 25, 2016 at 4:19 PM Enrico Granata via lldb-commits <lldb-commits at lists.llvm.org <mailto:lldb-commits at lists.llvm.org>> wrote:
> Author: enrico
> Date: Fri Mar 25 18:14:24 2016
> New Revision: 264474
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=264474&view=rev <http://llvm.org/viewvc/llvm-project?rev=264474&view=rev>
> Log:
> 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
> 
> Modified:
>     lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
> 
> Modified: lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp?rev=264474&r1=264473&r2=264474&view=diff <http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp?rev=264474&r1=264473&r2=264474&view=diff>
> ==============================================================================
> --- lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp (original)
> +++ lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp Fri Mar 25 18:14:24 2016
> @@ -13,11 +13,15 @@
>  #include "lldb/Core/ConstString.h"
>  #include "lldb/Core/Error.h"
>  #include "lldb/Core/Log.h"
> +#include "lldb/Core/Mangled.h"
>  #include "lldb/Core/Module.h"
>  #include "lldb/Core/PluginManager.h"
>  #include "lldb/Core/Scalar.h"
>  #include "lldb/Core/ValueObject.h"
>  #include "lldb/Core/ValueObjectMemory.h"
> +#include "lldb/Interpreter/CommandObject.h"
> +#include "lldb/Interpreter/CommandObjectMultiword.h"
> +#include "lldb/Interpreter/CommandReturnObject.h"
>  #include "lldb/Symbol/ClangASTContext.h"
>  #include "lldb/Symbol/Symbol.h"
>  #include "lldb/Symbol/SymbolFile.h"
> @@ -340,12 +344,96 @@ ItaniumABILanguageRuntime::CreateInstanc
>          return NULL;
>  }
> 
> +class CommandObjectMultiwordItaniumABI_Demangle : public CommandObjectParsed
> +{
> +public:
> +    CommandObjectMultiwordItaniumABI_Demangle (CommandInterpreter &interpreter) :
> +    CommandObjectParsed (interpreter,
> +                         "demangle",
> +                         "Demangle a C++ mangled name.",
> +                         "language cplusplus demangle")
> +    {
> +        CommandArgumentEntry arg;
> +        CommandArgumentData index_arg;
> +
> +        // Define the first (and only) variant of this arg.
> +        index_arg.arg_type = eArgTypeSymbol;
> +        index_arg.arg_repetition = eArgRepeatPlus;
> +
> +        // There is only one variant this argument could be; put it into the argument entry.
> +        arg.push_back (index_arg);
> +
> +        // Push the data for the first argument into the m_arguments vector.
> +        m_arguments.push_back (arg);
> +    }
> +
> +    ~CommandObjectMultiwordItaniumABI_Demangle() override = default;
> +
> +protected:
> +    bool
> +    DoExecute(Args& command, CommandReturnObject &result) override
> +    {
> +        bool demangled_any = false;
> +        bool error_any = false;
> +        for (size_t i = 0; i < command.GetArgumentCount(); i++)
> +        {
> +            auto arg = command.GetArgumentAtIndex(i);
> +            if (arg && *arg)
> +            {
> +                ConstString mangled_cs(arg);
> +
> +                // the actual Mangled class should be strict about this, but on the command line
> +                // if you're copying mangled names out of 'nm' on Darwin, they will come out with
> +                // an extra underscore - be willing to strip this on behalf of the user
> +                // This is the moral equivalent of the -_/-n options to c++filt
> +                if (mangled_cs.GetStringRef().startswith("__Z"))
> +                    mangled_cs.SetCString(arg+1);
> +
> +                Mangled mangled(mangled_cs, true);
> +                if (mangled.GuessLanguage() == lldb::eLanguageTypeC_plus_plus)
> +                {
> +                    ConstString demangled(mangled.GetDisplayDemangledName(lldb::eLanguageTypeC_plus_plus));
> +                    demangled_any = true;
> +                    result.AppendMessageWithFormat("%s ---> %s\n", arg, demangled.GetCString());
> +                }
> +                else
> +                {
> +                    error_any = true;
> +                    result.AppendErrorWithFormat("%s is not a valid C++ mangled name\n", arg);
> +                }
> +            }
> +        }
> +
> +        result.SetStatus(error_any ? lldb::eReturnStatusFailed :
> +                         (demangled_any ? lldb::eReturnStatusSuccessFinishResult : lldb::eReturnStatusSuccessFinishNoResult));
> +        return result.Succeeded();
> +    }
> +};
> +
> +class CommandObjectMultiwordItaniumABI : public CommandObjectMultiword
> +{
> +public:
> +    CommandObjectMultiwordItaniumABI (CommandInterpreter &interpreter) :
> +    CommandObjectMultiword (interpreter,
> +                            "cplusplus",
> +                            "A set of commands for operating on the C++ Language Runtime.",
> +                            "cplusplus <subcommand> [<subcommand-options>]")
> +    {
> +        LoadSubCommand ("demangle",   CommandObjectSP (new CommandObjectMultiwordItaniumABI_Demangle (interpreter)));
> +    }
> +
> +    ~CommandObjectMultiwordItaniumABI() override = default;
> +};
> +
>  void
>  ItaniumABILanguageRuntime::Initialize()
>  {
>      PluginManager::RegisterPlugin (GetPluginNameStatic(),
>                                     "Itanium ABI for the C++ language",
> -                                   CreateInstance);
> +                                   CreateInstance,
> +                                   [] (CommandInterpreter& interpreter) -> lldb::CommandObjectSP {
> +                                       return CommandObjectSP(new CommandObjectMultiwordItaniumABI(interpreter));
> +                                   });
>  }
> 
>  void
> 
> 
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at lists.llvm.org <mailto:lldb-commits at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits <http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits>


Thanks,
- Enrico
📩 egranata@.com ☎️ 27683

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160325/3b2ec22d/attachment-0001.html>


More information about the lldb-commits mailing list