binutils-gdb/gdb/testsuite/gdb.linespec/explicit.c

72 lines
1.5 KiB
C
Raw Normal View History

Explicit locations: add UI features for CLI This patch exposes explicit locations to the CLI user. This enables users to "explicitly" specify attributes of the breakpoint location to avoid any ambiguity that might otherwise exist with linespecs. The general syntax of explicit locations is: -source SOURCE_FILENAME -line {+-}LINE -function FUNCTION_NAME -label LABEL_NAME Option names may be abbreviated, e.g., "-s SOURCE_FILENAME -li 3" and users may use the completer with either options or values. gdb/ChangeLog: * completer.c: Include location.h. (enum match_type): New enum. (location_completer): Rename to ... (linespec_completer): ... this. (collect_explicit_location_matches, backup_text_ptr) (explicit_location_completer): New functions. (location_completer): "New" function; handle linespec and explicit location completions. (complete_line_internal): Remove all location completer-specific handling. * linespec.c (linespec_lexer_lex_keyword, is_ada_operator) (find_toplevel_char): Export. (linespec_parse_line_offset): Export. Issue error if STRING is not numerical. (gdb_get_linespec_parser_quote_characters): New function. * linespec.h (linespec_parse_line_offset): Declare. (get_gdb_linespec_parser_quote_characters): Declare. (is_ada_operator): Declare. (find_toplevel_char): Declare. (linespec_lexer_lex_keyword): Declare. * location.c (explicit_to_event_location): New function. (explicit_location_lex_one): New function. (string_to_explicit_location): New function. (string_to_event_location): Handle explicit locations. * location.h (explicit_to_event_location): Declare. (string_to_explicit_location): Declare. gdb/testsuite/ChangeLog: * gdb.linespec/3explicit.c: New file. * gdb.linespec/cpexplicit.cc: New file. * gdb.linespec/cpexplicit.exp: New file. * gdb.linespec/explicit.c: New file. * gdb.linespec/explicit.exp: New file. * gdb.linespec/explicit2.c: New file. * gdb.linespec/ls-errs.exp: Add explicit location tests. * lib/gdb.exp (capture_command_output): Regexp-escape `command' before using in the matching pattern. Clarify that `prefix' is a regular expression.
2015-08-12 02:09:36 +02:00
/* This testcase is part of GDB, the GNU debugger.
Copyright 2012-2018 Free Software Foundation, Inc.
Explicit locations: add UI features for CLI This patch exposes explicit locations to the CLI user. This enables users to "explicitly" specify attributes of the breakpoint location to avoid any ambiguity that might otherwise exist with linespecs. The general syntax of explicit locations is: -source SOURCE_FILENAME -line {+-}LINE -function FUNCTION_NAME -label LABEL_NAME Option names may be abbreviated, e.g., "-s SOURCE_FILENAME -li 3" and users may use the completer with either options or values. gdb/ChangeLog: * completer.c: Include location.h. (enum match_type): New enum. (location_completer): Rename to ... (linespec_completer): ... this. (collect_explicit_location_matches, backup_text_ptr) (explicit_location_completer): New functions. (location_completer): "New" function; handle linespec and explicit location completions. (complete_line_internal): Remove all location completer-specific handling. * linespec.c (linespec_lexer_lex_keyword, is_ada_operator) (find_toplevel_char): Export. (linespec_parse_line_offset): Export. Issue error if STRING is not numerical. (gdb_get_linespec_parser_quote_characters): New function. * linespec.h (linespec_parse_line_offset): Declare. (get_gdb_linespec_parser_quote_characters): Declare. (is_ada_operator): Declare. (find_toplevel_char): Declare. (linespec_lexer_lex_keyword): Declare. * location.c (explicit_to_event_location): New function. (explicit_location_lex_one): New function. (string_to_explicit_location): New function. (string_to_event_location): Handle explicit locations. * location.h (explicit_to_event_location): Declare. (string_to_explicit_location): Declare. gdb/testsuite/ChangeLog: * gdb.linespec/3explicit.c: New file. * gdb.linespec/cpexplicit.cc: New file. * gdb.linespec/cpexplicit.exp: New file. * gdb.linespec/explicit.c: New file. * gdb.linespec/explicit.exp: New file. * gdb.linespec/explicit2.c: New file. * gdb.linespec/ls-errs.exp: Add explicit location tests. * lib/gdb.exp (capture_command_output): Regexp-escape `command' before using in the matching pattern. Clarify that `prefix' is a regular expression.
2015-08-12 02:09:36 +02:00
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/>. */
extern int myfunction2 (int arg);
static int
myfunction (int arg)
{
int i, j, r;
j = 0; /* myfunction location */
r = arg;
top:
++j; /* top location */
if (j == 10)
goto done;
for (i = 0; i < 10; ++i)
{
r += i;
if (j % 2)
goto top;
}
done:
return r;
}
Fix gdb.linespec/explicit.exp This patch addresses timeout failures i noticed while testing aarch64-elf. FAIL: gdb.linespec/explicit.exp: complete unique function name (timeout) FAIL: gdb.linespec/explicit.exp: complete non-unique function name (timeout) FAIL: gdb.linespec/explicit.exp: complete non-existant function name (timeout) FAIL: gdb.linespec/explicit.exp: complete unique file name (timeout) FAIL: gdb.linespec/explicit.exp: complete non-unique file name (timeout) The timeouts were caused by an attempt to match a bell character (x07) that doesn't show up on my particular test setup. The bell character is output whenever one tries to complete a pattern and there are multiple possible matches. When there is only one possible match, GDB will complete the input pattern without outputting the bell character. The reason for the discrepancy in this test's behavior is due to the use of "main" for a unique name test. On glibc-based systems, GDB may notice the "main_arena" symbol, which is a data global part of glibc's malloc implementation. Therefore a bell character will be output because we have a couple possible completion matches. GDB should not be outputting such a data symbol as a possible match, but this problem may/will be addressed in a future change and is besides the point of this particular change. On systems that are not based on glibc, GDB will not see any other possible matches for completing "main", so there will be no bell characters. The use of main is a bit fragile though, so the patch adds a new local function with a name that has a greater chance of being unique and adjusts the test to iuse it. I've also added the regular expression switch (-re) to all the gdb_test_multiple calls that were missing it. Hopefully this will reduce the chances of someone wasting time trying to match a regular expression (a much more common use case) when, in reality, the pattern is supposed to be matched literally. gdb/testsuite/ChangeLog 2017-02-13 Luis Machado <lgustavo@codesourcery.com> * gdb.linespec/explicit.c (my_unique_function_name): New function. (main): Call my_unique_function_name. * gdb.linespec/explicit.exp: Use my_unique_function_name to test completion of patterns with a single match. Add missing -re switches to gdb_test_multiple calls.
2017-02-13 14:16:34 +01:00
static int
my_unique_function_name (int arg)
{
int j = 0;
/* Just do something random. We only care about the unique function
name. */
if (arg == 50)
j = 10;
return j;
}
Explicit locations: add UI features for CLI This patch exposes explicit locations to the CLI user. This enables users to "explicitly" specify attributes of the breakpoint location to avoid any ambiguity that might otherwise exist with linespecs. The general syntax of explicit locations is: -source SOURCE_FILENAME -line {+-}LINE -function FUNCTION_NAME -label LABEL_NAME Option names may be abbreviated, e.g., "-s SOURCE_FILENAME -li 3" and users may use the completer with either options or values. gdb/ChangeLog: * completer.c: Include location.h. (enum match_type): New enum. (location_completer): Rename to ... (linespec_completer): ... this. (collect_explicit_location_matches, backup_text_ptr) (explicit_location_completer): New functions. (location_completer): "New" function; handle linespec and explicit location completions. (complete_line_internal): Remove all location completer-specific handling. * linespec.c (linespec_lexer_lex_keyword, is_ada_operator) (find_toplevel_char): Export. (linespec_parse_line_offset): Export. Issue error if STRING is not numerical. (gdb_get_linespec_parser_quote_characters): New function. * linespec.h (linespec_parse_line_offset): Declare. (get_gdb_linespec_parser_quote_characters): Declare. (is_ada_operator): Declare. (find_toplevel_char): Declare. (linespec_lexer_lex_keyword): Declare. * location.c (explicit_to_event_location): New function. (explicit_location_lex_one): New function. (string_to_explicit_location): New function. (string_to_event_location): Handle explicit locations. * location.h (explicit_to_event_location): Declare. (string_to_explicit_location): Declare. gdb/testsuite/ChangeLog: * gdb.linespec/3explicit.c: New file. * gdb.linespec/cpexplicit.cc: New file. * gdb.linespec/cpexplicit.exp: New file. * gdb.linespec/explicit.c: New file. * gdb.linespec/explicit.exp: New file. * gdb.linespec/explicit2.c: New file. * gdb.linespec/ls-errs.exp: Add explicit location tests. * lib/gdb.exp (capture_command_output): Regexp-escape `command' before using in the matching pattern. Clarify that `prefix' is a regular expression.
2015-08-12 02:09:36 +02:00
int
main (void)
{
int i, j;
/* Call the test function repeatedly, enough times for all our tests
without running forever if something goes wrong. */
for (i = 0, j = 0; i < 1000; ++i)
j += myfunction (0);
Fix gdb.linespec/explicit.exp This patch addresses timeout failures i noticed while testing aarch64-elf. FAIL: gdb.linespec/explicit.exp: complete unique function name (timeout) FAIL: gdb.linespec/explicit.exp: complete non-unique function name (timeout) FAIL: gdb.linespec/explicit.exp: complete non-existant function name (timeout) FAIL: gdb.linespec/explicit.exp: complete unique file name (timeout) FAIL: gdb.linespec/explicit.exp: complete non-unique file name (timeout) The timeouts were caused by an attempt to match a bell character (x07) that doesn't show up on my particular test setup. The bell character is output whenever one tries to complete a pattern and there are multiple possible matches. When there is only one possible match, GDB will complete the input pattern without outputting the bell character. The reason for the discrepancy in this test's behavior is due to the use of "main" for a unique name test. On glibc-based systems, GDB may notice the "main_arena" symbol, which is a data global part of glibc's malloc implementation. Therefore a bell character will be output because we have a couple possible completion matches. GDB should not be outputting such a data symbol as a possible match, but this problem may/will be addressed in a future change and is besides the point of this particular change. On systems that are not based on glibc, GDB will not see any other possible matches for completing "main", so there will be no bell characters. The use of main is a bit fragile though, so the patch adds a new local function with a name that has a greater chance of being unique and adjusts the test to iuse it. I've also added the regular expression switch (-re) to all the gdb_test_multiple calls that were missing it. Hopefully this will reduce the chances of someone wasting time trying to match a regular expression (a much more common use case) when, in reality, the pattern is supposed to be matched literally. gdb/testsuite/ChangeLog 2017-02-13 Luis Machado <lgustavo@codesourcery.com> * gdb.linespec/explicit.c (my_unique_function_name): New function. (main): Call my_unique_function_name. * gdb.linespec/explicit.exp: Use my_unique_function_name to test completion of patterns with a single match. Add missing -re switches to gdb_test_multiple calls.
2017-02-13 14:16:34 +01:00
my_unique_function_name (j);
Explicit locations: add UI features for CLI This patch exposes explicit locations to the CLI user. This enables users to "explicitly" specify attributes of the breakpoint location to avoid any ambiguity that might otherwise exist with linespecs. The general syntax of explicit locations is: -source SOURCE_FILENAME -line {+-}LINE -function FUNCTION_NAME -label LABEL_NAME Option names may be abbreviated, e.g., "-s SOURCE_FILENAME -li 3" and users may use the completer with either options or values. gdb/ChangeLog: * completer.c: Include location.h. (enum match_type): New enum. (location_completer): Rename to ... (linespec_completer): ... this. (collect_explicit_location_matches, backup_text_ptr) (explicit_location_completer): New functions. (location_completer): "New" function; handle linespec and explicit location completions. (complete_line_internal): Remove all location completer-specific handling. * linespec.c (linespec_lexer_lex_keyword, is_ada_operator) (find_toplevel_char): Export. (linespec_parse_line_offset): Export. Issue error if STRING is not numerical. (gdb_get_linespec_parser_quote_characters): New function. * linespec.h (linespec_parse_line_offset): Declare. (get_gdb_linespec_parser_quote_characters): Declare. (is_ada_operator): Declare. (find_toplevel_char): Declare. (linespec_lexer_lex_keyword): Declare. * location.c (explicit_to_event_location): New function. (explicit_location_lex_one): New function. (string_to_explicit_location): New function. (string_to_event_location): Handle explicit locations. * location.h (explicit_to_event_location): Declare. (string_to_explicit_location): Declare. gdb/testsuite/ChangeLog: * gdb.linespec/3explicit.c: New file. * gdb.linespec/cpexplicit.cc: New file. * gdb.linespec/cpexplicit.exp: New file. * gdb.linespec/explicit.c: New file. * gdb.linespec/explicit.exp: New file. * gdb.linespec/explicit2.c: New file. * gdb.linespec/ls-errs.exp: Add explicit location tests. * lib/gdb.exp (capture_command_output): Regexp-escape `command' before using in the matching pattern. Clarify that `prefix' is a regular expression.
2015-08-12 02:09:36 +02:00
return myfunction2 (j);
}