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)