diff -urbN linux-2.4.17-v/Documentation/Configure.help linux-2.4.17-gcov/Documentation/Configure.help --- linux-2.4.17-v/Documentation/Configure.help Fri Dec 21 12:41:53 2001 +++ linux-2.4.17-gcov/Documentation/Configure.help Wed Jan 30 13:30:21 2002 @@ -24208,7 +24208,6 @@ of these is normally used as the system console. If in doubt, press "y". - Use LinuxSH standard BIOS CONFIG_SH_STANDARD_BIOS Say Y here if your target has the gdb-sh-stub @@ -24236,6 +24235,23 @@ If you are using GDB for remote debugging over a serial port and would like kernel messages to be formatted into GDB $O packets so that GDB prints them as program output, say 'Y'. + +Include GCOV coverage profiling +CONFIG_GCOV_PROFILE + Provide infrastructure for coverage support for the kernel. This + will not compile the kernel by default with the necessary flags. + To obtain coverage information for the entire kernel, one should + enable the subsequent option (Profile entire kernel). If only + particular files or directories of the kernel are desired, then + one must provide the following compile options for such targets: + "-fprofile-arcs -ftest-coverage" in the CFLAGS. To obtain + access to the coverage data one must insmod the gcov-prof kernel + module. + +Include GCOV kernel profiler +CONFIG_GCOV_ALL + If you say Y here, it will compile the entire kernel with coverage + option enabled. # # A couple of things I keep forgetting: diff -urbN linux-2.4.17-v/Makefile linux-2.4.17-gcov/Makefile --- linux-2.4.17-v/Makefile Wed Jan 30 09:45:31 2002 +++ linux-2.4.17-gcov/Makefile Wed Jan 30 13:30:21 2002 @@ -1,7 +1,7 @@ VERSION = 2 PATCHLEVEL = 4 SUBLEVEL = 17 -EXTRAVERSION = +EXTRAVERSION =-gcov KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) @@ -18,7 +18,7 @@ HOSTCC = gcc HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer - +LPROF_FLAGS = -fprofile-arcs -ftest-coverage CROSS_COMPILE = # @@ -296,7 +296,11 @@ linuxsubdirs: $(patsubst %, _dir_%, $(SUBDIRS)) $(patsubst %, _dir_%, $(SUBDIRS)) : dummy include/linux/version.h include/config/MARKER +ifdef CONFIG_GCOV_ALL + $(MAKE) CFLAGS="$(CFLAGS) $(LPROF_FLAGS) $(CFLAGS_KERNEL)" -C $(patsubst _dir_%, %, $@) +else $(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" -C $(patsubst _dir_%, %, $@) +endif $(TOPDIR)/include/linux/version.h: include/linux/version.h $(TOPDIR)/include/linux/compile.h: include/linux/compile.h @@ -412,7 +416,7 @@ endif clean: archclean - find . \( -name '*.[oas]' -o -name core -o -name '.*.flags' \) -type f -print \ + find . \( -name '*.[oas]' -o -name core -o -name '.*.flags' -o -name '*.bb' -o -name '*.bbg' \) -type f -print \ | grep -v lxdialog/ | xargs rm -f rm -f $(CLEAN_FILES) rm -rf $(CLEAN_DIRS) @@ -428,7 +432,7 @@ rm -f core `find . \( -not -type d \) -and \ \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \ - -o -name '.*.rej' -o -name '.SUMS' -o -size 0 \) -type f -print` TAGS tags + -o -name '.*.rej' -o -name '.SUMS' -o -name '*.bb' -o -name '*.bbg' -o -size 0 \) -type f -print` TAGS tags backup: mrproper cd .. && tar cf - linux/ | gzip -9 > backup.gz diff -urbN linux-2.4.17-v/arch/i386/config.in linux-2.4.17-gcov/arch/i386/config.in --- linux-2.4.17-v/arch/i386/config.in Fri Dec 21 12:41:53 2001 +++ linux-2.4.17-gcov/arch/i386/config.in Wed Jan 30 13:30:21 2002 @@ -414,5 +414,14 @@ bool ' Spinlock debugging' CONFIG_DEBUG_SPINLOCK bool ' Verbose BUG() reporting (adds 70K)' CONFIG_DEBUG_BUGVERBOSE fi +endmenu + +mainmenu_option next_comment +comment 'GCOV coverage profiling' + +bool 'GCOV kernel' CONFIG_GCOV_PROFILE +if [ "$CONFIG_GCOV_PROFILE" != "n" ]; then + bool ' GCOV kernel profiler' CONFIG_GCOV_ALL +fi endmenu diff -urbN linux-2.4.17-v/arch/i386/kernel/head.S linux-2.4.17-gcov/arch/i386/kernel/head.S --- linux-2.4.17-v/arch/i386/kernel/head.S Wed Jun 20 14:00:53 2001 +++ linux-2.4.17-gcov/arch/i386/kernel/head.S Wed Jan 30 13:30:21 2002 @@ -455,3 +455,10 @@ */ .section .text.lock ENTRY(stext_lock) + +#ifdef CONFIG_GCOV_PROFILE +.section ".ctors","aw" +.globl __CTOR_LIST__ +.type __CTOR_LIST__,@object +__CTOR_LIST__: +#endif diff -urbN linux-2.4.17-v/kernel/Makefile linux-2.4.17-gcov/kernel/Makefile --- linux-2.4.17-v/kernel/Makefile Mon Sep 17 00:22:40 2001 +++ linux-2.4.17-gcov/kernel/Makefile Fri Feb 1 09:32:29 2002 @@ -9,6 +9,7 @@ O_TARGET := kernel.o + export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o printk.o obj-y = sched.o dma.o fork.o exec_domain.o panic.o printk.o \ @@ -16,10 +17,16 @@ sysctl.o acct.o capability.o ptrace.o timer.o user.o \ signal.o sys.o kmod.o context.o +ifdef CONFIG_GCOV_PROFILE +obj-y += gcov.o +CFLAGS_gcov.o := -DGCOV_PATH='"$(TOPDIR)"' +endif + obj-$(CONFIG_UID16) += uid16.o obj-$(CONFIG_MODULES) += ksyms.o obj-$(CONFIG_PM) += pm.o + ifneq ($(CONFIG_IA64),y) # According to Alan Modra , the -fno-omit-frame-pointer is # needed for x86 only. Why this used to be enabled for all architectures is beyond @@ -29,4 +36,7 @@ CFLAGS_sched.o := $(PROFILING) -fno-omit-frame-pointer endif + include $(TOPDIR)/Rules.make + + diff -urbN linux-2.4.17-v/kernel/gcov.c linux-2.4.17-gcov/kernel/gcov.c --- linux-2.4.17-v/kernel/gcov.c Wed Dec 31 19:00:00 1969 +++ linux-2.4.17-gcov/kernel/gcov.c Fri Feb 1 14:47:25 2002 @@ -0,0 +1,59 @@ +/* + * linux/kernel/gcov.c + * + * Kernel basic block profile / coverage data + * + * (C) 2002 by Hubertus Franke, IBM T.J.Watson Research Center + * This software is distributed under the terms of GNU GPL + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +struct bb +{ + long zero_word; + const char *filename; + long *counts; + long ncounts; + struct bb *next; + const unsigned long *addresses; + + /* Older GCC's did not emit these fields. */ + long nwords; + const char **functions; + const long *line_nums; + const char **filenames; + char *flags; +}; + +struct bb *bb_head; + +#ifdef GCOV_PATH +char *gcov_kernelpath = GCOV_PATH; +#else +char *gcov_kernelpath = __FILE__; +#endif + + +void +__bb_init_func (struct bb *blocks) +{ + printk("bb_init_func<%s> %ld\n", blocks->filename,blocks->ncounts); + if (blocks->zero_word) + return; + + /* Set up linked list. */ + blocks->zero_word = 1; + blocks->next = bb_head; + bb_head = blocks; +} + diff -urbN linux-2.4.17-v/kernel/ksyms.c linux-2.4.17-gcov/kernel/ksyms.c --- linux-2.4.17-v/kernel/ksyms.c Fri Dec 21 12:42:04 2001 +++ linux-2.4.17-gcov/kernel/ksyms.c Wed Jan 30 18:27:27 2002 @@ -65,6 +65,13 @@ extern void free_dma(unsigned int dmanr); extern spinlock_t dma_spin_lock; +#ifdef CONFIG_GCOV_PROFILE +extern struct bb *bb_head; +extern void __bb_init_func(struct bb *blocks); +extern long __CTOR_LIST__; +extern char *gcov_kernelpath; +#endif + #ifdef CONFIG_MODVERSIONS const struct module_symbol __export_Using_Versions __attribute__((section("__ksymtab"))) = { @@ -559,3 +566,10 @@ EXPORT_SYMBOL(tasklist_lock); EXPORT_SYMBOL(pidhash); + +#ifdef CONFIG_GCOV_PROFILE +EXPORT_SYMBOL(bb_head); +EXPORT_SYMBOL(__bb_init_func); +EXPORT_SYMBOL(__CTOR_LIST__); +EXPORT_SYMBOL(gcov_kernelpath); +#endif