--- /dev/null
+/* Copyright 2022-2023 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/>. */
+
+int
+foo ()
+{
+ return 0; /* Breakpoint in foo. */
+}
--- /dev/null
+/* Copyright 2022-2023 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/>. */
+
+extern int foo ();
+
+int
+main ()
+{
+ int answer = foo ();
+ return answer;
+}
--- /dev/null
+# Copyright 2022-2023 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/>.
+
+# Places a breakpoint on a function in a shared library before the
+# inferior has started. GDB will place the breakpoint on the @plt
+# symbol in the main executable.
+#
+# When the inferior is started GDB will re-evaluate the breakpoint
+# location and move the breakpoint to the function implementation in
+# the shared library.
+#
+# Then, with the inferior started, delete all breakpoints, and
+# re-create the breakpoint on the shared library function, GDB should
+# place a single breakpoint on the function implementation in the
+# shared library.
+
+require allow_shlib_tests
+
+standard_testfile .cc -lib.cc
+
+set libobj [standard_output_file libfoo.so]
+if {[build_executable "build shared library" $libobj $srcfile2 \
+ {debug c++ shlib}] != 0} {
+ return -1
+}
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
+ [list debug c++ shlib=$libobj]]} {
+ return -1
+}
+
+# Place the breakpoint before the shared library has been loaded, the
+# breakpoint should be placed on the @plt symbol.
+gdb_test "break foo" "Breakpoint $decimal at $hex"
+gdb_test "info breakpoints" "<foo\\(\\)@plt>"
+
+# This is used as an override for delete_breakpoints when we don't
+# want functions in gdb.exp to delete breakpoints behind the scenes
+# for us.
+proc do_not_delete_breakpoints {} {
+ # Just do nothing.
+}
+
+# Runto main, but don't delete all the breakpoints.
+with_override delete_breakpoints do_not_delete_breakpoints {
+ if {![runto_main]} {
+ return -1
+ }
+}
+
+# The breakpoint should now be showing in `foo` for real.
+gdb_test "info breakpoints" \
+ "\r\n$decimal\\s+\[^\r\n\]+ in foo\\(\\) at \[^\r\n\]+\r\n.*" \
+ "check breakpoints after starting the inferior"
+
+# Now we can delete the breakpoints.
+delete_breakpoints
+
+# And recreate the foo breakpoint, we should only get one location,
+# the actual location.
+gdb_test "break foo" "Breakpoint $decimal at \[^\r\n\]+" \
+ "recreate foo breakpoint"
+
+# Check the breakpoint was recreated correctly.
+gdb_test "info breakpoints" \
+ "\r\n$decimal\\s+\[^\r\n\]+ in foo\\(\\) at \[^\r\n\]+" \
+ "check breakpoints after recreation"
+
+# Continue to breakpoint in foo and confirm we stop in the expected
+# place.
+gdb_continue_to_breakpoint "breakpoint in foo" \
+ ".*/\\* Breakpoint in foo\\. \\*/.*"
return 0;
}
else
- return (*string1 != '\0' && *string1 != '(');
+ {
+ if (*string1 == '(')
+ {
+ int p_count = 0;
+
+ do
+ {
+ if (*string1 == '(')
+ ++p_count;
+ else if (*string1 == ')')
+ --p_count;
+ ++string1;
+ }
+ while (*string1 != '\0' && p_count > 0);
+
+ /* There maybe things like 'const' after the parameters,
+ which we do want to ignore. However, if there's an '@'
+ then this likely indicates something like '@plt' which we
+ should not ignore. */
+ return *string1 == '@';
+ }
+
+ return *string1 == '\0' ? 0 : 1;
+ }
+
}
else
return 1;
CHECK_MATCH ("foo[abi:a][abi:b](bar[abi:c][abi:d])", "foo[abi:a][abi:b](bar[abi:c][abi:d])",
MATCH_PARAMS);
CHECK_MATCH ("foo[abi:a][abi:b](bar[abi:c][abi:d])", "foo", MATCH_PARAMS);
+ CHECK_NO_MATCH ("foo(args)@plt", "foo", MATCH_PARAMS);
+ CHECK_NO_MATCH ("foo((())args(()))@plt", "foo", MATCH_PARAMS);
+ CHECK_MATCH ("foo((())args(()))", "foo", MATCH_PARAMS);
+ CHECK_MATCH ("foo(args) const", "foo", MATCH_PARAMS);
+ CHECK_MATCH ("foo(args)const", "foo", MATCH_PARAMS);
/* strncmp_iw_with_mode also supports case insensitivity. */
{