[RFC,00/18] Allow building (more) C tests with a C++ compiler

Message ID 20200914001437.31157-1-pedro@palves.net
Headers show
Series
  • Allow building (more) C tests with a C++ compiler
Related show

Message

Pedro Alves Sept. 14, 2020, 12:14 a.m.
I've been playing with the AMD ROCm toolchain (GPU debugging, yay!)
and I had the idea of writing a board file that runs the whole
testsuite against the GPU, compiling programs with HIP.

Of course any testcase that relies on system calls like fork/exec, or
even threads, can't work, but there are many tests under gdb.base/ ,
gdb.mi/ , gdb.python/ , etc.  that are useful and exercise many of the
core gdb commands and features.

Since HIP is a C++-based language however (similar to CUDA), many of
those simple test programs don't compile or test cleanly, since they
are written in C without care for C++ compatibility.

Regardless of HIP, many of the tests written in C aren't really
testing C-specific things, but rather GDB core commands.  It's just
that C is seen as the lowest common denominator.  It seems like a good
idea to be able to run them in C++ mode too, to say, discover spurious
GCC vs G++ differences.  gdb.base/break.exp uncovered one such
difference that seems like a buglet (I'll probably file a GCC bug).

We already have some tests under gdb.base/ that explicitly test both C
and C++ modes, like align-c.exp/align-c++.exp and others.  I propose
allowing some more tests to run in C++ mode.  I'm not proposing always
running the tests in both C and C++, at least not yet.  Essentially,
I'm currently only after making it possible to run these test with
either:

 $ make check RUNTESTFLAGS="CC_FOR_TARGET='g++'"
 $ make check RUNTESTFLAGS="CC_FOR_TARGET='clang++ -Wno-deprecated'"

which is a necessary step anyway if we ever want to always run these
tests in both C and C++ modes.

Most of the changes are actually trivial and the kind you'd expect --
avoid identifiers named "this", explicit casts from 'void *' to 'type
*' or from int to enum.  In the .exp files, adjust to the fact that in
C++ mode, GDB prints the full prototype of functions (i.e., shows
parameter types), or that some commands by default show mangled names.

I don't think I'll do this to other tests in the foreseeable future,
as this this already enables a good subset of the testsuite, and most
the remaining tests fail to compile with HIP for other reasons AFAICT.

 gdb/testsuite/gdb.base/break.exp                  | 50 +++++++++++++----------
 gdb/testsuite/gdb.base/charset.c                  |  7 +++-
 gdb/testsuite/gdb.base/charset.exp                | 12 +++---
 gdb/testsuite/gdb.base/display.exp                |  3 ++
 gdb/testsuite/gdb.base/examine-backward.c         |  7 +++-
 gdb/testsuite/gdb.base/examine-backward.exp       |  7 +++-
 gdb/testsuite/gdb.base/exprs.c                    |  4 +-
 gdb/testsuite/gdb.base/find.c                     |  3 +-
 gdb/testsuite/gdb.base/find.exp                   |  3 ++
 gdb/testsuite/gdb.base/nested-addr.c              |  2 +-
 gdb/testsuite/gdb.base/nested-addr.exp            |  2 +-
 gdb/testsuite/gdb.base/printcmds.c                |  6 +--
 gdb/testsuite/gdb.base/prologue.c                 |  6 +++
 gdb/testsuite/gdb.base/prologue.exp               |  2 +-
 gdb/testsuite/gdb.base/ptype.c                    |  8 ++--
 gdb/testsuite/gdb.base/ptype1.c                   |  2 +-
 gdb/testsuite/gdb.base/setvar.c                   |  4 +-
 gdb/testsuite/gdb.base/share-env-with-gdbserver.c |  2 +-
 gdb/testsuite/gdb.base/sizeof.c                   |  2 +-
 gdb/testsuite/gdb.base/symbol-alias.exp           |  2 +-
 gdb/testsuite/gdb.base/symbol-alias2.c            |  6 +++
 gdb/testsuite/gdb.base/watchpoint.c               |  4 +-
 gdb/testsuite/gdb.base/watchpoint.exp             |  4 +-
 gdb/testsuite/gdb.base/whatis.c                   |  4 +-
 gdb/testsuite/gdb.cp/call-c-1.c                   |  3 ++
 gdb/testsuite/gdb.mi/var-cmd.c                    |  2 +-
 gdb/testsuite/gdb.python/py-as-string.c           |  2 +-
 gdb/testsuite/gdb.python/py-frame-inline.exp      |  2 +-
 gdb/testsuite/gdb.python/py-framefilter-mi.c      |  4 +-
 gdb/testsuite/gdb.python/py-framefilter.c         |  8 ++--
 gdb/testsuite/gdb.python/py-nested-maps.c         | 44 ++++++++++----------
 31 files changed, 128 insertions(+), 89 deletions(-)


base-commit: dc3a371e83b6df36beb8c6d12a07d3e469b68a36
-- 
2.14.5

Comments

Tom Tromey Sept. 14, 2020, 8:18 p.m. | #1
>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:


Pedro> We already have some tests under gdb.base/ that explicitly test both C
Pedro> and C++ modes, like align-c.exp/align-c++.exp and others.  I propose
Pedro> allowing some more tests to run in C++ mode.

Seems fine to me.  I skimmed a few patches and what I saw seemed
reasonable enough.

I didn't see patch #1 for whatever reason.

Tom
Pedro Alves Sept. 16, 2020, 11:39 a.m. | #2
On 9/14/20 9:18 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:

> 

> Pedro> We already have some tests under gdb.base/ that explicitly test both C

> Pedro> and C++ modes, like align-c.exp/align-c++.exp and others.  I propose

> Pedro> allowing some more tests to run in C++ mode.

> 

> Seems fine to me.  I skimmed a few patches and what I saw seemed

> reasonable enough.


Awesome, thanks.

> I didn't see patch #1 for whatever reason.


Curious.  I don't see it in the archives, but I did get a copy
via the mailing list.  Anyhow, I've resent it now:

 https://sourceware.org/pipermail/gdb-patches/2020-September/171893.html
Pedro Alves Sept. 17, 2020, 11:11 p.m. | #3
On 9/16/20 12:39 PM, Pedro Alves wrote:
> On 9/14/20 9:18 PM, Tom Tromey wrote:

>>>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:

>>

>> Pedro> We already have some tests under gdb.base/ that explicitly test both C

>> Pedro> and C++ modes, like align-c.exp/align-c++.exp and others.  I propose

>> Pedro> allowing some more tests to run in C++ mode.

>>

>> Seems fine to me.  I skimmed a few patches and what I saw seemed

>> reasonable enough.

> 

> Awesome, thanks.


I went ahead and wrote ChangeLogs & merged it.  I figure it's not worth
it to repost just for ChangeLogs.

Thanks again.

Pedro Alves

> 

>> I didn't see patch #1 for whatever reason.

> 

> Curious.  I don't see it in the archives, but I did get a copy

> via the mailing list.  Anyhow, I've resent it now:

> 

>  https://sourceware.org/pipermail/gdb-patches/2020-September/171893.html

>