You can combine +check=bounds:[pointerall] with all other +check options, except for +check=globals (which would be ignored in this case).
Also see the +check=malloc and the +check=stack options for related runtime checks for heap and stack objects.
+check=globals
This option enables runtime checks to detect corruption of global variables, by introducing and checking "guards" between them, at the time of program exit. Setting environment variable RTC_ROUTINE_LEVEL_CHECK will also enable the check whenever a function compiled with this option returns.
For this purpose, the definition of global is extended to be all variables that have static storage duration, including file or namespace scope variables, function scope static variables, and class (or template class) static data members.
+check=lock
This option enables checking of C and C++ user applications that use pthreads. The option reports violations of locking discipline when appropriate locks are not held while accessing shared data by different threads. The check is based on the lockset method for detecting locking discipline violations, as described in the Eraser tool article at http://citeseer.ist.psu.edu/savage97eraser.html.
Note that +check=all does not enable +check=lock. Also note that because +check=lock requires instrumenting each memory access; it can result in a considerable slowdown of the application at runtime. +check=lock also increases the memory consumption of the instrumented application.
The check is performed on each memory access. It detects violations in locking discipline for mutual exclusion locks (mutexes) for applications using posix threads. When the locking discipline is violated, it is reported along with the line number and the address for which the violation occurs. Consider the following code example:
#include <stdio.h> #include <unistd.h> #include <pthread.h> unsigned long things_done=0;
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER; void *thread1(void *arg) {
pthread_mutex_lock(&mutex1); things_done++; pthread_mutex_unlock(&mutex1); return 0;
}
void *thread2(void *arg) { pthread_mutex_lock(&mutex2); things_done++; pthread_mutex_unlock(&mutex2); return 0;
}
int main(int argc, char *argv[])
{
pthread_t th1, th2;
pthread_create(&th1, NULL, thread1, (void*)NULL ); pthread_mutex_lock(&mutex1);
things_done++;
pthread_mutex_unlock(&mutex1);
pthread_create(&th2, NULL, thread2, (void*)NULL );
10