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"
19 namespace simgrid::dwarf {
21 /** A DWARF expression with optional validity constraints */
22 class LocationListEntry {
24 using range_type = simgrid::xbt::Range<std::uint64_t>;
27 DwarfExpression expression_;
28 // By default, the expression is always valid:
29 range_type range_ = {0, UINT64_MAX};
32 LocationListEntry() = default;
33 LocationListEntry(DwarfExpression expression, range_type range) : expression_(std::move(expression)), range_(range) {}
34 explicit LocationListEntry(DwarfExpression expression) : expression_(std::move(expression)), range_({0, UINT64_MAX})
38 DwarfExpression& expression() { return expression_; }
39 DwarfExpression const& expression() const { return expression_; }
40 bool valid_for_ip(unw_word_t ip) const { return range_.contain(ip); }
43 using LocationList = std::vector<LocationListEntry>;
45 /** Location of some variable in memory
47 * The variable is located either in memory of a register.
51 void* memory_ = nullptr;
55 explicit Location(void* x) : memory_(x) {}
56 explicit Location(int register_id) : register_id_(register_id) {}
58 bool in_register() const { return memory_ == nullptr; }
59 bool in_memory() const { return memory_ != nullptr; }
62 void* address() const { return memory_; }
63 int register_id() const { return register_id_; }
67 Location resolve(simgrid::dwarf::DwarfExpression const& expression, simgrid::mc::ObjectInformation* object_info,
68 unw_cursor_t* c, void* frame_pointer_address, const simgrid::mc::AddressSpace* address_space);
70 Location resolve(simgrid::dwarf::LocationList const& locations, simgrid::mc::ObjectInformation* object_info,
71 unw_cursor_t* c, void* frame_pointer_address, const simgrid::mc::AddressSpace* address_space);
74 simgrid::dwarf::LocationList location_list(const simgrid::mc::ObjectInformation& info, Dwarf_Attribute& attr);
76 } // namespace simgrid::dwarf