Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Philippe Waroquiers <philippe.waroquiers@skynet.be>,
	gdb-patches@sourceware.org
Subject: Re: [RFAv3 5/5] Add a test case for info args|functions|locals|variables [-q] [-t TYPEREGEXP] [NAMEREGEXP]
Date: Mon, 22 Oct 2018 14:19:00 -0000	[thread overview]
Message-ID: <0f46cdb0-4c14-2d1b-9f5f-410b32c0915d@redhat.com> (raw)
In-Reply-To: <20180923214209.985-6-philippe.waroquiers@skynet.be>

On 09/23/2018 10:42 PM, Philippe Waroquiers wrote:
> Add a test case for info args|functions|locals|variables [-q] [-t TYPEREGEXP] [NAMEREGEXP]
> 
> gdb/testsuite/ChangeLog
> 2018-09-23  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
> 
>         * gdb.base/info_qt.c: New file.
>         * gdb.base/info_qt.exp: New file.
> ---
>  gdb/testsuite/gdb.base/info_qt.c   |  81 ++++++++++
>  gdb/testsuite/gdb.base/info_qt.exp | 234 +++++++++++++++++++++++++++++
>  2 files changed, 315 insertions(+)
>  create mode 100644 gdb/testsuite/gdb.base/info_qt.c
>  create mode 100644 gdb/testsuite/gdb.base/info_qt.exp
> 
> diff --git a/gdb/testsuite/gdb.base/info_qt.c b/gdb/testsuite/gdb.base/info_qt.c
> new file mode 100644
> index 0000000000..77c4ea8236
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/info_qt.c
> @@ -0,0 +1,81 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> +   Copyright 2018 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +#include <stdio.h>
> +#include <stdlib.h>

Are these two needed?

> +
> +typedef int entier;
> +
> +int info_qt_inc = 0;
> +entier info_qt_ent = 0;
> +
> +static void
> +setup_done (void)
> +{
> +}
> +
> +static void
> +setup (char arg_c, int arg_i, int arg_j)
> +{
> +  char loc_arg_c = arg_c;
> +  int loc_arg_i = arg_i;
> +  int loc_arg_j = arg_j;
> +
> +  info_qt_inc += loc_arg_c + loc_arg_i + loc_arg_j;
> +  setup_done ();
> +}
> +
> +void info_fun1 (void)
> +{
> +  info_qt_inc++;
> +  info_qt_ent++;
> +}
> +
> +int info_fun2 (char c)
> +{
> +  info_qt_inc += c;
> +  return info_qt_inc;
> +}
> +
> +int info_fun2bis (char c)
> +{
> +  info_qt_inc += c;
> +  return info_qt_inc;
> +}
> +
> +entier info_fun2xxx (char arg_c, int arg_i, int arg_j)
> +{
> +  info_qt_inc += arg_c + arg_i + arg_j;
> +  return info_qt_inc;
> +}
> +
> +entier info_fun2yyy (char arg_c, int arg_i, int arg_j)
> +{
> +  setup (arg_c, arg_i, arg_j);
> +  info_qt_inc += arg_c + arg_i + arg_j;
> +  return info_qt_inc;
> +}
> +
> +int
> +main (int argc, char **argv, char **envp)
> +{
> +  info_fun1 ();
> +  (void) info_fun2 ('a');
> +  (void) info_fun2bis ('b');
> +  (void) info_fun2xxx ('c', 1, 2);
> +  (void) info_fun2yyy ('d', 3, 4);
> +}
> diff --git a/gdb/testsuite/gdb.base/info_qt.exp b/gdb/testsuite/gdb.base/info_qt.exp
> new file mode 100644
> index 0000000000..3ece05c5e4
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/info_qt.exp
> @@ -0,0 +1,234 @@
> +# This testcase is part of GDB, the GNU debugger.
> +
> +# Copyright 2018 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +
> +# This test verifies that a macro using backtrace can be applied to all threads
> +# and will continue for each thread even though an error may occur in
> +# backtracing one of the threads.

Err, nope, it does not, that was gdb.threads/threadapply.exp.  :-)

Please remove/update.

> +
> +# Test info [args|functions|locals|variables] [-q] [-t TYPEREGEXP] [NAMEREGEXP]

Add some empty line here.

> +standard_testfile
> +
> +if { [prepare_for_testing "failed to prepare" ${testfile}] } {
> +    return -1
> +}
> +
> +clean_restart ${binfile}
> +
> +if ![runto setup_done] then {
> +    gdb_suppress_tests

We don't use gdb_suppress_tests anymore (for years).  Please
fail/return instead.

> +}
> +set any "\[^\r\n\]*"
> +set ws "\[ \t\]\+"
> +set number "\[0-9]\+"
> +
> +
> +############# test 'info functions'
> +
> +# test simple matching with name regexp

Please write complete sentences starting with uppercase
and ending in a period.  Here and throughout.

