Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
code simplification around simgrid::surf::NetCardImpl
[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 <stdint.h>
11
12 #include <vector>
13
14 #include <libunwind.h>
15 #include <dwarf.h>
16 #include <elfutils/libdw.h>
17
18 #include "simgrid_config.h"
19 #include "src/mc/mc_base.h"
20 #include "src/mc/mc_forward.hpp"
21 #include "src/mc/AddressSpace.hpp"
22 #include "src/mc/DwarfExpression.hpp"
23
24 namespace simgrid {
25 namespace dwarf {
26
27 /** \brief A DWARF expression with optional validity contraints */
28 class LocationListEntry {
29 public:
30   simgrid::dwarf::DwarfExpression expression;
31   void* lowpc, *highpc;
32
33   LocationListEntry() : lowpc(nullptr), highpc(nullptr) {}
34
35   bool always_valid() const
36   {
37     return this->lowpc == nullptr && this->highpc == nullptr;
38   }
39   bool valid_for_ip(unw_word_t ip) const
40   {
41     return always_valid() || (
42       ip >= (unw_word_t) this->lowpc &&
43       ip <  (unw_word_t) this->highpc);
44   }
45 };
46
47 typedef std::vector<LocationListEntry> LocationList;
48
49 /** Location of some variable in memory
50  *
51  *  The variable is located either in memory of a register.
52  */
53 class Location {
54 private:
55   void* memory_;
56   int register_id_;
57 public:
58   Location(void* x) :memory_(x) {}
59   Location(int register_id) :
60     memory_(nullptr), register_id_(register_id) {}
61   // Type of location:
62   bool in_register() const { return memory_ == nullptr; }
63   bool in_memory()   const { return memory_ != nullptr; }
64
65   // Get the location:
66   void* address()    const { return memory_; }
67   int register_id()  const { return register_id_;     }
68 };
69
70 XBT_PRIVATE
71 Location resolve(
72   simgrid::dwarf::DwarfExpression const& expression,
73   simgrid::mc::ObjectInformation* object_info, unw_cursor_t* c,
74   void* frame_pointer_address, simgrid::mc::AddressSpace* address_space,
75   int process_index);
76
77 Location resolve(
78   simgrid::dwarf::LocationList const& locations,
79   simgrid::mc::ObjectInformation* object_info,
80   unw_cursor_t * c,
81   void *frame_pointer_address,
82   simgrid::mc::AddressSpace* address_space,
83   int process_index);
84
85 XBT_PRIVATE
86 simgrid::dwarf::LocationList location_list(
87   simgrid::mc::ObjectInformation& info,
88   Dwarf_Attribute& attr);
89
90 }
91 }
92
93 #endif