On Tue, 17 Aug 2010 09:48:41 -0500 Will Fiveash <will.five...@oracle.com> wrote:
> dtrace can trace the lock calls and plockstat can provide lock stats > for user space programs. truss can also trace user space function > calls but has higher overhead than dtrace. In addition the SunStudio > C dev. tools includes a static lock analyzer called lock_lint. I > suggest trying those first before going to the trouble of writing a > library. I looked at http://developers.sun.com/solaris/articles/locklint.html And under "Limitations of LockLint" there is a big list of cases where LockLint may not work. I have to say those cases crop up very often in my code and I would prefer to have a tool that works 100%. I have a limited knowledge of DTrace, since I mainly develop on BSD system, but for my own needs, developing a small debugging library seemed like a simpler and more portable approach, i.e. compile and run program and watch diagnostic info on stderr. Below is a simple example of test.c file: #include <stdlib.h> #include <pthread.h> /* Must be last include line */ #include "pvf.h" int main(void) { int i; pthread_mutex_t **mvec; /* Array of pointers to mutex locks */ /* Allocate array of 10 pointers */ if((mvec = malloc(10 * sizeof(pthread_mutex_t *))) == NULL) abort(); for(i = 0; i < 10; i++) { /* Allocate mutex */ if((mvec[i] = malloc(sizeof(pthread_mutex_t))) == NULL) abort(); /* Initialise mutex */ if(pthread_mutex_init(mvec[i], NULL) != 0) abort(); /* Lock mutex */ if(pthread_mutex_lock(mvec[i]) != 0) abort(); } /* Lock already locked mutex */ pthread_mutex_lock(mvec[0]); /* Lock uninitialised mutex */ pthread_mutex_lock(mvec[10]); /* Unlock mutex locks 0 to 9 */ for(i = 0; i < 9; i++) { if(pthread_mutex_unlock(mvec[i]) != 0) abort(); } /* Destroy mutex locks 1 to 10 */ for(i = 1; i < 10; i++) { if(pthread_mutex_destroy(mvec[i]) != 0) abort(); } /* Exit without freeing: mutex locks and array of pointers to locks. mutex pointed by mvec[0] has not been destroyed. */ exit(0); } # gcc -std=c99 test.c -L. -lpvf -DPVF_MALLOC -DPVF_PTHREAD # ./a.out pvf: locking already locked mutex: test.c:32 pvf: locking bogus mutex: test.c:35 pvf: destroying locked mutex: test.c:47 Memory allocations that were never freed: addr=0xbb90b620, test.c:19 addr=0xbb90b580, test.c:19 addr=0xbb90b4e0, test.c:19 addr=0xbb90b440, test.c:19 addr=0xbb90b3a0, test.c:19 addr=0xbb90b300, test.c:19 addr=0xbb90b260, test.c:19 addr=0xbb90b1c0, test.c:19 addr=0xbb90b120, test.c:19 addr=0xbb90b080, test.c:19 addr=0xbb90a040, test.c:13 pthread_mutex_t objects that were never destroyed: addr=0xbb90b080, test.c:23 pthread_rwlock_t objects that were never destroyed: NONE _______________________________________________ opensolaris-code mailing list opensolaris-code@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/opensolaris-code