#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "test.h"
extern "C" {
void __tsan_on_report(void *report);
void *__tsan_get_current_report();
int __tsan_get_report_data(void *report, const char **description, int *count,
int *stack_count, int *mop_count, int *loc_count,
int *mutex_count, int *thread_count,
int *unique_tid_count, void **sleep_trace,
unsigned long trace_size);
int __tsan_get_report_mop(void *report, unsigned long idx, int *tid,
void **addr, int *size, int *write, int *atomic,
void **trace, unsigned long trace_size);
int __tsan_get_report_thread(void *report, unsigned long idx, int *tid,
uint64_t *os_id, int *running,
const char **name, int *parent_tid, void **trace,
unsigned long trace_size);
}
long my_global;
void *Thread(void *a) {
barrier_wait(&barrier);
my_global = 42;
return NULL;
}
int main() {
barrier_init(&barrier, 2);
fprintf(stderr, "&my_global = %p\n", &my_global);
pthread_t t;
pthread_create(&t, 0, Thread, 0);
my_global = 41;
barrier_wait(&barrier);
pthread_join(t, 0);
fprintf(stderr, "Done.\n");
}
#if (__APPLE__)
__attribute__((weak))
#endif
__attribute__((disable_sanitizer_instrumentation))
extern "C" void
__tsan_on_report(void *report) {
fprintf(stderr, "__tsan_on_report(%p)\n", report);
fprintf(stderr, "__tsan_get_current_report() = %p\n",
__tsan_get_current_report());
const char *description;
int count;
int stack_count, mop_count, loc_count, mutex_count, thread_count,
unique_tid_count;
void *sleep_trace[16] = {0};
__tsan_get_report_data(report, &description, &count, &stack_count, &mop_count,
&loc_count, &mutex_count, &thread_count,
&unique_tid_count, sleep_trace, 16);
fprintf(stderr, "report type = '%s', count = %d\n", description, count);
fprintf(stderr, "mop_count = %d\n", mop_count);
int tid;
void *addr;
int size, write, atomic;
void *trace[16] = {0};
__tsan_get_report_mop(report, 0, &tid, &addr, &size, &write, &atomic, trace,
16);
fprintf(stderr, "tid = %d, addr = %p, size = %d, write = %d, atomic = %d\n",
tid, addr, size, write, atomic);
fprintf(stderr, "trace[0] = %p, trace[1] = %p\n", trace[0], trace[1]);
__tsan_get_report_mop(report, 1, &tid, &addr, &size, &write, &atomic, trace,
16);
fprintf(stderr, "tid = %d, addr = %p, size = %d, write = %d, atomic = %d\n",
tid, addr, size, write, atomic);
fprintf(stderr, "trace[0] = %p, trace[1] = %p\n", trace[0], trace[1]);
fprintf(stderr, "thread_count = %d\n", thread_count);
uint64_t os_id;
int running;
const char *name;
int parent_tid;
__tsan_get_report_thread(report, 0, &tid, &os_id, &running, &name, &parent_tid, trace, 16);
fprintf(stderr, "tid = %d\n", tid);
__tsan_get_report_thread(report, 1, &tid, &os_id, &running, &name, &parent_tid, trace, 16);
fprintf(stderr, "tid = %d\n", tid);
}