* [PATCH][gdb] Add maint selftest -verbose option
@ 2021-09-15 10:01 Tom de Vries via Gdb-patches
2021-09-22 9:49 ` Tom de Vries via Gdb-patches
0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries via Gdb-patches @ 2021-09-15 10:01 UTC (permalink / raw)
To: gdb-patches
Hi,
The print_one_insn selftest in gdb/disasm-selftests.c contains:
...
/* If you want to see the disassembled instruction printed to gdb_stdout,
set verbose to true. */
static const bool verbose = false;
...
Make this parameter available in the maint selftest command using a new option
-verbose, such that we can do:
...
(gdb) maint selftest -verbose print_one_insn
...
Tested on x86_64-linux.
Any comments?
Thanks,
- Tom
[gdb] Add maint selftest -verbose option
---
gdb/disasm-selftests.c | 9 ++++-----
gdb/doc/gdb.texinfo | 5 +++--
gdb/maint.c | 3 ++-
gdbsupport/selftest.cc | 13 ++++++++++++-
gdbsupport/selftest.h | 7 ++++++-
5 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/gdb/disasm-selftests.c b/gdb/disasm-selftests.c
index ae71e711bba..0a383d6b795 100644
--- a/gdb/disasm-selftests.c
+++ b/gdb/disasm-selftests.c
@@ -103,8 +103,7 @@ print_one_insn_test (struct gdbarch *gdbarch)
/* Test gdb_disassembler for a given gdbarch by reading data from a
pre-allocated buffer. If you want to see the disassembled
- instruction printed to gdb_stdout, set verbose to true. */
- static const bool verbose = false;
+ instruction printed to gdb_stdout, use maint selftest -verbose. */
class gdb_disassembler_test : public gdb_disassembler
{
@@ -114,7 +113,7 @@ print_one_insn_test (struct gdbarch *gdbarch)
const gdb_byte *insn,
size_t len)
: gdb_disassembler (gdbarch,
- (verbose ? gdb_stdout : &null_stream),
+ (run_verbose () ? gdb_stdout : &null_stream),
gdb_disassembler_test::read_memory),
m_insn (insn), m_len (len)
{
@@ -123,7 +122,7 @@ print_one_insn_test (struct gdbarch *gdbarch)
int
print_insn (CORE_ADDR memaddr)
{
- if (verbose)
+ if (run_verbose ())
{
fprintf_unfiltered (stream (), "%s ",
gdbarch_bfd_arch_info (arch ())->arch_name);
@@ -131,7 +130,7 @@ print_one_insn_test (struct gdbarch *gdbarch)
int len = gdb_disassembler::print_insn (memaddr);
- if (verbose)
+ if (run_verbose ())
fprintf_unfiltered (stream (), "\n");
return len;
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 5e1de7e7a70..57bbc7cd878 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -39433,11 +39433,12 @@ data structures, including its flags and contained types.
@kindex maint selftest
@cindex self tests
-@item maint selftest @r{[}@var{filter}@r{]}
+@item maint selftest @r{[}-verbose@r{]} @r{[}@var{filter}@r{]}
Run any self tests that were compiled in to @value{GDBN}. This will
print a message showing how many tests were run, and how many failed.
If a @var{filter} is passed, only the tests with @var{filter} in their
-name will be ran.
+name will be ran. If @code{-verbose} is passed, the self tests can be
+more verbose.
@kindex maint info selftests
@cindex self tests
diff --git a/gdb/maint.c b/gdb/maint.c
index 8f8bdc87be8..c6d13a3a732 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -1127,8 +1127,9 @@ static void
maintenance_selftest (const char *args, int from_tty)
{
#if GDB_SELF_TEST
+ bool verbose = args != nullptr && check_for_argument (&args, "-verbose");
gdb_argv argv (args);
- selftests::run_tests (argv.as_array_view ());
+ selftests::run_tests (argv.as_array_view (), verbose);
#else
printf_filtered (_("\
Selftests have been disabled for this build.\n"));
diff --git a/gdbsupport/selftest.cc b/gdbsupport/selftest.cc
index d0511abe654..fd455b27f51 100644
--- a/gdbsupport/selftest.cc
+++ b/gdbsupport/selftest.cc
@@ -65,12 +65,23 @@ register_test (const std::string &name, self_test_function *function)
register_test (name, new simple_selftest (function));
}
+static bool run_verbose_ = false;
+
+/* See selftest.h. */
+
+bool
+run_verbose ()
+{
+ return run_verbose_;
+}
+
/* See selftest.h. */
void
-run_tests (gdb::array_view<const char *const> filters)
+run_tests (gdb::array_view<const char *const> filters, bool verbose)
{
int ran = 0, failed = 0;
+ run_verbose_ = verbose;
for (const auto &pair : tests)
{
diff --git a/gdbsupport/selftest.h b/gdbsupport/selftest.h
index 13441b05a21..ceb965de530 100644
--- a/gdbsupport/selftest.h
+++ b/gdbsupport/selftest.h
@@ -37,6 +37,10 @@ struct selftest
virtual void operator() () const = 0;
};
+/* True if selftest should run verbosely. */
+
+extern bool run_verbose ();
+
/* Register a new self-test. */
extern void register_test (const std::string &name, selftest *test);
@@ -52,7 +56,8 @@ extern void register_test (const std::string &name,
If FILTERS is not empty, only run tests with names containing one of the
element of FILTERS. */
-extern void run_tests (gdb::array_view<const char *const> filters);
+extern void run_tests (gdb::array_view<const char *const> filters,
+ bool verbose = false);
/* Reset GDB or GDBserver's internal state. */
extern void reset ();
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH][gdb] Add maint selftest -verbose option
2021-09-15 10:01 [PATCH][gdb] Add maint selftest -verbose option Tom de Vries via Gdb-patches
@ 2021-09-22 9:49 ` Tom de Vries via Gdb-patches
0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries via Gdb-patches @ 2021-09-22 9:49 UTC (permalink / raw)
To: gdb-patches
On 9/15/21 12:01 PM, Tom de Vries wrote:
> Hi,
>
> The print_one_insn selftest in gdb/disasm-selftests.c contains:
> ...
> /* If you want to see the disassembled instruction printed to gdb_stdout,
> set verbose to true. */
> static const bool verbose = false;
> ...
>
> Make this parameter available in the maint selftest command using a new option
> -verbose, such that we can do:
> ...
> (gdb) maint selftest -verbose print_one_insn
> ...
>
> Tested on x86_64-linux.
>
> Any comments?
>
Committed.
Thanks,
- Tom
> [gdb] Add maint selftest -verbose option
>
> ---
> gdb/disasm-selftests.c | 9 ++++-----
> gdb/doc/gdb.texinfo | 5 +++--
> gdb/maint.c | 3 ++-
> gdbsupport/selftest.cc | 13 ++++++++++++-
> gdbsupport/selftest.h | 7 ++++++-
> 5 files changed, 27 insertions(+), 10 deletions(-)
>
> diff --git a/gdb/disasm-selftests.c b/gdb/disasm-selftests.c
> index ae71e711bba..0a383d6b795 100644
> --- a/gdb/disasm-selftests.c
> +++ b/gdb/disasm-selftests.c
> @@ -103,8 +103,7 @@ print_one_insn_test (struct gdbarch *gdbarch)
>
> /* Test gdb_disassembler for a given gdbarch by reading data from a
> pre-allocated buffer. If you want to see the disassembled
> - instruction printed to gdb_stdout, set verbose to true. */
> - static const bool verbose = false;
> + instruction printed to gdb_stdout, use maint selftest -verbose. */
>
> class gdb_disassembler_test : public gdb_disassembler
> {
> @@ -114,7 +113,7 @@ print_one_insn_test (struct gdbarch *gdbarch)
> const gdb_byte *insn,
> size_t len)
> : gdb_disassembler (gdbarch,
> - (verbose ? gdb_stdout : &null_stream),
> + (run_verbose () ? gdb_stdout : &null_stream),
> gdb_disassembler_test::read_memory),
> m_insn (insn), m_len (len)
> {
> @@ -123,7 +122,7 @@ print_one_insn_test (struct gdbarch *gdbarch)
> int
> print_insn (CORE_ADDR memaddr)
> {
> - if (verbose)
> + if (run_verbose ())
> {
> fprintf_unfiltered (stream (), "%s ",
> gdbarch_bfd_arch_info (arch ())->arch_name);
> @@ -131,7 +130,7 @@ print_one_insn_test (struct gdbarch *gdbarch)
>
> int len = gdb_disassembler::print_insn (memaddr);
>
> - if (verbose)
> + if (run_verbose ())
> fprintf_unfiltered (stream (), "\n");
>
> return len;
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 5e1de7e7a70..57bbc7cd878 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -39433,11 +39433,12 @@ data structures, including its flags and contained types.
>
> @kindex maint selftest
> @cindex self tests
> -@item maint selftest @r{[}@var{filter}@r{]}
> +@item maint selftest @r{[}-verbose@r{]} @r{[}@var{filter}@r{]}
> Run any self tests that were compiled in to @value{GDBN}. This will
> print a message showing how many tests were run, and how many failed.
> If a @var{filter} is passed, only the tests with @var{filter} in their
> -name will be ran.
> +name will be ran. If @code{-verbose} is passed, the self tests can be
> +more verbose.
>
> @kindex maint info selftests
> @cindex self tests
> diff --git a/gdb/maint.c b/gdb/maint.c
> index 8f8bdc87be8..c6d13a3a732 100644
> --- a/gdb/maint.c
> +++ b/gdb/maint.c
> @@ -1127,8 +1127,9 @@ static void
> maintenance_selftest (const char *args, int from_tty)
> {
> #if GDB_SELF_TEST
> + bool verbose = args != nullptr && check_for_argument (&args, "-verbose");
> gdb_argv argv (args);
> - selftests::run_tests (argv.as_array_view ());
> + selftests::run_tests (argv.as_array_view (), verbose);
> #else
> printf_filtered (_("\
> Selftests have been disabled for this build.\n"));
> diff --git a/gdbsupport/selftest.cc b/gdbsupport/selftest.cc
> index d0511abe654..fd455b27f51 100644
> --- a/gdbsupport/selftest.cc
> +++ b/gdbsupport/selftest.cc
> @@ -65,12 +65,23 @@ register_test (const std::string &name, self_test_function *function)
> register_test (name, new simple_selftest (function));
> }
>
> +static bool run_verbose_ = false;
> +
> +/* See selftest.h. */
> +
> +bool
> +run_verbose ()
> +{
> + return run_verbose_;
> +}
> +
> /* See selftest.h. */
>
> void
> -run_tests (gdb::array_view<const char *const> filters)
> +run_tests (gdb::array_view<const char *const> filters, bool verbose)
> {
> int ran = 0, failed = 0;
> + run_verbose_ = verbose;
>
> for (const auto &pair : tests)
> {
> diff --git a/gdbsupport/selftest.h b/gdbsupport/selftest.h
> index 13441b05a21..ceb965de530 100644
> --- a/gdbsupport/selftest.h
> +++ b/gdbsupport/selftest.h
> @@ -37,6 +37,10 @@ struct selftest
> virtual void operator() () const = 0;
> };
>
> +/* True if selftest should run verbosely. */
> +
> +extern bool run_verbose ();
> +
> /* Register a new self-test. */
>
> extern void register_test (const std::string &name, selftest *test);
> @@ -52,7 +56,8 @@ extern void register_test (const std::string &name,
> If FILTERS is not empty, only run tests with names containing one of the
> element of FILTERS. */
>
> -extern void run_tests (gdb::array_view<const char *const> filters);
> +extern void run_tests (gdb::array_view<const char *const> filters,
> + bool verbose = false);
>
> /* Reset GDB or GDBserver's internal state. */
> extern void reset ();
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-22 9:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-15 10:01 [PATCH][gdb] Add maint selftest -verbose option Tom de Vries via Gdb-patches
2021-09-22 9:49 ` Tom de Vries via Gdb-patches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox