[v2,2/2] Fix --enable-libctf, --disable-static, and tests sans CTF-capable toolchain

Message ID 20191009182648.274292-2-nick.alcock@oracle.com
State New, archived
Headers

Commit Message

Nick Alcock Oct. 9, 2019, 6:26 p.m. UTC
  gdb/
	* configure.ac: Add --enable-libctf: handle --disable-static
	properly.
	* Makefile.in (LIBCTF): Substitute in.
	(CTF_DEPS): New, likewise.
	(CLIBS): libctf needs symbols from libbfd: move earlier.
	(CDEPS): Use CTF_DEPS, not LIBCTF, now LIBCTF can include rpath
	flags.
	* ctfread.c: Surround in ENABLE_LIBCTF.
	_initialize_ctfread [!ENABLE_LIBCTF]: New stub.
	elfctf_build_psymtabs [!ENABLE_LIBCTF]: Likewise.
	* configure: Regenerate.
	* config.in: Likewise.

gdb/testsuite/
	* configure.ac: Add --enable-libctf.
	* Makefile.in (site.exp): Add enable_libctf to site.exp.
	* lib/gdb.exp (skip_ctf_tests): New.
	* gdb.base/ctf-constvars.exp: Use it.
	* gdb.base/ctf-cvexpr.exp: Likewise.
	* gdb.base/ctf-ptype.exp: Likewise.
	* gdb.base/ctf-whatis.exp: Likewise.
	* configure: Regenerate.
---
 gdb/Makefile.in                          |  7 +++--
 gdb/config.in                            |  3 ++
 gdb/configure                            | 36 ++++++++++++++++++++++++
 gdb/configure.ac                         | 24 ++++++++++++++++
 gdb/ctfread.c                            | 18 ++++++++++++
 gdb/testsuite/Makefile.in                |  2 ++
 gdb/testsuite/configure                  | 18 ++++++++++++
 gdb/testsuite/configure.ac               | 10 +++++++
 gdb/testsuite/gdb.base/ctf-constvars.exp |  4 +++
 gdb/testsuite/gdb.base/ctf-cvexpr.exp    |  4 +++
 gdb/testsuite/gdb.base/ctf-ptype.exp     |  4 +++
 gdb/testsuite/gdb.base/ctf-whatis.exp    |  4 +++
 gdb/testsuite/lib/gdb.exp                | 17 +++++++++++
 13 files changed, 148 insertions(+), 3 deletions(-)
  

Comments

Tom Tromey Oct. 15, 2019, 8:01 p.m. UTC | #1
>>>>> "Nick" == Nick Alcock <nick.alcock@oracle.com> writes:

Thanks for doing this.  This looks basically ok, just a few nits below.

The patch should have some intro text.  gdb style is to use the same
text for the description in the email and for the commit.

Nick> +if test x${enable_static} = xno; then
Nick> +  LIBCTF="-Wl,--rpath,../libctf/.libs ../libctf/.libs/libctf.so"

Indentation of 2 here...

Nick> +if test "${enable_libctf}" = yes; then
Nick> +    AC_DEFINE(ENABLE_LIBCTF, 1, [Handle .ctf type-info sections])

... but 4 here.  I think they could be the same, whatever is most common
in the file, or most common nearby anyhow.

Nick> +#else
Nick> +
Nick> +void
Nick> +_initialize_ctfread (void)

gdb just uses "()", not "(void)" now.

