C++11ing some things.
This commit is contained in:
@@ -107,12 +107,10 @@ class Debugger {
|
||||
Runtime* runtime_;
|
||||
|
||||
std::mutex threads_lock_;
|
||||
typedef std::unordered_map<uint32_t, ThreadState*> ThreadMap;
|
||||
ThreadMap threads_;
|
||||
std::unordered_map<uint32_t, ThreadState*> threads_;
|
||||
|
||||
std::mutex breakpoints_lock_;
|
||||
typedef std::multimap<uint64_t, Breakpoint*> BreakpointMultimap;
|
||||
BreakpointMultimap breakpoints_;
|
||||
std::multimap<uint64_t, Breakpoint*> breakpoints_;
|
||||
};
|
||||
|
||||
} // namespace runtime
|
||||
|
||||
@@ -16,7 +16,7 @@ EntryTable::EntryTable() = default;
|
||||
|
||||
EntryTable::~EntryTable() {
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
EntryMap::iterator it = map_.begin();
|
||||
auto& it = map_.begin();
|
||||
for (; it != map_.end(); ++it) {
|
||||
Entry* entry = it->second;
|
||||
delete entry;
|
||||
@@ -25,7 +25,7 @@ EntryTable::~EntryTable() {
|
||||
|
||||
Entry* EntryTable::Get(uint64_t address) {
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
EntryMap::const_iterator it = map_.find(address);
|
||||
const auto& it = map_.find(address);
|
||||
Entry* entry = it != map_.end() ? it->second : nullptr;
|
||||
if (entry) {
|
||||
// TODO(benvanik): wait if needed?
|
||||
@@ -38,7 +38,7 @@ Entry* EntryTable::Get(uint64_t address) {
|
||||
|
||||
Entry::Status EntryTable::GetOrCreate(uint64_t address, Entry** out_entry) {
|
||||
lock_.lock();
|
||||
EntryMap::const_iterator it = map_.find(address);
|
||||
const auto& it = map_.find(address);
|
||||
Entry* entry = it != map_.end() ? it->second : nullptr;
|
||||
Entry::Status status;
|
||||
if (entry) {
|
||||
|
||||
@@ -47,8 +47,7 @@ class EntryTable {
|
||||
private:
|
||||
// TODO(benvanik): replace with a better data structure.
|
||||
std::mutex lock_;
|
||||
typedef std::unordered_map<uint64_t, Entry*> EntryMap;
|
||||
EntryMap map_;
|
||||
std::unordered_map<uint64_t, Entry*> map_;
|
||||
};
|
||||
|
||||
} // namespace runtime
|
||||
|
||||
@@ -20,20 +20,13 @@ namespace runtime {
|
||||
Module::Module(Runtime* runtime)
|
||||
: runtime_(runtime), memory_(runtime->memory()) {}
|
||||
|
||||
Module::~Module() {
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
SymbolMap::iterator it = map_.begin();
|
||||
for (; it != map_.end(); ++it) {
|
||||
SymbolInfo* symbol_info = it->second;
|
||||
delete symbol_info;
|
||||
}
|
||||
}
|
||||
Module::~Module() = default;
|
||||
|
||||
bool Module::ContainsAddress(uint64_t address) { return true; }
|
||||
|
||||
SymbolInfo* Module::LookupSymbol(uint64_t address, bool wait) {
|
||||
lock_.lock();
|
||||
SymbolMap::const_iterator it = map_.find(address);
|
||||
const auto it = map_.find(address);
|
||||
SymbolInfo* symbol_info = it != map_.end() ? it->second : nullptr;
|
||||
if (symbol_info) {
|
||||
if (symbol_info->status() == SymbolInfo::STATUS_DECLARING) {
|
||||
@@ -60,7 +53,7 @@ SymbolInfo::Status Module::DeclareSymbol(SymbolInfo::Type type,
|
||||
SymbolInfo** out_symbol_info) {
|
||||
*out_symbol_info = nullptr;
|
||||
lock_.lock();
|
||||
SymbolMap::const_iterator it = map_.find(address);
|
||||
auto it = map_.find(address);
|
||||
SymbolInfo* symbol_info = it != map_.end() ? it->second : nullptr;
|
||||
SymbolInfo::Status status;
|
||||
if (symbol_info) {
|
||||
@@ -91,7 +84,7 @@ SymbolInfo::Status Module::DeclareSymbol(SymbolInfo::Type type,
|
||||
break;
|
||||
}
|
||||
map_[address] = symbol_info;
|
||||
list_.push_back(symbol_info);
|
||||
list_.emplace_back(symbol_info);
|
||||
status = SymbolInfo::STATUS_NEW;
|
||||
}
|
||||
lock_.unlock();
|
||||
@@ -157,10 +150,9 @@ SymbolInfo::Status Module::DefineVariable(VariableInfo* symbol_info) {
|
||||
void Module::ForEachFunction(std::function<void(FunctionInfo*)> callback) {
|
||||
SCOPE_profile_cpu_f("alloy");
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
for (auto it = list_.begin(); it != list_.end(); ++it) {
|
||||
SymbolInfo* symbol_info = *it;
|
||||
for (auto& symbol_info : list_) {
|
||||
if (symbol_info->type() == SymbolInfo::TYPE_FUNCTION) {
|
||||
FunctionInfo* info = (FunctionInfo*)symbol_info;
|
||||
FunctionInfo* info = static_cast<FunctionInfo*>(symbol_info.get());
|
||||
callback(info);
|
||||
}
|
||||
}
|
||||
@@ -173,9 +165,9 @@ void Module::ForEachFunction(size_t since, size_t& version,
|
||||
size_t count = list_.size();
|
||||
version = count;
|
||||
for (size_t n = since; n < count; n++) {
|
||||
SymbolInfo* symbol_info = list_[n];
|
||||
auto& symbol_info = list_[n];
|
||||
if (symbol_info->type() == SymbolInfo::TYPE_FUNCTION) {
|
||||
FunctionInfo* info = (FunctionInfo*)symbol_info;
|
||||
FunctionInfo* info = static_cast<FunctionInfo*>(symbol_info.get());
|
||||
callback(info);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,10 +63,8 @@ class Module {
|
||||
private:
|
||||
// TODO(benvanik): replace with a better data structure.
|
||||
std::mutex lock_;
|
||||
typedef std::unordered_map<uint64_t, SymbolInfo*> SymbolMap;
|
||||
SymbolMap map_;
|
||||
typedef std::vector<SymbolInfo*> SymbolList;
|
||||
SymbolList list_;
|
||||
std::unordered_map<uint64_t, SymbolInfo*> map_;
|
||||
std::vector<std::unique_ptr<SymbolInfo>> list_;
|
||||
};
|
||||
|
||||
} // namespace runtime
|
||||
|
||||
@@ -30,11 +30,7 @@ Runtime::Runtime(Memory* memory) : memory_(memory) {}
|
||||
Runtime::~Runtime() {
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(modules_lock_);
|
||||
for (ModuleList::iterator it = modules_.begin(); it != modules_.end();
|
||||
++it) {
|
||||
Module* module = *it;
|
||||
delete module;
|
||||
}
|
||||
modules_.clear();
|
||||
}
|
||||
|
||||
debugger_.reset();
|
||||
@@ -99,28 +95,28 @@ int Runtime::Initialize(std::unique_ptr<Frontend> frontend,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Runtime::AddModule(Module* module) {
|
||||
int Runtime::AddModule(std::unique_ptr<Module> module) {
|
||||
std::lock_guard<std::mutex> guard(modules_lock_);
|
||||
modules_.push_back(module);
|
||||
modules_.push_back(std::move(module));
|
||||
return 0;
|
||||
}
|
||||
|
||||
Module* Runtime::GetModule(const char* name) {
|
||||
std::lock_guard<std::mutex> guard(modules_lock_);
|
||||
Module* result = NULL;
|
||||
for (ModuleList::iterator it = modules_.begin(); it != modules_.end(); ++it) {
|
||||
Module* module = *it;
|
||||
for (const auto& module : modules_) {
|
||||
if (module->name() == name) {
|
||||
result = module;
|
||||
break;
|
||||
return module.get();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Runtime::ModuleList Runtime::GetModules() {
|
||||
std::vector<Module*> Runtime::GetModules() {
|
||||
std::lock_guard<std::mutex> guard(modules_lock_);
|
||||
ModuleList clone = modules_;
|
||||
std::vector<Module*> clone(modules_.size());
|
||||
for (const auto& module : modules_) {
|
||||
clone.push_back(module.get());
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
@@ -176,11 +172,9 @@ int Runtime::LookupFunctionInfo(uint64_t address,
|
||||
std::lock_guard<std::mutex> guard(modules_lock_);
|
||||
// TODO(benvanik): sort by code address (if contiguous) so can bsearch.
|
||||
// TODO(benvanik): cache last module low/high, as likely to be in there.
|
||||
for (ModuleList::const_iterator it = modules_.begin(); it != modules_.end();
|
||||
++it) {
|
||||
Module* module = *it;
|
||||
for (const auto& module : modules_) {
|
||||
if (module->ContainsAddress(address)) {
|
||||
code_module = module;
|
||||
code_module = module.get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,6 @@ namespace alloy {
|
||||
namespace runtime {
|
||||
|
||||
class Runtime {
|
||||
public:
|
||||
typedef std::vector<Module*> ModuleList;
|
||||
|
||||
public:
|
||||
explicit Runtime(Memory* memory);
|
||||
virtual ~Runtime();
|
||||
@@ -43,9 +40,10 @@ class Runtime {
|
||||
int Initialize(std::unique_ptr<frontend::Frontend> frontend,
|
||||
std::unique_ptr<backend::Backend> backend = 0);
|
||||
|
||||
int AddModule(Module* module);
|
||||
int AddModule(std::unique_ptr<Module> module);
|
||||
Module* GetModule(const char* name);
|
||||
ModuleList GetModules();
|
||||
Module* GetModule(const std::string& name) { return GetModule(name.c_str()); }
|
||||
std::vector<Module*> GetModules();
|
||||
|
||||
std::vector<Function*> FindFunctionsWithAddress(uint64_t address);
|
||||
|
||||
@@ -69,7 +67,7 @@ class Runtime {
|
||||
|
||||
EntryTable entry_table_;
|
||||
std::mutex modules_lock_;
|
||||
ModuleList modules_;
|
||||
std::vector<std::unique_ptr<Module>> modules_;
|
||||
};
|
||||
|
||||
} // namespace runtime
|
||||
|
||||
@@ -69,7 +69,7 @@ class FunctionInfo : public SymbolInfo {
|
||||
|
||||
public:
|
||||
FunctionInfo(Module* module, uint64_t address);
|
||||
virtual ~FunctionInfo();
|
||||
~FunctionInfo() override;
|
||||
|
||||
bool has_end_address() const { return end_address_ > 0; }
|
||||
uint64_t end_address() const { return end_address_; }
|
||||
@@ -101,9 +101,7 @@ class FunctionInfo : public SymbolInfo {
|
||||
class VariableInfo : public SymbolInfo {
|
||||
public:
|
||||
VariableInfo(Module* module, uint64_t address);
|
||||
virtual ~VariableInfo();
|
||||
|
||||
private:
|
||||
~VariableInfo() override;
|
||||
};
|
||||
|
||||
} // namespace runtime
|
||||
|
||||
Reference in New Issue
Block a user