示例#1
0
int
add_typedef_name ( char * name )
{
    if ( name == NULL ) return(1) ;
    if ( get_typedef_name ( name ) == NULL )
    {
        if ( NumTypeDefs >= MAX_TYPEDEFS ) return(1) ;
        strcpy( typedefs[NumTypeDefs++] , name ) ;
    }
    return(0) ;
}
示例#2
0
// check if there is a typedef with a given name and equivalent content in the db
// equivalent content means e.g. structures, unions and enums have the same members
// return its ordinal if the typedef is found. (0 otherwise)
uint32 get_equivalent_typedef_ordinal(DieHolder &typedef_holder, uint32 const type_ordinal)
{
  uint32 ordinal = 0;
  char const *typedef_name = typedef_holder.get_name();
  type_t const *type = NULL;
  char const *name = NULL;
  bool ok = get_numbered_type(idati, type_ordinal, &type);

  if(ok)
  {
    type_t const *existing_type = NULL;
    // already an existing type with the same name?
    ok = get_named_type(idati, typedef_name, NTF_TYPE | NTF_NOBASE, &existing_type);

    if(ok)
    {
      // existing type is a typedef?
      if(is_type_typedef(*existing_type))
      {
        // typedef to a structure/union?
        if(is_type_struni(*type))
        {
          name = get_typedef_name(existing_type);

          if(name != NULL)
          {
            tid_t struc_id = get_struc_id(name);

            ok = (struc_id != BADNODE);
            if(ok)
            {
              Dwarf_Off offset = 0;

              ok = diecache.get_type_offset(type_ordinal, &offset);
              if(ok)
              {
                DieHolder structure_holder(typedef_holder.get_dbg(), offset);
                StrucCmp struc_cmp(name);

                ok = struc_cmp.equal(structure_holder);
              }
            }
          }
        }
        // typedef to an enum
        else if(is_type_enum(*type))
        {
          name = get_typedef_name(existing_type);

          if(name != NULL)
          {
            enum_t enum_id = get_enum(name);

            ok = (enum_id != BADNODE);
            if(ok)
            {
              Dwarf_Off offset = 0;

              ok = diecache.get_type_offset(type_ordinal, &offset);
              if(ok)
              {
                DieHolder enumeration_holder(typedef_holder.get_dbg(), offset);
                EnumCmp enum_cmp(name);

                ok = enum_cmp.equal(enumeration_holder);
              }
            }
          }
        }
      }
    }
  }

  if(name != NULL)
  {
    if(ok)
    {
      ordinal = get_type_ordinal(idati, typedef_name);

      DEBUG("found equivalent typedef typedef_name='%s' name='%s' type_ordinal=%u ordinal=%u\n",
            typedef_name, name, type_ordinal, ordinal);
    }
  }

  return ordinal;
}