Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Fix Snapshot::read_bytes
[simgrid.git] / src / mc / mc_location.h
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 "mc_base.h"
20 #include "mc_forward.hpp"
21 #include "mc/AddressSpace.hpp"
22 #include "mc/DwarfExpression.hpp"
23
24 namespace simgrid {
25 namespace mc {
26
27
28 /** \brief A DWARF expression with optional validity contraints */
29 class LocationListEntry {
30 public:
31   simgrid::dwarf::DwarfExpression expression;
32   void* lowpc, *highpc;
33
34   LocationListEntry() : lowpc(nullptr), highpc(nullptr) {}
35
36   bool valid_for_ip(unw_word_t ip)
37   {
38     return (this->lowpc == nullptr && this->highpc == nullptr)
39         || (ip >= (unw_word_t) this->lowpc
40             && ip < (unw_word_t) this->highpc);
41   }
42 };
43
44 typedef std::vector<LocationListEntry> LocationList;
45
46 }
47 }
48
49 SG_BEGIN_DECL()
50
51 /** A location is either a location in memory of a register location
52  *
53  *  Usage:
54  *
55  *    * mc_dwarf_resolve_locations or mc_dwarf_resolve_location is used
56  *      to find the location of a given location expression or location list;
57  *
58  *    * mc_get_location_type MUST be used to find the location type;
59  *
60  *    * for MC_LOCATION_TYPE_ADDRESS, memory_address is the resulting address
61  *
62  *    * for MC_LOCATION_TYPE_REGISTER, unw_get_reg(l.cursor, l.register_id, value)
63  *        and unw_get_reg(l.cursor, l.register_id, value) can be used to read/write
64  *        the value.
65  *  </ul>
66  */
67 typedef struct s_mc_location {
68   void* memory_location;
69   unw_cursor_t* cursor;
70   int register_id;
71 } s_mc_location_t, *mc_location_t;
72
73 /** Type of a given location
74  *
75  *  Use `mc_get_location_type(location)` to find the type.
76  * */
77 typedef enum mc_location_type {
78   MC_LOCATION_TYPE_ADDRESS,
79   MC_LOCATION_TYPE_REGISTER
80 } mc_location_type;
81
82 /** Find the type of a location */
83 static inline __attribute__ ((always_inline))
84 enum mc_location_type mc_get_location_type(mc_location_t location) {
85   if (location->cursor) {
86     return MC_LOCATION_TYPE_REGISTER;
87   } else {
88     return MC_LOCATION_TYPE_ADDRESS;
89   }
90 }
91
92 SG_END_DECL()
93
94 namespace simgrid {
95 namespace dwarf {
96
97 XBT_PRIVATE void resolve_location(
98   mc_location_t location, simgrid::dwarf::DwarfExpression const& expression,
99   simgrid::mc::ObjectInformation* object_info, unw_cursor_t* c,
100   void* frame_pointer_address, simgrid::mc::AddressSpace* address_space,
101   int process_index);
102
103 }
104 }
105
106 SG_BEGIN_DECL()
107
108 void mc_dwarf_resolve_locations(
109   mc_location_t location, simgrid::mc::LocationList* locations,
110   simgrid::mc::ObjectInformation* object_info, unw_cursor_t* c,
111   void* frame_pointer_address, simgrid::mc::AddressSpace* address_space,
112   int process_index);
113
114 XBT_PRIVATE void mc_dwarf_location_list_init(
115   simgrid::mc::LocationList*, simgrid::mc::ObjectInformation* info, Dwarf_Die* die,
116   Dwarf_Attribute* attr);
117
118 void* mc_find_frame_base(
119   simgrid::mc::Frame* frame, simgrid::mc::ObjectInformation* object_info, unw_cursor_t* unw_cursor);
120
121 SG_END_DECL()
122
123 #endif