Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[project-description] Fix extraction of the ns-3 version.
[simgrid.git] / src / mc / inspect / LocationList.hpp
1 /* Copyright (c) 2004-2022. 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)), range_({0, UINT64_MAX})
35   {
36   }
37
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); }
41 };
42
43 using LocationList = std::vector<LocationListEntry>;
44
45 /** Location of some variable in memory
46  *
47  *  The variable is located either in memory of a register.
48  */
49 class Location {
50 private:
51   void* memory_    = nullptr;
52   int register_id_ = 0;
53
54 public:
55   explicit Location(void* x) : memory_(x) {}
56   explicit Location(int register_id) : register_id_(register_id) {}
57   // Type of location:
58   bool in_register() const { return memory_ == nullptr; }
59   bool in_memory() const { return memory_ != nullptr; }
60
61   // Get the location:
62   void* address() const { return memory_; }
63   int register_id() const { return register_id_; }
64 };
65
66 XBT_PRIVATE
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);
69
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);
72
73 XBT_PRIVATE
74 simgrid::dwarf::LocationList location_list(const simgrid::mc::ObjectInformation& info, Dwarf_Attribute& attr);
75
76 } // namespace simgrid::dwarf
77
78 #endif