> +foreach_with_prefix cmd {
> +    "info functions info_fun"
> +    "info functions -- info_fun"
> +    "info functions ^info_fun" } {
> +    gdb_test $cmd \
> +	[multi_line \
> +	     "All functions matching regular expression \".*info_fun.*\":" \
> +	     "" \
> +	     "File .*info_qt.c:" \
> +	     "${number}:	void info_fun1\\\(void\\\);" \
> +	     "${number}:	int info_fun2\\\(char\\\);" \
> +	     "${number}:	int info_fun2bis\\\(char\\\);" \
> +	     "${number}:	entier info_fun2xxx\\\(char, int, int\\\);" \
> +	     "${number}:	entier info_fun2yyy\\\(char, int, int\\\);" \
> +	    ] \
> +	"info functions info_fun"
> +}
> +
> +# test simple matching with name regexp, but with -q to avoid the first header
> +foreach_with_prefix cmd {
> +    "info functions -q info_fun"
> +    "info functions -q -- info_fun" } {
> +    gdb_test $cmd \
> +	[multi_line \
> +	     "" \
> +	     "File .*info_qt.c:" \
> +	     "${number}:	void info_fun1\\\(void\\\);" \
> +	     "${number}:	int info_fun2\\\(char\\\);" \
> +	     "${number}:	int info_fun2bis\\\(char\\\);" \
> +	     "${number}:	entier info_fun2xxx\\\(char, int, int\\\);" \
> +	     "${number}:	entier info_fun2yyy\\\(char, int, int\\\);" \
> +	    ] \
> +	"info functions -q info_fun"
> +}
> +
> +# test -q and no matching functions
> +foreach_with_prefix cmd {
> +    "info functions -q nowaythiscanmatch"
> +    "info functions -q -- -q" } {
> +    gdb_test $cmd "" "quiet info functions empty output"

This matches any output before the gdb prompt.
Use gdb_test_no_output instead.

> +}
> +
> +# test with a type regexp
> +foreach_with_prefix cmd {
> +    "info functions -t entier -q info_fun"
> +    "info functions -q -t 'entier (' -- info_fun"
> +    "info functions -q -t '(char, int, int)' -- info_fun"
> +    "info functions -q -t 'entier (char, int, int)' -- info_fun" } {
> +    gdb_test $cmd \
> +	[multi_line \
> +	     "" \
> +	     "File .*info_qt.c:" \
> +	     "${number}:	entier info_fun2xxx\\\(char, int, int\\\);" \
> +	     "${number}:	entier info_fun2yyy\\\(char, int, int\\\);" \
> +	    ] \
> +	"info functions -q info_fun"
> +}
> +
> +# test with a non matching type regexp
> +gdb_test "info functions -t ganze_Zahl -q info_fun" "" \
> +    "quiet output info functions non matching type"
> +
> +
> +############# test 'info variables'
> +
> +# test simple matching with name regexp
> +foreach_with_prefix cmd {
> +    "info variables info_qt"
> +    "info variables -- info_qt"
> +    "info variables ^info_qt" } {
> +    gdb_test $cmd \
> +	[multi_line \
> +	     "All variables matching regular expression \".*info_qt.*\":" \
> +	     "" \
> +	     "File .*info_qt.c:" \
> +	     "${number}:	entier info_qt_ent;" \
> +	     "${number}:	int info_qt_inc;" \
> +	    ] \
> +	"info functions info_fun"
> +}
> +
> +# test simple matching with name regexp, but with -q to avoid the first header
> +
> +# test -q and no matching variables
> +foreach_with_prefix cmd {
> +    "info variables -q nowaythiscanmatch"
> +    "info variables -q -- -q" } {
> +    gdb_test $cmd "" "quiet info variables empty output"

gdb_test_no_output.

> +}
> +
> +# test with a type regexp
> +foreach_with_prefix cmd {
> +    "info variables -t entier -q info_qt"
> +    "info variables -q -t entier -- info_qt" } {
> +    gdb_test $cmd \
> +	[multi_line \
> +	     "" \
> +	     "File .*info_qt.c:" \
> +	     "${number}:	entier info_qt_ent;" \
> +	    ] \
> +	"info variables -q -t entier info_fun"
> +}
> +
> +# test with a non matching type regexp
> +gdb_test "info variables -t ganze_Zahl -q info_at" "" \
> +    "quiet output info variables non matching type"

gdb_test_no_output.


> +
> +
> +
> +############# test 'info args' in function setup.
> +
> +gdb_test "frame 1" ".* in setup .*" "set frame 1 for info args"
> +
> +# test name regexp matching all
> +foreach_with_prefix cmd {
> +    "info args"
> +    "info args arg_"
> +    "info args g"
> +    "info args -- .*" } {
> +    gdb_test $cmd \
> +	[multi_line \
> +	     "arg_c = 100 'd'" \
> +	     "arg_i = 3" \
> +	     "arg_j = 4" \
> +	    ] \
> +	"info args"
> +}
> +
> +# test name regexp or type regexp matching some
> +foreach_with_prefix cmd {
> +    "info args -t int"
> +    "info args arg_[ij]"} {
> +    gdb_test $cmd \
> +	[multi_line \
> +	     "arg_i = 3" \
> +	     "arg_j = 4" \
> +	    ] \
> +	"info args"
> +}

