LLDB mainline
CommandObjectCPlusPlus.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
11#include "lldb/Core/Mangled.h"
13
14using namespace lldb;
15using namespace lldb_private;
16
18 CommandInterpreter &interpreter)
19 : CommandObjectParsed(interpreter, "demangle",
20 "Demangle a C++ mangled name.",
21 "language cplusplus demangle [<mangled-name> ...]") {
23}
24
26 CommandReturnObject &result) {
27 bool demangled_any = false;
28 bool error_any = false;
29 for (auto &entry : command.entries()) {
30 if (entry.ref().empty())
31 continue;
32
33 // the actual Mangled class should be strict about this, but on the
34 // command line if you're copying mangled names out of 'nm' on Darwin,
35 // they will come out with an extra underscore - be willing to strip this
36 // on behalf of the user. This is the moral equivalent of the -_/-n
37 // options to c++filt
38 auto name = entry.ref();
39 if (name.starts_with("__Z"))
40 name = name.drop_front();
41
42 Mangled mangled(name);
44 ConstString demangled(mangled.GetDisplayDemangledName());
45 demangled_any = true;
46 result.AppendMessageWithFormatv("{0} ---> {1}", entry.c_str(),
47 demangled.GetCString());
48 } else {
49 error_any = true;
50 result.AppendErrorWithFormat("%s is not a valid C++ mangled name\n",
51 entry.ref().str().c_str());
52 }
53 }
54
55 result.SetStatus(
59}
60
63 interpreter, "cplusplus",
64 "Commands for operating on the C++ language runtime.",
65 "cplusplus <subcommand> [<subcommand-options>]") {
67 interpreter)));
68}
A command line argument class.
Definition Args.h:33
llvm::ArrayRef< ArgEntry > entries() const
Definition Args.h:132
CommandObjectCPlusPlusDemangle(CommandInterpreter &interpreter)
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectCPlusPlus(CommandInterpreter &interpreter)
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
CommandObjectMultiword(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
CommandObjectParsed(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void void AppendMessageWithFormatv(const char *format, Args &&...args)
A uniqued constant string class.
Definition ConstString.h:40
const char * GetCString() const
Get the string value as a C string.
A class that handles mangled names.
Definition Mangled.h:34
lldb::LanguageType GuessLanguage() const
Try to guess the language from the mangling.
Definition Mangled.cpp:425
ConstString GetDisplayDemangledName() const
Display demangled name get accessor.
Definition Mangled.cpp:354
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
@ eLanguageTypeC_plus_plus
ISO C++:1998.
@ eReturnStatusFailed
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult