*/
static std::uint64_t MC_dwarf_at_type(Dwarf_Die * die);
-/** \brief A class of DWARF tags (DW_TAG_*)
- */
-typedef enum mc_tag_class {
- mc_tag_unknown,
- mc_tag_type,
- mc_tag_subprogram,
- mc_tag_variable,
- mc_tag_scope,
- mc_tag_namespace
-} mc_tag_class;
-
-static mc_tag_class MC_dwarf_tag_classify(int tag)
+namespace simgrid {
+namespace dwarf {
+
+enum class TagClass {
+ Unknown,
+ Type,
+ Subprogram,
+ Variable,
+ Scope,
+ Namespace
+};
+
+namespace {
+
+TagClass classify_tag(int tag)
{
switch (tag) {
case DW_TAG_interface_type:
case DW_TAG_unspecified_type:
case DW_TAG_shared_type:
- return mc_tag_type;
+ return TagClass::Type;
case DW_TAG_subprogram:
- return mc_tag_subprogram;
+ return TagClass::Subprogram;
case DW_TAG_variable:
case DW_TAG_formal_parameter:
- return mc_tag_variable;
+ return TagClass::Variable;
case DW_TAG_lexical_block:
case DW_TAG_try_block:
case DW_TAG_catch_block:
case DW_TAG_inlined_subroutine:
case DW_TAG_with_stmt:
- return mc_tag_scope;
+ return TagClass::Scope;
case DW_TAG_namespace:
- return mc_tag_namespace;
+ return TagClass::Namespace;
default:
- return mc_tag_unknown;
-
+ return TagClass::Unknown;
}
}
+}
+}
+}
+
#define MC_DW_CLASS_UNKNOWN 0
#define MC_DW_CLASS_ADDRESS 1 // Location in the address space of the program
#define MC_DW_CLASS_BLOCK 2 // Arbitrary block of bytes
* \param member the member of the type
* \param child DIE of the member (DW_TAG_member)
*/
-static void MC_dwarf_fill_member_location(simgrid::mc::Type* type, simgrid::mc::Type* member,
- Dwarf_Die * child)
+static void MC_dwarf_fill_member_location(
+ simgrid::mc::Type* type, simgrid::mc::Member* member, Dwarf_Die * child)
{
if (dwarf_hasattr(child, DW_AT_data_bit_offset))
xbt_die("Can't groke DW_AT_data_bit_offset.");
continue;
// TODO, we should use another type (because is is not a type but a member)
- simgrid::mc::Type member;
- member.type = tag;
-
- // Global Offset:
- member.id = dwarf_dieoffset(&child);
+ simgrid::mc::Member member;
+ member.inheritance = tag == DW_TAG_inheritance;
const char *name = MC_dwarf_attr_integrate_string(&child, DW_AT_name);
if (name)
member.name = name;
member.byte_size =
MC_dwarf_attr_integrate_uint(&child, DW_AT_byte_size, 0);
- member.element_count = -1;
member.type_id = MC_dwarf_at_type(&child);
if (dwarf_hasattr(&child, DW_AT_data_bit_offset))
{
// TODO, handle DW_TAG_type/DW_TAG_location for DW_TAG_with_stmt
int tag = dwarf_tag(die);
- mc_tag_class klass = MC_dwarf_tag_classify(tag);
+ simgrid::dwarf::TagClass klass = simgrid::dwarf::classify_tag(tag);
// (Template) Subprogram declaration:
- if (klass == mc_tag_subprogram
+ if (klass == simgrid::dwarf::TagClass::Subprogram
&& MC_dwarf_attr_flag(die, DW_AT_declaration, false))
return;
- if (klass == mc_tag_scope)
+ if (klass == simgrid::dwarf::TagClass::Scope)
xbt_assert(parent_frame, "No parent scope for this scope");
simgrid::mc::Frame frame;
frame.id = dwarf_dieoffset(die);
frame.object_info = info;
- if (klass == mc_tag_subprogram) {
+ if (klass == simgrid::dwarf::TagClass::Subprogram) {
const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_name);
if(ns)
frame.name = std::string(ns) + "::" + name;
}
}
- if (klass == mc_tag_subprogram) {
+ if (klass == simgrid::dwarf::TagClass::Subprogram) {
Dwarf_Attribute attr_frame_base;
if (dwarf_attr_integrate(die, DW_AT_frame_base, &attr_frame_base))
mc_dwarf_location_list_init(&frame.frame_base, info, die,
MC_compare_variable);
// Register it:
- if (klass == mc_tag_subprogram)
+ if (klass == simgrid::dwarf::TagClass::Subprogram)
info->subprograms[frame.id] = frame;
- else if (klass == mc_tag_scope)
+ else if (klass == simgrid::dwarf::TagClass::Scope)
parent_frame->scopes.push_back(std::move(frame));
}
const char *ns)
{
int tag = dwarf_tag(die);
- mc_tag_class klass = MC_dwarf_tag_classify(tag);
+ simgrid::dwarf::TagClass klass = simgrid::dwarf::classify_tag(tag);
switch (klass) {
// Type:
- case mc_tag_type:
+ case simgrid::dwarf::TagClass::Type:
MC_dwarf_handle_type_die(info, die, unit, frame, ns);
break;
// Subprogram or scope:
- case mc_tag_subprogram:
- case mc_tag_scope:
+ case simgrid::dwarf::TagClass::Subprogram:
+ case simgrid::dwarf::TagClass::Scope:
MC_dwarf_handle_scope_die(info, die, unit, frame, ns);
return;
// Variable:
- case mc_tag_variable:
+ case simgrid::dwarf::TagClass::Variable:
MC_dwarf_handle_variable_die(info, die, unit, frame, ns);
break;
- case mc_tag_namespace:
+ case simgrid::dwarf::TagClass::Namespace:
mc_dwarf_handle_namespace_die(info, die, unit, frame, ns);
break;
}
-/** \brief Fill/lookup the "subtype" field.
- */
-static void MC_resolve_subtype(simgrid::mc::ObjectInformation* info, simgrid::mc::Type* type)
+static
+simgrid::mc::Type* MC_resolve_type(
+ simgrid::mc::ObjectInformation* info, unsigned type_id)
{
- if (!type->type_id)
- return;
- type->subtype = simgrid::util::find_map_ptr(info->types, type->type_id);
- if (type->subtype == nullptr)
- return;
- if (type->subtype->byte_size != 0)
- return;
- if (type->subtype->name.empty())
- return;
+ if (!type_id)
+ return nullptr;
+ simgrid::mc::Type* type = simgrid::util::find_map_ptr(info->types, type_id);
+ if (type == nullptr)
+ return nullptr;
+
+ // We already have the information on the type:
+ if (type->byte_size != 0)
+ return type;
+
+ // Don't have a name, we can't find a more complete version:
+ if (type->name.empty())
+ return type;
+
// Try to find a more complete description of the type:
// We need to fix in order to support C++.
simgrid::mc::Type** subtype = simgrid::util::find_map_ptr(
- info->full_types_by_name, type->subtype->name);
+ info->full_types_by_name, type->name);
if (subtype)
- type->subtype = *subtype;
+ type = *subtype;
+ return type;
}
static void MC_post_process_types(simgrid::mc::ObjectInformation* info)
{
// Lookup "subtype" field:
for(auto& i : info->types) {
- MC_resolve_subtype(info, &(i.second));
- for (simgrid::mc::Type& member : i.second.members)
- MC_resolve_subtype(info, &member);
+ i.second.subtype = MC_resolve_type(info, i.second.type_id);
+ for (simgrid::mc::Member& member : i.second.members)
+ member.type = MC_resolve_type(info, member.type_id);
}
}