int attribute)
{
Dwarf_Attribute attr;
- if (!dwarf_attr_integrate(die, attribute, &attr)) {
+ if (!dwarf_attr_integrate(die, attribute, &attr))
return nullptr;
- } else {
+ else
return dwarf_formstring(&attr);
- }
}
/** \brief Get the linkage name of a DIE.
if (low_pc) {
// DW_AT_high_pc:
Dwarf_Attribute attr;
- if (!dwarf_attr_integrate(die, DW_AT_high_pc, &attr)) {
+ if (!dwarf_attr_integrate(die, DW_AT_high_pc, &attr))
xbt_die("Missing DW_AT_high_pc matching with DW_AT_low_pc");
- }
Dwarf_Sword offset;
Dwarf_Addr high_pc;
Dwarf_Die child;
int res;
for (res = dwarf_child(die, &child); res == 0;
- res = dwarf_siblingof(&child, &child)) {
+ res = dwarf_siblingof(&child, &child))
MC_dwarf_handle_die(info, &child, unit, frame, ns);
- }
}
static void MC_dwarf_handle_die(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
}
static
-Elf64_Half MC_dwarf_elf_type(Dwarf* dwarf)
+Elf64_Half get_type(Elf* elf)
{
- Elf* elf = dwarf_getelf(dwarf);
Elf64_Ehdr* ehdr64 = elf64_getehdr(elf);
if (ehdr64)
return ehdr64->e_type;
xbt_die("Could not get ELF heeader");
}
+static
+void read_dwarf_info(simgrid::mc::ObjectInformation* info, Dwarf* dwarf)
+{
+ // For each compilation unit:
+ Dwarf_Off offset = 0;
+ Dwarf_Off next_offset = 0;
+ size_t length;
+
+ while (dwarf_nextcu(dwarf, offset, &next_offset, &length, nullptr, NULL, NULL) ==
+ 0) {
+ Dwarf_Die unit_die;
+ if (dwarf_offdie(dwarf, offset + length, &unit_die) != nullptr)
+ MC_dwarf_handle_children(info, &unit_die, &unit_die, nullptr, NULL);
+ offset = next_offset;
+ }
+}
+
/** \brief Populate the debugging informations of the given ELF object
*
* Read the DWARf information of the EFFL object and populate the
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());
- Dwarf *dwarf = dwarf_begin(fd, DWARF_C_READ);
- if (dwarf == nullptr)
+ 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);
+ // Dwarf *dwarf = dwarf_begin(fd, DWARF_C_READ);
+ if (dwarf != nullptr) {
+ read_dwarf_info(info, dwarf);
+ dwarf_end(dwarf);
+ dwarf = nullptr;
+ }
+ else
xbt_die("Missing debugging information in %s\n"
"Your program and its dependencies must have debugging information.\n"
"You might want to recompile with -g or install the suitable debugging package.\n",
info->file_name.c_str());
- Elf64_Half elf_type = MC_dwarf_elf_type(dwarf);
- if (elf_type == ET_EXEC)
- info->flags |= simgrid::mc::ObjectInformation::Executable;
-
- // For each compilation unit:
- Dwarf_Off offset = 0;
- Dwarf_Off next_offset = 0;
- size_t length;
-
- while (dwarf_nextcu(dwarf, offset, &next_offset, &length, nullptr, NULL, NULL) ==
- 0) {
- Dwarf_Die unit_die;
- if (dwarf_offdie(dwarf, offset + length, &unit_die) != nullptr)
- MC_dwarf_handle_children(info, &unit_die, &unit_die, nullptr, NULL);
- offset = next_offset;
- }
-
- dwarf_end(dwarf);
+ elf_end(elf);
close(fd);
}
break;
// Resolve full_type:
- if (!subtype->name.empty() && subtype->byte_size == 0) {
+ if (!subtype->name.empty() && subtype->byte_size == 0)
for (auto const& object_info : process->object_infos) {
auto i = object_info->full_types_by_name.find(subtype->name);
if (i != object_info->full_types_by_name.end()
break;
}
}
- } else type->full_type = subtype;
+ else type->full_type = subtype;
}
}