X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f9bc1eb9da233212a26b57efa214e1224fd03677..3ce8390e04369fc85458df13a3718b4bd00b94d3:/src/mc/mc_checkpoint.c diff --git a/src/mc/mc_checkpoint.c b/src/mc/mc_checkpoint.c index acdafa7fb7..26b56fbe88 100644 --- a/src/mc/mc_checkpoint.c +++ b/src/mc/mc_checkpoint.c @@ -1,16 +1,34 @@ +/* Copyright (c) 2008-2012 Da SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + #include -#include "private.h" +#include "mc_private.h" +#include "xbt/module.h" + +#include "../simix/smx_private.h" +#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc, "Logging specific to mc_checkpoint"); +void *start_text_libsimgrid; +void *start_plt, *end_plt; +char *libsimgrid_path; + static mc_mem_region_t MC_region_new(int type, void *start_addr, size_t size); static void MC_region_restore(mc_mem_region_t reg); static void MC_region_destroy(mc_mem_region_t reg); static void MC_snapshot_add_region(mc_snapshot_t snapshot, int type, void *start_addr, size_t size); +static void add_value(xbt_dynar_t *list, const char *type, unsigned long int val); +static xbt_dynar_t take_snapshot_stacks(void *heap); +static void get_local_variables_values(xbt_dynar_t *all_variables, stack_region_t stack, void *heap); +static void print_local_variables_values(xbt_dynar_t all_variables); + static mc_mem_region_t MC_region_new(int type, void *start_addr, size_t size) { mc_mem_region_t new_reg = xbt_new0(s_mc_mem_region_t, 1); @@ -18,8 +36,9 @@ static mc_mem_region_t MC_region_new(int type, void *start_addr, size_t size) new_reg->start_addr = start_addr; new_reg->size = size; new_reg->data = xbt_malloc0(size); - XBT_DEBUG("New reg data %p, start_addr %p", new_reg->data, start_addr); memcpy(new_reg->data, start_addr, size); + + XBT_DEBUG("New region : type : %d, data : %p, size : %zu", type, new_reg->data, size); return new_reg; } @@ -28,31 +47,9 @@ static void MC_region_restore(mc_mem_region_t reg) { /*FIXME: check if start_addr is still mapped, if it is not, then map it before copying the data */ - if(reg->type == 3){ - memory_map_t maps = get_memory_map(); - MC_UNSET_RAW_MEM; - unsigned int i=0; - s_map_region r; - while(i < maps->mapsize){ - r = maps->regions[i]; - if (maps->regions[i].pathname != NULL){ - if (!memcmp(maps->regions[i].pathname, "[stack]", 7)){ - size_t diff = (char*)reg->start_addr - (char*)r.start_addr; - void *segment = malloc(reg->size + diff); - XBT_DEBUG("Size of segment : %lu", sizeof(segment)); - memcpy((char *)segment + diff, reg->data, reg->size); - memcpy(r.start_addr, segment, sizeof(segment)); - XBT_DEBUG("Memcpy region ok"); - break; - } - } - i++; - } - }else{ - XBT_DEBUG("Memcpy : dest %p, src %p, size %Zu", reg->start_addr, reg->data, reg->size); - memcpy(reg->start_addr, reg->data, reg->size); - } - + + memcpy(reg->start_addr, reg->data, reg->size); + return; } @@ -64,20 +61,6 @@ static void MC_region_destroy(mc_mem_region_t reg) static void MC_snapshot_add_region(mc_snapshot_t snapshot, int type, void *start_addr, size_t size) { - switch(type){ - case 0 : - XBT_DEBUG("New region heap (%Zu)", size); - break; - case 1 : - XBT_DEBUG("New region libsimgrid (%Zu)", size); - break; - case 2 : - XBT_DEBUG("New region program (%Zu)", size); - break; - case 3 : - XBT_DEBUG("New region stack (%Zu)", size); - break; - } mc_mem_region_t new_reg = MC_region_new(type, start_addr, size); snapshot->regions = xbt_realloc(snapshot->regions, (snapshot->num_reg + 1) * sizeof(mc_mem_region_t)); snapshot->regions[snapshot->num_reg] = new_reg; @@ -88,7 +71,7 @@ static void MC_snapshot_add_region(mc_snapshot_t snapshot, int type, void *start void MC_take_snapshot(mc_snapshot_t snapshot) { unsigned int i = 0; - s_map_region reg; + s_map_region_t reg; memory_map_t maps = get_memory_map(); /* Save the std heap and the writable mapped pages of libsimgrid */ @@ -108,88 +91,53 @@ void MC_take_snapshot(mc_snapshot_t snapshot) i++; } - /* FIXME: free the memory map */ + free_memory_map(maps); } - void MC_take_snapshot_liveness(mc_snapshot_t snapshot) { unsigned int i = 0; - s_map_region reg; + s_map_region_t reg; memory_map_t maps = get_memory_map(); - - for(i=0; i< snapshot->num_reg; i++){ - MC_region_destroy(snapshot->regions[i]); - } - - snapshot->num_reg = 0; - - i = 0; + int nb_reg = 0; + void *heap = NULL; /* Save the std heap and the writable mapped pages of libsimgrid */ - while (i < maps->mapsize) { + while (i < maps->mapsize && nb_reg < 3) { reg = maps->regions[i]; if ((reg.prot & PROT_WRITE)){ if (maps->regions[i].pathname == NULL){ if (reg.start_addr == std_heap){ // only save the std heap (and not the raw one) - MC_snapshot_add_region(snapshot, 0, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); + MC_snapshot_add_region(snapshot, 0, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); + heap = snapshot->regions[nb_reg]->data; + nb_reg++; } } else { if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){ MC_snapshot_add_region(snapshot, 1, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); + nb_reg++; } else { - if (!memcmp(basename(maps->regions[i].pathname), basename(prog_name), strlen(basename(prog_name)))){ - MC_snapshot_add_region(snapshot, 2, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); - } /*else { - if (!memcmp(maps->regions[i].pathname, "[stack]", 7)){ - MC_snapshot_add_region(snapshot, 3, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); - } - }*/ - } - } - } - i++; - } - - /* FIXME: free the memory map */ -} - -void MC_take_snapshot_to_restore_liveness(mc_snapshot_t snapshot) -{ - unsigned int i = 0; - s_map_region reg; - memory_map_t maps = get_memory_map(); - - for(i=0; i< snapshot->num_reg; i++){ - MC_region_destroy(snapshot->regions[i]); - } - - snapshot->num_reg = 0; - - i = 0; - - /* Save the std heap and the writable mapped pages of libsimgrid */ - while (i < maps->mapsize) { - reg = maps->regions[i]; - if ((reg.prot & PROT_WRITE)){ - if (maps->regions[i].pathname == NULL){ - if (reg.start_addr == std_heap){ // only save the std heap (and not the raw one) - MC_snapshot_add_region(snapshot, 0, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); + if (!memcmp(basename(maps->regions[i].pathname), basename(xbt_binary_name), strlen(basename(xbt_binary_name)))){ + MC_snapshot_add_region(snapshot, 2, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); + nb_reg++; + } } - } else { + } + }else if ((reg.prot & PROT_READ)){ + if (maps->regions[i].pathname != NULL){ if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){ - MC_snapshot_add_region(snapshot, 1, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); - } else { - if (!memcmp(basename(maps->regions[i].pathname), basename(prog_name), strlen(basename(prog_name)))){ - MC_snapshot_add_region(snapshot, 2, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); - } - } + start_text_libsimgrid = reg.start_addr; + libsimgrid_path = strdup(maps->regions[i].pathname); + } } } i++; } - /* FIXME: free the memory map */ + snapshot->stacks = take_snapshot_stacks(heap); + + free_memory_map(maps); + } void MC_restore_snapshot(mc_snapshot_t snapshot) @@ -197,21 +145,6 @@ void MC_restore_snapshot(mc_snapshot_t snapshot) unsigned int i; for(i=0; i < snapshot->num_reg; i++){ MC_region_restore(snapshot->regions[i]); - switch(snapshot->regions[i]->type){ - case 0 : - XBT_DEBUG("heap restored"); - break; - case 1: - XBT_DEBUG("libsimgrid (data) restored"); - break; - case 2: - XBT_DEBUG("program (data) restored"); - break; - case 3: - XBT_DEBUG("stack restored"); - break; - } - } } @@ -226,3 +159,60 @@ void MC_free_snapshot(mc_snapshot_t snapshot) } +void get_plt_section(){ + + FILE *fp; + char *line = NULL; /* Temporal storage for each line that is readed */ + ssize_t read; /* Number of bytes readed */ + size_t n = 0; /* Amount of bytes to read by getline */ + + char *lfields[7]; + int i, plt_not_found = 1; + unsigned long int size, offset; + + char *command = bprintf( "objdump --section-headers %s", libsimgrid_path); + + fp = popen(command, "r"); + + if(fp == NULL) + perror("popen failed"); + + while ((read = getline(&line, &n, fp)) != -1 && plt_not_found == 1) { + + if(n == 0) + continue; + + /* Wipeout the new line character */ + line[read - 1] = '\0'; + + lfields[0] = strtok(line, " "); + + if(lfields[0] == NULL) + continue; + + if(strcmp(lfields[0], "Sections:") == 0 || strcmp(lfields[0], "Idx") == 0 || strcmp(lfields[0], "libsimgrid.so:") == 0) + continue; + + for (i = 1; i < 7 && lfields[i - 1] != NULL; i++) { + lfields[i] = strtok(NULL, " "); + } + + if(i>=5){ + if(strcmp(lfields[1], ".plt") == 0){ + size = strtoul(lfields[2], NULL, 16); + offset = strtoul(lfields[4], NULL, 16); + start_plt = (char *)start_text_libsimgrid + offset; + end_plt = (char *)start_plt + size; + plt_not_found = 0; + } + } + + + } + + free(command); + free(line); + pclose(fp); + +} +