XS-libdwarf

 view release on metacpan or  search on metacpan

libdwarf-code-0.11.1/src/lib/libdwarf/dwarf_debugnames.c  view on Meta::CPAN

    Dwarf_Unsigned    * bucket_number,
    Dwarf_Unsigned    * hash_value,
    Dwarf_Unsigned    * offset_to_debug_str,
    char *            * ptrtostr ,
    Dwarf_Unsigned    * offset_in_entrypool,
    Dwarf_Unsigned    * abbrev_code,
    Dwarf_Half        * abbrev_tag,
    Dwarf_Unsigned      array_size,
    Dwarf_Half        * idxattr_array,
    Dwarf_Half        * form_array,
    Dwarf_Unsigned    * attr_count,
    Dwarf_Error *       error)
{
    Dwarf_Debug dbg                     = 0;
    int res                             = 0;
    Dwarf_Unsigned entrypooloffset      = 0;
    Dwarf_Unsigned debugstroffset       = 0;
    Dwarf_Small * strpointer            = 0;
    struct Dwarf_D_Abbrev_s *abbrevdata = 0;
    Dwarf_Unsigned code                 = 0;

    if (!dn || dn->dn_magic != DWARF_DNAMES_MAGIC) {
        _dwarf_error_string(NULL, error,DW_DLE_DBG_NULL,
            "DW_DLE_DBG_NULL: "
            "a call to dwarf_dnames_name() "
            "Passes in a NULL or uninitialized pointer");
        return DW_DLV_ERROR;
    }
    dbg = dn->dn_dbg;
    if (IS_INVALID_DBG(dbg)) {
        _dwarf_error_string(NULL, error,DW_DLE_DBG_NULL,
            "DW_DLE_DBG_NULL: "
            "a call to dwarf_dnames_name() "
            "finds a NULL Dwarf_Debug in a Dwarf_Dnames_Head");
        return DW_DLV_ERROR;
    }
    if (!name_index || name_index > dn->dn_name_count) {
        return DW_DLV_NO_ENTRY;
    }
    res = get_bucket_number(dn,name_index,bucket_number);
    if (res == DW_DLV_OK) {
        res = get_hash_value_number(dn,name_index,hash_value,error);
        if (res == DW_DLV_ERROR) {
            return res;
        }
    }
    {
        Dwarf_Small *ptr = dn->dn_string_offsets +
            (name_index-1) * dn->dn_offset_size;
        Dwarf_Small *endptr = dn->dn_abbrevs;

        READ_UNALIGNED_CK(dbg, debugstroffset, Dwarf_Unsigned,
            ptr, dn->dn_offset_size,
            error,endptr);
        if (offset_to_debug_str) {
            *offset_to_debug_str = debugstroffset;
        }
    }
    /* Get str ptr from .debug_str */
    {
        Dwarf_Small *secdataptr = 0;
        Dwarf_Unsigned secdatalen = 0;
        Dwarf_Small *secend = 0;
        int res_s = 0;

        secdataptr = (Dwarf_Small *)dbg->de_debug_str.dss_data;
        secdatalen = dbg->de_debug_str.dss_size;
        secend = secdataptr+secdatalen;
        strpointer = secdataptr +debugstroffset;
        res_s = _dwarf_check_string_valid(dbg,
            secdataptr,strpointer,secend,
            DW_DLE_FORM_STRING_BAD_STRING,error);
        if (res_s != DW_DLV_OK) {
            return res_s;
        }
        if (ptrtostr) {
            *ptrtostr = (char *)strpointer;
        }
    }

    {
        Dwarf_Small *ptr = dn->dn_entry_offsets +
            (name_index-1) * dn->dn_offset_size;
        Dwarf_Small *endptr = dn->dn_abbrevs;
        /*  offsets relative to the start of the
            entry_pool */

        READ_UNALIGNED_CK(dbg, entrypooloffset, Dwarf_Unsigned,
            ptr, dn->dn_offset_size,
            error,endptr);
        if (entrypooloffset >= dn->dn_entry_pool_size) {
            _dwarf_error_string(dbg, error,DW_DLE_DEBUG_NAMES_ERROR,
                "DW_DLE_DEBUG_NAMES_ERROR: "
                "The entrypool offset read is larger than"
                "the entrypool size");
            return DW_DLV_ERROR;
        }
        if (offset_in_entrypool) {
            *offset_in_entrypool = entrypooloffset;
        }
    }
    /*   Find abbrev code at the given entry offset */
    res = _dwarf_read_abbrev_code_from_pool(dn,
        entrypooloffset, &code,error);
    if (res != DW_DLV_OK) {
        return res;
    }
    res = _dwarf_find_abbrev_for_code(dn,code,&abbrevdata,error);
    if (res == DW_DLV_ERROR) {
        return res;
    }
    if (res == DW_DLV_NO_ENTRY) {
        return res;
    }

    if (abbrev_code) {
        *abbrev_code =  code;
    }
    if (code && abbrev_tag) {
        *abbrev_tag =  (Dwarf_Half)abbrevdata->da_tag;
    }
    if (code) {
        if (attr_count) {
            *attr_count = abbrevdata->da_pairs_count;
        }
        res = _dwarf_fill_in_attr_form(dn,abbrevdata,idxattr_array,
            form_array, array_size,error);
        if (res == DW_DLV_ERROR) {
            return res;
        }
    }



( run in 1.398 second using v1.01-cache-2.11-cpan-39bf76dae61 )