Nick> diff --git a/gdb/testsuite/configure.ac b/gdb/testsuite/configure.ac
... 
Nick> +AC_ARG_ENABLE(libctf,
Nick> +[AS_HELP_STRING([--enable-libctf], [Handle .ctf type-info sections])], [

This seems to be identical to what's in gdb.
I don't really mind, but if you're duplicating this across several
subdirectories, it may be better to stick a new macro into a new .m4 in
config/, then use that everywhere.

Nick> +if {[skip_ctf_tests]} {
Nick> +    return
Nick> +}

I think these spots should call "unsupported" to explain what happened.

Nick> +proc skip_ctf_tests {} {

I suspect you probably want to use gdb_caching_proc here.  This can be
friendlier when running a lot of parallel tests, because it caches the
result, and this proc is doing a compilation.

Tom
  
Nick Alcock Oct. 16, 2019, 12:53 p.m. UTC | #2
On 15 Oct 2019, Tom Tromey said:

>>>>>> "Nick" == Nick Alcock <nick.alcock@oracle.com> writes:
>
> Thanks for doing this.  This looks basically ok, just a few nits below.

Thanks for the review!

> The patch should have some intro text.  gdb style is to use the same
> text for the description in the email and for the commit.

I know: almost uniquely for me, I couldn't think of anything. :) I was
hoping you'd recommend something that wasn't literally repeating the
subject line...

(I also need to change things to cite the ChangeLog names in the commit
changelog text copy, rather than just the dir as binutils does.)

> Nick> +if test x${enable_static} = xno; then
> Nick> +  LIBCTF="-Wl,--rpath,../libctf/.libs ../libctf/.libs/libctf.so"
>
> Indentation of 2 here...
> 
> Nick> +if test "${enable_libctf}" = yes; then
> Nick> +    AC_DEFINE(ENABLE_LIBCTF, 1, [Handle .ctf type-info sections])
>
> ... but 4 here.  I think they could be the same, whatever is most common
> in the file, or most common nearby anyhow.

Oops! You can tell I was editing several sorts of thing at once with
different indentatn levels: fixed.

> Nick> +#else
> Nick> +
> Nick> +void
> Nick> +_initialize_ctfread (void)
>
> gdb just uses "()", not "(void)" now.

Oh good! C++ to the rescue etc. Fixed. (And the other instance I copied
it from, further up in the file.)

> Nick> diff --git a/gdb/testsuite/configure.ac b/gdb/testsuite/configure.ac
> ... 
> Nick> +AC_ARG_ENABLE(libctf,
> Nick> +[AS_HELP_STRING([--enable-libctf], [Handle .ctf type-info sections])], [
>
> This seems to be identical to what's in gdb.
> 
> I don't really mind, but if you're duplicating this across several
> subdirectories, it may be better to stick a new macro into a new .m4 in
> config/, then use that everywhere.

I was thinking exactly the same thing last night. It's now duplicated in
four places, clearly way above any reasonable refactoring bound... I'll
adjust both patches in the series accordingly.

> Nick> +if {[skip_ctf_tests]} {
> Nick> +    return
> Nick> +}
>
> I think these spots should call "unsupported" to explain what happened.

I didn't notice that existed. Thank you, will do!

Something like

unsupported "No compiler CTF support, or CTF disabled in GDB"

I suppose.

> Nick> +proc skip_ctf_tests {} {
>
> I suspect you probably want to use gdb_caching_proc here.  This can be
> friendlier when running a lot of parallel tests, because it caches the
> result, and this proc is doing a compilation.

I was hoping something like this existed too. (You can tell I'm a newbie
to the GDB testsuite.)

Hm let's see if it has any special requirements... doesn't look like it,
other than that the output is unvarying.

New series coming soon. :) (Changes on the binutils side, as well, for
the --enable-libctf refactoring.)
  

Patch

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 36650ad555..3b25da55fe 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -154,7 +154,8 @@  INCLUDE_CFLAGS = -I$(INCLUDE_DIR)
 LIBIBERTY = ../libiberty/libiberty.a
 
 # Where is the CTF library?  Typically in ../libctf.
-LIBCTF = ../libctf/.libs/libctf.a
+LIBCTF = @LIBCTF@
+CTF_DEPS = @CTF_DEPS@
 
 # Where is the BFD library?  Typically in ../bfd.
 BFD_DIR = ../bfd
@@ -591,14 +592,14 @@  INTERNAL_LDFLAGS = \
 # Libraries and corresponding dependencies for compiling gdb.
 # XM_CLIBS, defined in *config files, have host-dependent libs.
 # LIBIBERTY appears twice on purpose.
-CLIBS = $(SIM) $(READLINE) $(OPCODES) $(BFD) $(LIBCTF) $(ZLIB) \
+CLIBS = $(SIM) $(READLINE) $(OPCODES) $(LIBCTF) $(BFD) $(ZLIB) \
         $(INTL) $(LIBIBERTY) $(LIBDECNUMBER) \
 	$(XM_CLIBS) $(GDBTKLIBS) \
 	@LIBS@ @GUILE_LIBS@ @PYTHON_LIBS@ \
 	$(LIBEXPAT) $(LIBLZMA) $(LIBBABELTRACE) $(LIBIPT) \
 	$(LIBIBERTY) $(WIN32LIBS) $(LIBGNU) $(LIBICONV) $(LIBMPFR) \
 	$(SRCHIGH_LIBS)
-CDEPS = $(NAT_CDEPS) $(SIM) $(BFD) $(READLINE_DEPS) $(LIBCTF) \
+CDEPS = $(NAT_CDEPS) $(SIM) $(BFD) $(READLINE_DEPS) $(CTF_DEPS) \
 	$(OPCODES) $(INTL_DEPS) $(LIBIBERTY) $(CONFIG_DEPS) $(LIBGNU)
 
 DIST = gdb
diff --git a/gdb/config.in b/gdb/config.in
index 26ca02f6a3..5d6737b874 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -33,6 +33,9 @@ 
 /* Define to BFD's default target vector. */
 #undef DEFAULT_BFD_VEC
 
+/* Handle .ctf type-info sections */
+#undef ENABLE_LIBCTF
+
 /* Define to 1 if translation of program messages to the user's native
    language is requested. */
 #undef ENABLE_NLS
diff --git a/gdb/configure b/gdb/configure
index 22a5f6051d..ed30f909a0 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -627,6 +627,9 @@  GCORE_TRANSFORM_NAME
 GDB_TRANSFORM_NAME
 XSLTPROC
 GDB_NM_FILE
+CTF_DEPS
+LIBCTF
+ENABLE_LIBCTF
 LTLIBBABELTRACE
 LIBBABELTRACE
 HAVE_LIBBABELTRACE
@@ -897,6 +900,7 @@  enable_sim
 enable_gdbserver
 with_babeltrace
 with_libbabeltrace_prefix
+enable_libctf
 enable_unit_tests
 '
       ac_precious_vars='build_alias
@@ -1564,6 +1568,7 @@  Optional Features:
   --enable-sim            link gdb with simulator
   --enable-gdbserver      automatically build gdbserver (yes/no/auto, default
                           is auto)
+  --enable-libctf         Handle .ctf type-info sections
   --enable-unit-tests     Enable the inclusion of unit tests when compiling
                           GDB
 
@@ -17556,6 +17561,37 @@  $as_echo "$as_me: WARNING: babeltrace is missing or unusable; GDB is unable to r
   fi
 fi
 
+# Check whether --enable-libctf was given.
+if test "${enable_libctf+set}" = set; then :
+  enableval=$enable_libctf;
+if test "${enableval}" = no; then
+  enable_libctf=no
+else
+  enable_libctf=yes
+fi
+else
+  enable_libctf=yes
+fi
+
+if test x${enable_static} = xno; then
+  LIBCTF="-Wl,--rpath,../libctf/.libs ../libctf/.libs/libctf.so"
+  CTF_DEPS="../libctf/.libs/libctf.so"
+else
+  LIBCTF="../libctf/.libs/libctf.a"
+  CTF_DEPS="$LIBCTF"
+fi
+if test "${enable_libctf}" = yes; then
+
+$as_echo "#define ENABLE_LIBCTF 1" >>confdefs.h
+
+else
+    LIBCTF=
+    CTF_DEPS=
+fi
+
+
+
+
 # If nativefile (NAT_FILE) is not set in configure.nat, we link to an
 # empty version.
 
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 9da8818fb5..761e436277 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -2217,6 +2217,30 @@  else
   fi
 fi
 
+AC_ARG_ENABLE(libctf,
+[AS_HELP_STRING([--enable-libctf], [Handle .ctf type-info sections])], [
+if test "${enableval}" = no; then
+  enable_libctf=no
+else
+  enable_libctf=yes
+fi], [enable_libctf=yes])
+if test x${enable_static} = xno; then
+  LIBCTF="-Wl,--rpath,../libctf/.libs ../libctf/.libs/libctf.so"
+  CTF_DEPS="../libctf/.libs/libctf.so"
+else
+  LIBCTF="../libctf/.libs/libctf.a"
+  CTF_DEPS="$LIBCTF"
+fi
+if test "${enable_libctf}" = yes; then
+    AC_DEFINE(ENABLE_LIBCTF, 1, [Handle .ctf type-info sections])
+else
+    LIBCTF=
+    CTF_DEPS=
+fi
+AC_SUBST(ENABLE_LIBCTF)
+AC_SUBST(LIBCTF)
+AC_SUBST(CTF_DEPS)
+
 # If nativefile (NAT_FILE) is not set in configure.nat, we link to an
 # empty version.
 
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 44ccff62ae..ad8446b56c 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -81,6 +81,9 @@ 
 #include "block.h"
 #include "ctfread.h"
 #include "psympriv.h"
+
+#if ENABLE_LIBCTF
+
 #include "ctf.h"
 #include "ctf-api.h"
 
@@ -1484,3 +1487,18 @@  _initialize_ctfread (void)
   ctf_file_key
     = register_objfile_data_with_cleanup (NULL, ctf_close_objfile);
 }
+
+#else
+
+void
+_initialize_ctfread (void)
+{
+}
+
+void
+elfctf_build_psymtabs (struct objfile *of)
+{
+  /* Nothing to do if CTF is disabled.  */
+}
+
+#endif /* ENABLE_LIBCTF */
diff --git a/gdb/testsuite/Makefile.in b/gdb/testsuite/Makefile.in
index 2beba053ee..42de3d6f22 100644
--- a/gdb/testsuite/Makefile.in
+++ b/gdb/testsuite/Makefile.in
@@ -28,6 +28,7 @@  program_transform_name = @program_transform_name@
 build_canonical = @build@
 host_canonical = @host@
 target_canonical = @target@
+enable_libctf = @enable_libctf@
 
 SHELL = @SHELL@
 EXEEXT = @EXEEXT@
@@ -131,6 +132,7 @@  $(abs_builddir)/site.exp site.exp: ./config.status Makefile
 	@echo "set build_triplet ${build_canonical}" >> ./tmp0
 	@echo "set srcdir ${abs_srcdir}" >> ./tmp0
 	@echo "set tool gdb" >> ./tmp0
+	@echo "set enable_libctf ${enable_libctf}" >> ./tmp0
 	@echo 'source $${srcdir}/lib/append_gdb_boards_dir.exp' >> ./tmp0
 	@echo "## All variables above are generated by configure. Do Not Edit ##" >> ./tmp0
 		@cat ./tmp0 > site.exp
diff --git a/gdb/testsuite/configure b/gdb/testsuite/configure
index cc00f8dfa8..dc4e498855 100755
--- a/gdb/testsuite/configure
+++ b/gdb/testsuite/configure
@@ -638,6 +638,7 @@  LDFLAGS
 CFLAGS
 CC
 RPATH_ENVVAR
+enable_libctf
 subdirs
 target_noncanonical
 target_os
@@ -694,6 +695,7 @@  ac_subst_files=''
 ac_user_opts='
 enable_option_checking
 enable_gdbtk
+enable_libctf
 enable_shared
 '
       ac_precious_vars='build_alias
@@ -1323,6 +1325,7 @@  Optional Features:
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
   --enable-gtk            enable gdbtk graphical user interface (GUI)
+  --enable-libctf         Handle .ctf type-info sections
   --enable-shared         build shared libraries deault=yes
 
 Some influential environment variables:
@@ -2189,6 +2192,21 @@  subdirs="$subdirs gdb.gdbtk"
 
 fi
 
+# Check whether --enable-libctf was given.
+if test "${enable_libctf+set}" = set; then :
+  enableval=$enable_libctf;
+if test "${enableval}" = no; then
+  enable_libctf=no
+else
+  enable_libctf=yes
+fi
+else
+  enable_libctf=yes
+fi
+
+
+
+
 # Enable shared libraries.
 # Check whether --enable-shared was given.
 if test "${enable_shared+set}" = set; then :
diff --git a/gdb/testsuite/configure.ac b/gdb/testsuite/configure.ac
index 1c4dc99c47..8f7c99084e 100644
--- a/gdb/testsuite/configure.ac
+++ b/gdb/testsuite/configure.ac
@@ -43,6 +43,16 @@  if test $enable_gdbtk = yes; then
    AC_CONFIG_SUBDIRS(gdb.gdbtk)
 fi
 
+AC_ARG_ENABLE(libctf,
+[AS_HELP_STRING([--enable-libctf], [Handle .ctf type-info sections])], [
+if test "${enableval}" = no; then
+  enable_libctf=no
+else
+  enable_libctf=yes
+fi], [enable_libctf=yes])
+
+AC_SUBST(enable_libctf)
+
 # Enable shared libraries.
 AC_ARG_ENABLE(shared,
 [  --enable-shared         build shared libraries [deault=yes]],,
diff --git a/gdb/testsuite/gdb.base/ctf-constvars.exp b/gdb/testsuite/gdb.base/ctf-constvars.exp
index 4a81a94ddb..e7b81edb9e 100644
--- a/gdb/testsuite/gdb.base/ctf-constvars.exp
+++ b/gdb/testsuite/gdb.base/ctf-constvars.exp
@@ -32,6 +32,10 @@ 
 standard_testfile .c
 set opts "additional_flags=-gt"
 
+if {[skip_ctf_tests]} {
+    return
+}
+
 if { [prepare_for_testing "failed to prepare" ${testfile} \
 	  [list $srcfile] [list $opts nowarnings]] } {
     return 0
diff --git a/gdb/testsuite/gdb.base/ctf-cvexpr.exp b/gdb/testsuite/gdb.base/ctf-cvexpr.exp
index 67ceb21f52..7c97e10446 100644
--- a/gdb/testsuite/gdb.base/ctf-cvexpr.exp
+++ b/gdb/testsuite/gdb.base/ctf-cvexpr.exp
@@ -27,6 +27,10 @@ 
 standard_testfile cvexpr.c
 set opts "additional_flags=-gt"
 
+if {[skip_ctf_tests]} {
+    return
+}
+
 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
      untested "failed to compile"
      return -1
diff --git a/gdb/testsuite/gdb.base/ctf-ptype.exp b/gdb/testsuite/gdb.base/ctf-ptype.exp
index 9f54582422..7242131a47 100644
--- a/gdb/testsuite/gdb.base/ctf-ptype.exp
+++ b/gdb/testsuite/gdb.base/ctf-ptype.exp
@@ -23,6 +23,10 @@ 
 standard_testfile .c
 set opts "additional_flags=-gt"
 
+if {[skip_ctf_tests]} {
+    return
+}
+
 if { [prepare_for_testing "failed to prepare" ${testfile} \
 	  [list $srcfile] [list $opts nowarnings]] } {
     return 0
diff --git a/gdb/testsuite/gdb.base/ctf-whatis.exp b/gdb/testsuite/gdb.base/ctf-whatis.exp
index 3f26fc326e..19150ea247 100644
--- a/gdb/testsuite/gdb.base/ctf-whatis.exp
+++ b/gdb/testsuite/gdb.base/ctf-whatis.exp
@@ -23,6 +23,10 @@ 
 standard_testfile .c
 set opts "additional_flags=-gt"
 
+if {[skip_ctf_tests]} {
+    return
+}
+
 if { [prepare_for_testing "failed to prepare" ${testfile} \
           [list $srcfile] [list $opts nowarnings]] } {
     return 0
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 50db45d1b1..51447c1f91 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2013,6 +2013,23 @@  proc skip_tui_tests {} {
     return 0
 }
 
+# Return 1 if we should skip CTF-related tests.
+
+proc skip_ctf_tests {} {
+    set me "skip_ctf_tests"
+    set src { int main () {return 0;} }
+    set compile_flags "additional_flags=-gt"
+    global enable_libctf
+
+    if {$enable_libctf eq "no"} {
+	return 1
+    }
+    if {![gdb_simple_compile $me $src executable $compile_flags]} {
+	return 1
+    }
+    return 0
+}
+
 # Test files shall make sure all the test result lines in gdb.sum are
 # unique in a test run, so that comparing the gdb.sum files of two
 # test runs gives correct results.  Test files that exercise