From e7c91bff0bd806356165411e2d81c047ab243028 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Tue, 23 Feb 2016 16:36:39 +0100 Subject: [PATCH] [mc] Cleanup LocationListEntry --- src/mc/LocationList.cpp | 31 ++++++++++++++----------------- src/mc/LocationList.hpp | 36 ++++++++++++++++++++++++++---------- src/mc/mc_dwarf.cpp | 8 +++----- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/mc/LocationList.cpp b/src/mc/LocationList.cpp index 652d3f0d2b..7ce1b1e424 100644 --- a/src/mc/LocationList.cpp +++ b/src/mc/LocationList.cpp @@ -47,7 +47,7 @@ static simgrid::dwarf::DwarfExpression const* find_expression( { for (simgrid::dwarf::LocationListEntry const& entry : locations) if (entry.valid_for_ip(ip)) - return &entry.expression; + return &entry.expression(); return nullptr; } @@ -71,11 +71,11 @@ Location resolve( frame_pointer_address, address_space, process_index); } -simgrid::dwarf::LocationList location_list( +LocationList location_list( simgrid::mc::ObjectInformation& info, Dwarf_Attribute& attr) { - simgrid::dwarf::LocationList locations; + LocationList locations; std::ptrdiff_t offset = 0; while (1) { @@ -87,26 +87,23 @@ simgrid::dwarf::LocationList location_list( &attr, offset, &base, &start, &end, &ops, &len); if (offset == 0) - return std::move(locations); + break; else if (offset == -1) xbt_die("Error while loading location list"); - simgrid::dwarf::LocationListEntry entry; - entry.expression = simgrid::dwarf::DwarfExpression(ops, ops + len); + std::uint64_t base_address = (std::uint64_t) info.base_address(); - void *base_address = info.base_address(); + LocationListEntry::range_type range; + if (start == 0) + // If start == 0, this is not a location list: + range = {0, 0}; + else + range = { base_address + start, base_address + end }; - // If start == 0, this is not a location list: - if (start == 0) { - entry.lowpc = nullptr; - entry.highpc = nullptr; - } else { - entry.lowpc = (char *) base_address + start; - entry.highpc = (char *) base_address + end; - } - - locations.push_back(std::move(entry)); + locations.push_back({ DwarfExpression(ops, ops+len), range }); } + + return std::move(locations); } diff --git a/src/mc/LocationList.hpp b/src/mc/LocationList.hpp index c5c186f29b..289a2c18f8 100644 --- a/src/mc/LocationList.hpp +++ b/src/mc/LocationList.hpp @@ -7,7 +7,7 @@ #ifndef SIMGRID_MC_OBJECT_LOCATION_H #define SIMGRID_MC_OBJECT_LOCATION_H -#include +#include #include @@ -15,6 +15,8 @@ #include #include +#include + #include "simgrid_config.h" #include "src/mc/mc_base.h" #include "src/mc/mc_forward.hpp" @@ -27,20 +29,34 @@ namespace dwarf { /** \brief A DWARF expression with optional validity contraints */ class LocationListEntry { public: - simgrid::dwarf::DwarfExpression expression; - void* lowpc, *highpc; - - LocationListEntry() : lowpc(nullptr), highpc(nullptr) {} - + typedef simgrid::xbt::range range_type; +private: + DwarfExpression expression_; + range_type range_ = {0, 0}; +public: + LocationListEntry() {} + LocationListEntry(DwarfExpression expression, range_type range) + : expression_(std::move(expression)), range_(range) + {} + LocationListEntry(DwarfExpression expression) + : expression_(std::move(expression)), range_({0, 0}) + {} + + DwarfExpression& expression() + { + return expression_; + } + DwarfExpression const& expression() const + { + return expression_; + } bool always_valid() const { - return this->lowpc == nullptr && this->highpc == nullptr; + return range_.begin() == 0 && range_.end() == 0; } bool valid_for_ip(unw_word_t ip) const { - return always_valid() || ( - ip >= (unw_word_t) this->lowpc && - ip < (unw_word_t) this->highpc); + return always_valid() || range_.contain(ip); } }; diff --git a/src/mc/mc_dwarf.cpp b/src/mc/mc_dwarf.cpp index d5afe09700..c0cac6fe0d 100644 --- a/src/mc/mc_dwarf.cpp +++ b/src/mc/mc_dwarf.cpp @@ -750,11 +750,9 @@ static std::unique_ptr MC_die_to_variable( uintptr_t offset = (uintptr_t) expr[0].number; uintptr_t base = (uintptr_t) info->base_address(); variable->address = (void *) (base + offset); - } else { - simgrid::dwarf::LocationListEntry entry; - entry.expression = {expr, expr + len}; - variable->location_list = { std::move(entry) }; - } + } else + variable->location_list = { + simgrid::dwarf::DwarfExpression(expr, expr + len) }; break; } -- 2.20.1