Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
[simgrid.git] / src / mc / inspect / LocationList.hpp
1 /* Copyright (c) 2004-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_MC_OBJECT_LOCATION_H
7 #define SIMGRID_MC_OBJECT_LOCATION_H
8
9 #include "xbt/base.h"
10 #include "xbt/range.hpp"
11
12 #include "src/mc/inspect/DwarfExpression.hpp"
13 #include "src/mc/mc_base.hpp"
14 #include "src/mc/mc_forward.hpp"
15
16 #include <cstdint>
17 #include <vector>
18
19 namespace simgrid::dwarf {
20
21 /** A DWARF expression with optional validity constraints */
22 class LocationListEntry {
23 public:
24   using range_type = simgrid::xbt::Range<std::uint64_t>;
25
26 private:
27   DwarfExpression expression_;
28   // By default, the expression is always valid:
29   range_type range_ = {0, UINT64_MAX};
30
31 public:
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)) {}
35
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); }
39 };
40
41 using LocationList = std::vector<LocationListEntry>;
42
43 /** Location of some variable in memory
44  *
45  *  The variable is located either in memory of a register.
46  */
47 class Location {
48 private:
49   void* memory_    = nullptr;
50   int register_id_ = 0;
51
52 public:
53   explicit Location(void* x) : memory_(x) {}
54   explicit Location(int register_id) : register_id_(register_id) {}
55   // Type of location:
56   bool in_register() const { return memory_ == nullptr; }
57   bool in_memory() const { return memory_ != nullptr; }
58
59   // Get the location:
60   void* address() const { return memory_; }
61   int register_id() const { return register_id_; }
62 };
63
64 XBT_PRIVATE
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);
67
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);
70
71 XBT_PRIVATE
72 simgrid::dwarf::LocationList location_list(const simgrid::mc::ObjectInformation& info, Dwarf_Attribute& attr);
73
74 } // namespace simgrid::dwarf
75
76 #endif