1 /* Copyright (c) 2004-2023. 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)) {}
36 DwarfExpression& expression() { return expression_; }
37 DwarfExpression const& expression() const { return expression_; }
38 bool valid_for_ip(unw_word_t ip) const { return range_.contain(ip); }
41 using LocationList = std::vector<LocationListEntry>;
43 /** Location of some variable in memory
45 * The variable is located either in memory of a register.
49 void* memory_ = nullptr;
53 explicit Location(void* x) : memory_(x) {}
54 explicit Location(int register_id) : register_id_(register_id) {}
56 bool in_register() const { return memory_ == nullptr; }
57 bool in_memory() const { return memory_ != nullptr; }
60 void* address() const { return memory_; }
61 int register_id() const { return register_id_; }
65 Location resolve(simgrid::dwarf::DwarfExpression const& expression, simgrid::mc::ObjectInformation* object_info,
66 unw_cursor_t* c, void* frame_pointer_address, const simgrid::mc::AddressSpace* address_space);
68 Location resolve(simgrid::dwarf::LocationList const& locations, simgrid::mc::ObjectInformation* object_info,
69 unw_cursor_t* c, void* frame_pointer_address, const simgrid::mc::AddressSpace* address_space);
72 simgrid::dwarf::LocationList location_list(const simgrid::mc::ObjectInformation& info, Dwarf_Attribute& attr);
74 } // namespace simgrid::dwarf