This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC 4/7] Share code in initialize_tdesc_ functions

[Resend it as the message is too large, and mail list doesn't accept
it.  Compress the patch and put it in attachment.]

We define target description features in .xml files, and compose
target descriptions of different features in .xml too.  They are
used to generated .c files and these .c files are included into
GDB.  Each feature may exist in multiple target descriptions, for
example, feature avx exists in 4 different i386-linux target
descriptions, so that each .c file generated from these 4 target
descriptions has a copy of code for this feature, like this,

  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
  tdesc_create_reg (feature, "ymm0h", 42, 1, NULL, 128, "uint128");
  tdesc_create_reg (feature, "ymm1h", 43, 1, NULL, 128, "uint128");

that is the code duplication.

This patch moves the code for each feature into a function, and
each target description just call the function for that feature.
it becomes,

  #ifndef _ORG_GNU_GDB_I386_AVX
  #define _ORG_GNU_GDB_I386_AVX
  static void
  create_feature_org_gnu_gdb_i386_avx (struct target_desc *result)
    struct tdesc_feature *feature;

    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
    tdesc_create_reg (feature, "ymm0h", 42, 1, NULL, 128, "uint128");

  static void
  initialize_tdesc_i386_avx_mpx_avx512_pku_linux (void)
    create_feature_org_gnu_gdb_i386_avx (result);

So far, everything looks simple, however, two things make it more

 1) different target features have the same feature name, like
    "org.gnu.gdb.power.core" and "org.gnu.gdb.mips.cpu", so we can't
    define only one function for "org.gnu.gdb.power.core",
 2) the register number of target feature (tdesc_reg::target_regnum)
    varies in different target descriptions, because the register
    number is allocated sequentially feature by feature within a
    target description, so we can't use the c function for a feature
    generated in one target description for some other target

In order to address 1), function tdesc_feature_unique_name is added
in this patch, which returns the unique name for each feature, even
these feature name are the same.  To address 2), this patch removes
the constant number in generated c functions, instead, use variable
"regnum", and get it passed from the c functions.

The benefits of doing this are two-folded,

 - remove the duplication, there is only one copy of code for each
   feature.  With all targets enabled, gdb size is smaller,

$ size ./gdb
   text    data     bss     dec     hex filename
23823773        2395640  364776 26584189        195a47d ./gdb

with the patch applied,

   text    data     bss     dec     hex filename
23552417        2395648  364808 26312873        19180a9 ./gdb

 - the composition of features can be more flexible, which will be
   demonstrated in the following patch,


