Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Cleanup LocationListEntry
[simgrid.git] / src / mc / LocationList.hpp
1 /* Copyright (c) 2004-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_MC_OBJECT_LOCATION_H
8 #define SIMGRID_MC_OBJECT_LOCATION_H
9
10 #include <cstdint>
11
12 #include <vector>
13
14 #include <libunwind.h>
15 #include <dwarf.h>
16 #include <elfutils/libdw.h>
17
18 #include <xbt/range.hpp>
19
20 #include "simgrid_config.h"
21 #include "src/mc/mc_base.h"
22 #include "src/mc/mc_forward.hpp"
23 #include "src/mc/AddressSpace.hpp"
24 #include "src/mc/DwarfExpression.hpp"
25
26 namespace simgrid {
27 namespace dwarf {
28
29 /** \brief A DWARF expression with optional validity contraints */
30 class LocationListEntry {
31 public:
32   typedef simgrid::xbt::range<std::uint64_t> range_type;
33 private:
34   DwarfExpression expression_;
35   range_type range_ = {0, 0};
36 public:
37   LocationListEntry() {}
38   LocationListEntry(DwarfExpression expression, range_type range)
39     : expression_(std::move(expression)), range_(range)
40   {}
41   LocationListEntry(DwarfExpression expression)
42     : expression_(std::move(expression)), range_({0, 0})
43   {}
44
45   DwarfExpression& expression()
46   {
47     return expression_;
48   }
49   DwarfExpression const& expression() const
50   {
51     return expression_;
52   }
53   bool always_valid() const
54   {
55     return range_.begin() == 0 && range_.end() == 0;
56   }
57   bool valid_for_ip(unw_word_t ip) const
58   {
59     return always_valid() || range_.contain(ip);
60   }
61 };
62
63 typedef std::vector<LocationListEntry> LocationList;
64
65 /** Location of some variable in memory
66  *
67  *  The variable is located either in memory of a register.
68  */
69 class Location {
70 private:
71   void* memory_;
72   int register_id_;
73 public:
74   Location(void* x) :memory_(x) {}
75   Location(int register_id) :
76     memory_(nullptr), register_id_(register_id) {}
77   // Type of location:
78   bool in_register() const { return memory_ == nullptr; }
79   bool in_memory()   const { return memory_ != nullptr; }
80
81   // Get the location:
82   void* address()    const { return memory_; }
83   int register_id()  const { return register_id_;     }
84 };
85
86 XBT_PRIVATE
87 Location resolve(
88   simgrid::dwarf::DwarfExpression const& expression,
89   simgrid::mc::ObjectInformation* object_info, unw_cursor_t* c,
90   void* frame_pointer_address, simgrid::mc::AddressSpace* address_space,
91   int process_index);
92
93 Location resolve(
94   simgrid::dwarf::LocationList const& locations,
95   simgrid::mc::ObjectInformation* object_info,
96   unw_cursor_t * c,
97   void *frame_pointer_address,
98   simgrid::mc::AddressSpace* address_space,
99   int process_index);
100
101 XBT_PRIVATE
102 simgrid::dwarf::LocationList location_list(
103   simgrid::mc::ObjectInformation& info,
104   Dwarf_Attribute& attr);
105
106 }
107 }
108
109 #endif