Example #1
0
extern void DWRFiniFileTable( file_table *tab, bool freenames )
/*************************************************************/
{
    filetab_idx     ftidx;

    if( freenames ) {
        for( ftidx = 0; ftidx < tab->len; ftidx++ ) {
            DWRFREE( tab->tab[ftidx].u.name );
        }
    }
    if( tab->tab != NULL ) {
        DWRFREE( tab->tab );
    }
}
Example #2
0
static bool CheckEntry( drmem_hdl abbrev, drmem_hdl mod, mod_scan_info *minfo, void *data )
/*****************************************************************************************/
{
    int                 index;
    sym_search_data     *sinfo;
    dr_sym_context      symctxt;

    sinfo = (sym_search_data *)data;

    symctxt.handle = minfo->handle;
    symctxt.context = minfo->context;

    symctxt.name = NULL;
    if( sinfo->name != NULL ) {
        symctxt.name = DWRGetName( abbrev, mod );
        if( symctxt.name == NULL )
            return( true );
        if( !RegExec( sinfo->name, symctxt.name, true ) ) {
            DWRFREE( symctxt.name );
            return( true );
        }
    }

    symctxt.type = DR_SYM_MACRO;
    for( index = 0; index < DR_SYM_NOT_SYM; index++ ) {
        if( DWRSearchArray( SearchTags[index], minfo->tag ) ) {
            symctxt.type = index;
            break;
        }
    }

    return( sinfo->callback( &symctxt, sinfo->data ) );
}
Example #3
0
extern void DWRVMSwap( drmem_hdl base, unsigned_32 size, bool *ret )
/******************************************************************/
// Swap out base for length size
// If memory was freed set *ret
{
    volatile virt_struct    vm;         // cg bug workaround
    page_entry              *entry;
    bool                    ret_val;

    vm.l = base;
    ret_val = false;
    if( size > 0 ) {
        for( ;; ) {
            entry = NODE( vm );
            entry->refd = 0;
            if( entry->inmem ) {
                --PageCount;
                DWRFREE( entry->mem );
                entry->inmem = 0;
                ret_val = true;
            }
            if( size <= MAX_NODE_SIZE )
                break;
            size -= MAX_NODE_SIZE;
            vm.l += MAX_NODE_SIZE;
        }
    }
    if( !ret_val ) {
        *ret = ret_val;
    }
}
Example #4
0
void DWRStackFree(                          // DESTRUCT A STACK
    dr_stack *stk )                         // -- stack to trash
/***********************/
{
    DWRFREE( stk->stack );
    stk->stack = NULL;
    stk->size = 0;
    stk->free = 0;
}
Example #5
0
extern void DWRVMDestroy( void )
/******************************/
{
    alloc_struct    *walk;
    alloc_struct    *prev;

    for( walk = AllocHead; walk != NULL; ) {
        prev = walk;
        walk = walk->next;
        DWRFREE( prev );
    }
    AllocHead = NULL;
}
Example #6
0
extern void DWRVMDestroy( void )
/******************************/
/* this frees all virtual memory */
{
    unsigned        branch;
    unsigned        leaf;
    page_entry      *entry;

    DontSwap = true;
    if( PageTab == NULL ) return;
    for( branch = 1; branch < NumBranches; branch++ ) {
        entry = PageTab[ branch ];
        if( entry != NULL ) {
            for( leaf = 0; leaf < MAX_LEAFS; leaf++ ) {
                if( entry->inmem ) {
                    DWRFREE( entry->mem );
                }
                entry++;
            }
            DWRFREE( PageTab[branch] );
        }
    }
    DWRFREE( PageTab );
}
Example #7
0
extern filetab_idx DWRAddFileName( char *name, file_table *tab )
/**************************************************************/
{
    filetab_idx     ftidx;
    char            **names;

    names = (char **)tab->tab;
    for( ftidx = 0; ftidx < tab->len; ++ftidx ) {
        if( strcmp( name, *names ) == 0 ) {
            DWRFREE( name );
            return( ftidx );
        }
        names++;
    }
    GrowTable( tab );
    tab->tab[ftidx].u.name = name;
    return( ftidx );
}
Example #8
0
static void GetMoreBranches( void )
/*********************************/
// make a larger array to hold branch pointers in.
{
    page_entry      **branches;
    unsigned        alloc_size;

    alloc_size = NumBranches * sizeof( page_entry * );
    NumBranches = NumBranches * 2;   // double the # of pointers.
    if( NumBranches > SEG_LIMIT ) {
        DWREXCEPT( DREXCEP_OUT_OF_VM );
    }
    branches = DWRALLOC( alloc_size * 2 );
    memcpy( branches, PageTab, alloc_size );
    memset( (char *)branches + alloc_size, 0, alloc_size ); // null pointers
    DWRFREE( PageTab );
    PageTab = branches;
}
Example #9
0
bool DRSwap( void )
/*****************/
// this uses the second-chance cyclic algorithm for page replacement.
// NOTE: this tends to degenerate into FIFO under very tight memory
// requirements, which is rather bad for the current usage.  Any better ideas?
{
    unsigned_16         startbranch;
    unsigned_16         startleaf;
    page_entry          *entry;
    bool                passtwo;

    if( DontSwap )
        return( false );
    passtwo = false;
    startbranch = SwapBranch;
    startleaf = SwapLeaf;
    for( ;; ) {
        SwapLeaf++;
        if( SwapLeaf >= MAX_LEAFS ) {
            SwapLeaf = 0;
            SwapBranch++;
            if( SwapBranch > CurrBranch ) {
                SwapBranch = 1;
            }
        }
        entry = &PageTab[SwapBranch][SwapLeaf];
        if( entry != NULL ) {
            if( entry->refd ) {
                entry->refd = 0;
            } else if( entry->inmem ) {
                DWRFREE( entry->mem );
                PageCount--;
                entry->inmem = 0;
                return( true );
            }
        }
        if( SwapLeaf == startleaf && SwapBranch == startbranch ) {
            if( passtwo ) break;        // nothing to swap;
            passtwo = true;
        }
    }
    return( false );
}
Example #10
0
extern int DWRVMSectDone( dr_handle base, unsigned_32 size )
/**********************************************************/
{
    alloc_struct    *walk;
    alloc_struct    **lnk;
    int             ret;

    lnk = &AllocHead;
    ret = FALSE;
    while( (walk = *lnk) != NULL ) {
        if( (dr_handle)walk->data == base ) {
            *lnk = walk->next;
            DWRFREE( walk );
            ret = TRUE;
            break;
        }
        lnk = &walk->next;
    }
    return( ret );
}
Example #11
0
extern void DRFreeSearchContext( dr_search_context *ctxt )
/********************************************************/
{
    DWRFREE( ctxt->stack.stack );
    DWRFREE( ctxt );
}
Example #12
0
static void References( ReferWhich which, dr_handle entry, void *data1,
                hook_func do_callback, void *data2, DRSYMREF callback )