Duplicate test names.  

Consider sing  with_test_prefix to wrap groups of tests.

> +
> +gdb_test "info args nowaythiscanmatch" "No matching arguments." "non matching args"
> +gdb_test "info args -q nowaythiscanmatch" "" "quiet non matching args"
> +gdb_test "info args -q -t entier" "" "quiet non matching args with type"

gdb_test_no_output.

> +
> +############# test 'info locals' in function setup.
> +
> +gdb_test "frame 1" ".* in setup .*" "set frame 1 for info locals"
> +
> +# test name regexp matching all
> +foreach_with_prefix cmd {
> +    "info locals"
> +    "info locals loc_arg_"
> +    "info locals g"
> +    "info locals -- .*" } {
> +    gdb_test $cmd \
> +	[multi_line \
> +	     "loc_arg_c = 100 'd'" \
> +	     "loc_arg_i = 3" \
> +	     "loc_arg_j = 4" \
> +	    ] \
> +	"info locals"
> +}
> +
> +# test name regexp or type regexp matching some
> +foreach_with_prefix cmd {
> +    "info locals -t int"
> +    "info locals arg_[ij]"
> +    "info locals loc_arg_[ij]"} {
> +    gdb_test $cmd \
> +	[multi_line \
> +	     "loc_arg_i = 3" \
> +	     "loc_arg_j = 4" \
> +	    ] \
> +	"info args"
> +}

Note duplicate test name.

> +
> +gdb_test "info locals nowaythiscanmatch" "No matching locals." "non matching locals"
> +gdb_test "info locals -q nowaythiscanmatch" "" "quiet non matching locals"
> +gdb_test "info locals -q -t ganze_Zahl loc" "" "quiet non matching locals with type"

These last two match anything.  Use gdb_test_no_output instead.

> +
> +# verify that the rest of the args is taken as a single regexp
> +gdb_test "info functions abc def" \
> +    "All functions matching regular expression \\\"abc def\\\":" \
> +    "single regexp"
> +
> +gdb_test "info functions -t uvw abc def" \
> +    "All functions matching regular expression \\\"abc def\\\" with type matching regulation expression \\\"uvw\\\":" \
> +    "-t noquote single regexp"
> +
> +gdb_test "info functions -t 'uvw xyz' abc def" \
> +    "All functions matching regular expression \\\"abc def\\\" with type matching regulation expression \\\"uvw xyz\\\":" \
> +    "-t quote single regexp"
> 

Thanks,
Pedro Alves


  reply	other threads:[~2018-10-22 14:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-23 21:42 [RFAv3 0/5] info [args|functions|locals|variables] " Philippe Waroquiers
2018-09-23 21:42 ` [RFAv3 2/5] Add [-q] [-t TYPEREGEXP] [NAMEREGEXP] args to info [args|functions|locals|variables] Philippe Waroquiers
2018-10-22 14:16   ` Pedro Alves
2018-09-23 21:42 ` [RFAv3 3/5] Document changes " Philippe Waroquiers
2018-09-24  7:03   ` Eli Zaretskii
2018-10-22 14:17   ` Pedro Alves
2018-09-23 21:42 ` [RFAv3 4/5] Announce changes in NEWS " Philippe Waroquiers
2018-09-24  6:59   ` Eli Zaretskii
2018-09-23 21:42 ` [RFAv3 5/5] Add a test case for info args|functions|locals|variables [-q] [-t TYPEREGEXP] [NAMEREGEXP] Philippe Waroquiers
2018-10-22 14:19   ` Pedro Alves [this message]
2018-10-23 22:05     ` Philippe Waroquiers
2018-10-24 17:18       ` Pedro Alves
2018-09-23 21:42 ` [RFAv3 1/5] New cli-utils.h/.c function extract_info_print_args Philippe Waroquiers
2018-10-22 14:16   ` Pedro Alves
2018-10-23 21:59     ` Philippe Waroquiers
2018-10-24 17:03       ` Pedro Alves
2018-10-02 18:17 ` [RFAv3 0/5] info [args|functions|locals|variables] [-q] [-t TYPEREGEXP] [NAMEREGEXP] Philippe Waroquiers
2018-10-11 19:56 ` PING^2 " Philippe Waroquiers
2018-10-18 19:37 ` PING^3 " Philippe Waroquiers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0f46cdb0-4c14-2d1b-9f5f-410b32c0915d@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=philippe.waroquiers@skynet.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox