LLDB mainline
RustLanguage.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
9#include "RustLanguage.h"
10
11#include "lldb/Core/Mangled.h"
14#include "lldb/Utility/Log.h"
15
16#include "llvm/Demangle/Demangle.h"
17
18#include <cassert>
19#include <cstdlib>
20
21using namespace lldb;
22using namespace lldb_private;
23
25
26/// The mangling scheme that this plugin registered.
27static Mangled::ManglingScheme g_rust_v0_scheme = Mangled::eManglingSchemeNone;
28
34
39
40// Static Functions
42 if (language == eLanguageTypeRust)
43 return new RustLanguage();
44 return nullptr;
45}
46
47bool RustLanguage::IsSourceFile(llvm::StringRef file_path) const {
48 return file_path.ends_with_insensitive(".rs");
49}
50
54 const DemangleOptions &options) const {
55 assert(scheme == g_rust_v0_scheme);
56 llvm::StringRef mangled_str = mangled.GetStringRef();
57 char *demangled_cstr = llvm::rustDemangle(mangled_str);
58
59 if (Log *log = GetLog(LLDBLog::Demangle)) {
60 if (demangled_cstr && demangled_cstr[0])
61 LLDB_LOG(log, "demangled rustv0: {0} -> \"{1}\"", mangled_str,
62 demangled_cstr);
63 else
64 LLDB_LOG(log, "demangled rustv0: {0} -> error: failed to demangle",
65 mangled_str);
66 }
67
68 DemangledName demangled;
69 if (demangled_cstr) {
70 demangled.name = demangled_cstr;
71 std::free(demangled_cstr);
72 }
73 return demangled;
74}
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
#define LLDB_PLUGIN_DEFINE(PluginName)
static Mangled::ManglingScheme g_rust_v0_scheme
The mangling scheme that this plugin registered.
A uniqued constant string class.
Definition ConstString.h:40
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
A class that handles mangled names.
Definition Mangled.h:36
static ManglingScheme RegisterManglingScheme(llvm::ArrayRef< llvm::StringRef > prefixes, lldb::LanguageType language, ManglingSchemeMatcher matches=nullptr)
Register a mangling scheme for language.
Definition Mangled.cpp:163
static void UnregisterManglingScheme(ManglingScheme scheme)
Stop recognizing the names of scheme, a scheme returned by RegisterManglingScheme().
Definition Mangled.cpp:169
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
static Language * CreateInstance(lldb::LanguageType language)
DemangledName DemangleSymbol(ConstString mangled, Mangled::ManglingScheme scheme, const DemangleOptions &options) const override
Demangle mangled, a name mangled with scheme, a scheme that this language registered with Mangled::Re...
bool IsSourceFile(llvm::StringRef file_path) const override
static llvm::StringRef GetPluginNameStatic()
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
LanguageType
Programming language type.
@ eLanguageTypeRust
Rust.
How to demangle a name in DemangleSymbol().
Definition Language.h:334
A demangled name and, if requested, where its parts begin and end.
Definition Language.h:340
std::string name
Empty if the name couldn't be demangled.
Definition Language.h:342