From 4911b107dae26150ec87cc31cada0e52f97061d6 Mon Sep 17 00:00:00 2001 From: Cedric Roux <cedric.roux@eurecom.fr> Date: Sun, 1 May 2016 14:10:59 +0200 Subject: [PATCH] instrument X using gcc's -finstrument-functions used to debug locking --- common/utils/T/tracer/gui/Makefile | 3 +++ common/utils/T/tracer/gui/gui.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/common/utils/T/tracer/gui/Makefile b/common/utils/T/tracer/gui/Makefile index cc6a409e75..9552d03d82 100644 --- a/common/utils/T/tracer/gui/Makefile +++ b/common/utils/T/tracer/gui/Makefile @@ -10,6 +10,9 @@ gui.a: $(OBJS) test: test.o gui.a $(CC) -o test $(OBJS) test.o -lX11 -pthread -lm +x.o:x.c + $(CC) $(CFLAGS) -o $@ -c $< -finstrument-functions + %.o: %.c $(CC) $(CFLAGS) -o $@ -c $< diff --git a/common/utils/T/tracer/gui/gui.c b/common/utils/T/tracer/gui/gui.c index ef8640b0de..52e1b1cc74 100644 --- a/common/utils/T/tracer/gui/gui.c +++ b/common/utils/T/tracer/gui/gui.c @@ -5,15 +5,31 @@ #include <stdlib.h> #include <pthread.h> +static volatile int locked = 0; + +void __cyg_profile_func_enter (void *func, void *caller) +{ + if (locked == 0) abort(); + printf("E %p %p %lu\n", func, caller, time(NULL)); +} + +void __cyg_profile_func_exit (void *func, void *caller) +{ + if (locked == 0) abort(); + printf("X %p %p %lu\n", func, caller, time(NULL)); +} + void glock(gui *_gui) { struct gui *g = _gui; if (pthread_mutex_lock(g->lock)) ERR("mutex error\n"); + locked = 1; } void gunlock(gui *_gui) { struct gui *g = _gui; + locked = 0; if (pthread_mutex_unlock(g->lock)) ERR("mutex error\n"); } -- 2.26.2