Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Prefer "using" to "typedef".
[simgrid.git] / src / mc / inspect / LocationList.hpp
1 /* Copyright (c) 2004-2020. 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.h"
14 #include "src/mc/mc_forward.hpp"
15
16 #include <cstdint>
17 #include <vector>
18
19 namespace simgrid {
20 namespace dwarf {
21
22 /** A DWARF expression with optional validity constraints */
23 class LocationListEntry {
24 public:
25   using range_type = simgrid::xbt::Range<std::uint64_t>;
26
27 private:
28   DwarfExpression expression_;
29   // By default, the expression is always valid:
30   range_type range_ = {0, UINT64_MAX};
31
32 public:
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})
36   {
37   }
38
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); }
42 };
43
44 using LocationList = std::vector<LocationListEntry>;
45
46 /** Location of some variable in memory
47  *
48  *  The variable is located either in memory of a register.
49  */
50 class Location {
51 private:
52   void* memory_    = nullptr;
53   int register_id_ = 0;
54
55 public:
56   explicit Location(void* x) : memory_(x) {}
57   explicit Location(int register_id) : register_id_(register_id) {}
58   // Type of location:
59   bool in_register() const { return memory_ == nullptr; }
60   bool in_memory() const { return memory_ != nullptr; }
61
62   // Get the location:
63   void* address() const { return memory_; }
64   int register_id() const { return register_id_; }
65 };
66
67 XBT_PRIVATE
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);
70
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);
73
74 XBT_PRIVATE
75 simgrid::dwarf::LocationList location_list(const simgrid::mc::ObjectInformation& info, Dwarf_Attribute& attr);
76
77 } // namespace dwarf
78 } // namespace simgrid
79
80 #endif