LLDB mainline
SymbolLocatorSymStore.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
15#include "lldb/Utility/Args.h"
17#include "lldb/Utility/Log.h"
18#include "lldb/Utility/UUID.h"
19
20#include "llvm/ADT/StringExtras.h"
21#include "llvm/Support/Endian.h"
22#include "llvm/Support/FileSystem.h"
23#include "llvm/Support/Path.h"
24
25using namespace lldb;
26using namespace lldb_private;
27
29
30namespace {
31
32#define LLDB_PROPERTIES_symbollocatorsymstore
33#include "SymbolLocatorSymStoreProperties.inc"
34
35enum {
36#define LLDB_PROPERTIES_symbollocatorsymstore
37#include "SymbolLocatorSymStorePropertiesEnum.inc"
38};
39
40class PluginProperties : public Properties {
41public:
42 static llvm::StringRef GetSettingName() {
44 }
45
46 PluginProperties() {
47 m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
48 m_collection_sp->Initialize(g_symbollocatorsymstore_properties_def);
49 }
50
51 Args GetURLs() const {
52 Args urls;
53 m_collection_sp->GetPropertyAtIndexAsArgs(ePropertySymStoreURLs, urls);
54 return urls;
55 }
56};
57
58} // namespace
59
60static PluginProperties &GetGlobalPluginProperties() {
61 static PluginProperties g_settings;
62 return g_settings;
63}
64
66
68 // First version can only locate PDB in local SymStore (no download yet).
71 nullptr, LocateExecutableSymbolFile, nullptr, nullptr,
73}
74
77 debugger, PluginProperties::GetSettingName())) {
78 constexpr bool is_global_setting = true;
80 debugger, GetGlobalPluginProperties().GetValueProperties(),
81 "Properties for the SymStore Symbol Locator plug-in.",
82 is_global_setting);
83 }
84}
85
89
91 return "Symbol locator for PDB in SymStore";
92}
93
97
98// RSDS entries store identity as a 20-byte UUID composed of 16-byte GUID and
99// 4-byte age:
100// 12345678-1234-5678-9ABC-DEF012345678-00000001
101//
102// SymStore key is a string with no separators and age as decimal:
103// 12345678123456789ABCDEF0123456781
104//
105static std::string formatSymStoreKey(const UUID &uuid) {
106 llvm::ArrayRef<uint8_t> bytes = uuid.GetBytes();
107 uint32_t age = llvm::support::endian::read32be(bytes.data() + 16);
108 constexpr bool LowerCase = false;
109 return llvm::toHex(bytes.slice(0, 16), LowerCase) + std::to_string(age);
110}
111
113 const ModuleSpec &module_spec, const FileSpecList &default_search_paths) {
114 const UUID &uuid = module_spec.GetUUID();
115 if (!uuid.IsValid() ||
116 !ModuleList::GetGlobalModuleListProperties().GetEnableExternalLookup())
117 return {};
118
120 std::string pdb_name =
121 module_spec.GetSymbolFileSpec().GetFilename().GetStringRef().str();
122 if (pdb_name.empty()) {
123 LLDB_LOGV(log, "Failed to resolve symbol PDB module: PDB name empty");
124 return {};
125 }
126
127 LLDB_LOGV(log, "LocateExecutableSymbolFile {0} with UUID {1}", pdb_name,
128 uuid.GetAsString());
129 if (uuid.GetBytes().size() != 20) {
130 LLDB_LOGV(log, "Failed to resolve symbol PDB module: UUID invalid");
131 return {};
132 }
133
134 std::string key = formatSymStoreKey(uuid);
135 Args sym_store_urls = GetGlobalPluginProperties().GetURLs();
136 for (const Args::ArgEntry &url : sym_store_urls) {
137 llvm::SmallString<256> path;
138 llvm::sys::path::append(path, url.ref(), pdb_name, key, pdb_name);
139 FileSpec spec(path);
140 if (FileSystem::Instance().Exists(spec)) {
141 LLDB_LOGV(log, "Found {0} in SymStore {1}", pdb_name, url.ref());
142 return spec;
143 }
144 }
145
146 return {};
147}
static PluginProperties & GetGlobalPluginProperties()
#define LLDB_LOGV(log,...)
Definition Log.h:383
#define LLDB_PLUGIN_DEFINE(PluginName)
static PluginProperties & GetGlobalPluginProperties()
static std::string formatSymStoreKey(const UUID &uuid)
A command line argument class.
Definition Args.h:33
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
A class to manage flag bits.
Definition Debugger.h:87
A file collection class.
A file utility class.
Definition FileSpec.h:57
const ConstString & GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:250
static FileSystem & Instance()
static ModuleListProperties & GetGlobalModuleListProperties()
FileSpec & GetSymbolFileSpec()
Definition ModuleSpec.h:81
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static lldb::OptionValuePropertiesSP GetSettingForSymbolLocatorPlugin(Debugger &debugger, llvm::StringRef setting_name)
static bool UnregisterPlugin(ABICreateInstance create_callback)
static bool CreateSettingForSymbolLocatorPlugin(Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, llvm::StringRef description, bool is_global_property)
This plugin implements lookup in Microsoft SymStore instances.
static void DebuggerInitialize(Debugger &debugger)
static lldb_private::SymbolLocator * CreateInstance()
static llvm::StringRef GetPluginNameStatic()
static llvm::StringRef GetPluginDescriptionStatic()
static std::optional< FileSpec > LocateExecutableSymbolFile(const ModuleSpec &module_spec, const FileSpecList &default_search_paths)
Represents UUID's of various sizes.
Definition UUID.h:27
llvm::ArrayRef< uint8_t > GetBytes() const
Definition UUID.h:66
std::string GetAsString(llvm::StringRef separator="-") const
Definition UUID.cpp:54
bool IsValid() const
Definition UUID.h:69
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:332