[v2] gdbserver: Suffix generated C files with -generated

Message ID 20170331145554.26349-1-simon.marchi@ericsson.com
State New, archived
Headers

Commit Message

Simon Marchi March 31, 2017, 2:55 p.m. UTC
  From: Simon Marchi <simon.marchi@polymtl.ca>

I noticed that there were some missing files in gdbserver's gitignore
(some generated register format .c files).  Of course the easy fix would
be to add those files to .gitignore, but I think we can do a better job,
so that we don't have to worry about adding generated files to
.gitignore or the clean Makefile target.

I suggest naming all generated source files -generated.c.  This way, we
can use a single rule in .gitignore and do a "rm -f *-generated.c" to
clean them up.

New in v2:

  - Don't rename version.o and xml-builtin.o

gdb/gdbserver/ChangeLog:

	* .gitignore: Remove generated files, replace with wildcard.
	* (clean): Replace removal of generated files with wildcard.
	(version.c): Replace with...
	(version-generated.c): ...this.
	(xml-builtin.c): Replace with...
	(xml-builtin-generated.c): ...this.
	(%-ipa.o: %-generated.c, %.o: %-generated.c): New rules.
	(%.c: *regformats*): Replace with...
	(%-generated.c: *regformats*): ...this.
---
 gdb/gdbserver/.gitignore  | 18 +------------
 gdb/gdbserver/Makefile.in | 68 ++++++++++++++---------------------------------
 2 files changed, 21 insertions(+), 65 deletions(-)
  

Comments

Pedro Alves March 31, 2017, 3:12 p.m. UTC | #1
On 03/31/2017 03:55 PM, Simon Marchi wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
> 
> I noticed that there were some missing files in gdbserver's gitignore
> (some generated register format .c files).  Of course the easy fix would
> be to add those files to .gitignore, but I think we can do a better job,
> so that we don't have to worry about adding generated files to
> .gitignore or the clean Makefile target.
> 
> I suggest naming all generated source files -generated.c.  This way, we
> can use a single rule in .gitignore and do a "rm -f *-generated.c" to
> clean them up.
> 
> New in v2:
> 
>   - Don't rename version.o and xml-builtin.o
> 
> gdb/gdbserver/ChangeLog:
> 
> 	* .gitignore: Remove generated files, replace with wildcard.
> 	* (clean): Replace removal of generated files with wildcard.
> 	(version.c): Replace with...
> 	(version-generated.c): ...this.
> 	(xml-builtin.c): Replace with...
> 	(xml-builtin-generated.c): ...this.
> 	(%-ipa.o: %-generated.c, %.o: %-generated.c): New rules.
> 	(%.c: *regformats*): Replace with...
> 	(%-generated.c: *regformats*): ...this.

OK.

Thanks,
Pedro Alves
  
Simon Marchi March 31, 2017, 3:40 p.m. UTC | #2
On 2017-03-31 11:12, Pedro Alves wrote:
> On 03/31/2017 03:55 PM, Simon Marchi wrote:
>> From: Simon Marchi <simon.marchi@polymtl.ca>
>> 
>> I noticed that there were some missing files in gdbserver's gitignore
>> (some generated register format .c files).  Of course the easy fix 
>> would
>> be to add those files to .gitignore, but I think we can do a better 
>> job,
>> so that we don't have to worry about adding generated files to
>> .gitignore or the clean Makefile target.
>> 
>> I suggest naming all generated source files -generated.c.  This way, 
>> we
>> can use a single rule in .gitignore and do a "rm -f *-generated.c" to
>> clean them up.
>> 
>> New in v2:
>> 
>>   - Don't rename version.o and xml-builtin.o
>> 
>> gdb/gdbserver/ChangeLog:
>> 
>> 	* .gitignore: Remove generated files, replace with wildcard.
>> 	* (clean): Replace removal of generated files with wildcard.
>> 	(version.c): Replace with...
>> 	(version-generated.c): ...this.
>> 	(xml-builtin.c): Replace with...
>> 	(xml-builtin-generated.c): ...this.
>> 	(%-ipa.o: %-generated.c, %.o: %-generated.c): New rules.
>> 	(%.c: *regformats*): Replace with...
>> 	(%-generated.c: *regformats*): ...this.
> 
> OK.

