Skip to content

Commit bf88db7

Browse files
authored
[Symbolizer, DebugInfo] Clean up LLVMSymbolizer API: const string& -> StringRef (#104541)
Nothing in the affected code depends on the `ModuleName` being null-terminated, so take it by `StringRef` instead of `const std::string &`. This change simplifies API consumption, since one doesn't always have a `std::string` at the call site (might have `std::string_view` instead), and also gives some minor performance improvements by removing string-copies in the cache-hit path of `getOrCreateModuleInfo`.
1 parent 65f66d2 commit bf88db7

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,39 +77,38 @@ class LLVMSymbolizer {
7777
// Overloads accepting ObjectFile does not support COFF currently
7878
Expected<DILineInfo> symbolizeCode(const ObjectFile &Obj,
7979
object::SectionedAddress ModuleOffset);
80-
Expected<DILineInfo> symbolizeCode(const std::string &ModuleName,
80+
Expected<DILineInfo> symbolizeCode(StringRef ModuleName,
8181
object::SectionedAddress ModuleOffset);
8282
Expected<DILineInfo> symbolizeCode(ArrayRef<uint8_t> BuildID,
8383
object::SectionedAddress ModuleOffset);
8484
Expected<DIInliningInfo>
8585
symbolizeInlinedCode(const ObjectFile &Obj,
8686
object::SectionedAddress ModuleOffset);
8787
Expected<DIInliningInfo>
88-
symbolizeInlinedCode(const std::string &ModuleName,
88+
symbolizeInlinedCode(StringRef ModuleName,
8989
object::SectionedAddress ModuleOffset);
9090
Expected<DIInliningInfo>
9191
symbolizeInlinedCode(ArrayRef<uint8_t> BuildID,
9292
object::SectionedAddress ModuleOffset);
9393

9494
Expected<DIGlobal> symbolizeData(const ObjectFile &Obj,
9595
object::SectionedAddress ModuleOffset);
96-
Expected<DIGlobal> symbolizeData(const std::string &ModuleName,
96+
Expected<DIGlobal> symbolizeData(StringRef ModuleName,
9797
object::SectionedAddress ModuleOffset);
9898
Expected<DIGlobal> symbolizeData(ArrayRef<uint8_t> BuildID,
9999
object::SectionedAddress ModuleOffset);
100100
Expected<std::vector<DILocal>>
101101
symbolizeFrame(const ObjectFile &Obj, object::SectionedAddress ModuleOffset);
102102
Expected<std::vector<DILocal>>
103-
symbolizeFrame(const std::string &ModuleName,
104-
object::SectionedAddress ModuleOffset);
103+
symbolizeFrame(StringRef ModuleName, object::SectionedAddress ModuleOffset);
105104
Expected<std::vector<DILocal>>
106105
symbolizeFrame(ArrayRef<uint8_t> BuildID,
107106
object::SectionedAddress ModuleOffset);
108107

109108
Expected<std::vector<DILineInfo>>
110109
findSymbol(const ObjectFile &Obj, StringRef Symbol, uint64_t Offset);
111110
Expected<std::vector<DILineInfo>>
112-
findSymbol(const std::string &ModuleName, StringRef Symbol, uint64_t Offset);
111+
findSymbol(StringRef ModuleName, StringRef Symbol, uint64_t Offset);
113112
Expected<std::vector<DILineInfo>>
114113
findSymbol(ArrayRef<uint8_t> BuildID, StringRef Symbol, uint64_t Offset);
115114

@@ -132,8 +131,7 @@ class LLVMSymbolizer {
132131
/// Only one attempt is made to load a module, and errors during loading are
133132
/// only reported once. Subsequent calls to get module info for a module that
134133
/// failed to load will return nullptr.
135-
Expected<SymbolizableModule *>
136-
getOrCreateModuleInfo(const std::string &ModuleName);
134+
Expected<SymbolizableModule *> getOrCreateModuleInfo(StringRef ModuleName);
137135

138136
private:
139137
// Bundles together object file with code/data and object file with
@@ -210,7 +208,7 @@ class LLVMSymbolizer {
210208
ObjectPairForPathArch;
211209

212210
/// Contains parsed binary for each path, or parsing error.
213-
std::map<std::string, CachedBinary> BinaryForPath;
211+
std::map<std::string, CachedBinary, std::less<>> BinaryForPath;
214212

215213
/// A list of cached binaries in LRU order.
216214
simple_ilist<CachedBinary> LRUBinaries;

llvm/lib/DebugInfo/Symbolize/Symbolize.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ LLVMSymbolizer::symbolizeCode(const ObjectFile &Obj,
8787
}
8888

8989
Expected<DILineInfo>
90-
LLVMSymbolizer::symbolizeCode(const std::string &ModuleName,
90+
LLVMSymbolizer::symbolizeCode(StringRef ModuleName,
9191
object::SectionedAddress ModuleOffset) {
9292
return symbolizeCodeCommon(ModuleName, ModuleOffset);
9393
}
@@ -138,7 +138,7 @@ LLVMSymbolizer::symbolizeInlinedCode(const ObjectFile &Obj,
138138
}
139139

140140
Expected<DIInliningInfo>
141-
LLVMSymbolizer::symbolizeInlinedCode(const std::string &ModuleName,
141+
LLVMSymbolizer::symbolizeInlinedCode(StringRef ModuleName,
142142
object::SectionedAddress ModuleOffset) {
143143
return symbolizeInlinedCodeCommon(ModuleName, ModuleOffset);
144144
}
@@ -183,7 +183,7 @@ LLVMSymbolizer::symbolizeData(const ObjectFile &Obj,
183183
}
184184

185185
Expected<DIGlobal>
186-
LLVMSymbolizer::symbolizeData(const std::string &ModuleName,
186+
LLVMSymbolizer::symbolizeData(StringRef ModuleName,
187187
object::SectionedAddress ModuleOffset) {
188188
return symbolizeDataCommon(ModuleName, ModuleOffset);
189189
}
@@ -224,7 +224,7 @@ LLVMSymbolizer::symbolizeFrame(const ObjectFile &Obj,
224224
}
225225

226226
Expected<std::vector<DILocal>>
227-
LLVMSymbolizer::symbolizeFrame(const std::string &ModuleName,
227+
LLVMSymbolizer::symbolizeFrame(StringRef ModuleName,
228228
object::SectionedAddress ModuleOffset) {
229229
return symbolizeFrameCommon(ModuleName, ModuleOffset);
230230
}
@@ -272,7 +272,7 @@ LLVMSymbolizer::findSymbol(const ObjectFile &Obj, StringRef Symbol,
272272
}
273273

274274
Expected<std::vector<DILineInfo>>
275-
LLVMSymbolizer::findSymbol(const std::string &ModuleName, StringRef Symbol,
275+
LLVMSymbolizer::findSymbol(StringRef ModuleName, StringRef Symbol,
276276
uint64_t Offset) {
277277
return findSymbolCommon(ModuleName, Symbol, Offset);
278278
}
@@ -604,13 +604,13 @@ LLVMSymbolizer::createModuleInfo(const ObjectFile *Obj,
604604
}
605605

606606
Expected<SymbolizableModule *>
607-
LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
608-
std::string BinaryName = ModuleName;
609-
std::string ArchName = Opts.DefaultArch;
607+
LLVMSymbolizer::getOrCreateModuleInfo(StringRef ModuleName) {
608+
StringRef BinaryName = ModuleName;
609+
StringRef ArchName = Opts.DefaultArch;
610610
size_t ColonPos = ModuleName.find_last_of(':');
611611
// Verify that substring after colon form a valid arch name.
612612
if (ColonPos != std::string::npos) {
613-
std::string ArchStr = ModuleName.substr(ColonPos + 1);
613+
StringRef ArchStr = ModuleName.substr(ColonPos + 1);
614614
if (Triple(ArchStr).getArch() != Triple::UnknownArch) {
615615
BinaryName = ModuleName.substr(0, ColonPos);
616616
ArchName = ArchStr;
@@ -623,7 +623,8 @@ LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
623623
return I->second.get();
624624
}
625625

626-
auto ObjectsOrErr = getOrCreateObjectPair(BinaryName, ArchName);
626+
auto ObjectsOrErr =
627+
getOrCreateObjectPair(std::string{BinaryName}, std::string{ArchName});
627628
if (!ObjectsOrErr) {
628629
// Failed to find valid object file.
629630
Modules.emplace(ModuleName, std::unique_ptr<SymbolizableModule>());

0 commit comments

Comments
 (0)