Logo AND Algorithmique Numérique Distribuée

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