+ }
+
+ xbt_dynar_insert_at(mmalloc_ignore, cursor, ®ion);
+
+ MC_UNSET_RAW_MEM;
+}
+
+void MC_new_stack_area(void *stack, char *name){
+ MC_SET_RAW_MEM;
+ stack_region_t region = NULL;
+ region = xbt_new0(s_stack_region_t, 1);
+ region->address = stack;
+ region->process_name = strdup(name);
+ xbt_dynar_push(stacks_areas, ®ion);
+ MC_UNSET_RAW_MEM;
+}
+
+/************ DWARF ***********/
+
+static e_dw_location_type get_location(char *expr, dw_location_t entry);
+
+void MC_get_binary_local_variables(){
+
+ char *command = bprintf("dwarfdump -i %s", xbt_binary_name);
+
+ FILE* fp = popen(command, "r");
+
+ if(fp == NULL)
+ perror("popen failed");
+
+ char *line = NULL, *tmp_line = NULL, *tmp_location = NULL, *frame_name = NULL;
+ ssize_t read;
+ size_t n = 0;
+ int valid_variable = 1, valid_frame = 1;
+ char *node_type = NULL, *location_type = NULL, *variable_name = NULL, *lowpc = NULL, *highpc = NULL;
+ xbt_dynar_t split = NULL;
+
+ void *low_pc = NULL, *old_low_pc = NULL;
+
+ int compile_unit_found = 0; /* Detect if the program has been compiled with -g */
+
+ read = getline(&line, &n, fp);
+
+ while (read != -1) {
+
+ if(n == 0)
+ continue;
+
+ /* Wipeout the new line character */
+ line[read - 1] = '\0';
+
+ if(line[0] == '<'){
+
+ /* If the program hasn't been compiled with -g, no symbol (line starting with '<' ) found */
+ compile_unit_found = 1;
+
+ /* Get node type */
+ strtok(line, " ");
+ strtok(NULL, " ");
+ node_type = strtok(NULL, " ");
+
+ if(strcmp(node_type, "DW_TAG_subprogram") == 0){ /* New frame */
+
+ read = getline(&line, &n, fp);
+
+ while(read != -1 && line[0] != '<'){
+
+ if(n == 0)
+ continue;
+
+ node_type = strtok(line, " ");
+
+ if(node_type != NULL && strcmp(node_type, "DW_AT_name") == 0){
+
+ frame_name = strdup(strtok(NULL, " "));
+ xbt_str_trim(frame_name, NULL);
+ xbt_str_trim(frame_name, "\"");
+ read = getline(&line, &n, fp);
+
+ }else if(node_type != NULL && strcmp(node_type, "DW_AT_frame_base") == 0){
+
+ if(valid_frame == 1){
+
+ dw_frame_t frame = xbt_new0(s_dw_frame_t, 1);
+ frame->name = strdup(frame_name);
+ frame->variables = xbt_dynar_new(sizeof(dw_local_variable_t), NULL);
+ frame->location = xbt_new0(s_dw_location_t, 1);
+
+ location_type = strtok(NULL, " ");
+
+ if(strcmp(location_type, "<loclist") == 0){
+
+ frame->location->type = e_dw_loclist;
+ frame->location->location.loclist = xbt_dynar_new(sizeof(dw_location_entry_t), NULL);
+
+ read = getline(&line, &n, fp);
+ xbt_str_ltrim(line, NULL);
+
+ while(read != -1 && line[0] == '['){
+
+ strtok(line, "<");
+ lowpc = strdup(strtok(NULL, "<"));
+ highpc = strdup(strtok(NULL, ">"));
+ tmp_location = strdup(strtok(NULL, ">"));
+ lowpc[strlen(lowpc) - 1] = '\0'; /* Remove last character '>' */
+
+ dw_location_entry_t new_entry = xbt_new0(s_dw_location_entry_t, 1);
+
+ if(low_pc == NULL){
+ strtok(lowpc, "=");
+ new_entry->lowpc = (void *) strtoul(strtok(NULL, "="), NULL, 16);
+ strtok(highpc, "=");
+ new_entry->highpc = (void *) strtoul(strtok(NULL, "="), NULL, 16);
+ }else{
+ strtok(lowpc, "=");
+ old_low_pc = (void *)strtoul(strtok(NULL, "="), NULL, 16);
+ new_entry->lowpc = (char *)low_pc + (long)old_low_pc;
+ strtok(highpc, "=");
+ new_entry->highpc = (char*)low_pc + ((char *)((void *)strtoul(strtok(NULL, "="), NULL, 16)) - (char*)old_low_pc);
+ }
+
+ new_entry->location = xbt_new0(s_dw_location_t, 1);
+
+ get_location(tmp_location, new_entry->location);
+
+ xbt_dynar_push(frame->location->location.loclist, &new_entry);
+
+ read = getline(&line, &n, fp);
+ xbt_str_ltrim(line, NULL);
+ }
+
+ }else{
+ read = getline(&line, &n, fp);
+ frame->location->type = get_location(location_type, frame->location);
+
+ }
+
+ xbt_dynar_push(mc_binary_local_variables, &frame);
+
+ }else{
+
+ read = getline(&line, &n, fp);
+
+ }
+
+ }else if(node_type != NULL && (strcmp(node_type, "DW_AT_declaration") == 0 || strcmp(node_type, "DW_AT_abstract_origin") == 0 || strcmp(node_type, "DW_AT_artificial") == 0)){
+
+ read = getline(&line, &n, fp);
+ valid_frame = 0;
+
+ }else{
+
+ read = getline(&line, &n, fp);
+
+ }
+
+ }
+
+ valid_frame = 1;
+
+ }else if(strcmp(node_type, "DW_TAG_variable") == 0){ /* New variable */
+
+ variable_name = NULL;
+ location_type = NULL;
+
+ read = getline(&line, &n, fp);
+
+ while(read != -1 && line[0] != '<'){
+
+ if(n == 0)
+ continue;
+
+ tmp_line = strdup(line);
+
+ node_type = strtok(line, " ");
+
+ if(node_type != NULL && strcmp(node_type, "DW_AT_name") == 0){
+
+ variable_name = strdup(strtok(NULL, " "));
+ xbt_str_trim(variable_name, NULL);
+ xbt_str_trim(variable_name, "\"");
+ read = getline(&line, &n, fp);
+
+ }else if(node_type != NULL && strcmp(node_type, "DW_AT_location") == 0){
+
+ if(valid_variable == 1){
+
+ location_type = strdup(strtok(NULL, " "));
+
+ dw_local_variable_t variable = xbt_new0(s_dw_local_variable_t, 1);
+ variable->name = strdup(variable_name);
+ variable->location = xbt_new0(s_dw_location_t, 1);
+
+ if(strcmp(location_type, "<loclist") == 0){
+
+ variable->location->type = e_dw_loclist;
+ variable->location->location.loclist = xbt_dynar_new(sizeof(dw_location_entry_t), NULL);
+
+ read = getline(&line, &n, fp);
+ xbt_str_ltrim(line, NULL);
+
+ while(read != -1 && line[0] == '['){
+
+ strtok(line, "<");
+ lowpc = strdup(strtok(NULL, "<"));
+ highpc = strdup(strtok(NULL, ">"));
+ tmp_location = strdup(strtok(NULL, ">"));
+ lowpc[strlen(lowpc) - 1] = '\0'; /* Remove last character '>' */
+
+ dw_location_entry_t new_entry = xbt_new0(s_dw_location_entry_t, 1);
+
+ if(low_pc == NULL){
+ strtok(lowpc, "=");
+ new_entry->lowpc = (void *) strtoul(strtok(NULL, "="), NULL, 16);
+ strtok(highpc, "=");
+ new_entry->highpc = (void *) strtoul(strtok(NULL, "="), NULL, 16);
+ }else{
+ strtok(lowpc, "=");
+ old_low_pc = (void *)strtoul(strtok(NULL, "="), NULL, 16);
+ new_entry->lowpc = (char *)low_pc + (long)old_low_pc;
+ strtok(highpc, "=");
+ new_entry->highpc = (char*)low_pc + ((char *)((void *)strtoul(strtok(NULL, "="), NULL, 16)) - (char*)old_low_pc);
+ }
+
+ new_entry->location = xbt_new0(s_dw_location_t, 1);
+
+ get_location(tmp_location, new_entry->location);
+
+ xbt_dynar_push(variable->location->location.loclist, &new_entry);
+
+ read = getline(&line, &n, fp);
+ xbt_str_ltrim(line, NULL);
+ }
+
+ }else{
+
+ xbt_str_strip_spaces(tmp_line);
+ split = xbt_str_split(tmp_line, " ");
+ xbt_dynar_remove_at(split, 0, NULL);
+ location_type = xbt_str_join(split, " ");
+
+ variable->location->type = get_location(location_type, variable->location);
+ read = getline(&line, &n, fp);
+
+ }
+
+ xbt_dynar_push(((dw_frame_t)xbt_dynar_get_as(mc_binary_local_variables, xbt_dynar_length(mc_binary_local_variables) - 1, dw_frame_t))->variables, &variable);
+
+ }else{
+
+ read = getline(&line, &n, fp);
+
+ }
+
+ }else if(node_type != NULL && (strcmp(node_type, "DW_AT_artificial") == 0 || strcmp(node_type, "DW_AT_external") == 0)){
+
+ valid_variable = 0;
+ read = getline(&line, &n, fp);
+
+ }else{
+
+ read = getline(&line, &n, fp);
+
+ }
+
+ }
+
+ valid_variable = 1;
+
+ }else if(strcmp(node_type, "DW_TAG_compile_unit") == 0){
+
+ read = getline(&line, &n, fp);
+
+ while(read != -1 && line[0] != '<'){
+
+ if(n == 0)
+ continue;
+
+ node_type = strtok(line, " ");
+
+ if(node_type != NULL && strcmp(node_type, "DW_AT_low_pc") == 0){
+ low_pc = (void *) strtoul(strtok(NULL, " "), NULL, 16);
+ }
+
+ read = getline(&line, &n, fp);
+
+ }
+
+ }else{
+
+ read = getline(&line, &n, fp);
+
+ }
+
+ }else{
+
+ read = getline(&line, &n, fp);
+