Thanks, pushed.
  
Simon Marchi March 31, 2017, 6:46 p.m. UTC | #3
On 2017-03-31 11:40, Simon Marchi wrote:
> On 2017-03-31 11:12, Pedro Alves wrote:
>> On 03/31/2017 03:55 PM, Simon Marchi wrote:
>>> From: Simon Marchi <simon.marchi@polymtl.ca>
>>> 
>>> I noticed that there were some missing files in gdbserver's gitignore
>>> (some generated register format .c files).  Of course the easy fix 
>>> would
>>> be to add those files to .gitignore, but I think we can do a better 
>>> job,
>>> so that we don't have to worry about adding generated files to
>>> .gitignore or the clean Makefile target.
>>> 
>>> I suggest naming all generated source files -generated.c.  This way, 
>>> we
>>> can use a single rule in .gitignore and do a "rm -f *-generated.c" to
>>> clean them up.
>>> 
>>> New in v2:
>>> 
>>>   - Don't rename version.o and xml-builtin.o
>>> 
>>> gdb/gdbserver/ChangeLog:
>>> 
>>> 	* .gitignore: Remove generated files, replace with wildcard.
>>> 	* (clean): Replace removal of generated files with wildcard.
>>> 	(version.c): Replace with...
>>> 	(version-generated.c): ...this.
>>> 	(xml-builtin.c): Replace with...
>>> 	(xml-builtin-generated.c): ...this.
>>> 	(%-ipa.o: %-generated.c, %.o: %-generated.c): New rules.
>>> 	(%.c: *regformats*): Replace with...
>>> 	(%-generated.c: *regformats*): ...this.
>> 
>> OK.
> 
> Thanks, pushed.

Note that when updating past this commit and rebuilding, or in general 
hopping back and forth between branches that have this commit and 
branches that don't and rebuilding, you may stumble on errors like:

   make: *** No rule to make target `version.c', needed by `version.o'.  
Stop.

It's the same issue some people had when environ.c was moved to 
common/environ.c, and it will happen every time we move a source file.  
The reason is the leftover dependency file in .deps, containing 
something like:

   version.o: version.c

These files are automatically generated by gcc and state all the files 
that went into creating version.o during the last build.  That rule 
states that version.c should exist when for version.o to be built, and 
that version.o should be rebuilt if version.c is more recent.  But 
version.c was moved and no longer exists, hence the error.

One thing I see we could do to mitigate the problem is clear the .deps 
directory when doing a "make clean".  After all, when doing a clean, all 
objects are deleted and are going to be rebuilt, so we don't care about 
the dependencies anymore.  So if somebody stumbles on that problem, 
there's a chance they'll try to clean and build again, which would fix 
the problem.

Do you have any better idea?

Simon
  
Simon Marchi March 31, 2017, 7:39 p.m. UTC | #4
On 2017-03-31 14:46, Simon Marchi wrote:
> Note that when updating past this commit and rebuilding, or in general
> hopping back and forth between branches that have this commit and
> branches that don't and rebuilding, you may stumble on errors like:
> 
>   make: *** No rule to make target `version.c', needed by `version.o'.  
> Stop.
> 
> It's the same issue some people had when environ.c was moved to
> common/environ.c, and it will happen every time we move a source file.
>  The reason is the leftover dependency file in .deps, containing
> something like:
> 
>   version.o: version.c
> 
> These files are automatically generated by gcc and state all the files
> that went into creating version.o during the last build.  That rule
> states that version.c should exist when for version.o to be built, and
> that version.o should be rebuilt if version.c is more recent.  But
> version.c was moved and no longer exists, hence the error.
> 
> One thing I see we could do to mitigate the problem is clear the .deps
> directory when doing a "make clean".  After all, when doing a clean,
> all objects are deleted and are going to be rebuilt, so we don't care
> about the dependencies anymore.  So if somebody stumbles on that
> problem, there's a chance they'll try to clean and build again, which
> would fix the problem.
> 
> Do you have any better idea?
> 
> Simon