2017-05-09  Yao Qi  <>

	* target-descriptions.c: Include string and algorithm.
	(struct tdesc_reg) <target_regnum>: Add comments.
	(tdesc_reg_equals): Update.
	(tdesc_remote_register_number): Call abs.
	(tdesc_feature_unique_name): New function.
	(maint_print_c_tdesc_cmd): Print function for each feature.
	* xml-tdesc.c (tdesc_start_reg): Set regnum negative if the
	value is from "regnum" attribute.
	(tdesc_start_reg): Call abs.

	* features/aarch64.c: Regenerated.
	* features/arc-arcompact.c: Regenerated.
	* features/arc-v2.c: Regenerated.
	* features/arm/arm-with-iwmmxt.c: Regenerated.
	* features/arm/arm-with-m-fpa-layout.c: Regenerated.
	* features/arm/arm-with-m-vfp-d16.c: Regenerated.
	* features/arm/arm-with-m.c: Regenerated.
	* features/arm/arm-with-neon.c: Regenerated.
	* features/arm/arm-with-vfpv2.c: Regenerated.
	* features/arm/arm-with-vfpv3.c: Regenerated.
	* features/i386/amd64-avx-avx512-linux.c: Regenerated.
	* features/i386/amd64-avx-avx512.c: Regenerated.
	* features/i386/amd64-avx-linux.c: Regenerated.
	* features/i386/amd64-avx-mpx-avx512-pku-linux.c: Regenerated.
	* features/i386/amd64-avx-mpx-avx512-pku.c: Regenerated.
	* features/i386/amd64-avx-mpx-linux.c: Regenerated.
	* features/i386/amd64-avx-mpx.c: Regenerated.
	* features/i386/amd64-avx.c: Regenerated.
	* features/i386/amd64-linux.c: Regenerated.
	* features/i386/amd64-mpx-linux.c: Regenerated.
	* features/i386/amd64-mpx.c: Regenerated.
	* features/i386/amd64.c: Regenerated.
	* features/i386/i386-avx-avx512-linux.c: Regenerated.
	* features/i386/i386-avx-avx512.c: Regenerated.
	* features/i386/i386-avx-linux.c: Regenerated.
	* features/i386/i386-avx-mpx-avx512-pku-linux.c: Regenerated.
	* features/i386/i386-avx-mpx-avx512-pku.c: Regenerated.
	* features/i386/i386-avx-mpx-linux.c: Regenerated.
	* features/i386/i386-avx-mpx.c: Regenerated.
	* features/i386/i386-avx.c: Regenerated.
	* features/i386/i386-linux.c: Regenerated.
	* features/i386/i386-mmx-linux.c: Regenerated.
	* features/i386/i386-mmx.c: Regenerated.
	* features/i386/i386-mpx-linux.c: Regenerated.
	* features/i386/i386-mpx.c: Regenerated.
	* features/i386/i386.c: Regenerated.
	* features/i386/x32-avx-avx512-linux.c: Regenerated.
	* features/i386/x32-avx-avx512.c: Regenerated.
	* features/i386/x32-avx-linux.c: Regenerated.
	* features/i386/x32-avx.c: Regenerated.
	* features/i386/x32-linux.c: Regenerated.
	* features/i386/x32.c: Regenerated.
	* features/microblaze-with-stack-protect.c: Regenerated.
	* features/microblaze.c: Regenerated.
	* features/mips-dsp-linux.c: Regenerated.
	* features/mips-linux.c: Regenerated.
	* features/mips64-dsp-linux.c: Regenerated.
	* features/mips64-linux.c: Regenerated.
	* features/nds32.c: Regenerated.
	* features/nios2-linux.c: Regenerated.
	* features/nios2.c: Regenerated.
	* features/rs6000/powerpc-32.c: Regenerated.
	* features/rs6000/powerpc-32l.c: Regenerated.
	* features/rs6000/powerpc-403.c: Regenerated.
	* features/rs6000/powerpc-403gc.c: Regenerated.
	* features/rs6000/powerpc-405.c: Regenerated.
	* features/rs6000/powerpc-505.c: Regenerated.
	* features/rs6000/powerpc-601.c: Regenerated.
	* features/rs6000/powerpc-602.c: Regenerated.
	* features/rs6000/powerpc-603.c: Regenerated.
	* features/rs6000/powerpc-604.c: Regenerated.
	* features/rs6000/powerpc-64.c: Regenerated.
	* features/rs6000/powerpc-64l.c: Regenerated.
	* features/rs6000/powerpc-7400.c: Regenerated.
	* features/rs6000/powerpc-750.c: Regenerated.
	* features/rs6000/powerpc-860.c: Regenerated.
	* features/rs6000/powerpc-altivec32.c: Regenerated.
	* features/rs6000/powerpc-altivec32l.c: Regenerated.
	* features/rs6000/powerpc-altivec64.c: Regenerated.
	* features/rs6000/powerpc-altivec64l.c: Regenerated.
	* features/rs6000/powerpc-cell32l.c: Regenerated.
	* features/rs6000/powerpc-cell64l.c: Regenerated.
	* features/rs6000/powerpc-e500.c: Regenerated.
	* features/rs6000/powerpc-e500l.c: Regenerated.
	* features/rs6000/powerpc-isa205-32l.c: Regenerated.
	* features/rs6000/powerpc-isa205-64l.c: Regenerated.
	* features/rs6000/powerpc-isa205-altivec32l.c: Regenerated.
	* features/rs6000/powerpc-isa205-altivec64l.c: Regenerated.
	* features/rs6000/powerpc-isa205-vsx32l.c: Regenerated.
	* features/rs6000/powerpc-isa205-vsx64l.c: Regenerated.
	* features/rs6000/powerpc-vsx32.c: Regenerated.
	* features/rs6000/powerpc-vsx32l.c: Regenerated.
	* features/rs6000/powerpc-vsx64.c: Regenerated.
	* features/rs6000/powerpc-vsx64l.c: Regenerated.
	* features/rs6000/rs6000.c: Regenerated.
	* features/s390-linux32.c: Regenerated.
	* features/s390-linux32v1.c: Regenerated.
	* features/s390-linux32v2.c: Regenerated.
	* features/s390-linux64.c: Regenerated.
	* features/s390-linux64v1.c: Regenerated.
	* features/s390-linux64v2.c: Regenerated.
	* features/s390-te-linux64.c: Regenerated.
	* features/s390-tevx-linux64.c: Regenerated.
	* features/s390-vx-linux64.c: Regenerated.
	* features/s390x-linux64.c: Regenerated.
	* features/s390x-linux64v1.c: Regenerated.
	* features/s390x-linux64v2.c: Regenerated.
	* features/s390x-te-linux64.c: Regenerated.
	* features/s390x-tevx-linux64.c: Regenerated.
	* features/s390x-vx-linux64.c: Regenerated.
	* features/tic6x-c62x-linux.c: Regenerated.
	* features/tic6x-c62x.c: Regenerated.
	* features/tic6x-c64x-linux.c: Regenerated.
	* features/tic6x-c64x.c: Regenerated.
	* features/tic6x-c64xp-linux.c: Regenerated.
	* features/tic6x-c64xp.c: Regenerated.


2017-05-10  Yao Qi  <>

	* gdb.xml/maint_print_struct.exp: Update.

Attachment: 4.patch.tar.gz
Description: application/gzip

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]