+static char hexdigits[16] = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'a', 'b', 'c', 'd', 'e', 'f'
+};
+
+static inline
+std::array<char, 2> to_hex(std::uint8_t byte)
+{
+ return { hexdigits[byte >> 4], hexdigits[byte & 0xF] };
+}
+
+/** Hexadecimal representation of some binary data */
+static
+std::string to_hex(const char* data, std::size_t count)
+{
+ std::string res;
+ res.resize(2*count);
+ for (std::size_t i = 0; i < count; i++) {
+ std::array<char, 2> hex_byte = to_hex(data[i]);
+ for (int j = 0; j < 2; ++j)
+ res[2 * i + j] = hex_byte[j];
+ }
+ return std::move(res);
+}
+
+static
+std::string to_hex(std::vector<char> const& data)
+{
+ return to_hex(data.data(), data.size());
+}
+
+const char* debug_paths[] = {
+ "/usr/lib/debug/",
+ "/usr/local/lib/debug/"
+};
+
+static
+std::string find_by_build_id(std::vector<char> id)
+{
+ std::string filename;
+ for (const char* debug_path : debug_paths) {
+ filename = debug_path;
+ filename += ".build-id/" + to_hex(id.data(), 1) + '/'
+ + to_hex(id.data() + 1, id.size() - 1) + ".debug";
+ XBT_DEBUG("Checking debug file: %s", filename.c_str());
+ if (access(filename.c_str(), F_OK) == 0)
+ return std::move(filename);
+ }
+ return std::string();
+}
+
+/** \brief Populate the debugging informations of the given ELF object
+ *
+ * Read the DWARf information of the EFFL object and populate the
+ * lists of types, variables, functions.
+ */
+static
+void MC_dwarf_get_variables(simgrid::mc::ObjectInformation* info)
+{
+ if (elf_version(EV_CURRENT) == EV_NONE)
+ xbt_die("libelf initialization error");
+
+ int fd = open(info->file_name.c_str(), O_RDONLY);
+ if (fd < 0)
+ xbt_die("Could not open file %s", info->file_name.c_str());
+ Elf* elf = elf_begin(fd, ELF_C_READ, nullptr);
+ if (elf == nullptr)
+ xbt_die("Not an ELF file 1");
+ Elf_Kind kind = elf_kind(elf);
+ if (kind != ELF_K_ELF)
+ xbt_die("Not an ELF file 2");
+
+ Elf64_Half type = get_type(elf);
+ if (type == ET_EXEC)
+ info->flags |= simgrid::mc::ObjectInformation::Executable;
+
+ Dwarf* dwarf = dwarf_begin_elf (elf, DWARF_C_READ, nullptr);
+ if (dwarf != nullptr) {
+ // This is the simple case where DWARF is located in the ELF file:
+ read_dwarf_info(info, dwarf);
+ dwarf_end(dwarf);
+ elf_end(elf);
+ close(fd);
+ return;
+ }