Huh, I've just noticed that gdb does this already:

   rm -f $(DEPDIR)/*

which translates to:

   rm -f .deps/*

So I guess it'd make sense to do it as well in gdbserver.
  
Pedro Alves April 4, 2017, 10:44 a.m. UTC | #5
On 03/31/2017 08:39 PM, Simon Marchi wrote:

>> Do you have any better idea?

Not off hand.

> Huh, I've just noticed that gdb does this already:
> 
>   rm -f $(DEPDIR)/*
> 
> which translates to:
> 
>   rm -f .deps/*
> 
> So I guess it'd make sense to do it as well in gdbserver.

Go for it.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/gdbserver/.gitignore b/gdb/gdbserver/.gitignore
index 66ce8439e5..fef0d01b14 100644
--- a/gdb/gdbserver/.gitignore
+++ b/gdb/gdbserver/.gitignore
@@ -7,20 +7,4 @@  libinproctrace.so
 build-gnulib-gdbserver
 build-libiberty-gdbserver
 
-amd64-avx-linux.c
-amd64-avx-mpx-linux.c
-amd64-avx512-linux.c
-amd64-linux.c
-amd64-mpx-linux.c
-i386-avx-linux.c
-i386-avx-mpx-linux.c
-i386-avx512-linux.c
-i386-linux.c
-i386-mmx-linux.c
-i386-mpx-linux.c
-reg-*.c
-version.c
-x32-avx-linux.c
-x32-avx512-linux.c
-x32-linux.c
-xml-builtin.c
+*-generated.c
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 9935012eb8..6af7c402f8 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -413,47 +413,10 @@  tags: TAGS
 
 clean:
 	rm -f *.o ${ADD_FILES} *~
-	rm -f version.c
 	rm -f gdbserver$(EXEEXT) gdbreplay$(EXEEXT) core make.log
 	rm -f $(IPA_LIB)
-	rm -f aarch64.c
-	rm -f reg-arm.c reg-bfin.c i386.c reg-ia64.c reg-m32r.c reg-m68k.c
-	rm -f reg-sh.c reg-sparc.c reg-spu.c amd64.c i386-linux.c
-	rm -f reg-cris.c reg-crisv32.c amd64-linux.c reg-xtensa.c
-	rm -f reg-tilegx.c reg-tilegx32.c
-	rm -f arm-with-iwmmxt.c
-	rm -f arm-with-vfpv2.c arm-with-vfpv3.c arm-with-neon.c
-	rm -f mips-linux.c mips-dsp-linux.c
-	rm -f mips64-linux.c mips64-dsp-linux.c
-	rm -f nios2-linux.c
-	rm -f powerpc-32.c powerpc-32l.c powerpc-64l.c powerpc-e500l.c
-	rm -f powerpc-altivec32l.c powerpc-cell32l.c powerpc-vsx32l.c
-	rm -f powerpc-altivec64l.c powerpc-cell64l.c powerpc-vsx64l.c
-	rm -f powerpc-isa205-32l.c powerpc-isa205-64l.c
-	rm -f powerpc-isa205-altivec32l.c powerpc-isa205-vsx32l.c powerpc-isa205-altivec64l.c
-	rm -f powerpc-isa205-vsx64l.c
-	rm -f s390-linux32.c s390-linux64.c s390x-linux64.c
-	rm -f s390-linux32v1.c s390-linux32v2.c s390-linux64v1.c
-	rm -f s390-linux64v2.c s390x-linux64v1.c s390x-linux64v2.c
-	rm -f s390-te-linux64.c s390x-te-linux64.c
-	rm -f s390-vx-linux64.c s390x-vx-linux64.c
-	rm -f s390-tevx-linux64.c s390x-tevx-linux64.c
-	rm -f tic6x-c64xp-linux.c tic6x-c64x-linux.c tic6x-c62x-linux.c
-	rm -f xml-builtin.c stamp-xml
-	rm -f i386-avx.c i386-avx-linux.c
-	rm -f i386-mpx.c i386-mpx-linux.c
-	rm -f i386-avx-mpx.c i386-avx-mpx-linux.c
-	rm -f i386-avx-avx512.c i386-avx-avx512-linux.c
-	rm -f i386-avx-mpx-avx512-pku.c i386-avx-mpx-avx512-pku-linux.c
-	rm -f amd64-avx.c amd64-avx-linux.c
-	rm -f amd64-mpx.c amd64-mpx-linux.c
-	rm -f amd64-avx-mpx.c amd64-avx-mpx-linux.c
-	rm -f amd64-avx-avx512.c amd64-avx-avx512-linux.c
-	rm -f amd64-avx-mpx-avx512-pku.c amd64-avx-mpx-avx512-pku-linux.c
-	rm -f i386-mmx.c i386-mmx-linux.c
-	rm -f x32.c x32-linux.c
-	rm -f x32-avx.c x32-avx-linux.c
-	rm -f x32-avx-avx512.c x32-avx-avx512-linux.c
+	rm -f *-generated.c
+	rm -f stamp-xml
 	@$(MAKE) $(FLAGS_TO_PASS) DO=$@ "DODIRS=$(SUBDIRS)" subdir_do
 
 maintainer-clean realclean distclean: clean
@@ -504,15 +467,15 @@  am--refresh:
 
 force:
 
-version.c: Makefile $(srcdir)/../version.in $(srcdir)/../../bfd/version.h $(srcdir)/../common/create-version.sh
+version-generated.c: Makefile $(srcdir)/../version.in $(srcdir)/../../bfd/version.h $(srcdir)/../common/create-version.sh
 	$(SHELL) $(srcdir)/../common/create-version.sh $(srcdir)/.. \
-	    $(host_alias) $(target_alias) version.c
+	    $(host_alias) $(target_alias) $@
 
-xml-builtin.c: stamp-xml; @true
+xml-builtin-generated.c: stamp-xml; @true
 stamp-xml: $(XML_DIR)/feature_to_c.sh Makefile $(XML_FILES)
 	rm -f xml-builtin.tmp
 	$(SHELL) $(XML_DIR)/feature_to_c.sh xml-builtin.tmp $(XML_FILES)
-	$(SHELL) $(srcdir)/../../move-if-change xml-builtin.tmp xml-builtin.c
+	$(SHELL) $(srcdir)/../../move-if-change xml-builtin.tmp xml-builtin-generated.c
 	echo stamp > stamp-xml
 
 .PRECIOUS: xml-builtin.c
@@ -552,6 +515,10 @@  ax.o: ax.c
 
 # Rules for objects that go in the in-process agent.
 
+%-ipa.o: %-generated.c
+	$(IPAGENT_COMPILE) $<
+	$(POSTCOMPILE)
+
 %-ipa.o: %.c
 	$(IPAGENT_COMPILE) $<
 	$(POSTCOMPILE)
@@ -573,6 +540,10 @@  ax.o: ax.c
 
 # Rules for objects that go in the gdbserver binary.
 
+%.o: %-generated.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
+
 %.o: %.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
@@ -593,18 +564,19 @@  ax.o: ax.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
 
-# Rules for register format descriptions.
+# Rules for register format descriptions.  Suffix destination files with
+# -generated to identify and clean them easily.
 
-%.c: ../regformats/%.dat | $(regdat_sh)
+%-generated.c: ../regformats/%.dat | $(regdat_sh)
 	$(SHELL) $(regdat_sh) $< $@
 
-%.c: ../regformats/arm/%.dat | $(regdat_sh)
+%-generated.c: ../regformats/arm/%.dat | $(regdat_sh)
 	$(SHELL) $(regdat_sh) $< $@
 
-%.c: ../regformats/i386/%.dat | $(regdat_sh)
+%-generated.c: ../regformats/i386/%.dat | $(regdat_sh)
 	$(SHELL) $(regdat_sh) $< $@
 
-%.c: ../regformats/rs6000/%.dat | $(regdat_sh)
+%-generated.c: ../regformats/rs6000/%.dat | $(regdat_sh)
 	$(SHELL) $(regdat_sh) $< $@
 
 #