static int get_member_size(Dwarf_Die *type_die, Dwarf_Word *msize_out) { if (dwarf_aggregate_size(type_die, msize_out) != -1) return (0); if (dwarf_tag(type_die) == DW_TAG_pointer_type) return (pointer_size); dwarf_err(EX_DATAERR, "dwarf_aggregate_size"); return (-1); }
/* If this type is an HFA small enough to be returned in FP registers, return the number of registers to use. Otherwise 9, or -1 for errors. */ static int hfa_type (Dwarf_Die *typedie, Dwarf_Word size, const Dwarf_Op **locp, int fpregs_used) { /* Descend the type structure, counting elements and finding their types. If we find a datum that's not an FP type (and not quad FP), punt. If we find a datum that's not the same FP type as the first datum, punt. If we count more than eight total homogeneous FP data, punt. */ inline int hfa (const Dwarf_Op *loc, int nregs) { if (fpregs_used == 0) *locp = loc; else if (*locp != loc) return 9; return fpregs_used + nregs; } int tag = DWARF_TAG_OR_RETURN (typedie); switch (tag) { Dwarf_Attribute attr_mem; case -1: return -1; case DW_TAG_base_type:; Dwarf_Word encoding; if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding, &attr_mem), &encoding) != 0) return -1; switch (encoding) { case DW_ATE_float: switch (size) { case 4: /* float */ return hfa (loc_fpreg_4, 1); case 8: /* double */ return hfa (loc_fpreg_8, 1); case 10: /* x86-style long double, not really used */ return hfa (loc_fpreg_10, 1); } break; case DW_ATE_complex_float: switch (size) { case 4 * 2: /* complex float */ return hfa (loc_fpreg_4, 2); case 8 * 2: /* complex double */ return hfa (loc_fpreg_8, 2); case 10 * 2: /* complex long double (x86-style) */ return hfa (loc_fpreg_10, 2); } break; } break; case DW_TAG_structure_type: case DW_TAG_class_type: case DW_TAG_union_type:; Dwarf_Die child_mem; switch (dwarf_child (typedie, &child_mem)) { default: return -1; case 1: /* No children: empty struct. */ break; case 0:; /* Look at each element. */ int max_used = fpregs_used; do switch (dwarf_tag (&child_mem)) { case -1: return -1; case DW_TAG_member:; Dwarf_Die child_type_mem; Dwarf_Die *child_typedie = dwarf_formref_die (dwarf_attr_integrate (&child_mem, DW_AT_type, &attr_mem), &child_type_mem); Dwarf_Word child_size; if (dwarf_aggregate_size (child_typedie, &child_size) != 0) return -1; if (tag == DW_TAG_union_type) { int used = hfa_type (child_typedie, child_size, locp, fpregs_used); if (used < 0 || used > 8) return used; if (used > max_used) max_used = used; } else { fpregs_used = hfa_type (child_typedie, child_size, locp, fpregs_used); if (fpregs_used < 0 || fpregs_used > 8) return fpregs_used; } } while (dwarf_siblingof (&child_mem, &child_mem) == 0); if (tag == DW_TAG_union_type) fpregs_used = max_used; break; } break; case DW_TAG_array_type: if (size == 0) break; Dwarf_Die base_type_mem; Dwarf_Die *base_typedie = dwarf_formref_die (dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem), &base_type_mem); Dwarf_Word base_size; if (dwarf_aggregate_size (base_typedie, &base_size) != 0) return -1; int used = hfa_type (base_typedie, base_size, locp, 0); if (used < 0 || used > 8) return used; if (size % (*locp)[1].number != 0) return 0; fpregs_used += used * (size / (*locp)[1].number); break; default: return 9; } return fpregs_used; }
int ia64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp) { /* Start with the function's type, and get the DW_AT_type attribute, which is the type of the return value. */ Dwarf_Attribute attr_mem; Dwarf_Attribute *attr = dwarf_attr_integrate (functypedie, DW_AT_type, &attr_mem); if (attr == NULL) /* The function has no return value, like a `void' function in C. */ return 0; Dwarf_Die die_mem; Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem); int tag = DWARF_TAG_OR_RETURN (typedie); /* Follow typedefs and qualifiers to get to the actual type. */ while (tag == DW_TAG_typedef || tag == DW_TAG_const_type || tag == DW_TAG_volatile_type || tag == DW_TAG_restrict_type || tag == DW_TAG_mutable_type) { attr = dwarf_attr (typedie, DW_AT_type, &attr_mem); typedie = dwarf_formref_die (attr, &die_mem); tag = DWARF_TAG_OR_RETURN (typedie); } Dwarf_Word size; switch (tag) { case -1: return -1; case DW_TAG_subrange_type: if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size)) { attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem); typedie = dwarf_formref_die (attr, &die_mem); tag = DWARF_TAG_OR_RETURN (typedie); } /* Fall through. */ case DW_TAG_base_type: case DW_TAG_enumeration_type: case DW_TAG_pointer_type: case DW_TAG_ptr_to_member_type: if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size, &attr_mem), &size) != 0) { if (tag == DW_TAG_pointer_type || tag == DW_TAG_ptr_to_member_type) size = 8; else return -1; } if (tag == DW_TAG_base_type) { Dwarf_Word encoding; if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding, &attr_mem), &encoding) != 0) return -1; switch (encoding) { case DW_ATE_float: switch (size) { case 4: /* float */ *locp = loc_fpreg_4; return nloc_fpreg; case 8: /* double */ *locp = loc_fpreg_8; return nloc_fpreg; case 10: /* x86-style long double, not really used */ *locp = loc_fpreg_10; return nloc_fpreg; case 16: /* long double, IEEE quad format */ *locp = loc_intreg; return nloc_intregs (2); } return -2; case DW_ATE_complex_float: switch (size) { case 4 * 2: /* complex float */ *locp = loc_fpreg_4; return nloc_fpregs (2); case 8 * 2: /* complex double */ *locp = loc_fpreg_8; return nloc_fpregs (2); case 10 * 2: /* complex long double (x86-style) */ *locp = loc_fpreg_10; return nloc_fpregs (2); case 16 * 2: /* complex long double (IEEE quad) */ *locp = loc_intreg; return nloc_intregs (4); } return -2; } } intreg: *locp = loc_intreg; if (size <= 8) return nloc_intreg; if (size <= 32) return nloc_intregs ((size + 7) / 8); large: *locp = loc_aggregate; return nloc_aggregate; case DW_TAG_structure_type: case DW_TAG_class_type: case DW_TAG_union_type: case DW_TAG_array_type: if (dwarf_aggregate_size (typedie, &size) != 0) return -1; /* If this qualifies as an homogeneous floating-point aggregate (HFA), then it should be returned in FP regs. */ int nfpreg = hfa_type (typedie, size, locp, 0); if (nfpreg < 0) return nfpreg; else if (nfpreg > 0 && nfpreg <= 8) return nfpreg == 1 ? nloc_fpreg : nloc_fpregs (nfpreg); if (size > 32) goto large; goto intreg; } /* XXX We don't have a good way to return specific errors from ebl calls. This value means we do not understand the type, but it is well-formed DWARF and might be valid. */ return -2; }
/** \brief Create a MC type object from a DIE * * \param info current object info object * \param die DIE (for a given type) * \param unit compilation unit of the current DIE * \return MC representation of the type */ static simgrid::mc::Type MC_dwarf_die_to_type( simgrid::mc::ObjectInformation* info, Dwarf_Die * die, Dwarf_Die * unit, simgrid::mc::Frame* frame, const char *ns) { simgrid::mc::Type type; type.type = dwarf_tag(die); type.name = std::string(); type.element_count = -1; // Global Offset type.id = dwarf_dieoffset(die); const char *prefix = ""; switch (type.type) { case DW_TAG_structure_type: prefix = "struct "; break; case DW_TAG_union_type: prefix = "union "; break; case DW_TAG_class_type: prefix = "class "; break; default: prefix = ""; } const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_name); if (name != nullptr) { if (ns) type.name = simgrid::xbt::string_printf("%s%s::%s", prefix, ns, name); else type.name = simgrid::xbt::string_printf("%s%s", prefix, name); } type.type_id = MC_dwarf_at_type(die); // Some compilers do not emit DW_AT_byte_size for pointer_type, // so we fill this. We currently assume that the model-checked process is in // the same architecture.. if (type.type == DW_TAG_pointer_type) type.byte_size = sizeof(void*); // Computation of the byte_size if (dwarf_hasattr_integrate(die, DW_AT_byte_size)) type.byte_size = MC_dwarf_attr_integrate_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: break; case DW_TAG_structure_type: case DW_TAG_union_type: case DW_TAG_class_type: MC_dwarf_add_members(info, die, unit, &type); MC_dwarf_handle_children(info, die, unit, frame, ns ? simgrid::xbt::string_printf("%s::%s", ns, name).c_str() : type.name.c_str()); break; default: XBT_DEBUG("Unhandled type: %d (%s)", type.type, simgrid::dwarf::tagname(type.type)); break; } return type; }
int ppc_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp) { /* Start with the function's type, and get the DW_AT_type attribute, which is the type of the return value. */ Dwarf_Attribute attr_mem; Dwarf_Attribute *attr = dwarf_attr_integrate (functypedie, DW_AT_type, &attr_mem); if (attr == NULL) /* The function has no return value, like a `void' function in C. */ return 0; Dwarf_Die die_mem; Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem); int tag = dwarf_tag (typedie); /* Follow typedefs and qualifiers to get to the actual type. */ while (tag == DW_TAG_typedef || tag == DW_TAG_const_type || tag == DW_TAG_volatile_type || tag == DW_TAG_restrict_type || tag == DW_TAG_mutable_type) { attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem); typedie = dwarf_formref_die (attr, &die_mem); tag = dwarf_tag (typedie); } Dwarf_Word size; switch (tag) { case -1: return -1; case DW_TAG_subrange_type: if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size)) { attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem); typedie = dwarf_formref_die (attr, &die_mem); tag = dwarf_tag (typedie); } /* Fall through. */ case DW_TAG_base_type: case DW_TAG_enumeration_type: case DW_TAG_pointer_type: case DW_TAG_ptr_to_member_type: if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size, &attr_mem), &size) != 0) { if (tag == DW_TAG_pointer_type || tag == DW_TAG_ptr_to_member_type) size = 4; else return -1; } if (size <= 8) { if (tag == DW_TAG_base_type) { Dwarf_Word encoding; if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding, &attr_mem), &encoding) != 0) return -1; if (encoding == DW_ATE_float) { *locp = loc_fpreg; return nloc_fpreg; } } intreg: *locp = loc_intreg; return size <= 4 ? nloc_intreg : nloc_intregpair; } aggregate: *locp = loc_aggregate; return nloc_aggregate; case DW_TAG_array_type: { bool is_vector; if (dwarf_formflag (dwarf_attr_integrate (typedie, DW_AT_GNU_vector, &attr_mem), &is_vector) == 0 && is_vector && dwarf_aggregate_size (typedie, &size) == 0) switch (size) { case 16: if (ppc_altivec_abi ()) { *locp = loc_vmxreg; return nloc_vmxreg; } *locp = loc_intreg; return nloc_intregquad; } } /* Fall through. */ case DW_TAG_structure_type: case DW_TAG_class_type: case DW_TAG_union_type: if (SVR4_STRUCT_RETURN && dwarf_aggregate_size (typedie, &size) == 0 && size > 0 && size <= 8) goto intreg; goto aggregate; } /* XXX We don't have a good way to return specific errors from ebl calls. This value means we do not understand the type, but it is well-formed DWARF and might be valid. */ return -2; }
static void structprobe(Dwarf *dw, Dwarf_Die *structdie) { Dwarf_Die memdie; Dwarf_Word lastoff = 0, structsize; unsigned cline, members, nholes; size_t memsz, holesz; int x; (void)dw; cline = members = nholes = 0; memsz = holesz = 0; printf("struct %s {\n", dwarf_diename(structdie)); if (dwarf_aggregate_size(structdie, &structsize) == -1) dwarf_err(EX_DATAERR, "dwarf_aggregate_size"); if (dwarf_child(structdie, &memdie)) { printf("XXX ???\n"); exit(EX_DATAERR); } do { Dwarf_Attribute type_attr, base_type_attr; Dwarf_Die type_die, base_type_die; char type_name[128], mem_name[128], ptr_suffix[32] = { '\0' }; const char *type_tag = ""; const char *type = NULL; unsigned type_ptrlevel = 0; Dwarf_Word msize, off; if (dwarf_tag(&memdie) != DW_TAG_member) continue; members++; /* * TODO: Handle bitfield members. DW_AT_bit_offset, * DW_AT_bit_size; */ /* Chase down the type die of this member */ get_dwarf_attr(&memdie, DW_AT_type, &type_attr, &type_die); /* Member offset ... */ if (get_member_offset(&memdie, &off) == -1) dwarf_err(EX_DATAERR, "%s", dwarf_diename(&memdie)); /* Member size. */ if (get_member_size(&type_die, &msize) == -1) dwarf_err(EX_DATAERR, "get_member_size"); /* Format name; 'struct foo', 'enum bar', 'char **', etc. */ if (isstruct(dwarf_tag(&type_die))) { type_tag = "struct "; type = dwarf_diename(&type_die); } else if (dwarf_tag(&type_die) == DW_TAG_enumeration_type) { type_tag = "enum "; type = dwarf_diename(&type_die); } else if (dwarf_tag(&type_die) == DW_TAG_pointer_type) { unsigned i; do { if (dwarf_tag(&type_die) == DW_TAG_pointer_type) type_ptrlevel++; else if (isstruct(dwarf_tag(&type_die))) type_tag = "struct "; else if (dwarf_tag(&type_die) == DW_TAG_enumeration_type) type_tag = "enum "; else printf("!!! XXX ignored pointer qualifier TAG %#x\n", dwarf_tag(&type_die)); /* * Pointers to basic types still need some * work. Clang doesn't emit an AT_TYPE for * 'void*,' for example. */ if (!dwarf_hasattr(&type_die, DW_AT_type)) break; get_dwarf_attr(&type_die, DW_AT_type, &base_type_attr, &base_type_die); type_die = base_type_die; type_attr = base_type_attr; } while (dwarf_tag(&type_die) != DW_TAG_base_type); type = dwarf_diename(&type_die); if (type_ptrlevel > sizeof(ptr_suffix) - 2) type_ptrlevel = sizeof(ptr_suffix) - 2; ptr_suffix[0] = ' '; for (i = 1; i <= type_ptrlevel; i++) ptr_suffix[i] = '*'; ptr_suffix[i] = '\0'; } else type = dwarf_diename(&type_die); if (type == NULL) type = "<anonymous>"; snprintf(type_name, sizeof(type_name), "%s%s%s", type_tag, type, ptr_suffix); if (off != lastoff) { printf("\n\t/* XXX %ld bytes hole, try to pack */\n\n", off - lastoff); nholes++; holesz += (off - lastoff); } snprintf(mem_name, sizeof(mem_name), "%s;", dwarf_diename(&memdie)); printf("\t%-27s%-21s /* %5ld %5ld */\n", type_name, mem_name, (long)off, (long)msize); memsz += msize; lastoff = off + msize; if (lastoff / cachelinesize > cline) { int ago = lastoff % cachelinesize; cline = lastoff / cachelinesize; if (ago) printf("\t/* --- cacheline %u boundary (%ld " "bytes) was %d bytes ago --- */\n", cline, (long)cline * cachelinesize, ago); else printf("\t/* --- cacheline %u boundary (%ld " "bytes) --- */\n", cline, (long)cline * cachelinesize); } } while ((x = dwarf_siblingof(&memdie, &memdie)) == 0); if (x == -1) dwarf_err(EX_DATAERR, "dwarf_siblingof"); printf("\n\t/* size: %lu, cachelines: %u, members: %u */\n", structsize, cline + 1, members); printf("\t/* sum members: %zu, holes: %u, sum holes: %zu */\n", memsz, nholes, holesz); printf("\t/* last cacheline: %lu bytes */\n", lastoff % cachelinesize); printf("};\n"); }
int tilegx_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp) { /* Start with the function's type, and get the DW_AT_type attribute, which is the type of the return value. */ Dwarf_Attribute attr_mem; Dwarf_Attribute *attr = dwarf_attr_integrate (functypedie, DW_AT_type, &attr_mem); if (attr == NULL) /* The function has no return value, like a `void' function in C. */ return 0; Dwarf_Die die_mem; Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem); int tag = DWARF_TAG_OR_RETURN (typedie); /* Follow typedefs and qualifiers to get to the actual type. */ while (tag == DW_TAG_typedef || tag == DW_TAG_const_type || tag == DW_TAG_volatile_type || tag == DW_TAG_restrict_type || tag == DW_TAG_mutable_type) { attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem); typedie = dwarf_formref_die (attr, &die_mem); tag = DWARF_TAG_OR_RETURN (typedie); } Dwarf_Word size; switch (tag) { case -1: return -1; case DW_TAG_subrange_type: if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size)) { attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem); typedie = dwarf_formref_die (attr, &die_mem); tag = DWARF_TAG_OR_RETURN (typedie); } /* Fall through. */ case DW_TAG_base_type: case DW_TAG_enumeration_type: case DW_TAG_pointer_type: case DW_TAG_ptr_to_member_type: if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size, &attr_mem), &size) != 0) { if (tag == DW_TAG_pointer_type || tag == DW_TAG_ptr_to_member_type) size = 8; else return -1; } if (tag == DW_TAG_base_type) { Dwarf_Word encoding; if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding, &attr_mem), &encoding) != 0) return -1; } /* Small enough structs are passed directly in registers R0 ... R7. */ if (size <= 8) { intreg: *locp = loc_intreg; return nloc_intreg; } /* Else fall through. */ case DW_TAG_structure_type: case DW_TAG_class_type: case DW_TAG_union_type: aggregate: *locp = loc_aggregate; return nloc_aggregate; case DW_TAG_array_type: case DW_TAG_string_type: if (dwarf_aggregate_size (typedie, &size) == 0 && size <= 8) { if (tag == DW_TAG_array_type) { /* Check if it's a character array. */ attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem); typedie = dwarf_formref_die (attr, &die_mem); tag = DWARF_TAG_OR_RETURN (typedie); if (tag != DW_TAG_base_type) goto aggregate; if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size, &attr_mem), &size) != 0) return -1; if (size != 1) goto aggregate; } goto intreg; } goto aggregate; } /* XXX We don't have a good way to return specific errors from ebl calls. This value means we do not understand the type, but it is well-formed DWARF and might be valid. */ return -2; }
int x86_64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp) { /* Start with the function's type, and get the DW_AT_type attribute, which is the type of the return value. */ Dwarf_Attribute attr_mem; Dwarf_Attribute *attr = dwarf_attr_integrate (functypedie, DW_AT_type, &attr_mem); if (attr == NULL) /* The function has no return value, like a `void' function in C. */ return 0; Dwarf_Die die_mem; Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem); int tag = DWARF_TAG_OR_RETURN (typedie); /* Follow typedefs and qualifiers to get to the actual type. */ while (tag == DW_TAG_typedef || tag == DW_TAG_const_type || tag == DW_TAG_volatile_type || tag == DW_TAG_restrict_type || tag == DW_TAG_mutable_type) { attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem); typedie = dwarf_formref_die (attr, &die_mem); tag = DWARF_TAG_OR_RETURN (typedie); } Dwarf_Word size; switch (tag) { case -1: return -1; case DW_TAG_subrange_type: if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size)) { attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem); typedie = dwarf_formref_die (attr, &die_mem); tag = DWARF_TAG_OR_RETURN (typedie); } /* Fall through. */ case DW_TAG_base_type: case DW_TAG_enumeration_type: case DW_TAG_pointer_type: case DW_TAG_ptr_to_member_type: if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size, &attr_mem), &size) != 0) { if (tag == DW_TAG_pointer_type || tag == DW_TAG_ptr_to_member_type) size = 8; else return -1; } if (tag == DW_TAG_base_type) { Dwarf_Word encoding; if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding, &attr_mem), &encoding) != 0) return -1; switch (encoding) { case DW_ATE_complex_float: switch (size) { case 4 * 2: /* complex float */ case 8 * 2: /* complex double */ *locp = loc_ssereg; return nloc_sseregpair; case 16 * 2: /* complex long double */ *locp = loc_x87reg; return nloc_x87regpair; } return -2; case DW_ATE_float: switch (size) { case 4: /* float */ case 8: /* double */ *locp = loc_ssereg; return nloc_ssereg; case 16: /* long double */ /* XXX distinguish __float128, which is sseregpair?? */ *locp = loc_x87reg; return nloc_x87reg; } return -2; } } intreg: *locp = loc_intreg; if (size <= 8) return nloc_intreg; if (size <= 16) return nloc_intregpair; large: *locp = loc_aggregate; return nloc_aggregate; case DW_TAG_structure_type: case DW_TAG_class_type: case DW_TAG_union_type: case DW_TAG_array_type: if (dwarf_aggregate_size (typedie, &size) != 0) goto large; if (size > 16) goto large; /* XXX Must examine the fields in picayune ways to determine the actual answer. This will be right for small C structs containing integer types and similarly simple cases. */ goto intreg; } /* XXX We don't have a good way to return specific errors from ebl calls. This value means we do not understand the type, but it is well-formed DWARF and might be valid. */ return -2; }