--- rpl/src/gestion_objets.c 2010/03/04 10:17:48 1.7 +++ rpl/src/gestion_objets.c 2010/05/24 10:58:30 1.20 @@ -1,6 +1,6 @@ /* ================================================================================ - RPL/2 (R) version 4.0.12 + RPL/2 (R) version 4.0.16 Copyright (C) 1989-2010 Dr. BERTRAND Joël This file is part of RPL/2. @@ -877,12 +877,21 @@ liberation(struct_processus *s_etat_proc { if (decrementation_atomique(s_objet) > 0) { + BUG((*(*((struct_fichier *) (*s_objet).objet)).format) + .nombre_occurrences <= 1, + pthread_mutex_unlock(&((*s_objet).mutex)), + printf("(*(*((struct_fichier *) (*s_objet).objet))" + ".format).nombre_occurrences=%ld\n", + (*(*((struct_fichier *) (*s_objet).objet)).format) + .nombre_occurrences)); + + liberation(s_etat_processus, + (*((struct_fichier *) (*s_objet).objet)).format); return; } liberation(s_etat_processus, (*((struct_fichier *) (*s_objet).objet)).format); - free((unsigned char *) (*((struct_fichier *) (*s_objet).objet)).nom); free((struct_fichier *) ((*s_objet).objet)); @@ -1208,11 +1217,22 @@ liberation(struct_processus *s_etat_proc { if (decrementation_atomique(s_objet) > 0) { + BUG((*(*((struct_socket *) (*s_objet).objet)).format) + .nombre_occurrences <= 1, + pthread_mutex_unlock(&((*s_objet).mutex)), + printf("(*(*((struct_socket *) (*s_objet).objet))" + ".format).nombre_occurrences=%ld\n", + (*(*((struct_socket *) (*s_objet).objet)).format) + .nombre_occurrences)); + + liberation(s_etat_processus, (*((struct_socket *) + (*s_objet).objet)).format); return; } liberation(s_etat_processus, (*((struct_socket *) (*s_objet).objet)).format); + free((unsigned char *) (*((struct_socket *) (*s_objet).objet)) .adresse); free((unsigned char *) (*((struct_socket *) (*s_objet).objet)) @@ -1749,6 +1769,14 @@ copie_objet(struct_processus *s_etat_pro if (type == 'P') { incrementation_atomique(s_objet); + + if (((*((struct_fichier *) ((*s_objet).objet))).format = + copie_objet(s_etat_processus, (*((struct_fichier *) + ((*s_objet).objet))).format, 'P')) == NULL) + { + return(NULL); + } + return(s_objet); } @@ -2265,6 +2293,15 @@ copie_objet(struct_processus *s_etat_pro if (type == 'P') { incrementation_atomique(s_objet); + + if (((*((struct_socket *) ((*s_objet).objet))) + .format = copie_objet(s_etat_processus, + (*((struct_socket *) ((*s_objet).objet))).format, 'P')) + == NULL) + { + return(NULL); + } + return(s_objet); } @@ -2721,7 +2758,16 @@ copie_etat_processus(struct_processus *s * n'ont aucune raison de changer. */ +# ifndef SEMAPHORES_NOMMES sem_init(&((*s_nouvel_etat_processus).semaphore_fork), 0, 0); +# else + if (((*s_nouvel_etat_processus).semaphore_fork = sem_init2(0, sem_fork)) + == SEM_FAILED) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return(NULL); + } +# endif (*s_nouvel_etat_processus).var_volatile_processus_pere = 0; (*s_nouvel_etat_processus).fichiers_graphiques = NULL; @@ -2753,6 +2799,8 @@ copie_etat_processus(struct_processus *s (*s_nouvel_etat_processus).nombre_interruptions_en_queue = 0; (*s_nouvel_etat_processus).nombre_interruptions_non_affectees = 0; + (*s_nouvel_etat_processus).at_exit = NULL; + for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++) { (*s_nouvel_etat_processus).corps_interruptions[i] = NULL; @@ -3032,6 +3080,8 @@ copie_etat_processus(struct_processus *s (*s_etat_processus).s_liste_variables[i].niveau; (*s_nouvel_etat_processus).s_liste_variables[i].variable_statique = (*s_etat_processus).s_liste_variables[i].variable_statique; + (*s_nouvel_etat_processus).s_liste_variables[i].variable_partagee = + (*s_etat_processus).s_liste_variables[i].variable_partagee; (*s_nouvel_etat_processus).s_liste_variables[i].variable_verrouillee = (*s_etat_processus).s_liste_variables[i].variable_verrouillee; @@ -3522,9 +3572,12 @@ copie_etat_processus(struct_processus *s #undef fprintf +#ifdef __BACKTRACE #define return(a) { if (a == NULL) \ { BACKTRACE(20); fprintf(stderr, ">>> MEDITATION %d\n", __LINE__); } \ return(a); } while(0) +#define PROFONDEUR_PILE 64 +#endif typedef struct memoire { @@ -3534,6 +3587,10 @@ typedef struct memoire unsigned long ligne; size_t taille; unsigned long long ordre; +# ifdef __BACKTRACE + void *pile[PROFONDEUR_PILE]; + int profondeur; +# endif struct memoire *suivant; } struct_memoire; @@ -3542,6 +3599,7 @@ static unsigned long long ordre = 0; static pthread_mutex_t mutex_allocation = PTHREAD_MUTEX_INITIALIZER; #define check(a, b) ((strcmp(#a, fonction) == 0) && (ligne == b)) +#undef CORE_DUMP void * debug_memoire_ajout(size_t taille, const unsigned char *fonction, @@ -3570,23 +3628,28 @@ debug_memoire_ajout(size_t taille, const (*debug).taille = taille; (*debug).ordre = ordre; - pthread_mutex_unlock(&mutex_allocation); +# ifdef __BACKTRACE + (*debug).profondeur = backtrace((*debug).pile, PROFONDEUR_PILE); +# endif if (((*debug).fonction = malloc((strlen(fonction) + 1) * sizeof(unsigned char))) == NULL) { + pthread_mutex_unlock(&mutex_allocation); return(NULL); } if (((*debug).argument = malloc((strlen(argument) + 1) * sizeof(unsigned char))) == NULL) { + pthread_mutex_unlock(&mutex_allocation); return(NULL); } strcpy((*debug).fonction, fonction); strcpy((*debug).argument, argument); + pthread_mutex_unlock(&mutex_allocation); ordre++; return((*debug).pointeur); @@ -3631,11 +3694,10 @@ debug_memoire_modification(void *pointeu return(NULL); } - pthread_mutex_unlock(&mutex_allocation); - if (((*element_courant).pointeur = realloc(pointeur, taille)) == NULL) { + pthread_mutex_unlock(&mutex_allocation); return(NULL); } @@ -3647,18 +3709,22 @@ debug_memoire_modification(void *pointeu if (((*element_courant).fonction = malloc((strlen(fonction) + 1) * sizeof(unsigned char))) == NULL) { + pthread_mutex_unlock(&mutex_allocation); return(NULL); } if (((*element_courant).argument = malloc((strlen(argument) + 1) * sizeof(unsigned char))) == NULL) { + pthread_mutex_unlock(&mutex_allocation); return(NULL); } strcpy((*element_courant).fonction, fonction); strcpy((*element_courant).argument, argument); + pthread_mutex_unlock(&mutex_allocation); + return((*element_courant).pointeur); } } @@ -3713,14 +3779,20 @@ debug_memoire_retrait(void *pointeur) } void -debug_memoire_verification(struct_processus *s_etat_processus) +debug_memoire_verification() { +# ifdef __BACKTRACE + char **appels; + + int j; +# endif + integer8 i; struct_memoire *element_courant; struct_memoire *element_suivant; - fprintf(stderr, "[%d-%llu] MEMORY LEAK\n", + fprintf(stderr, "[%d-%llu] LIST OF MEMORY LEAKS\n", getpid(), (unsigned long long) pthread_self()); pthread_mutex_lock(&mutex_allocation); @@ -3742,21 +3814,64 @@ debug_memoire_verification(struct_proces (unsigned long long) pthread_self(), (*element_courant).argument); - switch(i) + if (strstr((*element_courant).argument, "sizeof(unsigned char)") + != NULL) + { + fprintf(stderr, "[%d-%llu] ", getpid(), + (unsigned long long) pthread_self()); + fprintf(stderr, "O: %s\n", (unsigned char *) + (*element_courant).pointeur); + } + else if (strcmp((*element_courant).argument, "sizeof(struct_objet)") + == 0) + { + fprintf(stderr, "[%d-%llu] ", getpid(), + (unsigned long long) pthread_self()); + fprintf(stderr, "O: %d\n", (*((struct_objet *) + (*element_courant).pointeur)).type); + } + else if (strcmp((*element_courant).argument, + "sizeof(struct_liste_chainee)") == 0) { - // Affichage des méditations - case 1: + fprintf(stderr, "[%d-%llu] ", getpid(), + (unsigned long long) pthread_self()); + fprintf(stderr, "O: data=%p next=%p\n", (*((struct_liste_chainee *) + (*element_courant).pointeur)).donnee, + (*((struct_liste_chainee *) (*element_courant).pointeur)) + .suivant); + } + +# ifdef __BACKTRACE + appels = backtrace_symbols((*element_courant).pile, + (*element_courant).profondeur); + + fprintf(stderr, "[%d-%llu] BACKTRACE\n", + getpid(), (unsigned long long) pthread_self()); + + if (appels != NULL) + { + for(j = 0; j < (*element_courant).profondeur; j++) { - break; + fprintf(stderr, "[%d-%llu] %s\n", getpid(), + (unsigned long long) pthread_self(), appels[j]); } + + free(appels); } +# endif + + fprintf(stderr, "\n"); i++; element_suivant = (*element_courant).suivant; + +# ifndef CORE_DUMP free((*element_courant).fonction); free((*element_courant).argument); free(element_courant); +# endif + element_courant = element_suivant; } @@ -3767,6 +3882,30 @@ debug_memoire_verification(struct_proces return; } + +void +debug_memoire_reinitialisation() +{ + ordre = 0; + debug = NULL; + + pthread_mutex_trylock(&mutex_allocation); + pthread_mutex_unlock(&mutex_allocation); + + return; +} + +void +analyse_post_mortem() +{ +# ifdef CORE_DUMP + BUG(debug != NULL, uprintf("[%d-%llu] CREATE CORE DUMP FILE FOR " + "POST MORTEM ANALYZE\n", getpid(), + (unsigned long long) pthread_self())); +# endif + + return; +} #endif