1 /* Copyright (c) 2014-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
11 #include "mc_object_info.h"
12 #include "mc_private.h"
19 static void mc_frame_free(void* frame)
21 delete (simgrid::mc::Frame*)frame;
24 static void mc_type_free(void* t)
26 delete (simgrid::mc::Type*)t;
36 this->element_count = 0;
37 this->is_pointer_type = 0;
39 this->subtype = nullptr;
40 this->full_type = nullptr;
47 this->dwarf_offset = 0;
51 this->address = nullptr;
52 this->start_scope = 0;
53 this->object_info = nullptr;
61 this->low_pc = nullptr;
62 this->high_pc = nullptr;
64 this->abstract_origin_id = 0;
65 this->object_info = nullptr;
70 ObjectInformation::ObjectInformation()
73 this->file_name = nullptr;
74 this->start = nullptr;
76 this->start_exec = nullptr;
77 this->end_exec = nullptr;
78 this->start_rw = nullptr;
79 this->end_rw = nullptr;
80 this->start_ro = nullptr;
81 this->end_ro = nullptr;
82 this->subprograms = xbt_dict_new_homogeneous(mc_frame_free);
83 this->functions_index = nullptr;
86 ObjectInformation::~ObjectInformation()
88 xbt_free(this->file_name);
89 xbt_dict_free(&this->subprograms);
90 xbt_dynar_free(&this->functions_index);
93 /** Find the DWARF offset for this ELF object
95 * An offset is applied to address found in DWARF:
98 * <li>for an executable obejct, addresses are virtual address
99 * (there is no offset) i.e. \f$\text{virtual address} = \{dwarf address}\f$;</li>
100 * <li>for a shared object, the addreses are offset from the begining
101 * of the shared object (the base address of the mapped shared
102 * object must be used as offset
103 * i.e. \f$\text{virtual address} = \text{shared object base address}
104 * + \text{dwarf address}\f$.</li>
107 void *ObjectInformation::base_address() const
109 if (this->executable())
112 void *result = this->start_exec;
113 if (this->start_rw != NULL && result > (void *) this->start_rw)
114 result = this->start_rw;
115 if (this->start_ro != NULL && result > (void *) this->start_ro)
116 result = this->start_ro;
120 mc_frame_t ObjectInformation::find_function(const void *ip) const
122 xbt_dynar_t dynar = this->functions_index;
123 mc_function_index_item_t base =
124 (mc_function_index_item_t) xbt_dynar_get_ptr(dynar, 0);
126 int j = xbt_dynar_length(dynar) - 1;
128 int k = i + ((j - i) / 2);
129 if (ip < base[k].low_pc) {
131 } else if (ip >= base[k].high_pc) {
134 return base[k].function;
140 simgrid::mc::Variable* ObjectInformation::find_variable(const char* name) const
142 for (simgrid::mc::Variable& variable : this->global_variables)
143 if(variable.name == name)