Exemple #1
0
static void
do_checking(Dwarf_Debug dbg, Dwarf_Arange *arange_buf,Dwarf_Signed i,
    Dwarf_Off cu_die_offset,Dwarf_Bool first_cu,
    Dwarf_Off cu_die_offset_prev, Dwarf_Die cu_die )
{
    int dres = 0;
    Dwarf_Off cuhdroff = 0;
    Dwarf_Off cudieoff3 = 0;
    dres = dwarf_get_arange_cu_header_offset(
        arange_buf[i],&cuhdroff,&err);
    if (dres == DW_DLV_OK) {
        Dwarf_Off cudieoff2 = 0;

        /* Get the CU offset for easy error reporting */
        if (first_cu || cu_die_offset != cu_die_offset_prev) {
            cu_die_offset_prev = cu_die_offset;
            dres = dwarf_die_offsets(cu_die,&DIE_overall_offset,&DIE_offset,&err);
            if (dres != DW_DLV_OK) {
                print_error(dbg, "dwarf_die_offsets", dres, err);
            }
        }
        dres = dwarf_get_cu_die_offset_given_cu_header_offset(
            dbg,cuhdroff,&cudieoff2,&err);
        if (dres == DW_DLV_OK) {
            /* Get the CU offset for easy error reporting */
            dwarf_die_offsets(cu_die,&DIE_overall_offset,&DIE_offset,&err);
            DWARF_CHECK_COUNT(aranges_result,1);
            if (cudieoff2 != cu_die_offset) {
                printf("Error, cu_die offsets mismatch,  0x%"
                    DW_PR_DUx
                    " != 0x%" DW_PR_DUx " from arange data",
                    cu_die_offset,cudieoff2);
                DWARF_CHECK_ERROR(aranges_result,
                    " dwarf_get_cu_die_offset_given_cu..."
                    " gets wrong offset");
            }
        } else {
            print_error(dbg, "dwarf_get_cu_die_offset_given...", dres, err);
        }
    } else {
        print_error(dbg, "dwarf_get_arange_cu_header_offset", dres, err);
    }
    dres = dwarf_get_cu_die_offset(arange_buf[i],&cudieoff3,
        &err);
    if (dres == DW_DLV_OK) {
        DWARF_CHECK_COUNT(aranges_result,1);
        if (cudieoff3 != cu_die_offset) {
            printf(
                "Error, cu_die offsets (b) mismatch ,  0x%"
                DW_PR_DUx
                " != 0x%" DW_PR_DUx " from arange data",
                cu_die_offset,cudieoff3);
            DWARF_CHECK_ERROR(aranges_result,
                " dwarf_get_cu_die_offset "
                " gets wrong offset");
        }
    } else {
        print_error(dbg, "dwarf_get_cu_die_offset failed ",
            dres,err);
    }
}
Exemple #2
0
/*  Extracted this from print_range_attribute() to isolate the check of
    the range list.
*/
static void
check_ranges_list(Dwarf_Debug dbg,
    Dwarf_Off die_off,
    Dwarf_Die cu_die,
    Dwarf_Unsigned original_off,
    Dwarf_Ranges *rangeset,
    Dwarf_Signed rangecount,
    Dwarf_Unsigned bytecount)
{
    Dwarf_Unsigned off = original_off;

    Dwarf_Signed index = 0;
    Dwarf_Addr base_address = CU_base_address;
    Dwarf_Addr lopc = 0;
    Dwarf_Addr hipc = 0;
    Dwarf_Bool bError = FALSE;

    static boolean do_print = TRUE;
#if 0
{
/* START -> Just for debugging */
struct esb_s rangesstr;
esb_constructor(&rangesstr);
printf("\n**** START ****\n");
printf("\tGLB_OFF: (0x%" DW_PR_XZEROS DW_PR_DUx ") ",die_off);
printf("\tRGN_OFF: (0x%" DW_PR_XZEROS DW_PR_DUx ")\n",original_off);
print_ranges_list_to_extra(dbg,original_off,
    rangeset,rangecount,bytecount,
    &rangesstr);
printf("%s\n", esb_get_string(&rangesstr));
printf("**** END ****\n");
/* END <- Just for debugging */
}
#endif /* 0 */

    /* Ignore last entry, is the end-of-list */
    for (index = 0; index < rangecount - 1; index++) {
        Dwarf_Ranges *r = rangeset + index;

        if (r->dwr_addr1 == elf_max_address) {
            /* (0xffffffff,addr), use specific address (current PU address) */
            base_address = r->dwr_addr2;
        } else {
            /* (offset,offset), update using CU address */
            lopc = r->dwr_addr1 + base_address;
            hipc = r->dwr_addr2 + base_address;
            DWARF_CHECK_COUNT(ranges_result,1);

            /*  Check the low_pc and high_pc
                are within a valid range in
                the .text section */
            if (IsValidInBucketGroup(pRangesInfo,lopc) &&
                IsValidInBucketGroup(pRangesInfo,hipc)) {
                /* Valid values; do nothing */
            } else {
                /*  At this point may be we
                    are dealing with a
                    linkonce symbol */
                if (IsValidInLinkonce(pLinkonceInfo,
                    PU_name,lopc,hipc)) {
                    /* Valid values; do nothing */
                } else {
                    bError = TRUE;
                    DWARF_CHECK_ERROR(ranges_result,
                        ".debug_ranges: Address outside a "
                        "valid .text range");
                    if (check_verbose_mode && do_print) {
                        /*  Update DIEs offset just for printing */
                        int res = dwarf_die_offsets(cu_die,
                            &DIE_overall_offset,&DIE_offset,&err);
                        if (res != DW_DLV_OK) {
                            print_error(dbg, "dwarf_die_offsets",res,err);
                        }
                        printf(
                            "Offset = 0x%" DW_PR_XZEROS DW_PR_DUx
                            ", Base = 0x%" DW_PR_XZEROS DW_PR_DUx
                            ", "
                            "Low = 0x%" DW_PR_XZEROS DW_PR_DUx
                            " (0x%" DW_PR_XZEROS  DW_PR_DUx
                            "), High = 0x%"
                            DW_PR_XZEROS  DW_PR_DUx
                            " (0x%" DW_PR_XZEROS DW_PR_DUx
                            ")\n",
                            off,base_address,lopc,
                            r->dwr_addr1,hipc,
                            r->dwr_addr2);
                    }
                }
            }
        }
        /*  Each entry holds 2 addresses (offsets) */
        off += elf_address_size * 2;
    }

    /*  In the case of errors, we have to print the range records that
        caused the error. */
    if (bError && check_verbose_mode && do_print) {
        struct esb_s rangesstr;
        esb_constructor(&rangesstr);

        printf("\n");
        print_ranges_list_to_extra(dbg,original_off,
            rangeset,rangecount,bytecount,
            &rangesstr);
        printf("%s\n", esb_get_string(&rangesstr));
    }

    /*  In the case of printing unique errors, stop the printing of any
        subsequent errors, which have the same text. */
    if (bError && check_verbose_mode && print_unique_errors) {
        do_print = FALSE;
    }
}