diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2013-10-15 19:23:32 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2013-10-15 19:23:32 +0000 |
commit | 7fe7df8c1ff94b29f2b1dc9510582270a6920a1c (patch) | |
tree | 54862ead52523ff4dd23dd90b29cd786628c8260 /sys | |
parent | 36467888cc52d0957b3258039a2812b7824c902b (diff) |
Rewrite the awk script that generates the data for option DDB_STRUCT:
- switch to perl for better data structures and (thus) speed
- fix a couple glitches in the interpretation of the stabs output
- compress the strings by putting them in one big array and overlaying
suffixes
- all sizes and offsets are <64k, so use u_short for them
This results in ~60% reduction in the resulting text size and it now
takes less than a second to create on fast platforms.
ok miod@
Diffstat (limited to 'sys')
25 files changed, 425 insertions, 87 deletions
diff --git a/sys/arch/alpha/conf/Makefile.alpha b/sys/arch/alpha/conf/Makefile.alpha index 7b6f4862536..0af5550c3e3 100644 --- a/sys/arch/alpha/conf/Makefile.alpha +++ b/sys/arch/alpha/conf/Makefile.alpha @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.alpha,v 1.81 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.alpha,v 1.82 2013/10/15 19:23:25 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -132,9 +132,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.s assym.h diff --git a/sys/arch/amd64/conf/Makefile.amd64 b/sys/arch/amd64/conf/Makefile.amd64 index acec5f7ac24..cc36603c8f0 100644 --- a/sys/arch/amd64/conf/Makefile.amd64 +++ b/sys/arch/amd64/conf/Makefile.amd64 @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.amd64,v 1.56 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.amd64,v 1.57 2013/10/15 19:23:25 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -136,9 +136,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.S assym.h @@ -150,10 +150,11 @@ MACHINE_NAME!= uname -n install: install-kernel-${MACHINE_NAME} .if !target(install-kernel-${MACHINE_NAME}}) install-kernel-${MACHINE_NAME}: - rm -f /obsd - ln /bsd /obsd - cp bsd /nbsd - mv /nbsd /bsd + ${SUDO} rm -f /obsd + ${SUDO} ln /bsd /obsd + ${SUDO} cp bsd /nbsd + ${SUDO} mv /nbsd /bsd + cp bsd.gdb /var/crash .endif # pull in the dependency information diff --git a/sys/arch/armish/conf/Makefile.armish b/sys/arch/armish/conf/Makefile.armish index 3fab2617a46..a3556a363ae 100644 --- a/sys/arch/armish/conf/Makefile.armish +++ b/sys/arch/armish/conf/Makefile.armish @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.armish,v 1.46 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.armish,v 1.47 2013/10/15 19:23:25 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -141,9 +141,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o ${_mach}_start.o: ${_machdir}/${_mach}/${_mach}_start.S diff --git a/sys/arch/armv7/conf/Makefile.armv7 b/sys/arch/armv7/conf/Makefile.armv7 index 684267cd716..76c824ad845 100644 --- a/sys/arch/armv7/conf/Makefile.armv7 +++ b/sys/arch/armv7/conf/Makefile.armv7 @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.armv7,v 1.1 2013/09/04 14:38:25 patrick Exp $ +# $OpenBSD: Makefile.armv7,v 1.2 2013/10/15 19:23:26 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -137,9 +137,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o ${_mach}_start.o: ${_machdir}/${_mach}/${_mach}_start.S diff --git a/sys/arch/aviion/conf/Makefile.aviion b/sys/arch/aviion/conf/Makefile.aviion index 4a4c87701dc..3ffef0564e1 100644 --- a/sys/arch/aviion/conf/Makefile.aviion +++ b/sys/arch/aviion/conf/Makefile.aviion @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.aviion,v 1.41 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.aviion,v 1.42 2013/10/15 19:23:26 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -136,9 +136,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.S assym.h diff --git a/sys/arch/hp300/conf/Makefile.hp300 b/sys/arch/hp300/conf/Makefile.hp300 index 7b98bdb2afe..7a5c51bfead 100644 --- a/sys/arch/hp300/conf/Makefile.hp300 +++ b/sys/arch/hp300/conf/Makefile.hp300 @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.hp300,v 1.82 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.hp300,v 1.83 2013/10/15 19:23:26 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -158,9 +158,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.s assym.h diff --git a/sys/arch/hppa/conf/Makefile.hppa b/sys/arch/hppa/conf/Makefile.hppa index 28da337f2db..82cd34630f4 100644 --- a/sys/arch/hppa/conf/Makefile.hppa +++ b/sys/arch/hppa/conf/Makefile.hppa @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.hppa,v 1.73 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.hppa,v 1.74 2013/10/15 19:23:26 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -142,9 +142,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.S assym.h diff --git a/sys/arch/hppa64/conf/Makefile.hppa64 b/sys/arch/hppa64/conf/Makefile.hppa64 index b11aae79d99..52e0f02b57e 100644 --- a/sys/arch/hppa64/conf/Makefile.hppa64 +++ b/sys/arch/hppa64/conf/Makefile.hppa64 @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.hppa64,v 1.45 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.hppa64,v 1.46 2013/10/15 19:23:27 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -134,9 +134,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.S assym.h diff --git a/sys/arch/i386/conf/Makefile.i386 b/sys/arch/i386/conf/Makefile.i386 index ac6643390a9..6c36f7fbe54 100644 --- a/sys/arch/i386/conf/Makefile.i386 +++ b/sys/arch/i386/conf/Makefile.i386 @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.i386,v 1.87 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.i386,v 1.88 2013/10/15 19:23:27 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -138,9 +138,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.s assym.h diff --git a/sys/arch/landisk/conf/Makefile.landisk b/sys/arch/landisk/conf/Makefile.landisk index 608d97d929a..5cc93316c04 100644 --- a/sys/arch/landisk/conf/Makefile.landisk +++ b/sys/arch/landisk/conf/Makefile.landisk @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.landisk,v 1.48 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.landisk,v 1.49 2013/10/15 19:23:27 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -132,9 +132,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.S assym.h diff --git a/sys/arch/loongson/conf/Makefile.loongson b/sys/arch/loongson/conf/Makefile.loongson index c7d14b251f3..d7743d7a6ec 100644 --- a/sys/arch/loongson/conf/Makefile.loongson +++ b/sys/arch/loongson/conf/Makefile.loongson @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.loongson,v 1.38 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.loongson,v 1.39 2013/10/15 19:23:28 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -144,9 +144,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.S assym.h diff --git a/sys/arch/luna88k/conf/Makefile.luna88k b/sys/arch/luna88k/conf/Makefile.luna88k index e6b42c5ecda..e64dd31895b 100644 --- a/sys/arch/luna88k/conf/Makefile.luna88k +++ b/sys/arch/luna88k/conf/Makefile.luna88k @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.luna88k,v 1.48 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.luna88k,v 1.49 2013/10/15 19:23:28 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -142,9 +142,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.S assym.h diff --git a/sys/arch/macppc/conf/Makefile.macppc b/sys/arch/macppc/conf/Makefile.macppc index fda9e6affcf..c94643d7ce8 100644 --- a/sys/arch/macppc/conf/Makefile.macppc +++ b/sys/arch/macppc/conf/Makefile.macppc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.macppc,v 1.66 2013/03/30 07:25:20 tedu Exp $ +# $OpenBSD: Makefile.macppc,v 1.67 2013/10/15 19:23:28 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -132,9 +132,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.S assym.h diff --git a/sys/arch/mvme68k/conf/Makefile.mvme68k b/sys/arch/mvme68k/conf/Makefile.mvme68k index 7a23e89fe17..bd08d501929 100644 --- a/sys/arch/mvme68k/conf/Makefile.mvme68k +++ b/sys/arch/mvme68k/conf/Makefile.mvme68k @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.mvme68k,v 1.68 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.mvme68k,v 1.69 2013/10/15 19:23:28 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -135,9 +135,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.s assym.h diff --git a/sys/arch/mvme88k/conf/Makefile.mvme88k b/sys/arch/mvme88k/conf/Makefile.mvme88k index 83570c8aee6..5c71ac13f9e 100644 --- a/sys/arch/mvme88k/conf/Makefile.mvme88k +++ b/sys/arch/mvme88k/conf/Makefile.mvme88k @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.mvme88k,v 1.78 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.mvme88k,v 1.79 2013/10/15 19:23:29 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -132,9 +132,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.S assym.h diff --git a/sys/arch/octeon/conf/Makefile.octeon b/sys/arch/octeon/conf/Makefile.octeon index 2c344a249c9..f057e6ba4b6 100644 --- a/sys/arch/octeon/conf/Makefile.octeon +++ b/sys/arch/octeon/conf/Makefile.octeon @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.octeon,v 1.14 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.octeon,v 1.15 2013/10/15 19:23:29 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -144,9 +144,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.S assym.h diff --git a/sys/arch/sgi/conf/Makefile.sgi b/sys/arch/sgi/conf/Makefile.sgi index 77254b68112..c3946b2e53c 100644 --- a/sys/arch/sgi/conf/Makefile.sgi +++ b/sys/arch/sgi/conf/Makefile.sgi @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.sgi,v 1.61 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.sgi,v 1.62 2013/10/15 19:23:29 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -144,9 +144,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.S assym.h diff --git a/sys/arch/socppc/conf/Makefile.socppc b/sys/arch/socppc/conf/Makefile.socppc index d6d05f205be..c8ab05671f2 100644 --- a/sys/arch/socppc/conf/Makefile.socppc +++ b/sys/arch/socppc/conf/Makefile.socppc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.socppc,v 1.37 2013/03/30 07:25:20 tedu Exp $ +# $OpenBSD: Makefile.socppc,v 1.38 2013/10/15 19:23:30 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -132,9 +132,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.S assym.h diff --git a/sys/arch/solbourne/conf/Makefile.solbourne b/sys/arch/solbourne/conf/Makefile.solbourne index 2db1cb5c673..56949551b66 100644 --- a/sys/arch/solbourne/conf/Makefile.solbourne +++ b/sys/arch/solbourne/conf/Makefile.solbourne @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.solbourne,v 1.41 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.solbourne,v 1.42 2013/10/15 19:23:30 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -133,9 +133,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.s assym.h diff --git a/sys/arch/sparc/conf/Makefile.sparc b/sys/arch/sparc/conf/Makefile.sparc index 4fb18aa8a63..be2e25c9f8f 100644 --- a/sys/arch/sparc/conf/Makefile.sparc +++ b/sys/arch/sparc/conf/Makefile.sparc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.sparc,v 1.77 2013/06/23 20:33:51 miod Exp $ +# $OpenBSD: Makefile.sparc,v 1.78 2013/10/15 19:23:30 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -135,9 +135,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.s assym.h diff --git a/sys/arch/sparc64/conf/Makefile.sparc64 b/sys/arch/sparc64/conf/Makefile.sparc64 index ba84672da9f..603b9743013 100644 --- a/sys/arch/sparc64/conf/Makefile.sparc64 +++ b/sys/arch/sparc64/conf/Makefile.sparc64 @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.sparc64,v 1.66 2013/08/16 19:52:08 kettenis Exp $ +# $OpenBSD: Makefile.sparc64,v 1.67 2013/10/15 19:23:31 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -132,9 +132,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.s assym.h diff --git a/sys/arch/vax/conf/Makefile.vax b/sys/arch/vax/conf/Makefile.vax index a20261c72c2..1dab76a33b2 100644 --- a/sys/arch/vax/conf/Makefile.vax +++ b/sys/arch/vax/conf/Makefile.vax @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.vax,v 1.69 2013/07/05 21:11:57 miod Exp $ +# $OpenBSD: Makefile.vax,v 1.70 2013/10/15 19:23:31 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -133,9 +133,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o locore.o: ${_machdir}/${_mach}/locore.S assym.h diff --git a/sys/arch/zaurus/conf/Makefile.zaurus b/sys/arch/zaurus/conf/Makefile.zaurus index 50472d86f63..1fbcf7feb2d 100644 --- a/sys/arch/zaurus/conf/Makefile.zaurus +++ b/sys/arch/zaurus/conf/Makefile.zaurus @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.zaurus,v 1.48 2013/06/23 20:33:52 miod Exp $ +# $OpenBSD: Makefile.zaurus,v 1.49 2013/10/15 19:23:31 guenther Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -137,9 +137,9 @@ depend: tags: @echo "see $S/kern/Makefile for tags" -db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk +db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.pl ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c - objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ + objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@ rm -f db_structinfo.o ${_mach}_start.o: ${_machdir}/${_mach}/${_mach}_start.S diff --git a/sys/ddb/db_struct.c b/sys/ddb/db_struct.c index 373cd2c53eb..e575d2923f2 100644 --- a/sys/ddb/db_struct.c +++ b/sys/ddb/db_struct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_struct.c,v 1.1 2009/08/09 23:04:49 miod Exp $ */ +/* $OpenBSD: db_struct.c,v 1.2 2013/10/15 19:23:24 guenther Exp $ */ /* * Copyright (c) 2009 Miodrag Vallat. @@ -60,17 +60,17 @@ db_struct_print_field(uint fidx, int flags, db_expr_t baseaddr) if (ISSET(flags, DBSP_STRUCT_NAME)) { struc = &ddb_struct_info[field->sidx]; - namelen = strlen(struc->name); - db_printf("%-30s ", struc->name); + namelen = strlen(ddb_structfield_strings + struc->name); + db_printf("%-30s ", ddb_structfield_strings + struc->name); if (namelen > 30) basecol += namelen + 1; else basecol += 30 + 1; } - namelen = strlen(field->name); + namelen = strlen(ddb_structfield_strings + field->name); if (field->nitems == 1) { - db_printf("%-30s ", field->name); + db_printf("%-30s ", ddb_structfield_strings + field->name); if (namelen > 30) basecol += namelen + 1; else @@ -83,11 +83,14 @@ db_struct_print_field(uint fidx, int flags, db_expr_t baseaddr) tmp /= 10; } if (namelen >= width) { - db_printf("%s[%zu] ", field->name, field->nitems); + db_printf("%s[%hu] ", + ddb_structfield_strings + field->name, + field->nitems); basecol += namelen + (30 - width) + 1; } else { - db_printf("%s[%zu]%*s ", field->name, field->nitems, - width - (int)namelen, ""); + db_printf("%s[%hu]%*s ", + ddb_structfield_strings + field->name, + field->nitems, width - (int)namelen, ""); /* namelen + (30-width) + (width-namelen) + 1 */ basecol += 30 + 1; } @@ -97,7 +100,7 @@ db_struct_print_field(uint fidx, int flags, db_expr_t baseaddr) db_printf("bitfield"); /* basecol irrelevant from there on */ } else { - snprintf(tmpfmt, sizeof tmpfmt, "%zu", field->size); + snprintf(tmpfmt, sizeof tmpfmt, "%hu", field->size); basecol += strlen(tmpfmt) + 1; db_printf("%s ", tmpfmt); } @@ -176,7 +179,7 @@ db_struct_offset_cmd(db_expr_t addr, int have_addr, db_expr_t count, { db_expr_t offset = 0; const struct ddb_field_offsets *field; - const uint *fidx; + const u_short *fidx; uint oidx; int width; char tmpfmt[28]; @@ -209,7 +212,7 @@ db_struct_offset_cmd(db_expr_t addr, int have_addr, db_expr_t count, } db_printf("%-30s %-30s size\n", "struct", "member"); - for (fidx = field->list; *fidx != 0; fidx++) + for (fidx = ddb_fields_by_offset + field->list; *fidx != 0; fidx++) db_struct_print_field(*fidx, DBSP_STRUCT_NAME, 0); } @@ -238,7 +241,8 @@ db_struct_layout_cmd(db_expr_t addr, int have_addr, db_expr_t count, for (struc = ddb_struct_info, sidx = 0; sidx < NSTRUCT; struc++, sidx++) - if (strcmp(struc->name, db_tok_string) == 0) + if (strcmp(ddb_structfield_strings + struc->name, + db_tok_string) == 0) break; if (sidx == NSTRUCT) { @@ -264,8 +268,8 @@ db_struct_layout_cmd(db_expr_t addr, int have_addr, db_expr_t count, * Display the structure contents. */ - db_printf("struct %s at %p (%zu bytes)\n", struc->name, (vaddr_t)addr, - struc->size); + db_printf("struct %s at %p (%hu bytes)\n", + ddb_structfield_strings + struc->name, (void *)addr, struc->size); for (fidx = struc->fmin; fidx <= struc->fmax; fidx++) db_struct_print_field(fidx, DBSP_VALUE, addr); } diff --git a/sys/ddb/parse_structinfo.pl b/sys/ddb/parse_structinfo.pl new file mode 100755 index 00000000000..225e0cadf95 --- /dev/null +++ b/sys/ddb/parse_structinfo.pl @@ -0,0 +1,333 @@ +#!/usr/bin/perl +# $OpenBSD: parse_structinfo.pl,v 1.1 2013/10/15 19:23:24 guenther Exp $ +# +# Copyright (c) 2009 Miodrag Vallat. +# Copyright (c) 2013 Philip Guenther. +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +# This ugly script parses the output of objdump -g in order to extract +# structure layout information, to be used by ddb. +# +# The output of this script is the following static data: +# - for each struct: +# - its name +# - its size (individual element size if an array) +# - the number of elements in the array (1 if not) +# - its first and last field indexes +# - for each field: +# - its name +# - its offset and size +# - the index of the struct it is member of +# This allows fast struct -> field information retrieval. +# +# To retrieve information from a field size or offset, we also output +# the following reverse arrays: +# - for each offset, in ascending order, a variable length list of field +# indexes. +# - for each size, in ascending order, a variable length list of field +# indexes. +# +# The compromise here is that I want to minimize linear searches. Memory +# use is considered secondary, hence the back `pointer' to the struct in the +# fields array. + +use strict; +use warnings; +use integer; + +use constant MAX_COLUMN => 72; + +my $depth = 0; +my $ignore = 0; + +my $cur_struct; + +my $max_offs = 0; +my $max_fsize = 0; +my $max_ssize = 0; + +# count of how many times each literal string appears +my %strings; +my @strings_by_len; +sub add_string +{ + my $string = shift; + if ($strings{$string}++ == 0) { + push @{ $strings_by_len[ length $string ] }, $string; + } +} + +my @structs; + +my %offs_to_fields; +my %size_to_fields; +my @fields = ( { + name => "", + offs => 0, + size => 0, + items => 0, + struct => 0, + } ); +sub new_field +{ + my($name, $offs, $size, $items) = @_; + + add_string($name); + push @fields, { + name => $name, + offs => $offs, + size => $size, + items => $items // 1, + struct => scalar(@structs), + }; + $max_offs = $offs if $offs > $max_offs; + $max_fsize = $size if $size > $max_fsize; + push @{ $offs_to_fields{$offs} }, $#fields; + push @{ $size_to_fields{$size} }, $#fields; +} + +while (<>) { + chomp; # strip record separator + if (m!^struct (\w+) \{ /\* size (\d+) !) { + $depth = 1; + $cur_struct = { + name => $1, + size => $2, + fieldmin => scalar(@fields) + }; + next + } + + if (/^};/) { + if ($depth == 0) { + $ignore--; + next + } + $depth = 0; + if (scalar(@fields) == $cur_struct->{fieldmin}) { + # empty struct, ignore it + undef $cur_struct; + next + } + $cur_struct->{fieldmax} = $#fields; + add_string( $cur_struct->{name} ); + $max_ssize = $cur_struct->{size} if $cur_struct->{size} > $max_ssize; + push @structs, $cur_struct; + next + } + + next if /\{.*\}/; # single line enum + + if (/\{/) { + # subcomponent + if ($depth) { + $depth++; + } else { + $ignore++; + } + next + } + + if (/\}/) { + if ($ignore) { + $ignore--; + next + } + $depth--; + next if $depth != 1; + # FALL THROUGH + } + + if (/bitsize (\d+), bitpos (\d+)/) { + next if $ignore; + next if $depth != 1; + + # Bitfields are a PITA... From a ddb point of view, we can't really + # access storage units smaller than a byte. + # So we'll report all bitfields as having size 0, and the + # rounded down byte position where they start. + my $cursize = ($1 % 8) ? 0 : ($1 / 8); + my $curoffs = $2 / 8; + + # Try and gather the field name. + # The most common case: not a function pointer or array + if (m!\s\**(\w+);\s/\* bitsize!) { + new_field($1, $curoffs, $cursize); + next + } + + # How about a function pointer? + if (m!\s\**\(\*+(\w+)\) \(/\* unknown \*/\);\s/\* bitsize!) { + new_field($1, $curoffs, $cursize); + next + } + + # Maybe it's an array + if (m!\s\**([][:\w]+);\s/\* bitsize!) { + my $name = $1; + my $items = 1; + while ($name =~ s/\[(\d+)\]:\w+//) { + $items *= $1; + } + new_field($name, $curoffs, $cursize / $items, $items); + next + } + + # skip any anonymous unions { + next if m!\}; /\*!; + + # Should be nothing left + print STDERR "unknown member type: $_\n"; + next + } +} + +print <<EOM; +/* + * THIS IS A GENERATED FILE. DO NOT EDIT! + */ + +#include <sys/param.h> +#include <sys/types.h> + +struct ddb_struct_info { + u_short name; + u_short size; + u_short fmin, fmax; +}; +struct ddb_field_info { + u_short name; + u_short sidx; + u_short offs; + u_short size; + u_short nitems; +}; +struct ddb_field_offsets { + u_short offs; + u_short list; +}; +struct ddb_field_sizes { + u_short size; + u_short list; +}; +EOM + +my $prefix = qq(static const char ddb_structfield_strings[] =\n\t"\\0); +my %string_to_offset = ( "" => 0 ); +my $soff = 1; +for (my $len = $#strings_by_len; $len > 0; $len--) { + foreach my $string (@{ $strings_by_len[$len] }) { + next if exists $string_to_offset{$string}; + my $off = $string_to_offset{$string} = $soff; + $soff += $len + 1; # for the NUL + print $prefix, $string; + $prefix = qq(\\0"\n\t"); + + # check for suffixes that are also strings + for (my $o = 1; $o < $len; $o++) { + my $sstr = substr($string, $o); + next unless exists $strings{$sstr}; + next if exists $string_to_offset{$sstr}; + $string_to_offset{$sstr} = $off + $o; + #print STDERR "found $sstr inside $string\n"; + } + } +} +print qq(";\n); + +sub resolve_string +{ + my $string = shift; + if (! exists $string_to_offset{$string}) { + die "no mapping for $string"; + } + return $string_to_offset{$string}; +} + +# Check for overflow and, if so, print some stats +if ($soff > 65535 || $max_offs > 65535 || $max_fsize > 65535 || + $max_ssize > 65535 || @structs > 65535 || @fields > 65535) { + print STDERR <<EOM; +ERROR: value of range of u_short Time to change types? + +max string offset: $soff +max field offset: $max_offs +max field size: $max_fsize +max struct size: $max_ssize +number of structs: ${\scalar(@structs)} +number of fields: ${\scalar(@fields)} +EOM + exit 1 +} + + +print "#define NSTRUCT ", scalar(@structs), "\n"; +print "static const struct ddb_struct_info ddb_struct_info[NSTRUCT] = {\n"; + +foreach my $s (@structs) { + my $name = resolve_string($s->{name}); + print "\t{ ", + join(", ", $name, @{$s}{qw( size fieldmin fieldmax )}), + " },\n"; +} +printf "};\n\n"; + +print "#define NFIELD ", scalar(@fields), "\n"; +print "static const struct ddb_field_info ddb_field_info[NFIELD] = {\n"; +foreach my $f (@fields) { + my $name = resolve_string($f->{name}); + print "\t{ ", + join(", ", $name, @{$f}{qw( struct offs size items )}), + " },\n"; +} +printf "};\n\n"; + + +# Given a mapping from values to fields that have that value, generate +# two C arrays, one containing lists of fields which each value, in order, +# the other indexing into that one for each value. I.e., to get the +# fields that have a given value, find the value in the second array and +# then iterate from where that points into the first array until you hit +# an entry with field==0. +sub print_reverse_mapping +{ + my($prefix, $map, $max) = @_; + print "static const u_short ddb_fields_by_${prefix}[] = {"; + my @heads; + my $w = 0; + foreach my $val (sort { $a <=> $b } keys %$map) { + push @heads, [$val, $w]; + foreach my $field (@{ $map->{$val} }, 0) { + print( ($w++ % 10) == 0 ? "\n\t" : " ", $field, ","); + } + } + print "\n};\n\n"; + print "#define $max ", scalar(@heads), "\n"; + print "static const struct ddb_field_${prefix}s", + " ddb_field_${prefix}s[$max] = {\n"; + foreach my $h (@heads) { + #print "\t{ $h->[0], ddb_fields_by_${prefix} + $h->[1] },\n"; + print "\t{ $h->[0], $h->[1] },\n"; + } + print "};\n"; +} + +# reverse arrays +print_reverse_mapping("offset", \%offs_to_fields, "NOFFS"); +print "\n"; + +# The size->field mapping isn't used by ddb currently, so don't output it +# print_reverse_mapping("size", \%size_to_fields, "NSIZES"); + |