1 /* Copyright (c) 2004-2022. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_MC_OBJECT_LOCATION_H
7 #define SIMGRID_MC_OBJECT_LOCATION_H
10 #include "xbt/range.hpp"
12 #include "src/mc/inspect/DwarfExpression.hpp"
13 #include "src/mc/mc_base.hpp"
14 #include "src/mc/mc_forward.hpp"
22 /** A DWARF expression with optional validity constraints */
23 class LocationListEntry {
25 using range_type = simgrid::xbt::Range<std::uint64_t>;
28 DwarfExpression expression_;
29 // By default, the expression is always valid:
30 range_type range_ = {0, UINT64_MAX};
33 LocationListEntry() = default;
34 LocationListEntry(DwarfExpression expression, range_type range) : expression_(std::move(expression)), range_(range) {}
35 explicit LocationListEntry(DwarfExpression expression) : expression_(std::move(expression)), range_({0, UINT64_MAX})
39 DwarfExpression& expression() { return expression_; }
40 DwarfExpression const& expression() const { return expression_; }
41 bool valid_for_ip(unw_word_t ip) const { return range_.contain(ip); }
44 using LocationList = std::vector<LocationListEntry>;
46 /** Location of some variable in memory
48 * The variable is located either in memory of a register.
52 void* memory_ = nullptr;
56 explicit Location(void* x) : memory_(x) {}
57 explicit Location(int register_id) : register_id_(register_id) {}
59 bool in_register() const { return memory_ == nullptr; }
60 bool in_memory() const { return memory_ != nullptr; }
63 void* address() const { return memory_; }
64 int register_id() const { return register_id_; }
68 Location resolve(simgrid::dwarf::DwarfExpression const& expression, simgrid::mc::ObjectInformation* object_info,
69 unw_cursor_t* c, void* frame_pointer_address, const simgrid::mc::AddressSpace* address_space);
71 Location resolve(simgrid::dwarf::LocationList const& locations, simgrid::mc::ObjectInformation* object_info,
72 unw_cursor_t* c, void* frame_pointer_address, const simgrid::mc::AddressSpace* address_space);
75 simgrid::dwarf::LocationList location_list(const simgrid::mc::ObjectInformation& info, Dwarf_Attribute& attr);
78 } // namespace simgrid