diff --git a/Makefile b/Makefile index be1083ea1..e60d129eb 100644 --- a/Makefile +++ b/Makefile @@ -124,6 +124,10 @@ DEPS := $(patsubst %.o,%.d,$(OBJS)) .PHONY: all zdtm test rebuild clean distclean tags cscope \ docs help pie protobuf x86 +ifeq ($(GCOV),1) +%.o $(PROGRAM): override CFLAGS += --coverage +endif + all: pie $(Q) $(MAKE) $(PROGRAM) @@ -180,6 +184,8 @@ clean: $(Q) $(RM) -f ./*.bin $(Q) $(RM) -f ./$(PROGRAM) $(Q) $(RM) -rf ./test/dump/ + $(Q) $(RM) -f ./*.gcov ./*.gcda ./*.gcno + $(Q) $(RM) -rf ./gcov $(Q) $(MAKE) -C protobuf/ clean $(Q) $(MAKE) -C arch/x86/ clean $(Q) $(MAKE) -C pie/ clean @@ -218,6 +224,17 @@ help: $(E) ' rebuild - Force-rebuild of [*] targets' $(E) ' test - Run zdtm test-suite' +gcov: + $(E) " GCOV" + $(Q) mkdir gcov && \ + cd gcov && \ + cp ../*.gcno ../*.c ../test/root/crtools/ && \ + geninfo --no-checksum --output-filename tproxyd.l.info --no-recursion .. && \ + geninfo --no-checksum --output-filename tproxyd.ns.info --no-recursion ../test/root/crtools && \ + sed -i 's#/test/root/crtools##' tproxyd.ns.info && \ + lcov -a tproxyd.l.info -a tproxyd.ns.info -o tproxyd.info && \ + genhtml -o html tproxyd.info + deps-targets := $(OBJS) $(patsubst %.o,%.s,$(OBJS)) $(patsubst %.o,%.i,$(OBJS)) $(PROGRAM) .DEFAULT_GOAL := all diff --git a/cr-restore.c b/cr-restore.c index 70343baa2..ba4932db3 100644 --- a/cr-restore.c +++ b/cr-restore.c @@ -1702,6 +1702,9 @@ static int sigreturn_prep_xsave_frame(struct thread_restore_args *args, CoreEntr return 0; } +extern void __gcov_flush(void) __attribute__((weak)); +void __gcov_flush(void) {} + static int sigreturn_restore(pid_t pid, CoreEntry *core) { long restore_task_vma_len; @@ -1962,6 +1965,8 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core) close_image_dir(); + __gcov_flush(); + pr_info("task_args: %p\n" "task_args->pid: %d\n" "task_args->nr_threads: %d\n"