+ elm_size = subtype->size;
+ break;
+ case e_dw_typedef:
+ case e_dw_volatile_type:
+ subsubtype = xbt_dict_get_or_null(all_types, subtype->dw_type_id);
+ if(subsubtype->size == 0){ /*declaration of the type, need the complete description */
+ type_desc = get_type_description(all_types, subsubtype->name);
+ if(type_desc){
+ subsubtype = xbt_dict_get_or_null(all_types, type_desc);
+ }else{
+ subsubtype = xbt_dict_get_or_null(other_types, get_type_description(other_types, subtype->name));
+ switch_types = 1;
+ }
+ }
+ elm_size = subsubtype->size;
+ break;
+ default :
+ return 0;
+ break;
+ }
+ for(i=0; i<type->size; i++){
+ if(switch_types)
+ res = compare_heap_area_with_type((char *)real_area1 + (i*elm_size), (char *)real_area2 + (i*elm_size), (char *)area1 + (i*elm_size), (char *)area2 + (i*elm_size), previous, other_types, all_types, type->dw_type_id, type->size, check_ignore, pointer_level);
+ else
+ res = compare_heap_area_with_type((char *)real_area1 + (i*elm_size), (char *)real_area2 + (i*elm_size), (char *)area1 + (i*elm_size), (char *)area2 + (i*elm_size), previous, all_types, other_types, type->dw_type_id, type->size, check_ignore, pointer_level);
+ if(res == 1)
+ return res;
+ }
+ break;
+ case e_dw_pointer_type:
+ if(type->dw_type_id && ((dw_type_t)xbt_dict_get_or_null(all_types, type->dw_type_id))->type == e_dw_subroutine_type){
+ addr_pointed1 = *((void **)(area1));
+ addr_pointed2 = *((void **)(area2));
+ return (addr_pointed1 != addr_pointed2);;
+ }else{
+ pointer_level++;
+ if(pointer_level > 1){ /* Array of pointers */
+ for(i=0; i<(area_size/sizeof(void *)); i++){
+ addr_pointed1 = *((void **)((char *)area1 + (i*sizeof(void *))));
+ addr_pointed2 = *((void **)((char *)area2 + (i*sizeof(void *))));
+ if(addr_pointed1 > s_heap && (char *)addr_pointed1 < (char*) s_heap + STD_HEAP_SIZE && addr_pointed2 > s_heap && (char *)addr_pointed2 < (char*) s_heap + STD_HEAP_SIZE)
+ res = compare_heap_area(addr_pointed1, addr_pointed2, previous, all_types, other_types, type->dw_type_id, pointer_level);
+ else
+ res = (addr_pointed1 != addr_pointed2);
+ if(res == 1)
+ return res;
+ }
+ }else{
+ addr_pointed1 = *((void **)(area1));
+ addr_pointed2 = *((void **)(area2));
+ if(addr_pointed1 > s_heap && (char *)addr_pointed1 < (char*) s_heap + STD_HEAP_SIZE && addr_pointed2 > s_heap && (char *)addr_pointed2 < (char*) s_heap + STD_HEAP_SIZE)
+ return compare_heap_area(addr_pointed1, addr_pointed2, previous, all_types, other_types, type->dw_type_id, pointer_level);
+ else
+ return (addr_pointed1 != addr_pointed2);
+ }
+ }
+ break;
+ case e_dw_structure_type:
+ if(type->size == 0){ /*declaration of the structure, need the complete description */
+ type_desc = get_type_description(all_types, type->name);
+ if(type_desc){
+ type = xbt_dict_get_or_null(all_types, type_desc);
+ }else{
+ type = xbt_dict_get_or_null(other_types, get_type_description(other_types, type->name));
+ switch_types = 1;
+ }
+ }
+ if(area_size != -1 && type->size != area_size){
+ if(area_size>type->size && area_size%type->size == 0){
+ for(i=0; i<(area_size/type->size); i++){
+ if(switch_types)
+ res = compare_heap_area_with_type((char *)real_area1 + (i*type->size), (char *)real_area2 + (i*type->size), (char *)area1 + (i*type->size), (char *)area2 + (i*type->size), previous, other_types, all_types, type_id, -1, check_ignore, 0);
+ else
+ res = compare_heap_area_with_type((char *)real_area1 + (i*type->size), (char *)real_area2 + (i*type->size), (char *)area1 + (i*type->size), (char *)area2 + (i*type->size), previous, all_types, other_types, type_id, -1, check_ignore, 0);
+ if(res == 1)
+ return res;
+ }
+ }else{
+ return -1;
+ }
+ }else{
+ cursor = 0;
+ xbt_dynar_foreach(type->members, cursor, member){
+ if(switch_types)
+ res = compare_heap_area_with_type((char *)real_area1 + member->offset, (char *)real_area2 + member->offset, (char *)area1 + member->offset, (char *)area2 + member->offset, previous, other_types, all_types, member->dw_type_id, -1, check_ignore, 0);
+ else
+ res = compare_heap_area_with_type((char *)real_area1 + member->offset, (char *)real_area2 + member->offset, (char *)area1 + member->offset, (char *)area2 + member->offset, previous, all_types, other_types, member->dw_type_id, -1, check_ignore, 0);
+ if(res == 1)
+ return res;
+ }
+ }
+ break;
+ case e_dw_union_type:
+ if((check_ignore > 0) && ((ignore1 = heap_comparison_ignore_size(to_ignore1, real_area1)) > 0) && ((ignore2 = heap_comparison_ignore_size(to_ignore2, real_area2)) == ignore1))
+ return 0;
+ else
+ return compare_heap_area_without_type(real_area1, real_area2, area1, area2, previous, all_types, other_types, type->size, check_ignore);
+ break;
+ case e_dw_volatile_type:
+ return compare_heap_area_with_type(real_area1, real_area2, area1, area2, previous, all_types, other_types, type->dw_type_id, area_size, check_ignore, pointer_level);
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+
+}
+
+int compare_heap_area(void *area1, void* area2, xbt_dynar_t previous, xbt_dict_t all_types, xbt_dict_t other_types, char *type_id, int pointer_level){
+
+ int res_compare;
+ ssize_t block1, frag1, block2, frag2;
+ ssize_t size;
+ int check_ignore = 0;
+
+ void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
+ void *area1_to_compare, *area2_to_compare;
+ dw_type_t type = NULL;
+ char *type_desc;
+ int type_size = -1;
+
+ int match_pairs = 0;
+
+ if(previous == NULL){
+ previous = xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
+ match_pairs = 1;
+ }
+
+ block1 = ((char*)area1 - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
+ block2 = ((char*)area2 - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
+
+ if(is_block_stack((int)block1) && is_block_stack((int)block2)){
+ add_heap_area_pair(previous, block1, -1, block2, -1);
+ if(match_pairs){
+ match_equals(previous);
+ xbt_dynar_free(&previous);
+ }
+ return 0;
+ }
+
+ if(((char *)area1 < (char*)((xbt_mheap_t)s_heap)->heapbase) || (block1 > heapsize1) || (block1 < 1) || ((char *)area2 < (char*)((xbt_mheap_t)s_heap)->heapbase) || (block2 > heapsize2) || (block2 < 1)){
+ if(match_pairs){
+ xbt_dynar_free(&previous);
+ }
+ return 1;
+ }
+
+ addr_block1 = ((void*) (((ADDR2UINT(block1)) - 1) * BLOCKSIZE + (char*)heapbase1));
+ addr_block2 = ((void*) (((ADDR2UINT(block2)) - 1) * BLOCKSIZE + (char*)heapbase2));
+
+ if(type_id){
+ type = xbt_dict_get_or_null(all_types, type_id);
+ if(type->size == 0){
+ if(type->dw_type_id == NULL){
+ type_desc = get_type_description(all_types, type->name);
+ if(type_desc)
+ type = xbt_dict_get_or_null(all_types, type_desc);
+ else
+ type = xbt_dict_get_or_null(other_types, get_type_description(other_types, type->name));
+ }else{
+ type = xbt_dict_get_or_null(all_types, type->dw_type_id);
+ }
+ }
+ if((type->type == e_dw_pointer_type) || ((type->type == e_dw_base_type) && (!strcmp(type->name, "char"))))
+ type_size = -1;
+ else
+ type_size = type->size;
+ }
+
+ if((heapinfo1[block1].type == -1) && (heapinfo2[block2].type == -1)){ /* Free block */
+
+ if(match_pairs){
+ match_equals(previous);
+ xbt_dynar_free(&previous);
+ }
+ return 0;
+
+ }else if((heapinfo1[block1].type == 0) && (heapinfo2[block2].type == 0)){ /* Complete block */
+
+ if(equals_to1[block1][0] != NULL && equals_to2[block2][0] != NULL){
+ if(equal_blocks(block1, block2)){
+ if(match_pairs){
+ match_equals(previous);
+ xbt_dynar_free(&previous);
+ }
+ return 0;
+ }
+ }
+
+ if(type_size != -1){
+ if(type_size != heapinfo1[block1].busy_block.busy_size && type_size != heapinfo2[block2].busy_block.busy_size && strcmp(type->name, "s_smx_context") != 0)
+ return -1;
+ }
+
+ if(heapinfo1[block1].busy_block.size != heapinfo2[block2].busy_block.size){
+ if(match_pairs){
+ xbt_dynar_free(&previous);
+ }
+ return 1;
+ }
+
+ if(heapinfo1[block1].busy_block.busy_size != heapinfo2[block2].busy_block.busy_size){
+ if(match_pairs){
+ xbt_dynar_free(&previous);
+ }
+ return 1;
+ }
+
+ if(!add_heap_area_pair(previous, block1, -1, block2, -1)){
+ if(match_pairs){
+ match_equals(previous);
+ xbt_dynar_free(&previous);
+ }
+ return 0;
+ }
+
+ size = heapinfo1[block1].busy_block.busy_size;
+
+ if(size <= 0){
+ if(match_pairs){
+ match_equals(previous);
+ xbt_dynar_free(&previous);
+ }
+ return 0;
+ }
+
+ frag1 = -1;
+ frag2 = -1;
+
+ area1_to_compare = addr_block1;
+ area2_to_compare = addr_block2;
+
+ if((heapinfo1[block1].busy_block.ignore > 0) && (heapinfo2[block2].busy_block.ignore == heapinfo1[block1].busy_block.ignore))
+ check_ignore = heapinfo1[block1].busy_block.ignore;