Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / mc / LocationList.hpp
1 /* Copyright (c) 2004-2017. 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 <cstdint>
10
11 #include <vector>
12
13 #include <libunwind.h>
14 #include <dwarf.h>
15 #include <elfutils/libdw.h>
16
17 #include "xbt/base.h"
18 #include "xbt/range.hpp"
19
20 #include "src/mc/mc_base.h"
21 #include "src/mc/mc_forward.hpp"
22 #include "src/mc/DwarfExpression.hpp"
23
24 namespace simgrid {
25 namespace dwarf {
26
27 /** A DWARF expression with optional validity constraints */
28 class LocationListEntry {
29 public:
30   typedef simgrid::xbt::Range<std::uint64_t> range_type;
31 private:
32   DwarfExpression expression_;
33   // By default, the expression is always valid:
34   range_type range_ = {0, UINT64_MAX};
35 public:
36   LocationListEntry() = default;
37   LocationListEntry(DwarfExpression expression, range_type range)
38     : expression_(std::move(expression)), range_(range)
39   {}
40   LocationListEntry(DwarfExpression expression) : expression_(std::move(expression)), range_({0, UINT64_MAX}) {}
41
42   DwarfExpression& expression()
43   {
44     return expression_;
45   }
46   DwarfExpression const& expression() const
47   {
48     return expression_;
49   }
50   bool valid_for_ip(unw_word_t ip) const
51   {
52     return range_.contain(ip);
53   }
54 };
55
56 typedef std::vector<LocationListEntry> LocationList;
57
58 /** Location of some variable in memory
59  *
60  *  The variable is located either in memory of a register.
61  */
62 class Location {
63 private:
64   void* memory_;
65   int register_id_ = 0;
66
67 public:
68   explicit Location(void* x) : memory_(x) {}
69   explicit Location(int register_id) : memory_(nullptr), register_id_(register_id) {}
70   // Type of location:
71   bool in_register() const { return memory_ == nullptr; }
72   bool in_memory()   const { return memory_ != nullptr; }
73
74   // Get the location:
75   void* address()    const { return memory_; }
76   int register_id()  const { return register_id_;     }
77 };
78
79 XBT_PRIVATE
80 Location resolve(
81   simgrid::dwarf::DwarfExpression const& expression,
82   simgrid::mc::ObjectInformation* object_info, unw_cursor_t* c,
83   void* frame_pointer_address, simgrid::mc::AddressSpace* address_space,
84   int process_index);
85
86 Location resolve(
87   simgrid::dwarf::LocationList const& locations,
88   simgrid::mc::ObjectInformation* object_info,
89   unw_cursor_t * c,
90   void *frame_pointer_address,
91   simgrid::mc::AddressSpace* address_space,
92   int process_index);
93
94 XBT_PRIVATE
95 simgrid::dwarf::LocationList location_list(
96   simgrid::mc::ObjectInformation& info,
97   Dwarf_Attribute& attr);
98
99 }
100 }
101
102 #endif