/*********************************************************************/
{
    dr_handle   loc;
    dr_handle   end;
    dr_handle   owning_node;
    dr_handle   infoOffset;
    unsigned_8  opcode;
    dr_ref_info registers = { { 0, 0, NULL }, 0L, NULL, 1L, 1 };
    bool        quit = FALSE;
    bool        inScope = FALSE;

    loc = DWRCurrNode->sections[ DR_DEBUG_REF ].base;
    end = loc + DWRCurrNode->sections[ DR_DEBUG_REF ].size;
    infoOffset = DWRCurrNode->sections[ DR_DEBUG_INFO ].base;

    loc += sizeof( unsigned_32 );   /* skip size */
    while( loc < end && !quit ) {
        opcode = DWRVMReadByte( loc );
        loc += sizeof( unsigned_8 );

        switch( opcode ) {
        case REF_BEGIN_SCOPE:
            owning_node = DWRVMReadDWord( loc ) + infoOffset;
            loc += sizeof( unsigned_32 );
            ScopePush( &registers.scope, owning_node );
            if( (which & REFERSTO) != 0 && owning_node == entry ) {
                inScope = TRUE;
            }
            break;

        case REF_END_SCOPE:
            ScopePop( &registers.scope );
            inScope = FALSE;
            break;

        case REF_SET_FILE:
            registers.file = DWRFindFileName( DWRVMReadULEB128( &loc ), infoOffset );
            break;

        case REF_SET_LINE:
            registers.line = DWRVMReadULEB128( &loc );
            break;

        case REF_SET_COLUMN:
            registers.column = (unsigned_8)DWRVMReadULEB128( &loc );
            break;

        case REF_ADD_LINE:
            registers.line += DWRVMReadSLEB128( &loc );
            registers.column = 0;
            break;

        case REF_ADD_COLUMN:
            registers.column += (signed_8)DWRVMReadSLEB128( &loc );
            break;

        case REF_COPY:
        default:
            if( opcode >= REF_CODE_BASE ) {
                unsigned_32 ld;

                opcode -= REF_CODE_BASE;

                ld = opcode / REF_COLUMN_RANGE;
                if( ld != 0 ) {
                    registers.column = 0;
                    registers.line += ld;
                }
                registers.column += opcode % REF_COLUMN_RANGE;

                registers.dependent = DWRVMReadDWord( loc ) + infoOffset;
                loc += sizeof( unsigned_32 );
            }

            quit = FALSE; /* don't terminate */
            if( do_callback( &registers, data1 ) || inScope ) {
                char    *name = NULL;

                owning_node = ScopeLastNameable( &registers.scope, &name );

                /* make sure that there is something nameable on the stack */
                if( owning_node != DR_HANDLE_NUL ) {
                    quit = !callback( owning_node, &registers, name, data2 );
                }
            }
            break;
        }
    }

    DWRFREE( registers.scope.stack );
}