Ejemplo n.º 1
0
int
main(int argc, char **argv)
{
    char *endptr;
    unsigned long nsteps = 1000000;
    VMState *state;
    bool hit_bp = false;
#ifdef WITH_DIFF
    VMStateDiff *diff;
#endif
    
    if (argc <= 1) {
        printf("Using a default of %lu steps\n", nsteps);
    } else {
        nsteps = strtoul(argv[1], &endptr, 0);
        
        if (errno) {
            perror("Invalid command line argument.");
            return 1;
        }
        
        if (*endptr)
            fprintf(stderr, "Warning: junk at end of number.\n");
    }
    

    check_error(state = vm_newstate_no_code(VM_POLICY_INTERRUPT_ALWAYS));
    
    put_code(state);
    
#ifdef WITH_DIFF
    check_error(diff = vm_newdiff());
    if (!vm_step(state, nsteps, diff, &hit_bp))
        goto error;
#else
    if (!vm_step(state, nsteps, NULL, &hit_bp))
        goto error;
#endif
    
    return EXIT_SUCCESS;
error:
    fputs(vm_strerror(-1), stderr);
    fputc('\n', stderr);
    return EXIT_FAILURE;
}
Ejemplo n.º 2
0
/* allocation functions */
VMState *
vm_newstate(void *program,
            size_t program_size,
            VMInterruptPolicy interrupt_policy)
{
    VMState *newstate;

    if (!(newstate = vm_newstate_no_code(interrupt_policy)))
        goto error;

    if (!_read_elf(newstate, program, program_size))
        goto error;

    return newstate;
error:
    vm_closestate(newstate);
    return NULL;
}