Skip to content

Commit

Permalink
[LLVMSymbolize] Use std::unique_ptr more extensively to clarify owner…
Browse files Browse the repository at this point in the history
…ship.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251336 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
vonosmas committed Oct 26, 2015
1 parent 14ff71a commit c2df336
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
5 changes: 2 additions & 3 deletions include/llvm/DebugInfo/Symbolize/Symbolize.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ class LLVMSymbolizer {
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>
Expand All @@ -103,7 +102,7 @@ class LLVMSymbolizer {

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;
Expand Down
23 changes: 12 additions & 11 deletions lib/DebugInfo/Symbolize/Symbolize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ getDILineInfoSpecifier(const LLVMSymbolizer::Options &Opts) {
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
Expand Down Expand Up @@ -308,7 +308,7 @@ std::string LLVMSymbolizer::symbolizeData(const std::string &ModuleName,
}

void LLVMSymbolizer::flush() {
DeleteContainerSeconds(Modules);
Modules.clear();
ObjectPairForPathArch.clear();
ObjectFileForArch.clear();
}
Expand Down Expand Up @@ -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(':');
Expand All @@ -528,26 +528,27 @@ LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {

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.
std::unique_ptr<IPDBSession> Session;
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,
Expand Down

0 comments on commit c2df336

Please sign in to comment.