1 #include "src/mc/Frame.hpp"
2 #include "src/mc/ObjectInformation.hpp"
3 #include "src/mc/Variable.hpp"
8 ObjectInformation::ObjectInformation()
11 this->start = nullptr;
13 this->start_exec = nullptr;
14 this->end_exec = nullptr;
15 this->start_rw = nullptr;
16 this->end_rw = nullptr;
17 this->start_ro = nullptr;
18 this->end_ro = nullptr;
21 /** Find the DWARF offset for this ELF object
23 * An offset is applied to address found in DWARF:
25 * * for an executable obejct, addresses are virtual address
26 * (there is no offset) i.e.
27 * \f$\text{virtual address} = \{dwarf address}\f$;
29 * * for a shared object, the addreses are offset from the begining
30 * of the shared object (the base address of the mapped shared
31 * object must be used as offset
32 * i.e. \f$\text{virtual address} = \text{shared object base address}
33 * + \text{dwarf address}\f$.
35 void *ObjectInformation::base_address() const
37 if (this->executable())
40 void *result = this->start_exec;
41 if (this->start_rw != NULL && result > (void *) this->start_rw)
42 result = this->start_rw;
43 if (this->start_ro != NULL && result > (void *) this->start_ro)
44 result = this->start_ro;
48 /* Find a function by instruction pointer */
49 simgrid::mc::Frame* ObjectInformation::find_function(const void *ip) const
51 /* This is implemented by binary search on a sorted array.
53 * We do quite a lot ot those so we want this to be cache efficient.
54 * We pack the only information we need in the index entries in order
55 * to successfully do the binary search. We do not need the high_pc
56 * during the binary search (only at the end) so it is not included
57 * in the index entry. We could use parallel arrays as well.
59 * We cannot really use the std:: alogrithm for this.
60 * We could use std::binary_search by including the high_pc inside
61 * the FunctionIndexEntry.
63 const simgrid::mc::FunctionIndexEntry* base =
64 this->functions_index.data();
66 int j = this->functions_index.size() - 1;
68 int k = i + ((j - i) / 2);
70 /* In most of the search, we do not dereference the base[k].function.
71 * This way the memory accesses are located in the base[k] array. */
72 if (ip < base[k].low_pc)
74 else if (k < j && ip >= base[k + 1].low_pc)
77 /* At this point, the search is over.
78 * Either we have found the correct function or we do not know
79 * any function corresponding to this instruction address.
80 * Only at the point do we derefernce the function pointer. */
81 else if (ip < base[k].function->high_pc)
82 return base[k].function;
89 simgrid::mc::Variable* ObjectInformation::find_variable(const char* name) const
91 for (simgrid::mc::Variable& variable : this->global_variables)
92 if(variable.name == name)
97 void ObjectInformation::remove_global_variable(const char* name)
99 typedef std::vector<Variable>::size_type size_type;
101 if (this->global_variables.empty())
106 size_type end = this->global_variables.size() - 1;
108 while (start <= end) {
109 size_type cursor = start + (end - start) / 2;
110 simgrid::mc::Variable& current_var = this->global_variables[cursor];
111 int cmp = current_var.name.compare(name);
114 // Find the whole range:
116 while (start != 0 && this->global_variables[start - 1].name == name)
118 size_type size = this->global_variables.size();
120 while (end != size - 1 && this->global_variables[end + 1].name == name)
122 // Remove the whole range:
123 this->global_variables.erase(
124 this->global_variables.begin() + cursor,
125 this->global_variables.begin() + end + 1);
129 else if (cursor != 0)