--- rpl/src/gestion_objets.c 2010/05/05 21:20:37 1.15 +++ rpl/src/gestion_objets.c 2010/05/13 19:09:18 1.16 @@ -3535,9 +3535,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 { @@ -3547,7 +3550,13 @@ 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; + pthread_t thread; + pid_t pid; } struct_memoire; static struct_memoire *debug = NULL; @@ -3582,6 +3591,12 @@ debug_memoire_ajout(size_t taille, const (*debug).ligne = ligne; (*debug).taille = taille; (*debug).ordre = ordre; + (*debug).thread = pthread_self(); + (*debug).pid = getpid(); + +# ifdef __BACKTRACE + (*debug).profondeur = backtrace((*debug).pile, PROFONDEUR_PILE); +# endif pthread_mutex_unlock(&mutex_allocation); @@ -3728,6 +3743,12 @@ debug_memoire_retrait(void *pointeur) void debug_memoire_verification(struct_processus *s_etat_processus) { +# ifdef __BACKTRACE + char **appels; +# endif + + int j; + integer8 i; struct_memoire *element_courant; @@ -3743,28 +3764,44 @@ debug_memoire_verification(struct_proces while(element_courant != NULL) { - fprintf(stderr, "[%d-%llu] MEDITATION %lld (%llu)\n", getpid(), - (unsigned long long) pthread_self(), i, - (*element_courant).ordre); - fprintf(stderr, "[%d-%llu] P: %p, F: %s(), L: %lu, S: %d\n", - getpid(), (unsigned long long) pthread_self(), - (*element_courant).pointeur, - (*element_courant).fonction, (*element_courant).ligne, - (int) (*element_courant).taille); - fprintf(stderr, "[%d-%llu] A: %s\n", getpid(), - (unsigned long long) pthread_self(), - (*element_courant).argument); - - switch(i) + if (((*element_courant).pid == getpid()) && + (pthread_equal((*element_courant).thread, pthread_self()) != 0)) { - // Affichage des méditations - case 1: + fprintf(stderr, "[%d-%llu] MEDITATION %lld (%llu)\n", getpid(), + (unsigned long long) pthread_self(), i, + (*element_courant).ordre); + fprintf(stderr, "[%d-%llu] P: %p, F: %s(), L: %lu, S: %d\n", + getpid(), (unsigned long long) pthread_self(), + (*element_courant).pointeur, + (*element_courant).fonction, (*element_courant).ligne, + (int) (*element_courant).taille); + fprintf(stderr, "[%d-%llu] A: %s\n", getpid(), + (unsigned long long) pthread_self(), + (*element_courant).argument); + +# 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) { - break; + for(j = 0; j < (*element_courant).profondeur; j++) + { + fprintf(stderr, "[%d-%llu] %s\n", getpid(), + (unsigned long long) pthread_self(), appels[j]); + } + + free(appels); } - } +# endif + + fprintf(stderr, "\n"); - i++; + i++; + } element_suivant = (*element_courant).suivant; free((*element_courant).fonction);