Beispiel #1
0
static int
applybypointer(struct myacts *m,
    const char *msg,
    int hideactions,
    int printwalk,
    int dumpeverystage)
{

    unsigned ct = 1;
    void *treesq1 = 0;
    int errcount = 0;

    INITTREE(treesq1,mt_hashfunc);
    printf("special sequence %s\n",msg);
    for(; m->action_ != 0; m++,ct++) {
        if(!hideactions) {
            printf("Action %2u: %s 0x%x val 0x%x\n",ct,
                describe_action(m->action_),
                m->action_,m->addr_);
        }
        if(m->action_ == 'a') {
            errcount += insertonebypointer(&treesq1,m->addr_,ct);
            continue;
        }
        if(m->action_ == 'd') {
            errcount += deleteonebypointer(&treesq1,m->addr_,ct);
            continue;
        }
        printf("Fail applybypointer, bad action %s entry %d.\n",msg,ct);
        return 1;
    }
    dwarf_tdestroy(treesq1,mt_free_func);
    return errcount;

}
Beispiel #2
0
/*  This demonstrates using a simple integer as the
    value saved, as itself, not a pointer, per-se.

    The various flags are not important except in that
    they can help in case bugs still exist.

*/
static int
applybyvalue(struct myacts *m,
    const char *msg,
    int hideactions,
    int printwalk,
    int dumpeverystage)
{
    unsigned ct = 1;
    void *treesq1 = 0;
    int errcount = 0;

    INITTREE(treesq1,value_hashfunc);
    printf("special sequence %s\n",msg);
    for(; m->action_ != 0; m++,ct++) {
        if(!hideactions) {
            printf("Action %2u: %s 0x%x val 0x%x\n",ct,
                describe_action(m->action_),
                m->action_,m->addr_);
        }
        if(m->action_ == 'a') {
            errcount += insertbyvalue(&treesq1,m->addr_,ct);
            if(ct == 0) {
                printf("Add    done. action# %2d value 0x%x\n",
                    ct,m->addr_);
                dwarf_tdump(treesq1,value_keyprint,"first sequence2 added");
            } else if(dumpeverystage) {
                dwarf_tdump(treesq1,value_keyprint,"after add");
            }
            continue;
        }
        if(m->action_ == 'd') {
            errcount += deletebyvalue(&treesq1,m->addr_,ct);
            if(dumpeverystage) {
                printf("Delete done. action# %2d value 0x%x\n",
                    ct,m->addr_);
                dwarf_tdump(treesq1,value_keyprint,"after delete");
            }
            continue;
        }
        printf("Fail applybyvalue, bad action %s entry %d.\n",msg,ct);
        return 1;
    }
    if(printwalk) {
        printf("Twalk start, simple value \n");
        dwarf_twalk(treesq1,value_only_walk_entry);
        printf("Twalk end, simple value\n");
        dwarf_tdump(treesq1,value_keyprint,"tdump simple value from applybyvalue");
    }
    dwarf_tdestroy(treesq1,value_node_free);
    return errcount;

}
Beispiel #3
0
/*
    Used to free all space allocated for this Dwarf_Debug.
    The caller should assume that the Dwarf_Debug pointer
    itself is no longer valid upon return from this function.

    In case of difficulty, this function simply returns quietly.
*/
int
_dwarf_free_all_of_one_debug(Dwarf_Debug dbg)
{
    if (dbg == NULL) {
        return (DW_DLV_ERROR);
    }

    /*  To do complete validation that we have no surprising missing or
        erroneous deallocs it is advisable to do the dwarf_deallocs here
        that are not things the user can otherwise request.
        Housecleaning.  */
    freecontextlist(dbg,&dbg->de_info_reading);
    freecontextlist(dbg,&dbg->de_types_reading);

    /* Housecleaning done. Now really free all the space. */
    rela_free(&dbg->de_debug_info);
    rela_free(&dbg->de_debug_types);
    rela_free(&dbg->de_debug_abbrev);
    rela_free(&dbg->de_debug_line);
    rela_free(&dbg->de_debug_loc);
    rela_free(&dbg->de_debug_aranges);
    rela_free(&dbg->de_debug_macinfo);
    rela_free(&dbg->de_debug_pubnames);
    rela_free(&dbg->de_debug_str);
    rela_free(&dbg->de_debug_frame);
    rela_free(&dbg->de_debug_frame_eh_gnu);
    rela_free(&dbg->de_debug_pubtypes);
    rela_free(&dbg->de_debug_funcnames);
    rela_free(&dbg->de_debug_typenames);
    rela_free(&dbg->de_debug_varnames);
    rela_free(&dbg->de_debug_weaknames);
    rela_free(&dbg->de_debug_ranges);
    dwarf_harmless_cleanout(&dbg->de_harmless_errors);

    if (dbg->de_printf_callback.dp_buffer &&
        !dbg->de_printf_callback.dp_buffer_user_provided ) {
        free(dbg->de_printf_callback.dp_buffer);
    }

    dwarf_tdestroy(dbg->de_alloc_tree,tdestroy_free_node);
    memset(dbg, 0, sizeof(*dbg)); /* Prevent accidental use later. */
    free(dbg);
    return (DW_DLV_OK);
}
Beispiel #4
0
static int
standard_tests(void)
{
    void *tree1 = 0;
    int errcount = 0;

    if(applyby == applybypointer) {
        printf("Test with increasing input\n");
        INITTREE(tree1,mt_hashfunc);

        errcount += insertrecsbypointer(3,&tree1,increasing);
        errcount += findrecsbypointer(6,3,(const void **)&tree1,increasing);
        dwarf_twalk(tree1,walk_entry);
        dwarf_tdump(tree1,mt_keyprint,"Dump Tree from increasing input");
        errcount += delrecsbypointer(6,3,&tree1,increasing,0);
#ifdef HASHSEARCH
        dwarf_tdestroy(tree1,mt_free_func);
        tree1 = 0;
#endif
        if(tree1) {
            printf("FAIL: delrecsbypointer of increasing did not empty the tree.\n");
            exit(1);
        }

        printf("Test twalk with empty tree\n");
        dwarf_twalk(tree1,walk_entry);

        INITTREE(tree1,mt_hashfunc);
        printf("Insert decreasing, try tdestroy\n");
        errcount += insertrecsbypointer(6,&tree1,decreasing);
        dwarf_twalk(tree1,walk_entry);
        dwarf_tdestroy(tree1,mt_free_func);
        tree1 = 0;

        INITTREE(tree1,mt_hashfunc);
        printf("Now test with decreasing input and test twalk and tdelete\n");
        errcount += insertrecsbypointer(5,&tree1,decreasing);
        errcount += findrecsbypointer(6,5,(const void **)&tree1,decreasing);
        dwarf_twalk(tree1,walk_entry);
        dwarf_tdump(tree1,mt_keyprint,"Dump Tree from decreasing input");
        errcount += delrecsbypointer(6,5,&tree1,decreasing,0);
#ifdef HASHSEARCH
        dwarf_tdestroy(tree1,mt_free_func);
        tree1 = 0;
#endif
        if(tree1) {
            printf("FAIL: delrecsbypointer of decreasing did not empty the tree.\n");
            exit(1);
        }

        INITTREE(tree1,mt_hashfunc);
        printf("Now test with balanced input and test twalk and tdelete\n");
        errcount += insertrecsbypointer(4,&tree1,balanced);
        errcount += findrecsbypointer(6,4,(const void **)&tree1,balanced);
        dwarf_twalk(tree1,walk_entry);
        dwarf_tdump(tree1,mt_keyprint,"Dump Tree from balanced input");
        errcount += delrecsbypointer(6,4,&tree1,balanced,1);
#ifdef HASHSEARCH
        dwarf_tdestroy(tree1,mt_free_func);
        tree1 = 0;
#endif
        if(tree1) {
            printf("FAIL: delrecsbypointer of balanced did not empty the tree.\n");
            exit(1);
        }

        dwarf_twalk(tree1,walk_entry);
        if (errcount > 0) {
            printf("FAIL tsearch test.\n");
            exit(1);
        }

        errcount += applyby(&sequence1[0],"Sequence 1",
            g_hideactions,0,0);
        errcount += applyby(&sequence2[0],"Sequence 2, a",
            g_hideactions,0,0);
    } else {
        errcount += applyby(&sequence2[0],"Sequence 2, b",
            g_hideactions,0,0);
        errcount += applyby(&sequence3[0],"Sequence 3",
            g_hideactions,0,0);
        errcount += applyby(&sequential64[0],"Sequential 64",
            g_hideactions,1,0);
    }
    return errcount;
}
Beispiel #5
0
static void
macrocheck_map_destroy(void *map)
{
    /* tdestroy is not part of Posix. */
    dwarf_tdestroy(map,macrocheck_map_free_func);
}
Beispiel #6
0
static void
helpertree_map_destroy(void *map)
{
    /* tdestroy is not part of Posix. */
    dwarf_tdestroy(map,helpertree_map_free_func);
}