Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] libdwarf integration for types
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 6 Jan 2014 10:21:02 +0000 (11:21 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 17 Jan 2014 09:54:30 +0000 (10:54 +0100)
buildtools/Cmake/DefinePackages.cmake
generate.sh [new file with mode: 0755]
src/mc/mc_checkpoint.c
src/mc/mc_dwarf.c [new file with mode: 0644]
src/mc/mc_dwarf_attrnames.h [new file with mode: 0644]
src/mc/mc_dwarf_tagnames.h [new file with mode: 0644]
src/mc/mc_global.c
src/mc/mc_private.h

index 193de82..b9854a6 100644 (file)
@@ -517,6 +517,7 @@ set(MC_SRC
   src/mc/mc_compare.c
   src/mc/mc_dpor.c
   src/mc/mc_global.c
+  src/mc/mc_dwarf.c
   src/mc/mc_liveness.c
   src/mc/mc_memory.c
   src/mc/mc_private.h
diff --git a/generate.sh b/generate.sh
new file mode 100755 (executable)
index 0000000..7fbfe6f
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+# Generate files from dwarf.h
+
+(for tag in $(grep -o 'DW_TAG_[^ ]*' /usr/include/dwarf.h) ; do
+    echo "case $tag: return \"$tag\";"
+done) > src/mc/mc_dwarf_tagnames.h
+
+(for attr in $(grep -o 'DW_AT_[^ ]*' /usr/include/dwarf.h) ; do
+    echo "case $attr: return \"$attr\";"
+done) > src/mc/mc_dwarf_attrnames.h
index 4b8283b..898c0d1 100644 (file)
@@ -221,7 +221,7 @@ void MC_init_memory_map_info(){
     else if ((reg.prot & PROT_WRITE) && !memcmp(maps->regions[i].pathname, "[stack]", 7)){
           maestro_stack_start = reg.start_addr;
           maestro_stack_end = reg.end_addr;
-    }else if ((reg.prot & PROT_READ) && (reg.prot & PROT_EXEC) && !memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
+    } else if ((reg.prot & PROT_READ) && (reg.prot & PROT_EXEC) && !memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
       if(libsimgrid_path == NULL)
           libsimgrid_path = strdup(maps->regions[i].pathname);
     }
@@ -242,6 +242,10 @@ mc_object_info_t MC_find_object_info(memory_map_t maps, char* name) {
   result->file_name = xbt_strdup(name);
   result->start_data = NULL;
   result->start_text = NULL;
+  result->start_plt = NULL;
+  result->end_plt = NULL;
+  result->start_got_plt = NULL;
+  result->end_got_plt = NULL;
   MC_find_object_address(maps, result);
   MC_get_plt_section(result);
   MC_dwarf_get_variables(result);
@@ -252,18 +256,15 @@ mc_object_info_t MC_find_object_info(memory_map_t maps, char* name) {
 static void MC_find_object_address(memory_map_t maps, mc_object_info_t result) {
   unsigned int i = 0;
   s_map_region_t reg;
-  const char* name = result->file_name;
-  int len = strlen(basename(result->file_name));
+  const char* name = basename(result->file_name);
   while (i < maps->mapsize) {
     reg = maps->regions[i];
-    if (maps->regions[i].pathname == NULL || memcmp(basename(maps->regions[i].pathname), basename(name), len)){
+    if (maps->regions[i].pathname == NULL || strcmp(basename(maps->regions[i].pathname),  name)) {
       // Nothing to do
     }
     else if ((reg.prot & PROT_WRITE)){
           result->start_data = reg.start_addr;
-          i++;
-          reg = maps->regions[i];
-    }else if (reg.prot & PROT_READ) {
+    } else if ((reg.prot & PROT_READ) && (reg.prot & PROT_EXEC)){
           result->start_text = reg.start_addr;
     }
     i++;
diff --git a/src/mc/mc_dwarf.c b/src/mc/mc_dwarf.c
new file mode 100644 (file)
index 0000000..195cce2
--- /dev/null
@@ -0,0 +1,400 @@
+/* Copyright (c) 2008-2013. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include <stdlib.h>
+#include <dwarf.h>
+#include <elfutils/libdw.h>
+#include <inttypes.h>
+
+#include <simgrid_config.h>
+#include <xbt/log.h>
+#include <xbt/sysdep.h>
+
+#include "mc_private.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_dwarf, mc, "DWARF processing");
+
+/** \brief The default DW_TAG_lower_bound for a given DW_AT_language.
+ *
+ *  The default for a given language is defined in the DWARF spec.
+ */
+static uint64_t MC_dwarf_default_lower_bound(int lang);
+
+static uint64_t MC_dwarf_subrange_element_count(Dwarf_Die* die, Dwarf_Die* unit);
+
+/** \brief Computes the number of elements of a given DW_TAG_array_type
+ *
+ */
+static uint64_t MC_dwarf_array_element_count(Dwarf_Die* die, Dwarf_Die* unit);
+
+/** \brief Checks if a given tag is a (known) type tag.
+ */
+static int MC_dwarf_tag_type(int tag);
+static void MC_dwarf_handle_die(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit);
+static void MC_dwarf_handle_type_die(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit);
+static void MC_dwarf_handle_children(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit);
+static void MC_dwarf_handle_die(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit);
+static Dwarf_Die* MC_dwarf_resolve_die(Dwarf_Die* die, int attribute);
+
+const char* MC_dwarf_attrname(int attr) {
+  switch (attr) {
+#include "mc_dwarf_attrnames.h"
+  default:
+    return "DW_AT_unkown";
+  }
+}
+
+const char* MC_dwarf_tagname(int tag) {
+  switch (tag) {
+#include "mc_dwarf_tagnames.h"
+  case DW_TAG_invalid:
+    return "DW_TAG_invalid";
+  default:
+    return "DW_TAG_unkown";
+  }
+}
+
+static inline const char* MC_dwarf_die_tagname(Dwarf_Die* die) {
+  return MC_dwarf_tagname(dwarf_tag(die));
+}
+
+static int MC_dwarf_tag_type(int tag) {
+  switch(tag) {
+  case DW_TAG_array_type:
+  case DW_TAG_class_type:
+  case DW_TAG_enumeration_type:
+  case DW_TAG_typedef:
+  case DW_TAG_pointer_type:
+  case DW_TAG_string_type:
+  case DW_TAG_structure_type:
+  case DW_TAG_subroutine_type:
+  case DW_TAG_union_type:
+  case DW_TAG_ptr_to_member_type:
+  case DW_TAG_set_type:
+  case DW_TAG_subrange_type:
+  case DW_TAG_base_type:
+  case DW_TAG_const_type:
+  case DW_TAG_file_type:
+  case DW_TAG_packed_type:
+  case DW_TAG_volatile_type:
+  case DW_TAG_restrict_type:
+  case DW_TAG_interface_type:
+  case DW_TAG_unspecified_type:
+  case DW_TAG_mutable_type:
+  case DW_TAG_shared_type:
+  case DW_TAG_rvalue_reference_type:
+    return 1;
+  default:
+    return 0;
+  }
+}
+
+static const char* MC_dwarf_attr_string(Dwarf_Die* die, int attribute) {
+  Dwarf_Attribute attr;
+  if (!dwarf_attr_integrate(die, attribute, &attr)) {
+       return NULL;
+  } else {
+       return dwarf_formstring(&attr);
+  }
+}
+
+// Return a new string for the type (NULL if none)
+static char* MC_dwarf_at_type(Dwarf_Die* die) {
+  Dwarf_Attribute attr;
+  if (dwarf_hasattr_integrate(die, DW_AT_type)) {
+       dwarf_attr_integrate(die, DW_AT_type, &attr);
+       Dwarf_Die subtype_die;
+       if (dwarf_formref_die(&attr, &subtype_die)==NULL) {
+         xbt_die("Could not find DIE for type");
+       }
+       Dwarf_Off subtype_global_offset = dwarf_dieoffset(&subtype_die);
+    return bprintf("%" PRIx64 , subtype_global_offset);
+  }
+  else return NULL;
+}
+
+static uint64_t MC_dwarf_attr_uint(Dwarf_Die* die, int attribute, uint64_t default_value) {
+  Dwarf_Attribute attr;
+  Dwarf_Word value;
+  return dwarf_formudata(dwarf_attr_integrate(die, attribute, &attr), &value) == 0 ? (uint64_t) value : default_value;
+}
+
+static uint64_t MC_dwarf_default_lower_bound(int lang) {
+  switch(lang) {
+  case DW_LANG_C:
+  case DW_LANG_C89:
+  case DW_LANG_C99:
+  case DW_LANG_C_plus_plus:
+  case DW_LANG_D:
+  case DW_LANG_Java:
+  case DW_LANG_ObjC:
+  case DW_LANG_ObjC_plus_plus:
+  case DW_LANG_Python:
+  case DW_LANG_UPC:
+    return 0;
+  case DW_LANG_Ada83:
+  case DW_LANG_Ada95:
+  case DW_LANG_Fortran77:
+  case DW_LANG_Fortran90:
+  case DW_LANG_Fortran95:
+  case DW_LANG_Modula2:
+  case DW_LANG_Pascal83:
+  case DW_LANG_PL1:
+  case DW_LANG_Cobol74:
+  case DW_LANG_Cobol85:
+    return 1;
+  default:
+    xbt_die("No default MT_TAG_lower_bound for language %i and none given", lang);
+    return 0;
+  }
+}
+
+static uint64_t MC_dwarf_subrange_element_count(Dwarf_Die* die, Dwarf_Die* unit) {
+  // Use DW_TAG_count if present:
+  if (dwarf_hasattr_integrate(die, DW_AT_count)) {
+    return MC_dwarf_attr_uint(die, DW_AT_count, 0);
+  }
+
+  // Otherwise compute DW_TAG_upper_bound-DW_TAG_lower_bound:
+
+  if (!dwarf_hasattr_integrate(die, DW_AT_upper_bound)) {
+       // This is not really 0, but the code expects this (we do not know):
+    return 0;
+  }
+  uint64_t upper_bound = MC_dwarf_attr_uint(die, DW_AT_upper_bound, -1);
+
+  uint64_t lower_bound = 0;
+  if (dwarf_hasattr_integrate(die, DW_AT_lower_bound)) {
+    lower_bound = MC_dwarf_attr_uint(die, DW_AT_lower_bound, -1);
+  } else {
+       lower_bound = MC_dwarf_default_lower_bound(dwarf_srclang(unit));
+  }
+  return upper_bound - lower_bound;
+}
+
+static uint64_t MC_dwarf_array_element_count(Dwarf_Die* die, Dwarf_Die* unit) {
+  xbt_assert(dwarf_tag(die)==DW_TAG_array_type,
+    "MC_dwarf_array_element_count called with DIE of type %s", MC_dwarf_die_tagname(die));
+
+  int result = 1;
+  Dwarf_Die child;
+  int res;
+  for (res=dwarf_child(die, &child); res==0; res=dwarf_siblingof(&child,&child)) {
+       int child_tag = dwarf_tag(&child);
+    if (child_tag==DW_TAG_subrange_type ||child_tag==DW_TAG_enumeration_type) {
+      result *= MC_dwarf_subrange_element_count(&child, unit);
+    }
+  }
+  return result;
+}
+
+static void MC_dwarf_fill_member_location(dw_type_t type, dw_type_t member, Dwarf_Die* child) {
+  if (dwarf_hasattr(child, DW_AT_data_bit_offset)) {
+    xbt_die("Can't groke DW_AT_data_bit_offset.");
+  }
+
+  if (!dwarf_hasattr_integrate(child, DW_AT_data_member_location)) {
+    if (type->type != DW_TAG_union_type) {
+        xbt_die(
+          "Missing DW_AT_data_member_location field in DW_TAG_member %s of type <%p>%s",
+          member->name, type->id, type->name);
+    } else {
+      return;
+    }
+  }
+
+  Dwarf_Attribute attr;
+  dwarf_attr_integrate(child, DW_AT_data_member_location, &attr);
+  switch (dwarf_whatform(&attr)) {
+
+  case DW_FORM_exprloc:
+    {
+      //TODO, location can be an integer as well
+      Dwarf_Op* expr;
+      size_t len;
+      if (dwarf_getlocation(&attr, &expr, &len)) {
+        xbt_die(
+          "Could not read location expression DW_AT_data_member_location in DW_TAG_member %s of type <%p>%s",
+          MC_dwarf_attr_string(child, DW_AT_name),
+          type->id, type->name);
+      }
+      if (len==1 && expr[0].atom == DW_OP_plus_uconst) {
+        member->offset =  expr[0].number;
+      } else {
+        xbt_die("Can't groke this location expression yet. %i %i",
+          len==1 , expr[0].atom == DW_OP_plus_uconst);
+      }
+      break;
+    }
+  case DW_FORM_data1:
+  case DW_FORM_data2:
+  case DW_FORM_data4:
+  case DW_FORM_data8:
+  case DW_FORM_sdata:
+  case DW_FORM_udata:
+    {
+      Dwarf_Word offset;
+      if (!dwarf_formudata(&attr, &offset))
+        member->offset = offset;
+      else
+        xbt_die("Cannot get DW_AT_data_member_%s location <%p>%s",
+          MC_dwarf_attr_string(child, DW_AT_name),
+          type->id, type->name);
+      break;
+    }
+  }
+}
+
+static void MC_dwarf_add_members(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit, dw_type_t type) {
+  int res;
+  Dwarf_Die child;
+  xbt_assert(!type->members);
+  type->members = xbt_dynar_new(sizeof(dw_type_t), (void(*)(void*))dw_type_free);
+  for (res=dwarf_child(die, &child); res==0; res=dwarf_siblingof(&child,&child)) {
+    if (dwarf_tag(&child)==DW_TAG_member) {
+      // TODO, we should use another type (because is is not a type but a member)
+      dw_type_t member = xbt_new0(s_dw_type_t, 1);
+      member->type = -1;
+      member->id = NULL;
+
+      const char* name = MC_dwarf_attr_string(&child, DW_AT_name);
+      if(name)
+        member->name = xbt_strdup(name);
+      else
+        member->name = NULL;
+
+      member->byte_size = MC_dwarf_attr_uint(&child, DW_AT_byte_size, 0);
+      member->element_count = -1;
+      member->dw_type_id = MC_dwarf_at_type(&child);
+      member->members = NULL;
+      member->is_pointer_type = 0;
+      member->offset = 0;
+
+      if(dwarf_hasattr(&child, DW_AT_data_bit_offset)) {
+        xbt_die("Can't groke DW_AT_data_bit_offset.");
+      }
+
+      MC_dwarf_fill_member_location(type, member, &child);
+
+      xbt_dynar_push(type->members, &member);
+    }
+  }
+}
+
+static dw_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit) {
+
+  dw_type_t type = xbt_new0(s_dw_type_t, 1);
+  type->type = -1;
+  type->id = NULL;
+  type->name = NULL;
+  type->byte_size = 0;
+  type->element_count = -1;
+  type->dw_type_id = NULL;
+  type->members = NULL;
+  type->is_pointer_type = 0;
+  type->offset = 0;
+
+  type->type = dwarf_tag(die);
+
+  // Global Offset
+  type->id = (void *) dwarf_dieoffset(die);
+
+  const char* name = MC_dwarf_attr_string(die, DW_AT_name);
+  if (name!=NULL) {
+       type->name = xbt_strdup(name);
+  }
+
+  XBT_DEBUG("Processing type <%p>%s", type->id, type->name);
+
+  type->dw_type_id = MC_dwarf_at_type(die);
+
+  // Computation of the byte_size;
+  if (dwarf_hasattr_integrate(die, DW_AT_byte_size))
+    type->byte_size = MC_dwarf_attr_uint(die, DW_AT_byte_size, 0);
+  else if (type->type == DW_TAG_array_type || type->type==DW_TAG_structure_type || type->type==DW_TAG_class_type) {
+    Dwarf_Word size;
+    if (dwarf_aggregate_size(die, &size)==0) {
+      type->byte_size = size;
+    }
+  }
+
+  switch (type->type) {
+  case DW_TAG_array_type:
+       type->element_count = MC_dwarf_array_element_count(die, unit);
+       // TODO, handle DW_byte_stride and (not) DW_bit_stride
+       break;
+
+  case DW_TAG_pointer_type:
+  case DW_TAG_reference_type:
+  case DW_TAG_rvalue_reference_type:
+    type->is_pointer_type = 1;
+    break;
+
+  case DW_TAG_structure_type:
+  case DW_TAG_union_type:
+  case DW_TAG_class_type:
+         MC_dwarf_add_members(info, die, unit, type);
+  }
+
+  return type;
+}
+
+static void MC_dwarf_handle_type_die(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit) {
+  dw_type_t type = MC_dwarf_die_to_type(info, die, unit);
+
+  char* key = bprintf("%" PRIx64, (uint64_t) type->id);
+  xbt_dict_set(info->types, key, type, NULL);
+}
+
+
+static void MC_dwarf_handle_children(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit) {
+  Dwarf_Die child;
+  int res;
+  for (res=dwarf_child(die, &child); res==0; res=dwarf_siblingof(&child,&child)) {
+    MC_dwarf_handle_die(info, &child, unit);
+  }
+}
+
+static void MC_dwarf_handle_die(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit) {
+       int tag = dwarf_tag(die);
+
+       // Register types:
+       if (MC_dwarf_tag_type(tag))
+               MC_dwarf_handle_type_die(info, die, unit);
+
+       // Other tag-specific handling:
+       else switch(tag) {
+
+       }
+
+       // Recursive processing od children DIE:
+       MC_dwarf_handle_children(info, die, unit);
+}
+
+void MC_dwarf_get_variables_libdw(mc_object_info_t info) {
+  int fd = open(info->file_name, O_RDONLY);
+  if (fd<0) {
+    xbt_die("Could not open file %s", info->file_name);
+  }
+  Dwarf *dwarf = dwarf_begin(fd, DWARF_C_READ);
+  if (dwarf==NULL) {
+    xbt_die("Your program must be compiled with -g");
+  }
+
+  Dwarf_Off offset = 0;
+  Dwarf_Off next_offset = 0;
+  size_t length;
+  while (dwarf_nextcu (dwarf, offset, &next_offset, &length, NULL, NULL, NULL) == 0) {
+    Dwarf_Die die;
+    if(dwarf_offdie(dwarf, offset+length, &die)!=NULL) {
+      MC_dwarf_handle_die(info, &die, &die);
+    }
+    offset = next_offset;
+  }
+
+  dwarf_end(dwarf);
+  close(fd);
+}
diff --git a/src/mc/mc_dwarf_attrnames.h b/src/mc/mc_dwarf_attrnames.h
new file mode 100644 (file)
index 0000000..6ddc3ab
--- /dev/null
@@ -0,0 +1,139 @@
+case DW_AT_sibling: return "DW_AT_sibling";
+case DW_AT_location: return "DW_AT_location";
+case DW_AT_name: return "DW_AT_name";
+case DW_AT_ordering: return "DW_AT_ordering";
+case DW_AT_subscr_data: return "DW_AT_subscr_data";
+case DW_AT_byte_size: return "DW_AT_byte_size";
+case DW_AT_bit_offset: return "DW_AT_bit_offset";
+case DW_AT_bit_size: return "DW_AT_bit_size";
+case DW_AT_element_list: return "DW_AT_element_list";
+case DW_AT_stmt_list: return "DW_AT_stmt_list";
+case DW_AT_low_pc: return "DW_AT_low_pc";
+case DW_AT_high_pc: return "DW_AT_high_pc";
+case DW_AT_language: return "DW_AT_language";
+case DW_AT_member: return "DW_AT_member";
+case DW_AT_discr: return "DW_AT_discr";
+case DW_AT_discr_value: return "DW_AT_discr_value";
+case DW_AT_visibility: return "DW_AT_visibility";
+case DW_AT_import: return "DW_AT_import";
+case DW_AT_string_length: return "DW_AT_string_length";
+case DW_AT_common_reference: return "DW_AT_common_reference";
+case DW_AT_comp_dir: return "DW_AT_comp_dir";
+case DW_AT_const_value: return "DW_AT_const_value";
+case DW_AT_containing_type: return "DW_AT_containing_type";
+case DW_AT_default_value: return "DW_AT_default_value";
+case DW_AT_inline: return "DW_AT_inline";
+case DW_AT_is_optional: return "DW_AT_is_optional";
+case DW_AT_lower_bound: return "DW_AT_lower_bound";
+case DW_AT_producer: return "DW_AT_producer";
+case DW_AT_prototyped: return "DW_AT_prototyped";
+case DW_AT_return_addr: return "DW_AT_return_addr";
+case DW_AT_start_scope: return "DW_AT_start_scope";
+case DW_AT_bit_stride: return "DW_AT_bit_stride";
+case DW_AT_upper_bound: return "DW_AT_upper_bound";
+case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
+case DW_AT_accessibility: return "DW_AT_accessibility";
+case DW_AT_address_class: return "DW_AT_address_class";
+case DW_AT_artificial: return "DW_AT_artificial";
+case DW_AT_base_types: return "DW_AT_base_types";
+case DW_AT_calling_convention: return "DW_AT_calling_convention";
+case DW_AT_count: return "DW_AT_count";
+case DW_AT_data_member_location: return "DW_AT_data_member_location";
+case DW_AT_decl_column: return "DW_AT_decl_column";
+case DW_AT_decl_file: return "DW_AT_decl_file";
+case DW_AT_decl_line: return "DW_AT_decl_line";
+case DW_AT_declaration: return "DW_AT_declaration";
+case DW_AT_discr_list: return "DW_AT_discr_list";
+case DW_AT_encoding: return "DW_AT_encoding";
+case DW_AT_external: return "DW_AT_external";
+case DW_AT_frame_base: return "DW_AT_frame_base";
+case DW_AT_friend: return "DW_AT_friend";
+case DW_AT_identifier_case: return "DW_AT_identifier_case";
+case DW_AT_macro_info: return "DW_AT_macro_info";
+case DW_AT_namelist_item: return "DW_AT_namelist_item";
+case DW_AT_priority: return "DW_AT_priority";
+case DW_AT_segment: return "DW_AT_segment";
+case DW_AT_specification: return "DW_AT_specification";
+case DW_AT_static_link: return "DW_AT_static_link";
+case DW_AT_type: return "DW_AT_type";
+case DW_AT_use_location: return "DW_AT_use_location";
+case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
+case DW_AT_virtuality: return "DW_AT_virtuality";
+case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
+case DW_AT_allocated: return "DW_AT_allocated";
+case DW_AT_associated: return "DW_AT_associated";
+case DW_AT_data_location: return "DW_AT_data_location";
+case DW_AT_byte_stride: return "DW_AT_byte_stride";
+case DW_AT_entry_pc: return "DW_AT_entry_pc";
+case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
+case DW_AT_extension: return "DW_AT_extension";
+case DW_AT_ranges: return "DW_AT_ranges";
+case DW_AT_trampoline: return "DW_AT_trampoline";
+case DW_AT_call_column: return "DW_AT_call_column";
+case DW_AT_call_file: return "DW_AT_call_file";
+case DW_AT_call_line: return "DW_AT_call_line";
+case DW_AT_description: return "DW_AT_description";
+case DW_AT_binary_scale: return "DW_AT_binary_scale";
+case DW_AT_decimal_scale: return "DW_AT_decimal_scale";
+case DW_AT_small: return "DW_AT_small";
+case DW_AT_decimal_sign: return "DW_AT_decimal_sign";
+case DW_AT_digit_count: return "DW_AT_digit_count";
+case DW_AT_picture_string: return "DW_AT_picture_string";
+case DW_AT_mutable: return "DW_AT_mutable";
+case DW_AT_threads_scaled: return "DW_AT_threads_scaled";
+case DW_AT_explicit: return "DW_AT_explicit";
+case DW_AT_object_pointer: return "DW_AT_object_pointer";
+case DW_AT_endianity: return "DW_AT_endianity";
+case DW_AT_elemental: return "DW_AT_elemental";
+case DW_AT_pure: return "DW_AT_pure";
+case DW_AT_recursive: return "DW_AT_recursive";
+case DW_AT_signature: return "DW_AT_signature";
+case DW_AT_main_subprogram: return "DW_AT_main_subprogram";
+case DW_AT_data_bit_offset: return "DW_AT_data_bit_offset";
+case DW_AT_const_expr: return "DW_AT_const_expr";
+case DW_AT_enum_class: return "DW_AT_enum_class";
+case DW_AT_linkage_name: return "DW_AT_linkage_name";
+case DW_AT_lo_user: return "DW_AT_lo_user";
+case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
+case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
+case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
+case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
+case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
+case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
+case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
+case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
+case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
+case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
+case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
+case DW_AT_MIPS_stride_byte: return "DW_AT_MIPS_stride_byte";
+case DW_AT_MIPS_stride_elem: return "DW_AT_MIPS_stride_elem";
+case DW_AT_MIPS_ptr_dopetype: return "DW_AT_MIPS_ptr_dopetype";
+case DW_AT_MIPS_allocatable_dopetype: return "DW_AT_MIPS_allocatable_dopetype";
+case DW_AT_MIPS_assumed_shape_dopetype: return "DW_AT_MIPS_assumed_shape_dopetype";
+case DW_AT_MIPS_assumed_size: return "DW_AT_MIPS_assumed_size";
+case DW_AT_sf_names: return "DW_AT_sf_names";
+case DW_AT_src_info: return "DW_AT_src_info";
+case DW_AT_mac_info: return "DW_AT_mac_info";
+case DW_AT_src_coords: return "DW_AT_src_coords";
+case DW_AT_body_begin: return "DW_AT_body_begin";
+case DW_AT_body_end: return "DW_AT_body_end";
+case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
+case DW_AT_GNU_guarded_by: return "DW_AT_GNU_guarded_by";
+case DW_AT_GNU_pt_guarded_by: return "DW_AT_GNU_pt_guarded_by";
+case DW_AT_GNU_guarded: return "DW_AT_GNU_guarded";
+case DW_AT_GNU_pt_guarded: return "DW_AT_GNU_pt_guarded";
+case DW_AT_GNU_locks_excluded: return "DW_AT_GNU_locks_excluded";
+case DW_AT_GNU_exclusive_locks_required: return "DW_AT_GNU_exclusive_locks_required";
+case DW_AT_GNU_shared_locks_required: return "DW_AT_GNU_shared_locks_required";
+case DW_AT_GNU_odr_signature: return "DW_AT_GNU_odr_signature";
+case DW_AT_GNU_template_name: return "DW_AT_GNU_template_name";
+case DW_AT_GNU_call_site_value: return "DW_AT_GNU_call_site_value";
+case DW_AT_GNU_call_site_data_value: return "DW_AT_GNU_call_site_data_value";
+case DW_AT_GNU_call_site_target: return "DW_AT_GNU_call_site_target";
+case DW_AT_GNU_call_site_target_clobbered: return "DW_AT_GNU_call_site_target_clobbered";
+case DW_AT_GNU_tail_call: return "DW_AT_GNU_tail_call";
+case DW_AT_GNU_all_tail_call_sites: return "DW_AT_GNU_all_tail_call_sites";
+case DW_AT_GNU_all_call_sites: return "DW_AT_GNU_all_call_sites";
+case DW_AT_GNU_all_source_call_sites: return "DW_AT_GNU_all_source_call_sites";
+case DW_AT_GNU_macros: return "DW_AT_GNU_macros";
+case DW_AT_hi_user: return "DW_AT_hi_user";
diff --git a/src/mc/mc_dwarf_tagnames.h b/src/mc/mc_dwarf_tagnames.h
new file mode 100644 (file)
index 0000000..8739af6
--- /dev/null
@@ -0,0 +1,74 @@
+case DW_TAG_array_type: return "DW_TAG_array_type";
+case DW_TAG_class_type: return "DW_TAG_class_type";
+case DW_TAG_entry_point: return "DW_TAG_entry_point";
+case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
+case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
+case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
+case DW_TAG_label: return "DW_TAG_label";
+case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
+case DW_TAG_member: return "DW_TAG_member";
+case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
+case DW_TAG_reference_type: return "DW_TAG_reference_type";
+case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
+case DW_TAG_string_type: return "DW_TAG_string_type";
+case DW_TAG_structure_type: return "DW_TAG_structure_type";
+case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
+case DW_TAG_typedef: return "DW_TAG_typedef";
+case DW_TAG_union_type: return "DW_TAG_union_type";
+case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
+case DW_TAG_variant: return "DW_TAG_variant";
+case DW_TAG_common_block: return "DW_TAG_common_block";
+case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
+case DW_TAG_inheritance: return "DW_TAG_inheritance";
+case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
+case DW_TAG_module: return "DW_TAG_module";
+case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
+case DW_TAG_set_type: return "DW_TAG_set_type";
+case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
+case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
+case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
+case DW_TAG_base_type: return "DW_TAG_base_type";
+case DW_TAG_catch_block: return "DW_TAG_catch_block";
+case DW_TAG_const_type: return "DW_TAG_const_type";
+case DW_TAG_constant: return "DW_TAG_constant";
+case DW_TAG_enumerator: return "DW_TAG_enumerator";
+case DW_TAG_file_type: return "DW_TAG_file_type";
+case DW_TAG_friend: return "DW_TAG_friend";
+case DW_TAG_namelist: return "DW_TAG_namelist";
+case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
+case DW_TAG_packed_type: return "DW_TAG_packed_type";
+case DW_TAG_subprogram: return "DW_TAG_subprogram";
+case DW_TAG_template_type_parameter: return "DW_TAG_template_type_parameter";
+case DW_TAG_template_value_parameter: return "DW_TAG_template_value_parameter";
+case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
+case DW_TAG_try_block: return "DW_TAG_try_block";
+case DW_TAG_variant_part: return "DW_TAG_variant_part";
+case DW_TAG_variable: return "DW_TAG_variable";
+case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
+case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
+case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
+case DW_TAG_interface_type: return "DW_TAG_interface_type";
+case DW_TAG_namespace: return "DW_TAG_namespace";
+case DW_TAG_imported_module: return "DW_TAG_imported_module";
+case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
+case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
+case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
+case DW_TAG_mutable_type: return "DW_TAG_mutable_type";
+case DW_TAG_condition: return "DW_TAG_condition";
+case DW_TAG_shared_type: return "DW_TAG_shared_type";
+case DW_TAG_type_unit: return "DW_TAG_type_unit";
+case DW_TAG_rvalue_reference_type: return "DW_TAG_rvalue_reference_type";
+case DW_TAG_template_alias: return "DW_TAG_template_alias";
+case DW_TAG_lo_user: return "DW_TAG_lo_user";
+case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
+case DW_TAG_format_label: return "DW_TAG_format_label";
+case DW_TAG_function_template: return "DW_TAG_function_template";
+case DW_TAG_class_template: return "DW_TAG_class_template";
+case DW_TAG_GNU_BINCL: return "DW_TAG_GNU_BINCL";
+case DW_TAG_GNU_EINCL: return "DW_TAG_GNU_EINCL";
+case DW_TAG_GNU_template_template_param: return "DW_TAG_GNU_template_template_param";
+case DW_TAG_GNU_template_parameter_pack: return "DW_TAG_GNU_template_parameter_pack";
+case DW_TAG_GNU_formal_parameter_pack: return "DW_TAG_GNU_formal_parameter_pack";
+case DW_TAG_GNU_call_site: return "DW_TAG_GNU_call_site";
+case DW_TAG_GNU_call_site_parameter: return "DW_TAG_GNU_call_site_parameter";
+case DW_TAG_hi_user: return "DW_TAG_hi_user";
index 8164ac3..07b7e20 100644 (file)
@@ -150,7 +150,7 @@ static void dw_location_entry_free(dw_location_entry_t e){
   xbt_free(e);
 }
 
-static void dw_type_free(dw_type_t t){
+void dw_type_free(dw_type_t t){
   xbt_free(t->name);
   xbt_free(t->dw_type_id);
   xbt_dynar_free(&(t->members));
@@ -534,6 +534,8 @@ static int MC_dwarf_get_variable_index(xbt_dynar_t variables, char* var, void *a
 
 /** \brief Fill DWARf debug infomations (types, frames, variables ...). */
 void MC_dwarf_get_variables(mc_object_info_t info) {
+  if(MC_USE_LIBDW_TYPES)
+    MC_dwarf_get_variables_libdw(info);
   mc_object_info_t result = info;
   const char *elf_file = info->file_name;
 
@@ -918,13 +920,13 @@ void MC_dwarf_get_variables(mc_object_info_t info) {
       
       }
 
-    }else if(strcmp(node_type, "(DW_TAG_base_type)") == 0 
+    }else if(!MC_USE_LIBDW_TYPES&&(strcmp(node_type, "(DW_TAG_base_type)") == 0
              || strcmp(node_type, "(DW_TAG_enumeration_type)") == 0
              || strcmp(node_type, "(DW_TAG_typedef)") == 0
              || strcmp(node_type, "(DW_TAG_const_type)") == 0
              || strcmp(node_type, "(DW_TAG_subroutine_type)") == 0
              || strcmp(node_type, "(DW_TAG_volatile_type)") == 0
-             || (is_pointer = !strcmp(node_type, "(DW_TAG_pointer_type)"))){
+             || (is_pointer = !strcmp(node_type, "(DW_TAG_pointer_type)")))){
 
       /* Create the and add it to the types dictionnary */
 
@@ -1284,17 +1286,23 @@ void MC_dwarf_get_variables(mc_object_info_t info) {
   MC_post_process_types(info);
 }
 
+static void MC_post_process_array_size(mc_object_info_t info, dw_type_t type) {
+  xbt_assert(type->dw_type_id, "No base type for array <%p>%s", type->id, type->name);
+  dw_type_t subtype = xbt_dict_get_or_null(info->types, type->dw_type_id);
+  xbt_assert(subtype, "Unkown base type <%s> for array <%p>%s", type->dw_type_id, type->id, type->name);
+  if(subtype->type==DW_TAG_array_type && type->byte_size==0) {
+         MC_post_process_array_size(info, subtype);
+  }
+  type->byte_size = type->element_count*subtype->byte_size;
+}
+
 static void MC_post_process_types(mc_object_info_t info) {
   xbt_dict_cursor_t cursor;
   char *origin;
   dw_type_t type;
   xbt_dict_foreach(info->types, cursor, origin, type){
-    if(type->type==DW_TAG_array_type) {
-      xbt_assert(type->dw_type_id, "No base type for array <%p>%s", type->id, type->name);
-      dw_type_t subtype = xbt_dict_get_or_null(info->types, type->dw_type_id);
-         xbt_assert(subtype, "Unkown base type for array <%p>%s", type->id, type->name);
-      type->byte_size = type->element_count*subtype->byte_size;
-    }
+    if(type->type==DW_TAG_array_type && type->byte_size==0)
+      MC_post_process_array_size(info, type);
   }
 }
 
index 9d438f7..941cc0d 100644 (file)
@@ -335,6 +335,9 @@ mc_object_info_t MC_find_object_info(memory_map_t maps, char* name);
 void MC_free_object_info(mc_object_info_t* p);
 
 void MC_dwarf_get_variables(mc_object_info_t info);
+void MC_dwarf_get_variables_libdw(mc_object_info_t info);
+const char* MC_dwarf_attrname(int attr);
+const char* MC_dwarf_tagname(int tag);
 
 extern mc_object_info_t mc_libsimgrid_info;
 extern mc_object_info_t mc_binary_info;
@@ -421,6 +424,10 @@ typedef struct s_dw_frame{
   unsigned long int end;   /* Dwarf offset of the next sibling */
 }s_dw_frame_t, *dw_frame_t;
 
+void dw_type_free(dw_type_t t);
+
+/********************************** DWARF **********************************/
+
 /********************************** Miscellaneous **********************************/
 
 typedef struct s_local_variable{
@@ -432,5 +439,7 @@ typedef struct s_local_variable{
   int region;
 }s_local_variable_t, *local_variable_t;
 
+#define MC_USE_LIBDW_TYPES 1
+
 #endif