示例#1
0
void dpenv(SS_psides *si, object *penv)
   {int i, ie, n, nx;
    char pre[MAXLINE];
    char *fname, **lines;
    hasharr *tab;
    object *b;

    if (si == NULL)
       si = SS_get_current_scheme(-1);       /* diagnostic default */

    if (penv == NULL)
       penv = si->env;

    for (ie = 1; !SS_nullobjp(penv); penv = SS_cdr(si, penv), ie++)
        {GET_FRAME(fname, tab, penv);

	 if ((fname != NULL) && (strcmp(fname, "global-environment") != 0))
	    {lines = SC_hasharr_dump(tab, NULL, NULL, TRUE);

	     if (lines != NULL)

/* subtract 1 for the NULL entry in lines signalling the end */
	        {SC_ptr_arr_len(nx, lines);

		 PRINT(stdout, "----------------------------------------\n");
		 PRINT(stdout, "Frame %d: %s\n", ie, fname);

		 n = min(nx, si->trace_env);
		 for (i = 0; i < n; i++)
		     {if ((i != (n-1)) || (lines[i] != NULL))
			 {b = (object *) SC_hasharr_def_lookup(tab, lines[i]);
			  snprintf(pre, MAXLINE, "%4d\t%s\t", i+1, lines[i]);
			  SS_print(si, si->outdev, b, pre, "\n");};};

		 if (n != nx)
		    {PRINT(stdout, "\t...\n");
		     b = (object *) SC_hasharr_def_lookup(tab, lines[nx-1]);
		     snprintf(pre, MAXLINE, "%4d\t%s\t", nx, lines[nx-1]);
		     SS_print(si, si->outdev, b, pre, "\n");};

		 CFREE(lines);};};};

    return;}
示例#2
0
/********************** ************************/
int main(int argc,char *argv[]) {
    int n_pages  = 0;
    //int n_frames = 0;
	ram_info_t ram_info;//
	ram_info.n_frames = 0;//
	ram_info.algorithm = NULL;//
    int n_cache  = 0;
    int n_tlb    = 0;
    char *access_file = NULL;
    FILE *access_fd = NULL;
    addr_t virtual_addr = 0;
    addr_t physical_addr;
    pid_t pid = 0;
    char mode;

    /*
     * Parse arguments
     */
    if( 0 != parse_args(argc, argv, &access_file, &n_pages, &ram_info.n_frames, &n_cache, &n_tlb, &ram_info.algorithm) ) {//
        return -1;
    }

    /*
     * Setup data structures
     */
    srand(time(NULL));
    current_ref = (char *)malloc(sizeof(char) * MAX_LINE);
    clear_stats();

    stats.cache_size = n_cache;
    stats.tlb_size   = n_tlb;
    stats.num_pages  = n_pages;
    stats.num_frames = ram_info.n_frames;//

	printf("Allocating resources...\n");
    allocate_cache(n_cache);
    allocate_tlb(n_tlb);
    allocate_page_table(n_pages);
    allocate_page_directory(n_pages);
    //allocate_ram(n_frames);
    allocate_ram(ram_info);

    /*
     * Open the file that we are going to read
     */
    if( NULL == (access_fd = fopen(access_file, "r") ) ) {
        fprintf(stderr, "Error: Unable to open the access file <%s>\n", access_file);
        return -1;
    }

    /*
     * Read page requests from the file
     */
    gettimeofday(&stats.start, NULL);

    while(0 == feof(access_fd) ) {
        /* Read one line */
        current_ref[0] = '\0';
        if( NULL == fgets(current_ref, MAX_LINE, access_fd) ) {
            break;
        }

        /* Strip off the newline */
        if( '\n' == current_ref[strlen(current_ref)-1] ) {
            current_ref[strlen(current_ref)-1] = '\0';
        }

        extract_args(current_ref, &pid, &mode, &virtual_addr);

        /*
         * Memory management operations to access the page
         */
		if(VERBOSE){
			printf("-----------------------------------------------------------\n");
			printf("%s: Process %*d \t Access [Page %4d, Offset %#05x] (%#010x)\n",
				current_ref,
				MAX_PID_LEN, pid,
				GET_PAGE(virtual_addr), GET_OFFSET(virtual_addr), virtual_addr);
		}
		access_page(pid, mode, virtual_addr, &physical_addr);
		if(VERBOSE){
			printf("%s: Process %*d \t Access [Page %4d, Offset %#05x] (%#010x) --> (%#010x) [Frame %4d, Offset %#05x]\n",
				current_ref,
				MAX_PID_LEN, pid,
				GET_PAGE(virtual_addr), GET_OFFSET(virtual_addr), virtual_addr,
				physical_addr, GET_FRAME(physical_addr), GET_OFFSET(physical_addr));
		}
	}

    gettimeofday(&stats.end, NULL);
    display_stats();

    /*
     * Cleanup
     */
	 
    fclose(access_fd);
	
    if( NULL != current_ref ) {
        free(current_ref);
        current_ref = NULL;
    }
	
    free_ram();
	free_page_dir();
    free_tlb();
    free_cache();

    return 0;
}
示例#3
0
/* This function is called when a segmentation fault is caught.  The system
   is in an instable state now.  This means especially that malloc() might
   not work anymore.  */
static void
catch_segfault (int signal, SIGCONTEXT ctx)
{
    struct layout *current;
    void *__unbounded top_frame;
    void *__unbounded top_stack;
    int fd;
    void **arr;
    size_t cnt;
    struct sigaction sa;

    /* This is the name of the file we are writing to.  If none is given
       or we cannot write to this file write to stderr.  */
    fd = 2;
    if (fname != NULL)
    {
        fd = open (fname, O_TRUNC | O_WRONLY | O_CREAT, 0666);
        if (fd == -1)
            fd = 2;
    }

    WRITE_STRING ("*** ");
    write_strsignal (fd, signal);
    WRITE_STRING ("\n");

#ifdef REGISTER_DUMP
    REGISTER_DUMP;
#endif

    WRITE_STRING ("\nBacktrace:\n");

    top_frame = GET_FRAME (ctx);
    top_stack = GET_STACK (ctx);

    /* First count how many entries we'll have.  */
    cnt = 1;
    current = BOUNDED_1 ((struct layout *) top_frame);
    while (!((void *) current INNER_THAN top_stack
             || !((void *) current INNER_THAN __libc_stack_end)))
    {
        ++cnt;

        current = ADVANCE_STACK_FRAME (current->next);
    }

    arr = alloca (cnt * sizeof (void *));

    /* First handle the program counter from the structure.  */
    arr[0] = GET_PC (ctx);

    current = BOUNDED_1 ((struct layout *) top_frame);
    cnt = 1;
    while (!((void *) current INNER_THAN top_stack
             || !((void *) current INNER_THAN __libc_stack_end)))
    {
        arr[cnt++] = current->return_address;

        current = ADVANCE_STACK_FRAME (current->next);
    }

    /* If the last return address was NULL, assume that it doesn't count.  */
    if (arr[cnt-1] == NULL)
        cnt--;

    /* Now generate nicely formatted output.  */
    __backtrace_symbols_fd (arr, cnt, fd);

    /* Pass on the signal (so that a core file is produced).  */
    sa.sa_handler = SIG_DFL;
    sigemptyset (&sa.sa_mask);
    sa.sa_flags = 0;
    sigaction (signal, &sa, NULL);
    raise (signal);
}