[llvm] r251336 - [LLVMSymbolize] Use std::unique_ptr more extensively to clarify ownership.
Alexey Samsonov via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 26 12:41:24 PDT 2015
Author: samsonov
Date: Mon Oct 26 14:41:23 2015
New Revision: 251336
URL: http://llvm.org/viewvc/llvm-project?rev=251336&view=rev
Log:
[LLVMSymbolize] Use std::unique_ptr more extensively to clarify ownership.
Modified:
llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h
llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h?rev=251336&r1=251335&r2=251336&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h Mon Oct 26 14:41:23 2015
@@ -90,8 +90,7 @@ private:
MemoryBuffers.push_back(std::move(MemBuf));
}
- // Owns module info objects.
- std::map<std::string, ModuleInfo *> Modules;
+ std::map<std::string, std::unique_ptr<ModuleInfo>> Modules;
std::map<std::pair<MachOUniversalBinary *, std::string>, ObjectFile *>
ObjectFileForArch;
std::map<std::pair<std::string, std::string>, ObjectPair>
@@ -103,7 +102,7 @@ private:
class ModuleInfo {
public:
- ModuleInfo(ObjectFile *Obj, DIContext *DICtx);
+ ModuleInfo(ObjectFile *Obj, std::unique_ptr<DIContext> DICtx);
DILineInfo symbolizeCode(uint64_t ModuleOffset,
const LLVMSymbolizer::Options &Opts) const;
Modified: llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp?rev=251336&r1=251335&r2=251336&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp (original)
+++ llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp Mon Oct 26 14:41:23 2015
@@ -61,8 +61,8 @@ getDILineInfoSpecifier(const LLVMSymboli
Opts.PrintFunctions);
}
-ModuleInfo::ModuleInfo(ObjectFile *Obj, DIContext *DICtx)
- : Module(Obj), DebugInfoContext(DICtx) {
+ModuleInfo::ModuleInfo(ObjectFile *Obj, std::unique_ptr<DIContext> DICtx)
+ : Module(Obj), DebugInfoContext(std::move(DICtx)) {
std::unique_ptr<DataExtractor> OpdExtractor;
uint64_t OpdAddress = 0;
// Find the .opd (function descriptor) section if any, for big-endian
@@ -308,7 +308,7 @@ std::string LLVMSymbolizer::symbolizeDat
}
void LLVMSymbolizer::flush() {
- DeleteContainerSeconds(Modules);
+ Modules.clear();
ObjectPairForPathArch.clear();
ObjectFileForArch.clear();
}
@@ -512,7 +512,7 @@ ModuleInfo *
LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
const auto &I = Modules.find(ModuleName);
if (I != Modules.end())
- return I->second;
+ return I->second.get();
std::string BinaryName = ModuleName;
std::string ArchName = Opts.DefaultArch;
size_t ColonPos = ModuleName.find_last_of(':');
@@ -528,10 +528,10 @@ LLVMSymbolizer::getOrCreateModuleInfo(co
if (!Objects.first) {
// Failed to find valid object file.
- Modules.insert(make_pair(ModuleName, (ModuleInfo *)nullptr));
+ Modules.emplace(ModuleName, nullptr);
return nullptr;
}
- DIContext *Context = nullptr;
+ std::unique_ptr<DIContext> Context;
if (auto CoffObject = dyn_cast<COFFObjectFile>(Objects.first)) {
// If this is a COFF object, assume it contains PDB debug information. If
// we don't find any we will fall back to the DWARF case.
@@ -539,15 +539,16 @@ LLVMSymbolizer::getOrCreateModuleInfo(co
PDB_ErrorCode Error = loadDataForEXE(PDB_ReaderType::DIA,
Objects.first->getFileName(), Session);
if (Error == PDB_ErrorCode::Success) {
- Context = new PDBContext(*CoffObject, std::move(Session));
+ Context.reset(new PDBContext(*CoffObject, std::move(Session)));
}
}
if (!Context)
- Context = new DWARFContextInMemory(*Objects.second);
+ Context.reset(new DWARFContextInMemory(*Objects.second));
assert(Context);
- ModuleInfo *Info = new ModuleInfo(Objects.first, Context);
- Modules.insert(make_pair(ModuleName, Info));
- return Info;
+ auto Info = make_unique<ModuleInfo>(Objects.first, std::move(Context));
+ ModuleInfo *Res = Info.get();
+ Modules.emplace(ModuleName, std::move(Info));
+ return Res;
}
std::string LLVMSymbolizer::printDILineInfo(DILineInfo LineInfo,
More information about the llvm-commits
mailing list